jvanzyl     2002/07/14 15:18:16

  Added:       src/plugins-build/tasklist/src/java/org/apache/maven/tasklist
                        Task.java TaskList.java TaskListEntry.java
                        TaskListExecutor.java TaskListVisitor.java
  Log:
  o tasklist code moved to plugin.
  
  Revision  Changes    Path
  1.1                  
jakarta-turbine-maven/src/plugins-build/tasklist/src/java/org/apache/maven/tasklist/Task.java
  
  Index: Task.java
  ===================================================================
  package org.apache.maven.tasklist;
  
  /* ====================================================================
   * 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 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/>.
   *
   * ====================================================================
   */
  
  /** 
   * This class represents a task identified by the 'task' JavaDoc tag in
   * a source file.  A task has only a description current associated with
   * it, in the future it may contain other properties such as a priority,
   * and/or owner.
   * 
   * @author <a href="mailto:[EMAIL PROTECTED]";>Pete Kazmier</a>
   * @version $Id: Task.java,v 1.1 2002/07/14 22:18:16 jvanzyl Exp $
   * @task Currently, task only contains a description, but there is no
   * reason we can't expand this to include an owner and/or priority.
   */
  class Task
  {
      /** The task description. */
      private String description;
  
      /** 
       * Default constructor.
       */
      public Task()
      {
      }
  
      /** 
       * Gets the task description.
       * 
       * @return The task description.
       */
      public String getDescription()
      {
          return description;
      }
  
      /** 
       * Sets the task description.
       * 
       * @param description The task description.
       */
      public void setDescription(String description)
      {
          this.description = description;
      }
  
      /** 
       * Creates a String representation of the Task.
       * 
       * @return The String representation of the Task.
       */
      public String toString()
      {
          return description;
      }
  
      /** 
       * Creates an XML String representation of the Task.  The Task is
       * composed of a top-level <tt>&lt;task&gt;</tt> element with a single
       * child element called <tt>&lt;description&gt;</tt>.  The description
       * is enclosed in a <tt>CDATA</tt> block.
       * 
       * @return The XML String representation of the Task.
       */
      public String toXML()
      {
          StringBuffer sb = new StringBuffer();
  
          sb.append("<task>\n");
          sb.append("  <description><![CDATA[");
          sb.append(description);
          sb.append("]]></description>\n");
          sb.append("</task>\n");
  
          return sb.toString();
      }
  }
  
  
  
  
  1.1                  
jakarta-turbine-maven/src/plugins-build/tasklist/src/java/org/apache/maven/tasklist/TaskList.java
  
  Index: TaskList.java
  ===================================================================
  package org.apache.maven.tasklist;
  
  /* ====================================================================
   * 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 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 java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  /**
   * This class represents a list of {@link TaskListEntry} objects.  The
   * task list is used to represent the tasks that have been parsed from
   * JavaDoc task tags in a source tree.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Pete Kazmier</a>
   * @version $Id: TaskList.java,v 1.1 2002/07/14 22:18:16 jvanzyl Exp $
   */
  class TaskList
  {
      /**
       * Output encoding.
       */
      private String outputEncoding = "ISO-8859-1";
  
      /** The list of TaskListEntries accumulated. */
      private List taskListEntries = new ArrayList();
  
      /**
       * Default constructor.
       */
      public TaskList()
      {
      }
  
      /**
       * Gets the list of entries representing the entire task list.  Each
       * entry represents all of the tasks from a given file.
       *
       * @return A List of TaskListEntries.
       */
      public List getTaskListEntries()
      {
          return taskListEntries;
      }
  
      /**
       * Set Output encoding.
       * @param outputEncoding the Charset Encoding that the object is using
       */
      public void setOutputEncoding(String outputEncoding)
      {
          this.outputEncoding = outputEncoding;
      }
  
      /**
       * Get Output encoding.
       * @return the Charset Encoding that the object is using
       */
      public String getOutputEncoding()
      {
          return outputEncoding;
      }
  
      /**
       * Add a TaskListEntry to the list of entries.
       *
       * @param taskListEntry The TaskListEntry to be added.
       */
      public void addTaskListEntry(TaskListEntry taskListEntry)
      {
          taskListEntries.add(taskListEntry);
      }
  
      /**
       * Creates a String representation of the TaskList.
       *
       * @return The String representation of the TaskList.
       */
      public String toString()
      {
          return taskListEntries.toString();
      }
  
      /**
       * Creates an XML String representation of the TaskList.  The TaskList
       * XML representation is a valid <tt>xdoc</tt>.  The first section of
       * the xdoc contains a top-level <tt>&lt;taskList&gt;</tt> element.
       * Each {@link TaskListEntry} then renders itself (please see JavaDoc
       * for details).
       *
       * @return The XML String representation of the TaskList.
       */
      public String toXML()
      {
          StringBuffer sb = new StringBuffer();
  
          sb.append("<?xml version=\"1.0\" encoding=\"");
          sb.append(outputEncoding);
          sb.append("\" ?>\n");
          sb.append("<document>\n");
          sb.append("<properties>\n");
          sb.append("  <title>Task List</title>\n");
          sb.append("</properties>\n");
          sb.append("<body>\n");
          sb.append("  <section name=\"Task List\">\n");
          sb.append("    <taskList>\n");
  
          // Let each entry create its own XML representation.
          for (Iterator i = taskListEntries.iterator(); i.hasNext();)
          {
              TaskListEntry taskListEntry = (TaskListEntry) i.next();
              sb.append(taskListEntry.toXML());
          }
  
          sb.append("    </taskList>\n");
          sb.append("  </section>\n");
          sb.append("</body>\n");
          sb.append("</document>\n");
  
          return sb.toString();
      }
  }
  
  
  1.1                  
