You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2016/07/08 22:32:00 UTC

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

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.



Re: 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

Posted by Hervé BOUTEMY <he...@free.fr>.
when they will upgrade their dependency version, they'll recompile: I don't 
really know where (if) this code is used, but I don't expect to get binary 
compatibility issues in real life on this

yes, probably moving this whole cli/javatool somewhere else would be a better 
choice: but I don't know where. And since I don't know where this code is 
used, I'm just doing the work to be able to release a maven-shared-utils that 
can be used in Maven core

But if you know how to move the code, don't hesitate to do so: now that I took 
time to really discover it, I'm sure it should not have landed here, or it 
should have been written in another way

Regards,

Hervé

Le samedi 9 juillet 2016 13:47:51 Robert Scholte a écrit :
> Hi Hervé,
> 
> This will already break backwards compatibility because the signature has
> changed. In other words: projects using this method need to be recompiled;
> they can't simply switch to this version.
> So is it worth keeping this piece of code here?
> 
> Robert
> 
> On Sat, 09 Jul 2016 00:32:00 +0200, <hb...@apache.org> wrote:
> > ---
> > maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/share
> > d/utils/cli/javatool/JavaTool.java (original)
> > +++
> > maven/shared/trunk/maven-shared-utils/src/main/java/org/apache/maven/share
> > d/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.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
> For additional commands, e-mail: dev-help@maven.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org


Re: 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

Posted by Robert Scholte <rf...@apache.org>.
Hi Hervé,

This will already break backwards compatibility because the signature has  
changed. In other words: projects using this method need to be recompiled;  
they can't simply switch to this version.
So is it worth keeping this piece of code here?

Robert


On Sat, 09 Jul 2016 00:32:00 +0200, <hb...@apache.org> wrote:

> ---  
> 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.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org