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 AntStructure.java
Date Tue, 05 Sep 2000 08:53:36 GMT
bodewig     00/09/05 01:53:34

  Modified:    .        WHATSNEW build.xml
               docs     index.html
               src/main/org/apache/tools/ant ProjectHelper.java
               src/main/org/apache/tools/ant/taskdefs AntStructure.java
  Log:
  Added support for data types to be defined at the project level. The
  currently implemented data types are <path>, <fileset> and
  <patternset>.
  
  Revision  Changes    Path
  1.24      +2 -0      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- WHATSNEW	2000/09/04 14:06:31	1.23
  +++ WHATSNEW	2000/09/05 08:53:24	1.24
  @@ -46,6 +46,8 @@
   all files if the stylesheet changes.
   
   * New data types fileset and patternset - expected to get a broader use.
  +They as well as PATH like structures can now be defined on a global
  +level and later be referenced by their id attribute.
   
   * You can specify environment variables to <exec>.
   
  
  
  
  1.65      +10 -4     jakarta-ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/build.xml,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- build.xml	2000/09/04 12:20:09	1.64
  +++ build.xml	2000/09/05 08:53:26	1.65
  @@ -35,6 +35,15 @@
     <property name="build.compiler.emacs" value="on"/>
   
     <!-- =================================================================== -->
  +  <!-- Define a global set of patterns that can be referenced by           -->
  +  <!-- its id attribute                                                    -->
  +  <!-- =================================================================== -->
  +  <patternset id="chmod.patterns">
  +    <include name="**/ant" />
  +    <include name="**/antRun" />
  +  </patternset>
  +
  +  <!-- =================================================================== -->
     <!-- Check to see what optional dependencies are available               -->
     <!-- =================================================================== -->
     <target name="check_for_optional_packages">
  @@ -125,10 +134,7 @@
        <copydir src="${src.bin.dir}" dest="${bin.dir}"/>
        <chmod perm="+x">
          <fileset dir="${bin.dir}">
  -         <patternset id="chmod.patterns">
  -           <include name="**/ant" />
  -           <include name="**/antRun" />
  -         </patternset>
  +         <patternsetref refid="chmod.patterns"/>
          </fileset>
        </chmod>
        <fixcrlf srcdir="${bin.dir}" includes="ant,antRun" cr="remove"/>
  
  
  
  1.89      +49 -26    jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.88
  retrieving revision 1.89
  diff -u -r1.88 -r1.89
  --- index.html	2000/09/05 08:29:49	1.88
  +++ index.html	2000/09/05 08:53:29	1.89
  @@ -460,6 +460,11 @@
   <p>Builds a PATH which holds the value of <code>${classpath}</code>
   followed by all JAR files in the <code>lib</code> directory, followed
   by the <code>classes</code> directory.</p>
  +<p>If you want to use the same PATH like structure for several tasks,
  +you can define them with a <code>&lt;path&gt;</code> element at the
  +same level as <em>target</em>s and reference them via their
  +<em>id</em> attribute - see <a href="#references">References</a>
