diff --git a/proposal/mutant/build.xml b/proposal/mutant/build.xml
index 0db43c459..960e22f66 100644
--- a/proposal/mutant/build.xml
+++ b/proposal/mutant/build.xml
@@ -77,14 +77,14 @@
-
+
-
+
@@ -199,7 +199,7 @@
.
*/
package org.apache.ant.init;
+import java.io.File;
+import java.net.MalformedURLException;
import java.net.URL;
-import java.io.File;
+import java.net.URLClassLoader;
/**
* InitConfig is the initialization configuration created to start Ant. This
@@ -64,6 +66,10 @@ import java.io.File;
* @created 9 January 2002
*/
public class InitConfig {
+
+ /** The default name of the jar containing the XML parser */
+ public static final String DEFAULT_PARSER_JAR = "crimson.jar";
+
/** The system classloader */
private ClassLoader systemLoader;
@@ -107,6 +113,59 @@ public class InitConfig {
/** The location of the user config file */
private File userConfigArea;
+ /**
+ * XXX Constructor for the InitConfig object
+ *
+ * @exception InitException XXX Description of Exception
+ */
+ public InitConfig() throws InitException {
+ try {
+ URL antLibURL = getAntLibURL();
+ setLibraryURL(antLibURL);
+
+ URL antHome = new URL(antLibURL, "..");
+ setAntHome(antHome);
+ if (antHome.getProtocol().equals("file")) {
+ File systemConfigArea = new File(antHome.getFile(), "conf");
+ setSystemConfigArea(systemConfigArea);
+ }
+ File userConfigArea
+ = new File(System.getProperty("user.home"), ".ant/conf");
+ setUserConfigArea(userConfigArea);
+
+ // set up the class loaders that will be used when running Ant
+ ClassLoader systemLoader = getClass().getClassLoader();
+ setSystemLoader(systemLoader);
+ URL toolsJarURL = ClassLocator.getToolsJarURL();
+ setToolsJarURL(toolsJarURL);
+
+ URL commonJarLib = new URL(libraryURL, "common/");
+ ClassLoader commonLoader
+ = new URLClassLoader(LoaderUtils.getLocationURLs(commonJarLib,
+ "common.jar"), systemLoader);
+ setCommonLoader(commonLoader);
+
+ // core needs XML parser for parsing various XML components.
+ URL parserBase = new URL(libraryURL, "parser/");
+ URL[] parserURLs
+ = LoaderUtils.getLocationURLs(parserBase, DEFAULT_PARSER_JAR);
+ setParserURLs(parserURLs);
+
+ URL[] coreURLs
+ = LoaderUtils.getLocationURLs(new URL(libraryURL, "antcore/"),
+ "antcore.jar");
+ URL[] combinedURLs = new URL[parserURLs.length + coreURLs.length];
+ System.arraycopy(coreURLs, 0, combinedURLs, 0, coreURLs.length);
+ System.arraycopy(parserURLs, 0, combinedURLs, coreURLs.length,
+ parserURLs.length);
+ ClassLoader coreLoader = new URLClassLoader(combinedURLs,
+ commonLoader);
+ setCoreLoader(coreLoader);
+ } catch (MalformedURLException e) {
+ throw new InitException(e);
+ }
+ }
+
/**
* Sets the location of the user configuration files
*
@@ -268,5 +327,24 @@ public class InitConfig {
public URL getLibraryURL() {
return libraryURL;
}
+
+ /**
+ * Get a URL to the Ant Library directory.
+ *
+ * @return the URL for the Ant library directory
+ * @throws MalformedURLException if there is a problem constructing the
+ * library URL
+ */
+ private URL getAntLibURL() throws MalformedURLException {
+ URL initClassURL = ClassLocator.getClassLocationURL(getClass());
+
+ String initURLString = initClassURL.toString();
+ int index = initURLString.lastIndexOf("/");
+ if (index != -1) {
+ initURLString = initURLString.substring(0, index + 1);
+ }
+
+ return new URL(initURLString);
+ }
}
diff --git a/proposal/mutant/src/java/start/org/apache/ant/start/Main.java b/proposal/mutant/src/java/start/org/apache/ant/start/Main.java
index 60a7c371d..25dc9e524 100755
--- a/proposal/mutant/src/java/start/org/apache/ant/start/Main.java
+++ b/proposal/mutant/src/java/start/org/apache/ant/start/Main.java
@@ -53,16 +53,10 @@
*/
package org.apache.ant.start;
-import java.io.File;
import java.lang.reflect.Method;
-import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
-import org.apache.ant.init.ClassLocator;
-import org.apache.ant.init.InitUtils;
import org.apache.ant.init.InitConfig;
-import org.apache.ant.init.InitException;
-import org.apache.ant.init.LoaderUtils;
/**
* This is the main startup class for the command line interface of Ant. It
@@ -76,46 +70,10 @@ public class Main {
public static final String COMMANDLINE_CLASS
= "org.apache.ant.cli.Commandline";
-
- /**
- * Get a URL to the Ant Library directory.
- *
- * @return the URL for the Ant library directory
- * @throws InitException if there is a problem constructing the library
- * URL
- */
- public static URL getLibraryURL()
- throws InitException {
- try {
- URL cliURL = ClassLocator.getClassLocationURL(Main.class);
-
- if (cliURL.getProtocol().equals("file")
- && cliURL.getFile().endsWith("/")) {
- // we are running from a set of classes. This should only
- // happen in an Ant build situation. We use some embedded
- // knowledge to locate the lib directory
- File classesDirectory = new File(cliURL.getFile());
- File libDirectory = new File(classesDirectory.getParent(),
- "lib");
- if (!libDirectory.exists()) {
- throw new RuntimeException("Ant library directory "
- + libDirectory + " does not exist");
- }
- return InitUtils.getFileURL(libDirectory);
- } else {
- String cliURLString = cliURL.toString();
- int index = cliURLString.lastIndexOf("/");
- if (index != -1) {
- cliURLString = cliURLString.substring(0, index + 1);
- }
- return new URL(cliURLString);
- }
- } catch (MalformedURLException e) {
- throw new InitException(e);
- }
- }
-
-
+
+ /** The default front end name */
+ public static final String DEFAULT_FRONTEND = "cli";
+
/**
* Entry point for starting command line Ant
*
@@ -123,92 +81,27 @@ public class Main {
*/
public static void main(String[] args) {
Main main = new Main();
- main.start(args);
+ main.start(DEFAULT_FRONTEND, args);
}
-
-
- /**
- * Get the location of AntHome
- *
- * @return the URL containing AntHome.
- * @throws InitException if Ant's home cannot be determined or properly
- * contructed.
- */
- private URL getAntHome()
- throws InitException {
- try {
- URL libraryURL = getLibraryURL();
- if (libraryURL != null) {
- return new URL(libraryURL, "..");
- }
- } catch (MalformedURLException e) {
- throw new InitException(e);
- }
- throw new InitException("Unable to determine Ant Home");
- }
-
-
/**
* Internal start method used to initialise front end
*
+ * @param frontend the frontend jar to launch
* @param args commandline arguments
*/
- private void start(String[] args) {
+ public void start(String frontend, String[] args) {
try {
InitConfig config = new InitConfig();
- URL libraryURL = getLibraryURL();
- config.setLibraryURL(libraryURL);
-
- URL antHome = getAntHome();
- config.setAntHome(antHome);
- if (antHome.getProtocol().equals("file")) {
- File systemConfigArea = new File(antHome.getFile(), "conf");
- config.setSystemConfigArea(systemConfigArea);
- }
- File userConfigArea
- = new File(System.getProperty("user.home"), ".ant/conf");
- config.setUserConfigArea(userConfigArea);
+ URL frontendJar = new URL(config.getLibraryURL(),
+ "frontend/" + frontend + ".jar");
+ URL[] frontendJars = new URL[]{frontendJar};
+ ClassLoader frontEndLoader
+ = new URLClassLoader(frontendJars, config.getCoreLoader());
- // set up the class loaders that will be used when running Ant
- ClassLoader systemLoader = getClass().getClassLoader();
- config.setSystemLoader(systemLoader);
- URL toolsJarURL = ClassLocator.getToolsJarURL();
- config.setToolsJarURL(toolsJarURL);
-
- URL commonJarLib = new URL(libraryURL, "common/");
- ClassLoader commonLoader
- = new URLClassLoader(LoaderUtils.getLocationURLs(commonJarLib,
- "common.jar"), systemLoader);
- config.setCommonLoader(commonLoader);
-
- // core needs XML parser for parsing various XML components.
- URL[] parserURLs
- = LoaderUtils.getLocationURLs(new URL(libraryURL, "parser/"),
- "crimson.jar");
- config.setParserURLs(parserURLs);
-
- URL[] coreURLs
- = LoaderUtils.getLocationURLs(new URL(libraryURL, "antcore/"),
- "antcore.jar");
- URL[] combinedURLs = new URL[parserURLs.length + coreURLs.length];
- System.arraycopy(coreURLs, 0, combinedURLs, 0, coreURLs.length);
- System.arraycopy(parserURLs, 0, combinedURLs, coreURLs.length,
- parserURLs.length);
- ClassLoader coreLoader = new URLClassLoader(combinedURLs,
- commonLoader);
- config.setCoreLoader(coreLoader);
-
- URL cliJarLib = new URL(libraryURL, "cli/");
- ClassLoader frontEndLoader
- = new URLClassLoader(LoaderUtils.getLocationURLs(cliJarLib,
- "cli.jar"), coreLoader);
-
- //System.out.println("System Loader config");
- //LoaderUtils.dumpLoader(System.out, systemLoader);
- // System.out.println("Front End Loader config");
- // LoaderUtils.dumpLoader(System.out, frontEndLoader);
+ //System.out.println("Front End Loader config");
+ //LoaderUtils.dumpLoader(System.out, frontEndLoader);
// Now start the front end by reflection.
Class commandLineClass = Class.forName(COMMANDLINE_CLASS, true,
@@ -220,7 +113,6 @@ public class Main {
= commandLineClass.getMethod("start", param);
final Object[] argument = {args, config};
startMethod.invoke(null, argument);
-
} catch (Exception e) {
e.printStackTrace();
}