maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject svn commit: r1751975 - in /maven/shared/trunk/maven-shared-utils: pom.xml src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java
Date Fri, 08 Jul 2016 22:32:00 GMT
Author: hboutemy
Date: Fri Jul  8 22:32:00 2016
New Revision: 1751975

URL: http://svn.apache.org/viewvc?rev=1751975&view=rev
Log:
[MSHARED-567] removed compile dependency on Maven core (and discovered hard dependency on
Plexus Container)

Modified:
    maven/shared/trunk/maven-shared-utils/pom.xml
    maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java
    maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java

Modified: maven/shared/trunk/maven-shared-utils/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/pom.xml?rev=1751975&r1=1751974&r2=1751975&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/pom.xml (original)
+++ maven/shared/trunk/maven-shared-utils/pom.xml Fri Jul  8 22:32:00 2016
@@ -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>

Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java?rev=1751975&r1=1751974&r2=1751975&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java
(original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java
Fri Jul  8 22:32:00 2016
@@ -25,11 +25,12 @@ import org.apache.maven.shared.utils.cli
 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 @@ public abstract class AbstractJavaTool<R
     /**
      * 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 @@ public abstract class AbstractJavaTool<R
     /**
      * {@inheritDoc}
      */
-    public void setToolchain( Toolchain toolchain )
+    public void setToolchain( Object toolchain )
     {
         this.toolchain = toolchain;
     }
@@ -249,15 +250,15 @@ public abstract class AbstractJavaTool<R
      */
     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 @@ public abstract class AbstractJavaTool<R
     }
 
     /**
+     * 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>.

Modified: maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java?rev=1751975&r1=1751974&r2=1751975&view=diff
==============================================================================
--- maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java
(original)
+++ maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java
Fri Jul  8 22:32:00 2016
@@ -19,8 +19,6 @@ package org.apache.maven.shared.utils.cl
  * 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 @@ public interface JavaTool<Request extend
      * 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.



Mime
View raw message