conor 02/02/06 04:52:58
Modified: proposal/mutant/src/java/antcore/org/apache/ant/antcore/config
AntConfig.java AntConfigHandler.java
proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution
ExecutionDataService.java ExecutionFrame.java
proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant
Project.java Task.java
proposal/mutant/src/java/cli/org/apache/ant/cli
Commandline.java
proposal/mutant/src/java/start/org/apache/ant/start
Main.java
Log:
Made unset property behaviour a config item
Allowed Ant1 compat layer to create current Ant1 tasks
Revision Changes Path
1.5 +49 -5
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfig.java
Index: AntConfig.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfig.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -u -r1.4 -r1.5
--- AntConfig.java 5 Feb 2002 11:49:04 -0000 1.4
+++ AntConfig.java 6 Feb 2002 12:52:57 -0000 1.5
@@ -82,10 +82,22 @@
private Map libPaths = new HashMap();
/** Indicates if remote libraries may be used */
- private boolean allowRemoteLibs = false;
+ private boolean remoteLibs = false;
/** Indicates if remote projects may be used */
- private boolean allowRemoteProjects = false;
+ private boolean remoteProjects = false;
+
+ /** Indicates if unset properties are ignored */
+ private boolean unsetProperties = true;
+
+ /**
+ * Indicate if unset properties are OK.
+ *
+ * @return true if unset properties will not cause an exception
+ */
+ public boolean isUnsetPropertiesAllowed() {
+ return unsetProperties;
+ }
/**
* Indicate if the use of remote library's is allowe dby this config.
@@ -93,7 +105,7 @@
* @return true if this config allows the use of remote libraries,
*/
public boolean isRemoteLibAllowed() {
- return allowRemoteLibs;
+ return remoteLibs;
}
/**
@@ -102,7 +114,7 @@
* @return true if remote projects are allowed
*/
public boolean isRemoteProjectAllowed() {
- return allowRemoteProjects;
+ return remoteProjects;
}
/**
@@ -141,6 +153,34 @@
}
/**
+ * Allow remote libraries to be used
+ *
+ * @param allowRemoteLibs true if remote libraries may be used.
+ */
+ public void allowRemoteLibs(boolean allowRemoteLibs) {
+ this.remoteLibs = allowRemoteLibs;
+ }
+
+ /**
+ * Allow remote projects to be used
+ *
+ * @param allowRemoteProjects true if remote projects may be executed.
+ */
+ public void allowRemoteProjects(boolean allowRemoteProjects) {
+ this.remoteProjects = allowRemoteProjects;
+ }
+
+ /**
+ * Allow properties to be used even when they have not been set
+ *
+ * @param allowUnsetProperties true if un set properties should not
+ * cause an exception
+ */
+ public void allowUnsetProperties(boolean allowUnsetProperties) {
+ this.unsetProperties = allowUnsetProperties;
+ }
+
+ /**
* Add an additional set of paths for the given library.
*
* @param libraryId The library id for which the additional class path
@@ -207,6 +247,10 @@
combined.addAll(currentList);
libPaths.put(libraryId, combined);
}
+
+ remoteLibs = otherConfig.remoteLibs;
+ remoteProjects = otherConfig.remoteProjects;
+ unsetProperties = otherConfig.unsetProperties;
}
/**
1.5 +35 -2
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfigHandler.java
Index: AntConfigHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/config/AntConfigHandler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -w -u -r1.4 -r1.5
--- AntConfigHandler.java 5 Feb 2002 11:49:04 -0000 1.4
+++ AntConfigHandler.java 6 Feb 2002 12:52:57 -0000 1.5
@@ -64,6 +64,18 @@
* @created 20 January 2002
*/
public class AntConfigHandler extends ElementHandler {
+ /** The allowRemoteProject attribute name */
+ public final static String REMOTE_PROJECT_ATTR = "allow-remote-project";
+
+ /** The allowRemoteLibrary attribute name */
+ public final static String REMOTE_LIBRARY_ATTR = "allow-remote-library";
+
+ /** The allowReportProject attribute name */
+ public final static String UNSET_PROPS_ATTR = "allow-unset-properties";
+
+ /** The list of allowed Attributes */
+ public final static String[] ALLOWED_ATTRIBUTES
+ = {REMOTE_PROJECT_ATTR, REMOTE_LIBRARY_ATTR, UNSET_PROPS_ATTR};
/**
* The config object which is contructed from the XML representation of
* the config
@@ -89,6 +101,9 @@
public void processElement(String elementName)
throws SAXParseException {
config = new AntConfig();
+ config.allowRemoteLibs(getBooleanAttribute(REMOTE_LIBRARY_ATTR));
+ config.allowRemoteProjects(getBooleanAttribute(REMOTE_PROJECT_ATTR));
+ config.allowUnsetProperties(getBooleanAttribute(UNSET_PROPS_ATTR));
}
/**
@@ -136,6 +151,24 @@
}
}
+ /**
+ * Validate that the given attribute and value are valid.
+ *
+ * @param attributeName The name of the attributes
+ * @param attributeValue The value of the attributes
+ * @exception SAXParseException if the attribute is not allowed on the
+ * element.
+ */
+ protected void validateAttribute(String attributeName,
+ String attributeValue)
+ throws SAXParseException {
+ for (int i = 0; i < ALLOWED_ATTRIBUTES.length; ++i) {
+ if (attributeName.equals(ALLOWED_ATTRIBUTES[i])) {
+ return;
+ }
+ }
+ throwInvalidAttribute(attributeName);
+ }
}
1.4 +15 -4
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionDataService.java
Index: ExecutionDataService.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionDataService.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -u -r1.3 -r1.4
--- ExecutionDataService.java 5 Feb 2002 11:49:04 -0000 1.3
+++ ExecutionDataService.java 6 Feb 2002 12:52:57 -0000 1.4
@@ -72,13 +72,20 @@
/** The ExecutionFrame this service instance is working for */
private ExecutionFrame frame;
+ /** all properties to be unset without throwing an exception */
+ private boolean allowUnsetProperties;
+
/**
* Constructor
*
* @param frame the frame containing this context
+ * @param allowUnsetProperties true if the reference to an unset
+ * property should not throw an exception
*/
- public ExecutionDataService(ExecutionFrame frame) {
+ public ExecutionDataService(ExecutionFrame frame,
+ boolean allowUnsetProperties) {
this.frame = frame;
+ this.allowUnsetProperties = allowUnsetProperties;
}
/**
@@ -169,10 +176,14 @@
if (fragment == null) {
String propertyName = (String)j.next();
if (!isDataValueSet(propertyName)) {
- throw new ExecutionException("Property \"" + propertyName
- + "\" has not been set");
+ if (!allowUnsetProperties) {
+ throw new ExecutionException("Property \""
+ + propertyName + "\" has not been set");
}
+ fragment = "${" + propertyName + "}";
+ } else {
fragment = getDataValue(propertyName).toString();
+ }
}
sb.append(fragment);
}
1.9 +5 -4
jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFrame.java
Index: ExecutionFrame.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antcore/org/apache/ant/antcore/execution/ExecutionFrame.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -w -u -r1.8 -r1.9
--- ExecutionFrame.java 6 Feb 2002 10:15:04 -0000 1.8
+++ ExecutionFrame.java 6 Feb 2002 12:52:57 -0000 1.9
@@ -168,9 +168,6 @@
this.standardLibs = standardLibs;
this.config = config;
this.initConfig = initConfig;
-
- configureServices();
- componentManager.setStandardLibraries(standardLibs);
}
/**
@@ -206,6 +203,9 @@
referencedFrames.put(referenceName, referencedFrame);
}
+
+ configureServices();
+ componentManager.setStandardLibraries(standardLibs);
}
/**
@@ -747,7 +747,8 @@
fileService = new ExecutionFileService(this);
componentManager
= new ComponentManager(this, config.isRemoteLibAllowed());
- dataService = new ExecutionDataService(this);
+ dataService = new ExecutionDataService(this,
+ config.isUnsetPropertiesAllowed());
services.put(FileService.class, fileService);
services.put(ComponentService.class, componentManager);
1.4 +125 -56
jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Project.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -u -r1.3 -r1.4
--- Project.java 5 Feb 2002 11:49:05 -0000 1.3
+++ Project.java 6 Feb 2002 12:52:57 -0000 1.4
@@ -54,17 +54,18 @@
package org.apache.tools.ant;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
import java.util.Hashtable;
-import java.util.Map;
import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
import org.apache.ant.common.antlib.AntContext;
import org.apache.ant.common.service.DataService;
import org.apache.ant.common.service.FileService;
import org.apache.ant.common.util.ExecutionException;
-import org.apache.ant.common.util.PropertyUtils;
import org.apache.ant.common.util.MessageLevel;
-import org.apache.tools.ant.taskdefs.ExecTask;
-import org.apache.tools.ant.taskdefs.Java;
+import org.apache.ant.common.util.PropertyUtils;
import org.apache.tools.ant.types.FilterSet;
import org.apache.tools.ant.types.FilterSetCollection;
import org.apache.tools.ant.util.FileUtils;
@@ -112,6 +113,11 @@
/** The java version detected that Ant is running on */
private static String javaVersion;
+ /** Collection of Ant1 type definitions */
+ private Hashtable dataClassDefinitions = new Hashtable();
+ /** Collection of Ant1 task definitions */
+ private Hashtable taskClassDefinitions = new Hashtable();
+
/** The project description */
private String description;
@@ -357,6 +363,53 @@
}
/**
+ * get a copy of the property hashtable
+ *
+ * @return the hashtable containing all properties, user included
+ */
+ public Hashtable getProperties() {
+ Map properties = dataService.getAllProperties();
+ Hashtable result = new Hashtable();
+ for (Iterator i = properties.keySet().iterator(); i.hasNext(); ) {
+ String name = (String)i.next();
+ Object value = properties.get(name);
+ if (value instanceof String) {
+ result.put(name, value);
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * get a copy of the property hashtable
+ *
+ * @return the hashtable containing all properties, user included
+ */
+ public Hashtable getUserProperties() {
+ return getProperties();
+ }
+
+ /**
+ * Get all references in the project
+ *
+ * @return the hashtable containing all references
+ */
+ public Hashtable getReferences() {
+ Map properties = dataService.getAllProperties();
+ Hashtable result = new Hashtable();
+ for (Iterator i = properties.keySet().iterator(); i.hasNext(); ) {
+ String name = (String)i.next();
+ Object value = properties.get(name);
+ if (!(value instanceof String)) {
+ result.put(name, value);
+ }
+ }
+
+ return result;
+ }
+
+ /**
* Add a reference to an object. NOte that in Ant2 objects and
* properties occupy the same namespace.
*
@@ -524,6 +577,66 @@
this.context = context;
fileService = (FileService)context.getCoreService(FileService.class);
dataService = (DataService)context.getCoreService(DataService.class);
+
+ String defs = "/org/apache/tools/ant/taskdefs/defaults.properties";
+
+ try {
+ Properties props = new Properties();
+ InputStream in = this.getClass().getResourceAsStream(defs);
+ if (in == null) {
+ throw new BuildException("Can't load default task list");
+ }
+ props.load(in);
+ in.close();
+
+ Enumeration enum = props.propertyNames();
+ while (enum.hasMoreElements()) {
+ String key = (String)enum.nextElement();
+ String value = props.getProperty(key);
+ try {
+ Class taskClass = Class.forName(value);
+ taskClassDefinitions.put(key, taskClass);
+ } catch (NoClassDefFoundError ncdfe) {
+ log("Could not load a dependent class ("
+ + ncdfe.getMessage() + ") for task " + key,
MSG_DEBUG);
+ } catch (ClassNotFoundException cnfe) {
+ log("Could not load class (" + value
+ + ") for task " + key, MSG_DEBUG);
+ }
+ }
+ } catch (IOException ioe) {
+ throw new BuildException("Can't load default task list");
+ }
+
+ String dataDefs = "/org/apache/tools/ant/types/defaults.properties";
+
+ try {
+ Properties props = new Properties();
+ InputStream in = this.getClass().getResourceAsStream(dataDefs);
+ if (in == null) {
+ throw new BuildException("Can't load default datatype list");
+ }
+ props.load(in);
+ in.close();
+
+ Enumeration enum = props.propertyNames();
+ while (enum.hasMoreElements()) {
+ String key = (String)enum.nextElement();
+ String value = props.getProperty(key);
+ try {
+ Class dataClass = Class.forName(value);
+ dataClassDefinitions.put(key, dataClass);
+ } catch (NoClassDefFoundError ncdfe) {
+ log("Could not load a dependent class ("
+ + ncdfe.getMessage() + ") for type " + key,
MSG_DEBUG);
+ } catch (ClassNotFoundException cnfe) {
+ log("Could not load class (" + value
+ + ") for type " + key, MSG_DEBUG);
+ }
+ }
+ } catch (IOException ioe) {
+ throw new BuildException("Can't load default datatype list");
+ }
}
/**
@@ -600,70 +713,26 @@
* Create a Task. This faced hard codes a few well known tasks at this
* time
*
- * @param taskName the name of the task to be created.
+ * @param taskType the name of the task to be created.
* @return the created task instance
*/
- public Task createTask(String taskName) {
+ public Task createTask(String taskType) {
// we piggy back the task onto the current context
Task task = null;
- if (taskName.equals("java")) {
- task = new Java();
- } else if (taskName.equals("exec")) {
- task = new ExecTask();
- } else {
+ Class c = (Class) taskClassDefinitions.get(taskType);
+
+ if (c == null) {
return null;
}
+
try {
+ task = (Task)c.newInstance();
task.setProject(this);
task.init(context);
return task;
- } catch (ExecutionException e) {
+ } catch (Throwable e) {
throw new BuildException(e);
}
- }
-
- /**
- * get a copy of the property hashtable
- * @return the hashtable containing all properties, user included
- */
- public Hashtable getProperties() {
- Map properties = dataService.getAllProperties();
- Hashtable result = new Hashtable();
- for (Iterator i = properties.keySet().iterator(); i.hasNext(); ) {
- String name = (String)i.next();
- Object value = properties.get(name);
- if (value instanceof String) {
- result.put(name, value);
- }
- }
-
- return result;
- }
-
- /**
- * get a copy of the property hashtable
- * @return the hashtable containing all properties, user included
- */
- public Hashtable getUserProperties() {
- return getProperties();
- }
-
- /**
- * Get all references in the project
- * @return the hashtable containing all references
- */
- public Hashtable getReferences() {
- Map properties = dataService.getAllProperties();
- Hashtable result = new Hashtable();
- for (Iterator i = properties.keySet().iterator(); i.hasNext(); ) {
- String name = (String)i.next();
- Object value = properties.get(name);
- if (!(value instanceof String)) {
- result.put(name, value);
- }
- }
-
- return result;
}
}
1.4 +5 -3
jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Task.java
Index: Task.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/antlibs/ant1compat/org/apache/tools/ant/Task.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -u -r1.3 -r1.4
--- Task.java 6 Feb 2002 10:15:04 -0000 1.3
+++ Task.java 6 Feb 2002 12:52:57 -0000 1.4
@@ -83,9 +83,11 @@
public void init(AntContext context) throws ExecutionException {
super.init(context);
+ if (context.getModelElement() instanceof BuildElement) {
BuildElement buildElement = (BuildElement)context.getModelElement();
taskType = buildElement.getType();
taskName = taskType;
+ }
}
/**
1.6 +0 -1
jakarta-ant/proposal/mutant/src/java/cli/org/apache/ant/cli/Commandline.java
Index: Commandline.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/proposal/mutant/src/java/cli/org/apache/ant/cli/Commandline.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -w -u -r1.5 -r1.6
--- Commandline.java 6 Feb 2002 10:15:04 -0000 1.5
+++ Commandline.java 6 Feb 2002 12:52:58 -0000 1.6
@@ -260,7 +260,6 @@
*/
private void process(String[] args, InitConfig initConfig) {
this.initConfig = initConfig;
- System.out.println("Ant Home is " + initConfig.getAntHome());
try {
parseArguments(args);
1.5 +0 -1
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.4
retrieving revision 1.5
diff -u -w -u -r1.4 -r1.5
--- Main.java 6 Feb 2002 10:15:05 -0000 1.4
+++ Main.java 6 Feb 2002 12:52:58 -0000 1.5
@@ -196,7 +196,6 @@
InitConfig config = new InitConfig();
URL libraryURL = getLibraryURL();
- System.out.println("Library URL is " + libraryURL);
config.setLibraryURL(libraryURL);
URL antHome = getAntHome();
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>