You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mk...@apache.org on 2008/04/18 12:02:14 UTC

svn commit: r649442 - in /maven/plugins/trunk/maven-compiler-plugin: pom.xml src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java

Author: mkleint
Date: Fri Apr 18 03:02:08 2008
New Revision: 649442

URL: http://svn.apache.org/viewvc?rev=649442&view=rev
Log:
MNG-468 add toolchains support to the compiler plugin. It recoginizes the "jdk" toolchain now. bumped the required version of maven to 2.0.6. Will only actually work in conjunction with maven-toolchains-plugin in 2.0.9+, but the plugin still works without toolchains in older versions (2.0.6+)
needed to excluded the plexus api jar, as it was causing class loading exceptions..

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

Modified: maven/plugins/trunk/maven-compiler-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/pom.xml?rev=649442&r1=649441&r2=649442&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-compiler-plugin/pom.xml Fri Apr 18 03:02:08 2008
@@ -19,97 +19,119 @@
 -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <modelVersion>4.0.0</modelVersion>
+    <modelVersion>4.0.0</modelVersion>
 
-  <parent>
-    <groupId>org.apache.maven.plugins</groupId>
-    <artifactId>maven-plugins</artifactId>
+    <parent>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-plugins</artifactId>
     <version>11</version>
   </parent>
 
-  <artifactId>maven-compiler-plugin</artifactId>
-  <packaging>maven-plugin</packaging>
-  <version>2.1-SNAPSHOT</version>
-  <name>Maven Compiler Plugin</name>
-  <inceptionYear>2001</inceptionYear>
-
-  <prerequisites>
-    <maven>2.0</maven>
-  </prerequisites>
+    <artifactId>maven-compiler-plugin</artifactId>
+    <packaging>maven-plugin</packaging>
+    <version>2.1-SNAPSHOT</version>
+    <name>Maven Compiler Plugin</name>
+    <inceptionYear>2001</inceptionYear>
+
+    <prerequisites>
+        <maven>2.0.6</maven>
+    </prerequisites>
   
-  <repositories>
-    <repository>
-      <id>codehaus.snapshots</id>
-      <url>http://snapshots.repository.codehaus.org/</url>
-      <snapshots>
+    <repositories>
+        <repository>
+            <id>codehaus.snapshots</id>
+            <url>http://snapshots.repository.codehaus.org/</url>
+            <snapshots>
         <enabled>true</enabled>
-      </snapshots>
-      <releases>
-        <enabled>false</enabled>
-      </releases>
-    </repository>
-  </repositories>
-
-  <issueManagement>
-    <system>JIRA</system>
-    <url>http://jira.codehaus.org/browse/MCOMPILER</url>
-  </issueManagement>
-
-  <scm>
-    <connection>scm:svn:http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-compiler-plugin/</connection>
-    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-compiler-plugin/</developerConnection>
-    <url>http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/</url>
-  </scm>
-
-  <dependencies>
-    <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-container-default</artifactId>
-      <version>1.0-alpha-9-stable-1</version>
-      <scope>test</scope>
-    </dependency>
+            </snapshots>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+        </repository>
+    </repositories>
+
+    <issueManagement>
+        <system>JIRA</system>
+        <url>http://jira.codehaus.org/browse/MCOMPILER</url>
+    </issueManagement>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/maven/plugins/trunk/maven-compiler-plugin/</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-compiler-plugin/</developerConnection>
+        <url>http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/</url>
+    </scm>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-container-default</artifactId>
+            <version>1.0-alpha-9-stable-1</version>
+        </dependency>
     
     <!-- Maven -->
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-plugin-api</artifactId>
-      <version>2.0</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-artifact</artifactId>
-      <version>2.0</version>
-    </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-plugin-api</artifactId>
+            <version>2.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-artifact</artifactId>
+            <version>2.0</version>
+        </dependency>
 
     <!-- Plexus -->
-    <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-utils</artifactId>
-      <version>1.0.4</version>
-    </dependency>
-    <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-compiler-api</artifactId>
-      <version>1.6-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-compiler-manager</artifactId>
-      <version>1.6-SNAPSHOT</version>
-    </dependency>
-    <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-compiler-javac</artifactId>
-      <version>1.6-SNAPSHOT</version>
-      <scope>runtime</scope>
-    </dependency>
-
-    <dependency>
-      <groupId>org.apache.maven.shared</groupId>
-      <artifactId>maven-plugin-testing-harness</artifactId>
-      <version>1.1</version>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
+        <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-utils</artifactId>
+            <version>1.0.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-compiler-api</artifactId>
+            <version>1.6-SNAPSHOT</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.codehaus.plexus</groupId>
+                    <artifactId>plexus-component-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.maven</groupId>
+            <artifactId>maven-toolchain</artifactId>
+            <version>1.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-compiler-manager</artifactId>
+            <version>1.6-SNAPSHOT</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.codehaus.plexus</groupId>
+                    <artifactId>plexus-component-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>org.codehaus.plexus</groupId>
+            <artifactId>plexus-compiler-javac</artifactId>
+            <version>1.6-SNAPSHOT</version>
+            <scope>runtime</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.codehaus.plexus</groupId>
+                    <artifactId>plexus-component-api</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.maven.shared</groupId>
+            <artifactId>maven-plugin-testing-harness</artifactId>
+            <version>1.1</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 
 </project>

Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java?rev=649442&r1=649441&r2=649442&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java Fri Apr 18 03:02:08 2008
@@ -41,6 +41,10 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.toolchain.Toolchain;
+import org.apache.maven.toolchain.ToolchainManager;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 
 /**
  * TODO: At least one step could be optimized, currently the plugin will do two
@@ -254,7 +258,17 @@
      * @component
      */
     private CompilerManager compilerManager;
-
+    
+    /**
+     * The current build session instance. This is used for
+     * toolchain manager API calls.
+     *
+     * @parameter expression="${session}"
+     * @required
+     * @readonly
+     */
+    private MavenSession session;
+    
     /**
      * Gets the source file encoding.
      *
@@ -296,7 +310,24 @@
         {
             throw new MojoExecutionException( "No such compiler '" + e.getCompilerId() + "'." );
         }
-
+        
+        //-----------toolchains start here ----------------------------------
+        //use the compilerId as identifier for toolchains as well.
+        Toolchain tc = getToolchain();
+        if ( tc != null ) 
+        {
+            getLog().info( "Toolchain in compiler-plugin: " + tc );
+            if ( executable  != null ) 
+            { 
+                getLog().warn( "Toolchains are ignored, 'executable' parameter is set to " + executable );
+            } 
+            else 
+            {
+                fork = true;
+                //TODO somehow shaky dependency between compilerId and tool executable.
+                executable = tc.findTool( compilerId );
+            }
+        }
         // ----------------------------------------------------------------------
         //
         // ----------------------------------------------------------------------
@@ -600,6 +631,27 @@
             }
         }
         return value;
+    }
+
+    //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;
     }
 
     private boolean isDigits( String string )