Browse Source

Auto-discover built-in conditions added >= 1.7 from the accompanying antlib so we can stop adding junk setters to ConditionBase.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@439014 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 19 years ago
parent
commit
82353694ec
2 changed files with 44 additions and 101 deletions
  1. +30
    -93
      src/main/org/apache/tools/ant/taskdefs/condition/ConditionBase.java
  2. +14
    -8
      src/main/org/apache/tools/ant/taskdefs/condition/antlib.xml

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

@@ -19,6 +19,9 @@ package org.apache.tools.ant.taskdefs.condition;

import java.util.Enumeration;
import java.util.Vector;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.DynamicElement;
import org.apache.tools.ant.ComponentHelper;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.taskdefs.Available;
import org.apache.tools.ant.taskdefs.Checksum;
@@ -31,7 +34,11 @@ import org.apache.tools.ant.taskdefs.UpToDate;
*
* @since Ant 1.4
*/
public abstract class ConditionBase extends ProjectComponent {
public abstract class ConditionBase extends ProjectComponent
implements DynamicElement {

private static final String CONDITION_ANTLIB
= "antlib:org.apache.tools.ant.taskdefs.condition:";

/**
* name of the component
@@ -44,17 +51,16 @@ public abstract class ConditionBase extends ProjectComponent {
private Vector conditions = new Vector();

/**
* simple constructor.
* Simple constructor.
*/
protected ConditionBase() {
taskName = "component";
}

/**
* constructor that takes the name of the task
* in the task name
* Constructor that takes the name of the task in the task name.
* @param taskName
* @since Ant1.7
* @since Ant 1.7
*/
protected ConditionBase(String taskName) {
this.taskName = taskName;
@@ -260,24 +266,6 @@ public abstract class ConditionBase extends ProjectComponent {
conditions.addElement(i);
}

/**
* Add an <typefound> condition.
* @param test a TypeFound condition
* @since Ant 1.7
*/
public void addTypeFound(TypeFound test) {
conditions.addElement(test);
}

/**
* Add an <isfailure> condition.
*
* @param test the condition
*/
public void addIsFailure(IsFailure test) {
conditions.addElement(test);
}

/**
* Add an <isfileselected> condition.
* @param test the condition
@@ -287,81 +275,30 @@ public abstract class ConditionBase extends ProjectComponent {
}

/**
* Add an <isreachable> condition.
*
* @param test the condition
* @since Ant 1.7
*/
public void addIsReachable(IsReachable test) {
conditions.addElement(test);
}

/**
* Add an <issigned> condition.
*
* @param test the condition
* @since Ant 1.7
*/
public void addIsSigned(IsSigned test) {
conditions.addElement(test);
}

/**
* Add an <parsersupports> condition.
*
* @param test the condition
* @since Ant 1.7
*/
public void addParserSupports(ParserSupports test) {
conditions.addElement(test);
}

/**
* Add a <ResourcesMatch> condition.
*
* @param test the condition
* @since Ant 1.7
*/
public void addResourcesMatch(ResourcesMatch test) {
conditions.addElement(test);
}

/**
* Add an <xor> condition.
*
* @param test the condition
* @since Ant 1.7
*/
public void addXor(Xor test) {
conditions.addElement(test);
}

/**
* Add a <hasMethod> condition.
*
* @param test the condition
* @since Ant 1.7
* Add an arbitrary condition
* @param c a condition
* @since Ant 1.6
*/
public void addHasMethod(HasMethod test) {
add(test);
public void add(Condition c) {
conditions.addElement(c);
}

/**
* Add an <antversion> condition.
*
* @param test the condition
* @since Ant 1.7
* Create a dynamically discovered condition. Built-in conditions can
* be discovered from the org.apache.tools.ant.taskdefs.condition
* antlib.
* @param name the condition to create.
*/
public void addAntVersion(AntVersion test) {
conditions.addElement(test);
public Object createDynamicElement(String name) {
Object cond = ComponentHelper.getComponentHelper(getProject())
.createComponent(CONDITION_ANTLIB + name);
if (!(cond instanceof Condition)) {
return null;
}
log("Dynamically discovered '" + name + "' " + cond,
Project.MSG_DEBUG);
add((Condition) cond);
return cond;
}

/**
* Add an arbitrary condition
* @param c a condition
* @since Ant 1.6
*/
public void add(Condition c) {
conditions.addElement(c);
}
}

+ 14
- 8
src/main/org/apache/tools/ant/taskdefs/condition/antlib.xml View File

@@ -1,8 +1,8 @@
<?xml version="1.0"?>
<antlib>
<!--
/*
* Copyright 2006 The Apache Software Foundation
/*
* Copyright 2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,11 +19,17 @@
*/

-->
<!-- ant1.6+ antlib declaration for the conditions
use with the declaration xmlns:cond="antlib:org.apache.tools.ant.condition" to
trigger ant's autoload of this file into a namespace.
<!-- Ant 1.6+ antlib declaration for conditions:
Use with the declaration xmlns:cond="antlib:org.apache.tools.ant.condition" to
trigger Ant's autoload of this file into namespace 'cond' (or whatever name
suits).

Please keep this list in alphabetical order -it is easier to verify that way
Please keep this list in alphabetical order; it is easier to verify that way.

Additionally, ConditionBase uses this antlib to discover built-in conditions.
Prior to Ant 1.7, a new built-in condition required an addXXX method to be
added to ConditionBase. Conditions added in or after version 1.7 need only
to be added to this antlib.
-->

<typedef name="and" classname="org.apache.tools.ant.taskdefs.condition.And"/>
@@ -31,7 +37,7 @@
classname="org.apache.tools.ant.taskdefs.condition.AntVersion"/>
<typedef name="contains" classname="org.apache.tools.ant.taskdefs.condition.Contains"/>
<typedef name="equals" classname="org.apache.tools.ant.taskdefs.condition.Equals"/>
<typedef name="filesmatch" classname="org.apache.tools.ant.taskdefs.condition.Filesmatch"/>
<typedef name="filesmatch" classname="org.apache.tools.ant.taskdefs.condition.FilesMatch"/>
<typedef name="http" classname="org.apache.tools.ant.taskdefs.condition.Http"/>
<typedef name="isfailure" classname="org.apache.tools.ant.taskdefs.condition.IsFailure"/>
<typedef name="isfalse" classname="org.apache.tools.ant.taskdefs.condition.IsFalse"/>
@@ -50,4 +56,4 @@
<typedef name="socket" classname="org.apache.tools.ant.taskdefs.condition.Socket"/>
<typedef name="typefound" classname="org.apache.tools.ant.taskdefs.condition.TypeFound"/>
<typedef name="xor" classname="org.apache.tools.ant.taskdefs.condition.Xor"/>
</antlib>
</antlib>

Loading…
Cancel
Save