diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index c8aa58b8c..e355c883d 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -290,7 +290,8 @@ public class Main implements AntMain { } /** - * Process command line arguments + * Process command line arguments. + * When ant is started from Launcher, the -lib argument does not get passed through to this routine. * * @param args the command line arguments. * diff --git a/src/main/org/apache/tools/ant/launch/Launcher.java b/src/main/org/apache/tools/ant/launch/Launcher.java index 4dc5eaa4d..bbeeb9494 100644 --- a/src/main/org/apache/tools/ant/launch/Launcher.java +++ b/src/main/org/apache/tools/ant/launch/Launcher.java @@ -57,6 +57,7 @@ import java.net.URL; import java.net.URLClassLoader; import java.net.MalformedURLException; import java.io.File; +import java.util.StringTokenizer; /** * This is a launcher for Ant. @@ -117,6 +118,36 @@ public class Launcher { throw new IllegalStateException("Ant home is set incorrectly or " + "ant could not be located"); } + String libPath = ""; + String[] newargs = null; + int argcount = -1; + for (argcount = 0; argcount < args.length -1; argcount++) { + if (args[argcount].equals("-lib")) { + libPath = args[argcount + 1]; + break; + } + } + if (libPath.equals("")) { + newargs = new String[args.length]; + System.arraycopy(args, 0, newargs, 0, args.length); + } else { + newargs = new String[args.length - 2]; + // copy the beginning of the args array + if (argcount > 0 ) { + System.arraycopy(args, 0, newargs, 0 ,argcount); + } + // copy the end of the args array + if ((argcount + 2 < args.length) && argcount > 0) { + System.arraycopy(args, argcount + 2, newargs, argcount, args.length - (argcount + 2)); + } + } + StringTokenizer myTokenizer = new StringTokenizer(libPath, System.getProperty("path.separator")); + URL[] classPathJars = new URL[myTokenizer.countTokens()]; + int classPathJarCount = 0; + while (myTokenizer.hasMoreElements()) { + String token = myTokenizer.nextToken(); + classPathJars[classPathJarCount++] = new File(token).toURL(); + } // Now try and find JAVA_HOME @@ -129,13 +160,14 @@ public class Launcher { URL[] userJars = Locator.getLocationURLs(userLibDir); - int numJars = userJars.length + systemJars.length; + int numJars = classPathJars.length + userJars.length + systemJars.length; if (toolsJar != null) { numJars++; } URL[] jars = new URL[numJars]; - System.arraycopy(userJars, 0, jars, 0, userJars.length); - System.arraycopy(systemJars, 0, jars, userJars.length, + System.arraycopy(classPathJars, 0, jars, 0, classPathJars.length); + System.arraycopy(userJars, 0, jars, classPathJars.length, userJars.length); + System.arraycopy(systemJars, 0, jars, userJars.length + classPathJars.length, systemJars.length); if (toolsJar != null) { @@ -159,7 +191,7 @@ public class Launcher { try { Class mainClass = loader.loadClass(MAIN_CLASS); AntMain main = (AntMain) mainClass.newInstance(); - main.startAnt(args, null, null); + main.startAnt(newargs, null, null); } catch (Throwable t) { t.printStackTrace(); } diff --git a/src/script/ant b/src/script/ant index b383d44cc..794523d9f 100644 --- a/src/script/ant +++ b/src/script/ant @@ -100,10 +100,6 @@ if [ ! -x "$JAVACMD" ] ; then exit 1 fi -if [ -n "$CLASSPATH" ] ; then - LOCALCLASSPATH="$CLASSPATH" -fi - # in rpm_mode get ant/optional/xml parser&api from JAVALIBDIR if $rpm_mode; then JAVALIBDIR=/usr/share/java @@ -156,14 +152,14 @@ fi 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 "$@" + 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" else - exec "$JAVACMD" $ANT_OPTS -classpath "$LOCALCLASSPATH" -Dant.home="${ANT_HOME}" -Dcygwin.user.home="$CYGHOME" org.apache.tools.ant.launch.Launcher $ANT_ARGS "$@" + exec "$JAVACMD" $ANT_OPTS -classpath "$LOCALCLASSPATH" -Dant.home="${ANT_HOME}" -Dcygwin.user.home="$CYGHOME" org.apache.tools.ant.launch.Launcher $ANT_ARGS "$@" -lib "$CLASSPATH" 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 "$@" + 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 "$@" + exec "$JAVACMD" $ANT_OPTS -classpath "$LOCALCLASSPATH" -Dant.home="${ANT_HOME}" org.apache.tools.ant.launch.Launcher $ANT_ARGS "$@" -lib "$CLASSPATH" fi fi diff --git a/src/script/ant.bat b/src/script/ant.bat index 6075466d9..8660f9f02 100755 --- a/src/script/ant.bat +++ b/src/script/ant.bat @@ -54,7 +54,7 @@ goto end :checkJava set _JAVACMD=%JAVACMD% -set LOCALCLASSPATH=%ANT_HOME%\lib\ant-launcher.jar;%CLASSPATH% +set LOCALCLASSPATH=%ANT_HOME%\lib\ant-launcher.jar if "%JAVA_HOME%" == "" goto noJavaHome if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome @@ -68,13 +68,23 @@ if "%_JAVACMD%" == "" set _JAVACMD=java.exe if not "%JIKESPATH%"=="" goto runAntWithJikes :runAnt +if not "%CLASSPATH%"=="" goto runAntWithClasspath "%_JAVACMD%" %ANT_OPTS% -classpath "%LOCALCLASSPATH%" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% %ANT_CMD_LINE_ARGS% goto end +:runAntWithClasspath +"%_JAVACMD%" %ANT_OPTS% -classpath "%LOCALCLASSPATH%" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% %ANT_CMD_LINE_ARGS% -lib "%CLASSPATH%" +goto end + :runAntWithJikes +if not "%CLASSPATH%"=="" goto runAntWithJikesAndClasspath "%_JAVACMD%" %ANT_OPTS% -classpath "%LOCALCLASSPATH%" "-Dant.home=%ANT_HOME%" "-Djikes.class.path=%JIKESPATH%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% %ANT_CMD_LINE_ARGS% goto end +:runAntWithJikesAndClasspath +"%_JAVACMD%" %ANT_OPTS% -classpath "%LOCALCLASSPATH%" "-Dant.home=%ANT_HOME%" "-Djikes.class.path=%JIKESPATH%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% %ANT_CMD_LINE_ARGS% -lib "%CLASSPATH%" +goto end + :end set LOCALCLASSPATH= set _JAVACMD= diff --git a/src/script/runant.pl b/src/script/runant.pl index 80fb2b10b..5232a9db5 100644 --- a/src/script/runant.pl +++ b/src/script/runant.pl @@ -39,7 +39,7 @@ use strict; #use warnings; #and set $debug to 1 to turn on trace info -my $debug=0; +my $debug=1; ####################################################################### # @@ -74,26 +74,7 @@ if(($^O eq "MSWin32") || ($^O eq "dos") || ($^O eq "cygwin") || } #build up standard classpath -my $localpath=$ENV{CLASSPATH}; -if ($localpath eq "") - { - print "warning: no initial classpath\n" if ($debug); - $localpath=""; - } -if ($onnetware == 1) -{ -# avoid building a command line bigger than 512 characters - make localpath -# only include the "extra" stuff, and add in the system classpath as an expanded -# variable. - $localpath=""; -} - -if ($localpath eq "") { - $localpath = "$HOME/lib/ant-launcher.jar"; -} else { - $localpath = "$HOME/lib/ant-launcher.jar$s$localpath"; -} - +my $localpath = "$HOME/lib/ant-launcher.jar"; #set JVM options and Ant arguments, if any my @ANT_OPTS=split(" ", $ENV{ANT_OPTS}); my @ANT_ARGS=split(" ", $ENV{ANT_ARGS}); @@ -110,25 +91,21 @@ push @ARGS, @ANT_OPTS; my $CYGHOME = ""; +my $classpath=$ENV{CLASSPATH}; if ($oncygwin == 1) { $localpath = `cygpath --path --windows $localpath`; chomp ($localpath); + if (! $classpath eq "") + { + $classpath = `cygpath --path --windows "$classpath"`; + chomp ($classpath); + } $HOME = `cygpath --path --windows $HOME`; chomp ($HOME); $CYGHOME = `cygpath --path --windows $ENV{HOME}`; chomp ($CYGHOME); } -if ($onnetware == 1) -{ -# make classpath literally $CLASSPATH; and then the contents of $localpath -# this is to avoid pushing us over the 512 character limit -# even skip the ; - that is already in $localpath - push @ARGS, "-classpath", "\$CLASSPATH$localpath"; -} -else -{ - push @ARGS, "-classpath", "$localpath"; -} +push @ARGS, "-classpath", "$localpath"; push @ARGS, "-Dant.home=$HOME"; if ( ! $CYGHOME eq "" ) { @@ -136,7 +113,20 @@ if ( ! $CYGHOME eq "" ) } push @ARGS, "org.apache.tools.ant.launch.Launcher", @ANT_ARGS; push @ARGS, @ARGV; - +if (! $classpath eq "") +{ + if ($onnetware == 1) + { + # make classpath literally $CLASSPATH + # this is to avoid pushing us over the 512 character limit + # even skip the ; - that is already in $localpath + push @ARGS, "-lib", "\$CLASSPATH"; + } + else + { + push @ARGS, "-lib", "$classpath"; + } +} print "\n $JAVACMD @ARGS\n\n" if ($debug); my $returnValue = system $JAVACMD, @ARGS;