You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@locus.apache.org on 1999/12/12 03:20:34 UTC
cvs commit: jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs Property.java
costin 99/12/11 18:20:33
Modified: ant/src/main/org/apache/tools/ant Project.java
ProjectHelper.java
ant/src/main/org/apache/tools/ant/taskdefs Property.java
Log:
- Moved all initialization under init target.
- Removed Taskdef and property from ProjectHelper - now
it uses normal Tasks to define properties or tasks
- changed replace so it can be used by different tasks ( use
Properties instead of project)
Everything should work as before - all changed are backward compatible.
Revision Changes Path
1.18 +39 -29 jakarta-tools/ant/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Project.java 1999/12/10 22:30:37 1.17
+++ Project.java 1999/12/12 02:20:33 1.18
@@ -122,6 +122,13 @@
// ignore...
}
}
+
+ Properties systemP=System.getProperties();
+ Enumeration e=systemP.keys();
+ while( e.hasMoreElements() ) {
+ String n=(String) e.nextElement();
+ properties.put( n, systemP.get(n));
+ }
} catch (IOException ioe) {
String msg = "Can't load default task list";
System.out.println(msg);
@@ -149,7 +156,7 @@
public void log(String msg, String tag, int msgLevel) {
if (msgLevel <= msgOutputLevel) {
- out.println("[" + tag + "] " + msg);
+ out.println("[" + tag + "]" + msg);
}
}
@@ -161,11 +168,12 @@
public String getProperty(String name) {
String property = (String)properties.get(name);
- if (property == null) {
- property = System.getProperty(name);
- }
return property;
}
+
+ public Hashtable getProperties() {
+ return properties;
+ }
public void setDefaultTarget(String defaultTarget) {
this.defaultTarget = defaultTarget;
@@ -237,6 +245,7 @@
javaVersion = "1.2";
Class.forName("java.lang.StrictMath");
javaVersion = "1.3";
+ setProperty("ant.java.version", javaVersion);
}
catch (ClassNotFoundException cnfe) {
// swallow as we've hit the max class version that
@@ -246,9 +255,9 @@
}
public void addTaskDefinition(String taskName, Class taskClass) {
- String msg = " +User task: " + taskName + " " + taskClass.getName();
- log(msg, MSG_VERBOSE);
- taskClassDefinitions.put(taskName, taskClass);
+ String msg = " +User task: " + taskName + " " + taskClass.getName();
+ log(msg, MSG_VERBOSE);
+ taskClassDefinitions.put(taskName, taskClass);
}
/**
@@ -258,15 +267,15 @@
* @exception BuildException if the Target already exists
* in the project.
* @see Project#addOrReplaceTarget to replace existing Targets.
- */
- public void addTarget(Target target) throws BuildException {
- String name = target.getName();
- if (targets.get(name) != null) {
- throw new BuildException("Duplicate target: `"+name+"'");
- }
- addOrReplaceTarget(name, target);
+ */
+ public void addTarget(Target target) {
+ String name = target.getName();
+ if (targets.get(name) != null) {
+ throw new BuildException("Duplicate target: `"+name+"'");
+ }
+ addOrReplaceTarget(name, target);
}
-
+
/**
* This call expects to add a <em>new</em> Target.
* @param target is the Target to be added to the current
@@ -276,20 +285,20 @@
* in the project.
* @see Project#addOrReplaceTarget to replace existing Targets.
*/
- public void addTarget(String targetName, Target target)
- throws BuildException {
- if (targets.get(targetName) != null) {
- throw new BuildException("Duplicate target: `"+targetName+"'");
- }
- addOrReplaceTarget(targetName, target);
- }
+ public void addTarget(String targetName, Target target)
+ throws BuildException {
+ if (targets.get(targetName) != null) {
+ throw new BuildException("Duplicate target: `"+targetName+"'");
+ }
+ addOrReplaceTarget(targetName, target);
+ }
/**
* @param target is the Target to be added or replaced in
* the current Project.
*/
public void addOrReplaceTarget(Target target) {
- addOrReplaceTarget(target.getName(), target);
+ addOrReplaceTarget(target.getName(), target);
}
/**
@@ -298,11 +307,11 @@
* @param targetName is the name to use for the Target
*/
public void addOrReplaceTarget(String targetName, Target target) {
- String msg = " +Target: " + targetName;
- log(msg, MSG_VERBOSE);
- targets.put(targetName, target);
- }
-
+ String msg = " +Target: " + targetName;
+ log(msg, MSG_VERBOSE);
+ targets.put(targetName, target);
+ }
+
public Task createTask(String taskType) throws BuildException {
Class c = (Class)taskClassDefinitions.get(taskType);
@@ -341,6 +350,7 @@
int curidx = 0;
String curtarget;
+
do {
curtarget = (String) sortedTargets.elementAt(curidx++);
runTarget(curtarget, targets);
@@ -536,4 +546,4 @@
} while(!c.equals(end));
return new BuildException(new String(sb));
}
-}
\ No newline at end of file
+}
1.8 +50 -63 jakarta-tools/ant/src/main/org/apache/tools/ant/ProjectHelper.java
Index: ProjectHelper.java
===================================================================
RCS file: /home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ProjectHelper.java 1999/12/03 12:44:22 1.7
+++ ProjectHelper.java 1999/12/12 02:20:33 1.8
@@ -58,8 +58,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.reflect.*;
-import java.util.Hashtable;
-import java.util.StringTokenizer;
+import java.util.*;
import org.xml.sax.SAXException;
import org.w3c.dom.*;
@@ -70,7 +69,7 @@
* @author duncan@x180.com
*/
-class ProjectHelper {
+public class ProjectHelper {
static void configureProject(Project project, File buildFile)
throws BuildException
@@ -125,68 +124,47 @@
// set up any properties that may be in the config file
- configureProperties(project, root);
+ // configureProperties(project, root);
// set up any task defs that may be in the config file
- configureTaskDefs(project, root);
+ // configureTaskDefs(project, root);
// set up the targets into the project
-
+ init(project, root );
configureTargets(project, root);
}
- private static void configureProperties(Project project, Element root)
- throws BuildException
- {
- NodeList list = root.getElementsByTagName("property");
- for (int i = 0; i < list.getLength(); i++) {
- Element element = (Element)list.item(i);
- String propertyName = element.getAttribute("name");
- String propertyValue = element.getAttribute("value");
-
- // sanity check
- if (propertyName.equals("") || propertyValue.equals("")) {
- String msg = "name or value attributes of property element " +
- "are undefined";
- throw new BuildException(msg);
- }
-
- project.setProperty(propertyName,
- replaceProperties( project, propertyValue ));
- }
- }
-
- private static void configureTaskDefs(Project project, Element root)
+ /** Read and execute init - all other targets will be loaded after ( to
+ * make sure all properties are set ).
+ *
+ */
+ private static void init(Project project, Element root)
throws BuildException
{
- NodeList list = root.getElementsByTagName("taskdef");
+ // Hack - all tasks outside init target will be added to init
+ // ( will be removed when / if build.xml will start using init )
+ Target initTarget = new Target();
+ initTarget.setProject(project);
+ initTarget.setName( "init" );
+ project.addTarget( "init", initTarget );
+ configureTasks( project, initTarget, root );
+
+ NodeList list = root.getElementsByTagName("target");
for (int i = 0; i < list.getLength(); i++) {
Element element = (Element)list.item(i);
- String taskName = element.getAttribute("name");
- String taskClassName = element.getAttribute("class");
-
- // sanity check
- if (taskName.equals("") || taskClassName.equals("")) {
- String msg = "name or class attributes of taskdef element "
- + "are undefined";
- throw new BuildException(msg);
- }
-
- try {
- Class taskClass = Class.forName(taskClassName);
- project.addTaskDefinition(taskName, taskClass);
- } catch (ClassNotFoundException cnfe) {
- String msg = "taskdef class " + taskClassName +
- " cannot be found";
- throw new BuildException(msg);
- }
+ String targetName = element.getAttribute("name");
+
+ if( targetName.equals("init") )
+ configureTasks(project, initTarget, element);
}
+ initTarget.execute();
}
private static void configureTargets(Project project, Element root)
throws BuildException
{
+ // configure targets
NodeList list = root.getElementsByTagName("target");
for (int i = 0; i < list.getLength(); i++) {
Element element = (Element)list.item(i);
@@ -199,6 +177,10 @@
throw new BuildException(msg);
}
+ // init is done already
+ if( targetName.equals("init") )
+ continue;
+
Target target = new Target();
target.setName(targetName);
project.addTarget(targetName, target);
@@ -234,18 +216,23 @@
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element)node;
String taskType = element.getTagName();
-
- // XXX
- // put in some sanity checking
-
- Task task = project.createTask(taskType);
-
- // get the attributes of this element and reflect them
- // into the task
-
- NamedNodeMap nodeMap = element.getAttributes();
- configureTask(project, task, nodeMap);
- target.addTask(task);
+
+ // special case - no target in a target.
+ // hack to allow this method to set "init" target
+ // using root element
+ if( ! taskType.equals( "target" ) ) {
+ // XXX
+ // put in some sanity checking
+
+ Task task = project.createTask(taskType);
+
+ // get the attributes of this element and reflect them
+ // into the task
+
+ NamedNodeMap nodeMap = element.getAttributes();
+ configureTask(project, task, nodeMap);
+ target.addTask(task);
+ }
}
}
}
@@ -308,7 +295,7 @@
throw new BuildException(msg);
}
- String value=replaceProperties( project, attr.getValue() );
+ String value=replaceProperties( attr.getValue(), project.getProperties() );
try {
setMethod.invoke(task, new String[] {value});
} catch (IllegalAccessException iae) {
@@ -329,7 +316,7 @@
/** Replace ${NAME} with the property value
*/
- public static String replaceProperties( Project proj, String value )
+ public static String replaceProperties( String value, Hashtable keys )
throws BuildException
{
// XXX use Map instead of proj, it's too heavy
@@ -353,7 +340,7 @@
value );
}
String n=value.substring( pos+2, endName );
- String v=proj.getProperty( n );
+ String v=(String) keys.get( n );
//System.out.println("N: " + n + " " + " V:" + v);
sb.append( v );
prev=endName+1;
@@ -361,7 +348,7 @@
}
if( prev < value.length() ) sb.append( value.substring( prev ) );
// System.out.println("After replace: " + sb.toString());
- // System.out.println("Before replace: " + value);
+ // System.out.println("Before replace: " + value);
return sb.toString();
}
}
1.2 +7 -3 jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Property.java
Index: Property.java
===================================================================
RCS file: /home/cvs/jakarta-tools/ant/src/main/org/apache/tools/ant/taskdefs/Property.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Property.java 1999/12/11 23:00:22 1.1
+++ Property.java 1999/12/12 02:20:33 1.2
@@ -70,8 +70,11 @@
public void execute() throws BuildException {
try {
- if(name!=null)
- project.setProperty( name, value);
+ if(name!=null) {
+ String value1= ProjectHelper.replaceProperties(value, project.getProperties());
+ project.setProperty( name,value1);
+ }
+
if( file!=null)
loadFile( file );
if( resource!=null)
@@ -128,7 +131,8 @@
while( e.hasMoreElements() ) {
String name=(String)e.nextElement();
String value=(String)props.getProperty(name);
- project.setProperty( name, value);
+ String value1= ProjectHelper.replaceProperties(value, project.getProperties());
+ project.setProperty( name, value1);
}
}
}