maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vsive...@apache.org
Subject svn commit: r679984 - in /maven/plugins/trunk/maven-javadoc-plugin/src: main/java/org/apache/maven/plugin/javadoc/ site/apt/examples/ test/java/org/apache/maven/plugin/javadoc/ test/java/org/apache/maven/plugin/javadoc/stubs/ test/resources/unit/taglet...
Date Sat, 26 Jul 2008 12:16:34 GMT
Author: vsiveton
Date: Sat Jul 26 05:16:33 2008
New Revision: 679984

URL: http://svn.apache.org/viewvc?rev=679984&view=rev
Log:
MJAVADOC-204: Have a way to auto detect tagletClass from a given tagletArtifact

o added new tagletArtifacts parameter
o added test case
o updated documentation

Added:
    maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/TagletArtifactsMavenProjectStub.java
  (with props)
    maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/
    maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/src/
    maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/src/main/
    maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/src/main/java/
    maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/src/main/java/test/
    maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/src/main/java/test/App.java
  (with props)
    maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml
  (with props)
Modified:
    maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java
    maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
    maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/taglet-configuration.apt
    maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java

Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java?rev=679984&r1=679983&r2=679984&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java
(original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java
Sat Jul 26 05:16:33 2008
@@ -1089,12 +1089,21 @@
     private String tagletpath;
 
     /**
-     * Specifies the artifact containing the taglet class files (.class).
+     * Specifies the Taglet artifact containing the taglet class files (.class).
      * <br/>
      * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#tagletpath">tagletpath</a>.
      * <br/>
      * Example:
      * <pre>
+     * &lt;taglets&gt;
+     * &nbsp;&nbsp;&lt;taglet&gt;
+     * &nbsp;&nbsp;&nbsp;&nbsp;&lt;tagletClass&gt;com.sun.tools.doclets.ToDoTaglet&lt;/tagletClass&gt;
+     * &nbsp;&nbsp;&lt;/taglet&gt;
+     * &nbsp;&nbsp;&lt;taglet&gt;
+     * &nbsp;&nbsp;&nbsp;&nbsp;&lt;tagletClass&gt;package.to.AnotherTagletClass&lt;/tagletClass&gt;
+     * &nbsp;&nbsp;&lt;/taglet&gt;
+     * &nbsp;&nbsp;...
+     * &lt;/taglets&gt;
      * &lt;tagletArtifact&gt;
      * &nbsp;&nbsp;&lt;groupId&gt;group-Taglet&lt;/groupId&gt;
      * &nbsp;&nbsp;&lt;artifactId&gt;artifact-Taglet&lt;/artifactId&gt;
@@ -1111,6 +1120,34 @@
     private TagletArtifact tagletArtifact;
 
     /**
+     * Specifies several Taglet artifacts containing the taglet class files (.class). These
taglets class names will be
+     * auto-detect and so no need to specify them.
+     * <br/>
+     * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#taglet">taglet</a>.
+     * <br/>
+     * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#tagletpath">tagletpath</a>.
+     * <br/>
+     * Example:
+     * <pre>
+     * &lt;tagletArtifacts&gt;
+     * &nbsp;&nbsp;&lt;tagletArtifact&gt;
+     * &nbsp;&nbsp;&nbsp;&nbsp;&lt;groupId&gt;group-Taglet&lt;/groupId&gt;
+     * &nbsp;&nbsp;&nbsp;&nbsp;&lt;artifactId&gt;artifact-Taglet&lt;/artifactId&gt;
+     * &nbsp;&nbsp;&nbsp;&nbsp;&lt;version&gt;version-Taglet&lt;/version&gt;
+     * &nbsp;&nbsp;&lt;/tagletArtifact&gt;
+     * &nbsp;&nbsp;...
+     * &lt;/tagletArtifacts&gt;
+     * </pre>
+     * <br/>
+     * See <a href="./apidocs/org/apache/maven/plugin/javadoc/options/TagletArtifact.html">Javadoc</a>.
+     * <br/>
+     *
+     * @since 2.5
+     * @parameter expression="${tagletArtifacts}"
+     */
+    private TagletArtifact[] tagletArtifacts;
+
+    /**
      * Enables the Javadoc tool to interpret multiple taglets.
      * <br/>
      * See <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#taglet">taglet</a>.
@@ -1641,6 +1678,7 @@
                     }
                 }
             }
+            addTagletsFromTagletArtifacts( arguments );
             addArgIfNotEmpty( arguments, "-tagletpath", JavadocUtil.quotedPathArgument( getTagletPath()
),
                               SINCE_JAVADOC_1_4 );
 
@@ -2398,7 +2436,28 @@
             path.append( StringUtils.join( getArtifactsAbsolutePath( tagletArtifact ).iterator(),
                                            File.pathSeparator ) );
         }
-        else if ( taglets != null )
+
+        if ( tagletArtifacts != null )
+        {
+            List tagletsPath = new ArrayList();
+            for ( int i = 0; i < tagletArtifacts.length; i++ )
+            {
+                TagletArtifact aTagletArtifact = tagletArtifacts[i];
+
+                if ( ( StringUtils.isNotEmpty( aTagletArtifact.getGroupId() ) )
+                    && ( StringUtils.isNotEmpty( aTagletArtifact.getArtifactId()
) )
+                    && ( StringUtils.isNotEmpty( aTagletArtifact.getVersion() ) )
)
+                {
+                    tagletsPath.addAll( getArtifactsAbsolutePath( aTagletArtifact ) );
+                }
+            }
+
+            tagletsPath = JavadocUtil.pruneFiles( tagletsPath );
+
+            path.append( StringUtils.join( tagletsPath.iterator(), File.pathSeparator ) );
+        }
+
+        if ( taglets != null )
         {
             List tagletsPath = new ArrayList();
             for ( int i = 0; i < taglets.length; i++ )
@@ -2427,7 +2486,8 @@
 
             path.append( StringUtils.join( tagletsPath.iterator(), File.pathSeparator ) );
         }
-        else
+
+        if ( StringUtils.isNotEmpty( tagletpath ) )
         {
             path.append( tagletpath );
         }
@@ -2511,16 +2571,23 @@
      * @return a resolved {@link Artifact}
      * @throws ArtifactResolutionException if the resolution of the artifact failed.
      * @throws ArtifactNotFoundException if the artifact hasn't been found.
+     * @throws ProjectBuildingException if the artifact POM could not be build.
      */
     private Artifact createAndResolveArtifact( JavadocPathArtifact javadocArtifact )
-        throws ArtifactResolutionException, ArtifactNotFoundException
+        throws ArtifactResolutionException, ArtifactNotFoundException, ProjectBuildingException
     {
         Artifact artifact =
-            factory.createArtifact( javadocArtifact.getGroupId(), javadocArtifact.getArtifactId(),
-                                    javadocArtifact.getVersion(), Artifact.SCOPE_COMPILE,
"jar" );
+            factory.createProjectArtifact( javadocArtifact.getGroupId(), javadocArtifact.getArtifactId(),
+                                           javadocArtifact.getVersion(), Artifact.SCOPE_COMPILE
);
 
-        // Find the Javadoc Artifact in the local repo
-        resolver.resolve( artifact, remoteRepositories, localRepository );
+        if ( artifact.getFile() == null )
+        {
+            MavenProject pluginProject =
+                mavenProjectBuilder.buildFromRepository( artifact, remoteRepositories, localRepository
);
+            artifact = pluginProject.getArtifact();
+
+            resolver.resolve( artifact, remoteRepositories, localRepository );
+        }
 
         return artifact;
     }
@@ -2677,7 +2744,7 @@
             if ( !javadocExe.isFile() )
             {
                 throw new IOException( "The javadoc executable '" + javadocExe
-                    + "' doesn't exist or is not a file. " + "Verify the <javadocExecutable/>
parameter." );
+                    + "' doesn't exist or is not a file. Verify the <javadocExecutable/>
parameter." );
             }
 
             return javadocExe.getAbsolutePath();
@@ -2720,7 +2787,7 @@
             if ( ( !new File( javaHome ).exists() ) || ( !new File( javaHome ).isDirectory()
) )
             {
                 throw new IOException( "The environment variable JAVA_HOME=" + javaHome
-                    + " doesn't exist or is " + "not a valid directory." );
+                    + " doesn't exist or is not a valid directory." );
             }
 
             javadocExe = new File( env.getProperty( "JAVA_HOME" ) + File.separator + "bin",
javadocCommand );
@@ -2729,7 +2796,7 @@
         if ( !javadocExe.exists() || !javadocExe.isFile() )
         {
             throw new IOException( "The javadoc executable '" + javadocExe
-                + "' doesn't exist or is not a file. " + "Verify the JAVA_HOME environment
variable." );
+                + "' doesn't exist or is not a file. Verify the JAVA_HOME environment variable."
);
         }
 
         return javadocExe.getAbsolutePath();
@@ -3207,6 +3274,11 @@
                 {
                     throw new MavenReportException( "Unable to find artifact:" + item, e
);
                 }
+                catch ( ProjectBuildingException e )
+                {
+                    throw new MavenReportException( "Unable to build the Maven project for
the artifact:"
+                        + item, e );
+                }
 
                 unArchiver.setSourceFile( artifact.getFile() );
                 unArchiver.setDestDirectory( anOutputDirectory );
@@ -3528,4 +3600,123 @@
         // if all of them have been found, we can continue.
         return foundInReactor.size() == missing.size();
     }
