git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@481322 13f79535-47bb-0310-9956-ffa450edef68master
@@ -51,6 +51,9 @@ Other changes: | |||||
* Do not uppercase the drive letters systematically in FileUtils#normalize. | * Do not uppercase the drive letters systematically in FileUtils#normalize. | ||||
* Java 5 enumerations may now be used as values in XML attributes in place of | |||||
EnumeratedAttribute. Bugzilla 41058. | |||||
Changes from Ant 1.7.0Beta3 to Ant 1.7.0RC1 | Changes from Ant 1.7.0Beta3 to Ant 1.7.0RC1 | ||||
=========================================== | =========================================== | ||||
@@ -1008,6 +1008,25 @@ public final class IntrospectionHelper { | |||||
} | } | ||||
} | } | ||||
}; | }; | ||||
} else if (reflectedArg.getSuperclass() != null && reflectedArg.getSuperclass().getName().equals("java.lang.Enum")) { | |||||
return new AttributeSetter(m) { | |||||
public void set(Project p, Object parent, String value) | |||||
throws InvocationTargetException, IllegalAccessException, BuildException { | |||||
try { | |||||
m.invoke(parent, new Object[] { | |||||
reflectedArg.getMethod("valueOf", new Class[] {String.class}). | |||||
invoke(null, new Object[] {value})}); | |||||
} catch (InvocationTargetException x) { | |||||
if (x.getTargetException() instanceof IllegalArgumentException) { | |||||
throw new BuildException("'" + value + "' is not a permitted value for " + reflectedArg.getName()); | |||||
} else { | |||||
throw new BuildException(x.getTargetException()); | |||||
} | |||||
} catch (Exception x) { | |||||
throw new BuildException(x); | |||||
} | |||||
} | |||||
}; | |||||
// worst case. look for a public String constructor and use it | // worst case. look for a public String constructor and use it | ||||
// also supports new Whatever(Project, String) as for Path or Reference | // also supports new Whatever(Project, String) as for Path or Reference | ||||
// This is used (deliberately) for all primitives/wrappers other than | // This is used (deliberately) for all primitives/wrappers other than | ||||
@@ -370,6 +370,24 @@ public class AntStructure extends Task { | |||||
} catch (IllegalAccessException ie) { | } catch (IllegalAccessException ie) { | ||||
sb.append("CDATA "); | sb.append("CDATA "); | ||||
} | } | ||||
} else if (type.getSuperclass() != null && type.getSuperclass().getName().equals("java.lang.Enum")) { | |||||
try { | |||||
Object[] values = (Object[]) type.getMethod("values", null).invoke(null, null); | |||||
if (values.length == 0) { | |||||
sb.append("CDATA "); | |||||
} else { | |||||
sb.append('('); | |||||
for (int i = 0; i < values.length; i++) { | |||||
if (i != 0) { | |||||
sb.append(" | "); | |||||
} | |||||
sb.append(type.getMethod("name", null).invoke(values[i], null)); | |||||
} | |||||
sb.append(") "); | |||||
} | |||||
} catch (Exception x) { | |||||
sb.append("CDATA "); | |||||
} | |||||
} else { | } else { | ||||
sb.append("CDATA "); | sb.append("CDATA "); | ||||
} | } | ||||