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.
29 These tests require a findable/working Java subsystem.
35 _python_
= TestSCons
._python
_
37 test
= TestSCons
.TestSCons()
39 where_javac
, java_version
= test
.java_where_javac()
40 where_jar
= test
.java_where_jar()
42 test
.file_fixture('wrapper_with_args.py')
44 test
.write('SConstruct', """\
45 DefaultEnvironment(tools=[])
46 foo = Environment(tools=['javac', 'jar'])
47 # jar = foo.Dictionary('JAR')
48 bar = foo.Clone(JAR=r'%(_python_)s wrapper_with_args.py jar')
49 foo.Java(target='classes', source='com/sub/foo')
50 bar.Java(target='classes', source='com/sub/bar')
51 foo.Jar(target='foo', source='classes/com/sub/foo')
52 bar.Jar(target='bar', source=Dir('classes/com/sub/bar'))
55 test
.subdir('com', ['com', 'sub'], ['com', 'sub', 'foo'], ['com', 'sub', 'bar'])
57 test
.write(['com', 'sub', 'foo', 'Example1.java'], """\
63 public static void main(String[] args)
71 test
.write(['com', 'sub', 'foo', 'Example2.java'], """\
77 public static void main(String[] args)
85 test
.write(['com', 'sub', 'foo', 'Example3.java'], """\
91 public static void main(String[] args)
99 test
.write(['com', 'sub', 'bar', 'Example4.java'], """\
102 public class Example4
105 public static void main(String[] args)
113 test
.write(['com', 'sub', 'bar', 'Example5.java'], """\
116 public class Example5
119 public static void main(String[] args)
127 test
.write(['com', 'sub', 'bar', 'Example6.java'], """\
130 public class Example6
133 public static void main(String[] args)
141 test
.run(arguments
= '.')
143 expected_wrapper_out
= "wrapper_with_args.py jar cf bar.jar classes/com/sub/bar\n"
144 expected_wrapper_out
= expected_wrapper_out
.replace('/', os
.sep
)
145 test
.must_match('wrapper.out', expected_wrapper_out
% locals(), mode
='r')
147 test
.must_exist('foo.jar')
148 test
.must_exist('bar.jar')
150 test
.up_to_date(arguments
='.')
153 # test java source files as source to Jar builder
155 # make some directories to test in
156 test
.subdir('testdir2',
158 ['testdir2', 'com', 'javasource'])
160 # simple SConstruct which passes the 3 .java as source
161 # and extracts the jars back to classes
162 test
.write(['testdir2', 'SConstruct'], """
163 DefaultEnvironment(tools=[])
169 'com/javasource/JavaFile1.java',
170 'com/javasource/JavaFile2.java',
171 'com/javasource/JavaFile3.java',
175 target=['foo', 'bar'],
177 'com/javasource/JavaFile1.java',
178 'com/javasource/JavaFile2.java',
179 'com/javasource/JavaFile3.java',
182 foo.Command("foobarTest", [], Mkdir("foobarTest"))
184 'foobarTest/com/javasource/JavaFile3.java',
186 foo['JAR'] + ' xvf ../foobar.jar',
189 foo.Command("fooTest", [], Mkdir("fooTest"))
191 'fooTest/com/javasource/JavaFile3.java',
193 foo['JAR'] + ' xvf ../foo.jar',
196 foo.Command("barTest", [], Mkdir("barTest"))
198 'barTest/com/javasource/JavaFile3.java',
200 foo['JAR'] + ' xvf ../bar.jar',
205 test
.write(['testdir2', 'com', 'javasource', 'JavaFile1.java'], """\
206 package com.javasource;
208 public class JavaFile1
210 public static void main(String[] args)
217 test
.write(['testdir2', 'com', 'javasource', 'JavaFile2.java'], """\
218 package com.javasource;
220 public class JavaFile2
222 public static void main(String[] args)
229 test
.write(['testdir2', 'com', 'javasource', 'JavaFile3.java'], """\
230 package com.javasource;
232 public class JavaFile3
234 public static void main(String[] args)
242 # check the output and make sure the java files got converted to classes
243 # use regex . for dirsep so this will work on both windows and other platforms.
244 expect
= ".*jar cf foo.jar -C com.javasource.JavaFile1 com.javasource.JavaFile1.class -C com.javasource.JavaFile2 com.javasource.JavaFile2.class -C com.javasource.JavaFile3 com.javasource.JavaFile3.class.*"
246 test
.run(chdir
='testdir2', match
=TestSCons
.match_re_dotall
, stdout
=expect
)
248 #test single target jar
249 test
.must_exist(['testdir2','foobar.jar'])
250 test
.must_exist(['testdir2', 'foobarTest', 'com', 'javasource', 'JavaFile1.class'])
251 test
.must_exist(['testdir2', 'foobarTest', 'com', 'javasource', 'JavaFile2.class'])
252 test
.must_exist(['testdir2', 'foobarTest', 'com', 'javasource', 'JavaFile3.class'])
254 # make sure there are class in the jar
255 test
.must_exist(['testdir2','foo.jar'])
256 test
.must_exist(['testdir2', 'fooTest', 'com', 'javasource', 'JavaFile1.class'])
257 test
.must_exist(['testdir2', 'fooTest', 'com', 'javasource', 'JavaFile2.class'])
258 test
.must_exist(['testdir2', 'fooTest', 'com', 'javasource', 'JavaFile3.class'])
260 # make sure both jars got createds
261 test
.must_exist(['testdir2','bar.jar'])
262 test
.must_exist(['testdir2', 'barTest', 'com', 'javasource', 'JavaFile1.class'])
263 test
.must_exist(['testdir2', 'barTest', 'com', 'javasource', 'JavaFile2.class'])
264 test
.must_exist(['testdir2', 'barTest', 'com', 'javasource', 'JavaFile3.class'])
270 # make some directories to test in
274 ['listOfLists', 'src'],
275 ['listOfLists', 'src', 'com'],
276 ['listOfLists', 'src', 'com', 'javasource'],
277 ['listOfLists', 'src', 'com', 'resource'],
280 # test varient dir and lists of lists
281 test
.write(['listOfLists', 'SConstruct'], """
282 DefaultEnvironment(tools=[])
285 foo.VariantDir('build', 'src', duplicate=0)
286 foo.VariantDir('test', '../manifest_dir', duplicate=0)
288 "src/com/javasource/JavaFile1.java",
289 "src/com/javasource/JavaFile2.java",
290 "src/com/javasource/JavaFile3.java",
292 list_of_class_files = foo.Java('build', source=sourceFiles)
293 resources = ['build/com/resource/resource1.txt', 'build/com/resource/resource2.txt']
294 for resource in resources:
296 resource, list_of_class_files, Copy(resource, resource.replace('build', 'src'))
298 contents = [list_of_class_files, resources]
299 foo.Jar(target='lists', source=contents + ['test/MANIFEST.mf'], JARCHDIR='build')
300 foo.Command("listsTest", [], Mkdir("listsTest"))
302 'listsTest/src/com/javasource/JavaFile3.java',
304 foo['JAR'] + ' xvf ../lists.jar',
309 test
.write(['listOfLists', 'src', 'com', 'javasource', 'JavaFile1.java'], """\
310 package com.javasource;
312 public class JavaFile1
314 public static void main(String[] args)
321 test
.write(['listOfLists', 'src', 'com', 'javasource', 'JavaFile2.java'], """\
322 package com.javasource;
324 public class JavaFile2
326 public static void main(String[] args)
333 test
.write(['listOfLists', 'src', 'com', 'javasource', 'JavaFile3.java'], """\
334 package com.javasource;
336 public class JavaFile3
338 public static void main(String[] args)
345 test
.write(['manifest_dir','MANIFEST.mf'],
346 """Manifest-Version: 1.0
350 test
.write(['listOfLists', 'src', 'com', 'resource', 'resource1.txt'], """\
351 this is a resource file
354 test
.write(['listOfLists', 'src', 'com', 'resource', 'resource2.txt'], """\
355 this is another resource file
359 test
.run(chdir
='listOfLists')
361 #test single target jar
362 test
.must_exist(['listOfLists','lists.jar'])
364 # make sure there are class in the jar
365 test
.must_exist(['listOfLists', 'listsTest', 'com', 'javasource', 'JavaFile1.class'])
366 test
.must_exist(['listOfLists', 'listsTest', 'com', 'javasource', 'JavaFile2.class'])
367 test
.must_exist(['listOfLists', 'listsTest', 'com', 'javasource', 'JavaFile3.class'])
368 test
.must_exist(['listOfLists', 'listsTest', 'com', 'resource', 'resource1.txt'])
369 test
.must_exist(['listOfLists', 'listsTest', 'com', 'resource', 'resource2.txt'])
370 test
.must_exist(['listOfLists', 'listsTest', 'META-INF', 'MANIFEST.MF'])
371 test
.must_contain(['listOfLists', 'listsTest', 'META-INF', 'MANIFEST.MF'], b
"MyManifestTest: Test" )
374 # test different style of passing in dirs
376 # make some directories to test in
380 ['testdir3', 'com', 'sub'],
381 ['testdir3', 'com', 'sub', 'foo'],
382 ['testdir3', 'com', 'sub', 'bar'],
385 # Create the jars then extract them back to check contents
386 test
.write(['testdir3', 'SConstruct'], """
387 DefaultEnvironment(tools=[])
390 foo_cls = foo.Java(target='classes', source='com/sub/foo')
391 foo_res = 'classes/com/sub/foo/NonJava.txt'
392 foo_res_src = 'com/sub/foo/NonJava.txt'
393 foo.Command(foo_res, foo_cls, Copy(foo_res, foo_res_src))
394 foo.Jar(target='foo', source='classes/com/sub/foo', JARCHDIR='classes')
395 foo.Command("fooTest", 'foo.jar', Mkdir("fooTest"))
396 foo.Command('doesnt_exist1', "fooTest", foo['JAR'] + ' xvf ../foo.jar', chdir='fooTest')
399 bar_cls = bar.Java(target='classes', source='com/sub/bar')
400 bar_res = 'classes/com/sub/bar/NonJava.txt'
401 bar_res_src = 'com/sub/bar/NonJava.txt'
402 bar.Command(bar_res, bar_cls, Copy(bar_res, bar_res_src))
403 bar.Jar(target='bar', source=Dir('classes/com/sub/bar'), JARCHDIR='classes')
404 bar.Command("barTest", 'bar.jar', Mkdir("barTest"))
405 bar.Command('doesnt_exist2', 'barTest', bar['JAR'] + ' xvf ../bar.jar', chdir='barTest')
408 test
.write(['testdir3', 'com', 'sub', 'foo', 'Example1.java'], """\
411 public class Example1
414 public static void main(String[] args)
422 test
.write(['testdir3', 'com', 'sub', 'foo', 'Example2.java'], """\
425 public class Example2
428 public static void main(String[] args)
436 test
.write(['testdir3', 'com', 'sub', 'foo', 'Example3.java'], """\
439 public class Example3
442 public static void main(String[] args)
450 test
.write(['testdir3', 'com', 'sub', 'foo', 'NonJava.txt'], """\
454 test
.write(['testdir3', 'com', 'sub', 'bar', 'Example4.java'], """\
457 public class Example4
460 public static void main(String[] args)
468 test
.write(['testdir3', 'com', 'sub', 'bar', 'Example5.java'], """\
471 public class Example5
474 public static void main(String[] args)
482 test
.write(['testdir3', 'com', 'sub', 'bar', 'Example6.java'], """\
485 public class Example6
488 public static void main(String[] args)
496 test
.write(['testdir3', 'com', 'sub', 'bar', 'NonJava.txt'], """\
500 test
.run(chdir
='testdir3')
502 # check the output and make sure the java files got converted to classes
504 # make sure there are class in the jar
505 test
.must_exist(['testdir3','foo.jar'])
506 test
.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example1.class'])
507 test
.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example2.class'])
508 test
.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example3.class'])
509 # TODO: determine expected behavior with resource files, should they be
510 # automatically copied in or specified in seperate commands
511 test
.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'NonJava.txt'])
513 # make sure both jars got createds
514 test
.must_exist(['testdir3','bar.jar'])
515 test
.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example4.class'])
516 test
.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example5.class'])
517 test
.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example6.class'])
518 # TODO: determine expected behavior with resource files, should they be
519 # automatically copied in or specified in seperate commands
520 test
.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'NonJava.txt'])
526 # indent-tabs-mode:nil
528 # vim: set expandtab tabstop=4 shiftwidth=4: