Author: mkleint
Date: Fri Apr 18 03:05:32 2008
New Revision: 649443

URL: http://svn.apache.org/viewvc?rev=649443&view=rev
Log:
MNG-468 add toolchains support to the javadoc plugin. It recoginizes the "jdk" 
toolchain now. 

Modified:
    maven/plugins/trunk/maven-javadoc-plugin/pom.xml
    
maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java

Modified: maven/plugins/trunk/maven-javadoc-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/pom.xml?rev=649443&r1=649442&r2=649443&view=diff
==============================================================================
--- maven/plugins/trunk/maven-javadoc-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-javadoc-plugin/pom.xml Fri Apr 18 03:05:32 2008
@@ -166,6 +166,18 @@
       </exclusions>
     </dependency>
     <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-toolchain</artifactId>
+      <version>1.0</version>
+      <exclusions>
+        <!-- Using org.codehaus.plexus:plexus-utils instead of -->
+        <exclusion>
+          <groupId>plexus</groupId>
+          <artifactId>plexus-utils</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
       <version>1.4.6</version>

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=649443&r1=649442&r2=649443&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
 Fri Apr 18 03:05:32 2008
@@ -54,6 +54,7 @@
 import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
 import org.apache.maven.artifact.versioning.ArtifactVersion;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
+import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.javadoc.options.DocletArtifact;
 import org.apache.maven.plugin.javadoc.options.Group;
@@ -67,7 +68,10 @@
 import org.apache.maven.reporting.MavenReportException;
 import org.apache.maven.settings.Proxy;
 import org.apache.maven.settings.Settings;
+import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.ToolchainManager;
 import org.apache.maven.wagon.PathUtils;
+import 
org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.ReaderFactory;
@@ -90,6 +94,16 @@
     extends AbstractMojo
 {
     /**
+     * The current build session instance. This is used for
+     * toolchain manager API calls.
+     *
+     * @parameter expression="${session}"
+     * @required
+     * @readonly
+     */
+    private MavenSession session;
+
+    /**
      * The current class directory
      */
     private static final String RESOURCE_DIR = ClassUtils.getPackageName( 
JavadocReport.class ).replace( '.', '/' );
@@ -1916,6 +1930,28 @@
         return StringUtils.join( classpathElements.iterator(), 
File.pathSeparator );
     }
 
+    
+    //TODO remove the part with ToolchainManager lookup once we depend on
+    //3.0.9 (have it as prerequisite). Define as regular component field then.
+    private Toolchain getToolchain() 
+    {
+        Toolchain tc = null;
+        try 
+        {
+            if (session != null) //session is null in tests..
+            {
+                ToolchainManager toolchainManager = (ToolchainManager) 
session.getContainer().lookup(ToolchainManager.ROLE);
+                if (toolchainManager != null) 
+                {
+                    tc = toolchainManager.getToolchainFromBuildContext("jdk", 
session);
+                }
+            }
+        } catch (ComponentLookupException componentLookupException) {
+            //just ignore, could happen in pre-3.0.9 builds..
+        }
+        return tc;
+    }
+
     /**
      * Method to put the artifacts in the hashmap.
      *
@@ -2336,6 +2372,21 @@
     private String getJavadocExecutable()
         throws IOException
     {
+        Toolchain tc = getToolchain();
+        
+        if ( tc != null )
+        {
+            getLog().info( "Toolchain in javadoc-plugin: " + tc );
+            if ( javadocExecutable  != null) 
+            { 
+                getLog().warn( "Toolchains are ignored, 'javadocExecutable' 
parameter is set to " + javadocExecutable );
+            } 
+            else 
+            {
+                javadocExecutable = tc.findTool( "javadoc" ); //NOI18N
+            }
+        }
+        
         String javadocCommand = "javadoc" + ( SystemUtils.IS_OS_WINDOWS ? 
".exe" : "" );
 
         File javadocExe;


Reply via email to