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.
27 Test building Java applications when using Repositories.
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
41 if java_version
.count('.') == 1:
43 major
, minor
= java_version
.split('.')
45 curver
= (int(major
), int(minor
))
48 elif java_version
.count('.') == 0:
51 curver
= (int(java_version
), 0)
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.
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()
76 ###############################################################################
79 test
.subdir('rep1', ['rep1', 'src'],
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'],
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)
104 test
.write(['rep1', 'src', 'Hello.java'], """\
107 import java.rmi.Remote;
108 import java.rmi.RemoteException;
110 public interface Hello extends Remote {
111 String sayHello() throws RemoteException;
115 test
.write(['rep1', 'src', 'Foo1.java'], """\
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 {
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());
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());
154 test
.write(['rep1', 'src', 'Foo2.java'], """\
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 {
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());
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());
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'], """\
227 import java.rmi.Remote;
228 import java.rmi.RemoteException;
230 public interface Hello extends Remote {
231 String sayHello() throws RemoteException;
235 test
.write(['work1', 'src', 'Foo1.java'], """\
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 {
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());
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());
274 test
.write(['work1', 'src', 'Foo2.java'], """\
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 {
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());
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());
313 test
.run(chdir
= 'work1', options
= opts
, arguments
= ".")
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'],
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)
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
= ".")
392 # indent-tabs-mode:nil
394 # vim: set expandtab tabstop=4 shiftwidth=4: