diff options
author | Steven Knight <knight@baldmt.com> | 2003-04-06 15:40:59 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2003-04-06 15:40:59 (GMT) |
commit | b967a4a50e7ad193583412bc5a585acde1fddbe7 (patch) | |
tree | f6f071523c90ec14c5835e69fe9272dc02b90d55 /test/JAR.py | |
parent | a2b9b257fec5cc6ec8a7a14ede42e8ae0c55ba98 (diff) | |
download | SCons-b967a4a50e7ad193583412bc5a585acde1fddbe7.zip SCons-b967a4a50e7ad193583412bc5a585acde1fddbe7.tar.gz SCons-b967a4a50e7ad193583412bc5a585acde1fddbe7.tar.bz2 |
Java!
Diffstat (limited to 'test/JAR.py')
-rw-r--r-- | test/JAR.py | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/test/JAR.py b/test/JAR.py new file mode 100644 index 0000000..f5b3048 --- /dev/null +++ b/test/JAR.py @@ -0,0 +1,212 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os +import string +import sys +import TestSCons + +python = TestSCons.python + +test = TestSCons.TestSCons() + + +test.write('myjar.py', r""" +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a == 'cf': + out = args[1] + args = args[1:] + else: + break + args = args[1:] +outfile = open(out, 'wb') +for file in args: + infile = open(file, 'rb') + for l in infile.readlines(): + if l[:7] != '/*jar*/': + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools = ['jar'], + JAR = r'%s myjar.py') +env.Jar(target = 'test1.jar', source = 'test1.class') +""" % (python)) + +test.write('test1.class', """\ +test1.class +/*jar*/ +line 3 +""") + +test.run(arguments = '.', stderr = None) + +test.fail_test(test.read('test1.jar') != "test1.class\nline 3\n") + +if os.path.normcase('.class') == os.path.normcase('.CLASS'): + + test.write('SConstruct', """ +env = Environment(tools = ['jar'], + JAR = r'%s myjar.py') +env.Program(target = 'test2.jar', source = 'test2.CLASS') +""" % (python)) + + test.write('test2.CLASS', """\ +test2.CLASS +/*jar*/ +line 3 +""") + + test.run(arguments = '.', stderr = None) + + test.fail_test(test.read('test2' + _exe) != "test2.CLASS\nline 3\n") + + + + +test.write("wrapper.py", """\ +import os +import string +import sys +open('%s', 'ab').write("wrapper.py %%s\\n" %% string.join(sys.argv[1:])) +os.system(string.join(sys.argv[1:], " ")) +""" % string.replace(test.workpath('wrapper.out'), '\\', '\\\\')) + +test.write('SConstruct', """ +foo = Environment(tools = ['javac', 'jar'], + JAVAC = '/usr/local/j2sdk1.3.1/bin/javac', + JAR = '/usr/local/j2sdk1.3.1/bin/jar') +jar = foo.Dictionary('JAR') +bar = foo.Copy(JAR = r'%s wrapper.py ' + jar) +foo.Java(target = 'classes', source = 'com/sub/foo') +bar.Java(target = 'classes', source = 'com/sub/bar') +foo.Jar(target = 'foo', source = 'classes/com/sub/foo') +bar.Jar(target = 'bar', source = 'classes/com/sub/bar') +""" % python) + +test.subdir('com', + ['com', 'sub'], + ['com', 'sub', 'foo'], + ['com', 'sub', 'bar']) + +test.write(['com', 'sub', 'foo', 'Example1.java'], """\ +package com.sub.foo; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example2.java'], """\ +package com.sub.foo; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example3.java'], """\ +package com.sub.foo; + +public class Example3 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example4.java'], """\ +package com.sub.bar; + +public class Example4 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example5.java'], """\ +package com.sub.bar; + +public class Example5 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example6.java'], """\ +package com.sub.bar; + +public class Example6 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.run(arguments = '.') + +test.fail_test(test.read('wrapper.out') != "wrapper.py /usr/local/j2sdk1.3.1/bin/jar cf bar.jar classes/com/sub/bar\n") + +test.fail_test(not os.path.exists(test.workpath('foo.jar'))) +test.fail_test(not os.path.exists(test.workpath('bar.jar'))) + +test.up_to_date(arguments = '.') + +test.pass_test() |