.IP Jar
Builds a Java archive (.jar) file
from a source tree of .class files.
+If the $JAVACHDIR value is set, the
+.B jar
+command will change to the specified directory using the
+.B \-C
+option.
+If the contents any of the source files begin with the string
+.BR Manifest-Version ,
+the file is assumed to be a manifest
+and is passed to the
+.B jar
+command with the
+.B m
+option set.
.ES
env.Jar(target = 'foo.jar', source = 'classes')
.IP JAR
The Java archive tool.
+.IP JARCHDIR
+The directory to which the Java archive tool should change
+(using the
+.B \-C
+option).
+
.IP JARCOM
The command line used to call the Java archive tool.
RELEASE X.XX - XXX
+ From Charles Crain:
+
+ - Add support for a JARCHDIR variable to control changing to a
+ directory using the jar -C option.
+
+ - Add support for detecting Java manifest files when using jar,
+ and specifying them using the jar m flag.
+
+ - Fix some Python 2.2 specific things in various tool modules.
+
From Christian Engel:
- Support more flexible inclusion of separate C and C++ compilers.
0 on error.
"""
+ global SCons
import SCons.Script # really ugly, but we need BuildTask :-(
# Is it better to provide a seperate Task for SConf builds ?
class SConfBuildTask(SCons.Script.BuildTask):
import SCons.Builder
+def jarSources(target, source, env, for_signature):
+ """Only include sources that are not a manifest file."""
+ ret = []
+ for src in source:
+ contents = src.get_contents()
+ if contents[:16] != "Manifest-Version":
+ if env.has_key('JARCHDIR'):
+ # If we are changing the dir with -C, then sources should
+ # be relative to that directory.
+ ret.append(src.get_path(src.fs.Dir(env['JARCHDIR'])))
+ else:
+ ret.append(src)
+ return ret
+
+def jarManifest(target, source, env, for_signature):
+ """Look in sources for a manifest file, if any."""
+ for src in source:
+ contents = src.get_contents()
+ if contents[:16] == "Manifest-Version":
+ return src
+ return ''
+
+def jarFlags(target, source, env, for_signature):
+ """If we have a manifest, make sure that the 'm'
+ flag is specified."""
+ for src in source:
+ contents = src.get_contents()
+ if contents[:16] == "Manifest-Version":
+ if not 'm' in env['JARFLAGS']:
+ return env['JARFLAGS'] + 'm'
+ break
+ return env['JARFLAGS']
+
+def jarChdir(target, source, env, for_signature):
+ """If we have an Environment variable by the name
+ of JARCHDIR, then supply the command line option
+ '-C <dir>' to Jar."""
+ if env.has_key('JARCHDIR'):
+ return [ '-C', '$JARCHDIR' ]
+ return ''
+
JarBuilder = SCons.Builder.Builder(action = '$JARCOM',
source_factory = SCons.Node.FS.default_fs.Entry,
suffix = '$JARSUFFIX')
env['JAR'] = 'jar'
env['JARFLAGS'] = 'cf'
- env['JARCOM'] = '$JAR $JARFLAGS $TARGET $SOURCE'
+ env['_JARFLAGS'] = jarFlags
+ env['_JARMANIFEST'] = jarManifest
+ env['_JARSOURCES'] = jarSources
+ env['_JARCHDIR'] = jarChdir
+ env['JARCOM'] = '$JAR $_JARFLAGS $TARGET $_JARMANIFEST $_JARCHDIR $_JARSOURCES'
env['JARSUFFIX'] = '.jar'
def exists(env):
return env.Detect('lib')
else:
# there's at least one version of MSVS installed.
- return True
+ return 1
return env.Detect('link')
else:
# there's at least one version of MSVS installed.
- return True
+ return 1
return env.Detect('cl')
else:
# there's at least one version of MSVS installed.
- return True
+ return 1
'# End Project\n')
# now we pickle some data and add it to the file -- MSDEV will ignore it.
- pdata = pickle.dumps(self.configs,True)
+ pdata = pickle.dumps(self.configs,1)
pdata = base64.encodestring(pdata)
self.file.write(pdata + '\n')
- pdata = pickle.dumps(self.sources,True)
+ pdata = pickle.dumps(self.sources,1)
pdata = base64.encodestring(pdata)
self.file.write(pdata + '\n')
self.file.write('</VisualStudioProject>\n')
# now we pickle some data and add it to the file -- MSDEV will ignore it.
- pdata = pickle.dumps(self.configs,True)
+ pdata = pickle.dumps(self.configs,1)
pdata = base64.encodestring(pdata)
self.file.write('<!-- SCons Data:\n' + pdata + '\n')
- pdata = pickle.dumps(self.sources,True)
+ pdata = pickle.dumps(self.sources,1)
pdata = base64.encodestring(pdata)
self.file.write(pdata + '-->\n')
' GlobalSection(ExtensibilityAddIns) = postSolution\n'
' EndGlobalSection\n'
'EndGlobal\n')
- pdata = pickle.dumps(self.configs,True)
+ pdata = pickle.dumps(self.configs,1)
pdata = base64.encodestring(pdata)
self.file.write(pdata + '\n')
return env.Detect('msdev')
else:
# there's at least one version of MSVS installed.
- return True
+ return 1
return rv
def DummyExists(path):
- return True
+ return 1
class msvsTestCase(unittest.TestCase):
def test_get_default_visual_studio_version(self):
test.fail_test(test.read('test2.jar') != "test2.CLASS\nline 3\n")
+test.write('myjar2.py', r"""
+import sys
+import string
+f=open(sys.argv[2], 'wb')
+f.write(string.join(sys.argv[1:]))
+f.write("\n")
+f.close()
+sys.exit(0)
+""")
+
+test.write('SConstruct', """
+env = Environment(tools = ['jar'],
+ JAR = r'%s myjar2.py',
+ JARFLAGS='cvf')
+env.Jar(target = 'classes.jar', source = [ 'testdir/bar.class',
+ 'foo.mf' ],
+ JARCHDIR='testdir')
+""" % (python))
+
+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.fail_test(test.read('classes.jar') != 'cvfm classes.jar foo.mf -C testdir bar.class\n')
if not os.path.exists('/usr/local/j2sdk1.3.1/bin/javac'):
print "Could not find Java, skipping test(s)."