Browse Source

add a -cp option to Launcher.java to cause it to

treat CLASSPATH different from -lib options.
PR: 28046


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276820 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 20 years ago
parent
commit
543344b839
4 changed files with 52 additions and 23 deletions
  1. +2
    -0
      WHATSNEW
  2. +46
    -19
      src/main/org/apache/tools/ant/launch/Launcher.java
  3. +2
    -2
      src/script/ant
  4. +2
    -2
      src/script/ant.bat

+ 2
- 0
WHATSNEW View File

@@ -88,6 +88,8 @@ Fixed bugs:

* Zip task was not zipping when only empty directories were found. Bugzilla 30365.

* Classpath was treated in the same way as -lib options. Bugzilla 28046.

Changes from Ant 1.6.1 to Ant 1.6.2
===================================



+ 46
- 19
src/main/org/apache/tools/ant/launch/Launcher.java View File

@@ -60,6 +60,34 @@ public class Launcher {
}
}

/**
* Add a CLASSPATH or -lib to lib path urls.
* @param path the classpath or lib path to add to the libPathULRLs
* @param getJars if true and a path is a directory, add the jars in
* the directory to the path urls
* @param libPathURLS the list of paths to add to
*/
private void addPath(String path, boolean getJars, List libPathURLs)
throws MalformedURLException {
StringTokenizer myTokenizer
= new StringTokenizer(path, System.getProperty("path.separator"));
while (myTokenizer.hasMoreElements()) {
String elementName = myTokenizer.nextToken();
File element = new File(elementName);
if (elementName.indexOf("%") != -1 && !element.exists()) {
continue;
}
if (getJars && element.isDirectory()) {
// add any jars in the directory
URL[] dirURLs = Locator.getLocationURLs(element);
for (int j = 0; j < dirURLs.length; ++j) {
libPathURLs.add(dirURLs[j]);
}
}

libPathURLs.add(element.toURL());
}
}

/**
* Run the launcher to launch Ant
@@ -91,6 +119,7 @@ public class Launcher {
}

List libPaths = new ArrayList();
String cpString = null;
List argList = new ArrayList();
String[] newArgs;

@@ -101,38 +130,36 @@ public class Launcher {
+ "be followed by a library location");
}
libPaths.add(args[++i]);
} else if (args[i].equals("-cp")) {
if (i == args.length - 1) {
throw new LaunchException("The -cp argument must "
+ "be followed by a classpath expression");
}
if (cpString != null) {
throw new LaunchException("The -cp argument must "
+ "not be repeated");
}
cpString = args[++i];
} else {
argList.add(args[i]);
}
}

if (libPaths.size() == 0) {
if (libPaths.size() == 0 && cpString == null) {
newArgs = args;
} else {
newArgs = (String[]) argList.toArray(new String[0]);
}

List libPathURLs = new ArrayList();

if (cpString != null) {
addPath(cpString, false, libPathURLs);
}

for (Iterator i = libPaths.iterator(); i.hasNext();) {
String libPath = (String) i.next();
StringTokenizer myTokenizer
= new StringTokenizer(libPath, System.getProperty("path.separator"));
while (myTokenizer.hasMoreElements()) {
String elementName = myTokenizer.nextToken();
File element = new File(elementName);
if (elementName.indexOf("%") != -1 && !element.exists()) {
continue;
}
if (element.isDirectory()) {
// add any jars in the directory
URL[] dirURLs = Locator.getLocationURLs(element);
for (int j = 0; j < dirURLs.length; ++j) {
libPathURLs.add(dirURLs[j]);
}
}

libPathURLs.add(element.toURL());
}
addPath(libPath, true, libPathURLs);
}

URL[] libJars = (URL[]) libPathURLs.toArray(new URL[0]);


+ 2
- 2
src/script/ant View File

@@ -192,7 +192,7 @@ if $rpm_mode && [ -f /usr/bin/build-classpath ] ; then
LOCALCLASSPATH="$LOCALCLASSPATH:$CLASSPATH"
fi

# remove class path from launcher -lib option
# remove class path from launcher -cp option
CLASSPATH=""
fi
else
@@ -295,7 +295,7 @@ else
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"
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 -cp \"$CLASSPATH\" $ant_exec_args"
if $ant_exec_debug ; then
echo $ant_exec_command
fi


+ 2
- 2
src/script/ant.bat View File

@@ -84,7 +84,7 @@ if not "%CLASSPATH%"=="" goto runAntWithClasspath
goto end

:runAntWithClasspath
"%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% -lib "%CLASSPATH%" %ANT_CMD_LINE_ARGS%
"%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% -cp "%CLASSPATH%" %ANT_CMD_LINE_ARGS%
goto end

:runAntWithJikes
@@ -93,7 +93,7 @@ if not "%CLASSPATH%"=="" goto runAntWithJikesAndClasspath
goto end

:runAntWithJikesAndClasspath
"%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" "-Djikes.class.path=%JIKESPATH%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% -lib "%CLASSPATH%" %ANT_CMD_LINE_ARGS%
"%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" "-Djikes.class.path=%JIKESPATH%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% -cp "%CLASSPATH%" %ANT_CMD_LINE_ARGS%
goto end

:end


Loading…
Cancel
Save