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()
36 test.write('myjavah.py', r"""
45 outfile = open(args[1], 'wb')
47 elif a == '-classpath':
49 elif a == '-sourcepath':
55 infile = open(file, 'rb')
56 for l in infile.readlines():
57 if l[:9] != '/*javah*/':
62 test.write('SConstruct', """
63 env = Environment(tools = ['javah'],
64 JAVAH = r'%s myjavah.py')
65 env.JavaH(target = File('test1.h'), source = 'test1.java')
68 test.write('test1.java', """\
74 test.run(arguments = '.', stderr = None)
76 test.must_match('test1.h', "test1.java\nline 3\n")
78 if os.path.normcase('.java') == os.path.normcase('.JAVA'):
80 test.write('SConstruct', """\
81 env = Environment(tools = ['javah'],
82 JAVAH = r'%s myjavah.py')
83 env.JavaH(target = File('test2.h'), source = 'test2.JAVA')
86 test.write('test2.JAVA', """\
92 test.run(arguments = '.', stderr = None)
94 test.must_match('test2.h', "test2.JAVA\nline 3\n")
97 if test.detect_tool('javac'):
98 where_javac = test.detect('JAVAC', 'javac')
100 import SCons.Environment
101 env = SCons.Environment.Environment()
102 where_javac = env.WhereIs('javac', os.environ['PATH'])
104 where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin')
106 print "Could not find Java javac, skipping test(s)."
109 if test.detect_tool('javah'):
110 where_javah = test.detect('JAVAH', 'javah')
112 import SCons.Environment
113 env = SCons.Environment.Environment()
114 where_javah = env.WhereIs('javah', os.environ['PATH'])
116 where_javah = env.WhereIs('javah', '/usr/local/j2sdk1.3.1/bin')
118 print "Could not find Java javah, skipping test(s)."
123 test.write("wrapper.py", """\
127 open('%s', 'ab').write("wrapper.py %%s\\n" %% string.join(sys.argv[1:]))
128 os.system(string.join(sys.argv[1:], " "))
129 """ % string.replace(test.workpath('wrapper.out'), '\\', '\\\\'))
131 test.write('SConstruct', """
132 foo = Environment(tools = ['javac', 'javah'],
133 JAVAC = '%(where_javac)s',
134 JAVAH = '%(where_javah)s')
135 javah = foo.Dictionary('JAVAH')
136 bar = foo.Copy(JAVAH = r'%(python)s wrapper.py ' + javah)
137 foo.Java(target = 'class1', source = 'com/sub/foo')
138 bar_classes = bar.Java(target = 'class2', source = 'com/sub/bar')
139 foo_classes = foo.Java(target = 'class3', source = 'src')
140 foo.JavaH(target = 'outdir1',
141 source = ['class1/com/sub/foo/Example1.class',
142 'class1/com/other/Example2',
143 'class1/com/sub/foo/Example3'],
144 JAVACLASSDIR = 'class1')
145 bar.JavaH(target = 'outdir2', source = bar_classes)
146 foo.JavaH(target = File('output.h'), source = foo_classes)
147 foo.Install('class4/com/sub/foo', 'class1/com/sub/foo/Example1.class')
148 foo.JavaH(target = 'outdir4',
149 source = ['class4/com/sub/foo/Example1.class'],
150 JAVACLASSDIR = 'class4')
155 ['com', 'sub', 'foo'],
156 ['com', 'sub', 'bar'],
159 test.write(['com', 'sub', 'foo', 'Example1.java'], """\
162 public class Example1
165 public static void main(String[] args)
173 test.write(['com', 'sub', 'foo', 'Example2.java'], """\
176 public class Example2
179 public static void main(String[] args)
187 test.write(['com', 'sub', 'foo', 'Example3.java'], """\
190 public class Example3
193 public static void main(String[] args)
201 test.write(['com', 'sub', 'bar', 'Example4.java'], """\
204 public class Example4
207 public static void main(String[] args)
215 test.write(['com', 'sub', 'bar', 'Example5.java'], """\
218 public class Example5
221 public static void main(String[] args)
229 test.write(['com', 'sub', 'bar', 'Example6.java'], """\
232 public class Example6
235 public static void main(String[] args)
243 test.write(['src', 'Test.java'], """\
248 public void execute();
257 public void execute() {
258 System.out.println("In Inner");
262 String s1 = "class A";
263 String s2 = "new Listener() { }";
265 /* new Listener() { } */
268 public static void main(String[] args) {
274 public void execute() {
275 use(new Listener( ) {
276 public void execute() {
277 System.out.println("Inside execute()");
286 void use(Listener l) {
294 public void execute() {
301 test.run(arguments = '.')
303 test.fail_test(test.read('wrapper.out') != "wrapper.py %(where_javah)s -d outdir2 -classpath class2 com.sub.bar.Example4 com.other.Example5 com.sub.bar.Example6\n" % locals())
305 test.must_exist(['outdir1', 'com_sub_foo_Example1.h'])
306 test.must_exist(['outdir1', 'com_other_Example2.h'])
307 test.must_exist(['outdir1', 'com_sub_foo_Example3.h'])
309 test.must_exist(['outdir2', 'com_sub_bar_Example4.h'])
310 test.must_exist(['outdir2', 'com_other_Example5.h'])
311 test.must_exist(['outdir2', 'com_sub_bar_Example6.h'])
313 test.up_to_date(arguments = '.')