jakarta-turbine-maven/src/plugins-build/tasklist/src/java/org/apache/maven/tasklist/TaskListEntry.java
  
  Index: TaskListEntry.java
  ===================================================================
  package org.apache.maven.tasklist;
  
  /* ====================================================================
   * 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 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 java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  /**
   * This class represents a filename and the {@link Task} objects
   * associated with it.  A series of TaskListEntries can then be
   * added to a {@link TaskList} to create a full task list for a
   * project.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Pete Kazmier</a>
   * @version $Id: TaskListEntry.java,v 1.1 2002/07/14 22:18:16 jvanzyl Exp $
   *
   */
  class TaskListEntry
  {
      /** The filename that these Tasks belong to. */
      private String filename;
  
      /** The tasks that are part of the filename. */
      private List tasks = new ArrayList();
  
      /**
       * Default constructor.
       */
      public TaskListEntry()
      {
      }
  
      /**
       * Gets the filename associated with this entry.
       *
       * @return The filename.
       */
      public String getFilename()
      {
          return filename;
      }
  
      /**
       * Sets the filename associated with this entry.
       *
       * @param filename The filename.
       */
      public void setFilename(String filename)
      {
          this.filename = filename;
      }
  
      /**
       * Gets the list of tasks associated with this entry.
       *
       * @return The list of tasks.
       */
      public List getTasks()
      {
          return tasks;
      }
  
      /**
       * Add a task to the current list of tasks.
       *
       * @param task The task to associate with this entry.
       */
      public void addTask(Task task)
      {
          tasks.add(task);
      }
  
      /**
       * Creates a String representation of the TaskListEntry.
       *
       * @return The String representation of the TaskListEntry.
       */
      public String toString()
      {
          return filename + ": " + tasks + "\n";
      }
  
      /**
       * Creates an XML String representation of the TaskListEntry.  The
       * entry is composed of a top-level <tt>&lt;taskEntry&gt;</tt>
       * element.  Within that element is the <tt>&lt;filename&gt;</tt>
       * element and a <tt>&lt;tasks&gt;</tt> element.  The
       * <tt>&lt;tasks&gt;</tt> element then contains the list of Tasks.
       *
       * @return The XML String representation of the Task.
       */
      public String toXML()
      {
          StringBuffer sb = new StringBuffer();
  
          sb.append("<taskEntry>\n");
          sb.append("  <filename>");
          sb.append(filename);
          sb.append("</filename>\n");
          sb.append("  <tasks>\n");
  
          for (Iterator i = tasks.iterator(); i.hasNext();)
          {
              Task task = (Task) i.next();
              sb.append(task.toXML());
          }
  
          sb.append("  </tasks>\n");
          sb.append("</taskEntry>\n");
  
          return sb.toString();
      }
  }
  
  
  
  
  1.1                  
