diff options
| author | William Deegan <bill@baddogconsulting.com> | 2015-09-21 17:03:12 (GMT) |
|---|---|---|
| committer | William Deegan <bill@baddogconsulting.com> | 2015-09-21 17:03:12 (GMT) |
| commit | 0941093e0e5a030faa49968457638a3a6aee7ad8 (patch) | |
| tree | 6d33513c14eb6eac0531dd050de0ecca4c39bd79 /test/Java | |
| download | SCons-2.4.0.zip SCons-2.4.0.tar.gz SCons-2.4.0.tar.bz2 | |
release 2.4.02.4.0
Diffstat (limited to 'test/Java')
29 files changed, 4748 insertions, 0 deletions
diff --git a/test/Java/DerivedSourceTest.py b/test/Java/DerivedSourceTest.py new file mode 100644 index 0000000..7f80595 --- /dev/null +++ b/test/Java/DerivedSourceTest.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test of javac.py when building java code from derived sources. + +Original issue definition: +Java emitter for derived sources outputs bogus class files. + +Repeatable with any N-tier, with N > 1, Java derived-source builds where +any of the following conditions are meet: +1. The java class does not belong to the root package. +2. A java source (*.java) creates N targets (*.class) where N > 1. +""" + +import os +import TestSCons +import SCons.Node.FS +import SCons.Defaults + +SCons.Defaults.DefaultEnvironment(tools = []) + +test = TestSCons.TestSCons() + +# This test is known to fail as of July 2014; see Tigris issue 1771 and issue 2931. +# Once the underlying issue is corrected, this test should be re-enabled. +test.skip_test('Skipping derived-source test until issue 1771 is fixed.\n') + +# No result if tools not available +test.no_result( condition=(test.where_is( 'javac' ) is None) ) +test.no_result( condition=(test.where_is( 'jar' ) is None) ) + +test.write( + ['Sample.java'], +""" +// Condition 1: class does not exist in the root package. +package org.sample; + +public class Sample { + // Condition 2: inner class definition causes javac to create + // a second class file. + enum InnerEnum { + stuff, + and, + things + } +} +""" +) + +test.write( + ['SConstruct'], +""" +import os + +env = Environment( + tools = [ + 'javac', + 'jar', + ] +) + +env.Command( + os.path.join( 'org', 'sample', 'Sample.java' ), + 'Sample.java', + Copy( + '$TARGET', + '$SOURCE' + ) +) + +# Copy operation makes the *.java file(s) under org derived-source. +env.Java( + 'build', + 'org' +) +""" +) + +expected = test.wrap_stdout( +build_str = +'''\ +Copy("org/sample/Sample.java", "Sample.java") +javac -d build -sourcepath org/sample org/sample/Sample.java ++-. + +-build + | +-build/org + | +-build/org/sample + | +-build/org/sample/Sample$InnerEnum.class + | +-org/sample/Sample.java + | +-build/org/sample/Sample.class + | +-org/sample/Sample.java + +-org + +-org/sample + +-org/sample/Sample.java +'''.replace( '/', os.sep ) +) + +test.run( arguments = '--tree=derived', stdout = expected ) + +test.up_to_date(arguments = '.') diff --git a/test/Java/JAR.py b/test/Java/JAR.py new file mode 100644 index 0000000..81664dc --- /dev/null +++ b/test/Java/JAR.py @@ -0,0 +1,253 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.write('myjar.py', r""" +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a == 'cf': + out = args[1] + args = args[1:] + else: + break + args = args[1:] +outfile = open(out, 'wb') +for file in args: + infile = open(file, 'rb') + for l in infile.readlines(): + if l[:7] != '/*jar*/': + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools = ['jar'], + JAR = r'%(_python_)s myjar.py') +env.Jar(target = 'test1.jar', source = 'test1.class') +""" % locals()) + +test.write('test1.class', """\ +test1.class +/*jar*/ +line 3 +""") + +test.run(arguments = '.', stderr = None) + +test.must_match('test1.jar', "test1.class\nline 3\n") + +if os.path.normcase('.class') == os.path.normcase('.CLASS'): + + test.write('SConstruct', """ +env = Environment(tools = ['jar'], + JAR = r'%(_python_)s myjar.py') +env.Jar(target = 'test2.jar', source = 'test2.CLASS') +""" % locals()) + + test.write('test2.CLASS', """\ +test2.CLASS +/*jar*/ +line 3 +""") + + test.run(arguments = '.', stderr = None) + + test.must_match('test2.jar', "test2.CLASS\nline 3\n") + +test.write('myjar2.py', r""" +import sys +f=open(sys.argv[2], 'wb') +f.write(" ".join(sys.argv[1:])) +f.write("\n") +f.close() +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools = ['jar'], + JAR = r'%(_python_)s myjar2.py', + JARFLAGS='cvf') +env.Jar(target = 'classes.jar', source = [ 'testdir/bar.class', + 'foo.mf' ], + TESTDIR='testdir', + JARCHDIR='$TESTDIR') +""" % locals()) + +test.subdir('testdir') +test.write([ 'testdir', 'bar.class' ], 'foo') +test.write('foo.mf', + """Manifest-Version : 1.0 + blah + blah + blah + """) +test.run(arguments='classes.jar') +test.must_match('classes.jar', + 'cvfm classes.jar foo.mf -C testdir bar.class\n') + + + +where_javac, java_version = test.java_where_javac() +where_jar = test.java_where_jar() + + + +test.write("wrapper.py", """\ +import os +import sys +open('%s', 'ab').write("wrapper.py %%s\\n" %% " ".join(sys.argv[1:])) +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + +test.write('SConstruct', """ +foo = Environment(tools = ['javac', 'jar'], + JAVAC = r'%(where_javac)s', + JAR = r'%(where_jar)s') +jar = foo.Dictionary('JAR') +bar = foo.Clone(JAR = r'%(_python_)s wrapper.py ' + jar) +foo.Java(target = 'classes', source = 'com/sub/foo') +bar.Java(target = 'classes', source = 'com/sub/bar') +foo.Jar(target = 'foo', source = 'classes/com/sub/foo') +bar.Jar(target = 'bar', source = 'classes/com/sub/bar') +""" % locals()) + +test.subdir('com', + ['com', 'sub'], + ['com', 'sub', 'foo'], + ['com', 'sub', 'bar']) + +test.write(['com', 'sub', 'foo', 'Example1.java'], """\ +package com.sub.foo; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example2.java'], """\ +package com.sub.foo; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example3.java'], """\ +package com.sub.foo; + +public class Example3 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example4.java'], """\ +package com.sub.bar; + +public class Example4 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example5.java'], """\ +package com.sub.bar; + +public class Example5 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example6.java'], """\ +package com.sub.bar; + +public class Example6 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.run(arguments = '.') + +expected_wrapper_out = "wrapper.py %(where_jar)s cf bar.jar classes/com/sub/bar\n" +expected_wrapper_out = expected_wrapper_out.replace('/', os.sep) +test.must_match('wrapper.out', + expected_wrapper_out % locals()) + +test.must_exist('foo.jar') +test.must_exist('bar.jar') + +test.up_to_date(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JARCHDIR.py b/test/Java/JARCHDIR.py new file mode 100644 index 0000000..d574fe7 --- /dev/null +++ b/test/Java/JARCHDIR.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test that when JARCHDIR that our command to create .jar files +correctly finds all the .class files (by putting -C in front +of each class file argument). + +Includes logic to make sure that expansions of $JARCHDIR that include +${TARGET} or ${SOURCE} work. +""" + +import os + +import TestSCons + +test = TestSCons.TestSCons() + +where_javac, java_version = test.java_where_javac() +where_jar = test.java_where_jar() + + + +test.write('SConstruct', """ +dir = 'dist' +env = Environment(tools = ['javac', 'jar'], + JAVAC = r'%(where_javac)s', + JAR = r'%(where_jar)s', + JARCHDIR = dir) +bin = env.Java(dir, Dir('./')) +jar = env.Jar(File('c.jar', dir), bin) + +# Make sure we handle class files with $ in them, such as typically +# created for inner classes. +env = env.Clone(JARCHDIR = '.') +inner = env.Jar('inner.jar', 'Inner$$Class.class') + +target_env = env.Clone(JARCHDIR = '${TARGET.dir}') +target_env.Jar('out/t.jar', 'in/t.class') + +source_env = env.Clone(JARCHDIR = '${SOURCE.dir}') +source_env.Jar('out/s.jar', 'in/s.class') + +Default(bin, jar, inner) +""" % locals()) + + + +test.subdir('in') + +test.write('a.java', """\ +package foo.bar; +public class a {} +""") + +test.write('b.java', """\ +package foo.bar; +public class b {} +""") + +test.write(['in', 's.class'], "s.class\n") + +# Okay, this is bogus, but we're going with it for testing purposes. +# If jar gets a command line like: +# +# jar cf out/t.jar -C out /tmp/tmpXYZZY/in/t.class +# +# Empirically, it doesn't seem to treat the absolute path name +# of the argument class file as an absolute path, but looks for +# "out/tmp/tmpXYZZY/in/t.class". SCons, however, still looks for it in +# the path name specified on the command line. To make this test work, +# we're going to just create the t.class file in both locations, and +# we can revisit this if someone actually tries to use ${TARGET.dir} +# in a real-life expansion. Right now, it at least makes sure things +# don't blow up (i.e., validates that we pass the right arguments to +# env.subst() in the code that handle jar). + +p = test.workpath('out') +for d in test.workpath('in').split(os.sep): + p = p + d + test.subdir(p) + p = p + os.sep + +test.write([p, 't.class'], "t.class\n") +test.write(['in', 't.class'], "t.class\n") + +test.write('Inner$Class.class', "Inner$Class.class\n") + +test.run(arguments = '.') + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JARCOM.py b/test/Java/JARCOM.py new file mode 100644 index 0000000..9d93ba5 --- /dev/null +++ b/test/Java/JARCOM.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test the ability to configure the $JARCOM construction variable. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myjar.py', r""" +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*jar*/\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(TOOLS = ['default', 'jar'], + JARCOM = r'%(_python_)s myjar.py $TARGET $SOURCES') +env.Jar(target = 'test1', source = ['file1.in', 'file2.in', 'file3.in']) +""" % locals()) + +test.write('file1.in', "file1.in\n/*jar*/\n") +test.write('file2.in', "file2.in\n/*jar*/\n") +test.write('file3.in', "file3.in\n/*jar*/\n") + +test.run() + +test.must_match('test1.jar', "file1.in\nfile2.in\nfile3.in\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JARCOMSTR.py b/test/Java/JARCOMSTR.py new file mode 100644 index 0000000..069587f --- /dev/null +++ b/test/Java/JARCOMSTR.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test that the $JARCOMSTR construction variable allows you to configure +the jar output. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myjar.py', r""" +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*jar*/\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(TOOLS = ['default', 'jar'], + JARCOM = r'%(_python_)s myjar.py $TARGET $SOURCES', + JARCOMSTR = "Jar'ing up $TARGET from $SOURCES") +env.Jar(target = 'test1', source = ['file1.in', 'file2.in', 'file3.in']) +""" % locals()) + +test.write('file1.in', "file1.in\n/*jar*/\n") +test.write('file2.in', "file2.in\n/*jar*/\n") +test.write('file3.in', "file3.in\n/*jar*/\n") + +test.run(stdout = test.wrap_stdout("""\ +Jar'ing up test1.jar from file1.in file2.in file3.in +""")) + +test.must_match('test1.jar', "file1.in\nfile2.in\nfile3.in\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JARFLAGS.py b/test/Java/JARFLAGS.py new file mode 100644 index 0000000..c0ae627 --- /dev/null +++ b/test/Java/JARFLAGS.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os + +import TestSCons + +test = TestSCons.TestSCons() + +test.subdir('src') + +where_javac, java_version = test.java_where_javac() +where_jar = test.java_where_jar() + + + +test.write('SConstruct', """ +env = Environment(tools = ['javac', 'jar'], + JAVAC = r'%(where_javac)s', + JAR = r'%(where_jar)s', + JARFLAGS = 'cvf') +env['JARFLAGS'] = 'cvf' +class_files = env.Java(target = 'classes', source = 'src') +env.Jar(target = 'test.jar', source = class_files) +""" % locals()) + +test.write(['src', 'Example1.java'], """\ +package src; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +expect = test.wrap_stdout("""\ +%(where_javac)s -d classes -sourcepath src src/Example1\.java +%(where_jar)s cvf test.jar -C classes src/Example1\.class +.* +adding: src/Example1\.class.* +""" % locals()) + +expect = expect.replace('/', os.sep) + +test.run(arguments = '.', + match=TestSCons.match_re_dotall, + stdout = expect) + +test.must_exist('test.jar') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JAVABOOTCLASSPATH.py b/test/Java/JAVABOOTCLASSPATH.py new file mode 100644 index 0000000..6913c6a --- /dev/null +++ b/test/Java/JAVABOOTCLASSPATH.py @@ -0,0 +1,100 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify that use of $JAVABOOTCLASSPATH sets the -bootclasspath option +on javac compilations. +""" + +import os + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +where_javac, java_version = test.java_where_javac() +where_javah = test.java_where_javah() + +test.write('SConstruct', """ +env = Environment(tools = ['javac', 'javah'], + JAVAC = r'%(where_javac)s', + JAVABOOTCLASSPATH = ['dir1', 'dir2']) +j1 = env.Java(target = 'class', source = 'com/Example1.java') +j2 = env.Java(target = 'class', source = 'com/Example2.java') +""" % locals()) + +test.subdir('com') + +test.write(['com', 'Example1.java'], """\ +package com; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'Example2.java'], """\ +package com; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +# Setting -bootclasspath messes with the Java runtime environment, so +# we'll just take the easy way out and examine the -n output to see if +# the expected option shows up on the command line. + +bootclasspath = os.pathsep.join(['dir1', 'dir2']) + +expect = """\ +%(where_javac)s -bootclasspath %(bootclasspath)s -d class -sourcepath com com/Example1.java +%(where_javac)s -bootclasspath %(bootclasspath)s -d class -sourcepath com com/Example2.java +""" % locals() + +test.run(arguments = '-Q -n .', stdout = expect) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JAVAC.py b/test/Java/JAVAC.py new file mode 100644 index 0000000..06b1969 --- /dev/null +++ b/test/Java/JAVAC.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test setting the JAVAC variable. +""" + +import os + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myjavac.py', r""" +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a == '-d': + args = args[1:] + elif a == '-sourcepath': + args = args[1:] + else: + break + args = args[1:] +for file in args: + infile = open(file, 'rb') + outfile = open(file[:-5] + '.class', 'wb') + for l in infile.readlines(): + if l[:9] != '/*javac*/': + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools = ['javac'], + JAVAC = r'%(_python_)s myjavac.py') +env.Java(target = '.', source = '.') +""" % locals()) + +test.write('test1.java', """\ +test1.java +/*javac*/ +line 3 +""") + +test.run(arguments = '.', stderr = None) + +test.must_match('test1.class', "test1.java\nline 3\n") + +if os.path.normcase('.java') == os.path.normcase('.JAVA'): + + test.write('SConstruct', """\ +env = Environment(tools = ['javac'], + JAVAC = r'%(_python_)s myjavac.py') +env.Java(target = '.', source = '.') +""" % locals()) + + test.write('test2.JAVA', """\ +test2.JAVA +/*javac*/ +line 3 +""") + + test.run(arguments = '.', stderr = None) + + test.must_match('test2.class', "test2.JAVA\nline 3\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JAVACCOM.py b/test/Java/JAVACCOM.py new file mode 100644 index 0000000..064feed --- /dev/null +++ b/test/Java/JAVACCOM.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test the ability to configure the $JAVACCOM construction variable. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.subdir('src') + + + +test.write('myjavac.py', r""" +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*javac*/\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(TOOLS = ['default', 'javac'], + JAVACCOM = r'%(_python_)s myjavac.py $TARGET $SOURCES') +env.Java(target = 'classes', source = 'src') +""" % locals()) + +test.write(['src', 'file1.java'], "file1.java\n/*javac*/\n") +test.write(['src', 'file2.java'], "file2.java\n/*javac*/\n") +test.write(['src', 'file3.java'], "file3.java\n/*javac*/\n") + +test.run() + +test.must_match(['classes', 'file1.class'], + "file1.java\nfile2.java\nfile3.java\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JAVACCOMSTR.py b/test/Java/JAVACCOMSTR.py new file mode 100644 index 0000000..6440283 --- /dev/null +++ b/test/Java/JAVACCOMSTR.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test that the $JAVACCOMSTR construction variable allows you to configure +the javac output. +""" + +import os.path + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.subdir('src') + + + +test.write('myjavac.py', r""" +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*javac*/\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(TOOLS = ['default', 'javac'], + JAVACCOM = r'%(_python_)s myjavac.py $TARGET $SOURCES', + JAVACCOMSTR = "Compiling class(es) $TARGET from $SOURCES") +env.Java(target = 'classes', source = 'src') +""" % locals()) + +test.write(['src', 'file1.java'], "file1.java\n/*javac*/\n") +test.write(['src', 'file2.java'], "file2.java\n/*javac*/\n") +test.write(['src', 'file3.java'], "file3.java\n/*javac*/\n") + +classes_file1_class = os.path.join('classes', 'file1.class') +src_file1_java= os.path.join('src', 'file1.java') +src_file2_java= os.path.join('src', 'file2.java') +src_file3_java= os.path.join('src', 'file3.java') + +test.run(stdout = test.wrap_stdout("""\ +Compiling class(es) %(classes_file1_class)s from %(src_file1_java)s %(src_file2_java)s %(src_file3_java)s +""" % locals())) + +test.must_match(['classes', 'file1.class'], + "file1.java\nfile2.java\nfile3.java\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JAVACFLAGS.py b/test/Java/JAVACFLAGS.py new file mode 100644 index 0000000..6afd1b9 --- /dev/null +++ b/test/Java/JAVACFLAGS.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os + +import TestSCons + +test = TestSCons.TestSCons() + +where_javac, java_version = test.java_where_javac() + +test.subdir('src') + +test.write('SConstruct', """ +env = Environment(tools = ['javac'], + JAVAC = r'%(where_javac)s', + JAVACFLAGS = '-O') +env.Java(target = 'classes', source = 'src') +""" % locals()) + +test.write(['src', 'Example1.java'], """\ +package src; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +expected_wrapper_out = "%(where_javac)s -O -d classes -sourcepath src src/Example1.java\n" +expected_wrapper_out = expected_wrapper_out.replace('/', os.sep) +test.run(arguments = '.', + stdout = test.wrap_stdout(expected_wrapper_out % locals())) + +test.must_exist(['classes', 'src', 'Example1.class']) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JAVACLASSPATH.py b/test/Java/JAVACLASSPATH.py new file mode 100644 index 0000000..bc3bb21 --- /dev/null +++ b/test/Java/JAVACLASSPATH.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify that use of $JAVASOURCEPATH allows finding Java .class +files in alternate locations by adding the -classpath option +to the javac command line. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +where_javac, java_version = test.java_where_javac() +where_javah = test.java_where_javah() + +test.write('SConstruct', """ +env = Environment(tools = ['javac', 'javah'], + JAVAC = r'%(where_javac)s', + JAVAH = r'%(where_javah)s') +j1 = env.Java(target = 'class1', source = 'com1/Example1.java') +j2 = env.Java(target = 'class2', source = 'com2/Example2.java') +env.JavaH(target = 'outdir', source = [j1, j2], JAVACLASSPATH = 'class2') +""" % locals()) + +test.subdir('com1', 'com2') + +test.write(['com1', 'Example1.java'], """\ +package com; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com2', 'Example2.java'], """\ +package com; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.run(arguments = '.') + +test.must_exist(['class1', 'com', 'Example1.class']) +test.must_exist(['class2', 'com', 'Example2.class']) + +test.must_exist(['outdir', 'com_Example1.h']) +test.must_exist(['outdir', 'com_Example2.h']) + +test.up_to_date(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JAVAH.py b/test/Java/JAVAH.py new file mode 100644 index 0000000..f7c9dcc --- /dev/null +++ b/test/Java/JAVAH.py @@ -0,0 +1,305 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.write('myjavah.py', r""" +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a == '-d': + outdir = args[1] + args = args[1:] + elif a == '-o': + outfile = open(args[1], 'wb') + args = args[1:] + elif a == '-classpath': + args = args[1:] + elif a == '-sourcepath': + args = args[1:] + else: + break + args = args[1:] +for file in args: + infile = open(file, 'rb') + for l in infile.readlines(): + if l[:9] != '/*javah*/': + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools = ['javah'], + JAVAH = r'%(_python_)s myjavah.py') +env.JavaH(target = File('test1.h'), source = 'test1.java') +""" % locals()) + +test.write('test1.java', """\ +test1.java +/*javah*/ +line 3 +""") + +test.run(arguments = '.', stderr = None) + +test.must_match('test1.h', "test1.java\nline 3\n") + +if os.path.normcase('.java') == os.path.normcase('.JAVA'): + + test.write('SConstruct', """\ +env = Environment(tools = ['javah'], + JAVAH = r'%(_python_)s myjavah.py') +env.JavaH(target = File('test2.h'), source = 'test2.JAVA') +""" % locals()) + + test.write('test2.JAVA', """\ +test2.JAVA +/*javah*/ +line 3 +""") + + test.run(arguments = '.', stderr = None) + + test.must_match('test2.h', "test2.JAVA\nline 3\n") + + + +where_javac, java_version = test.java_where_javac() +where_javah = test.java_where_javah() + +if java_version: + java_version = repr(java_version) + + + +test.write("wrapper.py", """\ +import os +import sys +open('%s', 'ab').write("wrapper.py %%s\\n" %% " ".join(sys.argv[1:])) +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + +test.write('SConstruct', """ +foo = Environment(tools = ['javac', 'javah', 'install'], + JAVAC = r'%(where_javac)s', + JAVAH = r'%(where_javah)s') +jv = %(java_version)s +if jv: + foo['JAVAVERSION'] = jv +javah = foo.Dictionary('JAVAH') +bar = foo.Clone(JAVAH = r'%(_python_)s wrapper.py ' + javah) +foo.Java(target = 'class1', source = 'com/sub/foo') +bar_classes = bar.Java(target = 'class2', source = 'com/sub/bar') +foo_classes = foo.Java(target = 'class3', source = 'src') +foo.JavaH(target = 'outdir1', + source = ['class1/com/sub/foo/Example1.class', + 'class1/com/other/Example2', + 'class1/com/sub/foo/Example3'], + JAVACLASSDIR = 'class1') +bar.JavaH(target = 'outdir2', source = bar_classes) +foo.JavaH(target = File('output.h'), source = foo_classes) +foo.Install('class4/com/sub/foo', 'class1/com/sub/foo/Example1.class') +foo.JavaH(target = 'outdir4', + source = ['class4/com/sub/foo/Example1.class'], + JAVACLASSDIR = 'class4') +""" % locals()) + +test.subdir('com', + ['com', 'sub'], + ['com', 'sub', 'foo'], + ['com', 'sub', 'bar'], + 'src') + +test.write(['com', 'sub', 'foo', 'Example1.java'], """\ +package com.sub.foo; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example2.java'], """\ +package com.other; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example3.java'], """\ +package com.sub.foo; + +public class Example3 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example4.java'], """\ +package com.sub.bar; + +public class Example4 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example5.java'], """\ +package com.other; + +public class Example5 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example6.java'], """\ +package com.sub.bar; + +public class Example6 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['src', 'Test.java'], """\ +class Empty { +} + +interface Listener { + public void execute(); +} + +public +class +Test { + class Inner { + void go() { + use(new Listener() { + public void execute() { + System.out.println("In Inner"); + } + }); + } + String s1 = "class A"; + String s2 = "new Listener() { }"; + /* class B */ + /* new Listener() { } */ + } + + public static void main(String[] args) { + new Test().run(); + } + + void run() { + use(new Listener() { + public void execute() { + use(new Listener( ) { + public void execute() { + System.out.println("Inside execute()"); + } + }); + } + }); + + new Inner().go(); + } + + void use(Listener l) { + l.execute(); + } +} + +class Private { + void run() { + new Listener() { + public void execute() { + } + }; + } +} +""") + +test.run(arguments = '.') + +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()) + +test.must_exist(['outdir1', 'com_sub_foo_Example1.h']) +test.must_exist(['outdir1', 'com_other_Example2.h']) +test.must_exist(['outdir1', 'com_sub_foo_Example3.h']) + +test.must_exist(['outdir2', 'com_sub_bar_Example4.h']) +test.must_exist(['outdir2', 'com_other_Example5.h']) +test.must_exist(['outdir2', 'com_sub_bar_Example6.h']) + +test.up_to_date(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JAVAHCOM.py b/test/Java/JAVAHCOM.py new file mode 100644 index 0000000..9db897a --- /dev/null +++ b/test/Java/JAVAHCOM.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test the ability to configure the $JAVAHCOM construction variable. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + + + +test.write('myjavah.py', r""" +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*javah*/\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(TOOLS = ['default', 'javah'], + JAVAHCOM = r'%(_python_)s myjavah.py $TARGET $SOURCES') +env.JavaH(target = 'out', source = 'file1.class') +env.JavaH(target = 'out', source = 'file2.class') +env.JavaH(target = 'out', source = 'file3.class') +""" % locals()) + +test.write('file1.class', "file1.class\n/*javah*/\n") +test.write('file2.class', "file2.class\n/*javah*/\n") +test.write('file3.class', "file3.class\n/*javah*/\n") + +test.run() + +test.must_match(['out', 'file1.h'], "file1.class\n") +test.must_match(['out', 'file2.h'], "file2.class\n") +test.must_match(['out', 'file3.h'], "file3.class\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JAVAHCOMSTR.py b/test/Java/JAVAHCOMSTR.py new file mode 100644 index 0000000..f8120d6 --- /dev/null +++ b/test/Java/JAVAHCOMSTR.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test that the $JAVAHCOMSTR construction variable allows you to configure +the javah output. +""" + +import os.path + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.subdir('src') + + + +out_file1_h = os.path.join('out', 'file1.h') +out_file2_h = os.path.join('out', 'file2.h') +out_file3_h = os.path.join('out', 'file3.h') + + + +test.write('myjavah.py', r""" +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*javah*/\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(TOOLS = ['default', 'javah'], + JAVAHCOM = r'%(_python_)s myjavah.py $TARGET $SOURCES', + JAVAHCOMSTR = 'Building javah $TARGET from $SOURCES') +env.JavaH(target = 'out', source = 'file1.class') +env.JavaH(target = 'out', source = 'file2.class') +env.JavaH(target = 'out', source = 'file3.class') +""" % locals()) + +test.write('file1.class', "file1.class\n/*javah*/\n") +test.write('file2.class', "file2.class\n/*javah*/\n") +test.write('file3.class', "file3.class\n/*javah*/\n") + +test.run(stdout = test.wrap_stdout("""\ +Building javah %(out_file1_h)s from file1.class +Building javah %(out_file2_h)s from file2.class +Building javah %(out_file3_h)s from file3.class +""" % locals())) + +test.must_match(['out', 'file1.h'], "file1.class\n") +test.must_match(['out', 'file2.h'], "file2.class\n") +test.must_match(['out', 'file3.h'], "file3.class\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/JAVASOURCEPATH.py b/test/Java/JAVASOURCEPATH.py new file mode 100644 index 0000000..5f19004 --- /dev/null +++ b/test/Java/JAVASOURCEPATH.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify that use of $JAVASOURCEPATH allows finding source .java +files in alternate locations by adding the -sourcepath option +to the javac command line. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +where_javac, java_version = test.java_where_javac() + +test.write('SConstruct', """ +env = Environment(tools = ['javac', 'javah'], + JAVAC = r'%(where_javac)s') +bar = env.Java(target = 'bar/classes', + source = 'bar/src/TestBar.java', + JAVASOURCEPATH = ['foo/src']) +""" % locals()) + +test.subdir('foo', + ['foo', 'src'], + ['foo', 'src', 'com'], + ['foo', 'src', 'com', 'foo'], + ['foo', 'src', 'com', 'foo', 'test'], + 'bar', ['bar', 'src']) + +test.write(['foo', 'src', 'com', 'foo', 'test', 'TestFoo.java'], """\ +package com.foo.test; +public class TestFoo {;} +""") + +test.write(['bar', 'src', 'TestBar.java'], """\ +package com.bar.test; +import com.foo.test.TestFoo; +class TestBar extends TestFoo {;} +""") + +test.run(arguments = '.') + +test.must_exist(['bar', 'classes', 'com', 'bar', 'test', 'TestBar.class']) +test.must_exist(['bar', 'classes', 'com', 'foo', 'test', 'TestFoo.class']) + +test.up_to_date(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/Java-1.4.py b/test/Java/Java-1.4.py new file mode 100644 index 0000000..c1eb5e5 --- /dev/null +++ b/test/Java/Java-1.4.py @@ -0,0 +1,393 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test Java compilation with a live Java 1.4 "javac" compiler. +""" + +import os +import sys + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +where_javac, java_version = test.java_where_javac('1.4') + + + +test.write('SConstruct', """ +env = Environment(tools = ['javac'], + JAVAVERSION = '1.4', + JAVAC = r'%(where_javac)s') +env.Java(target = 'class1', source = 'com/sub/foo') +env.Java(target = 'class2', source = 'com/sub/bar') +env.Java(target = 'class3', source = ['src1', 'src2']) +env.Java(target = 'class4', source = ['src4']) +env.Java(target = 'class5', source = ['src5']) +env.Java(target = 'class6', source = ['src6']) +""" % locals()) + +test.subdir('com', + ['com', 'sub'], + ['com', 'sub', 'foo'], + ['com', 'sub', 'bar'], + 'src1', + 'src2', + 'src4', + 'src5', + 'src6') + +test.write(['com', 'sub', 'foo', 'Example1.java'], """\ +package com.sub.foo; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example2.java'], """\ +package com.other; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example3.java'], """\ +package com.sub.foo; + +public class Example3 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example4.java'], """\ +package com.sub.bar; + +public class Example4 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example5.java'], """\ +package com.other; + +public class Example5 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example6.java'], """\ +package com.sub.bar; + +public class Example6 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['src1', 'Example7.java'], """\ +public class Example7 +{ + + public static void main(String[] args) + { + + } + +} +""") + +# Acid-test file for parsing inner Java classes, courtesy Chad Austin. +test.write(['src2', 'Test.java'], """\ +class Empty { +} + +interface Listener { + public void execute(); +} + +public +class +Test { + class Inner { + void go() { + use(new Listener() { + public void execute() { + System.out.println("In Inner"); + } + }); + } + String s1 = "class A"; + String s2 = "new Listener() { }"; + /* class B */ + /* new Listener() { } */ + } + + public static void main(String[] args) { + new Test().run(); + } + + void run() { + use(new Listener() { + public void execute() { + use(new Listener( ) { + public void execute() { + System.out.println("Inside execute()"); + } + }); + } + }); + + new Inner().go(); + } + + void use(Listener l) { + l.execute(); + } +} + +class Private { + void run() { + new Listener() { + public void execute() { + } + }; + } +} +""") + +# Testing nested anonymous inner classes, courtesy Brandon Mansfield. +test.write(['src4', 'NestedExample.java'], """\ +// import java.util.*; + +public class NestedExample +{ + public NestedExample() + { + new Thread() { + public void start() + { + new Thread() { + public void start() + { + try {Thread.sleep(200);} + catch (Exception e) {} + } + }; + while (true) + { + try {Thread.sleep(200);} + catch (Exception e) {} + } + } + }; + } + + + public static void main(String argv[]) + { + new NestedExample(); + } +} +""") + +# Test not finding an anonymous class when the second token after a +# "new" is a closing brace. This duplicates a test from the unit tests, +# but lets us make sure that we correctly determine that everything is +# up-to-date after the build. +test.write(['src5', 'TestSCons.java'], """\ +class TestSCons { + public static void main(String[] args) { + new Foo(); + } +} + +class Foo { } +""") + +# Test private inner class instantiation, courtesy Tilo Prutz: +# http://scons.tigris.org/issues/show_bug.cgi?id=1594 +test.write(['src6', 'TestSCons.java'], """\ +class test +{ + test() + { + super(); + new inner(); + } + + static class inner + { + private inner() {} + } +} +""") + + + +test.run(arguments = '.') + +expect_1 = [ + test.workpath('class1', 'com', 'other', 'Example2.class'), + test.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'), + test.workpath('class1', 'com', 'sub', 'foo', 'Example3.class'), +] + +expect_2 = [ + test.workpath('class2', 'com', 'other', 'Example5.class'), + test.workpath('class2', 'com', 'sub', 'bar', 'Example4.class'), + test.workpath('class2', 'com', 'sub', 'bar', 'Example6.class'), +] + +expect_3 = [ + test.workpath('class3', 'Empty.class'), + test.workpath('class3', 'Example7.class'), + test.workpath('class3', 'Listener.class'), + test.workpath('class3', 'Private$1.class'), + test.workpath('class3', 'Private.class'), + test.workpath('class3', 'Test$1.class'), + test.workpath('class3', 'Test$2.class'), + test.workpath('class3', 'Test$3.class'), + test.workpath('class3', 'Test$Inner.class'), + test.workpath('class3', 'Test.class'), +] + +expect_4 = [ + test.workpath('class4', 'NestedExample$1.class'), + test.workpath('class4', 'NestedExample$2.class'), + test.workpath('class4', 'NestedExample.class'), +] + +expect_5 = [ + test.workpath('class5', 'Foo.class'), + test.workpath('class5', 'TestSCons.class'), +] + +expect_6 = [ + test.workpath('class6', 'test$1.class'), + test.workpath('class6', 'test$inner.class'), + test.workpath('class6', 'test.class'), +] + +failed = None + +def classes_must_match(dir, expect): + global failed + got = test.java_get_class_files(test.workpath(dir)) + if expect != got: + missing = set(expect) - set(got) + if missing: + sys.stderr.write("Missing the following class files from '%s':\n" % dir) + for c in missing: + sys.stderr.write(' %s\n' % c) + unexpected = set(got) - set(expect) + if unexpected: + sys.stderr.write("Found the following unexpected class files in '%s':\n" % dir) + for c in unexpected: + sys.stderr.write(' %s\n' % c) + failed = 1 + +def classes_must_not_exist(dir, expect): + global failed + present = list(filter(os.path.exists, expect)) + if present: + sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir) + for c in present: + sys.stderr.write(' %s\n' % c) + failed = 1 + +classes_must_match('class1', expect_1) +classes_must_match('class2', expect_2) +classes_must_match('class3', expect_3) +classes_must_match('class4', expect_4) +classes_must_match('class5', expect_5) +classes_must_match('class6', expect_6) + +test.fail_test(failed) + +test.up_to_date(options='--debug=explain', arguments = '.') + +test.run(arguments = '-c .') + +classes_must_not_exist('class1', expect_1) +classes_must_not_exist('class2', expect_2) +classes_must_not_exist('class3', expect_3) +classes_must_not_exist('class4', expect_4) +classes_must_not_exist('class5', expect_5) +# This test case should pass, but doesn't. +# The expect_6 list contains the class files that the Java compiler +# actually creates, apparently because of the "private" instantiation +# of the "inner" class. Our parser doesn't currently detect this, so +# it doesn't know to remove that generated class file. +#classes_must_not_exist('class6', expect_6) + +test.fail_test(failed) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/Java-1.5.py b/test/Java/Java-1.5.py new file mode 100644 index 0000000..0f93a00 --- /dev/null +++ b/test/Java/Java-1.5.py @@ -0,0 +1,389 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test Java compilation with a live Java 1.5 "javac" compiler. +""" + +import os +import sys + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +where_javac, java_version = test.java_where_javac('1.5') + + + +test.write('SConstruct', """ +env = Environment(tools = ['javac'], + JAVAVERSION = '1.5', + JAVAC = r'%(where_javac)s') +env.Java(target = 'class1', source = 'com/sub/foo') +env.Java(target = 'class2', source = 'com/sub/bar') +env.Java(target = 'class3', source = ['src1', 'src2']) +env.Java(target = 'class4', source = ['src4']) +env.Java(target = 'class5', source = ['src5']) +env.Java(target = 'class6', source = ['src6']) +""" % locals()) + +test.subdir('com', + ['com', 'sub'], + ['com', 'sub', 'foo'], + ['com', 'sub', 'bar'], + 'src1', + 'src2', + 'src4', + 'src5', + 'src6') + +test.write(['com', 'sub', 'foo', 'Example1.java'], """\ +package com.sub.foo; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example2.java'], """\ +package com.other; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example3.java'], """\ +package com.sub.foo; + +public class Example3 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example4.java'], """\ +package com.sub.bar; + +public class Example4 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example5.java'], """\ +package com.other; + +public class Example5 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example6.java'], """\ +package com.sub.bar; + +public class Example6 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['src1', 'Example7.java'], """\ +public class Example7 +{ + + public static void main(String[] args) + { + + } + +} +""") + +# Acid-test file for parsing inner Java classes, courtesy Chad Austin. +test.write(['src2', 'Test.java'], """\ +class Empty { +} + +interface Listener { + public void execute(); +} + +public +class +Test { + class Inner { + void go() { + use(new Listener() { + public void execute() { + System.out.println("In Inner"); + } + }); + } + String s1 = "class A"; + String s2 = "new Listener() { }"; + /* class B */ + /* new Listener() { } */ + } + + public static void main(String[] args) { + new Test().run(); + } + + void run() { + use(new Listener() { + public void execute() { + use(new Listener( ) { + public void execute() { + System.out.println("Inside execute()"); + } + }); + } + }); + + new Inner().go(); + } + + void use(Listener l) { + l.execute(); + } +} + +class Private { + void run() { + new Listener() { + public void execute() { + } + }; + } +} +""") + +# Testing nested anonymous inner classes, courtesy Brandon Mansfield. +test.write(['src4', 'NestedExample.java'], """\ +// import java.util.*; + +public class NestedExample +{ + public NestedExample() + { + new Thread() { + public void start() + { + new Thread() { + public void start() + { + try {Thread.sleep(200);} + catch (Exception e) {} + } + }; + while (true) + { + try {Thread.sleep(200);} + catch (Exception e) {} + } + } + }; + } + + + public static void main(String argv[]) + { + new NestedExample(); + } +} +""") + +# Test not finding an anonymous class when the second token after a +# "new" is a closing brace. This duplicates a test from the unit tests, +# but lets us make sure that we correctly determine that everything is +# up-to-date after the build. +test.write(['src5', 'TestSCons.java'], """\ +class TestSCons { + public static void main(String[] args) { + Foo[] fooArray = new Foo[] { new Foo() }; + } +} + +class Foo { } +""") + +# Test private inner class instantiation, courtesy Tilo Prutz: +# http://scons.tigris.org/issues/show_bug.cgi?id=1594 +test.write(['src6', 'TestSCons.java'], """\ +class test +{ + test() + { + super(); + new inner(); + } + + static class inner + { + private inner() {} + } +} +""") + + + +test.run(arguments = '.') + +expect_1 = [ + test.workpath('class1', 'com', 'other', 'Example2.class'), + test.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'), + test.workpath('class1', 'com', 'sub', 'foo', 'Example3.class'), +] + +expect_2 = [ + test.workpath('class2', 'com', 'other', 'Example5.class'), + test.workpath('class2', 'com', 'sub', 'bar', 'Example4.class'), + test.workpath('class2', 'com', 'sub', 'bar', 'Example6.class'), +] + +expect_3 = [ + test.workpath('class3', 'Empty.class'), + test.workpath('class3', 'Example7.class'), + test.workpath('class3', 'Listener.class'), + test.workpath('class3', 'Private$1.class'), + test.workpath('class3', 'Private.class'), + test.workpath('class3', 'Test$1$1.class'), + test.workpath('class3', 'Test$1.class'), + test.workpath('class3', 'Test$Inner$1.class'), + test.workpath('class3', 'Test$Inner.class'), + test.workpath('class3', 'Test.class'), +] + +expect_4 = [ + test.workpath('class4', 'NestedExample$1$1.class'), + test.workpath('class4', 'NestedExample$1.class'), + test.workpath('class4', 'NestedExample.class'), +] + +expect_5 = [ + test.workpath('class5', 'Foo.class'), + test.workpath('class5', 'TestSCons.class'), +] + +expect_6 = [ + test.workpath('class6', 'test$1.class'), + test.workpath('class6', 'test$inner.class'), + test.workpath('class6', 'test.class'), +] + +failed = None + +def classes_must_match(dir, expect): + global failed + got = test.java_get_class_files(test.workpath(dir)) + if expect != got: + sys.stderr.write("Expected the following class files in '%s':\n" % dir) + for c in expect: + sys.stderr.write(' %s\n' % c) + sys.stderr.write("Got the following class files in '%s':\n" % dir) + for c in got: + sys.stderr.write(' %s\n' % c) + failed = 1 + +def classes_must_not_exist(dir, expect): + global failed + present = list(filter(os.path.exists, expect)) + if present: + sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir) + for c in present: + sys.stderr.write(' %s\n' % c) + failed = 1 + +classes_must_match('class1', expect_1) +classes_must_match('class2', expect_2) +classes_must_match('class3', expect_3) +classes_must_match('class4', expect_4) +classes_must_match('class5', expect_5) +classes_must_match('class6', expect_6) + +test.fail_test(failed) + +test.up_to_date(options='--debug=explain', arguments = '.') + +test.run(arguments = '-c .') + +classes_must_not_exist('class1', expect_1) +classes_must_not_exist('class2', expect_2) +classes_must_not_exist('class3', expect_3) +classes_must_not_exist('class4', expect_4) +classes_must_not_exist('class5', expect_5) +# This test case should pass, but doesn't. +# The expect_6 list contains the class files that the Java compiler +# actually creates, apparently because of the "private" instantiation +# of the "inner" class. Our parser doesn't currently detect this, so +# it doesn't know to remove that generated class file. +#classes_must_not_exist('class6', expect_6) + +test.fail_test(failed) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/Java-1.6.py b/test/Java/Java-1.6.py new file mode 100644 index 0000000..bd7a48f --- /dev/null +++ b/test/Java/Java-1.6.py @@ -0,0 +1,389 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test Java compilation with a live Java 1.6 "javac" compiler. +""" + +import os +import sys + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +where_javac, java_version = test.java_where_javac('1.6') + + + +test.write('SConstruct', """ +env = Environment(tools = ['javac'], + JAVAVERSION = '1.6', + JAVAC = r'%(where_javac)s') +env.Java(target = 'class1', source = 'com/sub/foo') +env.Java(target = 'class2', source = 'com/sub/bar') +env.Java(target = 'class3', source = ['src1', 'src2']) +env.Java(target = 'class4', source = ['src4']) +env.Java(target = 'class5', source = ['src5']) +env.Java(target = 'class6', source = ['src6']) +""" % locals()) + +test.subdir('com', + ['com', 'sub'], + ['com', 'sub', 'foo'], + ['com', 'sub', 'bar'], + 'src1', + 'src2', + 'src4', + 'src5', + 'src6') + +test.write(['com', 'sub', 'foo', 'Example1.java'], """\ +package com.sub.foo; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example2.java'], """\ +package com.other; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'foo', 'Example3.java'], """\ +package com.sub.foo; + +public class Example3 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example4.java'], """\ +package com.sub.bar; + +public class Example4 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example5.java'], """\ +package com.other; + +public class Example5 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'sub', 'bar', 'Example6.java'], """\ +package com.sub.bar; + +public class Example6 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['src1', 'Example7.java'], """\ +public class Example7 +{ + + public static void main(String[] args) + { + + } + +} +""") + +# Acid-test file for parsing inner Java classes, courtesy Chad Austin. +test.write(['src2', 'Test.java'], """\ +class Empty { +} + +interface Listener { + public void execute(); +} + +public +class +Test { + class Inner { + void go() { + use(new Listener() { + public void execute() { + System.out.println("In Inner"); + } + }); + } + String s1 = "class A"; + String s2 = "new Listener() { }"; + /* class B */ + /* new Listener() { } */ + } + + public static void main(String[] args) { + new Test().run(); + } + + void run() { + use(new Listener() { + public void execute() { + use(new Listener( ) { + public void execute() { + System.out.println("Inside execute()"); + } + }); + } + }); + + new Inner().go(); + } + + void use(Listener l) { + l.execute(); + } +} + +class Private { + void run() { + new Listener() { + public void execute() { + } + }; + } +} +""") + +# Testing nested anonymous inner classes, courtesy Brandon Mansfield. +test.write(['src4', 'NestedExample.java'], """\ +// import java.util.*; + +public class NestedExample +{ + public NestedExample() + { + new Thread() { + public void start() + { + new Thread() { + public void start() + { + try {Thread.sleep(200);} + catch (Exception e) {} + } + }; + while (true) + { + try {Thread.sleep(200);} + catch (Exception e) {} + } + } + }; + } + + + public static void main(String argv[]) + { + new NestedExample(); + } +} +""") + +# Test not finding an anonymous class when the second token after a +# "new" is a closing brace. This duplicates a test from the unit tests, +# but lets us make sure that we correctly determine that everything is +# up-to-date after the build. +test.write(['src5', 'TestSCons.java'], """\ +class TestSCons { + public static void main(String[] args) { + Foo[] fooArray = new Foo[] { new Foo() }; + } +} + +class Foo { } +""") + +# Test private inner class instantiation, courtesy Tilo Prutz: +# http://scons.tigris.org/issues/show_bug.cgi?id=1594 +test.write(['src6', 'TestSCons.java'], """\ +class test +{ + test() + { + super(); + new inner(); + } + + static class inner + { + private inner() {} + } +} +""") + + + +test.run(arguments = '.') + +expect_1 = [ + test.workpath('class1', 'com', 'other', 'Example2.class'), + test.workpath('class1', 'com', 'sub', 'foo', 'Example1.class'), + test.workpath('class1', 'com', 'sub', 'foo', 'Example3.class'), +] + +expect_2 = [ + test.workpath('class2', 'com', 'other', 'Example5.class'), + test.workpath('class2', 'com', 'sub', 'bar', 'Example4.class'), + test.workpath('class2', 'com', 'sub', 'bar', 'Example6.class'), +] + +expect_3 = [ + test.workpath('class3', 'Empty.class'), + test.workpath('class3', 'Example7.class'), + test.workpath('class3', 'Listener.class'), + test.workpath('class3', 'Private$1.class'), + test.workpath('class3', 'Private.class'), + test.workpath('class3', 'Test$1$1.class'), + test.workpath('class3', 'Test$1.class'), + test.workpath('class3', 'Test$Inner$1.class'), + test.workpath('class3', 'Test$Inner.class'), + test.workpath('class3', 'Test.class'), +] + +expect_4 = [ + test.workpath('class4', 'NestedExample$1$1.class'), + test.workpath('class4', 'NestedExample$1.class'), + test.workpath('class4', 'NestedExample.class'), +] + +expect_5 = [ + test.workpath('class5', 'Foo.class'), + test.workpath('class5', 'TestSCons.class'), +] + +expect_6 = [ + test.workpath('class6', 'test$1.class'), + test.workpath('class6', 'test$inner.class'), + test.workpath('class6', 'test.class'), +] + +failed = None + +def classes_must_match(dir, expect): + global failed + got = test.java_get_class_files(test.workpath(dir)) + if expect != got: + sys.stderr.write("Expected the following class files in '%s':\n" % dir) + for c in expect: + sys.stderr.write(' %s\n' % c) + sys.stderr.write("Got the following class files in '%s':\n" % dir) + for c in got: + sys.stderr.write(' %s\n' % c) + failed = 1 + +def classes_must_not_exist(dir, expect): + global failed + present = list(filter(os.path.exists, expect)) + if present: + sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir) + for c in present: + sys.stderr.write(' %s\n' % c) + failed = 1 + +classes_must_match('class1', expect_1) +classes_must_match('class2', expect_2) +classes_must_match('class3', expect_3) +classes_must_match('class4', expect_4) +classes_must_match('class5', expect_5) +classes_must_match('class6', expect_6) + +test.fail_test(failed) + +test.up_to_date(options='--debug=explain', arguments = '.') + +test.run(arguments = '-c .') + +classes_must_not_exist('class1', expect_1) +classes_must_not_exist('class2', expect_2) +classes_must_not_exist('class3', expect_3) +classes_must_not_exist('class4', expect_4) +classes_must_not_exist('class5', expect_5) +# This test case should pass, but doesn't. +# The expect_6 list contains the class files that the Java compiler +# actually creates, apparently because of the "private" instantiation +# of the "inner" class. Our parser doesn't currently detect this, so +# it doesn't know to remove that generated class file. +#classes_must_not_exist('class6', expect_6) + +test.fail_test(failed) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/RMIC.py b/test/Java/RMIC.py new file mode 100644 index 0000000..876ed80 --- /dev/null +++ b/test/Java/RMIC.py @@ -0,0 +1,354 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import os + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.write('myrmic.py', r""" +import os +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a == '-d': + outdir = args[1] + args = args[1:] + elif a == '-classpath': + args = args[1:] + elif a == '-sourcepath': + args = args[1:] + else: + break + args = args[1:] +for file in args: + infile = open(file, 'rb') + outfile = open(os.path.join(outdir, file[:-5] + '.class'), 'wb') + for l in infile.readlines(): + if l[:8] != '/*rmic*/': + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(tools = ['rmic'], + RMIC = r'%(_python_)s myrmic.py') +env.RMIC(target = 'outdir', source = 'test1.java') +""" % locals()) + +test.write('test1.java', """\ +test1.java +/*rmic*/ +line 3 +""") + +test.run(arguments = '.', stderr = None) + +test.fail_test(test.read(['outdir', 'test1.class']) != "test1.java\nline 3\n") + +if os.path.normcase('.java') == os.path.normcase('.JAVA'): + + test.write('SConstruct', """\ +env = Environment(tools = ['rmic'], + RMIC = r'%(_python_)s myrmic.py') +env.RMIC(target = 'outdir', source = 'test2.JAVA') +""" % locals()) + + test.write('test2.JAVA', """\ +test2.JAVA +/*rmic*/ +line 3 +""") + + test.run(arguments = '.', stderr = None) + + test.fail_test(test.read(['outdir', 'test2.class']) != "test2.JAVA\nline 3\n") + +where_javac, java_version = test.java_where_javac() +where_rmic = test.java_where_rmic() + +# Try to get the major/minor Java version +curver = (1, 0) +if java_version.count('.') == 1: + # Check Java version + major, minor = java_version.split('.') + try: + curver = (int(major), int(minor)) + except: + pass + +# Check the version of the found Java compiler. +# If it's 1.8 or higher, we skip the further RMIC test +# because we'll get warnings about the deprecated API... +# it's just not state-of-the-art anymore. +# Note, how we allow simple version strings like "5" and +# "6" to successfully pass this test. +if curver < (1, 8): + test.write("wrapper.py", """\ +import os +import sys +open('%s', 'ab').write("wrapper.py %%s\\n" %% " ".join(sys.argv[1:])) +os.system(" ".join(sys.argv[1:])) +""" % test.workpath('wrapper.out').replace('\\', '\\\\')) + + test.write('SConstruct', """ +foo = Environment(tools = ['javac', 'rmic'], + JAVAC = r'%(where_javac)s', + RMIC = r'%(where_rmic)s') +foo.Java(target = 'class1', source = 'com/sub/foo') +foo.RMIC(target = 'outdir1', + source = ['class1/com/sub/foo/Example1.class', + 'class1/com/sub/foo/Example2'], + JAVACLASSDIR = 'class1') + +rmic = foo.Dictionary('RMIC') +bar = foo.Clone(RMIC = r'%(_python_)s wrapper.py ' + rmic) +bar_classes = bar.Java(target = 'class2', source = 'com/sub/bar') +# XXX This is kind of a Python brute-force way to do what Ant +# does with its "excludes" attribute. We should probably find +# a similar friendlier way to do this. +bar_classes = [c for c in bar_classes if str(c).find('Hello') == -1] +bar.RMIC(target = Dir('outdir2'), source = bar_classes) +""" % locals() ) + + test.subdir('com', + ['com', 'other'], + ['com', 'sub'], + ['com', 'sub', 'foo'], + ['com', 'sub', 'bar'], + 'src3a', + 'src3b') + + test.write(['com', 'sub', 'foo', 'Hello.java'], """\ +package com.sub.foo; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +public interface Hello extends Remote { + String sayHello() throws RemoteException; +} +""") + + test.write(['com', 'sub', 'foo', 'Example1.java'], """\ +package com.sub.foo; + +import java.rmi.Naming; +import java.rmi.RemoteException; +import java.rmi.RMISecurityManager; +import java.rmi.server.UnicastRemoteObject; + +public class Example1 extends UnicastRemoteObject implements Hello { + + static final long serialVersionUID = 0; + + public Example1() throws RemoteException { + super(); + } + + public String sayHello() { + return "Hello World!"; + } + + public static void main(String args[]) { + if (System.getSecurityManager() == null) { + System.setSecurityManager(new RMISecurityManager()); + } + + try { + Example1 obj = new Example1(); + + Naming.rebind("//myhost/HelloServer", obj); + + System.out.println("HelloServer bound in registry"); + } catch (Exception e) { + System.out.println("Example1 err: " + e.getMessage()); + e.printStackTrace(); + } + } +} +""") + + test.write(['com', 'sub', 'foo', 'Example2.java'], """\ +package com.sub.foo; + +import java.rmi.Naming; +import java.rmi.RemoteException; +import java.rmi.RMISecurityManager; +import java.rmi.server.UnicastRemoteObject; + +public class Example2 extends UnicastRemoteObject implements Hello { + + static final long serialVersionUID = 0; + + public Example2() throws RemoteException { + super(); + } + + public String sayHello() { + return "Hello World!"; + } + + public static void main(String args[]) { + if (System.getSecurityManager() == null) { + System.setSecurityManager(new RMISecurityManager()); + } + + try { + Example2 obj = new Example2(); + + Naming.rebind("//myhost/HelloServer", obj); + + System.out.println("HelloServer bound in registry"); + } catch (Exception e) { + System.out.println("Example2 err: " + e.getMessage()); + e.printStackTrace(); + } + } +} +""") + + test.write(['com', 'sub', 'bar', 'Hello.java'], """\ +package com.sub.bar; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +public interface Hello extends Remote { + String sayHello() throws RemoteException; +} +""") + + test.write(['com', 'sub', 'bar', 'Example3.java'], """\ +package com.sub.bar; + +import java.rmi.Naming; +import java.rmi.RemoteException; +import java.rmi.RMISecurityManager; +import java.rmi.server.UnicastRemoteObject; + +public class Example3 extends UnicastRemoteObject implements Hello { + + static final long serialVersionUID = 0; + + public Example3() throws RemoteException { + super(); + } + + public String sayHello() { + return "Hello World!"; + } + + public static void main(String args[]) { + if (System.getSecurityManager() == null) { + System.setSecurityManager(new RMISecurityManager()); + } + + try { + Example3 obj = new Example3(); + + Naming.rebind("//myhost/HelloServer", obj); + + System.out.println("HelloServer bound in registry"); + } catch (Exception e) { + System.out.println("Example3 err: " + e.getMessage()); + e.printStackTrace(); + } + } +} +""") + + test.write(['com', 'sub', 'bar', 'Example4.java'], """\ +package com.sub.bar; + +import java.rmi.Naming; +import java.rmi.RemoteException; +import java.rmi.RMISecurityManager; +import java.rmi.server.UnicastRemoteObject; + +public class Example4 extends UnicastRemoteObject implements Hello { + + static final long serialVersionUID = 0; + + public Example4() throws RemoteException { + super(); + } + + public String sayHello() { + return "Hello World!"; + } + + public static void main(String args[]) { + if (System.getSecurityManager() == null) { + System.setSecurityManager(new RMISecurityManager()); + } + + try { + Example4 obj = new Example4(); + + Naming.rebind("//myhost/HelloServer", obj); + + System.out.println("HelloServer bound in registry"); + } catch (Exception e) { + System.out.println("Example4 err: " + e.getMessage()); + e.printStackTrace(); + } + } +} +""") + + test.run(arguments = '.') + + test.fail_test(test.read('wrapper.out') != "wrapper.py %s -d outdir2 -classpath class2 com.sub.bar.Example3 com.sub.bar.Example4\n" % where_rmic) + + test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example1_Stub.class')) + test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example2_Stub.class')) + test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example3_Stub.class')) + test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example4_Stub.class')) + + # We used to check for _Skel.class files as well, but they're not + # generated by default starting with Java 1.5, and they apparently + # haven't been needed for a while. Don't bother looking, even if we're + # running Java 1.4. If we think they're needed but they don't exist + # the test.up_to_date() call below will detect it. + #test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example1_Skel.class')) + #test.must_exist(test.workpath('outdir1', 'com', 'sub', 'foo', 'Example2_Skel.class')) + #test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example3_Skel.class')) + #test.must_exist(test.workpath('outdir2', 'com', 'sub', 'bar', 'Example4_Skel.class')) + + test.up_to_date(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/RMICCOM.py b/test/Java/RMICCOM.py new file mode 100644 index 0000000..ba7f965 --- /dev/null +++ b/test/Java/RMICCOM.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test the ability to configure the $RMICCOM construction variable. +""" + +import os.path + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.subdir('src') + + + +out_file1 = os.path.join('out', 'file1', 'class_Stub.class') +out_file2 = os.path.join('out', 'file2', 'class_Stub.class') +out_file3 = os.path.join('out', 'file3', 'class_Stub.class') + + + +test.write('myrmic.py', r""" +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*rmic*/\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(TOOLS = ['default', 'rmic'], + RMICCOM = r'%(_python_)s myrmic.py $TARGET $SOURCES') +env.RMIC(target = 'out', source = 'file1.class') +env.RMIC(target = 'out', source = 'file2.class') +env.RMIC(target = 'out', source = 'file3.class') +""" % locals()) + +test.write('file1.class', "file1.class\n/*rmic*/\n") +test.write('file2.class', "file2.class\n/*rmic*/\n") +test.write('file3.class', "file3.class\n/*rmic*/\n") + +test.run() + +test.must_match(out_file1, "file1.class\n") +test.must_match(out_file2, "file2.class\n") +test.must_match(out_file3, "file3.class\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/RMICCOMSTR.py b/test/Java/RMICCOMSTR.py new file mode 100644 index 0000000..8fe535a --- /dev/null +++ b/test/Java/RMICCOMSTR.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test that the $RMICCOMSTR construction variable allows you to configure +the rmic output. +""" + +import os.path + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.subdir('src') + + + +out_file1 = os.path.join('out', 'file1', 'class_Stub.class') +out_file2 = os.path.join('out', 'file2', 'class_Stub.class') +out_file3 = os.path.join('out', 'file3', 'class_Stub.class') + + + +test.write('myrmic.py', r""" +import sys +outfile = open(sys.argv[1], 'wb') +for f in sys.argv[2:]: + infile = open(f, 'rb') + for l in [l for l in infile.readlines() if l != '/*rmic*/\n']: + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +env = Environment(TOOLS = ['default', 'rmic'], + RMICCOM = r'%(_python_)s myrmic.py $TARGET $SOURCES', + RMICCOMSTR = 'Building rmic $TARGET from $SOURCES') +env.RMIC(target = 'out', source = 'file1.class') +env.RMIC(target = 'out', source = 'file2.class') +env.RMIC(target = 'out', source = 'file3.class') +""" % locals()) + +test.write('file1.class', "file1.class\n/*rmic*/\n") +test.write('file2.class', "file2.class\n/*rmic*/\n") +test.write('file3.class', "file3.class\n/*rmic*/\n") + +test.run(stdout = test.wrap_stdout("""\ +Building rmic %(out_file1)s from file1.class +Building rmic %(out_file2)s from file2.class +Building rmic %(out_file3)s from file3.class +""" % locals())) + +test.must_match(out_file1, "file1.class\n") +test.must_match(out_file2, "file2.class\n") +test.must_match(out_file3, "file3.class\n") + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/jar_not_in_PATH.py b/test/Java/jar_not_in_PATH.py new file mode 100644 index 0000000..9a716c5 --- /dev/null +++ b/test/Java/jar_not_in_PATH.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Ensures that the Tool gets initialized, even when jar is not directly +found via the PATH variable (issue #2730). +""" + +import os + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.write('myjar.py', r""" +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a == 'cf': + out = args[1] + args = args[1:] + else: + break + args = args[1:] +outfile = open(out, 'wb') +for file in args: + infile = open(file, 'rb') + for l in infile.readlines(): + if l[:7] != '/*jar*/': + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +import os +oldpath = os.environ.get('PATH','') +env = Environment(ENV = {'PATH' : ['.']}) +env['ENV']['PATH'] = oldpath +env['JAR'] = r'%(_python_)s ./myjar.py' +env.Jar(target = 'test1.jar', source = 'test1.class') +""" % locals()) + +test.write('test1.class', """\ +test1.class +/*jar*/ +line 3 +""") + +test.run(arguments = '.', stderr = None) + +test.must_exist('test1.jar') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/multi-step.py b/test/Java/multi-step.py new file mode 100644 index 0000000..a8efcd4 --- /dev/null +++ b/test/Java/multi-step.py @@ -0,0 +1,570 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Real-world test (courtesy Leanid Nazdrynau) of the multi-step +capabilities of the various Java Builders. +""" + +import os + +import TestSCons + +test = TestSCons.TestSCons() + +where_javac, java_version = test.java_where_javac() +where_javah = test.java_where_javah() +where_java_include=test.java_where_includes() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + + + +test.subdir(['src'], + ['src', 'HelloApplet'], + ['src', 'HelloApplet', 'com'], + ['src', 'javah'], + ['src', 'jni'], + ['src', 'server'], + ['src', 'server', 'JavaSource'], + ['src', 'server', 'JavaSource', 'com'], + ['src', 'server', 'JavaSource', 'com', 'gnu'], + ['src', 'server', 'JavaSource', 'com', 'gnu', 'scons'], + ['src', 'server', 'JavaSource', 'com', 'gnu', 'scons', 'web'], + ['src', 'server', 'JavaSource', 'com', 'gnu', 'scons', 'web', 'tools'], + ['src', 'server', 'WebContent'], + ['src', 'server', 'WebContent', 'META-INF'], + ['src', 'server', 'WebContent', 'WEB-INF'], + ['src', 'server', 'WebContent', 'WEB-INF', 'conf'], + ['src', 'server', 'WebContent', 'WEB-INF', 'lib'], + ['src', 'server', 'WebContent', 'theme']) + +test.write(['SConstruct'], """\ +import os,sys +env=Environment(tools = ['default', 'javac', 'javah'], + CPPPATH=%(where_java_include)s, + JAVAC = r'%(where_javac)s', + JAVAH = r'%(where_javah)s') +Export('env') +env.PrependENVPath('PATH',os.environ.get('PATH',[])) +env['INCPREFIX']='-I' +env.Append(SWIGFLAGS=['-c++','$_CPPINCFLAGS']) + +#this is for JNI +#env.Append(CCFLAGS=['/IN:/jdk/v1.3.1/include','/IN:/jdk/v1.3.1/include/win32']) + +#this for windows only C++ build +#env.Append(CXXFLAGS='-GX') + +env.Append(CPPPATH='.') + +env.VariantDir('buildout', 'src', duplicate=0) + +if sys.platform[:6]=='darwin': + env.Append(CPPPATH=['/System/Library/Frameworks/JavaVM.framework/Headers']) + +#If you do not have swig on your system please remove 'buildout/jni/SConscript' line from next call +env.SConscript(['buildout/server/JavaSource/SConscript', + 'buildout/HelloApplet/SConscript', + 'buildout/jni/SConscript', + 'buildout/javah/SConscript']) +""" % locals()) + +test.write(['src', 'HelloApplet', 'Hello.html'], """\ +<HTML> +<HEAD> +<TITLE> Applet Hello </TITLE> +</HEAD> +<BODY> +<CENTER> +<applet name="Hello" archive="HelloApplet.jar" code="com.Hello.Hello.class" + width="800" height="286" MAYSCRIPT> +</applet> +</CENTER> +</BODY> +</HTML> + +""") + +test.write(['src', 'HelloApplet', 'SConscript'], """\ +import os +Import ("env") +denv=env.Clone() +classes=denv.Java(target='classes',source=['com']) +#set correct path for jar +denv['JARCHDIR']=os.path.join(denv.Dir('.').get_abspath(),'classes') +denv.Jar('HelloApplet',classes) + + +#To sign applet you have to create keystore before and made a calls like this + +#keystore='/path/to/jarsignkey' +#denv['JARSIGNFLAGS']='-keystore '+keystore+' -storepass pass -keypass passkey' +#denv['JARSIGNALIAS']='ALIAS' +#denv['JARCOM']=[denv['JARCOM'],'$JARSIGNCOM'] + +""") + +test.write(['src', 'HelloApplet', 'com', 'Hello.java'], """\ +package com.Hello; +import java.awt.*; +import java.applet.*; + +public class Hello extends Applet { + static final long serialVersionUID = 0; + public void paint(Graphics g) + { + g.drawString("Hello from SCons signed applet",250,150); + } +} +""") + +test.write(['src', 'javah', 'MyID.cc'], """\ +#include "MyID.h" +int getMyID() +{ + return 0; +} +""") + +test.write(['src', 'javah', 'MyID.java'], """\ +public class MyID +{ + static private long current = System.currentTimeMillis(); + static public String get() + { + current++; + return new Long( current ).toString(); + } +} +""") + +test.write(['src', 'javah', 'SConscript'], """\ +Import('env') +denv=env.Clone() +denv['JARCHDIR']=denv.Dir('.').get_abspath() +denv.Jar('myid','MyID.java') +denv.JavaH(denv.Dir('.').get_abspath(),'MyID.java') +denv.SharedLibrary('myid','MyID.cc') + +""") + +test.write(['src', 'jni', 'A.java'], """\ +package web.jni; + +public class A +{ +class C +{ + void echo2( String text ) + { + System.out.println( text+"aa" ); + + } +} +class B +{ + void echo( String text ) + { + System.out.println( text ); + C c = new C(); + c.echo2("from B callin C"); + } +} + public void main( String[] x) + { + B b = new B(); + b.echo("123"); + C c = new C(); + c.echo2("456"); + } +} +""") + +test.write(['src', 'jni', 'JniWrapper.cc'], """\ +#include <vector> +#include <iostream> + +#include "JniWrapper.h" + + + +JniWrapper::JniWrapper( JNIEnv *pEnv ) + : mpEnv( pEnv ) +{ +} + +JniWrapper::JniWrapper( const JniWrapper& rJniWrapper ) + : mpEnv( rJniWrapper.mpEnv ) +{ +} + +JniWrapper::~JniWrapper() +{ + +} + +JniWrapper& JniWrapper::operator=( const JniWrapper& rJniWrapper ) +{ + if ( this != &rJniWrapper ) + { + mpEnv = rJniWrapper.mpEnv; + } + return *this; +} + +std::string JniWrapper::unmarshalString( jstring value ) +{ + std::string result; + if( value ) + { + const char *pStr = mpEnv->GetStringUTFChars( value, 0 ); + result = pStr; + mpEnv->ReleaseStringUTFChars( value, pStr ); + } + return result; +} + +jobject JniWrapper::marshalDouble( double value ) +{ + jclass classObject = mpEnv->FindClass( "java/lang/Double" ); + jmethodID constructorId = mpEnv->GetMethodID( classObject, "<init>", "(D)V" ); + jobject result = mpEnv->NewObject( classObject, constructorId, value ); + + return result; +} + +jobject JniWrapper::getVectorElement( jobject values, int i ) +{ + jclass vectorClass = mpEnv->FindClass( "java/util/Vector" ); + jmethodID methodID = mpEnv->GetMethodID( vectorClass, + "elementAt", + "(I)Ljava/lang/Object;" ); + jobject result = mpEnv->CallObjectMethod( values, methodID, i ); + + return result; +} + +jobject JniWrapper::newVector() +{ + jclass vectorClass = mpEnv->FindClass( "java/util/Vector" ); + jmethodID constructorID = mpEnv->GetMethodID( vectorClass, "<init>", "()V" ); + jobject result = mpEnv->NewObject( vectorClass, constructorID ); + + return result; +} + +void JniWrapper::addElement( jobject vector, jobject element ) +{ + jclass vectorClass = mpEnv->FindClass( "java/util/Vector" ); + jmethodID addElementMethodID = mpEnv->GetMethodID( vectorClass, + "addElement", + "(Ljava/lang/Object;)V" ); + + mpEnv->CallVoidMethod( vector, addElementMethodID, element ); +} + +jobject JniWrapper::marshalDoubleVector( const std::vector<double>& rVector ) +{ + jobject result = newVector(); + + for ( int i = 0; i < rVector.size(); i++ ) + { + addElement( result, marshalDouble( rVector[i] ) ); + } + + return result; +} + +std::pair<std::string, std::string> JniWrapper::unmarshalPairString( jobject vector ) +{ + std::pair<std::string, std::string> result; + result.first = unmarshalString( (jstring)getVectorElement( vector, 0 ) ); + result.second = unmarshalString( (jstring)getVectorElement( vector, 1 ) ); + + return result; +} +""") + +test.write(['src', 'jni', 'JniWrapper.h'], """\ +#ifndef JniWrapper_h +#define JniWrapper_h + +#include <jni.h> +/** + * Provides routines for dealing with JNI translation etc. + */ + +class JniWrapper +{ +public: + JniWrapper( JNIEnv *pEnv ); + JniWrapper( const JniWrapper& rJniWrapper ); + virtual ~JniWrapper(); + JniWrapper& operator=( const JniWrapper& rJniWrapper ); + + + std::string unmarshalString( jstring value ); + + jstring marshalString( const std::string& value ); + + jbyteArray marshalByteArray( const std::string& value ); + + double unmarshalDouble( jobject value ); + + jobject marshalDouble( double value ); + jobject marshallStringVector( const std::vector<std::string>& rMap ); + + jobject marshalDoubleVector( const std::vector<double>& rVector ); + std::pair<std::string, std::string> unmarshalPairString( jobject ); + +protected: + JNIEnv *mpEnv; + +private: + JniWrapper(); + jobject newVector(); + void addElement( jobject vector, jobject element ); + jobject getVectorElement( jobject values, int i ); + +}; + +#endif // JniWrapper_h + + +""") + +test.write(['src', 'jni', 'SConscript'], """\ +Import ("env") +denv=env.Clone() + +denv.Append(SWIGFLAGS=['-java']) +denv.SharedLibrary('scons',['JniWrapper.cc','Sample.i']) +denv['JARCHDIR']=denv.Dir('.').get_abspath() +denv.Jar(['Sample.i','A.java']) +""") + +test.write(['src', 'jni', 'Sample.h'], """\ +#include <vector> +#include <iostream> + +class SampleTest +{ +public: + std::vector<double> test1( std::pair<std::string, std::string> param ) + { + std::vector<double> result; + result.push_back(10); + return result; + } +}; + +""") + +test.write(['src', 'jni', 'Sample.i'], """\ +%module Sample + +%{ +#include "Sample.h" +#include "JniWrapper.h" +%} + +%typemap(jni) std::vector<double>, std::vector<double>& "jobject" +%typemap(jtype) std::vector<double>, std::vector<double>& "java.util.Vector" +%typemap(jstype) std::vector<double>, std::vector<double>& "java.util.Vector" + +// return a Vector of Doubles +%typemap(javaout) std::vector<double> { + return $jnicall; +} +%typemap(out) std::vector<double> { + JniWrapper JniWrapper(jenv); + $result = JniWrapper.marshalDoubleVector( $1 ); +} + +/********************************************************************* + * + * Pairs of String (IN/OUT) + * + *********************************************************************/ +%typemap(jni) std::pair<std::string, std::string>, const std::pair<std::string, std::string>& "jobject" +%typemap(jtype) std::pair<std::string, std::string>, const std::pair<std::string, std::string>& "java.util.Vector" +%typemap(jstype) std::pair<std::string, std::string>, const std::pair<std::string, std::string>& "java.util.Vector" +%typemap(javain) std::pair<std::string, std::string>, const std::pair<std::string, std::string>& "$javainput" + +// pass in by reference a Vector of std::string +%typemap(in) const std::pair<std::string, std::string>& { + $1 = new std::pair<std::string, std::string>(); + JniWrapper JniWrapper(jenv); + *($1) = JniWrapper.unmarshalPairString( $input ); +} + +//cleanup +%typemap(freearg) const std::pair<std::string, std::string>& { + delete $1; +} + +%include "Sample.h" + +// generate:Sample.java +// generate:SampleJni.java +// generate:SampleTest.java +""") + +test.write(['src', 'server', 'JavaSource', 'SConscript'], """\ +import os +Import ("env") +classes=env.Java(target='classes',source=['com']) + +HelloApplet=os.path.join('#/buildout/HelloApplet/HelloApplet.jar') +env['WARXFILES']=['SConscript','.cvsignore'] +env['WARXDIRS']=['CVS'] +#env.War('scons',[classes,Dir('../WebContent'),HelloApplet]) +""") + +test.write(['src', 'server', 'JavaSource', 'com', 'gnu', 'scons', 'web', 'tools', 'Bool.java'], """\ +package com.gnu.scons.web.tools; +public class Bool { + boolean flag; + + public Bool() + { + flag = false; + } + + public Bool( boolean aFlag ) + { + flag = aFlag; + } + + public boolean booleanValue() + { + return flag; + } +} +""") + +test.write(['src', 'server', 'JavaSource', 'com', 'gnu', 'scons', 'web', 'tools', 'StringUtils.java'], """\ +package com.gnu.scons.web.tools; + +public class StringUtils +{ + public static String toPercent( String value ) + { + if ( value.equals("") ) + { + return ""; + } + else + { + return value + "%"; + } + } + +} +""") + +test.write(['src', 'server', 'WebContent', 'index.html'], """\ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> +<HTML> +<HEAD> +<META http-equiv="refresh" content="0;URL=go?action=home"> +<TITLE>index.html</TITLE> +</HEAD> +<BODY> +<P><a href="go?action=home">go?action=home</a></P> +</BODY> +</HTML> +""") + +test.write(['src', 'server', 'WebContent', 'META-INF', 'MANIFEST.MF'], """\ +Manifest-Version: 1.0 +Class-Path: + +""") + +test.write(['src', 'server', 'WebContent', 'WEB-INF', 'web.xml'], """\ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> +<web-app id="WebExample"> + <display-name>scons</display-name> + <servlet> + <servlet-name>WebExample</servlet-name> + <display-name>WebExample</display-name> + <servlet-class>com.gnu.scons.web.tool.WebExample</servlet-class> + </servlet> + <servlet-mapping> + <servlet-name>WebExample</servlet-name> + <url-pattern>/go</url-pattern> + </servlet-mapping> + <welcome-file-list> + <welcome-file>index.html</welcome-file> + <welcome-file>index.htm</welcome-file> + </welcome-file-list> +</web-app> +""") + +test.write(['src', 'server', 'WebContent', 'WEB-INF', 'conf', 'app.properties'], """\ +logging = webExample.Example +""") + +test.write(['src', 'server', 'WebContent', 'theme', 'Master.css'], """\ +body +{ + font-family: Helvetica,Sans-Serif; + font-size: 11pt; +} +""") + +test.run(arguments = '.') + +test.must_exist(['buildout', 'javah', 'myid.jar']) +test.must_exist(['buildout', 'javah', 'MyID', 'MyID.class']) + +test.must_exist(['buildout', 'jni', 'Sample.class']) +test.must_exist(['buildout', 'jni', 'Sample.java']) +test.must_exist(['buildout', 'jni', 'SampleJNI.class']) +test.must_exist(['buildout', 'jni', 'SampleJNI.java']) +test.must_exist(['buildout', 'jni', 'SampleTest.java']) + +# Some combinations of Java + SWIG apparently don't actually generate +# a SampleTest.class file, while others do. Only issue a warning if +# it doesn't exist. +p = test.workpath('buildout', 'jni', 'SampleTest.class') +if not os.path.exists(p): + print 'Warning: %s does not exist' % p + +test.up_to_date(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/nested-classes.py b/test/Java/nested-classes.py new file mode 100644 index 0000000..2b1b5db --- /dev/null +++ b/test/Java/nested-classes.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Test Java compilation with inner and anonymous classes (Issue 2087). +""" + +import os + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() +where_javac, java_version = test.java_where_javac() + +# Work around javac 1.4 not reporting its version: +java_version = java_version or "1.4" + +test.write('SConstruct', """ +env = Environment() +env['JAVAVERSION'] = '%(java_version)s' +classes = env.Java(target = 'build', source = 'source') +env.Jar(target = 'anon.jar', source = classes) +""" % locals()) + +test.subdir('source', 'build') + +test.write(['source', 'Test.java'], """\ +public class Test { + class Inner { }; + public void testAnon(Test test) { } + public void testAnon(Inner inner) { } + public Test ( ) { + class Foo { + public int reply ( ) { + class Bar { }; + return 1 ; + } + } ; + testAnon(new Test() { }); + } + public Test (int a) { + class Foo { + public int reply ( ) { + class Bar { }; + return 1 ; + } + } ; + testAnon(new Test() { }); + } + public Test (int a, int b) { + class Foobar { + public int reply ( ) { + class Bar { }; + return 1 ; + } + } ; + testAnon(new Test() { }); + } + public Test (int a, int b, int c) { + testAnon(new Test() { }); + } + void run() { + testAnon(new Inner() { + public void execute() { + testAnon(new Inner( ) { + public void execute() { + System.out.println("Inside execute()"); + } + }); + } + }); + } +} +""") + +test.run(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/no-JARCHDIR.py b/test/Java/no-JARCHDIR.py new file mode 100644 index 0000000..2037524 --- /dev/null +++ b/test/Java/no-JARCHDIR.py @@ -0,0 +1,114 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify the Jar() behavior when we have no JARCHDIR set (it should +automatically use the classdir that was deduced from the Java() call) +and when we explicity set it to None (it should not use the Java() +classdir attribute at all). +""" + +import TestSCons + +test = TestSCons.TestSCons() + +where_javac, java_version = test.java_where_javac() +where_jar = test.java_where_jar() + +test.subdir('src') + + + +test.write(['src', 'a.java'], """\ +package foo.bar; +public class a {} +""") + +test.write(['src', 'b.java'], """\ +package foo.bar; +public class b {} +""") + + + +test.write('SConstruct', """\ +env = Environment(tools = ['javac', 'jar'], + JAVAC = r'%(where_javac)s', + JAR = r'%(where_jar)s') + +jar = env.Jar('x.jar', env.Java(target = 'classes', source = 'src')) +""" % locals()) + +test.run(arguments = '.') + + + +test.run(program = where_jar, arguments = 'tf x.jar') + +expect = """\ +foo/bar/a.class +foo/bar/b.class +""" + +test.must_contain_all_lines(test.stdout(), [expect]) + + + +test.run(arguments = '-c') + + + +test.write('SConstruct', """\ +env = Environment(tools = ['javac', 'jar'], + JAVAC = r'%(where_javac)s', + JAR = r'%(where_jar)s', + JARCHDIR = None) + +jar = env.Jar('x.jar', env.Java(target = 'classes', source = 'src')) +""" % locals()) + +test.run(arguments = '.') + + + +test.run(program = where_jar, arguments = 'tf x.jar') + +expect = """\ +classes/foo/bar/a.class +classes/foo/bar/b.class +""" + +test.must_contain_all_lines(test.stdout(), [expect]) + + + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/rmic_not_in_PATH.py b/test/Java/rmic_not_in_PATH.py new file mode 100644 index 0000000..9c7030c --- /dev/null +++ b/test/Java/rmic_not_in_PATH.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Ensures that the Tool gets initialized, even when rmic is not directly +found via the PATH variable (issue #2730). +""" + +import os + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +test.write('myrmic.py', r""" +import os +import sys +args = sys.argv[1:] +while args: + a = args[0] + if a == '-d': + outdir = args[1] + args = args[1:] + elif a == '-classpath': + args = args[1:] + elif a == '-sourcepath': + args = args[1:] + else: + break + args = args[1:] +for file in args: + infile = open(file, 'rb') + outfile = open(os.path.join(outdir, file[:-5] + '.class'), 'wb') + for l in infile.readlines(): + if l[:8] != '/*rmic*/': + outfile.write(l) +sys.exit(0) +""") + +test.write('SConstruct', """ +import os +oldpath = os.environ.get('PATH','') +env = Environment(ENV = {'PATH' : ['.']}) +env['ENV']['PATH'] = oldpath +env['RMIC'] = r'%(_python_)s myrmic.py' +env.RMIC(target = 'outdir', source = 'test1.java') +""" % locals()) + +test.write('test1.java', """\ +test1.java +/*rmic*/ +line 3 +""") + +test.run(arguments = '.', stderr = None) + +test.must_exist(os.path.join('outdir','test1.class')) + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/source-files.py b/test/Java/source-files.py new file mode 100644 index 0000000..bf263cf --- /dev/null +++ b/test/Java/source-files.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify that we can pass the Java() builder explicit lists of .java +files as sources. +""" + +import TestSCons + +_python_ = TestSCons._python_ + +test = TestSCons.TestSCons() + +where_javac, java_version = test.java_where_javac() + + +test.write('SConstruct', """ +env = Environment(tools = ['javac', 'javah'], + JAVAC = r'%(where_javac)s') +env.Java(target = 'class1', source = 'com/Example1.java') +env.Java(target = 'class2', source = ['com/Example2.java', 'com/Example3.java']) +""" % locals()) + +test.subdir('com', 'src') + +test.write(['com', 'Example1.java'], """\ +package com; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'Example2.java'], """\ +package com; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'Example3.java'], """\ +package com; + +public class Example3 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['com', 'Example4.java'], """\ +package com; + +public class Example4 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.run(arguments = '.') + +test.must_exist (['class1', 'com', 'Example1.class']) +test.must_not_exist(['class1', 'com', 'Example2.class']) +test.must_not_exist(['class1', 'com', 'Example3.class']) +test.must_not_exist(['class1', 'com', 'Example4.class']) + +test.must_not_exist(['class2', 'com', 'Example1.class']) +test.must_exist (['class2', 'com', 'Example2.class']) +test.must_exist (['class2', 'com', 'Example3.class']) +test.must_not_exist(['class2', 'com', 'Example4.class']) + +test.up_to_date(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/Java/swig-dependencies.py b/test/Java/swig-dependencies.py new file mode 100644 index 0000000..2c53f0c --- /dev/null +++ b/test/Java/swig-dependencies.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +""" +Verify that dependencies on SWIG-generated .java files work correctly. + +Test case courtesy Jonathan (toolshed@tigris.org). +""" + +import TestSCons + +test = TestSCons.TestSCons() + +swig = test.where_is('swig') +if not swig: + test.skip_test('Can not find installed "swig", skipping test.\n') + +where_javac, java_version = test.java_where_javac() +where_javah = test.java_where_javah() +#where_jar = test.java_where_jar() + +where_java_include=test.java_where_includes() + +test.subdir(['foo'], + ['java'], + ['java', 'build']) + +test.write(['SConstruct'], """\ +import os + +env = Environment(ENV = os.environ, + CPPPATH=%(where_java_include)s, + JAVAC = r'%(where_javac)s', + JAVAH = r'%(where_javah)s') + +env.Append(CPPFLAGS = ' -g -Wall') + +Export('env') + +SConscript('#foo/SConscript') +SConscript('#java/SConscript') +""" % locals()) + +test.write(['foo', 'SConscript'], """\ +Import('env') + +env.SharedLibrary('foo', 'foo.cpp') +""") + +test.write(['foo', 'foo.cpp'], """\ +#include "foo.h" + +int fooAdd(int a, int b) { + return a + b; +} +""") + +test.write(['foo', 'foo.h'], """\ +int fooAdd(int, int); +""") + +test.write(['java', 'Java_foo_interface.i'], """\ +#include "foo.h" + +%module foopack +""") + +test.write(['java', 'SConscript'], """\ +import os + +Import('env') + +# unnecessary? +env = env.Clone() + +env.Prepend(CPPPATH = ['#foo',]) + +libadd = ['foo',] + +libpath = ['#foo',] + +#swigflags = '-c++ -java -Wall -package foopack -Ifoo' +swigflags = '-c++ -java -Wall -Ifoo' + +Java_foo_interface = env.SharedLibrary( + 'Java_foo_interface', + 'Java_foo_interface.i', + LIBS = libadd, + LIBPATH = libpath, + SWIGFLAGS = swigflags, + SWIGOUTDIR = Dir('build'), + SWIGCXXFILESUFFIX = "_wrap.cpp") + +foopack_jar_javac = env.Java('classes', 'build') + +env['JARCHDIR'] = 'java/classes' +foopack_jar = env.Jar(target = 'foopack.jar', source = 'classes') +""") + +# Disable looking at stderr because some combinations of SWIG/gcc +# generate a warning about the sWIG_JavaThrowException() function +# being defined but not used. +test.run(arguments = '.', stderr=None) + +#test.must_exist(['java', 'classes', 'foopack', 'foopack.class']) +#test.must_exist(['java', 'classes', 'foopack', 'foopackJNI.class']) +test.must_exist(['java', 'classes', 'foopack.class']) +test.must_exist(['java', 'classes', 'foopackJNI.class']) + +test.up_to_date(arguments = '.') + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: |
