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")
94 if test.detect_tool('javac'):
95 where_javac = test.detect('JAVAC', 'javac')
97 import SCons.Environment
98 env = SCons.Environment.Environment()
99 where_javac = env.WhereIs('javac', os.environ['PATH'])
101 where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin')
103 print "Could not find Java, skipping test(s)."
108 test.write("wrapper.py", """\
112 open('%s', 'ab').write("wrapper.py %%s\\n" %% string.join(sys.argv[1:]))
113 os.system(string.join(sys.argv[1:], " "))
114 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
116 test.write('SConstruct', """
117 foo = Environment(tools = ['javac'],
119 javac = foo.Dictionary('JAVAC')
120 bar = foo.Copy(JAVAC = r'%s wrapper.py ' + javac)
121 foo.Java(target = 'class1', source = 'com/sub/foo')
122 bar.Java(target = 'class2', source = 'com/sub/bar')
123 foo.Java(target = 'class3', source = ['src1', 'src2'])
124 """ % (where_javac, python))
128 ['com', 'sub', 'foo'],
129 ['com', 'sub', 'bar'],
133 test.write(['com', 'sub', 'foo', 'Example1.java'], """\
136 public class Example1
139 public static void main(String[] args)
147 test.write(['com', 'sub', 'foo', 'Example2.java'], """\
150 public class Example2
153 public static void main(String[] args)
161 test.write(['com', 'sub', 'foo', 'Example3.java'], """\
164 public class Example3
167 public static void main(String[] args)
175 test.write(['com', 'sub', 'bar', 'Example4.java'], """\
178 public class Example4
181 public static void main(String[] args)
189 test.write(['com', 'sub', 'bar', 'Example5.java'], """\
192 public class Example5
195 public static void main(String[] args)
203 test.write(['com', 'sub', 'bar', 'Example6.java'], """\
206 public class Example6
209 public static void main(String[] args)
217 test.write(['src1', 'Example7.java'], """\
218 public class Example7
221 public static void main(String[] args)
229 # Acid-test file for parsing inner Java classes, courtesy Chad Austin.
230 test.write(['src2', 'Test.java'], """\
235 public void execute();
244 public void execute() {
245 System.out.println("In Inner");
249 String s1 = "class A";
250 String s2 = "new Listener() { }";
252 /* new Listener() { } */
255 public static void main(String[] args) {
261 public void execute() {
262 use(new Listener( ) {
263 public void execute() {
264 System.out.println("Inside execute()");
273 void use(Listener l) {
281 public void execute() {
288 test.run(arguments = '.')
290 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)
292 test.must_exist(test.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'))
293 test.must_exist(test.workpath('class1', 'com', 'other', 'Example2.class'))
294 test.must_exist(test.workpath('class1', 'com', 'sub', 'foo', 'Example3.class'))
296 test.must_exist(test.workpath('class2', 'com', 'sub', 'bar', 'Example4.class'))
297 test.must_exist(test.workpath('class2', 'com', 'other', 'Example5.class'))
298 test.must_exist(test.workpath('class2', 'com', 'sub', 'bar', 'Example6.class'))
300 test.must_exist(test.workpath('class3', 'Example7.class'))
302 test.must_exist(test.workpath('class3', 'Empty.class'))
303 test.must_exist(test.workpath('class3', 'Listener.class'))
304 test.must_exist(test.workpath('class3', 'Private.class'))
305 test.must_exist(test.workpath('class3', 'Private$1.class'))
306 test.must_exist(test.workpath('class3', 'Test.class'))
307 test.must_exist(test.workpath('class3', 'Test$1.class'))
308 test.must_exist(test.workpath('class3', 'Test$2.class'))
309 test.must_exist(test.workpath('class3', 'Test$3.class'))
310 test.must_exist(test.workpath('class3', 'Test$Inner.class'))
312 test.up_to_date(arguments = '.')