maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r594115 - in /maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc: AntDoc.java AntDocTask.java GenerateHTMLDoc.java
Date Mon, 12 Nov 2007 13:34:39 GMT
Author: vsiveton
Date: Mon Nov 12 05:34:38 2007
New Revision: 594115

URL: http://svn.apache.org/viewvc?rev=594115&view=rev
Log:
o using the Plexus way

Added:
    maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDoc.java
  (with props)
Modified:
    maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDocTask.java
    maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/GenerateHTMLDoc.java

Added: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDoc.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDoc.java?rev=594115&view=auto
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDoc.java
(added)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDoc.java
Mon Nov 12 05:34:38 2007
@@ -0,0 +1,59 @@
+package org.apache.maven.jxr.ant.doc;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Interface to generate documentation (images and HTML) from an <a href="http://ant.apache.org/">Ant</a>
buildfile.
+ * The image/HTML shows the Ant targets dependency.
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public interface AntDoc
+{
+    /** The Plexus lookup role. */
+    String ROLE = AntDoc.class.getName();
+
+    /**
+     * Generate documentation from an <a href="http://ant.apache.org/">Ant</a>
buildfile.
+     *
+     * @param antFile the Ant file, typically <code>build.xml</code>, should
be not null.
+     * @param destDir the destination directory of the generated documentation, should be
not null
+     * @throws IOException if any
+     * @throws AntDocException if any
+     */
+    void generate( File antFile, File destDir )
+        throws IOException, AntDocException;
+
+    /**
+     * Generate documentation from an <a href="http://ant.apache.org/">Ant</a>
buildfile.
+     *
+     * @param graphExecutable the graph executable to use, for instance <a href="http://www.graphviz.org/">Graphviz</a>,
should be not null.
+     * @param antFile the Ant file, typically <code>build.xml</code>, should
be not null.
+     * @param destDir the destination directory of the generated documentation, should be
not null
+     * @throws IOException if any
+     * @throws AntDocException if any
+     */
+    void generate( File graphExecutable, File antFile, File destDir )
+        throws IOException, AntDocException;
+}

Propchange: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDoc.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDoc.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDocTask.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDocTask.java?rev=594115&r1=594114&r2=594115&view=diff
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDocTask.java
(original)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/AntDocTask.java
Mon Nov 12 05:34:38 2007
@@ -20,6 +20,7 @@
  */
 
 import java.io.File;
+import java.io.IOException;
 
 import org.apache.maven.jxr.util.DotUtil.DotNotPresentInPathException;
 import org.apache.tools.ant.BuildException;
@@ -44,6 +45,9 @@
     /** Graphviz Dot executable file */
     private File dotExecutable;
 
+    /** Verbose mode */
+    private boolean verbose;
+
     /** Terminate Ant build */
     private boolean failOnError;
 
@@ -78,6 +82,16 @@
     }
 
     /**
+     * Set verbose mode.
+     *
+     * @param b true to verbose mode.
+     */
+    public void setVerbose( boolean b )
+    {
+        this.verbose = b;
+    }
+
+    /**
      * Set fail on an error.
      *
      * @param b true to fail on an error.
@@ -112,9 +126,16 @@
     {
         try
         {
-            GenerateHTMLDoc generator = new GenerateHTMLDoc( this.antFile, this.destDir );
-            generator.setDotExecutable( this.dotExecutable );
-            generator.generateDoc();
+            GenerateHTMLDoc generator = new GenerateHTMLDoc();
+            generator.setVerbose( this.verbose );
+            if ( this.dotExecutable != null )
+            {
+                generator.generate( this.dotExecutable, this.antFile, this.destDir );
+            }
+            else
+            {
+                generator.generate( this.antFile, this.destDir );
+            }
         }
         catch ( IllegalArgumentException e )
         {
@@ -133,6 +154,15 @@
             }
 
             log( "Dot is not present in the path: " + e.getMessage(), Project.MSG_ERR );
+        }
+        catch ( IOException e )
+        {
+            if ( !failOnError )
+            {
+                throw new BuildException( "IOException: " + e.getMessage(), e, getLocation()
);
+            }
+
+            log( "IOException: " + e.getMessage(), Project.MSG_ERR );
         }
         catch ( AntDocException e )
         {

Modified: maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/GenerateHTMLDoc.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/GenerateHTMLDoc.java?rev=594115&r1=594114&r2=594115&view=diff
==============================================================================
--- maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/GenerateHTMLDoc.java
(original)
+++ maven/sandbox/trunk/jxr/maven-jxr/maven-jxr-ant/src/main/java/org/apache/maven/jxr/ant/doc/GenerateHTMLDoc.java
Mon Nov 12 05:34:38 2007
@@ -36,6 +36,7 @@
 import org.apache.maven.jxr.ant.doc.vizant.Vizant;
 import org.apache.maven.jxr.util.DotUtil;
 import org.apache.maven.jxr.util.DotUtil.DotNotPresentInPathException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.cli.CommandLineException;
@@ -48,8 +49,11 @@
  *
  * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
  * @version $Id$
+ * @plexus.component role="org.apache.maven.jxr.ant.doc.AntDoc" role-hint="default"
  */
 public class GenerateHTMLDoc
