You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@apache.org on 2002/04/04 06:36:14 UTC
cvs commit: jakarta-ant/proposal/mutant/src/java/start/org/apache/tools/ant Main.java
conor 02/04/03 20:36:14
Modified: proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser
BuildElementHandler.java ProjectHandler.java
TargetHandler.java
proposal/mutant/src/java/antcore/org/apache/ant/antcore/xml
RootHandler.java
proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/taskdefs
Ant.java
proposal/mutant/src/java/common/org/apache/ant/common/model
ModelElement.java
proposal/mutant/src/java/common/org/apache/ant/common/util
Location.java
proposal/mutant/src/java/init/org/apache/ant/init
InitConfig.java
proposal/mutant/src/java/start/org/apache/ant/start
Main.java
proposal/mutant/src/java/start/org/apache/tools/ant
Main.java
Added: proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser
ModelElementHandler.java
Log:
Minor cleanups
Revision Changes Path
1.3 +3 -3 jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/BuildElementHandler.java
Index: BuildElementHandler.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/BuildElementHandler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -u -r1.2 -r1.3
--- BuildElementHandler.java 18 Mar 2002 02:44:25 -0000 1.2
+++ BuildElementHandler.java 4 Apr 2002 04:36:13 -0000 1.3
@@ -55,7 +55,6 @@
import java.util.Iterator;
import org.apache.ant.common.model.BuildElement;
-import org.apache.ant.antcore.xml.ElementHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXParseException;
@@ -66,7 +65,7 @@
* @author Conor MacNeill
* @created 9 January 2002
*/
-public class BuildElementHandler extends ElementHandler {
+public class BuildElementHandler extends ModelElementHandler {
/** The task element being parsed by this handler. */
private BuildElement buildElement;
@@ -87,6 +86,7 @@
public void processElement(String elementName) {
buildElement
= new BuildElement(getLocation(), elementName);
+ setModelElement(buildElement);
for (Iterator i = getAttributes(); i.hasNext(); ) {
String attributeName = (String)i.next();
1.5 +3 -3 jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/ProjectHandler.java
Index: ProjectHandler.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/ProjectHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -u -r1.4 -r1.5
--- ProjectHandler.java 18 Mar 2002 02:44:25 -0000 1.4
+++ ProjectHandler.java 4 Apr 2002 04:36:13 -0000 1.5
@@ -54,7 +54,6 @@
package org.apache.ant.antcore.modelparser;
import org.apache.ant.common.model.ModelException;
import org.apache.ant.common.model.Project;
-import org.apache.ant.antcore.xml.ElementHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXParseException;
@@ -66,7 +65,7 @@
* @author Conor MacNeill
* @created 9 January 2002
*/
-public class ProjectHandler extends ElementHandler {
+public class ProjectHandler extends ModelElementHandler {
/** The basedir attribute tag */
public static final String BASEDIR_ATTR = "basedir";
@@ -129,6 +128,7 @@
throws SAXParseException {
if (project == null) {
project = new Project(getElementSource(), getLocation());
+ setModelElement(project);
project.setDefaultTarget(getAttribute(DEFAULT_ATTR));
project.setBase(getAttribute(BASEDIR_ATTR));
1.5 +2 -2 jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/TargetHandler.java
Index: TargetHandler.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/TargetHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -u -r1.4 -r1.5
--- TargetHandler.java 18 Mar 2002 02:44:25 -0000 1.4
+++ TargetHandler.java 4 Apr 2002 04:36:13 -0000 1.5
@@ -55,7 +55,6 @@
import java.util.StringTokenizer;
import org.apache.ant.common.model.Target;
-import org.apache.ant.antcore.xml.ElementHandler;
import org.xml.sax.Attributes;
import org.xml.sax.SAXParseException;
@@ -65,7 +64,7 @@
* @author Conor MacNeill
* @created 9 January 2002
*/
-public class TargetHandler extends ElementHandler {
+public class TargetHandler extends ModelElementHandler {
/** The name attribute */
public static final String NAME_ATTR = "name";
@@ -104,6 +103,7 @@
public void processElement(String elementName)
throws SAXParseException {
target = new Target(getLocation(), getAttribute(NAME_ATTR));
+ setModelElement(target);
target.setDescription(getAttribute(DESC_ATTR));
target.setAspects(getAspects());
1.1 jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/modelparser/ModelElementHandler.java
Index: ModelElementHandler.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.ant.antcore.modelparser;
import org.apache.ant.antcore.xml.ElementHandler;
import org.apache.ant.common.model.ModelElement;
/**
* A BuildElementHandler parses the task elements of a build. Task elements
* include tasks themselves plus all their nested elements to any depth.
*
* @author Conor MacNeill
* @created 9 January 2002
*/
public abstract class ModelElementHandler extends ElementHandler {
/** The model element being parsed by this handler. */
private ModelElement modelElement;
/**
* Set the model element being handled by this handler
*
* @param modelElement The new modelElement value
*/
protected void setModelElement(ModelElement modelElement) {
this.modelElement = modelElement;
}
/** Set the end location of the element. */
protected void finish() {
if (modelElement != null) {
modelElement.setEndLocation(getLocation());
}
}
}
1.4 +2 -2 jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/xml/RootHandler.java
Index: RootHandler.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/xml/RootHandler.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -u -r1.3 -r1.4
--- RootHandler.java 18 Mar 2002 02:44:25 -0000 1.3
+++ RootHandler.java 4 Apr 2002 04:36:13 -0000 1.4
@@ -122,8 +122,8 @@
/**
- * Start a new element in the root. This must be a project element All
- * other elements are invalid.
+ * Start a new element in the root. This must be an allowed root element.
+ * All other elements are invalid.
*
* @param uri The Namespace URI.
* @param localName The local name (without prefix).
1.5 +3 -2 jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/taskdefs/Ant.java
Index: Ant.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/taskdefs/Ant.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -u -r1.4 -r1.5
--- Ant.java 18 Mar 2002 02:44:26 -0000 1.4
+++ Ant.java 4 Apr 2002 04:36:13 -0000 1.5
@@ -131,7 +131,7 @@
}
/**
- * XXX Sets the output of the Ant
+ * Set the output file in which Ant stores output
*
* @param s name of the file to store output.
*/
@@ -158,7 +158,8 @@
/**
* Do the execution.
*
- * @exception BuildException XXX Description of Exception
+ * @exception BuildException if the execution of the sub-build has a
+ * problem
*/
public void execute() throws BuildException {
for (Iterator i = properties.iterator(); i.hasNext(); ) {
1.3 +23 -2 jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/model/ModelElement.java
Index: ModelElement.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/model/ModelElement.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -u -r1.2 -r1.3
--- ModelElement.java 18 Mar 2002 02:44:27 -0000 1.2
+++ ModelElement.java 4 Apr 2002 04:36:13 -0000 1.3
@@ -70,8 +70,11 @@
/** The aspects defined for this element. */
private Map aspectMaps;
- /** The location of this element */
- private Location location;
+ /** The starting location of this element */
+ private Location location = Location.UNKNOWN_LOCATION;
+
+ /** The ending location of this element */
+ private Location endLocation = Location.UNKNOWN_LOCATION;
/** A comment associated with this element, if any */
private String comment;
@@ -95,6 +98,15 @@
}
/**
+ * Set the end location of this element
+ *
+ * @param endLocation the location where this element's definition ends
+ */
+ public void setEndLocation(Location endLocation) {
+ this.endLocation = endLocation;
+ }
+
+ /**
* Set the aspects of this element
*
* @param aspects a Map of apects that relate to this model element.
@@ -126,6 +138,15 @@
*/
public Location getLocation() {
return location;
+ }
+
+ /**
+ * Get the location of the source where this element's definition fiunishes
+ *
+ * @return the element's end location
+ */
+ public Location getEndLocation() {
+ return endLocation;
}
/**
1.6 +1 -0 jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/util/Location.java
Index: Location.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/common/org/apache/ant/common/util/Location.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -u -r1.5 -r1.6
--- Location.java 18 Mar 2002 02:44:27 -0000 1.5
+++ Location.java 4 Apr 2002 04:36:13 -0000 1.6
@@ -63,6 +63,7 @@
/** Standard unknown location constant; */
public static final Location UNKNOWN_LOCATION = new Location();
+
/** The source URL to which this location relates. */
private String source;
1.6 +2 -2 jakarta-ant/proposal/mutant/src/java/init/org/apache/ant/init/InitConfig.java
Index: InitConfig.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/init/org/apache/ant/init/InitConfig.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -u -r1.5 -r1.6
--- InitConfig.java 3 Apr 2002 15:02:47 -0000 1.5
+++ InitConfig.java 4 Apr 2002 04:36:13 -0000 1.6
@@ -114,9 +114,9 @@
private File userConfigArea;
/**
- * XXX Constructor for the InitConfig object
+ * Constructor for the Initialization configuration
*
- * @exception InitException XXX Description of Exception
+ * @exception InitException if the configuration cannot be initialized
*/
public InitConfig() throws InitException {
try {
1.10 +143 -85 jakarta-ant/proposal/mutant/src/java/start/org/apache/ant/start/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/start/org/apache/ant/start/Main.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -w -u -r1.9 -r1.10
--- Main.java 3 Apr 2002 15:49:06 -0000 1.9
+++ Main.java 4 Apr 2002 04:36:13 -0000 1.10
@@ -57,10 +57,12 @@
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
-import java.util.jar.Manifest;
import java.util.jar.Attributes;
import java.util.jar.JarInputStream;
+import java.util.jar.Manifest;
import org.apache.ant.init.InitConfig;
+import org.apache.ant.init.InitException;
+import java.io.File;
/**
* This is the main startup class for the command line interface of Ant. It
@@ -77,23 +79,61 @@
/** The default front end name */
public static final String DEFAULT_FRONTEND = "cli";
+
/**
* Entry point for starting command line Ant
*
* @param args commandline arguments
+ * @exception Exception if there is a problem running Ant
*/
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
Main main = new Main();
- main.start(DEFAULT_FRONTEND, args);
+ int frontendIndex = -1;
+ String frontend = DEFAULT_FRONTEND;
+
+ for (int i = 0; i < args.length; ++i) {
+ if (args[i].equals("-frontend")) {
+ frontendIndex = i;
+ break;
+ }
+ }
+
+ if (frontendIndex != -1) {
+ try {
+ frontend = args[frontendIndex + 1];
+ } catch (IndexOutOfBoundsException e) {
+ throw new InitException("You must specify a value for the "
+ + "-frontend argument");
+ }
+
+ String[] newArgs = new String[args.length - 2];
+
+ System.arraycopy(args, 0, newArgs, 0, frontendIndex);
+ if (args.length > (frontendIndex + 2)) {
+ System.arraycopy(args, frontendIndex + 2, newArgs,
+ frontendIndex, args.length - frontendIndex - 2);
+ }
+ args = newArgs;
+ }
+
+ String defaultClass = frontend.equals(DEFAULT_FRONTEND)
+ ? DEFAULT_COMMANDLINE_CLASS : null;
+
+ main.start(frontend, defaultClass, args);
}
+
/**
* Internal start method used to initialise front end
*
* @param frontend the frontend jar to launch
* @param args commandline arguments
+ * @param defaultClass the default class to use if it cannot be determined
+ * from the jar itself
+ * @exception InitException if the front end cannot be started
*/
- public void start(String frontend, String[] args) {
+ public void start(String frontend, String defaultClass, String[] args)
+ throws InitException {
try {
InitConfig config = new InitConfig();
@@ -106,44 +146,62 @@
//System.out.println("Front End Loader config");
//LoaderUtils.dumpLoader(System.out, frontEndLoader);
+ if (frontendJar.getProtocol().equals("file")) {
+ File jarFile = new File(frontendJar.getFile());
+ if (!jarFile.exists()) {
+ throw new InitException("Could not jar for frontend \""
+ + frontend + "\"");
+ }
+ }
String mainClass = getMainClass(frontendJar);
- System.out.println("Front end main class = " + mainClass);
+
+ if (mainClass == null) {
+ mainClass = defaultClass;
+ }
+
if (mainClass == null) {
- mainClass = DEFAULT_COMMANDLINE_CLASS;
+ throw new InitException("Unable to determine main class "
+ + " for \"" + frontend + "\" frontend");
}
// Now start the front end by reflection.
- Class commandLineClass = Class.forName(mainClass, true,
+ Class frontendClass = Class.forName(mainClass, true,
frontEndLoader);
final Class[] param = {Class.forName("[Ljava.lang.String;"),
InitConfig.class};
final Method startMethod
- = commandLineClass.getMethod("start", param);
+ = frontendClass.getMethod("start", param);
final Object[] argument = {args, config};
+
startMethod.invoke(null, argument);
} catch (Exception e) {
- e.printStackTrace();
+ throw new InitException(e);
}
}
+
/**
* Pick up the main class from a jar's manifest
*
* @param jarURL the URL to the jar
- * @return the jar's main-class or null if it is not specified or cannot be
- * determined.
+ * @return the jar's main-class or null if it is not specified or
+ * cannot be determined.
*/
private String getMainClass(URL jarURL) {
try {
JarInputStream stream = null;
+
try {
stream = new JarInputStream(jarURL.openStream());
+
Manifest manifest = stream.getManifest();
+
if (manifest == null) {
return null;
}
Attributes mainAttributes = manifest.getMainAttributes();
+
return mainAttributes.getValue("Main-Class");
} finally {
if (stream != null) {
1.3 +57 -55 jakarta-ant/proposal/mutant/src/java/start/org/apache/tools/ant/Main.java
Index: Main.java
===================================================================
RCS file: /home/cvs/jakarta-ant/proposal/mutant/src/java/start/org/apache/tools/ant/Main.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -w -u -r1.2 -r1.3
--- Main.java 18 Mar 2002 02:44:28 -0000 1.2
+++ Main.java 4 Apr 2002 04:36:13 -0000 1.3
@@ -57,14 +57,16 @@
* Old Ant1 entry point
*
* @author Conor MacNeill
+ * @created 4 April 2002
*/
public class Main {
/**
* Entry point for starting command line Ant
*
* @param args commandline arguments
+ * @exception Exception if there is a problem running Ant
*/
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
org.apache.ant.start.Main.main(args);
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>