ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs FixCRLF.java
Date Wed, 12 Jul 2000 14:05:12 GMT
bodewig     00/07/12 07:05:12

  Modified:    docs     index.html
               src/main/org/apache/tools/ant IntrospectionHelper.java
               src/main/org/apache/tools/ant/taskdefs FixCRLF.java
  Log:
  Added a helper class for enumerated attributes and demonstrated its
  usage in FixCRLF.
  
  Revision  Changes    Path
  1.46      +4 -0      jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- index.html	2000/07/12 13:30:47	1.45
  +++ index.html	2000/07/12 14:05:10	1.46
  @@ -3171,6 +3171,10 @@
       value of the attribute is interpreted relative to the project's basedir) 
       or any other type that has a constructor with a single <code>String</code>
       argument</li>
  +  <li>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.</li>
     <li>If the task should support character data, write a <code>public void

       addText(String)</code> method.</li>
     <li>For each nested element, write a create or add method. A create method 
  
  
  
  1.4       +17 -0     jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
  
  Index: IntrospectionHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- IntrospectionHelper.java	2000/07/12 11:51:29	1.3
  +++ IntrospectionHelper.java	2000/07/12 14:05:10	1.4
  @@ -438,6 +438,23 @@
   
                   };
   
  +        // 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 {
   
  
  
  
  1.11      +21 -12    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  
  Index: FixCRLF.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- FixCRLF.java	2000/07/11 12:13:10	1.10
  +++ FixCRLF.java	2000/07/12 14:05:12	1.11
  @@ -139,15 +139,15 @@
        * <li>remove: remove all CR characters
        * </ul>
        */
  -    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 @@
        * <li>remove: convert tabs to spaces
        * </ul>
        */
  -    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 @@
        * <li>remove: remove any eof character found at the end
        * </ul>
        */
  -    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;
           }
       }
   
  @@ -369,5 +369,14 @@
               }
   
           } /* 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"};
  +        }
       }
   }
  
  
  

Mime
View raw message