@@ -1,5 +1,5 @@
/*
/*
* Copyright 2001-2004 The Apache Software Foundation
* Copyright 2001-2005 The Apache Software Foundation
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
@@ -42,6 +42,7 @@ public class ConditionTask extends ConditionBase {
private String property = null;
private String property = null;
private String value = "true";
private String value = "true";
private String alternative = null;
/**
/**
* The name of the property to set. Required.
* The name of the property to set. Required.
@@ -62,6 +63,16 @@ public class ConditionTask extends ConditionBase {
value = v;
value = v;
}
}
/**
* The value for the property to set, if condition evaluates to false.
* If this attribute is not specified, the property will not be set.
* @param e the alternate value of the property.
* @since Ant 1.6.3
*/
public void setElse(String e) {
alternative = e;
}
/**
/**
* See whether our nested condition holds and set the property.
* See whether our nested condition holds and set the property.
*
*
@@ -80,12 +91,15 @@ public class ConditionTask extends ConditionBase {
if (property == null) {
if (property == null) {
throw new BuildException("The property attribute is required.");
throw new BuildException("The property attribute is required.");
}
}
Condition c = (Condition) getConditions().nextElement();
Condition c = (Condition) getConditions().nextElement();
if (c.eval()) {
if (c.eval()) {
log("Condition true; setting " + property + " to " + value,
log("Condition true; setting " + property + " to " + value,
Project.MSG_DEBUG);
Project.MSG_DEBUG);
getProject().setNewProperty(property, value);
getProject().setNewProperty(property, value);
} else if (alternative != null) {
log("Condition false; setting " + property + " to " + alternative,
Project.MSG_DEBUG);
getProject().setNewProperty(property, alternative);
} else {
} else {
log("Condition false; not setting " + property,
log("Condition false; not setting " + property,
Project.MSG_DEBUG);
Project.MSG_DEBUG);