+
+    /**
+     * Auto-detect taglets class name from <code>tagletArtifacts</code> and add
them to arguments.
+     *
+     * @param arguments not null
+     * @throws MavenReportException if any
+     * @see JavadocUtil#getTagletClassNames(File)
+     */
+    private void addTagletsFromTagletArtifacts( List arguments )
+        throws MavenReportException
+    {
+        if ( tagletArtifacts == null )
+        {
+            return;
+        }
+
+        List tagletsPath = new ArrayList();
+        for ( int i = 0; i < tagletArtifacts.length; i++ )
+        {
+            TagletArtifact aTagletArtifact = tagletArtifacts[i];
+
+            if ( ( StringUtils.isNotEmpty( aTagletArtifact.getGroupId() ) )
+                && ( StringUtils.isNotEmpty( aTagletArtifact.getArtifactId() ) )
+                && ( StringUtils.isNotEmpty( aTagletArtifact.getVersion() ) ) )
+            {
+                Artifact artifact;
+                try
+                {
+                    artifact = createAndResolveArtifact( aTagletArtifact );
+                }
+                catch ( ArtifactResolutionException e )
+                {
+                    throw new MavenReportException( "Unable to resolve artifact:" + aTagletArtifact,
e );
+                }
+                catch ( ArtifactNotFoundException e )
+                {
+                    throw new MavenReportException( "Unable to find artifact:" + aTagletArtifact,
e );
+                }
+                catch ( ProjectBuildingException e )
+                {
+                    throw new MavenReportException( "Unable to build the Maven project for
the artifact:"
+                        + aTagletArtifact, e );
+                }
+
+                tagletsPath.add( artifact.getFile().getAbsolutePath() );
+            }
+        }
+
+        tagletsPath = JavadocUtil.pruneFiles( tagletsPath );
+
+        for ( Iterator it = tagletsPath.iterator(); it.hasNext(); )
+        {
+            String tagletJar = (String) it.next();
+
+            if ( !tagletJar.toLowerCase( Locale.ENGLISH ).endsWith( ".jar" ) )
+            {
+                continue;
+            }
+
+            List tagletClasses;
+            try
+            {
+                tagletClasses = JavadocUtil.getTagletClassNames( new File( tagletJar ) );
+            }
+            catch ( IOException e )
+            {
+                if ( getLog().isWarnEnabled() )
+                {
+                    getLog().warn(
+                                   "Unable to auto-detect Taglet class names from '" + tagletJar
+                                       + "'. Try to specify them with <taglets/>."
);
+                }
+                if ( getLog().isDebugEnabled() )
+                {
+                    getLog().debug( "IOException: " + e.getMessage(), e );
+                }
+                continue;
+            }
+            catch ( ClassNotFoundException e )
+            {
+                if ( getLog().isWarnEnabled() )
+                {
+                    getLog().warn(
+                                   "Unable to auto-detect Taglet class names from '" + tagletJar
+                                       + "'. Try to specify them with <taglets/>."
);
+                }
+                if ( getLog().isDebugEnabled() )
+                {
+                    getLog().debug( "ClassNotFoundException: " + e.getMessage(), e );
+                }
+                continue;
+            }
+            catch ( NoClassDefFoundError e )
+            {
+                if ( getLog().isWarnEnabled() )
+                {
+                    getLog().warn(
+                                   "Unable to auto-detect Taglet class names from '" + tagletJar
+                                       + "'. Try to specify them with <taglets/>."
);
+                }
+                if ( getLog().isDebugEnabled() )
+                {
+                    getLog().debug( "NoClassDefFoundError: " + e.getMessage(), e );
+                }
+                continue;
+            }
+
+            if ( tagletClasses != null && !tagletClasses.isEmpty() )
+            {
+                for ( Iterator it2 = tagletClasses.iterator(); it2.hasNext(); )
+                {
+                    String tagletClass = (String) it2.next();
+
+                    addArgIfNotEmpty( arguments, "-taglet", JavadocUtil.quotedArgument( tagletClass
),
+                                      SINCE_JAVADOC_1_4 );
+                }
+            }
+        }
+    }
 }

Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java?rev=679984&r1=679983&r2=679984&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
(original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java
Sat Jul 26 05:16:33 2008
@@ -21,25 +21,32 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Modifier;
 import java.net.Authenticator;
 import java.net.PasswordAuthentication;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 import java.util.Properties;
 import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 
+import org.apache.commons.lang.SystemUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.settings.Proxy;
 import org.apache.maven.settings.Settings;
@@ -823,4 +830,116 @@
 
         return cmdLine;
     }
