Leave the bootstrap stuff in there as it still hasn't been integrated into myrmidon git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271940 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1,14 +0,0 @@ | |||
README for Ant(Eater) | |||
--------------------------------------------------------------------------------- | |||
Execution: | |||
ant [args] target | |||
Args: | |||
-help | |||
-quiet | |||
-verbose | |||
-taskpath [path] | |||
-antfile [file] |
@@ -1,67 +0,0 @@ | |||
package org.apache.ant.buildtarget; | |||
import org.apache.ant.*; | |||
/** | |||
* A simple task that builds a target if a property is set to true | |||
* | |||
* @author James Duncan Davidson (duncan@apache.org) | |||
*/ | |||
public class BuildTargetTask extends AbstractTask { | |||
// ----------------------------------------------------------------- | |||
// PRIVATE DATA MEMBERS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Data to echo | |||
*/ | |||
private String ifProperty; | |||
/** | |||
* Target to execute | |||
*/ | |||
private String targetName; | |||
// ----------------------------------------------------------------- | |||
// PUBLIC METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Executes this task. | |||
*/ | |||
public boolean execute() throws AntException { | |||
// XXX should really check internal state before proceeding! Target | |||
// has to be set... | |||
// XXX oh, and we should really check to see if the target exists | |||
// and fail out if it doesn't. :) | |||
if (ifProperty != null) { | |||
String ifPropertyValue = project.getProperty(ifProperty); | |||
if (ifPropertyValue.equals("true")) { | |||
project.startBuild(targetName); | |||
return true; | |||
} else { | |||
return true; | |||
} | |||
} else { | |||
project.startBuild(targetName); | |||
return true; | |||
} | |||
} | |||
/** | |||
* Sets the property that will be examined | |||
*/ | |||
public void setIf(String ifProperty) { | |||
this.ifProperty = ifProperty; | |||
} | |||
/** | |||
* Sets the target to be executed | |||
*/ | |||
public void setTarget(String targetName) { | |||
this.targetName = targetName; | |||
} | |||
} |
@@ -1,4 +0,0 @@ | |||
# taskdef.properties for Echo task | |||
tasks=buildtarget | |||
task.buildtarget.class=org.apache.ant.buildtarget.BuildTargetTask |
@@ -1,42 +0,0 @@ | |||
package org.apache.ant.echo; | |||
import org.apache.ant.*; | |||
/** | |||
* A very simple task that takes a bit of text and echos it back out | |||
* when it is executed. This is useful for troubleshooting properties | |||
* in buildfiles, letting the user know that something is going to happen | |||
* and as a very simple example that can be copied to create other tasks. | |||
* | |||
* @author James Duncan Davidson (duncan@apache.org) | |||
*/ | |||
public class EchoTask extends AbstractTask { | |||
// ----------------------------------------------------------------- | |||
// PRIVATE DATA MEMBERS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Data to echo | |||
*/ | |||
private String text; | |||
// ----------------------------------------------------------------- | |||
// PUBLIC METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Executes this task. | |||
*/ | |||
public boolean execute() throws AntException { | |||
project.getFrontEnd().writeMessage(text); | |||
return true; | |||
} | |||
/** | |||
* Sets the text that this task will echo. | |||
*/ | |||
public void setText(String text) { | |||
this.text = text; | |||
} | |||
} |
@@ -1,4 +0,0 @@ | |||
# taskdef.properties for Echo task | |||
tasks=echo | |||
task.echo.class=org.apache.ant.echo.EchoTask |
@@ -1,22 +0,0 @@ | |||
<?xml version="1.0"?> | |||
<!-- Comment outside of project --> | |||
<project name="Ant" default="default"> | |||
<!-- Comment inside of project --> | |||
<description>Primary buildfile for building Ant itself</description> | |||
<property name="foo" value="true"/> | |||
<target name="default" depends="main"> | |||
<echo text="Default Target is Executing"/> | |||
<buildtarget target="main" if="foo"/> | |||
</target> | |||
<target name="main"> | |||
<echo text="Main Target is Executing"/> | |||
</target> | |||
</project> |
@@ -1,85 +0,0 @@ | |||
package org.apache.ant; | |||
import java.io.*; | |||
import java.util.*; | |||
import java.lang.reflect.*; | |||
import java.beans.*; | |||
/** | |||
* Superclass of all Tasks. All tasks extend from this. | |||
* | |||
* @author James Duncan Davidson (duncan@apache.org) | |||
*/ | |||
public abstract class AbstractTask { | |||
// ----------------------------------------------------------------- | |||
// PROTECTED DATA MEMBERS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* | |||
*/ | |||
protected Project project; | |||
// ----------------------------------------------------------------- | |||
// ABSTRACT PUBLIC METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* | |||
*/ | |||
public abstract boolean execute() throws AntException; | |||
// ----------------------------------------------------------------- | |||
// PUBLIC METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Used by the system to set the attributes which then get reflected | |||
* into the particular implementation class | |||
*/ | |||
public void setAttributes(Hashtable attributes) { | |||
Class clazz = this.getClass(); | |||
BeanInfo bi; | |||
try { | |||
bi = Introspector.getBeanInfo(clazz); | |||
} catch (IntrospectionException ie) { | |||
System.out.println("Can't reflect on: " + clazz); | |||
// XXX exception out | |||
return; | |||
} | |||
PropertyDescriptor[] pda = bi.getPropertyDescriptors(); | |||
for (int i = 0; i < pda.length; i++) { | |||
PropertyDescriptor pd = pda[i]; | |||
String property = pd.getName(); | |||
Object o = attributes.get(property); | |||
if (o != null) { | |||
String value = (String)o; | |||
Method setMethod = pd.getWriteMethod(); | |||
if (setMethod != null) { | |||
Class[] ma = setMethod.getParameterTypes(); | |||
if (ma.length == 1) { | |||
Class c = ma[0]; | |||
if (c.getName().equals("java.lang.String")) { | |||
try { | |||
setMethod.invoke(this, new String[] {value}); | |||
} catch (Exception e) { | |||
// XXX bad bad bad -- narrow to exact exceptions | |||
System.out.println("OUCH: " + e); | |||
// XXX exception out. | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
} | |||
/** | |||
* Used by system to set the project. | |||
*/ | |||
public void setProject(Project project) { | |||
this.project = project; | |||
} | |||
} |
@@ -1,138 +0,0 @@ | |||
// ------------------------------------------------------------------------------- | |||
// Copyright (c)2000 Apache Software Foundation | |||
// ------------------------------------------------------------------------------- | |||
package org.apache.ant; | |||
/** | |||
* Signals a problem while setting up or executing a build. | |||
* | |||
* @author James Duncan Davidson (duncan@apache.org) | |||
*/ | |||
public class AntException extends Exception { | |||
// ----------------------------------------------------------------- | |||
// PRIVATE MEMBERS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* The cause of this exception. | |||
*/ | |||
private Throwable cause; | |||
/** | |||
* Project within which this exception occured, if applicable. | |||
*/ | |||
private Project project; | |||
/** | |||
* Target within which this exception occurred, if applicable. | |||
*/ | |||
private Target target; | |||
/** | |||
* Task within which this exception occurred, if applicable. | |||
*/ | |||
private Task task; | |||
// ----------------------------------------------------------------- | |||
// CONSTRUCTORS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Constructs a new AntException with no message. | |||
*/ | |||
public AntException() { | |||
super(); | |||
} | |||
/** | |||
* Constructs a new AntException with the given message. | |||
*/ | |||
public AntException(String msg) { | |||
super(msg); | |||
} | |||
/** | |||
* Constructs a new AntException with the given message and cause. | |||
*/ | |||
public AntException(String msg, Throwable cause) { | |||
super(msg); | |||
this.cause = cause; | |||
} | |||
/** | |||
* Constructs a new AntException with the given cause and a | |||
* detailed message of (cause==null ? null : cause.toString()) | |||
*/ | |||
public AntException(Throwable cause) { | |||
super(cause==null ? null : cause.toString()); | |||
this.cause = cause; | |||
} | |||
// ----------------------------------------------------------------- | |||
// PUBLIC METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Returns the cause of this exception. | |||
*/ | |||
public Throwable getCause() { | |||
return cause; | |||
} | |||
/** | |||
* Returns the Project within the scope of which this exception occurred, | |||
* if applicable. Otherwise null. | |||
*/ | |||
public Project getProject() { | |||
return project; | |||
} | |||
/** | |||
* Returns the Target within the scope of which this exception occurred, | |||
* if applicable. Otherwise null. | |||
*/ | |||
public Target getTarget() { | |||
return target; | |||
} | |||
/** | |||
* Returns the Task wihtin the scope of which this exception occurred, | |||
* if applicable. Otherwise null. | |||
*/ | |||
public Task getTask() { | |||
return task; | |||
} | |||
// ----------------------------------------------------------------- | |||
// PACKAGE METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Sets the project within the scope of which this exception occurred. | |||
* This method is called by the internal error handling mechanism of | |||
* Ant before it is propogated out. | |||
*/ | |||
void setProject(Project project) { | |||
this.project = project; | |||
} | |||
/** | |||
* Sets the target within the scope of which this exception occurred. | |||
* This method is called by the internal error handling mechansim of | |||
* Ant before it is propogated out. | |||
*/ | |||
void setTarget(Target target) { | |||
this.target = target; | |||
} | |||
/** | |||
* Sets the task within the scope of which this exception occurred. | |||
* This method is called by the internal error handling mechanism of | |||
* Ant before it is propogated out. | |||
*/ | |||
void setTask(Task task) { | |||
this.task = task; | |||
} | |||
} |
@@ -1,103 +0,0 @@ | |||
// ------------------------------------------------------------------------------- | |||
// Copyright (c)2000 Apache Software Foundation | |||
// ------------------------------------------------------------------------------- | |||
package org.apache.ant; | |||
/** | |||
* Abstract class that lets Ant talk to a front end such as a CLI front end, | |||
* GUI front end, Servlet front end, or some other front end. | |||
* | |||
* @author James Duncan Davidson (duncan@apache.org) | |||
*/ | |||
public abstract class AntFrontEnd { | |||
// ----------------------------------------------------------------- | |||
// CONSTANTS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Indicates that an associated message has a low importance. | |||
*/ | |||
public static final int MSG_LEVEL_LOW = 1; | |||
/** | |||
* Indicates that an associated message has a medium importance. | |||
*/ | |||
public static final int MSG_LEVEL_MED = 2; | |||
/** | |||
* Indicates that an associated message has a high importance. | |||
*/ | |||
public static final int MSG_LEVEL_HIGH = 3; | |||
// ----------------------------------------------------------------- | |||
// PUBLIC METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Send notification to the FrontEnd that execution has moved into | |||
* the scope of a particular project. The default implementation | |||
* does nothing. | |||
*/ | |||
public void notifyProjectStart(Project project) { | |||
} | |||
/** | |||
* Send notification to the FrontEnd that execution has moved out | |||
* of the scope of a particular Project. The default implementation | |||
* does nothing. | |||
*/ | |||
public void notifyProjectEnd(Project project) { | |||
} | |||
/** | |||
* Send notification to the FrontEnd that execution has moved into | |||
* the scope of a particular target. The default implementation does | |||
* nothing. | |||
*/ | |||
public void notifyTargetStart(Target target) { | |||
} | |||
/** | |||
* Send notification to the FrontEnd that execution has moved out of | |||
* the scope of a particular target. The default implementation does | |||
* nothing. | |||
*/ | |||
public void notifyTargetEnd(Target target) { | |||
} | |||
/** | |||
* Send notification to the FrontEnd that execution has moved into the | |||
* scope of a particular task. The default implementation does nothing. | |||
*/ | |||
public void notifyTaskStart(Task task) { | |||
} | |||
/** | |||
* Send notification to the FrontEnd that execution has moved out of | |||
* the scope of a particular task. The default implementation does | |||
* nothing. | |||
*/ | |||
public void notifyTaskEnd(Task task) { | |||
} | |||
/** | |||
* Writes a message to the front end with a medium importance. | |||
*/ | |||
public void writeMessage(String message) { | |||
writeMessage(message, MSG_LEVEL_MED); | |||
} | |||
/** | |||
* Writes a message to the front end. | |||
*/ | |||
public abstract void writeMessage(String message, int level); | |||
} |
@@ -1,286 +0,0 @@ | |||
// --------------------------------------------------------------------- | |||
// (c)2000 Apache Software Foundation | |||
// | |||
// --------------------------------------------------------------------- | |||
package org.apache.ant; | |||
import java.io.*; | |||
import java.util.*; | |||
/** | |||
* In memory container for an Ant project. | |||
* | |||
* @author James Duncan Davidson (duncan@apache.org) | |||
*/ | |||
public class Project { | |||
// ----------------------------------------------------------------- | |||
// PRIVATE DATA MEMBERS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* | |||
*/ | |||
//private Ant ant; | |||
/** | |||
* Base directory of this project. Usually this value is the directory | |||
* where the project file was found, but can be different. | |||
*/ | |||
private File baseDir; | |||
/** | |||
* | |||
*/ | |||
private String defaultTargetName; | |||
/** | |||
* Short description of the project. | |||
*/ | |||
private String description; | |||
/** | |||
* Front end that this project communicates to. | |||
*/ | |||
private AntFrontEnd frontEnd; | |||
/** | |||
* Properties of this project. | |||
*/ | |||
private Properties properties = new Properties(); | |||
/** | |||
* Parent project to this project, if one exists. | |||
*/ | |||
private Project parentProject = null; | |||
/** | |||
* | |||
*/ | |||
private String name; | |||
/** | |||
* Hashtable containing all of the targets that are part of this | |||
* project. Targets are stored in this hashtable using the name | |||
* of the target as the key and the Target object for the target | |||
* as the value. | |||
*/ | |||
private Hashtable targets = new Hashtable(); | |||
/** | |||
* TaskManager for this project. | |||
*/ | |||
private TaskManager taskManager; | |||
// ----------------------------------------------------------------- | |||
// CONSTRUCTORS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Creates a new Project object with the given FrontEnd and TaskManager | |||
*/ | |||
public Project(AntFrontEnd frontEnd, TaskManager taskManager) { | |||
this.frontEnd = frontEnd; | |||
this.taskManager = taskManager; | |||
} | |||
// ----------------------------------------------------------------- | |||
// PUBLIC METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Adds a target to this project. | |||
*/ | |||
public void addTarget(Target target) { | |||
// XXX check out for name, if null, reject! | |||
targets.put(target.getName(), target); | |||
} | |||
/** | |||
* Returns the base directory of this project. | |||
*/ | |||
public File getBaseDir() { | |||
return baseDir; | |||
} | |||
/** | |||
* Returns the default target for this project, if there is one. Otherwise | |||
* it returns null. | |||
*/ | |||
public String getDefaultTargetName() { | |||
return defaultTargetName; | |||
} | |||
/** | |||
* Returns a short description of this project, if any. If not, returns | |||
* null. | |||
*/ | |||
public String getDescription() { | |||
return description; | |||
} | |||
/** | |||
* Gets the front end that is running this project. | |||
*/ | |||
public AntFrontEnd getFrontEnd() { | |||
return frontEnd; | |||
} | |||
/** | |||
* Returns the parent Project object to this Project if a parent | |||
* project exists. If there is not a parent Project object, null | |||
* is returned. | |||
*/ | |||
public Project getParent() { | |||
return parentProject; | |||
} | |||
/** | |||
* Returns the target identified with the given name. If no target | |||
* is known by the given name, then null is returned. | |||
*/ | |||
public Target getTarget(String name) { | |||
return (Target)targets.get(name); | |||
} | |||
/** | |||
* Gets an exumeration of all the targets that are part of this project. | |||
*/ | |||
public Enumeration getTargets() { | |||
return targets.elements(); | |||
} | |||
/** | |||
* Gets the name of this project. | |||
*/ | |||
public String getName() { | |||
return name; | |||
} | |||
/** | |||
* Returns the value of a property. Returns null if the property does | |||
* not exist. | |||
*/ | |||
public String getProperty(String propertyName) { | |||
return properties.getProperty(propertyName); | |||
} | |||
/** | |||
* | |||
*/ | |||
//public void setAnt(Ant ant) { | |||
// this.ant = ant; | |||
//} | |||
/** | |||
* Sets the base dir for this project. | |||
*/ | |||
public void setBaseDir(File dir) { | |||
// XXX should check this to make sure it's a dir! | |||
baseDir = dir; | |||
} | |||
/** | |||
* Sets the default target for this project. | |||
*/ | |||
public void setDefaultTargetName(String targetName) { | |||
defaultTargetName = targetName; | |||
} | |||
/** | |||
* Sets the description for this project. | |||
*/ | |||
public void setDescription(String description) { | |||
this.description = description; | |||
} | |||
/** | |||
* Sets the front end for this project. | |||
*/ | |||
public void setFrontEnd(AntFrontEnd frontEnd) { | |||
this.frontEnd = frontEnd; | |||
} | |||
/** | |||
* Sets the name of this project. | |||
*/ | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
/** | |||
* Sets a property on this project. If the property is already | |||
* set, this method will override it. | |||
*/ | |||
public void setProperty(String propertyName, String propertyValue) { | |||
properties.put(propertyName, propertyValue); | |||
} | |||
/** | |||
* Starts a build of this project using the default target if one | |||
* is set. | |||
*/ | |||
public void startBuild() throws AntException { | |||
// XXX need to do something if the default target isn't set.. | |||
// maybe look for target name 'default', then bail? | |||
startBuild(defaultTargetName); | |||
} | |||
/** | |||
* Starts a build of this project with the entry point at the given | |||
* target. | |||
*/ | |||
public void startBuild(String targetName) throws AntException { | |||
// notify AntFrontEnd that we are starting a build on a project | |||
frontEnd.notifyProjectStart(this); | |||
Target target = getTarget(targetName); | |||
frontEnd.notifyTargetStart(target); | |||
// XXX don't forget to execute dependancies first! | |||
Enumeration enum = target.getTasks().elements(); | |||
while (enum.hasMoreElements()) { | |||
Task task = (Task)enum.nextElement(); | |||
frontEnd.notifyTaskStart(task); | |||
try { | |||
AbstractTask aTask = taskManager.getTaskInstance(task.getType()); | |||
aTask.setProject(this); | |||
aTask.setAttributes(task.getAttributes()); | |||
boolean b = aTask.execute(); | |||
if (!b) { | |||
String msg = "Task " + task.getType() + " failed"; | |||
AntException ae = new AntException(msg); | |||
throw ae; | |||
} | |||
} catch (Exception e) { | |||
AntException ae; | |||
if (!(e instanceof AntException)) { | |||
ae = new AntException(e); | |||
} else { | |||
ae = (AntException)e; | |||
} | |||
ae.setProject(this); | |||
ae.setTarget(target); | |||
ae.setTask(task); | |||
throw ae; | |||
} | |||
frontEnd.notifyTaskEnd(task); | |||
} | |||
// notify frontEnd that we are done | |||
frontEnd.notifyTargetEnd(target); | |||
frontEnd.notifyProjectEnd(this); | |||
} | |||
/** | |||
* Givens a string representation of this object. Useful for debugging. | |||
*/ | |||
public String toString() { | |||
return "Project name=" + name; | |||
} | |||
} |
@@ -1,307 +0,0 @@ | |||
// ------------------------------------------------------------------------------- | |||
// Copyright (c)2000 Apache Software Foundation | |||
// ------------------------------------------------------------------------------- | |||
package org.apache.ant; | |||
import java.io.*; | |||
import java.util.*; | |||
import javax.xml.parsers.*; | |||
import org.xml.sax.*; | |||
/** | |||
* Helper class to build Project object trees. | |||
* | |||
* XXX right now this class only deals with the primary levels (project/target/task) | |||
* and nothing else. Also, it only supports attributes.... | |||
* | |||
* @author James Duncan Davidson (duncan@apache.org) | |||
*/ | |||
public class ProjectBuilder { | |||
// ----------------------------------------------------------------- | |||
// PRIVATE MEMBERS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* | |||
*/ | |||
private AntFrontEnd frontEnd; | |||
/** | |||
* | |||
*/ | |||
private SAXParserFactory parserFactory; | |||
/** | |||
* | |||
*/ | |||
private TaskManager taskManager; | |||
// ----------------------------------------------------------------- | |||
// CONSTRUCTORS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Creates a new project builder that will build projects for the given | |||
* Ant. | |||
*/ | |||
public ProjectBuilder(AntFrontEnd frontEnd) { | |||
this.frontEnd = frontEnd; | |||
taskManager = new TaskManager(frontEnd); | |||
parserFactory = SAXParserFactory.newInstance(); | |||
parserFactory.setValidating(false); | |||
} | |||
// ----------------------------------------------------------------- | |||
// PUBLIC METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Builds a project from the given file. | |||
*/ | |||
public Project buildFromFile(File file) throws AntException { | |||
try { | |||
SAXParser parser = parserFactory.newSAXParser(); | |||
BuilderHandlerBase bhb = new BuilderHandlerBase(); | |||
bhb.setProjectFileLocation(file); | |||
parser.parse(file, bhb); | |||
Project project = bhb.getProject(); | |||
project.setFrontEnd(frontEnd); | |||
return project; | |||
} catch (ParserConfigurationException pce) { | |||
throw new AntException(pce); | |||
} catch (SAXException se) { | |||
Exception e = se.getException(); | |||
if (e != null && e instanceof AntException) { | |||
// it's one of our own thrown from inside the parser to stop it | |||
throw (AntException)e; | |||
} | |||
throw new AntException(se); | |||
} catch (IOException ioe) { | |||
throw new AntException(ioe); | |||
} | |||
} | |||
/** | |||
* Returns the TaskManager associated with this ProjectBuilder and | |||
* the projects that it builds | |||
*/ | |||
public TaskManager getTaskManager() { | |||
return taskManager; | |||
} | |||
// ----------------------------------------------------------------- | |||
// INNER CLASSES | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Inner class that implements the needed SAX methods to get all the | |||
* data needed out of a build file. | |||
*/ | |||
class BuilderHandlerBase extends HandlerBase { | |||
private static final int STATE_START = 0; | |||
private static final int STATE_PROJECT = 1; | |||
private static final int STATE_TARGET = 2; | |||
private static final int STATE_TASK = 3; | |||
private static final int STATE_DESCRIPTION = 4; | |||
private static final int STATE_PROPERTY = 5; | |||
private static final int STATE_FINISHED = 99; | |||
private int state = STATE_START; | |||
private Vector tagCharDataStack = new Vector(); | |||
private Target currentTarget; | |||
private Task currentTask; | |||
Project project = new Project(frontEnd, taskManager); | |||
Project getProject() { | |||
return project; | |||
} | |||
void setProjectFileLocation(File file) { | |||
project.setBaseDir(file.getParentFile()); | |||
} | |||
public void startElement(String name, AttributeList atts) throws SAXException { | |||
StringBuffer tagCharData = new StringBuffer(); | |||
tagCharDataStack.insertElementAt(tagCharData, 0); | |||
switch (state) { | |||
case STATE_START: | |||
if (name.equals("project")) { | |||
state = STATE_PROJECT; | |||
String projectName = atts.getValue("name"); | |||
if (projectName != null) { | |||
project.setName(projectName); | |||
} else { | |||
String msg = "Project element doesn't contain a name attribute"; | |||
AntException ae = new AntException(msg); | |||
throw new SAXException(ae); | |||
} | |||
String defaultTarget = atts.getValue("default"); | |||
if (defaultTarget != null) { | |||
project.setDefaultTargetName(defaultTarget); | |||
} | |||
String baseDirName = atts.getValue("basedir"); | |||
if (baseDirName != null) { | |||
// XXX need to check to see if base dir exists | |||
project.setBaseDir(new File(baseDirName)); | |||
} | |||
} else { | |||
String msg = "Project file doesn't contain a project element as " + | |||
"its root node"; | |||
AntException ae = new AntException(msg); | |||
throw new SAXException(ae); | |||
} | |||
break; | |||
case STATE_PROJECT: | |||
// valid tags in a project object are: description, property, and target | |||
if (name.equals("description")) { | |||
state = STATE_DESCRIPTION; | |||
} else if (name.equals("property")) { | |||
state = STATE_PROPERTY; | |||
String propertyName = atts.getValue("name"); | |||
String propertyValue = atts.getValue("value"); | |||
if (propertyName == null) { | |||
String msg = "Name attribute must be present on property"; | |||
AntException ae = new AntException(msg); | |||
throw new SAXException(ae); | |||
} else if (propertyValue == null) { | |||
String msg = "Value attribute must be present on property"; | |||
AntException ae = new AntException(msg); | |||
throw new SAXException(ae); | |||
} else { | |||
project.setProperty(propertyName, propertyValue); | |||
} | |||
} else if (name.equals("target")) { | |||
state = STATE_TARGET; | |||
String targetName = atts.getValue("name"); | |||
if (targetName != null) { | |||
currentTarget = new Target(targetName); | |||
project.addTarget(currentTarget); | |||
} else { | |||
// XXX figure out which target we're talking about! | |||
// Like a location | |||
String msg = "Target element doesn't contain a name attribute"; | |||
AntException ae = new AntException(msg); | |||
throw new SAXException(ae); | |||
} | |||
String depends = atts.getValue("depends"); | |||
if (depends != null) { | |||
StringTokenizer tok = new StringTokenizer(depends, ",", false); | |||
while(tok.hasMoreTokens()) { | |||
currentTarget.addDependancy(tok.nextToken().trim()); | |||
} | |||
} | |||
// XXX add dependency checks | |||
} else { | |||
System.out.println("Expecting target, got: " + name); | |||
// XXX exception out | |||
} | |||
break; | |||
case STATE_TARGET: | |||
// Valid tags inside target: task | |||
state = STATE_TASK; | |||
//System.out.println("Getting task: " + name + " for target " + | |||
// currentTarget); | |||
// XXX need to validate that task type (name) exists in system | |||
// else exception out. | |||
currentTask = new Task(name); | |||
currentTarget.addTask(currentTask); | |||
for (int i = 0; i < atts.getLength(); i++) { | |||
String atName = atts.getName(i); | |||
String atValue = atts.getValue(i); | |||
currentTask.addAttribute(atName, atValue); | |||
} | |||
break; | |||
case STATE_TASK: | |||
// data in here needs to be reflected into tasks | |||
System.out.println("Not yet supporting tags inside of tasks!"); | |||
System.out.println("The project build will probably bust right here"); | |||
break; | |||
default: | |||
System.out.println("I'm not sure, but we're off base here: " + name); | |||
// XXX exception out | |||
} | |||
} | |||
public void characters(char ch[], int start, int length) throws SAXException { | |||
StringBuffer buf = (StringBuffer)tagCharDataStack.elementAt(0); | |||
buf.append(ch, start, length); | |||
} | |||
public void endElement(String name) throws SAXException { | |||
StringBuffer elementData = (StringBuffer)tagCharDataStack.elementAt(0); | |||
tagCharDataStack.removeElementAt(0); | |||
switch (state) { | |||
case STATE_TASK: | |||
state = STATE_TARGET; | |||
break; | |||
case STATE_TARGET: | |||
if (name.equals("target")) { | |||
state = STATE_PROJECT; | |||
} else { | |||
System.out.println("Expecting to get an end of target, got: " + name); | |||
// XXX exception out. | |||
} | |||
break; | |||
case STATE_DESCRIPTION: | |||
if (name.equals("description")) { | |||
state = STATE_PROJECT; | |||
project.setDescription(elementData.toString().trim()); | |||
} else { | |||
System.out.println("Expecting to get an end of description, got: " + | |||
name); | |||
// XXX exception out. | |||
} | |||
break; | |||
case STATE_PROPERTY: | |||
if (name.equals("property")) { | |||
state = STATE_PROJECT; | |||
} else { | |||
System.out.println("Expecting to get end of property, got: " + name); | |||
// XXX exception out | |||
} | |||
break; | |||
case STATE_PROJECT: | |||
if (name.equals("project")) { | |||
state = STATE_FINISHED; | |||
} else { | |||
System.out.println("Expecting to get end of project, got: " + name); | |||
// XXX exception out; | |||
} | |||
break; | |||
default: | |||
System.out.println("I'm not sure what we are ending here: " + name); | |||
// XXX exception out; | |||
} | |||
} | |||
} | |||
} |
@@ -1,90 +0,0 @@ | |||
// --------------------------------------------------------------------- | |||
// (c)2000 Apache Software Foundation | |||
// | |||
// --------------------------------------------------------------------- | |||
package org.apache.ant; | |||
import java.util.*; | |||
/** | |||
* In memory container for an Ant target. | |||
*/ | |||
public class Target { | |||
// ----------------------------------------------------------------- | |||
// PRIVATE DATA MEMBERS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* String containing the name of the target. This name must be | |||
* unique withing a project. | |||
*/ | |||
private String name; | |||
/** | |||
* Vector containing the names of the targets that this target | |||
* depends on. | |||
*/ | |||
private Vector dependsList = new Vector(); | |||
/** | |||
* Vector containing the tasks that are part of this target. | |||
*/ | |||
private Vector tasks = new Vector(); | |||
// ----------------------------------------------------------------- | |||
// CONSTRUCTORS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Constructs a new Target object with the given name. | |||
*/ | |||
public Target(String name) { | |||
this.name = name; | |||
} | |||
// ----------------------------------------------------------------- | |||
// PUBLIC ACCESSOR METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Adds a dependancy to this task. | |||
*/ | |||
public void addDependancy(String targetName) { | |||
dependsList.addElement(targetName); | |||
} | |||
/** | |||
* | |||
*/ | |||
public void addTask(Task task) { | |||
tasks.addElement(task); | |||
} | |||
/** | |||
* Returns a String containing the name of this Target. | |||
*/ | |||
public String getName() { | |||
return name; | |||
} | |||
/** | |||
* | |||
*/ | |||
public String toString() { | |||
return "TARGET: " + name; | |||
} | |||
/** | |||
* Returns a Vector of Tasks contained in this Target. | |||
* <p> | |||
* Please use caution when using this method. I am not happy | |||
* about exposing this data as something other than a | |||
* Collection, but don't want to use 1.1 collections. So, | |||
* this method may change in the future. You have been warned. | |||
*/ | |||
public Vector getTasks() { | |||
return tasks; | |||
} | |||
} |
@@ -1,86 +0,0 @@ | |||
// --------------------------------------------------------------------- | |||
// (c)2000 Apache Software Foundation | |||
// | |||
// --------------------------------------------------------------------- | |||
package org.apache.ant; | |||
import java.util.*; | |||
/** | |||
* In memory container for an Ant target. | |||
* | |||
* XXX need a way to query which attributes are valid for this particular | |||
* task type... Like into Ant object to do this? | |||
*/ | |||
public class Task { | |||
// ----------------------------------------------------------------- | |||
// PRIVATE DATA MEMBERS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* | |||
*/ | |||
private Hashtable attributes = new Hashtable(); | |||
/** | |||
* String containing the type of the task. | |||
*/ | |||
private String type; | |||
// ----------------------------------------------------------------- | |||
// CONSTRUCTORS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Constructs a new Target object with the given name. | |||
*/ | |||
public Task(String type) { | |||
this.type = type; | |||
} | |||
// ----------------------------------------------------------------- | |||
// PUBLIC ACCESSOR METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* | |||
*/ | |||
public void addAttribute(String name, String value) { | |||
attributes.put(name, value); | |||
} | |||
public String getAttribute(String name) { | |||
return (String)attributes.get(name); | |||
} | |||
/** | |||
* | |||
*/ | |||
public Hashtable getAttributes() { | |||
return attributes; | |||
} | |||
/** | |||
* | |||
*/ | |||
public Enumeration getAttributeNames() { | |||
return attributes.keys(); | |||
} | |||
/** | |||
* Returns a String containing the name of this Target. | |||
*/ | |||
public String getType() { | |||
return type; | |||
} | |||
/** | |||
* | |||
*/ | |||
public String toString() { | |||
return "TASK: " + type; | |||
} | |||
} |
@@ -1,268 +0,0 @@ | |||
// ------------------------------------------------------------------------------- | |||
// Copyright (c)2000 Apache Software Foundation | |||
// ------------------------------------------------------------------------------- | |||
package org.apache.ant; | |||
import java.io.*; | |||
import java.net.*; | |||
import java.util.*; | |||
import java.util.zip.*; | |||
/** | |||
* Manager of tasks and all things related to tasks. Tasks can be found in a | |||
* wide number of locations -- and most of these locations require class loading | |||
* help. As well, new nodes on the task search path may be added at any time. | |||
* When these are added, new tasks should be scanned for. | |||
* | |||
* @author James Duncan Davidson (duncan@apache.org) | |||
*/ | |||
public class TaskManager { | |||
// ----------------------------------------------------------------- | |||
// PRIVATE DATA MEMBERS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* FrontEnd that this TaskManager can communicate through. | |||
*/ | |||
private AntFrontEnd frontEnd; | |||
/** | |||
* Data structure where all the Class definition for all known tasks are | |||
* held. | |||
*/ | |||
private Hashtable taskClasses = new Hashtable(); | |||
/** | |||
* Data structure that holds all the nodes where tasks are picked up from. | |||
*/ | |||
private Vector taskPathNodes = new Vector(); | |||
// ----------------------------------------------------------------- | |||
// CONSTRUCTORS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Creates a new TaskManager. | |||
*/ | |||
TaskManager(AntFrontEnd frontEnd) { | |||
this.frontEnd = frontEnd; | |||
} | |||
// ----------------------------------------------------------------- | |||
// PUBLIC METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Adds a node to the task path | |||
*/ | |||
public void addTaskPathNode(File file) throws AntException { | |||
taskPathNodes.addElement(file); | |||
processTaskPathNode(file); | |||
} | |||
// ----------------------------------------------------------------- | |||
// PACKAGE METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* | |||
*/ | |||
AbstractTask getTaskInstance(String taskName) throws AntException { | |||
Class clazz = (Class)taskClasses.get(taskName); | |||
try { | |||
return (AbstractTask)clazz.newInstance(); | |||
} catch (Exception e) { | |||
String msg = "Can't instantiate task: " + taskName; | |||
AntException ae = new AntException(msg, e); | |||
throw ae; | |||
} | |||
} | |||
// ----------------------------------------------------------------- | |||
// PRIVATE METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Returns an enum of the task names that are defined in a given | |||
* properties file. | |||
*/ | |||
private Enumeration getTaskNames(Properties props) { | |||
Vector v = new Vector(); | |||
String s = props.getProperty("tasks"); | |||
StringTokenizer tok = new StringTokenizer(s, ",", false); | |||
while (tok.hasMoreTokens()) { | |||
String taskName = tok.nextToken().trim(); | |||
v.addElement(taskName); | |||
} | |||
return v.elements(); | |||
} | |||
/** | |||
* Processes a directory to get class defintions from it | |||
*/ | |||
private void processDir(File dir) { | |||
frontEnd.writeMessage("Scanning " + dir + " for tasks", | |||
AntFrontEnd.MSG_LEVEL_LOW); | |||
File file = new File(dir, "taskdef.properties"); | |||
if (file.exists()) { | |||
try { | |||
InputStream in = new FileInputStream(file); | |||
Properties props = new Properties(); | |||
props.load(in); | |||
in.close(); | |||
Enumeration enum = getTaskNames(props); | |||
while (enum.hasMoreElements()) { | |||
String taskName = (String)enum.nextElement(); | |||
String taskClass = props.getProperty("task." + taskName + ".class"); | |||
URLClassLoader loader = new URLClassLoader(new URL[] {dir.toURL()}); | |||
try { | |||
Class clazz = loader.loadClass(taskClass); | |||
frontEnd.writeMessage("Got Task: " + taskName + | |||
clazz, AntFrontEnd.MSG_LEVEL_LOW); | |||
taskClasses.put(taskName, clazz); | |||
} catch (ClassNotFoundException cnfe) { | |||
System.out.println("Couldn't load task: " + taskName); | |||
System.out.println(cnfe); | |||
// XXX error out and stop.... | |||
} | |||
} | |||
} catch (IOException ioe) { | |||
System.out.println("Could not work with dir: " + dir); | |||
System.out.println(ioe); | |||
// XXX error out and stop the build | |||
} | |||
} | |||
} | |||
/** | |||
* Processes a jar file to get class definitions from it | |||
*/ | |||
private void processJar(File file) throws AntException { | |||
frontEnd.writeMessage("Scanning " + file + " for tasks", | |||
AntFrontEnd.MSG_LEVEL_LOW); | |||
try { | |||
ZipFile zipFile = new ZipFile(file); | |||
ZipEntry zipEntry = zipFile.getEntry("taskdef.properties"); | |||
if (zipEntry != null) { | |||
InputStream in = zipFile.getInputStream(zipEntry); | |||
Properties props = new Properties(); | |||
props.load(in); | |||
in.close(); | |||
Enumeration enum = getTaskNames(props); | |||
while (enum.hasMoreElements()) { | |||
String taskName = (String)enum.nextElement(); | |||
String taskClass = props.getProperty("task." + taskName + ".class"); | |||
if (taskClass == null) { | |||
String msg = "No class definition for task " + taskName + | |||
"in jar file " + file; | |||
throw new AntException(msg); | |||
} | |||
URLClassLoader loader = new URLClassLoader(new URL[] {file.toURL()}); | |||
try { | |||
Class clazz = loader.loadClass(taskClass); | |||
frontEnd.writeMessage("Got Task: " + taskName + | |||
clazz, AntFrontEnd.MSG_LEVEL_LOW); | |||
taskClasses.put(taskName, clazz); | |||
} catch (ClassNotFoundException cnfe) { | |||
System.out.println("Couldn't load task: " + taskName); | |||
System.out.println(cnfe); | |||
// XXX error out and stop.... | |||
} | |||
} | |||
} | |||
// make sure to not leave resources hanging | |||
zipFile.close(); | |||
} catch (IOException ioe) { | |||
System.out.println("Couldn't work with file: " + file); | |||
System.out.println(ioe); | |||
// XXX need to exception out of here properly to stop things | |||
} | |||
} | |||
/** | |||
* Processes a node of the task path searching for task definitions there | |||
* and adding them to the list of known tasks | |||
*/ | |||
private void processTaskPathNode(File file) throws AntException { | |||
// task path nodes can be any of the following: | |||
// * jar file | |||
// * directory of jar files | |||
// * directory holding class files | |||
if(file.isDirectory()) { | |||
// first look for all jar files here | |||
// second look for a taskdefs.properties here to see if we should | |||
// treat the directory as a classpath | |||
String[] files = file.list(); | |||
for (int i = 0; i < files.length; i++) { | |||
if (files[i].endsWith(".jar")) { | |||
processJar(new File(file, files[i])); | |||
} else if (files[i].equals("taskdef.properties")) { | |||
processDir(file); | |||
} | |||
} | |||
} else if (file.getName().endsWith(".jar")) { | |||
processJar(file); | |||
} | |||
} | |||
/** | |||
* Sets up the taskpath based on the currently running operating | |||
* system. In general, the ordering of the taskpath is: user directory, | |||
* system directory, and then installation. This allows users or | |||
* system admins to override or add tasks. | |||
*/ | |||
private void setUpTaskPath() throws AntException { | |||
// 1st, add user's home dir. | |||
File f; | |||
String userHome = System.getProperty("user.home"); | |||
// generic unix | |||
f = new File(userHome + ".ant", "tasks"); | |||
if (f.exists() && f.isDirectory()) { | |||
addTaskPathNode(f); | |||
} | |||
// macos x | |||
f = new File(userHome + "/Library/Ant", "Tasks"); | |||
if (f.exists() && f.isDirectory()) { | |||
addTaskPathNode(f); | |||
} | |||
// windows -- todo | |||
// 2nd, add system local dir. | |||
// generic unix | |||
f = new File("/usr/local/ant/tasks"); | |||
if (f.exists() && f.isDirectory()) { | |||
addTaskPathNode(f); | |||
} | |||
// macos x | |||
f = new File("/Library/Ant/Tasks"); | |||
if (f.exists() && f.isDirectory()) { | |||
addTaskPathNode(f); | |||
} | |||
// windows -- todo | |||
// 3rd, add installation local dir. | |||
//System.out.println("BASE: " + this.getClass().getResource("/")); | |||
// XXX ---- not really sure how the best way of getting this info is... | |||
// hafta think about it. | |||
} | |||
} |
@@ -1,307 +0,0 @@ | |||
// ------------------------------------------------------------------------------- | |||
// Copyright (c)2000 Apache Software Foundation | |||
// ------------------------------------------------------------------------------- | |||
package org.apache.ant.cli; | |||
import java.io.*; | |||
import java.util.*; | |||
import org.apache.ant.*; | |||
/** | |||
* Front end for the Command Line Interface that gets passed to Ant so that | |||
* it can communicate information to the CLI. | |||
* | |||
* @author James Duncan Davidson (duncan@apache.org) | |||
*/ | |||
public class CLIFrontEnd extends AntFrontEnd { | |||
// ----------------------------------------------------------------- | |||
// PRIVATE MEMBERS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* | |||
*/ | |||
private String[] args; | |||
/** | |||
* ProjectBuilder that is associated with this frontEnd. | |||
*/ | |||
private ProjectBuilder projectBuilder; | |||
/** | |||
* | |||
*/ | |||
private int msgLevelFilter = MSG_LEVEL_MED; | |||
/** | |||
* TaskManager instance that we can set taskpaths and such on. | |||
*/ | |||
private TaskManager taskManager; | |||
// ----------------------------------------------------------------- | |||
// CONSTRUCTORS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Creates a new CLIFrontEnd that can drive an Ant build from the Command | |||
* Line. | |||
*/ | |||
public CLIFrontEnd() { | |||
projectBuilder = new ProjectBuilder(this); | |||
taskManager = projectBuilder.getTaskManager(); | |||
} | |||
// ----------------------------------------------------------------- | |||
// PUBLIC METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Send notification to the FrontEnd that execution has moved into | |||
* the scope of a particular project. The default implementation | |||
* does nothing. | |||
*/ | |||
public void notifyProjectStart(Project project) { | |||
writeMessage("Project Start: " + project.getName(), MSG_LEVEL_LOW); | |||
} | |||
/** | |||
* Send notification to the FrontEnd that execution has moved out | |||
* of the scope of a particular Project. The default implementation | |||
* does nothing. | |||
*/ | |||
public void notifyProjectEnd(Project project) { | |||
writeMessage("Project End: " + project.getName(), MSG_LEVEL_LOW); | |||
} | |||
/** | |||
* Send notification to the FrontEnd that execution has moved into | |||
* the scope of a particular target. The default implementation does | |||
* nothing. | |||
*/ | |||
public void notifyTargetStart(Target target) { | |||
writeMessage("Target Start: " + target.getName(), MSG_LEVEL_LOW); | |||
} | |||
/** | |||
* Send notification to the FrontEnd that execution has moved out of | |||
* the scope of a particular target. The default implementation does | |||
* nothing. | |||
*/ | |||
public void notifyTargetEnd(Target target) { | |||
writeMessage("Target End: " + target.getName(), MSG_LEVEL_LOW); | |||
} | |||
/** | |||
* Send notification to the FrontEnd that execution has moved into the | |||
* scope of a particular task. The default implementation does nothing. | |||
*/ | |||
public void notifyTaskStart(Task task) { | |||
writeMessage("Task Start: " + task.getType(), MSG_LEVEL_LOW); | |||
} | |||
/** | |||
* Send notification to the FrontEnd that execution has moved out of | |||
* the scope of a particular task. The default implementation does | |||
* nothing. | |||
*/ | |||
public void notifyTaskEnd(Task task) { | |||
writeMessage("Task End: " + task.getType(), MSG_LEVEL_LOW); | |||
} | |||
/** | |||
* | |||
*/ | |||
public void run(String[] args) { | |||
this.args = args; | |||
String target = ""; | |||
File buildFile = null; | |||
writeMessage("Ant(Eater) -- Proposed Ant 2.0"); | |||
// process through the args set | |||
if (isArg("help")) { | |||
printHelp(); | |||
return; | |||
} | |||
if (isArg("quiet")) { | |||
msgLevelFilter = MSG_LEVEL_HIGH; | |||
} | |||
if (isArg("verbose")) { | |||
msgLevelFilter = MSG_LEVEL_LOW; | |||
} | |||
String argTaskpath = getArgValue("taskpath"); | |||
if (argTaskpath != null) { | |||
if (argTaskpath.equals("")) { | |||
writeMessage("Must give a value for -taskpath"); | |||
return; | |||
} else { | |||
// XXX need to separate on path seps so that real paths can be taken | |||
try { | |||
taskManager.addTaskPathNode(new File(argTaskpath)); | |||
} catch (AntException ae) { | |||
System.out.println(ae); | |||
System.out.println(ae.getMessage()); | |||
ae.printStackTrace(System.out); | |||
return; | |||
} | |||
} | |||
} | |||
String argBuildfile = getArgValue("buildfile"); | |||
if (argBuildfile != null) { | |||
if (argBuildfile.equals("")) { | |||
writeMessage("Must give a value for -buildfile"); | |||
return; | |||
} else { | |||
//try { | |||
buildFile = new File(argBuildfile); | |||
//ant.setBuildfile(new File(argBuildfile)); | |||
//} catch (AntException ae) { | |||
// writeMessage("Can't set buildfile"); | |||
// writeMessage(ae.toString()); | |||
// return; | |||
//} | |||
} | |||
} | |||
target = getTargetArg(); | |||
// XXX do something if we dont' have a buildfile set! | |||
// XXX really should check to make sure that the target is set to something | |||
// like get the default... | |||
try { | |||
Project project = projectBuilder.buildFromFile(buildFile); | |||
project.setFrontEnd(this); | |||
project.startBuild(target); | |||
} catch (AntException ae) { | |||
//XXX this whole write a string at a time message handling | |||
// sucks and needs to be improved... | |||
writeMessage("Build Stopped"); | |||
writeMessage(" Project: " + ae.getProject().getName()); | |||
writeMessage(" Target: " + ae.getTarget().getName()); | |||
writeMessage(" Task Type: " + ae.getTask().getType()); | |||
writeMessage("Details Follow"); | |||
writeMessage(""); | |||
writeMessage(ae.getMessage()); | |||
ae.printStackTrace(System.out); | |||
Throwable t = ae.getCause(); | |||
if (t != null) { | |||
writeMessage(""); | |||
writeMessage("Cause Exception: " + t.toString()); | |||
writeMessage(t.getMessage()); | |||
t.printStackTrace(System.out); | |||
} | |||
} | |||
} | |||
/** | |||
* Writes a message to the front end. | |||
*/ | |||
public void writeMessage(String message, int level) { | |||
if (level >= msgLevelFilter) { | |||
System.out.println(message); | |||
} | |||
} | |||
// ----------------------------------------------------------------- | |||
// PRIVATE METHODS | |||
// ----------------------------------------------------------------- | |||
/** | |||
* Returns the value for a given argument name, null if the argument | |||
* name isn't in the argument set, or "" if the argument doesn't have | |||
* a value. | |||
*/ | |||
private String getArgValue(String argName) { | |||
for (int i = 0; i < args.length; i++) { | |||
if (args[i].equals("-" + argName)) { | |||
if (i != args.length - 1) { | |||
return args[i + 1]; | |||
} else { | |||
return ""; | |||
} | |||
} | |||
} | |||
return null; | |||
} | |||
/** | |||
* Returns the target that was requested to be built, if any. If no | |||
* target is determined, returns null. | |||
*/ | |||
public String getTargetArg() { | |||
String possibleTarget = getArgValue("target"); | |||
if (possibleTarget != null) { | |||
if (possibleTarget.equals("")) { | |||
writeMessage("Must give a value for -target"); | |||
} else { | |||
return possibleTarget; | |||
} | |||
} | |||
possibleTarget = args[args.length - 1]; | |||
if (possibleTarget.startsWith("-")) { | |||
return null; | |||
} | |||
if (args[args.length - 2].startsWith("-")) { | |||
// our possible target might be an arg value instead of a target | |||
// XXX ugh -- there has to be a better way here. We need to hold | |||
// a list of all args that don't have values somewhere. | |||
if (args[args.length - 2].equals("-help") || | |||
args[args.length - 2].equals("-verbose") || | |||
args[args.length - 2].equals("-quiet")) { | |||
// we're ok, the arg before the possible target doesn't have a value | |||
return possibleTarget; | |||
} else { | |||
return null; | |||
} | |||
} else { | |||
return possibleTarget; | |||
} | |||
} | |||
/** | |||
* Indicates whether or not a given argument name exists in the argument | |||
* set. | |||
*/ | |||
private boolean isArg(String argName) { | |||
for (int i = 0; i < args.length; i++) { | |||
if (args[i].equals("-" + argName)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
/** | |||
* Prints help to System.out | |||
*/ | |||
private void printHelp() { | |||
// XXX resource bundle this. | |||
String ls = System.getProperty("line.separator"); | |||
String msg = "Usage: ant [args] [target]" + ls + | |||
" Arguments can be any of the following:" + ls + | |||
" -help" + ls + | |||
" -taskpath [path]" + ls + | |||
" -buildfile [file]" +ls + | |||
" -verbose" + ls + | |||
" -quiet" + ls + ls + | |||
" Note that if no buildfile argument is given, Ant will"+ls+ | |||
" try to find one in the current directory. If there are"+ls+ | |||
" two or more buildfiles in the current directory, it" +ls+ | |||
" will bail."; | |||
writeMessage(msg); | |||
} | |||
} |