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__"
32 python = TestSCons.python
34 test = TestSCons.TestSCons()
38 test.write('myjavac.py', r"""
45 elif a == '-sourcepath':
51 infile = open(file, 'rb')
52 outfile = open(file[:-5] + '.class', 'wb')
53 for l in infile.readlines():
54 if l[:9] != '/*javac*/':
59 test.write('SConstruct', """
60 env = Environment(tools = ['javac'],
61 JAVAC = r'%s myjavac.py')
62 env.Java(target = '.', source = '.')
65 test.write('test1.java', """\
71 test.run(arguments = '.', stderr = None)
73 test.must_match('test1.class', "test1.java\nline 3\n")
75 if os.path.normcase('.java') == os.path.normcase('.JAVA'):
77 test.write('SConstruct', """\
78 env = Environment(tools = ['javac'],
79 JAVAC = r'%s myjavac.py')
80 env.Java(target = '.', source = '.')
83 test.write('test2.JAVA', """\
89 test.run(arguments = '.', stderr = None)
91 test.must_match('test2.class', "test2.JAVA\nline 3\n")
97 if test.detect_tool('javac', ENV=ENV):
98 where_javac = test.detect('JAVAC', 'javac', ENV=ENV)
100 where_javac = test.where_is('javac')
102 test.skip_test("Could not find Java javac, skipping test(s).\n")
106 test.write("wrapper.py", """\
110 open('%s', 'ab').write("wrapper.py %%s\\n" %% string.join(sys.argv[1:]))
111 os.system(string.join(sys.argv[1:], " "))
112 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
114 test.write('SConstruct', """
115 foo = Environment(tools = ['javac'],
117 javac = foo.Dictionary('JAVAC')
118 bar = foo.Copy(JAVAC = r'%s wrapper.py ' + javac)
119 foo.Java(target = 'class1', source = 'com/sub/foo')
120 bar.Java(target = 'class2', source = 'com/sub/bar')
121 foo.Java(target = 'class3', source = ['src1', 'src2'])
122 """ % (where_javac, python))
126 ['com', 'sub', 'foo'],
127 ['com', 'sub', 'bar'],
131 test.write(['com', 'sub', 'foo', 'Example1.java'], """\
134 public class Example1
137 public static void main(String[] args)
145 test.write(['com', 'sub', 'foo', 'Example2.java'], """\
148 public class Example2
151 public static void main(String[] args)
159 test.write(['com', 'sub', 'foo', 'Example3.java'], """\
162 public class Example3
165 public static void main(String[] args)
173 test.write(['com', 'sub', 'bar', 'Example4.java'], """\
176 public class Example4
179 public static void main(String[] args)
187 test.write(['com', 'sub', 'bar', 'Example5.java'], """\
190 public class Example5
193 public static void main(String[] args)
201 test.write(['com', 'sub', 'bar', 'Example6.java'], """\
204 public class Example6
207 public static void main(String[] args)
215 test.write(['src1', 'Example7.java'], """\
216 public class Example7
219 public static void main(String[] args)
227 # Acid-test file for parsing inner Java classes, courtesy Chad Austin.
228 test.write(['src2', 'Test.java'], """\
233 public void execute();
242 public void execute() {
243 System.out.println("In Inner");
247 String s1 = "class A";
248 String s2 = "new Listener() { }";
250 /* new Listener() { } */
253 public static void main(String[] args) {
259 public void execute() {
260 use(new Listener( ) {
261 public void execute() {
262 System.out.println("Inside execute()");
271 void use(Listener l) {
279 public void execute() {
286 test.run(arguments = '.')
288 test.must_match('wrapper.out', "wrapper.py %s -d class2 -sourcepath com/sub/bar com/sub/bar/Example4.java com/sub/bar/Example5.java com/sub/bar/Example6.java\n" % where_javac)
290 test.must_exist(test.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'))
291 test.must_exist(test.workpath('class1', 'com', 'other', 'Example2.class'))
292 test.must_exist(test.workpath('class1', 'com', 'sub', 'foo', 'Example3.class'))
294 test.must_exist(test.workpath('class2', 'com', 'sub', 'bar', 'Example4.class'))
295 test.must_exist(test.workpath('class2', 'com', 'other', 'Example5.class'))
296 test.must_exist(test.workpath('class2', 'com', 'sub', 'bar', 'Example6.class'))
298 test.must_exist(test.workpath('class3', 'Example7.class'))
300 test.must_exist(test.workpath('class3', 'Empty.class'))
301 test.must_exist(test.workpath('class3', 'Listener.class'))
302 test.must_exist(test.workpath('class3', 'Private.class'))
303 test.must_exist(test.workpath('class3', 'Private$1.class'))
304 test.must_exist(test.workpath('class3', 'Test.class'))
305 test.must_exist(test.workpath('class3', 'Test$1.class'))
306 test.must_exist(test.workpath('class3', 'Test$2.class'))
307 test.must_exist(test.workpath('class3', 'Test$3.class'))
308 test.must_exist(test.workpath('class3', 'Test$Inner.class'))
310 test.up_to_date(arguments = '.')