+
+    /**
+     * Auto-detect the class names of the implementation of <code>com.sun.tools.doclets.Taglet</code>
class from a
+     * given jar file.
+     * <br/>
+     * <b>Note</b>: <code>JAVA_HOME/lib/tools.jar</code> is a requirement
to find
+     * <code>com.sun.tools.doclets.Taglet</code> class.
+     *
+     * @param jarFile not null
+     * @return the list of <code>com.sun.tools.doclets.Taglet</code> class names
from a given jarFile.
+     * @throws IOException if jarFile is invalid or not found, or if the <code>JAVA_HOME/lib/tools.jar</code>
+     * is not found.
+     * @throws ClassNotFoundException if any
+     * @throws NoClassDefFoundError if any
+     */
+    protected static List getTagletClassNames( File jarFile )
+        throws IOException, ClassNotFoundException, NoClassDefFoundError
+    {
+        File jdkHome = null;
+        if ( SystemUtils.IS_OS_MAC_OSX )
+        {
+            jdkHome = SystemUtils.getJavaHome();
+        }
+        else
+        {
+            jdkHome = SystemUtils.getJavaHome().getParentFile();
+        }
+
+        if ( !jdkHome.exists() || !jdkHome.isDirectory() )
+        {
+            Properties env = CommandLineUtils.getSystemEnvVars();
+            String javaHome = env.getProperty( "JAVA_HOME" );
+
+            if ( StringUtils.isEmpty( javaHome ) )
+            {
+                throw new IOException( "The environment variable JAVA_HOME is not correctly
set." );
+            }
+            jdkHome = new File( javaHome );
+            if ( !jdkHome.exists() || !jdkHome.isDirectory() )
+            {
+                throw new IOException( "The environment variable JAVA_HOME=" + javaHome
+                    + " doesn't exist or is not a valid directory." );
+            }
+        }
+
+        // Needed to find com.sun.tools.doclets.Taglet class
+        File tools = new File( jdkHome, "lib/tools.jar" );
+        if ( !tools.exists() || !tools.isFile() )
+        {
+            throw new IOException( "tools.jar '" + tools + "' was not found or is invalid."
);
+        }
+
+        List classes = getClassNamesFromJar( jarFile );
+        ClassLoader cl = new URLClassLoader( new URL[] { jarFile.toURI().toURL(), tools.toURI().toURL()
}, null );
+
+        List tagletClasses = new ArrayList();
+
+        Class tagletClass = cl.loadClass( "com.sun.tools.doclets.Taglet" );
+        for ( Iterator it = classes.iterator(); it.hasNext(); )
+        {
+            String s = (String) it.next();
+
+            Class c = cl.loadClass( s );
+
+            if ( tagletClass.isAssignableFrom( c ) && !Modifier.isAbstract( c.getModifiers()
) )
+            {
+                tagletClasses.add( c.getName() );
+            }
+        }
+
+        return tagletClasses;
+    }
+
+    // ----------------------------------------------------------------------
+    // private methods
+    // ----------------------------------------------------------------------
+
+    /**
+     * @param jarFile not null
+     * @return all class names from the given jar file.
+     * @throws IOException if any or if the jarFile is null or doesn't exist.
+     */
+    private static List getClassNamesFromJar( File jarFile )
+        throws IOException
+    {
+        if ( jarFile == null || !jarFile.exists() || !jarFile.isFile() )
+        {
+            throw new IOException( "The jar '" + jarFile + "' doesn't exist or is not a file."
);
+        }
+
+        List classes = new ArrayList();
+        JarInputStream jarStream = new JarInputStream( new FileInputStream( jarFile ) );
+        JarEntry jarEntry = jarStream.getNextJarEntry();
+        while ( jarEntry != null )
+        {
+            if ( jarEntry == null )
+            {
+                break;
+            }
+
+            if ( jarEntry.getName().toLowerCase( Locale.ENGLISH ).endsWith( ".class" ) )
+            {
+                String name = jarEntry.getName().substring( 0, jarEntry.getName().indexOf(
"." ) );
+
+                classes.add( name.replaceAll( "/", "\\." ) );
+            }
+
+            jarEntry = jarStream.getNextJarEntry();
+        }
+
+        return classes;
+    }
 }

