diff --git a/docs/index.html b/docs/index.html
index bc301509b..ae277354f 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -3171,6 +3171,10 @@ output.
value of the attribute is interpreted relative to the project's basedir)
or any other type that has a constructor with a single String
argument
+
If your task has enumerated attributes, you should consider using
+ a subclass of org.apache.tools.ant.EnumeratedAttribute as argument
+ to your setter method. See org.apache.tools.ant.taskdefs.FixCRLF for
+ an example.
If the task should support character data, write a public void
addText(String)
method.
For each nested element, write a create or add method. A create method
diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java
index 8483486dc..ed1227737 100644
--- a/src/main/org/apache/tools/ant/IntrospectionHelper.java
+++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java
@@ -438,6 +438,23 @@ public class IntrospectionHelper {
};
+ // EnumeratedAttributes have their own helper class
+ } else if (org.apache.tools.ant.EnumeratedAttribute.class.isAssignableFrom(arg)) {
+ return new AttributeSetter() {
+ public void set(Project p, Object parent, String value)
+ throws InvocationTargetException, IllegalAccessException, BuildException {
+ try {
+ EnumeratedAttribute ea =
+ (EnumeratedAttribute)arg.newInstance();
+ ea.setValue(value);
+ m.invoke(parent, new EnumeratedAttribute[] {ea});
+ } catch (InstantiationException ie) {
+ throw new BuildException(ie);
+ }
+ }
+ };
+
+
// worst case. look for a public String constructor and use it
} else {
diff --git a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
index 6a87c6040..2f8466756 100644
--- a/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
+++ b/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
@@ -139,15 +139,15 @@ public class FixCRLF extends MatchingTask {
* remove: remove all CR characters
*
*/
- public void setCr(String option) {
+ public void setCr(AddAsisRemove attr) {
+ String option = attr.getValue();
if (option.equals("remove")) {
addcr = -1;
} else if (option.equals("asis")) {
addcr = 0;
- } else if (option.equals("add")) {
- addcr = +1;
} else {
- throw new BuildException("Invalid option: " + option );
+ // must be "add"
+ addcr = +1;
}
}
@@ -161,15 +161,15 @@ public class FixCRLF extends MatchingTask {
* remove: convert tabs to spaces
*
*/
- public void setTab(String option) {
+ public void setTab(AddAsisRemove attr) {
+ String option = attr.getValue();
if (option.equals("remove")) {
addtab = -1;
} else if (option.equals("asis")) {
addtab = 0;
- } else if (option.equals("add")) {
- addtab = +1;
} else {
- throw new BuildException("Invalid option: " + option );
+ // must be "add"
+ addtab = +1;
}
}
@@ -196,15 +196,15 @@ public class FixCRLF extends MatchingTask {
* remove: remove any eof character found at the end
*
*/
- public void setEof(String option) {
+ public void setEof(AddAsisRemove attr) {
+ String option = attr.getValue();
if (option.equals("remove")) {
ctrlz = -1;
} else if (option.equals("asis")) {
ctrlz = 0;
- } else if (option.equals("add")) {
- ctrlz = +1;
} else {
- throw new BuildException("Invalid option: " + option );
+ // must be "add"
+ ctrlz = +1;
}
}
@@ -370,4 +370,13 @@ public class FixCRLF extends MatchingTask {
} /* end for */
}
+
+ /**
+ * Enumerated attribute with the values "asis", "add" and "remove".
+ */
+ public static class AddAsisRemove extends EnumeratedAttribute {
+ public String[] getValues() {
+ return new String[] {"add", "asis", "remove"};
+ }
+ }
}