bodewig 2004/02/05 05:09:28
Modified: src/main/org/apache/tools/ant/launch Launcher.java
src/script ant
Log:
Changes to make Ant installed in JPackage's RPM environment behave a
little bit more friendly.
* a new system property ant.lib.dir that if set will be used instead
of the location of ant-launcher.jar to slurp in the jars for Ant.
* a --noconfig switch that suppresses sourcing of additional
configuration files.
* various changes to the $rpm_mode specific parts of the file.
Submitted by: Randy Watler <rwatler at finali dot com>
Revision Changes Path
1.13 +15 -1 ant/src/main/org/apache/tools/ant/launch/Launcher.java
Index: Launcher.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/launch/Launcher.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Launcher.java 4 Feb 2004 20:37:24 -0000 1.12
+++ Launcher.java 5 Feb 2004 13:09:27 -0000 1.13
@@ -36,6 +36,9 @@
/** The Ant Home property */
public static final String ANTHOME_PROPERTY = "ant.home";
+ /** The Ant Library Directory property */
+ public static final String ANTLIBDIR_PROPERTY = "ant.library.dir";
+
/** The location of a per-user library directory */
public static final String USER_LIBDIR = ".ant/lib";
@@ -138,7 +141,18 @@
// Now try and find JAVA_HOME
File toolsJar = Locator.getToolsJar();
- URL[] systemJars = Locator.getLocationURLs(jarDir);
+ // determine ant library directory for system jars: use property
+ // or default using location of ant-launcher.jar
+ File antLibDir = null;
+ String antLibDirProperty = System.getProperty(ANTLIBDIR_PROPERTY);
+ if (antLibDirProperty != null) {
+ antLibDir = new File(antLibDirProperty);
+ }
+ if ((antLibDir == null) || ! antLibDir.exists()) {
+ antLibDir = jarDir;
+ System.setProperty(ANTLIBDIR_PROPERTY,
antLibDir.getAbsolutePath());
+ }
+ URL[] systemJars = Locator.getLocationURLs(antLibDir);
File userLibDir
= new File(System.getProperty("user.home"), USER_LIBDIR);
1.43 +127 -35 ant/src/script/ant
Index: ant
===================================================================
RCS file: /home/cvs/ant/src/script/ant,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -r1.42 -r1.43
--- ant 2 Feb 2004 19:30:05 -0000 1.42
+++ ant 5 Feb 2004 13:09:28 -0000 1.43
@@ -14,23 +14,64 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-# load system-wide ant configuration
-if [ -f "/etc/ant.conf" ] ; then
- . /etc/ant.conf
-fi
+# Extract launch and ant arguments, (see details below).
+ant_exec_args=
+no_config=false
+use_jikes_default=false
+ant_exec_debug=false
+show_help=false
+for arg in "$@" ; do
+ if [ "$arg" = "--noconfig" ] ; then
+ no_config=true
+ elif [ "$arg" = "--usejikes" ] ; then
+ use_jikes_default=true
+ elif [ "$arg" = "--execdebug" ] ; then
+ ant_exec_debug=true
+ elif [ "$arg" = "--h" -o "$arg" = "--help" ] ; then
+ show_help=true
+ ant_exec_args="$ant_exec_args -h"
+ else
+ if [ "$arg" = "-h" -o "$arg" = "-help" ] ; then
+ show_help=true
+ fi
+ ant_exec_args="$ant_exec_args \"$arg\""
+ fi
+done
-# provide default values for people who don't use RPMs
-if [ -z "$rpm_mode" ] ; then
- rpm_mode=false;
-fi
+# Source/default ant configuration
+if $no_config ; then
+ rpm_mode=false
+ usejikes=$use_jikes_default
+else
+ # load system-wide ant configuration
+ if [ -f "/etc/ant.conf" ] ; then
+ . /etc/ant.conf
+ fi
+
+ # load user ant configuration
+ if [ -f "$HOME/.ant/ant.conf" ] ; then
+ . $HOME/.ant/ant.conf
+ fi
+ if [ -f "$HOME/.antrc" ] ; then
+ . "$HOME/.antrc"
+ fi
-if [ -z "$usejikes" ] ; then
- usejikes=false;
+ # provide default configuration values
+ if [ -z "$rpm_mode" ] ; then
+ rpm_mode=false
+ fi
+ if [ -z "$usejikes" ] ; then
+ usejikes=$use_jikes_default
+ fi
fi
-# load user ant configuration
-if [ -f "$HOME/.antrc" ] ; then
- . "$HOME/.antrc"
+# Setup Java environment in rpm mode
+if $rpm_mode ; then
+ if [ -f /usr/share/java-utils/java-functions ] ; then
+ . /usr/share/java-utils/java-functions
+ set_jvm
+ set_javacmd
+ fi
fi
# OS specific support. $var _must_ be set to either true or false.
@@ -109,29 +150,58 @@
exit 1
fi
-# in rpm_mode get ant/optional/xml parser&api from JAVALIBDIR
-if $rpm_mode; then
- JAVALIBDIR=/usr/share/java
- for i in ant ant-optional jaxp_parser xml_apis
- do
- if [ -z "$LOCALCLASSPATH" ] ; then
- LOCALCLASSPATH="$JAVALIBDIR/$i.jar"
- else
- LOCALCLASSPATH="$JAVALIBDIR/$i.jar:$LOCALCLASSPATH"
+# Build local classpath using just the launcher in non-rpm mode or
+# use the Jpackage helper in rpm mode with basic and default jars
+# specified in the ant.conf configuration. Because the launcher is
+# used, libraries linked in ANT_HOME will also be include, but this
+# is discouraged as it is not java-version safe. A user should
+# request optional jars and their dependencies via the OPT_JAR_LIST
+# variable
+if $rpm_mode && [ -f /usr/bin/build-classpath ] ; then
+ LOCALCLASSPATH="$(/usr/bin/build-classpath ant ant-launcher
jaxp_parser_impl xml-commons-apis)"
+ # If the user requested to try to add some other jars to the classpath
+ if [ -n "$OPT_JAR_LIST" ] ; then
+ _OPTCLASSPATH="$(/usr/bin/build-classpath $OPT_JAR_LIST 2> /dev/null)"
+ if [ -n "$_OPTCLASSPATH" ] ; then
+ LOCALCLASSPATH="$LOCALCLASSPATH:$_OPTCLASSPATH"
fi
- done
+ fi
- # in rpm mode ant/lib is in /usr/share/java/ant
- ANT_LIB="${JAVALIBDIR}/ant"
-fi
+ # Explicitly add javac path to classpath, assume JAVA_HOME set
+ # properly in rpm mode
+ if [ -f "$JAVA_HOME/lib/tools.jar" ] ; then
+ LOCALCLASSPATH="$LOCALCLASSPATH:$JAVA_HOME/lib/tools.jar"
+ fi
+ if [ -f "$JAVA_HOME/lib/classes.zip" ] ; then
+ LOCALCLASSPATH="$LOCALCLASSPATH:$JAVA_HOME/lib/classes.zip"
+ fi
+
+ # if CLASSPATH_OVERRIDE env var is set, LOCALCLASSPATH will be
+ # user CLASSPATH first and ant-found jars after.
+ # In that case, the user CLASSPATH will override ant-found jars
+ #
+ # if CLASSPATH_OVERRIDE is not set, we'll have the normal behaviour
+ # with ant-found jars first and user CLASSPATH after
+ if [ -n "$CLASSPATH" -a -n "$CLASSPATH_OVERRIDE" ] ; then
+ # prepend local class path with class path override
+ if [ -z "$LOCALCLASSPATH" ] ; then
+ LOCALCLASSPATH="$CLASSPATH"
+ else
+ LOCALCLASSPATH="$CLASSPATH:$LOCALCLASSPATH"
+ fi
-if [ -z "$LOCALCLASSPATH" ] ; then
- LOCALCLASSPATH=$ANT_LIB/ant-launcher.jar
+ # remove class path from launcher -lib option
+ CLASSPATH=""
+ fi
else
- LOCALCLASSPATH=$ANT_LIB/ant-launcher.jar:$LOCALCLASSPATH
+ # not using rpm_mode; use launcher to determine classpaths
+ if [ -z "$LOCALCLASSPATH" ] ; then
+ LOCALCLASSPATH=$ANT_LIB/ant-launcher.jar
+ else
+ LOCALCLASSPATH=$ANT_LIB/ant-launcher.jar:$LOCALCLASSPATH
+ fi
fi
-
if [ -n "$JAVA_HOME" ] ; then
# OSX hack to make Ant work with jikes
if $darwin ; then
@@ -153,21 +223,43 @@
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
ANT_HOME=`cygpath --windows "$ANT_HOME"`
+ ANT_LIB=`cygpath --windows "$ANT_LIB"`
JAVA_HOME=`cygpath --windows "$JAVA_HOME"`
LOCALCLASSPATH=`cygpath --path --windows "$LOCALCLASSPATH"`
CYGHOME=`cygpath --windows "$HOME"`
fi
+# Show script help if requested
+if $show_help ; then
+ echo $0 '[script options] [options] [target [target2 [target3] ..]]'
+ echo 'Script Options:'
+ echo ' --help, --h print this message and ant help'
+ echo ' --noconfig suppress sourcing of /etc/ant.conf,'
+ echo ' $HOME/.ant/ant.conf, and $HOME/.antrc'
+ echo ' configuration files'
+ echo ' --usejikes enable use of jikes by default, unless'
+ echo ' set explicitly in configuration files'
+ echo ' --execdebug print ant exec line generated by this'
+ echo ' launch script'
+ echo ' '
+fi
+
+# Execute ant using eval/exec to preserve spaces in paths,
+# java options, and ant args
+ant_sys_opts=
if [ -n "$CYGHOME" ]; then
if [ -n "$JIKESPATH" ]; then
- exec "$JAVACMD" $ANT_OPTS -classpath "$LOCALCLASSPATH"
-Dant.home="${ANT_HOME}" -Djikes.class.path="$JIKESPATH"
-Dcygwin.user.home="$CYGHOME" org.apache.tools.ant.launch.Launcher $ANT_ARGS
-lib "$CLASSPATH" "$@"
+ ant_sys_opts="-Djikes.class.path=\"$JIKESPATH\"
-Dcygwin.user.home=\"$CYGHOME\""
else
- exec "$JAVACMD" $ANT_OPTS -classpath "$LOCALCLASSPATH"
-Dant.home="${ANT_HOME}" -Dcygwin.user.home="$CYGHOME"
org.apache.tools.ant.launch.Launcher $ANT_ARGS -lib "$CLASSPATH" "$@"
+ ant_sys_opts="-Dcygwin.user.home=\"$CYGHOME\""
fi
else
if [ -n "$JIKESPATH" ]; then
- exec "$JAVACMD" $ANT_OPTS -classpath "$LOCALCLASSPATH"
-Dant.home="${ANT_HOME}" -Djikes.class.path="$JIKESPATH"
org.apache.tools.ant.launch.Launcher $ANT_ARGS -lib "$CLASSPATH" "$@"
- else
- exec "$JAVACMD" $ANT_OPTS -classpath "$LOCALCLASSPATH"
-Dant.home="${ANT_HOME}" org.apache.tools.ant.launch.Launcher $ANT_ARGS -lib
"$CLASSPATH" "$@"
+ ant_sys_opts="-Djikes.class.path=\"$JIKESPATH\""
fi
fi
+ant_exec_command="exec \"$JAVACMD\" $ANT_OPTS -classpath \"$LOCALCLASSPATH\"
-Dant.home=\"$ANT_HOME\" -Dant.library.dir=\"$ANT_LIB\" $ant_sys_opts
org.apache.tools.ant.launch.Launcher $ANT_ARGS -lib \"$CLASSPATH\"
$ant_exec_args"
+if $ant_exec_debug ; then
+ echo $ant_exec_command
+fi
+eval $ant_exec_command
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]