ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlboud...@apache.org
Subject svn commit: r1497229 - /ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ParameterTask.java
Date Thu, 27 Jun 2013 07:32:00 GMT
Author: jlboudart
Date: Thu Jun 27 07:32:00 2013
New Revision: 1497229

URL: http://svn.apache.org/r1497229
Log:
Add possibleValues attribute on ParameterTask

Modified:
    ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/ParameterTask.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=1497229&r1=1497228&r2=1497229&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 Thu Jun
27 07:32:00 2013
@@ -17,6 +17,9 @@
  */
 package org.apache.easyant.tasks;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.easyant.core.EasyAntMagicNames;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -41,6 +44,7 @@ public class ParameterTask extends Task 
     private String defaultValue;
     private boolean required;
     private String phase;
+    private List<String> possibleValues = new ArrayList<String>();
 
     /**
      * Get a description to the property / path
@@ -156,11 +160,42 @@ public class ParameterTask extends Task 
         this.required = required;
     }
 
+    /**
+     * Get list of possible values of a property
+     * 
+     * @return a list of values
+     */
+    public List<String> getPossibleValues() {
+        return possibleValues;
+    }
+
+    /**
+     * Set list of possible values of a property
+     * 
+     * @param possibleValuesAsString
+     *            a comma separated list of values
+     */
+    public void setPossibleValues(String possibleValuesAsString) {
+        if (possibleValuesAsString != null) {
+            String[] split = possibleValuesAsString.split(",");
+            for (String possibleValue : split) {
+                possibleValues.add(possibleValue.trim());
+            }
+        }
+    }
+
     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());



Mime
View raw message