[MSHARED-567] removed compile dependency on Maven core (and discovered hard dependency on Plexus Container)
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1751975 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 5921cff..f98ad7d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -97,13 +97,18 @@
<scope>provided</scope>
</dependency>
<!--
- ! Maven Core is used in context with Maven cause
- ! it is needed for Toolchain access.
+ ! Maven Core was used in context with Maven cause for Toolchain access: avoided through reflection.
-->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ <version>1.0-alpha-9-stable-1</version>
<scope>provided</scope>
</dependency>
<dependency>
diff --git a/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java b/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java
index ab92bdf..09b33f0 100644
--- a/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java
+++ b/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java
@@ -25,11 +25,12 @@
import org.apache.maven.shared.utils.cli.CommandLineUtils;
import org.apache.maven.shared.utils.cli.Commandline;
import org.apache.maven.shared.utils.cli.StreamConsumer;
-import org.apache.maven.toolchain.Toolchain;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import java.io.File;
import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.Map;
/**
@@ -57,7 +58,7 @@
/**
* Optional toolChain used to find java tool executable file.
*/
- private Toolchain toolchain;
+ private Object toolchain;
/**
* @param javaToolName The name of the java tool.
@@ -89,7 +90,7 @@
/**
* {@inheritDoc}
*/
- public void setToolchain( Toolchain toolchain )
+ public void setToolchain( Object toolchain )
{
this.toolchain = toolchain;
}
@@ -249,15 +250,15 @@
*/
protected String findJavaToolExecutable()
{
- String command = javaToolName + ( Os.isFamily( Os.FAMILY_WINDOWS ) ? ".exe" : "" );
-
String executable = null;
if ( toolchain != null )
{
- executable = toolchain.findTool( javaToolName );
+ executable = findToolchainExecutable();
}
+ String command = javaToolName + ( Os.isFamily( Os.FAMILY_WINDOWS ) ? ".exe" : "" );
+
if ( executable == null )
{
executable = findExecutable( command, System.getProperty( "java.home" ), "../bin", "bin", "../sh" );
@@ -289,6 +290,45 @@
}
/**
+ * Run toolchain.findTool( javaToolName ); through reflection to avoid compile dependency on
+ * Maven core.
+ */
+ private String findToolchainExecutable()
+ {
+ try
+ {
+ Method m = toolchain.getClass().getMethod( "findTool", String.class );
+ return (String) m.invoke( toolchain, javaToolName );
+ }
+ catch ( NoSuchMethodException e )
+ {
+ // should not happen if toolchain is really a Toolchain object
+ getLogger().warn( "unexpected NoSuchMethodException", e );
+ }
+ catch ( SecurityException e )
+ {
+ // should not happen
+ getLogger().warn( "unexpected SecurityException", e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ // should not happen
+ getLogger().warn( "unexpected IllegalAccessException", e );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ // should not happen: parameter is the right type
+ getLogger().warn( "unexpected IllegalArgumentException", e );
+ }
+ catch ( InvocationTargetException e )
+ {
+ // not expected...
+ getLogger().warn( "unexpected InvocationTargetException", e );
+ }
+ return null;
+ }
+
+ /**
* Finds the specified command in any of the given sub directories of the specified JDK/JRE home directory.
*
* @param command The command to find, must not be <code>null</code>.
diff --git a/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java b/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java
index fe226f6..b4bc3a9 100644
--- a/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java
+++ b/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java
@@ -19,8 +19,6 @@
* under the License.
*/
-import org.apache.maven.toolchain.Toolchain;
-
/**
* Describes a java tool, means a executable available in the jdk.
* <p/>
@@ -51,8 +49,10 @@
* Set an optional tool chain to find out the java tool executable location.
*
* @param toolchain optional tool chain to find out the java tool executable location.
+ * To avoid direct dependency on Maven core, this parameter is an Object that will be
+ * used as Toolchain through reflection
*/
- void setToolchain( Toolchain toolchain );
+ void setToolchain( Object toolchain );
/**
* Execute the input request and then returns the result of the execution.