Browse Source

Add new <isset> condition, simplify ConditionBase by using ProjectComponent.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269756 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
ede07a7c22
3 changed files with 105 additions and 12 deletions
  1. +15
    -0
      docs/manual/CoreTasks/condition.html
  2. +11
    -12
      src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java
  3. +79
    -0
      src/main/org/apache/tools/ant/taskdefs/condition/IsSet.java

+ 15
- 0
docs/manual/CoreTasks/condition.html View File

@@ -121,6 +121,21 @@ are redundant and will be ignored.</p>
</tr>
</table>

<h4>isset</h4>
<p>Test whether a given property has been set in this project.</p>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td valign="top"><b>Attribute</b></td>
<td valign="top"><b>Description</b></td>
<td align="center" valign="top"><b>Required</b></td>
</tr>
<tr>
<td valign="top">property</td>
<td valign="top">The name of the property to test.</td>
<td valign="top" align="center">Yes</td>
</tr>
</table>

<h3>Examples</h3>
<pre>
&lt;condition property=&quot;javamail.complete&quot;&gt;


+ 11
- 12
src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java View File

@@ -59,7 +59,7 @@ 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.ProjectComponent;
import org.apache.tools.ant.taskdefs.Available;
import org.apache.tools.ant.taskdefs.UpToDate;

@@ -71,14 +71,8 @@ import org.apache.tools.ant.taskdefs.UpToDate;
* @author <a href="mailto:stefan.bodewig@epost.de>Stefan Bodewig</a>
* @version $Revision$
*/
public abstract class ConditionBase {
public abstract class ConditionBase extends ProjectComponent {
private Vector conditions = new Vector();
private Project project;

public void setProject(Project p) {
this.project = p;
}
protected Project getProject() {return project;}

/**
* Count the conditions.
@@ -145,6 +139,13 @@ public abstract class ConditionBase {
*/
public void addOs(Os o) {conditions.addElement(o);}

/**
* Add an &lt;isset&gt; condition.
*
* @since 1.1
*/
public void addIsSet(IsSet i) {conditions.addElement(i);}

/**
* Inner class that configures those conditions with a project
* instance that need it.
@@ -166,10 +167,8 @@ public abstract class ConditionBase {
throw new NoSuchElementException();
}
if (o instanceof Task) {
((Task) o).setProject(getProject());
} else if (o instanceof ConditionBase) {
((ConditionBase) o).setProject(getProject());
if (o instanceof ProjectComponent) {
((ProjectComponent) o).setProject(getProject());
}
return o;
}


+ 79
- 0
src/main/org/apache/tools/ant/taskdefs/condition/IsSet.java View File

@@ -0,0 +1,79 @@
/*
* 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 apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/

package org.apache.tools.ant.taskdefs.condition;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent;

/**
* Condition that tests whether a given property has been set.
*
* @author <a href="mailto:stefan.bodewig@epost.de>Stefan Bodewig</a>
* @version $Revision$
*/
public class IsSet extends ProjectComponent implements Condition {
private String property;

public void setProperty(String p) {property = p;}

public boolean eval() throws BuildException {
if (property == null) {
throw new BuildException("No property specified for isset condition");
}
return getProject().getProperty(property) != null;
}

}

Loading…
Cancel
Save