kaz         02/04/19 22:19:48

  Modified:    .        build.xml
               src/java/org/apache/maven MavenUtils.java
               src/java/org/apache/maven/java SourceTool.java
               src/templates/build build-docs.xml build.xml
  Added:       src/java/org/apache/maven TaskListExecutor.java
               src/java/org/apache/maven/executor
                        FileProcessingExecutor.java
               src/java/org/apache/maven/java TaskListVisitor.java
  Log:
  - Created a FileProcessingExecutor that can be used to process files in
    a project's directory.  This executor is an abstract class that
    provides a template method called "doProcessFile" that subclasses can
    override to do whatever (my motivation is to use SourceTool to parse
    each file and pass it a visitor).  Additionally, there is pre/post
    processing template methods that can be overridden if needed.  I.e. in
    most cases you'll want to use the postProcessing method to do
    something with the results of the processing (again, in my case, I
    query the visitor object for the information it accumulated).
  
  - Created a placeholder TaskListVisitor that will be used to accumulate
    todo/task tags in JavaDoc which will then be used to create the task
    list for a project.  Currenly, TaskListVisitor simply counts the
    number of JavaDoc entries (its a placeholder and I'm getting tired :)
  
  - Created a TaskListExecutor which is a subclass of the new
    FileProcessingExecutor.  By using the FileProcessingExecutor it
    becomes trivial to pass any type of visitor through the entire source
    tree.  TaskListExecutor uses a TaskListVisitor.  bhl: This is how you
    can create a new JXR task using another visitor.
  
  - Modified SourceTool to pass any parser exceptions.  Jason: you had
    modified this to ignore them so you could continue processing, but now
    I believe you can just use the FileProcessingExecutor instead, see the
    'doProcessFile' of my TaskListExecutor, this is the more appropriate
    spot to ignore the exception.
  
  - Modified MavenUtils.getFiles to check if the 'includes' parameter is
    null.  If it is null, then pass that directly to Ant's directory
    scanner setIncludes() method which indicates all files should be
    matched.  Prior to this change, a NPE was thrown.
  
  - Finally, the build files have a new target called maven:task-list
    which will invoke TaskListExecutor which will process all files in the
    {$src} directory and count the number of JavaDocs (until I actually
    write the real TaskListVisitor).  This new target is not automatically
    invoked as part of any other target yet (I'll hold off until it does
    what its supposed to), but in the meantime, you can invoke the target
    for testing purposes.
  
  Revision  Changes    Path
  1.27      +4 -0      jakarta-turbine-maven/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/build.xml,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- build.xml 18 Apr 2002 17:43:34 -0000      1.26
  +++ build.xml 20 Apr 2002 05:19:48 -0000      1.27
  @@ -128,6 +128,10 @@
         <ant antfile="${maven.home}/build-docs.xml" target="cross-ref"/>
       </target>
       
  +    <target name="maven:task-list">
  +      <ant antfile="${maven.home}/build-docs.xml" target="task-list"/>
  +    </target>
  +        
       <target name="maven:cvs-change-log">
         <ant antfile="${maven.home}/build-docs.xml" target="cvs-change-log"/>
       </target>
  
  
  
  1.12      +7 -2      jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java
  
  Index: MavenUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/MavenUtils.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- MavenUtils.java   19 Apr 2002 14:50:09 -0000      1.11
  +++ MavenUtils.java   20 Apr 2002 05:19:48 -0000      1.12
  @@ -74,7 +74,7 @@
    * the project.
    *
    * @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: MavenUtils.java,v 1.11 2002/04/19 14:50:09 jvanzyl Exp $
  + * @version $Id: MavenUtils.java,v 1.12 2002/04/20 05:19:48 kaz Exp $
    */
   public class MavenUtils
   {
  @@ -183,9 +183,14 @@
        */
       public static String[] getFiles(File directory, String includes)
       {
  +        String[] includePatterns = null;
  +        if (includes != null)
  +        {
  +            includePatterns = Strings.split(includes, ",");
  +        }
           DirectoryScanner directoryScanner = new DirectoryScanner();
           directoryScanner.setBasedir(directory);
  -        directoryScanner.setIncludes(Strings.split(includes,","));
  +        directoryScanner.setIncludes(includePatterns);
           directoryScanner.scan();
           String[] files = directoryScanner.getIncludedFiles();
   
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/TaskListExecutor.java
  
  Index: TaskListExecutor.java
  ===================================================================
  package org.apache.maven;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache jakarta-turbine-maven" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache jakarta-turbine-maven", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  import java.io.File;
  import java.io.FileInputStream;
  
  import org.apache.maven.java.SourceTool;
  import org.apache.maven.java.TaskListVisitor;
  import org.apache.maven.executor.FileProcessingExecutor;
  
  /** 
   * An executor that utilizes a visitor to generate a task list from
   * various tags in JavaDoc of a project's source tree.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>Pete Kazmier</a>
   * @version $Id: TaskListExecutor.java,v 1.1 2002/04/20 05:19:48 kaz Exp $
   */
  public class TaskListExecutor extends FileProcessingExecutor
  {
      /** 
       * Source tool reference for parsing files.
       */
      private SourceTool st;
  
      /** 
       * Reference to the visitor.
       */
      private TaskListVisitor visitor;
  
      /** 
       * Initializes the source tool and the appropriate visitor.
       */
      protected void doPreProcessing()
      {
          st = new SourceTool();
          visitor = new TaskListVisitor();
          st.setVisitor(visitor);
      }
  
      /** 
       * Processes a file using source tool which in turn passes the
       * visitor through the AST to perform its operation. 
       * 
       * @param file The file to parse.
       */
      protected void doProcessFile(File file)
      {
          try
          {
              FileInputStream is = new FileInputStream(file);
              st.parse(is);
              is.close();
          }
          catch (Exception e)
          {
              log("Error parsing file: " + file);
          }
      }
  
      /** 
       * Displays the results of the visitor.
       */
      protected void doPostProcessing()
      {
          log(">> The number of JavaDocNodes were: " + visitor.getCount());
      }
  }
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/executor/FileProcessingExecutor.java
  
  Index: FileProcessingExecutor.java
  ===================================================================
  package org.apache.maven.executor;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and 
   *    "Apache jakarta-turbine-maven" must not be used to endorse or promote products 
   *    derived from this software without prior written permission. For 
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache jakarta-turbine-maven", nor may "Apache" appear in their name, without 
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  import java.io.File;
  import java.io.FileNotFoundException;
  
  import org.apache.maven.MavenUtils;
  
  /** 
   * An executor that uses the Template Method pattern to alleviate the
   * burden of subclasses having to create the Maven project object and
   * processing a set of files in the project's directory structure.
   * Subclasses must implement <code>doProcessFile</code>, and optionally
   * <code>doPreProcess</code> and <code>doPostProcess</code>.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>Pete Kazmier</a>
   * @version $Id: FileProcessingExecutor.java,v 1.1 2002/04/20 05:19:48 kaz Exp $
   */
  public abstract class FileProcessingExecutor extends ProjectExecutor
  {
      /** 
       * The base directory or file to process.
       */
      private File base;
  
      /** 
       * A comma-separated list of Ant include patterns.
       */
      private String includes;
  
      /**
       * Set the base in which files are processed.  This may be a
       * directory or a single file.  If its a directory, the set of
       * includes is used to match files to process.
       *
       * @param base The base used when processing files.
       */
      public void setBase(File base)
      {
          this.base = base;
      }        
  
      /**
       * Set the include pattern to use when processing files.  This
       * is a list patterns that are used to select files to process.
       *
       * @param includes A comma-separated list of include patterns.
       */
      public void setIncludes(String includes)
      {
          this.includes = includes;
      }        
  
      /** 
       * Execute logic before processing starts.
       *
       * @throws Exception If an error occurs during pre-procesing.
       */
      private void preProcessing() throws Exception
      {
          //log("Starting pre-processing");
          doPreProcessing();
      }
  
      /** 
       * Execute logic before processing starts.  This is the template
       * method that can be overriden by subclasses to provide their own
       * logic prior to processing.
       * 
       * @exception Exception If an error occurs during pre-processing.
       */
      protected void doPreProcessing() throws Exception
      {
      }
  
      /** 
       * Execute logic after processing finishes.
       *
       * @throws Exception If an error occurs during post-procesing.
       */
      private void postProcessing() throws Exception
      {
          //log("Starting post-processing");
          doPostProcessing();
      }
  
      /** 
       * Execute logic after processing finishes.  This is the template
       * method that can be overriden by subclasses to provide their own
       * logic after processing completes.
       * 
       * @exception Exception If an error occurs during post-processing.
       */
      protected void doPostProcessing() throws Exception
      {
      }
  
      /** 
       * Process the file.  
       * 
       * @param file The file to process.
       * @throws Exception If an error occurs while processing.
       */
      private void processFile(File file) throws Exception
      {
          //log("Processing file: " + file);
          doProcessFile(file);
      }
  
      /** 
       * Process the file.  This is the template method that must be
       * overriden by subclasses to provide their own processing logic.
       * 
       * @param file The file to process.
       * @exception Exception If there is an error processing files.
       */
      protected abstract void doProcessFile(File file) throws Exception;
  
      /** 
       * Process the directory.
       * 
       * @exception Exception If there is an error processing files.
       */
      private void processDirectory() throws Exception
      {
          String[] files = 
              MavenUtils.getFiles(base.getAbsolutePath(), includes);
  
          for (int i = 0; i < files.length; i++)
          {
              processFile(new File(files[i]));
          }
      }
  
      /** 
       * Initiaites the processing of files.
       *
       * @throws FileNotFoundException If <base> does not exist.
       * @throws Exception If there is an error processing files.
       */
      public void doExecute() throws FileNotFoundException, Exception
      {
          if (base == null)
          {
              throw new NullPointerException("base must be set");
          }
  
          if (!base.exists())
          {
              throw new FileNotFoundException("Cannont find base " + 
                  base.getAbsolutePath());
          }
  
          preProcessing();
  
          if (base.isDirectory())
          {
              processDirectory();
          }
          else
          {
              processFile(base);
          }
  
          postProcessing();
      }
  }
  
  
  
  1.4       +3 -10     
jakarta-turbine-maven/src/java/org/apache/maven/java/SourceTool.java
  
  Index: SourceTool.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/java/SourceTool.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SourceTool.java   16 Apr 2002 18:14:50 -0000      1.3
  +++ SourceTool.java   20 Apr 2002 05:19:48 -0000      1.4
  @@ -67,7 +67,7 @@
    * specifying a visitor that has a particuluar behaviour
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
  - * @version $Id: SourceTool.java,v 1.3 2002/04/16 18:14:50 jvanzyl Exp $
  + * @version $Id: SourceTool.java,v 1.4 2002/04/20 05:19:48 kaz Exp $
    */
   public class SourceTool
   {
  @@ -110,15 +110,8 @@
       public void parse(InputStream is)
           throws Exception
       {
  -        try
  -        {
  -            source = parser.parse(is);
  -            source.jjtAccept(visitor,null);
  -        }
  -        catch (Exception e)
  -        {
  -            // We have a parse exception. Just move on.
  -        }
  +        source = parser.parse(is);
  +        source.jjtAccept(visitor,null);
       }
   
       /**
  
  
  
  1.1                  
jakarta-turbine-maven/src/java/org/apache/maven/java/TaskListVisitor.java
  
  Index: TaskListVisitor.java
  ===================================================================
  package org.apache.maven.java;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Maven" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Maven", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.maven.java.parser.Node;
  import org.apache.maven.java.parser.Token;
  import org.apache.maven.java.parser.ASTJavaDocEntry;
  
  /** 
   * A visitor that accumulates a list of tasks indicated by the todo and
   * task JavaDoc tags.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>Pete Kazmier</a>
   * @version $Id: TaskListVisitor.java,v 1.1 2002/04/20 05:19:48 kaz Exp $
   */
  public class TaskListVisitor extends BaseVisitor
  {
      /** 
       * A count of the number of ASTJavaDocEntry nodes.
       */
      private int count = 0;
      
      public Object visit(ASTJavaDocEntry node, Object data)
      {
          count++;
          data = node.childrenAccept(this, data);
          return data; 
      }
  
      /** 
       * Gets the number of JavaDocEntry nodes that were parsed.
       * 
       * @return The number of nodes parsed.
       */
      public int getCount()
      {
          return count;
      }
  }
  
  
  
  1.54      +22 -0     jakarta-turbine-maven/src/templates/build/build-docs.xml
  
  Index: build-docs.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/templates/build/build-docs.xml,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- build-docs.xml    18 Apr 2002 17:54:50 -0000      1.53
  +++ build-docs.xml    20 Apr 2002 05:19:48 -0000      1.54
  @@ -80,6 +80,28 @@
     </target>
   
     <!-- ================================================================== -->
  +  <!-- T A S K   C R E A T I O N                                          -->
  +  <!-- ================================================================== -->
  +
  +  <target
  +    name="task-list"
  +    depends="local-init">
  +
  +    <taskdef
  +      name="task-parser"
  +      classname="org.apache.maven.TaskListExecutor">
  +      <classpath refid="maven-classpath"/>
  +    </taskdef>
  +
  +    <task-parser
  +      projectDescriptor="project.xml"
  +      base="${src.dir}"
  +      includes="**/*.java"
  +    />
  +
  +  </target>
  +
  +  <!-- ================================================================== -->
     <!-- C V S  C H A N G E  L O G  R E P O R T                             -->
     <!-- ================================================================== -->
   
  
  
  
  1.29      +4 -0      jakarta-turbine-maven/src/templates/build/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-maven/src/templates/build/build.xml,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- build.xml 18 Apr 2002 17:43:34 -0000      1.28
  +++ build.xml 20 Apr 2002 05:19:48 -0000      1.29
  @@ -90,6 +90,10 @@
         <ant antfile="$mavenDirectory/build-docs.xml" target="cvs-change-log"/>
       </target>
           
  +    <target name="maven:task-list">
  +      <ant antfile="$mavenDirectory/build-docs.xml" target="task-list"/>
  +    </target>
  +        
       <target name="maven:javadocs">
         <ant antfile="$mavenDirectory/build-docs.xml" target="javadocs"/>
       </target>
  
  
  


Reply via email to