Author: bentmann
Date: Sun Aug 9 22:06:34 2009
New Revision: 802617
URL: http://svn.apache.org/viewvc?rev=802617&view=rev
Log:
[MNG-4287] Make ToolchainManagerPrivate session-aware
o Updated plugin to support both 2.x and 3.x style API
Modified:
maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainMojo.java
Modified:
maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainMojo.java
URL:
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainMojo.java?rev=802617&r1=802616&r2=802617&view=diff
==============================================================================
---
maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainMojo.java
(original)
+++
maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainMojo.java
Sun Aug 9 22:06:34 2009
@@ -19,6 +19,8 @@
* under the License.
*/
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -82,7 +84,7 @@
String type = (String) en.next();
getLog().info( "Type:" + type );
Map params = toolchains.getParams( type );
- ToolchainPrivate[] tcs =
toolchainManager.getToolchainsForType( type );
+ ToolchainPrivate[] tcs = getToolchains( type );
boolean matched = false;
for ( int i = 0; i < tcs.length; i++ )
{
@@ -130,7 +132,7 @@
}
getLog().error( buff.toString() );
throw new MojoFailureException( buff.toString()
- + "\nPlease make sure you define the required
toolchains in your ~/.m2/toolchains.xml file." );
+ + "\nPlease make sure you define the required toolchains
in your ~/.m2/toolchains.xml file." );
}
}
else
@@ -139,4 +141,52 @@
}
}
-}
\ No newline at end of file
+ private ToolchainPrivate[] getToolchains( String type )
+ throws MojoExecutionException, MisconfiguredToolchainException
+ {
+ Class managerClass = toolchainManager.getClass();
+
+ try
+ {
+ try
+ {
+ // 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 )
+ {
+ // 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 )
+ {
+ throw new MojoExecutionException( "Incompatible toolchain API", e
);
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new MojoExecutionException( "Incompatible toolchain API", e
);
+ }
+ catch ( InvocationTargetException e )
+ {
+ Throwable cause = e.getCause();
+
+ if ( cause instanceof RuntimeException )
+ {
+ throw (RuntimeException) cause;
+ }
+ if ( cause instanceof MisconfiguredToolchainException )
+ {
+ throw (MisconfiguredToolchainException) cause;
+ }
+
+ throw new MojoExecutionException( "Incompatible toolchain API", e
);
+ }
+ }
+
+}