You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by jl...@apache.org on 2013/12/07 09:08:04 UTC
svn commit: r1548807 - in /ant/easyant/core/trunk/src:
main/java/org/apache/easyant/tasks/ParameterTask.java
test/java/org/apache/easyant/tasks/ParameterTaskTest.java
Author: jlboudart
Date: Sat Dec 7 08:08:04 2013
New Revision: 1548807
URL: http://svn.apache.org/r1548807
Log:
EASYANT-58 required attribute of path parameter is ignored (thanks to Jérôme Leroux)
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ParameterTask.java
ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/ParameterTaskTest.java
Modified: ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ParameterTask.java
URL: http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ParameterTask.java?rev=1548807&r1=1548806&r2=1548807&view=diff
==============================================================================
--- ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ParameterTask.java (original)
+++ ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ParameterTask.java Sat Dec 7 08:08:04 2013
@@ -186,31 +186,9 @@ public class ParameterTask extends Task
public void execute() throws BuildException {
if (property != null) {
- if (isRequired() && getProject().getProperty(property) == null) {
- throw new BuildException("expected property '" + property + "': " + description);
- }
- if (!possibleValues.isEmpty()) {
- String currentValue = getProject().getProperty(property);
- if (!possibleValues.contains(currentValue)) {
- throw new BuildException("current value of property '" + property
- + "' doesn't match with possible values : " + possibleValues.toString());
- }
- }
- if (defaultValue != null && getProject().getProperty(property) == null) {
- Property propTask = new Property();
- propTask.setProject(getProject());
- propTask.setTaskName(getTaskName());
- propTask.setName(property);
- propTask.setValue(defaultValue);
- propTask.execute();
- }
+ handlePropertyParameter();
} else if (path != null) {
- Object p = getProject().getReference(path);
- if (isRequired() && p == null) {
- throw new BuildException("expected path '" + path + "': " + description);
- } else if (!(p instanceof Path)) {
- throw new BuildException("reference '" + path + "' must be a path");
- }
+ handlePathParameter();
} else if (phase != null) {
// to be removed
} else {
@@ -218,6 +196,36 @@ public class ParameterTask extends Task
}
}
+ private void handlePathParameter() {
+ Object p = getProject().getReference(path);
+ if (isRequired() && p == null) {
+ throw new BuildException("expected path '" + path + "': " + description);
+ } else if (p != null && !(p instanceof Path)) {
+ throw new BuildException("reference '" + path + "' must be a path");
+ }
+ }
+
+ private void handlePropertyParameter() {
+ if (isRequired() && getProject().getProperty(property) == null) {
+ throw new BuildException("expected property '" + property + "': " + description);
+ }
+ if (!possibleValues.isEmpty()) {
+ String currentValue = getProject().getProperty(property);
+ if (!possibleValues.contains(currentValue)) {
+ throw new BuildException("current value of property '" + property
+ + "' doesn't match with possible values : " + possibleValues.toString());
+ }
+ }
+ if (defaultValue != null && getProject().getProperty(property) == null) {
+ Property propTask = new Property();
+ propTask.setProject(getProject());
+ propTask.setTaskName(getTaskName());
+ propTask.setName(property);
+ propTask.setValue(defaultValue);
+ propTask.execute();
+ }
+ }
+
@Deprecated
// FIXME : remove this method after 0.9 release
public void setPhase(String phase) {
Modified: ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/ParameterTaskTest.java
URL: http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/ParameterTaskTest.java?rev=1548807&r1=1548806&r2=1548807&view=diff
==============================================================================
--- ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/ParameterTaskTest.java (original)
+++ ant/easyant/core/trunk/src/test/java/org/apache/easyant/tasks/ParameterTaskTest.java Sat Dec 7 08:08:04 2013
@@ -119,6 +119,15 @@ public class ParameterTaskTest {
}
@Test
+ /**
+ * @see EASYANT-58
+ */
+ public void shouldNotFailIfPathIsMissingButNotRequired() {
+ parameterTask.setPath("a-path-id");
+ parameterTask.execute();
+ }
+
+ @Test
public void shouldFailIfGivenPathIdIsNotAPath() {
expectedException.expectMessage("reference 'a-path-id' must be a path");
parameterTask.getProject().addReference("a-path-id", true);