jakarta-turbine-maven/src/plugins-build/tasklist/src/java/org/apache/maven/tasklist/TaskListExecutor.java
  
  Index: TaskListExecutor.java
  ===================================================================
  package org.apache.maven.tasklist;
  
  /* ====================================================================
   * 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 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 java.io.File;
  import java.io.FileInputStream;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.OutputStreamWriter;
  import java.io.PrintWriter;
  import java.util.Iterator;
  
  import org.apache.maven.executor.FileProcessingExecutor;
  import org.apache.maven.java.SourceTool;
  import org.apache.tools.ant.Project;
  
  /**
   * An executor that utilizes a visitor to generate a task list from
   * the various task tags in JavaDoc of a project's source tree.  The
   * task list is generated as an XML file.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Pete Kazmier</a>
   * @version $Id: TaskListExecutor.java,v 1.1 2002/07/14 22:18:16 jvanzyl Exp $
   */
  public class TaskListExecutor extends FileProcessingExecutor
  {
      /** The output file for the XML TaskList report. */
      private File outputFile;
  
      /** The JavaDoc tag that represents a task, defaults to "task". */
      private String taskTag = "task";
  
      /** Source tool reference for parsing files. */
      private SourceTool sourceTool;
  
      /** Reference to the visitor. */
      private TaskListVisitor visitor;
  
      /** A list of Tasks accumulated by the TaskListVisitor keyed on filename. */
      private TaskList taskList = new TaskList();
  
      /**
       * Sets the output file used when generating the task list report.
       *
       * @param outputFile The output file.
       */
      public void setOutputFile(File outputFile)
      {
          this.outputFile = outputFile;
      }
  
      /**
       * Sets the tag named used to represent a task in JavaDoc.  This
       * defaults to "task"; however, we'll leave this as an undocumented
       * feature in the event someone wants to change (like Vincent).
       *
       * @param taskTag The tag name used to represent a task.
       */
      public void setTaskTag(String taskTag)
      {
          this.taskTag = taskTag;
      }
  
      /**
       * Set Output encoding.
       * @param outputEncoding the Charset Encoding that the object is executing in
       */
      public void setOutputEncoding(String outputEncoding)
      {
          taskList.setOutputEncoding(outputEncoding);
      }        
  
      /**
       * Initializes the source tool and the appropriate visitor.  This
       * method is invoked once (not once per file) before any processing
       * begins.  The source tool is used to parse each file of the source
       * tree while passing a TaskListVisitor to accumulate tasks found.
       */
      protected void doPreProcessing()
      {
          sourceTool = new SourceTool();
          visitor = new TaskListVisitor();
          visitor.setTaskTag(taskTag);
          sourceTool.setVisitor(visitor);
      }
  
      /**
       * Processes a file using the source tool which in turn passes the
       * TaskListVisitor through the AST of each file to accumulate a
       * {@link TaskList} of {@link TaskListEntry} objects.  This TaskList
       * is then processed in doPostProcessing.
       *
       * @param file The file to parse.
       */
      protected void doProcessFile(File file)
      {
          try
          {
              /*
               * Open each file and pass it to the source tool for parsing.
               */
              FileInputStream fis = new FileInputStream(file);
              sourceTool.parse(fis);
              fis.close();
  
              /*
               * Process any Tasks that were found in the file.  These Tasks
               * are accumulated by the TaskListVisitor and are available via
               * its getTasks() method.  We create a TaskListEntry object
               * which associates a filename with the Tasks found in that file.
               */
              processResults(relativeFilename(file));
          }
          catch (Exception e)
          {
              log("Non-fatal error while parsing file: " + file);
              log(e.toString(), Project.MSG_DEBUG);
          }
      }
  
      /**
       * Prints the results of the executor to a file as XML if a task
       * list contains entries.  This method is invoked once (not once per
       * file) after processing is completed.
       */
      protected void doPostProcessing()
      {
          /*
           * No need to generate a task list if there aren't any entries
           * in the list!
           */
          if (taskList.getTaskListEntries().size() == 0)
          {
              return;
          }
  
          try
          {
              PrintWriter out = new PrintWriter(new OutputStreamWriter(
                      new FileOutputStream(outputFile), taskList.getOutputEncoding()));
  
              /*
               * Let the task list render itself.
               */
              out.println(taskList.toXML());
              out.close();
          }
          catch (IOException e)
          {
              log("Could not write the task list to " + outputFile);
              log(e.toString(), Project.MSG_DEBUG);
          }
      }
  
      /**
       * Checks to see if any Tasks were collected by the visitor for the
       * specified file and creates a new {@link TaskListEntry} for those
       * Tasks.  The entry is then added to the {@link TaskList}, and the
       * visitor's list of tasks is cleared.
       *
       * @param filename The filename that these Tasks came from.
       */
      private void processResults(String filename)
      {
          /*
           * If the visitor didn't collect any tasks, then there is no
           * further processing that needs to occur.
           */
          if (visitor.getTasks().size() == 0)
          {
              return;
          }
  
          /*
           * Create a new TaskListEntry for this filename and its Tasks.
           */
          TaskListEntry taskListEntry = new TaskListEntry();
          taskListEntry.setFilename(filename);
  
          for (Iterator i = visitor.getTasks().iterator(); i.hasNext();)
          {
              Task task = (Task) i.next();
              taskListEntry.addTask(task);
          }
  
          /*
           * Add the new entry to the TaskList, and then clear the list
           * of tasks present in the Visitor so they are not accounted
           * more than once.  If we didn't care about the filename, we
           * could just let the visitor accumulate all the tasks and forgo
           * any processing until the end in doPostProcessing.
           */
          taskList.addTaskListEntry(taskListEntry);
          visitor.getTasks().clear();
      }
  
      /**
       * Converts the absolute filename into the relative filename from
       * the base directory specified as part of the Ant task.
       *
       * @param file The file.
       * @return The relative pathname from the base specified by the Ant
       * task.
       */
      private String relativeFilename(File file)
      {
          String filename = file.toString();
          String base = getBase().toString();
  
          /*
           * The base can be a single file, or a directory.  First, lets
           * make sure that the two aren't equal (i.e. the base was
           * specified as a file), if they are, then just return the
           * filename.  Otherwise, strip the base from the filename.
           */
          if (base.equals(filename))
          {
              return filename;
          }
          else
          {
              return filename.substring(base.length() + 1);
          }
      }
  }
  
  
  
  1.1                  
jakarta-turbine-maven/src/plugins-build/tasklist/src/java/org/apache/maven/tasklist/TaskListVisitor.java
  
  Index: TaskListVisitor.java
  ===================================================================
  package org.apache.maven.tasklist;
  
  /* ====================================================================
   * 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 java.util.ArrayList;
  import java.util.List;
  
  import org.apache.maven.java.BaseVisitor;
  import org.apache.maven.java.JavaDocTagTokenizer;
  import org.apache.maven.java.parser.ASTJavaDocTag;
  
  /**
   * A visitor that accumulates a list of tasks indicated by the "task"
   * JavaDoc tags.  This visitor maintains a list of {@link Task} objects
   * that were found in the AST.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Pete Kazmier</a>
   * @version $Id: TaskListVisitor.java,v 1.1 2002/07/14 22:18:16 jvanzyl Exp $
   */
  class TaskListVisitor extends BaseVisitor
  {
      /** The string literal representing a task javadoc tag. */
      private String taskTag = "task";
  
      /** The list of tasks accumulated. */
      private List tasks = new ArrayList();
  
      /** The tokenizer to process each ASTJavaDocTag Node. */
      private JavaDocTagTokenizer tokenizer = new JavaDocTagTokenizer();
  
      /**
       * Called by a ASTJavDocTag Node when the TaskListVisitor visits to create
       * a list of tasks from the '@task' tags within the JavaDoc.
       *
       * @param node The current node being traversed (visited).
       * @param data Extra data passed from another visit.
       * @return Extra data returned from the visit.
       */
      public Object visit(ASTJavaDocTag node, Object data)
      {
          /*
           * Utilize a JavaDocTagTokenizer to provide simple access to
           * the various JavaDoc tag elements: name, params, and value.
           * The tokenizer can be re-used and initialized by calling
           * setNode with the new Node to process.
           */
          tokenizer.setNode(node);
  
          /*
           * Is this JavaDoc tag one that we are interested in?  We are
           * only looking for tags that match the task tag.
           */
          String tagName = tokenizer.getTagName();
          if (tagName != null && tagName.equals(getTaskTag()))
          {
              /*
               * Found a match, create an associated Task object to
               * represent the task tag and add it to the current list of
               * tasks.  Currently, the Task object only contains a
               * description which is set to the value of the JavaDoc tag.
               * In the future, Task may contain other components such as
               * a priority.
               */
              Task task = new Task();
              task.setDescription(tokenizer.getTagValue());
              tasks.add(task);
          }
  
          return data;
      }
  
      /**
       * Gets the list of tasks that were parsed from the JavaDoc tags
       * during visits.  The list is composed of {@link Task} objects.
       *
       * @return The list of tasks.
       */
      public List getTasks()
      {
          return tasks;
      }
  
      /**
       * Gets the tag that is used to represent a task.
       *
       * @return The task tag.
       */
      public String getTaskTag()
      {
          return taskTag;
      }
  
      /**
       * Sets the tag that is used to represent a task.
       *
       * @param taskTag The task tag.
       */
      public void setTaskTag(String taskTag)
      {
          this.taskTag = taskTag;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to