for an
  +example.</p>
   <h3><a name="arg">Command line arguments</a></h3>
   
   <p>Several tasks take arguments that shall be passed to another
  @@ -518,33 +523,49 @@
   example.</p>
   <p>The following example</p>
   <blockquote><pre>
  -&lt;rmic ...&gt;
  -  &lt;classpath&gt;
  -    &lt;pathelement location=&quot;lib/&quot; /&gt;
  -    &lt;pathelement path=&quot;${java.class.path}/&quot; /&gt;
  -    &lt;pathelement path=&quot;${additional.path}&quot; /&gt;
  -  &lt;/classpath&gt;
  -&lt;/rmic&gt;
  -&lt;javac ...&gt;
  -  &lt;classpath&gt;
  -    &lt;pathelement location=&quot;lib/&quot; /&gt;
  -    &lt;pathelement path=&quot;${java.class.path}/&quot; /&gt;
  -    &lt;pathelement path=&quot;${additional.path}&quot; /&gt;
  -  &lt;/classpath&gt;
  -&lt;/javac&gt;
  +&lt;project ... &gt;
  +  &lt;target ... &gt;
  +    &lt;rmic ...&gt;
  +      &lt;classpath&gt;
  +        &lt;pathelement location=&quot;lib/&quot; /&gt;
  +        &lt;pathelement path=&quot;${java.class.path}/&quot; /&gt;
  +        &lt;pathelement path=&quot;${additional.path}&quot; /&gt;
  +      &lt;/classpath&gt;
  +    &lt;/rmic&gt;
  +  &lt;/target&gt;
  +
  +  &lt;target ... &gt;
  +    &lt;javac ...&gt;
  +      &lt;classpath&gt;
  +        &lt;pathelement location=&quot;lib/&quot; /&gt;
  +        &lt;pathelement path=&quot;${java.class.path}/&quot; /&gt;
  +        &lt;pathelement path=&quot;${additional.path}&quot; /&gt;
  +      &lt;/classpath&gt;
  +    &lt;/javac&gt;
  +  &lt;/target&gt;
  +&lt;/project&gt;
   </pre></blockquote>
   <p>could be rewritten as</p>
   <blockquote><pre>
  -&lt;rmic ...&gt;
  -  &lt;classpath id=&quot;project.class.path&quot;&gt;
  +&lt;project ... &gt;
  +  &lt;path id=&quot;project.class.path&quot;&gt;
       &lt;pathelement location=&quot;lib/&quot; /&gt;
       &lt;pathelement path=&quot;${java.class.path}/&quot; /&gt;
       &lt;pathelement path=&quot;${additional.path}&quot; /&gt;
  -  &lt;/classpath&gt;
  -&lt;/rmic&gt;
  -&lt;javac ...&gt;
  -  &lt;classpathref refid=&quot;project.class.path&quot; /&gt;
  -&lt;/javac&gt;
  +  &lt;/path&gt;
  +
  +  &lt;target ... &gt;
  +    &lt;rmic ...&gt;
  +      &lt;classpathref refid=&quot;project.class.path&quot; /&gt;
  +    &lt;/rmic&gt;
  +  &lt;/target&gt;
  +
  +  &lt;target ... &gt;
  +    &lt;javac ...&gt;
  +      &lt;classpathref refid=&quot;project.class.path&quot; /&gt;
  +    &lt;/javac&gt;
  +  &lt;/target&gt;
  +&lt;/project&gt;
   </pre></blockquote>
   <p>All tasks that use nested elements for <a
   href="#patternset">PatternSet</a>s, <a href="#fileset">FileSet</a>s
or
  @@ -666,9 +687,10 @@
   <h3><a name="patternset">PatternSets</a></h3>
   <p>Patterns can be grouped to sets and later be referenced by their id
   attribute. They are defined via a <code>patternset</code> element -
  -which can currently only appear nested into a <a
  -href="#fileset">FileSet</a> or a directory based task that constitutes
  -an implicit FileSet.</p>
  +which can appear nested into a <a href="#fileset">FileSet</a> or a
  +directory based task that constitutes an implicit FileSet. In addition
  +<code>patternset</code>s can be defined at the same level as
  +<code>target</code> - i.e. as children of <code>project</code></p>
   <p>Patterns can be specified by nested <code>&lt;include&gt;</code>
