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 2014/10/31 23:37:12 UTC
svn commit: r1635873 - in
/maven/plugins/trunk/maven-toolchains-plugin/src/main:
java/org/apache/maven/plugin/toolchain/ resources/META-INF/plexus/
Author: hboutemy
Date: Fri Oct 31 22:37:11 2014
New Revision: 1635873
URL: http://svn.apache.org/r1635873
Log:
[MTOOLCHAINS-8] improved code and javadoc
Added:
maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainsRequirement.java
- copied, changed from r1635871, maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/Toolchains.java
Removed:
maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/Toolchains.java
Modified:
maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainConverter.java
maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainMojo.java
maven/plugins/trunk/maven-toolchains-plugin/src/main/resources/META-INF/plexus/components.xml
Modified: maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainConverter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainConverter.java?rev=1635873&r1=1635872&r2=1635873&view=diff
==============================================================================
--- maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainConverter.java (original)
+++ maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainConverter.java Fri Oct 31 22:37:11 2014
@@ -32,9 +32,10 @@ import org.codehaus.plexus.configuration
import org.codehaus.plexus.configuration.PlexusConfigurationException;
/**
- * Plexus ConfigurationConverter
+ * Custom Plexus ConfigurationConverter to instantiate <code>ToolchainRequirement</code> from configuration.
*
* @author mkleint
+ * @see ToolchainsRequirement
*/
public class ToolchainConverter
extends AbstractConfigurationConverter
@@ -47,7 +48,7 @@ public class ToolchainConverter
*/
public boolean canConvert( Class type )
{
- return Toolchains.class.isAssignableFrom( type );
+ return ToolchainsRequirement.class.isAssignableFrom( type );
}
/**
@@ -61,14 +62,14 @@ public class ToolchainConverter
ConfigurationListener listener )
throws ComponentConfigurationException
{
- Toolchains retValue = new Toolchains();
+ ToolchainsRequirement retValue = new ToolchainsRequirement();
processConfiguration( retValue, configuration, expressionEvaluator );
return retValue;
}
- private void processConfiguration( Toolchains chain,
+ private void processConfiguration( ToolchainsRequirement requirement,
PlexusConfiguration configuration,
ExpressionEvaluator expressionEvaluator )
throws ComponentConfigurationException
@@ -96,6 +97,6 @@ public class ToolchainConverter
map.put( type, parameters );
}
- chain.toolchains = map;
+ requirement.toolchains = map;
}
}
\ No newline at end of file
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=1635873&r1=1635872&r2=1635873&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 Fri Oct 31 22:37:11 2014
@@ -38,9 +38,13 @@ import java.util.List;
import java.util.Map;
/**
+ * Check that toolchains requirements are met by currently configured toolchains and
+ * store the selected toolchains in build context for later retrieval by other plugins.
+ *
* @author mkleint
*/
-@Mojo( name = "toolchain", defaultPhase = LifecyclePhase.VALIDATE, configurator = "override" )
+@Mojo( name = "toolchain", defaultPhase = LifecyclePhase.VALIDATE,
+ configurator = "toolchains-requirement-configurator" )
public class ToolchainMojo
extends AbstractMojo
{
@@ -51,20 +55,21 @@ public class ToolchainMojo
private ToolchainManagerPrivate toolchainManagerPrivate;
/**
- * The current build session instance. This is used for
- * toolchain manager API calls.
+ * The current build session instance. This is used for toolchain manager API calls.
*/
@Parameter( defaultValue = "${session}", readonly = true, required = true )
private MavenSession session;
/**
+ * Toolchains requirements, specified by one
+ * <pre> <toolchain-type>
+ * <param>expected value</param>
+ * ...
+ * </toolchain-type></pre>
+ * element for each required toolchain.
*/
@Parameter( required = true )
- private Toolchains toolchains;
-
- public ToolchainMojo()
- {
- }
+ private ToolchainsRequirement toolchains;
public void execute()
throws MojoExecutionException, MojoFailureException
@@ -80,36 +85,11 @@ public class ToolchainMojo
for ( Map.Entry<String, Map<String, String>> entry : toolchains.getToolchains().entrySet() )
{
- try
- {
- String type = entry.getKey();
- Map<String, String> params = entry.getValue();
-
- getLog().info( "Type:" + type );
- ToolchainPrivate[] tcs = getToolchains( type );
-
- boolean matched = false;
- for ( ToolchainPrivate tc : tcs )
- {
- if ( tc.matchesRequirements( params ) )
- {
- getLog().info( "Toolchain (" + type + ") matched: " + tc );
+ String type = entry.getKey();
- toolchainManagerPrivate.storeToolchainToBuildContext( tc, session );
-
- matched = true;
- break;
- }
- }
-
- if ( !matched )
- {
- nonMatchedTypes.add( type );
- }
- }
- catch ( MisconfiguredToolchainException ex )
+ if ( !selectToolchain( type, entry.getValue() ) )
{
- throw new MojoExecutionException( "Misconfigured toolchains.", ex );
+ nonMatchedTypes.add( type );
}
}
@@ -146,6 +126,36 @@ public class ToolchainMojo
}
}
+ protected boolean selectToolchain( String type, Map<String, String> params )
+ throws MojoExecutionException
+ {
+ getLog().info( "Required toolchain type:" + type );
+
+ try
+ {
+ ToolchainPrivate[] tcs = getToolchains( type );
+
+ for ( ToolchainPrivate tc : tcs )
+ {
+ if ( tc.matchesRequirements( params ) )
+ {
+ getLog().info( "Toolchain (" + type + ") matched: " + tc );
+
+ // store matching toolchain to build context
+ toolchainManagerPrivate.storeToolchainToBuildContext( tc, session );
+
+ return true;
+ }
+ }
+ }
+ catch ( MisconfiguredToolchainException ex )
+ {
+ throw new MojoExecutionException( "Misconfigured toolchains.", ex );
+ }
+
+ return false;
+ }
+
private ToolchainPrivate[] getToolchains( String type )
throws MojoExecutionException, MisconfiguredToolchainException
{
Copied: maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainsRequirement.java (from r1635871, maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/Toolchains.java)
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainsRequirement.java?p2=maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainsRequirement.java&p1=maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/Toolchains.java&r1=1635871&r2=1635873&rev=1635873&view=diff
==============================================================================
--- maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/Toolchains.java (original)
+++ maven/plugins/trunk/maven-toolchains-plugin/src/main/java/org/apache/maven/plugin/toolchain/ToolchainsRequirement.java Fri Oct 31 22:37:11 2014
@@ -24,11 +24,12 @@ import java.util.Map;
import java.util.Set;
/**
- * Type for plugins's <code>toolchain</code> attribute.
+ * Type for plugin's <code>toolchain</code> attribute representing toolchains requirements.
*
* @author mkleint
+ * @see ToolchainConverter the custom Plexus converter to instantiate this class
*/
-public final class Toolchains
+public final class ToolchainsRequirement
{
Map<String, Map<String, String>> toolchains;
Modified: maven/plugins/trunk/maven-toolchains-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-toolchains-plugin/src/main/resources/META-INF/plexus/components.xml?rev=1635873&r1=1635872&r2=1635873&view=diff
==============================================================================
--- maven/plugins/trunk/maven-toolchains-plugin/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/plugins/trunk/maven-toolchains-plugin/src/main/resources/META-INF/plexus/components.xml Fri Oct 31 22:37:11 2014
@@ -21,24 +21,24 @@ under the License.
<components>
<component>
<role>org.codehaus.plexus.component.configurator.ComponentConfigurator</role>
- <role-hint>override</role-hint>
+ <role-hint>toolchains-requirement-configurator</role-hint>
<implementation>org.codehaus.plexus.component.configurator.BasicComponentConfigurator</implementation>
<requirements>
<requirement>
<role>org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup</role>
- <role-hint>override</role-hint>
+ <role-hint>toolchains-requirement-configurator</role-hint>
</requirement>
</requirements>
</component>
<component>
<role>org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup</role>
- <role-hint>override</role-hint>
+ <role-hint>toolchains-requirement-configurator</role-hint>
<implementation>org.codehaus.plexus.component.configurator.converters.lookup.DefaultConverterLookup</implementation>
<requirements>
<requirement>
<role>org.codehaus.plexus.component.configurator.converters.ConfigurationConverter</role>
- <role-hint>Toolchains</role-hint>
+ <role-hint>ToolchainsRequirement</role-hint>
<field-name>customConverters</field-name>
</requirement>
</requirements>
@@ -46,7 +46,7 @@ under the License.
<component>
<role>org.codehaus.plexus.component.configurator.converters.ConfigurationConverter</role>
- <role-hint>Toolchains</role-hint>
+ <role-hint>ToolchainsRequirement</role-hint>
<implementation>org.apache.maven.plugin.toolchain.ToolchainConverter</implementation>
</component>
</components>