ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgl...@apache.org
Subject svn commit: r481322 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/IntrospectionHelper.java src/main/org/apache/tools/ant/taskdefs/AntStructure.java
Date Fri, 01 Dec 2006 17:50:49 GMT
Author: jglick
Date: Fri Dec  1 09:50:46 2006
New Revision: 481322

URL: http://svn.apache.org/viewvc?view=rev&rev=481322
Log:
#41058: permit Java 5 enumerations to work like EnumeratedAttribute.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=481322&r1=481321&r2=481322
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Dec  1 09:50:46 2006
@@ -51,6 +51,9 @@
 
 * 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
 ===========================================
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java?view=diff&rev=481322&r1=481321&r2=481322
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java Fri Dec  1 09:50:46
2006
@@ -1008,6 +1008,25 @@
                     }
                 }
             };
+        } 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
         // also supports new Whatever(Project, String) as for Path or Reference
         // This is used (deliberately) for all primitives/wrappers other than

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java?view=diff&rev=481322&r1=481321&r2=481322
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/AntStructure.java Fri Dec  1 09:50:46
2006
@@ -370,6 +370,24 @@
                     } catch (IllegalAccessException ie) {
                         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 {
                     sb.append("CDATA ");
                 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message