Modified: maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/taglet-configuration.apt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/taglet-configuration.apt?rev=679984&r1=679983&r2=679984&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/taglet-configuration.apt
(original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/site/apt/examples/taglet-configuration.apt
Sat Jul 26 05:16:33 2008
@@ -1,9 +1,9 @@
  ------
- Configuring Custom Taglet
+ Configuring Custom Taglets
  ------
  Vincent Siveton
  ------
- September 2006
+ 2008-07-26
  ------
 
 ~~ Licensed to the Apache Software Foundation (ASF) under one
@@ -26,15 +26,17 @@
 ~~ NOTE: For help with the syntax of this file, see:
 ~~ http://maven.apache.org/doxia/references/apt-format.html
 
-Configuring Custom Taglet
+Configuring Custom Taglets
 
- You could configure any custom taglet used in your javadoc via the \<taglet\> or \<taglets\>
elements, depending
- the number of taglet used.
+ You could configure any custom taglets in your Javadoc Plugin configuration via the \<taglet/\>,
\<taglets/\>
+ or \<tagletArtifacts/\> elements, depending the number of taglets used.
 
  For more information about the taglet technology, please refer to
- {{http://java.sun.com/j2se/1.4.2/docs/tooldocs/javadoc/taglet/overview.html}}
+ {{http://java.sun.com/j2se/1.4.2/docs/tooldocs/javadoc/taglet/overview.html}}.
 
-* One taglet
+* One Taglet
+
+ For one known Taglet, just use the \<taglet/\> element:
 
 +-----+
 <project>
@@ -63,7 +65,9 @@
 </project>
 +-----+
 
-* Several taglets
+* Several Taglets
+
+ For several known Taglets, just use the \<taglets/\> element:
 
 +-----+
 <project>
@@ -77,15 +81,102 @@
           ...
           <taglets>
             <taglet>
-              <tagletClass>package.to.YourTagletClass</tagletClass>
+              <tagletClass>package.to.YourFirstTagletClass</tagletClass>
+              <!-- <tagletpath>/path/to/taglet.jar</tagletpath> -->
+              <tagletArtifact>
+                <groupId>group-FirstTaglet</groupId>
+                <artifactId>artifact-FirstTaglet</artifactId>
+                <version>version-FirstTaglet</version>
+              </tagletArtifact>
+            </taglet>
+
+            <taglet>
+              <tagletClass>package.to.YourSecondTagletClass</tagletClass>
               <!-- <tagletpath>/path/to/taglet.jar</tagletpath> -->
               <tagletArtifact>
-                <groupId>group-Taglet</groupId>
-                <artifactId>artifact-Taglet</artifactId>
-                <version>version-Taglet</version>
+                <groupId>group-SecondTaglet</groupId>
+                <artifactId>artifact-SecondTaglet</artifactId>
+                <version>version-SecondTaglet</version>
               </tagletArtifact>
             </taglet>
+            ...
+          </taglets>
+          ...
+        </configuration>
+      </plugin>
+    </plugins>
+    ...
+  </reporting>
+  ...
+</project>
++-----+
+
+ If it is several Taglets in the same Taglet artifact, you could use the \<taglets/\>
and the \<tagletArtifact/\>
+ elements:
+
++-----+
+<project>
+  ...
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <configuration>
+          ...
+          <taglets>
+            <taglet>
+              <tagletClass>package.to.YourFirstTagletClass</tagletClass>
+            </taglet>
+
+            <taglet>
+              <tagletClass>package.to.YourSecondTagletClass</tagletClass>
+            </taglet>
+            ...
           </taglets>
+
+          <tagletArtifact>
+            <groupId>group-Taglet</groupId>
+            <artifactId>artifact-Taglet</artifactId>
+            <version>version-Taglet</version>
+          </tagletArtifact>
+          ...
+        </configuration>
+      </plugin>
+    </plugins>
+    ...
+  </reporting>
+  ...
+</project>
++-----+
+
+ If you don't know the Taglets or if you want to auto-detect Taglet class names, you could
use the
+ \<tagletArtifacts/\> element:
+
++-----+
+<project>
+  ...
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <configuration>
+          ...
+          <tagletArtifacts>
+            <tagletArtifact>
+              <groupId>group-FirstTaglet</groupId>
+              <artifactId>artifact-FirstTaglet</artifactId>
+              <version>version-FirstTaglet</version>
+            </tagletArtifact>
+
+            <tagletArtifact>
+              <groupId>group-SecondTaglet</groupId>
+              <artifactId>artifact-SecondTaglet</artifactId>
+              <version>version-SecondTaglet</version>
+            </tagletArtifact>
+            ...
+          </tagletArtifacts>
           ...
         </configuration>
       </plugin>
@@ -95,3 +186,4 @@
   ...
 </project>
 +-----+
+

Modified: maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java?rev=679984&r1=679983&r2=679984&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java
(original)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/JavadocReportTest.java
Sat Jul 26 05:16:33 2008
@@ -28,6 +28,7 @@
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
@@ -929,4 +930,48 @@
             assertTrue( "Not conflict catch", e.getMessage().indexOf( "Option <nohelp/>
conflicts with <helpfile/>" ) != -1 );
         }
     }
+
+    /**
+     * Method to test the <code>&lt;tagletArtifacts/&gt;</code> parameter.
+     *
+     * @throws Exception if any
+     */
+    public void testTagletArtifacts()
+        throws Exception
+    {
+        File testPom =
+            new File( getBasedir(),
+                      "src/test/resources/unit/tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml"
);
+        JavadocReport mojo = (JavadocReport) lookupMojo( "javadoc", testPom );
+
+        setVariableValueToObject( mojo, "remoteRepositories", mojo.project.getRemoteArtifactRepositories()
);
+
+        mojo.execute();
+
+        File optionsFile = new File( mojo.getOutputDirectory(), "options" );
+        assertTrue( optionsFile.exists() );
+        String options = readFile( optionsFile );
+        // count -taglet
+        assertEquals( StringUtils.countMatches( options, LINE_SEPARATOR + "-taglet" + LINE_SEPARATOR
), 20 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoAggregatorTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoComponentFieldTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoConfiguratorTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoExecuteTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoExecutionStrategyTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoGoalTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoInheritByDefaultTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoInstantiationStrategyTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoParameterFieldTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoPhaseTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoReadOnlyFieldTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDependencyResolutionTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresDirectInvocationTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresOnLineTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresProjectTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.apache.maven.tools.plugin.javadoc.MojoRequiresReportsTypeTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.codehaus.plexus.javadoc.PlexusConfigurationTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.codehaus.plexus.javadoc.PlexusRequirementTaglet"
) != -1 );
+        assertTrue( options.indexOf( "org.codehaus.plexus.javadoc.PlexusComponentTaglet"
) != -1 );
+    }
 }

Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/TagletArtifactsMavenProjectStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/TagletArtifactsMavenProjectStub.java?rev=679984&view=auto
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/TagletArtifactsMavenProjectStub.java
(added)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/TagletArtifactsMavenProjectStub.java
Sat Jul 26 05:16:33 2008
@@ -0,0 +1,111 @@
+package org.apache.maven.plugin.javadoc.stubs;
+
+/*
+ * 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.FileReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.DefaultArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+
+/**
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class TagletArtifactsMavenProjectStub
+    extends MavenProjectStub
+{
+    private Build build;
+
+    /**
+     * Default constructor.
+     */
+    public TagletArtifactsMavenProjectStub()
+    {
+        MavenXpp3Reader pomReader = new MavenXpp3Reader();
+        Model model = null;
+
+        try
+        {
+            model =
+                pomReader.read( new FileReader( new File( getBasedir(), "tagletArtifacts-test-plugin-config.xml"
) ) );
+            setModel( model );
+        }
+        catch ( Exception e )
+        {
+            throw new RuntimeException( e );
+        }
+
+        setGroupId( model.getGroupId() );
+        setArtifactId( model.getArtifactId() );
+        setVersion( model.getVersion() );
+        setName( model.getName() );
+        setUrl( model.getUrl() );
+        setPackaging( model.getPackaging() );
+
+        Build build = new Build();
+        build.setFinalName( model.getArtifactId() );
+        build.setSourceDirectory( getBasedir() + "/src/main/java" );
+        build.setDirectory( super.getBasedir() + "/target/test/unit/tagletArtifacts-test/target"
);
+        setBuild( build );
+
+        List compileSourceRoots = new ArrayList();
+        compileSourceRoots.add( getBasedir() + "/src/main/java" );
+        setCompileSourceRoots( compileSourceRoots );
+    }
+
+    /** {@inheritDoc} */
+    public Build getBuild()
+    {
+        return build;
+    }
+
+    /** {@inheritDoc} */
+    public void setBuild( Build build )
+    {
+        this.build = build;
+    }
+
+    /** {@inheritDoc} */
+    public List getRemoteArtifactRepositories()
+    {
+        ArtifactRepository repository =
+            new DefaultArtifactRepository( "central", "http://repo1.maven.org/maven2",
+                                           new DefaultRepositoryLayout() );
+
+        return Collections.singletonList( repository );
+    }
+
+    /**
+     * @see org.apache.maven.plugin.testing.stubs.MavenProjectStub#getBasedir()
+     */
+    public File getBasedir()
+    {
+        return new File( super.getBasedir() + "/src/test/resources/unit/tagletArtifacts-test"
);
+    }
+}

Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/TagletArtifactsMavenProjectStub.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/java/org/apache/maven/plugin/javadoc/stubs/TagletArtifactsMavenProjectStub.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/src/main/java/test/App.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/src/main/java/test/App.java?rev=679984&view=auto
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/src/main/java/test/App.java
(added)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/src/main/java/test/App.java
Sat Jul 26 05:16:33 2008
@@ -0,0 +1,48 @@
+package test;
+
+/*
+ * 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.
+ */
+
+/**
+ * Sample class inside the package to be included in the javadoc
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ */
+public class App
+{
+    /**
+     * The main method
+     *
+     * @param args  an array of strings that contains the arguments
+     */
+    public static void main( String[] args )
+    {
+        System.out.println( "Sample Application." );
+    }
+
+    /**
+     * Sample method that prints out the parameter string.
+     *
+     * @param str   The string value to be printed.
+     */
+    protected void sampleMethod( String str )
+    {
+        System.out.println( str );
+    }
+}

Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/src/main/java/test/App.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/src/main/java/test/App.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml?rev=679984&view=auto
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml
(added)
+++ maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml
Sat Jul 26 05:16:33 2008
@@ -0,0 +1,84 @@
+<!--
+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.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>def.configuration</groupId>
+  <artifactId>default-configuration</artifactId>
+  <packaging>jar</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <inceptionYear>2006</inceptionYear>
+  <name>Maven Javadoc Plugin Default Configuration Test</name>
+  <url>http://maven.apache.org</url>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <configuration>
+          <project implementation="org.apache.maven.plugin.javadoc.stubs.TagletArtifactsMavenProjectStub"/>
+          <localRepository>${localRepository}</localRepository>
+          <outputDirectory>${basedir}/target/test/unit/tagletArtifacts-test/target/site/apidocs</outputDirectory>
+          <breakiterator>false</breakiterator>
+          <old>false</old>
+          <show>protected</show>
+          <quiet>true</quiet>
+          <verbose>false</verbose>
+          <author>true</author>
+          <charset>ISO-8859-1</charset>
+          <docfilessubdirs>false</docfilessubdirs>
+          <linksource>false</linksource>
+          <nocomment>false</nocomment>
+          <nodeprecated>false</nodeprecated>
+          <nodeprecatedlist>false</nodeprecatedlist>
+          <nohelp>false</nohelp>
+          <noindex>false</noindex>
+          <nonavbar>false</nonavbar>
+          <nosince>false</nosince>
+          <notree>false</notree>
+          <serialwarn>false</serialwarn>
+          <splitindex>false</splitindex>
+          <stylesheet>java</stylesheet>
+          <groups/>
+          <tags/>
+          <use>true</use>
+          <version>true</version>
+          <windowtitle>Maven Javadoc Plugin Default configuration Test 1.0-SNAPSHOT
API</windowtitle>
+          <links>
+             <param>http://java.sun.com/j2se/1.4.2/docs/api</param>
+          </links>
+          <debug>true</debug>
+          <failOnError>true</failOnError>
+          <tagletArtifacts>
+            <tagletArtifact>
+              <groupId>org.apache.maven.plugin-tools</groupId>
+              <artifactId>maven-plugin-tools-javadoc</artifactId>
+              <version>2.4.2</version>
+            </tagletArtifact>
+            <tagletArtifact>
+              <groupId>org.codehaus.plexus</groupId>
+              <artifactId>plexus-javadoc</artifactId>
+              <version>1.0</version>
+            </tagletArtifact>
+          </tagletArtifacts>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-javadoc-plugin/src/test/resources/unit/tagletArtifacts-test/tagletArtifacts-test-plugin-config.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message