You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2016/09/26 21:37:39 UTC

svn commit: r1762385 - in /maven/plugins/trunk/maven-compiler-plugin/src: it/MCOMPILER-275_separate-moduleinfo/pom.xml main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

Author: rfscholte
Date: Mon Sep 26 21:37:38 2016
New Revision: 1762385

URL: http://svn.apache.org/viewvc?rev=1762385&view=rev
Log:
[MCOMPILER-269] Support modulepath (Java9/Jigsaw)
Add custom jdkToolchain, required when building module-info.java ( requires java9 ) while other sources have a lower target (e.g. 1.5) 

Modified:
    maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/pom.xml
    maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

Modified: maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/pom.xml?rev=1762385&r1=1762384&r2=1762385&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/pom.xml (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/MCOMPILER-275_separate-moduleinfo/pom.xml Mon Sep 26 21:37:38 2016
@@ -72,7 +72,6 @@
               <jdkToolchain>
                 <version>9</version>
               </jdkToolchain>
-              <fork>true</fork>
               <release>9</release>
             </configuration>
           </execution>

Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java?rev=1762385&r1=1762384&r2=1762385&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java Mon Sep 26 21:37:38 2016
@@ -20,6 +20,7 @@ package org.apache.maven.plugin.compiler
  */
 
 import java.io.File;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Date;
@@ -351,6 +352,12 @@ public abstract class AbstractCompilerMo
     @Component
     private ToolchainManager toolchainManager;
 
+    /**
+     * Specify the requirements for this jdk toolchain
+     */
+    @Parameter
+    private Map<String, String> jdkToolchain;
+
     // ----------------------------------------------------------------------
     // Read-only parameters
     // ----------------------------------------------------------------------
@@ -1201,10 +1208,53 @@ public abstract class AbstractCompilerMo
     private Toolchain getToolchain()
     {
         Toolchain tc = null;
-        if ( toolchainManager != null )
+        
+        if ( jdkToolchain != null )
+        {
+            // Maven 3.2.6 has plugin execution scoped Toolchain Support
+            try
+            {
+                Method getToolchainsMethod =
+                    toolchainManager.getClass().getMethod( "getToolchains", MavenSession.class, String.class,
+                                                           Map.class );
+
+                @SuppressWarnings( "unchecked" )
+                List<Toolchain> tcs =
+                    (List<Toolchain>) getToolchainsMethod.invoke( toolchainManager, session, "jdk",
+                                                                  jdkToolchain );
+
+                if ( tcs != null && tcs.size() > 0 )
+                {
+                    tc = tcs.get( tcs.size() - 1 );
+                }
+            }
+            catch ( NoSuchMethodException e )
+            {
+                // ignore
+            }
+            catch ( SecurityException e )
+            {
+                // ignore
+            }
+            catch ( IllegalAccessException e )
+            {
+                // ignore
+            }
+            catch ( IllegalArgumentException e )
+            {
+                // ignore
+            }
+            catch ( InvocationTargetException e )
+            {
+                // ignore
+            }
+        }
+        
+        if ( tc == null )
         {
             tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );
         }
+        
         return tc;
     }