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.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
33 _python_ = TestSCons._python_
35 test = TestSCons.TestSCons()
37 test.write('myjar.py', r"""
48 outfile = open(out, 'wb')
50 infile = open(file, 'rb')
51 for l in infile.readlines():
52 if l[:7] != '/*jar*/':
57 test.write('SConstruct', """
58 env = Environment(tools = ['jar'],
59 JAR = r'%(_python_)s myjar.py')
60 env.Jar(target = 'test1.jar', source = 'test1.class')
63 test.write('test1.class', """\
69 test.run(arguments = '.', stderr = None)
71 test.must_match('test1.jar', "test1.class\nline 3\n")
73 if os.path.normcase('.class') == os.path.normcase('.CLASS'):
75 test.write('SConstruct', """
76 env = Environment(tools = ['jar'],
77 JAR = r'%(_python_)s myjar.py')
78 env.Jar(target = 'test2.jar', source = 'test2.CLASS')
81 test.write('test2.CLASS', """\
87 test.run(arguments = '.', stderr = None)
89 test.must_match('test2.jar', "test2.CLASS\nline 3\n")
91 test.write('myjar2.py', r"""
94 f=open(sys.argv[2], 'wb')
95 f.write(string.join(sys.argv[1:]))
101 test.write('SConstruct', """
102 env = Environment(tools = ['jar'],
103 JAR = r'%(_python_)s myjar2.py',
105 env.Jar(target = 'classes.jar', source = [ 'testdir/bar.class',
111 test.subdir('testdir')
112 test.write([ 'testdir', 'bar.class' ], 'foo')
114 """Manifest-Version : 1.0
119 test.run(arguments='classes.jar')
120 test.must_match('classes.jar',
121 'cvfm classes.jar foo.mf -C testdir bar.class\n')
123 ENV = test.java_ENV()
125 if test.detect_tool('javac', ENV=ENV):
126 where_javac = test.detect('JAVAC', 'javac', ENV=ENV)
128 where_javac = test.where_is('javac')
130 test.skip_test("Could not find Java javac, skipping test(s).\n")
132 if test.detect_tool('jar', ENV=ENV):
133 where_jar = test.detect('JAR', 'jar', ENV=ENV)
135 where_jar = test.where_is('jar')
137 test.skip_test("Could not find Java jar, skipping test(s).\n")
140 test.write("wrapper.py", """\
144 open('%s', 'ab').write("wrapper.py %%s\\n" %% string.join(sys.argv[1:]))
145 os.system(string.join(sys.argv[1:], " "))
146 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
148 test.write('SConstruct', """
149 foo = Environment(tools = ['javac', 'jar'],
150 JAVAC = r'%(where_javac)s',
151 JAR = r'%(where_jar)s')
152 jar = foo.Dictionary('JAR')
153 bar = foo.Clone(JAR = r'%(_python_)s wrapper.py ' + jar)
154 foo.Java(target = 'classes', source = 'com/sub/foo')
155 bar.Java(target = 'classes', source = 'com/sub/bar')
156 foo.Jar(target = 'foo', source = 'classes/com/sub/foo')
157 bar.Jar(target = 'bar', source = 'classes/com/sub/bar')
162 ['com', 'sub', 'foo'],
163 ['com', 'sub', 'bar'])
165 test.write(['com', 'sub', 'foo', 'Example1.java'], """\
168 public class Example1
171 public static void main(String[] args)
179 test.write(['com', 'sub', 'foo', 'Example2.java'], """\
182 public class Example2
185 public static void main(String[] args)
193 test.write(['com', 'sub', 'foo', 'Example3.java'], """\
196 public class Example3
199 public static void main(String[] args)
207 test.write(['com', 'sub', 'bar', 'Example4.java'], """\
210 public class Example4
213 public static void main(String[] args)
221 test.write(['com', 'sub', 'bar', 'Example5.java'], """\
224 public class Example5
227 public static void main(String[] args)
235 test.write(['com', 'sub', 'bar', 'Example6.java'], """\
238 public class Example6
241 public static void main(String[] args)
249 test.run(arguments = '.')
251 expected_wrapper_out = "wrapper.py %(where_jar)s cf bar.jar classes/com/sub/bar\n"
252 expected_wrapper_out = string.replace(expected_wrapper_out, '/', os.sep)
253 test.must_match('wrapper.out',
254 expected_wrapper_out % locals())
256 test.must_exist('foo.jar')
257 test.must_exist('bar.jar')
259 test.up_to_date(arguments = '.')