You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/08/07 17:16:59 UTC

svn commit: r802042 - /maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java

Author: bentmann
Date: Fri Aug  7 15:16:59 2009
New Revision: 802042

URL: http://svn.apache.org/viewvc?rev=802042&view=rev
Log:
[MNG-4287] Make ToolchainManagerPrivate session-aware

o Updated IT plugin to account for API differences

Modified:
    maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java

Modified: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java?rev=802042&r1=802041&r2=802042&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java (original)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-toolchain/src/main/java/org/apache/maven/plugin/coreit/CoreItMojo.java Fri Aug  7 15:16:59 2009
@@ -23,6 +23,8 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.Properties;
@@ -87,15 +89,7 @@
     public void execute()
         throws MojoExecutionException
     {
-        ToolchainPrivate[] tcs;
-        try
-        {
-            tcs = toolchainManager.getToolchainsForType( type );
-        }
-        catch ( MisconfiguredToolchainException e )
-        {
-            throw new MojoExecutionException( e.getMessage(), e );
-        }
+        ToolchainPrivate[] tcs = getToolchains();
 
         getLog().info( "[MAVEN-CORE-IT-LOG] Toolchains in plugin: " + Arrays.asList( tcs ) );
 
@@ -145,4 +139,42 @@
             }
         }
     }
+
+    private ToolchainPrivate[] getToolchains()
+        throws MojoExecutionException
+    {
+        Class managerClass = toolchainManager.getClass();
+
+        try
+        {
+            try
+            {
+                // try 2.x style API
+                Method oldMethod = managerClass.getMethod( "getToolchainsForType", new Class[] { String.class } );
+
+                return (ToolchainPrivate[]) oldMethod.invoke( toolchainManager, new Object[] { type } );
+            }
+            catch ( NoSuchMethodException e )
+            {
+                // try 3.x style API
+                Method newMethod =
+                    managerClass.getMethod( "getToolchainsForType", new Class[] { String.class, MavenSession.class } );
+
+                return (ToolchainPrivate[]) newMethod.invoke( toolchainManager, new Object[] { type, session } );
+            }
+        }
+        catch ( NoSuchMethodException e )
+        {
+            throw new MojoExecutionException( "Incompatible toolchain API", e );
+        }
+        catch ( IllegalAccessException e )
+        {
+            throw new MojoExecutionException( "Incompatible toolchain API", e );
+        }
+        catch ( InvocationTargetException e )
+        {
+            throw new MojoExecutionException( "Incompatible toolchain API", e );
+        }
+    }
+
 }