bodewig 01/08/03 09:38:21
Modified: . build.xml
src/main/org/apache/tools/ant AntClassLoader.java
TaskAdapter.java
src/main/org/apache/tools/ant/taskdefs Available.java
UpToDate.java defaults.properties
src/main/org/apache/tools/ant/types Path.java
Added: src/main/org/apache/tools/ant/taskdefs ConditionTask.java
src/main/org/apache/tools/ant/taskdefs/condition And.java
Condition.java ConditionBase.java Equals.java
Not.java Or.java Os.java
Log:
New task <condition>.
This is a first cut of the generalization of <available> and
<uptodate> that is on the list for Ant2. This task supports a single
condition and sets a property if it holds true - conditions can be
containers for other conditions in turn, giving it the opportunity to
support boolean logic.
Built in conditions as of now:
* <available> and <uptodate> (slightly modified the tasks to allow them to
be used as conditions)
* containers <and>, <or> and <not>
* New conditions <equals> (compares to Strings) and <os> which should
give easier access to os.name.
More extensive documentation to follow. Take a look at Ant's build
file, it uses the task to detect whether javamail is available now.
I had to perform some ugly tricks to make sure that project gets
passed to every object that will need it - this will be very different
in the future I hope.
Revision Changes Path
1.168 +9 -13 jakarta-ant/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/build.xml,v
retrieving revision 1.167
retrieving revision 1.168
diff -u -r1.167 -r1.168
--- build.xml 2001/08/03 14:21:00 1.167
+++ build.xml 2001/08/03 16:38:20 1.168
@@ -89,7 +89,7 @@
Check to see what optional dependencies are available
===================================================================
-->
- <target name="check_for_optional_packages_1">
+ <target name="check_for_optional_packages">
<available property="jdk1.2+" classname="java.lang.ThreadLocal" />
<available property="jdk1.3+" classname="java.lang.StrictMath" />
<available property="jdk1.4+" classname="java.lang.CharSequence" />
@@ -147,22 +147,18 @@
<available property="jdepend.present"
classname="jdepend.framework.JDepend"
classpathref="classpath"/>
- <available property="jaf.present"
- classname="javax.activation.DataHandler"
- classpathref="classpath"/>
<available property="log4j.present"
classname="org.apache.log4j.Category"
classpathref="classpath"/>
-
- </target>
-
- <target name="check_for_optional_packages"
- depends="check_for_optional_packages_1"
- if="jaf.present">
- <available property="javamail.complete"
- classname="javax.mail.Transport"
- classpathref="classpath"/>
+ <condition property="javamail.complete">
+ <and>
+ <available classname="javax.activation.DataHandler"
+ classpathref="classpath"/>
+ <available classname="javax.mail.Transport"
+ classpathref="classpath"/>
+ </and>
+ </condition>
</target>
<!--
1.32 +1 -1
jakarta-ant/src/main/org/apache/tools/ant/AntClassLoader.java
Index: AntClassLoader.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/AntClassLoader.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- AntClassLoader.java 2001/07/24 14:53:40 1.31
+++ AntClassLoader.java 2001/08/03 16:38:20 1.32
@@ -237,7 +237,7 @@
/**
* Create a classloader for the given project using the classpath given.
*
- * @param project the project to ehich this classloader is to belong.
+ * @param project the project to which this classloader is to belong.
* @param classpath the classpath to use to load the classes. This
* is combined with the system classpath in a manner
* determined by the value of ${build.sysclasspath}
1.6 +15 -0
jakarta-ant/src/main/org/apache/tools/ant/TaskAdapter.java
Index: TaskAdapter.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/TaskAdapter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TaskAdapter.java 2001/01/03 14:18:27 1.5
+++ TaskAdapter.java 2001/08/03 16:38:20 1.6
@@ -71,6 +71,21 @@
* Do the execution.
*/
public void execute() throws BuildException {
+ Method setProjectM = null;
+ try {
+ Class c = proxy.getClass();
+ setProjectM =
+ c.getMethod( "setProject", new Class[] {Project.class});
+ if(setProjectM != null) {
+ setProjectM.invoke(proxy, new Object[] {project});
+ }
+ } catch( Exception ex ) {
+ log("Error setting project in " + proxy.getClass(),
+ Project.MSG_ERR);
+ throw new BuildException( ex );
+ }
+
+
Method executeM=null;
try {
Class c=proxy.getClass();
1.24 +14 -5
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java
Index: Available.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Available.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- Available.java 2001/07/18 03:16:05 1.23
+++ Available.java 2001/08/03 16:38:20 1.24
@@ -57,6 +57,7 @@
import java.io.*;
import java.util.*;
import org.apache.tools.ant.*;
+import org.apache.tools.ant.taskdefs.condition.Condition;
import org.apache.tools.ant.types.*;
/**
@@ -65,7 +66,7 @@
* @author Stefano Mazzocchi <a href="mailto:[EMAIL PROTECTED]">[EMAIL
PROTECTED]</a>
*/
-public class Available extends Task {
+public class Available extends Task implements Condition {
private String property;
private String classname;
@@ -133,7 +134,13 @@
if (property == null) {
throw new BuildException("property attribute is required",
location);
}
+
+ if (eval()) {
+ this.project.setProperty(property, value);
+ }
+ }
+ public boolean eval() throws BuildException {
if (classname == null && file == null && resource == null) {
throw new BuildException("At least one of
(classname|file|resource) is required", location);
}
@@ -145,28 +152,30 @@
}
if (classpath != null) {
+ classpath.setProject(project);
this.loader = new AntClassLoader(project, classpath);
}
if ((classname != null) && !checkClass(classname)) {
log("Unable to load class " + classname + " to set property " +
property, Project.MSG_VERBOSE);
- return;
+ return false;
}
if ((file != null) && !checkFile()) {
log("Unable to find " + file + " to set property " + property,
Project.MSG_VERBOSE);
- return;
+ return false;
}
if ((resource != null) && !checkResource(resource)) {
log("Unable to load resource " + resource + " to set property "
+ property, Project.MSG_VERBOSE);
- return;
+ return false;
}
- this.project.setProperty(property, value);
if (loader != null) {
loader.cleanup();
}
+
+ return true;
}
private boolean checkFile() {
1.7 +14 -6
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/UpToDate.java
Index: UpToDate.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/UpToDate.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- UpToDate.java 2001/07/12 10:06:40 1.6
+++ UpToDate.java 2001/08/03 16:38:20 1.7
@@ -55,6 +55,7 @@
package org.apache.tools.ant.taskdefs;
import org.apache.tools.ant.*;
+import org.apache.tools.ant.taskdefs.condition.Condition;
import org.apache.tools.ant.types.*;
import org.apache.tools.ant.util.*;
import java.io.*;
@@ -71,7 +72,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
*/
-public class UpToDate extends MatchingTask {
+public class UpToDate extends MatchingTask implements Condition {
private String _property;
private String _value;
@@ -137,11 +138,9 @@
}
/**
- * Sets property to true if target files have a more recent timestamp
than
- * each of the corresponding source files.
+ * Evaluate all target and source files, see if the targets are
up-to-date.
*/
- public void execute() throws BuildException {
-
+ public boolean eval() {
if (sourceFileSets.size() == 0) {
throw new BuildException("At least one <srcfiles> element must be
set");
}
@@ -151,7 +150,7 @@
}
// if not there then it can't be up to date
- if (_targetFile != null && !_targetFile.exists()) return;
+ if (_targetFile != null && !_targetFile.exists()) return false;
Enumeration enum = sourceFileSets.elements();
boolean upToDate = true;
@@ -161,7 +160,16 @@
upToDate = upToDate && scanDir(fs.getDir(project),
ds.getIncludedFiles());
}
+ return upToDate;
+ }
+
+ /**
+ * Sets property to true if target files have a more recent timestamp
than
+ * each of the corresponding source files.
+ */
+ public void execute() throws BuildException {
+ boolean upToDate = eval();
if (upToDate) {
this.project.setProperty(_property, this.getValue());
if (mapperElement == null) {
1.87 +1 -0
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties
Index: defaults.properties
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -r1.86 -r1.87
--- defaults.properties 2001/08/01 10:43:58 1.86
+++ defaults.properties 2001/08/03 16:38:20 1.87
@@ -51,6 +51,7 @@
ear=org.apache.tools.ant.taskdefs.Ear
parallel=org.apache.tools.ant.taskdefs.Parallel
sequential=org.apache.tools.ant.taskdefs.Sequential
+condition=org.apache.tools.ant.taskdefs.ConditionTask
# optional tasks
script=org.apache.tools.ant.taskdefs.optional.Script
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ConditionTask.java
Index: ConditionTask.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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.tools.ant.taskdefs;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.condition.Condition;
import org.apache.tools.ant.taskdefs.condition.ConditionBase;
/**
* <condition> task as a generalization of <available> and
* <uptodate>
*
* <p>This task supports boolean logic as well as pluggable conditions
* to decide, whether a property should be set.</p>
*
* <p>This task does not extend Task to take advantage of
* ConditionBase.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]>Stefan Bodewig</a>
* @version $Revision: 1.1 $
*/
public class ConditionTask extends ConditionBase {
private String property;
private String value = "true";
/**
* The name of the property to set. Required.
*
* @since 1.1
*/
public void setProperty(String p) {property = p;}
/**
* The value for the property to set. Defaults to "true".
*
* @since 1.1
*/
public void setValue(String v) {value = v;}
/**
* See whether our nested condition holds and set the property.
*
* @since 1.1
*/
public void execute() throws BuildException {
if (countConditions() > 1) {
throw new BuildException("You must not nest more than one
condition into <condition>");
}
if (countConditions() < 1) {
throw new BuildException("You must nest a condition into
<condition>");
}
Condition c = (Condition) getConditions().nextElement();
if (c.eval()) {
getProject().setProperty(property, value);
}
}
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/And.java
Index: And.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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.tools.ant.taskdefs.condition;
import java.util.Enumeration;
import org.apache.tools.ant.BuildException;
/**
* <and> condition container.
*
* <p>Iterates over all conditions and returns false as soon as one
* evaluates to false.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]>Stefan Bodewig</a>
* @version $Revision: 1.1 $
*/
public class And extends ConditionBase implements Condition {
public boolean eval() throws BuildException {
Enumeration enum = getConditions();
while (enum.hasMoreElements()) {
Condition c = (Condition) enum.nextElement();
if (!c.eval()) {
return false;
}
}
return true;
}
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/Condition.java
Index: Condition.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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.tools.ant.taskdefs.condition;
import org.apache.tools.ant.BuildException;
/**
* Interface for conditions to use inside the <condition> task.
*
* @author <a href="mailto:[EMAIL PROTECTED]>Stefan Bodewig</a>
* @version $Revision: 1.1 $
*/
public interface Condition {
/**
* Is this condition true?
*/
public boolean eval() throws BuildException;
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java
Index: ConditionBase.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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.tools.ant.taskdefs.condition;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import java.util.Vector;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.Available;
import org.apache.tools.ant.taskdefs.UpToDate;
/**
* Baseclass for the <condition> task as well as several
* conditions - ensures that the types of conditions inside the task
* and the "container" conditions are in sync.
*
* @author <a href="mailto:[EMAIL PROTECTED]>Stefan Bodewig</a>
* @version $Revision: 1.1 $
*/
public abstract class ConditionBase {
private Vector conditions = new Vector();
private Project project;
public void setProject(Project p) {
this.project = p;
}
protected Project getProject() {return project;}
/**
* Count the conditions.
*
* @since 1.1
*/
protected int countConditions() {return conditions.size();}
/**
* Iterate through all conditions.
*
* @since 1.1
*/
protected final Enumeration getConditions() {
return new ConditionEnumeration();
}
/**
* Add an <available> condition.
*
* @since 1.1
*/
public void addAvailable(Available a) {conditions.addElement(a);}
/**
* Add an <uptodate> condition.
*
* @since 1.1
*/
public void addUptodate(UpToDate u) {conditions.addElement(u);}
/**
* Add an <not> condition "container".
*
* @since 1.1
*/
public void addNot(Not n) {conditions.addElement(n);}
/**
* Add an <and> condition "container".
*
* @since 1.1
*/
public void addAnd(And a) {conditions.addElement(a);}
/**
* Add an <or> condition "container".
*
* @since 1.1
*/
public void addOr(Or o) {conditions.addElement(o);}
/**
* Add an <equals> condition.
*
* @since 1.1
*/
public void addEquals(Equals e) {conditions.addElement(e);}
/**
* Add an <os> condition.
*
* @since 1.1
*/
public void addOs(Os o) {conditions.addElement(o);}
/**
* Inner class that configures those conditions with a project
* instance that need it.
*
* @since 1.1
*/
private class ConditionEnumeration implements Enumeration {
private int currentElement = 0;
public boolean hasMoreElements() {
return countConditions() > currentElement;
}
public Object nextElement() throws NoSuchElementException {
Object o = null;
try {
o = conditions.elementAt(currentElement++);
} catch (ArrayIndexOutOfBoundsException e) {
throw new NoSuchElementException();
}
if (o instanceof Task) {
((Task) o).setProject(getProject());
} else if (o instanceof ConditionBase) {
((ConditionBase) o).setProject(getProject());
}
return o;
}
}
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/Equals.java
Index: Equals.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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.tools.ant.taskdefs.condition;
import org.apache.tools.ant.BuildException;
/**
* Simple String comparison condition.
*
* @author <a href="mailto:[EMAIL PROTECTED]>Stefan Bodewig</a>
* @version $Revision: 1.1 $
*/
public class Equals implements Condition {
private String arg1, arg2;
public void setArg1(String a1) {arg1 = a1;}
public void setArg2(String a2) {arg2 = a2;}
public boolean eval() throws BuildException {
if (arg1 == null || arg2 == null) {
throw new BuildException("both arg1 and arg2 are required in
equals");
}
return arg1.equals(arg2);
}
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/Not.java
Index: Not.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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.tools.ant.taskdefs.condition;
import org.apache.tools.ant.BuildException;
/**
* <not> condition.
*
* Evaluates to true if the single condition nested into it is false
* and vice versa.
*
* @author <a href="mailto:[EMAIL PROTECTED]>Stefan Bodewig</a>
* @version $Revision: 1.1 $
*/
public class Not extends ConditionBase implements Condition {
public boolean eval() throws BuildException {
if (countConditions() > 1) {
throw new BuildException("You must not nest more than one
condition into <not>");
}
if (countConditions() < 1) {
throw new BuildException("You must nest a condition into <not>");
}
return !((Condition) getConditions().nextElement()).eval();
}
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/Or.java
Index: Or.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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.tools.ant.taskdefs.condition;
import java.util.Enumeration;
import org.apache.tools.ant.BuildException;
/**
* <or> condition container.
*
* <p>Iterates over all conditions and returns true as soon as one
* evaluates to true.</p>
*
* @author <a href="mailto:[EMAIL PROTECTED]>Stefan Bodewig</a>
* @version $Revision: 1.1 $
*/
public class Or extends ConditionBase implements Condition {
public boolean eval() throws BuildException {
Enumeration enum = getConditions();
while (enum.hasMoreElements()) {
Condition c = (Condition) enum.nextElement();
if (c.eval()) {
return true;
}
}
return false;
}
}
1.1
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/condition/Os.java
Index: Os.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 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 [EMAIL PROTECTED]
*
* 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.tools.ant.taskdefs.condition;
import org.apache.tools.ant.BuildException;
/**
* Condition that tests the OS type.
*
* @author <a href="mailto:[EMAIL PROTECTED]>Stefan Bodewig</a>
* @version $Revision: 1.1 $
*/
public class Os implements Condition {
private String family;
public void setFamily(String f) {family = f.toLowerCase();}
public boolean eval() throws BuildException {
String osName = System.getProperty("os.name").toLowerCase();
String pathSep = System.getProperty("path.separator");
if (family != null) {
if (family.equals("windows")) {
return osName.indexOf("windows") > -1;
} else if (family.equals("dos")) {
return pathSep.equals(";");
} else if (family.equals("mac")) {
return osName.indexOf("mac") > -1;
} else if (family.equals("unix")) {
return pathSep.equals(":")
&& (!osName.startsWith("mac") || osName.endsWith("x"));
}
throw new BuildException("Don\'t know how to detect os family \""
+ family + "\"");
}
return false;
}
}
1.20 +10 -1 jakarta-ant/src/main/org/apache/tools/ant/types/Path.java
Index: Path.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Path.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- Path.java 2001/07/10 15:40:09 1.19
+++ Path.java 2001/08/03 16:38:21 1.20
@@ -138,6 +138,11 @@
elements = new Vector();
}
+ public void setProject(Project p) {
+ this.project = p;
+ }
+ public Project getProject() {return project;}
+
/**
* Adds a element definition to the path.
* @param location the location of the element to add (must not be
@@ -285,7 +290,11 @@
addUnlessPresent(result, parts[j]);
}
} else if (o instanceof Path) {
- String[] parts = ((Path) o).list();
+ Path p = (Path) o;
+ if (p.getProject() == null) {
+ p.setProject(project);
+ }
+ String[] parts = p.list();
for (int j=0; j<parts.length; j++) {
addUnlessPresent(result, parts[j]);
}