Browse Source

reorg of mutant's frontend

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272186 13f79535-47bb-0310-9956-ffa450edef68
master
Conor MacNeill 23 years ago
parent
commit
d9e6947368
4 changed files with 98 additions and 128 deletions
  1. +3
    -3
      proposal/mutant/build.xml
  2. +2
    -2
      proposal/mutant/src/java/bootstrap/org/apache/ant/builder/MutantBuilder.java
  3. +79
    -1
      proposal/mutant/src/java/init/org/apache/ant/init/InitConfig.java
  4. +14
    -122
      proposal/mutant/src/java/start/org/apache/ant/start/Main.java

+ 3
- 3
proposal/mutant/build.xml View File

@@ -77,14 +77,14 @@

<target name="cli" depends="antcore, start">
<mkdir dir="${bin.dir}/cli"/>
<mkdir dir="${distlib.dir}/cli"/>
<mkdir dir="${distlib.dir}/frontend"/>
<depend destdir="${bin.dir}/cli" srcdir="${java.dir}/cli">
<classpath refid="classpath.cli"/>
</depend>
<javac destdir="${bin.dir}/cli" srcdir="${java.dir}/cli" debug="${debug}">
<classpath refid="classpath.cli"/>
</javac>
<jar basedir="${bin.dir}/cli" jarfile="${distlib.dir}/cli/cli.jar"/>
<jar basedir="${bin.dir}/cli" jarfile="${distlib.dir}/frontend/cli.jar"/>
</target>

<target name="start" depends="init">
@@ -199,7 +199,7 @@
<mkdir dir="${javadocs.dir}"/>
<javadoc packagenames="org.apache.*"
useexternalfile="yes"
sourcepath="${java.dir}/antcore:${java.dir}/init:${java.dir}/common:${java.dir}/cli:${java.dir}/start"
sourcepath="${java.dir}/antcore:${java.dir}/init:${java.dir}/common:${java.dir}/frontend:${java.dir}/start"
destdir="${javadocs.dir}"
author="true"
private ="true"


+ 2
- 2
proposal/mutant/src/java/bootstrap/org/apache/ant/builder/MutantBuilder.java View File

@@ -51,9 +51,9 @@ public class MutantBuilder {
}
protected void cli(BuildHelper helper) {
helper.mkdir("${bin.dir}/cli");
helper.mkdir("${distlib.dir}/cli");
helper.mkdir("${distlib.dir}/frontend");
helper.javac("${java.dir}/cli", "${bin.dir}/cli", "classpath.cli");
helper.jar("${bin.dir}/cli", "${distlib.dir}/cli/cli.jar",
helper.jar("${bin.dir}/cli", "${distlib.dir}/frontend/cli.jar",
null, null);
}
protected void start(BuildHelper helper) {


+ 79
- 1
proposal/mutant/src/java/init/org/apache/ant/init/InitConfig.java View File

@@ -52,9 +52,11 @@
* <http://www.apache.org/>.
*/
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);
}
}


+ 14
- 122
proposal/mutant/src/java/start/org/apache/ant/start/Main.java View File

@@ -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();
}


Loading…
Cancel
Save