diff --git a/WHATSNEW b/WHATSNEW index 10de3d127..57a3ba43f 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -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 =================================== diff --git a/src/main/org/apache/tools/ant/launch/Launcher.java b/src/main/org/apache/tools/ant/launch/Launcher.java index 03acf21ca..cd34d448f 100644 --- a/src/main/org/apache/tools/ant/launch/Launcher.java +++ b/src/main/org/apache/tools/ant/launch/Launcher.java @@ -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]); diff --git a/src/script/ant b/src/script/ant index 14fc59107..57c1e2a0a 100644 --- a/src/script/ant +++ b/src/script/ant @@ -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 diff --git a/src/script/ant.bat b/src/script/ant.bat index b8f4814ac..d61f4756e 100755 --- a/src/script/ant.bat +++ b/src/script/ant.bat @@ -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