[ci skip] update generated files
[scons.git] / test / Repository / RMIC.py
blob92421be9998d57bc2d9672ba96267ba8232340ac
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Test building Java applications when using Repositories.
28 """
30 import TestSCons
31 import os
33 python = TestSCons.python
35 test = TestSCons.TestSCons()
37 where_javac, java_version = test.java_where_javac()
39 # Try to get the major/minor Java version
40 curver = (1, 0)
41 if java_version.count('.') == 1:
42 # Check Java version
43 major, minor = java_version.split('.')
44 try:
45 curver = (int(major), int(minor))
46 except ValueError:
47 pass
48 elif java_version.count('.') == 0:
49 # java 11?
50 try:
51 curver = (int(java_version), 0)
52 except ValueError:
53 pass
55 # Check the version of the found Java compiler.
56 # If it's 1.8 or higher, we skip the further RMIC test
57 # because we'll get warnings about the deprecated API...
58 # it's just not state-of-the-art anymore.
59 # Recent java versions (9 and greater) are back to being
60 # marketed as a simple version, but java_where_javac() will
61 # still return a dotted version, like 10.0. If this changes,
62 # will need to rework this rule.
63 # Note, how we allow simple version strings like "5" and
64 # "6" to successfully pass this test.
65 if curver >= (1, 8):
66 test.skip_test('The found version of javac is higher than 1.7, skipping test.\n')
69 where_java = test.java_where_java()
70 where_rmic = test.java_where_rmic()
72 java = where_java
73 javac = where_javac
74 rmic = where_rmic
76 ###############################################################################
79 test.subdir('rep1', ['rep1', 'src'],
80 'work1',
81 'work2',
82 'work3')
85 rep1_classes = test.workpath('rep1', 'classes')
86 work1_classes = test.workpath('work1', 'classes')
87 work3_classes = test.workpath('work3', 'classes')
90 opts = '-Y ' + test.workpath('rep1')
93 test.write(['rep1', 'SConstruct'], """
94 DefaultEnvironment(tools=[]) # test speedup
95 env = Environment(tools = ['javac', 'rmic'],
96 JAVAC = r'"%s"',
97 RMIC = r'"%s"')
98 classes = env.Java(target = 'classes', source = 'src')
99 # Brute-force removal of the "Hello" class.
100 classes = [c for c in classes if 'Hello' not in str(c)]
101 env.RMIC(target = 'outdir', source = classes)
102 """ % (javac, rmic))
104 test.write(['rep1', 'src', 'Hello.java'], """\
105 package com.sub.foo;
107 import java.rmi.Remote;
108 import java.rmi.RemoteException;
110 public interface Hello extends Remote {
111 String sayHello() throws RemoteException;
113 """)
115 test.write(['rep1', 'src', 'Foo1.java'], """\
116 package com.sub.foo;
118 import java.rmi.Naming;
119 import java.rmi.RemoteException;
120 import java.rmi.RMISecurityManager;
121 import java.rmi.server.UnicastRemoteObject;
123 public class Foo1 extends UnicastRemoteObject implements Hello {
125 static final long serialVersionUID = 0;
127 public Foo1() throws RemoteException {
128 super();
131 public String sayHello() {
132 return "rep1/src/Foo1.java";
135 public static void main(String args[]) {
136 if (System.getSecurityManager() == null) {
137 System.setSecurityManager(new RMISecurityManager());
140 try {
141 Foo1 obj = new Foo1();
143 Naming.rebind("//myhost/HelloServer", obj);
145 System.out.println("HelloServer bound in registry");
146 } catch (Exception e) {
147 System.out.println("Foo1 err: " + e.getMessage());
148 e.printStackTrace();
152 """)
154 test.write(['rep1', 'src', 'Foo2.java'], """\
155 package com.sub.foo;
157 import java.rmi.Naming;
158 import java.rmi.RemoteException;
159 import java.rmi.RMISecurityManager;
160 import java.rmi.server.UnicastRemoteObject;
162 public class Foo2 extends UnicastRemoteObject implements Hello {
164 static final long serialVersionUID = 0;
166 public Foo2() throws RemoteException {
167 super();
170 public String sayHello() {
171 return "rep1/src/Foo2.java";
174 public static void main(String args[]) {
175 if (System.getSecurityManager() == null) {
176 System.setSecurityManager(new RMISecurityManager());
179 try {
180 Foo2 obj = new Foo2();
182 Naming.rebind("//myhost/HelloServer", obj);
184 System.out.println("HelloServer bound in registry");
185 } catch (Exception e) {
186 System.out.println("Foo2 err: " + e.getMessage());
187 e.printStackTrace();
191 """)
193 # Make the repository non-writable,
194 # so we'll detect if we try to write into it accidentally.
195 test.writable('repository', 0)
198 test.run(chdir = 'work1', options = opts, arguments = ".")
200 # XXX I'd rather run the resulting class files through the JVM here to
201 # see that they were built from the proper rep1 sources, but I don't
202 # know how to do that with RMI, so punt for now.
204 test.must_not_exist(test.workpath('rep1', 'outdir', 'com', 'sub', 'foo', 'Foo1_Stub.class'))
205 test.must_not_exist(test.workpath('rep1', 'outdir', 'com', 'sub', 'foo', 'Foo2_Stub.class'))
207 test.must_exist (test.workpath('work1', 'outdir', 'com', 'sub', 'foo', 'Foo1_Stub.class'))
208 test.must_exist (test.workpath('work1', 'outdir', 'com', 'sub', 'foo', 'Foo2_Stub.class'))
210 # We used to check for _Skel.class files as well, but they're not
211 # generated by default starting with Java 1.5, and they apparently
212 # haven't been needed for a while. Don't bother looking, even if we're
213 # running Java 1.4. If we think they're needed but they don't exist
214 # the variou test.up_to_date() calls below will detect it.
215 #test.must_not_exist(test.workpath('rep1', 'outdir', 'com', 'sub', 'foo', 'Foo2_Skel.class'))
216 #test.must_exist (test.workpath('work1', 'outdir', 'com', 'sub', 'foo', 'Foo1_Skel.class'))
217 #test.must_exist (test.workpath('work1', 'outdir', 'com', 'sub', 'foo', 'Foo2_Skel.class'))
219 test.up_to_date(chdir = 'work1', options = opts, arguments = ".")
222 test.subdir(['work1', 'src'])
224 test.write(['work1', 'src', 'Hello.java'], """\
225 package com.sub.foo;
227 import java.rmi.Remote;
228 import java.rmi.RemoteException;
230 public interface Hello extends Remote {
231 String sayHello() throws RemoteException;
233 """)
235 test.write(['work1', 'src', 'Foo1.java'], """\
236 package com.sub.foo;
238 import java.rmi.Naming;
239 import java.rmi.RemoteException;
240 import java.rmi.RMISecurityManager;
241 import java.rmi.server.UnicastRemoteObject;
243 public class Foo1 extends UnicastRemoteObject implements Hello {
245 static final long serialVersionUID = 0;
247 public Foo1() throws RemoteException {
248 super();
251 public String sayHello() {
252 return "work1/src/Foo1.java";
255 public static void main(String args[]) {
256 if (System.getSecurityManager() == null) {
257 System.setSecurityManager(new RMISecurityManager());
260 try {
261 Foo1 obj = new Foo1();
263 Naming.rebind("//myhost/HelloServer", obj);
265 System.out.println("HelloServer bound in registry");
266 } catch (Exception e) {
267 System.out.println("Foo1 err: " + e.getMessage());
268 e.printStackTrace();
272 """)
274 test.write(['work1', 'src', 'Foo2.java'], """\
275 package com.sub.foo;
277 import java.rmi.Naming;
278 import java.rmi.RemoteException;
279 import java.rmi.RMISecurityManager;
280 import java.rmi.server.UnicastRemoteObject;
282 public class Foo2 extends UnicastRemoteObject implements Hello {
284 static final long serialVersionUID = 0;
286 public Foo2() throws RemoteException {
287 super();
290 public String sayHello() {
291 return "work1/src/Foo2.java";
294 public static void main(String args[]) {
295 if (System.getSecurityManager() == null) {
296 System.setSecurityManager(new RMISecurityManager());
299 try {
300 Foo2 obj = new Foo2();
302 Naming.rebind("//myhost/HelloServer", obj);
304 System.out.println("HelloServer bound in registry");
305 } catch (Exception e) {
306 System.out.println("Foo2 err: " + e.getMessage());
307 e.printStackTrace();
311 """)
313 test.run(chdir = 'work1', options = opts, arguments = ".")
315 expect = [
316 ' src' + os.sep + 'Foo1.java src' + os.sep + 'Foo2.java',
317 ' com.sub.foo.Foo1 com.sub.foo.Foo2',
320 test.must_contain_all_lines(test.stdout(), expect)
322 # XXX I'd rather run the resulting class files through the JVM here to
323 # see that they were built from the proper work1 sources, but I don't
324 # know how to do that with RMI, so punt for now.
326 test.must_not_exist(test.workpath('rep1', 'outdir', 'com', 'sub', 'foo', 'Foo1_Stub.class'))
327 test.must_not_exist(test.workpath('rep1', 'outdir', 'com', 'sub', 'foo', 'Foo2_Stub.class'))
328 test.must_exist (test.workpath('work1', 'outdir', 'com', 'sub', 'foo', 'Foo1_Stub.class'))
329 test.must_exist (test.workpath('work1', 'outdir', 'com', 'sub', 'foo', 'Foo2_Stub.class'))
331 #test.must_not_exist(test.workpath('rep1', 'outdir', 'com', 'sub', 'foo', 'Foo1_Skel.class'))
332 #test.must_not_exist(test.workpath('rep1', 'outdir', 'com', 'sub', 'foo', 'Foo2_Skel.class'))
333 #test.must_exist (test.workpath('work1', 'outdir', 'com', 'sub', 'foo', 'Foo1_Skel.class'))
334 #test.must_exist (test.workpath('work1', 'outdir', 'com', 'sub', 'foo', 'Foo2_Skel.class'))
336 test.up_to_date(chdir = 'work1', options = opts, arguments = ".")
339 test.writable('rep1', 1)
341 test.run(chdir = 'rep1', options = opts, arguments = ".")
343 # XXX I'd rather run the resulting class files through the JVM here to
344 # see that they were built from the proper work1 sources, but I don't
345 # know how to do that with RMI, so punt for now.
347 test.must_exist(test.workpath('rep1', 'outdir', 'com', 'sub', 'foo', 'Foo1_Stub.class'))
348 test.must_exist(test.workpath('rep1', 'outdir', 'com', 'sub', 'foo', 'Foo2_Stub.class'))
350 #test.must_exist(test.workpath('rep1', 'outdir', 'com', 'sub', 'foo', 'Foo1_Skel.class'))
351 #test.must_exist(test.workpath('rep1', 'outdir', 'com', 'sub', 'foo', 'Foo2_Skel.class'))
353 test.up_to_date(chdir = 'rep1', options = opts, arguments = ".")
356 test.writable('repository', 0)
359 test.up_to_date(chdir = 'work2', options = opts, arguments = ".")
362 test.write(['work3', 'SConstruct'], """
363 DefaultEnvironment(tools=[]) # test speedup
364 env = Environment(tools = ['javac', 'rmic'],
365 JAVAC = r'"%s"',
366 RMIC = r'"%s"')
367 classes = env.Java(target = 'classes', source = 'src')
368 # Brute-force removal of the "Hello" class.
369 classes = [c for c in classes if 'Hello' not in str(c)]
370 rmi_classes = env.RMIC(target = 'outdir', source = classes)
371 Local(rmi_classes)
372 """ % (javac, rmic))
374 test.run(chdir = 'work3', options = opts, arguments = ".")
376 test.must_not_exist(test.workpath('work3', 'classes', 'com', 'sub', 'foo', 'Hello.class'))
377 test.must_not_exist(test.workpath('work3', 'classes', 'com', 'sub', 'foo', 'Foo1.class'))
378 test.must_not_exist(test.workpath('work3', 'classes', 'com', 'sub', 'foo', 'Foo2.class'))
380 test.must_exist (test.workpath('work3', 'outdir', 'com', 'sub', 'foo', 'Foo1_Stub.class'))
381 test.must_exist (test.workpath('work3', 'outdir', 'com', 'sub', 'foo', 'Foo2_Stub.class'))
383 #test.must_exist (test.workpath('work3', 'outdir', 'com', 'sub', 'foo', 'Foo1_Skel.class'))
384 #test.must_exist (test.workpath('work3', 'outdir', 'com', 'sub', 'foo', 'Foo2_Skel.class'))
386 test.up_to_date(chdir = 'work3', options = opts, arguments = ".")
388 test.pass_test()
390 # Local Variables:
391 # tab-width:4
392 # indent-tabs-mode:nil
393 # End:
394 # vim: set expandtab tabstop=4 shiftwidth=4: