@@ -58,6 +58,10 @@ import java.net.URLClassLoader;
import java.net.MalformedURLException;
import java.net.MalformedURLException;
import java.io.File;
import java.io.File;
import java.util.StringTokenizer;
import java.util.StringTokenizer;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
/**
/**
* This is a launcher for Ant.
* This is a launcher for Ant.
@@ -118,43 +122,48 @@ 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;
List libPaths = new ArrayList();
List argList = new ArrayList();
String[] newArgs;
for (int i = 0; i < args.length; ++i) {
if (args[i].equals("-lib")) {
if (i == args.length - 1) {
throw new IllegalStateException("The -lib argument must "
+ "be followed by a library location");
}
libPaths.add(args[++i]);
} else {
argList.add(args[i]);
}
}
}
}
if (args.length > 0 && args[args.length -1].equals("-lib")) {
// if the last argument is -lib
// remove it from the arguments passed to Launcher
//
newargs = new String[args.length - 1];
System.arraycopy(args, 0, newargs, 0, args.length -1);
} else 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));
}
if (libPaths.size() == 0) {
newArgs = args;
} else {
newArgs = (String[]) argList.toArray(new String[0]);
}
}
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();
List libPathURLs = new ArrayList();
for (Iterator i = libPaths.iterator(); i.hasNext();) {
String libPath = (String) i.next();
StringTokenizer myTokenizer
= new StringTokenizer(libPath, System.getProperty("path.separator"));
while (myTokenizer.hasMoreElements()) {
File element = new File(myTokenizer.nextToken());
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());
}
}
}
URL[] libJars = (URL[])libPathURLs.toArray(new URL[0]);
// Now try and find JAVA_HOME
// Now try and find JAVA_HOME
File toolsJar = Locator.getToolsJar();
File toolsJar = Locator.getToolsJar();
@@ -166,14 +175,14 @@ public class Launcher {
URL[] userJars = Locator.getLocationURLs(userLibDir);
URL[] userJars = Locator.getLocationURLs(userLibDir);
int numJars = classPath Jars.length + userJars.length + systemJars.length;
int numJars = lib Jars.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(classPathJars, 0, jars, 0, classPath Jars.length);
System.arraycopy(userJars, 0, jars, classPath Jars.length, userJars.length);
System.arraycopy(systemJars, 0, jars, userJars.length + classPath Jars.length,
System.arraycopy(libJars, 0, jars, 0, lib Jars.length);
System.arraycopy(userJars, 0, jars, lib Jars.length, userJars.length);
System.arraycopy(systemJars, 0, jars, userJars.length + lib Jars.length,
systemJars.length);
systemJars.length);
if (toolsJar != null) {
if (toolsJar != null) {
@@ -184,6 +193,10 @@ public class Launcher {
// now update the class.path property
// now update the class.path property
StringBuffer baseClassPath
StringBuffer baseClassPath
= new StringBuffer(System.getProperty("java.class.path"));
= new StringBuffer(System.getProperty("java.class.path"));
if (baseClassPath.charAt(baseClassPath.length() - 1)
== File.pathSeparatorChar) {
baseClassPath.setLength(baseClassPath.length() - 1);
}
for (int i = 0; i < jars.length; ++i) {
for (int i = 0; i < jars.length; ++i) {
baseClassPath.append(File.pathSeparatorChar);
baseClassPath.append(File.pathSeparatorChar);
@@ -197,7 +210,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(newa rgs, null, null);
main.startAnt(newA rgs, null, null);
} catch (Throwable t) {
} catch (Throwable t) {
t.printStackTrace();
t.printStackTrace();
}
}