+    extends AbstractLogEnabled
+    implements AntDoc
 {
     /** An ant file */
     private File antFile;
@@ -60,6 +64,9 @@
     /** Graphviz Dot executable file */
     private File dotExecutable;
 
+    /** Verbose mode */
+    private boolean verbose;
+
     /** Temp xsl file */
     private File xml2dot;
 
@@ -78,13 +85,13 @@
     /** Temp generated touch graph */
     private File buildtg;
 
-    /**
-     * @param antFile
-     * @param destDir
-     * @throws IllegalArgumentException
-     */
-    public GenerateHTMLDoc( File antFile, File destDir )
-        throws IllegalArgumentException
+    // ----------------------------------------------------------------------
+    // Public
+    // ----------------------------------------------------------------------
+
+    /** {@inheritDoc} */
+    public void generate( File antFile, File destDir )
+        throws IllegalArgumentException, DotNotPresentInPathException, IOException, AntDocException
     {
         if ( antFile == null )
         {
@@ -92,110 +99,33 @@
         }
         if ( !antFile.exists() || !antFile.isFile() )
         {
-            throw new IllegalArgumentException( "Input '" + getAntFile() + "' not found or
not a file." );
+            throw new IOException( "Input '" + antFile + "' not found or not a file." );
         }
 
         if ( destDir == null )
         {
-            throw new IllegalArgumentException( "Missing mandatory attribute 'dest'." );
+            throw new IllegalArgumentException( "Missing mandatory attribute 'destDir'."
);
         }
         if ( destDir.exists() && !destDir.isDirectory() )
         {
-            throw new IllegalArgumentException( "Dest directory is a file." );
+            throw new IOException( "Input '" + destDir + "' is a file." );
         }
         if ( !destDir.exists() && !destDir.mkdirs() )
         {
-            throw new IllegalArgumentException( "Cannot create the dest directory." );
+            throw new IOException( "Cannot create the dest directory '" + destDir + "'."
);
         }
 
         this.antFile = antFile;
         this.destDir = destDir;
-    }
-
-    /**
-     * @return the Ant file which be parsed.
-     */
-    public File getAntFile()
-    {
-        return this.antFile;
-    }
-
-    /**
-     * @return the dest dir
-     */
-    public File getDestDir()
-    {
-        return this.destDir;
-    }
-
-    /**
-     * Getter for the dotExecutable
-     *
-     * @return the dotExecutable
-     */
-    public File getDotExecutable()
-    {
-        return this.dotExecutable;
-    }
 
-    /**
-     * Setter for the antFile
-     *
-     * @param antFile the antFile to set
-     */
-    public void setAntFile( File antFile )
-    {
-        this.antFile = antFile;
-    }
-
-    /**
-     * Setter for the destDir
-     *
-     * @param destDir the destDir to set
-     */
-    public void setDestDir( File destDir )
-    {
-        this.destDir = destDir;
-    }
-
-    /**
-     * Setter for the dotExecutable
-     *
-     * @param dotExecutable the dotExecutable to set
-     */
-    public void setDotExecutable( File dotExecutable )
-    {
-        this.dotExecutable = dotExecutable;
-    }
-
-    /**
-     * Generate the documentation.
-     *
-     * @throws DotNotPresentInPathException if any
-     * @throws AntDocException if any
-     */
-    public void generateDoc()
-        throws DotNotPresentInPathException, AntDocException
-    {
         // 1. Generate Vizant graph
-        try
-        {
-            generateVizantBuildGraph();
-        }
-        catch ( IOException e )
-        {
-            throw new AntDocException( "IOException: " + e.getMessage() );
-        }
+        generateVizantBuildGraph();
 
         // 2. Generate dot graph
         try
         {
             generateDotBuildGraph();
         }
-        catch ( IOException e )
-        {
-            throw new AntDocException( "IOException: " + e.getMessage() );
-        }
         catch ( TransformerException e )
         {
             throw new AntDocException( "TransformerException: " + e.getMessage() );
@@ -216,21 +146,89 @@
         {
             generateSite();
         }
-        catch ( IOException e )
-        {
-            throw new AntDocException( "IOException: " + e.getMessage() );
-        }
         catch ( TransformerException e )
         {
             throw new AntDocException( "TransformerException: " + e.getMessage() );
         }
     }
 
+    /** {@inheritDoc} */
+    public void generate( File graphExecutable, File antFile, File destDir )
+        throws IllegalArgumentException, DotNotPresentInPathException, IOException, AntDocException
+    {
+        if ( dotExecutable == null )
+        {
+            throw new IllegalArgumentException( "Missing mandatory attribute 'dotExecutable'."
);
+        }
+        if ( !dotExecutable.exists() || !dotExecutable.isFile() )
+        {
+            throw new IOException( "Input '" + dotExecutable + "' not found or not a file."
);
+        }
+        this.dotExecutable = graphExecutable;
+
+        generate( antFile, destDir );
+    }
+
+    // ----------------------------------------------------------------------
+    // Protected
+    // ----------------------------------------------------------------------
+
+    /**
+     * Setter for the verbose. Used by Ant task
+     *
+     * @param verbose the verbose to set
+     */
+    protected void setVerbose( boolean verbose )
+    {
+        this.verbose = verbose;
+    }
+
     // ----------------------------------------------------------------------
     // Private
     // ----------------------------------------------------------------------
 
     /**
+     * @return the Ant file which be parsed.
+     */
+    private File getAntFile()
+    {
+        return this.antFile;
+    }
+
+    /**
+     * @return the dest dir
+     */
+    private File getDestDir()
+    {
+        return this.destDir;
+    }
+
+    /**
+     * Getter for the dotExecutable
+     *
+     * @return the dotExecutable
+     */
+    private File getDotExecutable()
+    {
+        return this.dotExecutable;
+    }
+
+    /**
+     * Getter for the verbose
+     *
+     * @return the verbose
+     */
+    private boolean isVerbose()
+    {
+        if ( getLogger() != null ) // for Ant tasks
+        {
+            return !getLogger().isInfoEnabled();
+        }
+
+        return this.verbose;
+    }
+
+    /**
      * @return xsl temp file.
      * @throws IOException if any
      */
@@ -240,7 +238,10 @@
         if ( this.xml2dot == null )
         {
             this.xml2dot = FileUtils.createTempFile( "xml2dot", ".xsl", getDestDir() );
-            this.xml2dot.deleteOnExit();
+            if ( !isVerbose() )
+            {
+                this.xml2dot.deleteOnExit();
+            }
 
             InputStream is = getClass().getClassLoader().getResourceAsStream( "vizant/xml2dot.xsl"
);
             if ( is == null )
@@ -270,7 +271,10 @@
         if ( this.xml2html == null )
         {
             this.xml2html = FileUtils.createTempFile( "xml2html", ".xsl", getDestDir() );
-            this.xml2html.deleteOnExit();
+            if ( !isVerbose() )
+            {
+                this.xml2html.deleteOnExit();
+            }
 
             InputStream is = getClass().getClassLoader().getResourceAsStream( "vizant/xml2html.xsl"
);
             if ( is == null )
@@ -300,7 +304,10 @@
         if ( this.xml2tg == null )
         {
             this.xml2tg = FileUtils.createTempFile( "xml2tg", ".xsl", getDestDir() );
-            this.xml2tg.deleteOnExit();
+            if ( !isVerbose() )
+            {
+                this.xml2tg.deleteOnExit();
+            }
 
             InputStream is = getClass().getClassLoader().getResourceAsStream( "vizant/xml2tg.xsl"
);
             if ( is == null )
@@ -317,7 +324,7 @@
             IOUtil.close( w );
         }
 
-        return this.xml2html;
+        return this.xml2tg;
     }
 
     /**
@@ -328,7 +335,10 @@
         if ( this.buildGraph == null )
         {
             this.buildGraph = FileUtils.createTempFile( "buildgraph", ".xml", getDestDir()
);
-            this.buildGraph.deleteOnExit();
+            if ( !isVerbose() )
+            {
+                this.buildGraph.deleteOnExit();
+            }
         }
 
         return this.buildGraph;
@@ -342,7 +352,10 @@
         if ( this.dot == null )
         {
             this.dot = FileUtils.createTempFile( "buildgraph", ".dot", getDestDir() );
-            this.dot.deleteOnExit();
+            if ( !isVerbose() )
+            {
+                this.dot.deleteOnExit();
+            }
         }
 
         return this.dot;
@@ -356,7 +369,10 @@
         if ( this.buildtg == null )
         {
             this.buildtg = FileUtils.createTempFile( "buildtg", ".xml", getDestDir() );
-            this.buildtg.deleteOnExit();
+            if ( !isVerbose() )
+            {
+                this.buildtg.deleteOnExit();
+            }
         }
 
         return this.buildtg;



Mime
View raw message