diff options
-rw-r--r-- | src/engine/SCons/Tool/jar.py | 12 | ||||
-rw-r--r-- | test/Java/JAR.py | 142 |
2 files changed, 150 insertions, 4 deletions
diff --git a/src/engine/SCons/Tool/jar.py b/src/engine/SCons/Tool/jar.py index 49efe6f..c7ca4d4 100644 --- a/src/engine/SCons/Tool/jar.py +++ b/src/engine/SCons/Tool/jar.py @@ -145,6 +145,13 @@ def Jar(env, target = None, source = [], *args, **kw): else: return [env.fs.File(s)] + def dir_to_class(s): + dir_targets = env.JavaClassDir(source = s, *args, **kw) + if(dir_targets == []): + return [env.fs.Dir(s)] + else: + return dir_targets + # In the case that we are passed just string to a node which is directory # but does not exist, we need to check all the current targets to see if # that directory is going to exist so we can add it as a source to Jar builder @@ -169,14 +176,13 @@ def Jar(env, target = None, source = [], *args, **kw): target_classes.extend(file_to_class(s)) else: # found a dir so make sure its a dir of class files - target_classes.extend(env.JavaClassDir(source = env.fs.Dir(s), *args, **kw)) + target_classes.extend(dir_to_class(s)) else: if os.path.isfile(s): # found a file that exists on the FS, make sure its a class file target_classes.extend(file_to_class(s)) elif os.path.isdir(s): - # found a dir on the FS, add it as a dir of class files - target_classes.append(env.fs.Dir(s)) + target_classes.extend(dir_to_class(s)) elif s[-len(java_suffix):] == java_suffix or s[-len(java_class_suffix):] == java_class_suffix: # found a file that may not exists and is only a string # so add it after converting it to a class file diff --git a/test/Java/JAR.py b/test/Java/JAR.py index 051e051..da2e72e 100644 --- a/test/Java/JAR.py +++ b/test/Java/JAR.py @@ -134,7 +134,7 @@ bar = foo.Clone(JAR = r'%(_python_)s wrapper_with_args.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') +bar.Jar(target = 'bar', source = Dir('classes/com/sub/bar')) """ % locals()) test.subdir('com', @@ -421,6 +421,146 @@ test.must_exist(['listOfLists', 'listsTest', 'com', 'resource', 'resource1.txt'] test.must_exist(['listOfLists', 'listsTest', 'com', 'resource', 'resource2.txt']) test.must_exist(['listOfLists', 'listsTest', 'META-INF', 'MANIFEST.MF']) test.must_contain(['listOfLists', 'listsTest', 'META-INF', 'MANIFEST.MF'], b"MyManifestTest: Test" ) + +####### +# test different style of passing in dirs + +# make some directories to test in +test.subdir('testdir3', + ['testdir3', 'com'], + ['testdir3', 'com', 'sub'], + ['testdir3', 'com', 'sub', 'foo'], + ['testdir3', 'com', 'sub', 'bar']) + +# Create the jars then extract them back to check contents +test.write(['testdir3', 'SConstruct'], """ +foo = Environment() +bar = foo.Clone() +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', JARCHDIR='classes') +bar.Jar(target = 'bar', source = Dir('classes/com/sub/bar'), JARCHDIR='classes') +foo.Command("fooTest", 'foo.jar', Mkdir("fooTest") ) +foo.Command('doesnt_exist1', "fooTest", foo['JAR'] + ' xvf ../foo.jar', chdir='fooTest') +bar.Command("barTest", 'bar.jar', Mkdir("barTest") ) +bar.Command('doesnt_exist2', 'barTest', bar['JAR'] + ' xvf ../bar.jar', chdir='barTest') +""") + +test.write(['testdir3', 'com', 'sub', 'foo', 'Example1.java'], """\ +package com.sub.foo; + +public class Example1 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'foo', 'Example2.java'], """\ +package com.sub.foo; + +public class Example2 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'foo', 'Example3.java'], """\ +package com.sub.foo; + +public class Example3 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'foo', 'NonJava.txt'], """\ +testfile +""") + +test.write(['testdir3', 'com', 'sub', 'bar', 'Example4.java'], """\ +package com.sub.bar; + +public class Example4 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'bar', 'Example5.java'], """\ +package com.sub.bar; + +public class Example5 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'bar', 'Example6.java'], """\ +package com.sub.bar; + +public class Example6 +{ + + public static void main(String[] args) + { + + } + +} +""") + +test.write(['testdir3', 'com', 'sub', 'bar', 'NonJava.txt'], """\ +testfile +""") + +test.run(chdir='testdir3') + +# check the output and make sure the java files got converted to classes + + +# make sure there are class in the jar +test.must_exist(['testdir3','foo.jar']) +test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example1.class']) +test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example2.class']) +test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'Example3.class']) +# TODO: determine expected behavior with resource files, should they be +# automatically copied in or specified in seperate commands +#test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'foo', 'NonJava.txt']) + +# make sure both jars got createds +test.must_exist(['testdir3','bar.jar']) +test.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example4.class']) +test.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example5.class']) +test.must_exist(['testdir3', 'barTest', 'com', 'sub', 'bar', 'Example6.class']) +# TODO: determine expected behavior with resource files, should they be +# automatically copied in or specified in seperate commands +#test.must_exist(['testdir3', 'fooTest', 'com', 'sub', 'bar', 'NonJava.txt']) + test.pass_test() |