this command line argument is eaten by Launcher shell scripts reworked to pass the classpath in the right location git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275286 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -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. | * @param args the command line arguments. | ||||
| * | * | ||||
| @@ -57,6 +57,7 @@ import java.net.URL; | |||||
| import java.net.URLClassLoader; | import java.net.URLClassLoader; | ||||
| import java.net.MalformedURLException; | import java.net.MalformedURLException; | ||||
| import java.io.File; | import java.io.File; | ||||
| import java.util.StringTokenizer; | |||||
| /** | /** | ||||
| * This is a launcher for Ant. | * This is a launcher for Ant. | ||||
| @@ -117,6 +118,36 @@ public class Launcher { | |||||
| throw new IllegalStateException("Ant home is set incorrectly or " | throw new IllegalStateException("Ant home is set incorrectly or " | ||||
| + "ant could not be located"); | + "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 | // Now try and find JAVA_HOME | ||||
| @@ -129,13 +160,14 @@ public class Launcher { | |||||
| URL[] userJars = Locator.getLocationURLs(userLibDir); | URL[] userJars = Locator.getLocationURLs(userLibDir); | ||||
| int numJars = userJars.length + systemJars.length; | |||||
| int numJars = classPathJars.length + userJars.length + systemJars.length; | |||||
| if (toolsJar != null) { | if (toolsJar != null) { | ||||
| numJars++; | numJars++; | ||||
| } | } | ||||
| URL[] jars = new URL[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); | systemJars.length); | ||||
| if (toolsJar != null) { | if (toolsJar != null) { | ||||
| @@ -159,7 +191,7 @@ public class Launcher { | |||||
| try { | try { | ||||
| Class mainClass = loader.loadClass(MAIN_CLASS); | Class mainClass = loader.loadClass(MAIN_CLASS); | ||||
| AntMain main = (AntMain) mainClass.newInstance(); | AntMain main = (AntMain) mainClass.newInstance(); | ||||
| main.startAnt(args, null, null); | |||||
| main.startAnt(newargs, null, null); | |||||
| } catch (Throwable t) { | } catch (Throwable t) { | ||||
| t.printStackTrace(); | t.printStackTrace(); | ||||
| } | } | ||||
| @@ -100,10 +100,6 @@ if [ ! -x "$JAVACMD" ] ; then | |||||
| exit 1 | exit 1 | ||||
| fi | fi | ||||
| if [ -n "$CLASSPATH" ] ; then | |||||
| LOCALCLASSPATH="$CLASSPATH" | |||||
| fi | |||||
| # in rpm_mode get ant/optional/xml parser&api from JAVALIBDIR | # in rpm_mode get ant/optional/xml parser&api from JAVALIBDIR | ||||
| if $rpm_mode; then | if $rpm_mode; then | ||||
| JAVALIBDIR=/usr/share/java | JAVALIBDIR=/usr/share/java | ||||
| @@ -156,14 +152,14 @@ fi | |||||
| if [ -n "$CYGHOME" ]; then | if [ -n "$CYGHOME" ]; then | ||||
| if [ -n "$JIKESPATH" ]; 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 | 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 | fi | ||||
| else | else | ||||
| if [ -n "$JIKESPATH" ]; then | 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 | 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 | ||||
| fi | fi | ||||
| @@ -54,7 +54,7 @@ goto end | |||||
| :checkJava | :checkJava | ||||
| set _JAVACMD=%JAVACMD% | 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 "%JAVA_HOME%" == "" goto noJavaHome | ||||
| if not exist "%JAVA_HOME%\bin\java.exe" 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 | if not "%JIKESPATH%"=="" goto runAntWithJikes | ||||
| :runAnt | :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% | "%_JAVACMD%" %ANT_OPTS% -classpath "%LOCALCLASSPATH%" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% %ANT_CMD_LINE_ARGS% | ||||
| goto end | 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 | :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% | "%_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 | 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 | :end | ||||
| set LOCALCLASSPATH= | set LOCALCLASSPATH= | ||||
| set _JAVACMD= | set _JAVACMD= | ||||
| @@ -39,7 +39,7 @@ use strict; | |||||
| #use warnings; | #use warnings; | ||||
| #and set $debug to 1 to turn on trace info | #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 | #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 | #set JVM options and Ant arguments, if any | ||||
| my @ANT_OPTS=split(" ", $ENV{ANT_OPTS}); | my @ANT_OPTS=split(" ", $ENV{ANT_OPTS}); | ||||
| my @ANT_ARGS=split(" ", $ENV{ANT_ARGS}); | my @ANT_ARGS=split(" ", $ENV{ANT_ARGS}); | ||||
| @@ -110,25 +91,21 @@ push @ARGS, @ANT_OPTS; | |||||
| my $CYGHOME = ""; | my $CYGHOME = ""; | ||||
| my $classpath=$ENV{CLASSPATH}; | |||||
| if ($oncygwin == 1) { | if ($oncygwin == 1) { | ||||
| $localpath = `cygpath --path --windows $localpath`; | $localpath = `cygpath --path --windows $localpath`; | ||||
| chomp ($localpath); | chomp ($localpath); | ||||
| if (! $classpath eq "") | |||||
| { | |||||
| $classpath = `cygpath --path --windows "$classpath"`; | |||||
| chomp ($classpath); | |||||
| } | |||||
| $HOME = `cygpath --path --windows $HOME`; | $HOME = `cygpath --path --windows $HOME`; | ||||
| chomp ($HOME); | chomp ($HOME); | ||||
| $CYGHOME = `cygpath --path --windows $ENV{HOME}`; | $CYGHOME = `cygpath --path --windows $ENV{HOME}`; | ||||
| chomp ($CYGHOME); | 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"; | push @ARGS, "-Dant.home=$HOME"; | ||||
| if ( ! $CYGHOME eq "" ) | if ( ! $CYGHOME eq "" ) | ||||
| { | { | ||||
| @@ -136,7 +113,20 @@ if ( ! $CYGHOME eq "" ) | |||||
| } | } | ||||
| push @ARGS, "org.apache.tools.ant.launch.Launcher", @ANT_ARGS; | push @ARGS, "org.apache.tools.ant.launch.Launcher", @ANT_ARGS; | ||||
| push @ARGS, @ARGV; | 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); | print "\n $JAVACMD @ARGS\n\n" if ($debug); | ||||
| my $returnValue = system $JAVACMD, @ARGS; | my $returnValue = system $JAVACMD, @ARGS; | ||||