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__"
31 _python_ = TestSCons._python_
33 test = TestSCons.TestSCons()
35 test.write('myjar.py', r"""
46 outfile = open(out, 'wb')
48 infile = open(file, 'rb')
49 for l in infile.readlines():
50 if l[:7] != '/*jar*/':
55 test.write('SConstruct', """
56 env = Environment(tools = ['jar'],
57 JAR = r'%(_python_)s myjar.py')
58 env.Jar(target = 'test1.jar', source = 'test1.class')
61 test.write('test1.class', """\
67 test.run(arguments = '.', stderr = None)
69 test.must_match('test1.jar', "test1.class\nline 3\n")
71 if os.path.normcase('.class') == os.path.normcase('.CLASS'):
73 test.write('SConstruct', """
74 env = Environment(tools = ['jar'],
75 JAR = r'%(_python_)s myjar.py')
76 env.Jar(target = 'test2.jar', source = 'test2.CLASS')
79 test.write('test2.CLASS', """\
85 test.run(arguments = '.', stderr = None)
87 test.must_match('test2.jar', "test2.CLASS\nline 3\n")
89 test.write('myjar2.py', r"""
91 f=open(sys.argv[2], 'wb')
92 f.write(" ".join(sys.argv[1:]))
98 test.write('SConstruct', """
99 env = Environment(tools = ['jar'],
100 JAR = r'%(_python_)s myjar2.py',
102 env.Jar(target = 'classes.jar', source = [ 'testdir/bar.class',
108 test.subdir('testdir')
109 test.write([ 'testdir', 'bar.class' ], 'foo')
111 """Manifest-Version : 1.0
116 test.run(arguments='classes.jar')
117 test.must_match('classes.jar',
118 'cvfm classes.jar foo.mf -C testdir bar.class\n')
122 where_javac, java_version = test.java_where_javac()
123 where_jar = test.java_where_jar()
127 test.write("wrapper.py", """\
130 open('%s', 'ab').write("wrapper.py %%s\\n" %% " ".join(sys.argv[1:]))
131 os.system(" ".join(sys.argv[1:]))
132 """ % test.workpath('wrapper.out').replace('\\', '\\\\'))
134 test.write('SConstruct', """
135 foo = Environment(tools = ['javac', 'jar'],
136 JAVAC = r'%(where_javac)s',
137 JAR = r'%(where_jar)s')
138 jar = foo.Dictionary('JAR')
139 bar = foo.Clone(JAR = r'%(_python_)s wrapper.py ' + jar)
140 foo.Java(target = 'classes', source = 'com/sub/foo')
141 bar.Java(target = 'classes', source = 'com/sub/bar')
142 foo.Jar(target = 'foo', source = 'classes/com/sub/foo')
143 bar.Jar(target = 'bar', source = 'classes/com/sub/bar')
148 ['com', 'sub', 'foo'],
149 ['com', 'sub', 'bar'])
151 test.write(['com', 'sub', 'foo', 'Example1.java'], """\
154 public class Example1
157 public static void main(String[] args)
165 test.write(['com', 'sub', 'foo', 'Example2.java'], """\
168 public class Example2
171 public static void main(String[] args)
179 test.write(['com', 'sub', 'foo', 'Example3.java'], """\
182 public class Example3
185 public static void main(String[] args)
193 test.write(['com', 'sub', 'bar', 'Example4.java'], """\
196 public class Example4
199 public static void main(String[] args)
207 test.write(['com', 'sub', 'bar', 'Example5.java'], """\
210 public class Example5
213 public static void main(String[] args)
221 test.write(['com', 'sub', 'bar', 'Example6.java'], """\
224 public class Example6
227 public static void main(String[] args)
235 test.run(arguments = '.')
237 expected_wrapper_out = "wrapper.py %(where_jar)s cf bar.jar classes/com/sub/bar\n"
238 expected_wrapper_out = expected_wrapper_out.replace('/', os.sep)
239 test.must_match('wrapper.out',
240 expected_wrapper_out % locals())
242 test.must_exist('foo.jar')
243 test.must_exist('bar.jar')
245 test.up_to_date(arguments = '.')
251 # indent-tabs-mode:nil
253 # vim: set expandtab tabstop=4 shiftwidth=4: