jvanzyl     2002/07/11 15:04:31

  Modified:    src/java/org/apache/maven/jxr JxrBean.java
  Log:
  o JXR is now a straight bean which we utilize by making a dynamic
    jellybean. Thanks brian.
  
  Revision  Changes    Path
  1.2       +94 -82    jakarta-turbine-maven/src/java/org/apache/maven/jxr/JxrBean.java
  
  Index: JxrBean.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-maven/src/java/org/apache/maven/jxr/JxrBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JxrBean.java      6 Jul 2002 12:57:00 -0000       1.1
  +++ JxrBean.java      11 Jul 2002 22:04:31 -0000      1.2
  @@ -59,13 +59,12 @@
   import org.apache.maven.jxr.JXR;
   import org.apache.maven.jxr.DirectoryIndexer;
   import org.apache.maven.jxr.pacman.PackageManager;
  -import org.apache.maven.executor.AbstractExecutor;
  -import org.apache.tools.ant.types.Reference;
  -import org.apache.tools.ant.types.Path;
  -import org.apache.tools.ant.BuildException;
  +import java.util.List;
   import java.util.LinkedList;
  +import java.util.Iterator;
   import java.io.File;
   import java.io.IOException;
  +import java.io.FileNotFoundException;
   
   /**
    * Creates an html-based, cross referenced  version of Java source code
  @@ -73,22 +72,17 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Josh Lucas</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jason van Zyl</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]";>Brian Leonard</a>
    * @version $Id$
    */
   public class JxrBean
  -    extends AbstractExecutor
   {
       /**
        * Directories to be cross-referenced
        */
  -    private Path sourcePath;
  +    private List sourceDirs;
   
       /**
  -     * Reference object contatining multiple paths to be cross-referenced
  -     */
  -    private Reference ref;
  -    
  -    /**
        * the destination directory
        */
       private String destDir;
  @@ -110,59 +104,40 @@
   
   
       /**
  -     * Starts the cross-referencing and indexing.
  -     * @throws BuildException when any error occurs
  +     * Default constructor
        */
  -    public void execute()
  -        throws BuildException
  +    public JxrBean()
       {
  -        // ant's TaskAdapter doesn't set the Project until this method, so
  -        // figure out which path to use here. 
  -        if (sourcePath == null)
  -        {
  -            if (ref != null)
  -            {
  -                sourcePath = new Path(getProject());
  -                sourcePath.createPath().setRefid(ref);
  -            }
  -            else
  -            {
  -                String err = "Must specify either sourcePathRef or sourcePath";
  -                throw new BuildException(err);
  -            }
  -        }
  +        sourceDirs = new LinkedList();
  +    }
   
  +    
  +    /**
  +     * Starts the cross-referencing and indexing.
  +     * @throws IOException when any error occurs
  +     */
  +    public void xref()
  +        throws IOException
  +    {
           // get a relative link to the javadocs
           String javadocLinkDir = null;
  -        try
  -        {
  -            javadocLinkDir = getRelativeLink(destDir, javadocDir);
  -        }
  -        catch (IOException ioe)
  -        {
  -            throw new BuildException("Error finding javadocs", ioe);
  -        }
  +        javadocLinkDir = getRelativeLink(destDir, javadocDir);
           
           // go through each source directory and xref the java files
           PackageManager pkgmgr = PackageManager.getInstance();
  -        String[] paths = sourcePath.list();
  -        for (int i = 0; i < paths.length; ++i)
  +
  +        Iterator paths = sourceDirs.iterator();
  +        while (paths.hasNext())
           {
  -            pkgmgr.process(paths[i]);
  +            String path = (String) paths.next();
   
  -            new JXR(paths[i], destDir, javadocLinkDir, "HEAD");
  +            pkgmgr.process(path);
  +            new JXR(path, destDir, javadocLinkDir, "HEAD");
           }
  -
  +        
           // once we have all the source files xref'd, create the index pages
  -        try
  -        {
  -            new DirectoryIndexer(destDir, destDir, imageFolder, imageFile,
  -                                 DirectoryIndexer.MODE_JAVA);
  -        }
  -        catch (IOException ioe)
  -        {
  -            throw new BuildException(ioe);
  -        }
  +        new DirectoryIndexer(destDir, destDir, imageFolder, imageFile,
  +                             DirectoryIndexer.MODE_JAVA);
       }
   
       /**
  @@ -186,23 +161,22 @@
           StringBuffer toLink = new StringBuffer();   // up from fromDir
           StringBuffer fromLink = new StringBuffer(); // down into toDir
   
  -        // assume they are both at least rooted at the project's baseDir
  -        File baseDir = new File(getProject().getBaseDir().getCanonicalPath());
  -
           // create a List of toDir's parent directories
           LinkedList parents = new LinkedList();
  -        File f = new File(new File(javadocDir).getCanonicalPath());
  -        while (f != null && !f.equals(baseDir))
  +        File f = new File(toDir);
  +        f = f.getCanonicalFile();
  +        while (f != null)
           {
               parents.add(f);
  -            f = new File(f.getParent());
  +            f = f.getParentFile();
           }
               
           // walk up fromDir to find the common parent
  -        f = new File(new File(destDir).getCanonicalPath());
  -        f = new File(f.getParent());
  +        f = new File(fromDir);
  +        f = f.getCanonicalFile();
  +        f = f.getParentFile();
           boolean found = false;
  -        while (f != null && !found && !f.equals(baseDir))
  +        while (f != null && !found)
           {
               for (int i = 0; i < parents.size(); ++i)
               {
  @@ -220,15 +194,21 @@
                       break;
                   }
               }
  -            f = new File(f.getParent());
  +            f = f.getParentFile();
               fromLink.append("../");
           }
   
  +        if (!found)
  +        {
  +            throw new FileNotFoundException(fromDir + " and " + toDir +
  +                                            " have no common parent.");
  +        }
  +
           return fromLink.append(toLink).toString();
       }
  -    
  +
       /**
  -     * Sets the imageFile attribute of the JxrTask object
  +     * Sets the imageFile attribute
        * @param imageFile the image to be used for the {@link DirectoryIndexer}
        */
       public void setImageFile(String imageFile)
  @@ -237,7 +217,16 @@
       }
   
       /**
  -     * Sets the imageFolder attribute of the JxrTask object
  +     * Gets the imageFile attribute
  +     */
  +    public String getImageFile()
  +    {
  +        return imageFile;
  +    }
  +
  +
  +    /**
  +     * Sets the imageFolder attribute
        * @param imageFolder the folder for the {@link #imageFile}
        */
       public void setImageFolder(String imageFolder)
  @@ -246,33 +235,39 @@
       }
   
       /**
  -     * Sets the source path to a single path, or
  -     * appends onto the existing source path.
  -     * @param src The source directory to be cross-referenced.
  +     * Gets the imageFolder attribute
        */
  -    public void setSourcepath(Path src)
  +    public String setImageFolder()
       {
  -        if (sourcePath == null)
  -        {
  -            sourcePath = src;
  -        }
  -        else
  +        return imageFolder;
  +    }
  +
  +
  +    /**
  +     * Sets a single source directory to be cross-referenced.
  +     * @param sourceDir The source directory to be cross-referenced.
  +     */
  +    public void setSourceDir(String sourceDir)
  +    {
  +        if (!sourceDirs.isEmpty())
           {
  -            sourcePath.append(src);
  +            sourceDirs.clear();
           }
  +        addSourceDir(sourceDir);
       }
  -        
  +
       /**
  -     * Sets the source path to a reference object
  -     * @param ref The Reference object containing paths to be cross-referenced.
  +     * Adds a source directory to be cross-referenced.
  +     * @param sourceDir The source directory to be cross-referenced.
        */
  -    public void setSourcepathref(Reference ref)
  +    public void addSourceDir(String sourceDir)
       {
  -        this.ref = ref;
  +        sourceDirs.add(sourceDir);
       }
   
  +
       /**
  -     * Sets the destDir attribute of the JxrTask object
  +     * Sets the destDir attribute
        * @param destDir the destination directory for jxr output
        */
       public void setDestDir(String destDir)
  @@ -281,12 +276,29 @@
       }
   
       /**
  +     * Gets the destDir attribute
  +     */
  +    public String getDestDir()
  +    {
  +        return destDir;
  +    }
  +
  +
  +    /**
        * Sets the javadocDir attribute of the JxrTask object
        * @param javadocDir The root directory containing javadocs
        */
       public void setJavadocDir(String javadocDir)
       {
           this.javadocDir = javadocDir;
  +    }
  +
  +    /**
  +     * Gets the javadocDir attribute of the JxrTask object
  +     */
  +    public String setJavadocDir()
  +    {
  +        return javadocDir;
       }
   }
   
  
  
  

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

Reply via email to