You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2019/06/07 13:18:47 UTC

[maven-toolchains-plugin] branch MTOOLCHAINS-15 created (now a0d3eb1)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch MTOOLCHAINS-15
in repository https://gitbox.apache.org/repos/asf/maven-toolchains-plugin.git.


      at a0d3eb1  [MTOOLCHAINS-15] remove M2 specific code

This branch includes the following new commits:

     new a0d3eb1  [MTOOLCHAINS-15] remove M2 specific code

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-toolchains-plugin] 01/01: [MTOOLCHAINS-15] remove M2 specific code

Posted by rf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MTOOLCHAINS-15
in repository https://gitbox.apache.org/repos/asf/maven-toolchains-plugin.git

commit a0d3eb13ee516c082c793990e5627a0f3d005e64
Author: rfscholte <rf...@apache.org>
AuthorDate: Fri Jun 7 15:18:40 2019 +0200

    [MTOOLCHAINS-15] remove M2 specific code
---
 pom.xml                                            | 10 ++++
 .../plugins/toolchain/ToolchainConverter.java      |  9 ++--
 .../maven/plugins/toolchain/ToolchainMojo.java     | 55 +++-------------------
 3 files changed, 20 insertions(+), 54 deletions(-)

diff --git a/pom.xml b/pom.xml
index 8198f2c..b27a39b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -92,4 +92,14 @@ under the License.
       <scope>provided</scope>
     </dependency>
   </dependencies>
+  
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jxr-plugin</artifactId>
+        <version>3.0.0</version>
+      </plugin>
+    </plugins>
+  </reporting>
 </project>
diff --git a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainConverter.java b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainConverter.java
index 0e8f108..43e2b36 100644
--- a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainConverter.java
+++ b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainConverter.java
@@ -25,7 +25,6 @@ import java.util.Map;
 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
 import org.codehaus.plexus.component.configurator.ConfigurationListener;
 import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter;
-import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter;
 import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
 import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
 import org.codehaus.plexus.configuration.PlexusConfiguration;
@@ -40,11 +39,10 @@ public class ToolchainConverter
     extends AbstractConfigurationConverter
 {
 
-    public static final String ROLE = ConfigurationConverter.class.getName();
-
     /**
      * @see org.codehaus.plexus.component.configurator.converters.ConfigurationConverter#canConvert(java.lang.Class)
      */
+    @Override
     public boolean canConvert( Class type )
     {
         return ToolchainsRequirement.class.isAssignableFrom( type );
@@ -53,6 +51,7 @@ public class ToolchainConverter
     /**
      * @see org.codehaus.plexus.component.configurator.converters.ConfigurationConverter#fromConfiguration(org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup, org.codehaus.plexus.configuration.PlexusConfiguration, java.lang.Class, java.lang.Class, java.lang.ClassLoader, org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator, org.codehaus.plexus.component.configurator.ConfigurationListener)
      */
+    @Override
     public Object fromConfiguration( ConverterLookup converterLookup,
                                      PlexusConfiguration configuration,
                                      Class type, Class baseType,
@@ -73,7 +72,7 @@ public class ToolchainConverter
                                        ExpressionEvaluator expressionEvaluator )
         throws ComponentConfigurationException
     {
-        Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
+        Map<String, Map<String, String>> map = new HashMap<>();
 
         PlexusConfiguration[] tools = configuration.getChildren();
         for ( PlexusConfiguration tool : tools )
@@ -81,7 +80,7 @@ public class ToolchainConverter
             String type = tool.getName();
             PlexusConfiguration[] params = tool.getChildren();
 
-            Map<String, String> parameters = new HashMap<String, String>();
+            Map<String, String> parameters = new HashMap<>();
             for ( PlexusConfiguration param : params )
             {
                     parameters.put( param.getName(), param.getValue() );
diff --git a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java
index fbb25be..7cef3d7 100644
--- a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java
+++ b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java
@@ -31,8 +31,6 @@ import org.apache.maven.toolchain.MisconfiguredToolchainException;
 import org.apache.maven.toolchain.ToolchainManagerPrivate;
 import org.apache.maven.toolchain.ToolchainPrivate;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -71,6 +69,7 @@ public class ToolchainMojo
     @Parameter( required = true )
     private ToolchainsRequirement toolchains;
 
+    @Override
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
@@ -81,7 +80,7 @@ public class ToolchainMojo
             return;
         }
 
-        List<String> nonMatchedTypes = new ArrayList<String>();
+        List<String> nonMatchedTypes = new ArrayList<>();
 
         for ( Map.Entry<String, Map<String, String>> entry : toolchains.getToolchains().entrySet() )
         {
@@ -101,14 +100,14 @@ public class ToolchainMojo
 
             for ( String type : nonMatchedTypes )
             {
-                buff.append( '\n' );
+                buff.append( System.lineSeparator() );
                 buff.append( getToolchainRequirementAsString( type, toolchains.getParams( type ) ) );
             }
 
             getLog().error( buff.toString() );
 
-            throw new MojoFailureException( buff.toString()
-                + "\nPlease make sure you define the required toolchains in your ~/.m2/toolchains.xml file." );
+            throw new MojoFailureException( buff.toString() + System.lineSeparator()
+                + "Please make sure you define the required toolchains in your ~/.m2/toolchains.xml file." );
         }
     }
 
@@ -181,49 +180,7 @@ public class ToolchainMojo
     private ToolchainPrivate[] getToolchains( String type )
         throws MojoExecutionException, MisconfiguredToolchainException
     {
-        Class<?> managerClass = toolchainManagerPrivate.getClass();
-
-        try
-        {
-            try
-            {
-                // try 3.x style API
-                Method newMethod =
-                    managerClass.getMethod( "getToolchainsForType", new Class[] { String.class, MavenSession.class } );
-
-                return (ToolchainPrivate[]) newMethod.invoke( toolchainManagerPrivate, type, session );
-            }
-            catch ( NoSuchMethodException e )
-            {
-                // try 2.x style API
-                Method oldMethod = managerClass.getMethod( "getToolchainsForType", new Class[] { String.class } );
-
-                return (ToolchainPrivate[]) oldMethod.invoke( toolchainManagerPrivate, 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 );
-        }
+        return toolchainManagerPrivate.getToolchainsForType( type, session );
     }
 
 }