or
   <code>&lt;exclude&gt;</code> elements or the following attributes.</p>
   <table border="1" cellpadding="2" cellspacing="0">
  @@ -713,8 +735,9 @@
   <p>FileSets are groups of files. These files can be found in a
   directory tree starting in a base directory and are matched by
   patterns taken from a number of <a
  -href="#patternset">PatternSets</a>. Currently FileSets can only appear
  -inside task that support this feature.</p>
  +href="#patternset">PatternSets</a>. FileSets can appear inside task
  +that support this feature or at the same level as <code>target</code>
  +- i.e. as children of <code>project</code>.</p>
   <p>PatternSets can be specified as nested
   <code>&lt;patternset&gt;</code> or <code>&lt;patternsetref&gt;</code>
   elements. In addition FileSet holds an implicit PatternSet and
  
  
  
  1.26      +48 -2     jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
  
  Index: ProjectHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ProjectHelper.java	2000/09/04 13:19:53	1.25
  +++ ProjectHelper.java	2000/09/05 08:53:31	1.26
  @@ -250,6 +250,8 @@
                   handleProperty(name, attrs);
               } else if (name.equals("target")) {
                   handleTarget(name, attrs);
  +            } else if (project.getDataTypeDefinitions().get(name) != null) {
  +                handleDataType(name, attrs);
               } else {
                   throw new SAXParseException("Unexpected element \"" + name + "\"", locator);
               }
  @@ -266,6 +268,10 @@
           private void handleTarget(String tag, AttributeList attrs) throws SAXParseException
{
               new TargetHandler(this).init(tag, attrs);
           }
  +
  +        private void handleDataType(String name, AttributeList attrs) throws SAXParseException
{
  +            new DataTypeHandler(this).init(name, attrs);
  +        }
       }
   
       /**
  @@ -388,8 +394,6 @@
        * Handler for all nested properties.
        */
       private class NestedElementHandler extends AbstractHandler {
  -        private DocumentHandler parentHandler;
  -
           private Object target;
           private Object child;
   
  @@ -428,6 +432,48 @@
   
           public void startElement(String name, AttributeList attrs) throws SAXParseException
{
               new NestedElementHandler(this, child).init(name, attrs);
  +        }
  +    }
  +
  +    /**
  +     * Handler for all data types at global level.
  +     */
  +    private class DataTypeHandler extends AbstractHandler {
  +        private Object element;
  +
  +        public DataTypeHandler(DocumentHandler parentHandler) {
  +            super(parentHandler);
  +        }
  +
  +        public void init(String propType, AttributeList attrs) throws SAXParseException
{
  +            try {
  +                element = project.createDataType(propType);
  +                if (element == null) {
  +                    throw new BuildException("Unknown data type "+propType);
  +                }
  +                
  +                configure(element, attrs);
  +            } catch (BuildException exc) {
  +                throw new SAXParseException(exc.getMessage(), locator, exc);
  +            }
  +        }
  +
  +        public void characters(char[] buf, int start, int end) throws SAXParseException
{
  +            String text = new String(buf, start, end).trim();
  +            if (text.length() == 0) return;
  +
  +            IntrospectionHelper ih = 
  +                IntrospectionHelper.getHelper(element.getClass());
  +
  +            try {
  +                ih.addText(element, text);
  +            } catch (BuildException exc) {
  +                throw new SAXParseException(exc.getMessage(), locator, exc);
  +            }
  +        }
  +
  +        public void startElement(String name, AttributeList attrs) throws SAXParseException
{
  +            new NestedElementHandler(this, element).init(name, attrs);
           }
       }
   
  
  
  
  1.6       +17 -3     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
  
  Index: AntStructure.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/AntStructure.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AntStructure.java	2000/07/25 06:52:44	1.5
  +++ AntStructure.java	2000/09/05 08:53:33	1.6
  @@ -106,7 +106,8 @@
                   out = new PrintWriter(new FileWriter(output));
               }
               
  -            printHead(out);
  +            Enumeration dataTypes = project.getDataTypeDefinitions().keys();
  +            printHead(out, dataTypes);
   
               Vector tasks = new Vector();
               Enumeration enum = project.getTaskDefinitions().keys();
  @@ -116,6 +117,13 @@
               }
               printTargetDecl(out, tasks);
   
  +            dataTypes = project.getDataTypeDefinitions().keys();
  +            while (dataTypes.hasMoreElements()) {
  +                String typeName = (String) dataTypes.nextElement();
  +                printElementDecl(out, typeName, 
  +                                 (Class) project.getDataTypeDefinitions().get(typeName));
  +            }
  +            
               for (int i=0; i<tasks.size(); i++) {
                   String taskName = (String) tasks.elementAt(i);
                   printElementDecl(out, taskName, 
  @@ -134,12 +142,18 @@
           }
       }
   
  -    private void printHead(PrintWriter out) {
  +    private void printHead(PrintWriter out, Enumeration enum) {
           out.println("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
           out.println("<!ENTITY % boolean \"(true|false|on|off|yes|no)\">");
           out.println("");
           
  -        out.println("<!ELEMENT project (target | property | taskdef)*>");
  +        out.print("<!ELEMENT project (target | property | taskdef");
  +        while (enum.hasMoreElements()) {
  +            String typeName = (String) enum.nextElement();
  +            out.print(" | "+typeName);
  +        }
  +
  +        out.println(")*>");
           out.println("<!ATTLIST project");
           out.println("          name    CDATA #REQUIRED");
           out.println("          default CDATA #REQUIRED");
  
  
  

Mime
View raw message