EASYANT-58 required attribute of path parameter is ignored (thanks to Jérôme Leroux)

git-svn-id: https://svn.apache.org/repos/asf/ant/easyant/core/trunk@1548807 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/easyant/tasks/ParameterTask.java b/src/main/java/org/apache/easyant/tasks/ParameterTask.java
index b844855..713ff05 100644
--- a/src/main/java/org/apache/easyant/tasks/ParameterTask.java
+++ b/src/main/java/org/apache/easyant/tasks/ParameterTask.java
@@ -186,31 +186,9 @@
 
     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 @@
         }
     }
 
+    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) {
diff --git a/src/test/java/org/apache/easyant/tasks/ParameterTaskTest.java b/src/test/java/org/apache/easyant/tasks/ParameterTaskTest.java
index 9a2c7d5..cb67776 100644
--- a/src/test/java/org/apache/easyant/tasks/ParameterTaskTest.java
+++ b/src/test/java/org/apache/easyant/tasks/ParameterTaskTest.java
@@ -119,6 +119,15 @@
     }
 
     @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);