5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 from __future__ import generators ### KEEP FOR COMPATIBILITY FIXERS
26 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
29 Test Java compilation with a live Java 1.6 "javac" compiler.
37 _python_ = TestSCons._python_
39 test = TestSCons.TestSCons()
41 where_javac, java_version = test.java_where_javac('1.6')
45 test.write('SConstruct', """
46 env = Environment(tools = ['javac'],
48 JAVAC = r'%(where_javac)s')
49 env.Java(target = 'class1', source = 'com/sub/foo')
50 env.Java(target = 'class2', source = 'com/sub/bar')
51 env.Java(target = 'class3', source = ['src1', 'src2'])
52 env.Java(target = 'class4', source = ['src4'])
53 env.Java(target = 'class5', source = ['src5'])
54 env.Java(target = 'class6', source = ['src6'])
59 ['com', 'sub', 'foo'],
60 ['com', 'sub', 'bar'],
67 test.write(['com', 'sub', 'foo', 'Example1.java'], """\
73 public static void main(String[] args)
81 test.write(['com', 'sub', 'foo', 'Example2.java'], """\
87 public static void main(String[] args)
95 test.write(['com', 'sub', 'foo', 'Example3.java'], """\
101 public static void main(String[] args)
109 test.write(['com', 'sub', 'bar', 'Example4.java'], """\
112 public class Example4
115 public static void main(String[] args)
123 test.write(['com', 'sub', 'bar', 'Example5.java'], """\
126 public class Example5
129 public static void main(String[] args)
137 test.write(['com', 'sub', 'bar', 'Example6.java'], """\
140 public class Example6
143 public static void main(String[] args)
151 test.write(['src1', 'Example7.java'], """\
152 public class Example7
155 public static void main(String[] args)
163 # Acid-test file for parsing inner Java classes, courtesy Chad Austin.
164 test.write(['src2', 'Test.java'], """\
169 public void execute();
178 public void execute() {
179 System.out.println("In Inner");
183 String s1 = "class A";
184 String s2 = "new Listener() { }";
186 /* new Listener() { } */
189 public static void main(String[] args) {
195 public void execute() {
196 use(new Listener( ) {
197 public void execute() {
198 System.out.println("Inside execute()");
207 void use(Listener l) {
215 public void execute() {
222 # Testing nested anonymous inner classes, courtesy Brandon Mansfield.
223 test.write(['src4', 'NestedExample.java'], """\
224 // import java.util.*;
226 public class NestedExample
228 public NestedExample()
236 try {Thread.sleep(200);}
237 catch (Exception e) {}
242 try {Thread.sleep(200);}
243 catch (Exception e) {}
250 public static void main(String argv[])
257 # Test not finding an anonymous class when the second token after a
258 # "new" is a closing brace. This duplicates a test from the unit tests,
259 # but lets us make sure that we correctly determine that everything is
260 # up-to-date after the build.
261 test.write(['src5', 'TestSCons.java'], """\
263 public static void main(String[] args) {
264 Foo[] fooArray = new Foo[] { new Foo() };
271 # Test private inner class instantiation, courtesy Tilo Prutz:
272 # http://scons.tigris.org/issues/show_bug.cgi?id=1594
273 test.write(['src6', 'TestSCons.java'], """\
291 test.run(arguments = '.')
294 test.workpath('class1', 'com', 'other', 'Example2.class'),
295 test.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'),
296 test.workpath('class1', 'com', 'sub', 'foo', 'Example3.class'),
300 test.workpath('class2', 'com', 'other', 'Example5.class'),
301 test.workpath('class2', 'com', 'sub', 'bar', 'Example4.class'),
302 test.workpath('class2', 'com', 'sub', 'bar', 'Example6.class'),
306 test.workpath('class3', 'Empty.class'),
307 test.workpath('class3', 'Example7.class'),
308 test.workpath('class3', 'Listener.class'),
309 test.workpath('class3', 'Private$1.class'),
310 test.workpath('class3', 'Private.class'),
311 test.workpath('class3', 'Test$1$1.class'),
312 test.workpath('class3', 'Test$1.class'),
313 test.workpath('class3', 'Test$Inner$1.class'),
314 test.workpath('class3', 'Test$Inner.class'),
315 test.workpath('class3', 'Test.class'),
319 test.workpath('class4', 'NestedExample$1$1.class'),
320 test.workpath('class4', 'NestedExample$1.class'),
321 test.workpath('class4', 'NestedExample.class'),
325 test.workpath('class5', 'Foo.class'),
326 test.workpath('class5', 'TestSCons.class'),
330 test.workpath('class6', 'test$1.class'),
331 test.workpath('class6', 'test$inner.class'),
332 test.workpath('class6', 'test.class'),
337 def get_class_files(dir):
338 def find_class_files(arg, dirname, fnames):
340 if fname[-6:] == '.class':
341 arg.append(os.path.join(dirname, fname))
343 os.path.walk(dir, find_class_files, result)
347 def classes_must_match(dir, expect):
349 got = get_class_files(test.workpath(dir))
351 sys.stderr.write("Expected the following class files in '%s':\n" % dir)
353 sys.stderr.write(' %s\n' % c)
354 sys.stderr.write("Got the following class files in '%s':\n" % dir)
356 sys.stderr.write(' %s\n' % c)
359 def classes_must_not_exist(dir, expect):
361 present = list(filter(os.path.exists, expect))
363 sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir)
365 sys.stderr.write(' %s\n' % c)
368 classes_must_match('class1', expect_1)
369 classes_must_match('class2', expect_2)
370 classes_must_match('class3', expect_3)
371 classes_must_match('class4', expect_4)
372 classes_must_match('class5', expect_5)
373 classes_must_match('class6', expect_6)
375 test.fail_test(failed)
377 test.up_to_date(options='--debug=explain', arguments = '.')
379 test.run(arguments = '-c .')
381 classes_must_not_exist('class1', expect_1)
382 classes_must_not_exist('class2', expect_2)
383 classes_must_not_exist('class3', expect_3)
384 classes_must_not_exist('class4', expect_4)
385 classes_must_not_exist('class5', expect_5)
386 # This test case should pass, but doesn't.
387 # The expect_6 list contains the class files that the Java compiler
388 # actually creates, apparently because of the "private" instantiation
389 # of the "inner" class. Our parser doesn't currently detect this, so
390 # it doesn't know to remove that generated class file.
391 #classes_must_not_exist('class6', expect_6)
393 test.fail_test(failed)
399 # indent-tabs-mode:nil
401 # vim: set expandtab tabstop=4 shiftwidth=4: