diff --git a/pom.xml b/pom.xml
index 7a36744..608c253 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@ under the License.
maven-toolchains-plugin
- 3.1.1-SNAPSHOT
+ 4.0.0-SNAPSHOT
maven-plugin
Apache Maven Toolchains Plugin
@@ -67,33 +67,43 @@ under the License.
- 8
- 3.2.5
+ 11
+ 4.0.0-alpha-5
2022-06-18T21:03:59Z
org.apache.maven
- maven-plugin-api
- ${mavenVersion}
- provided
-
-
- org.apache.maven
- maven-core
+ maven-api-core
${mavenVersion}
provided
org.apache.maven.plugin-tools
maven-plugin-annotations
+ 3.8.1
provided
+
+ org.eclipse.sisu
+ org.eclipse.sisu.plexus
+ 0.9.0.M2
+
+
+ org.apache.maven.plugins
+ maven-plugin-plugin
+ 3.8.1
+
+
+ org.apache.maven.plugins
+ maven-invoker-plugin
+ 3.5.0
+
com.diffplug.spotless
spotless-maven-plugin
diff --git a/src/it/missing-toolchain/verify.groovy b/src/it/missing-toolchain/verify.groovy
index e1b7fe5..3fd9709 100644
--- a/src/it/missing-toolchain/verify.groovy
+++ b/src/it/missing-toolchain/verify.groovy
@@ -19,4 +19,4 @@
content = new File( basedir, 'build.log' ).text
-assert content.indexOf( "MojoFailureException: Cannot find matching toolchain definitions for the following toolchain types:" ) > 0
+assert content.indexOf( "MojoException: Cannot find matching toolchain definitions for the following toolchain types:" ) > 0
diff --git a/src/it/setup-custom-toolchain/pom.xml b/src/it/setup-custom-toolchain/pom.xml
index a1263e9..3a22366 100644
--- a/src/it/setup-custom-toolchain/pom.xml
+++ b/src/it/setup-custom-toolchain/pom.xml
@@ -80,7 +80,7 @@ under the License.
org.codehaus.plexus
plexus-component-metadata
- 1.5.5
+ 2.1.1
@@ -92,7 +92,7 @@ under the License.
org.apache.maven.plugins
maven-plugin-plugin
- 3.3
+ 3.8.1
default-descriptor
diff --git a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainConverter.java b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainConverter.java
deleted file mode 100644
index 2ce0c9f..0000000
--- a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainConverter.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.plugins.toolchain;
-
-import java.util.HashMap;
-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.lookup.ConverterLookup;
-import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
-import org.codehaus.plexus.configuration.PlexusConfiguration;
-
-/**
- * Custom Plexus ConfigurationConverter to instantiate ToolchainRequirement from configuration.
- *
- * @author mkleint
- * @see ToolchainsRequirement
- */
-public class ToolchainConverter extends AbstractConfigurationConverter {
-
- /**
- * @see org.codehaus.plexus.component.configurator.converters.ConfigurationConverter#canConvert(java.lang.Class)
- */
- @Override
- public boolean canConvert(Class type) {
- return ToolchainsRequirement.class.isAssignableFrom(type);
- }
-
- /**
- * @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,
- ClassLoader classLoader,
- ExpressionEvaluator expressionEvaluator,
- ConfigurationListener listener)
- throws ComponentConfigurationException {
- ToolchainsRequirement retValue = new ToolchainsRequirement();
-
- processConfiguration(retValue, configuration, expressionEvaluator);
-
- return retValue;
- }
-
- private void processConfiguration(
- ToolchainsRequirement requirement,
- PlexusConfiguration configuration,
- ExpressionEvaluator expressionEvaluator)
- throws ComponentConfigurationException {
- Map> map = new HashMap<>();
-
- PlexusConfiguration[] tools = configuration.getChildren();
- for (PlexusConfiguration tool : tools) {
- String type = tool.getName();
- PlexusConfiguration[] params = tool.getChildren();
-
- Map parameters = new HashMap<>();
- for (PlexusConfiguration param : params) {
- parameters.put(param.getName(), param.getValue());
- }
- map.put(type, parameters);
- }
-
- requirement.toolchains = map;
- }
-}
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 7b8ec3e..79d5af4 100644
--- a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java
+++ b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java
@@ -22,17 +22,17 @@
import java.util.List;
import java.util.Map;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.toolchain.MisconfiguredToolchainException;
-import org.apache.maven.toolchain.ToolchainManagerPrivate;
-import org.apache.maven.toolchain.ToolchainPrivate;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.Toolchain;
+import org.apache.maven.api.plugin.Log;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.annotations.Component;
+import org.apache.maven.api.plugin.annotations.LifecyclePhase;
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
+import org.apache.maven.api.services.ToolchainManager;
+import org.apache.maven.api.services.ToolchainManagerException;
+import org.apache.maven.api.xml.XmlNode;
/**
* Check that toolchains requirements are met by currently configured toolchains and
@@ -40,24 +40,24 @@
*
* @author mkleint
*/
-@Mojo(
- name = "toolchain",
- defaultPhase = LifecyclePhase.VALIDATE,
- configurator = "toolchains-requirement-configurator",
- threadSafe = true)
-public class ToolchainMojo extends AbstractMojo {
+@Mojo(name = "toolchain", defaultPhase = LifecyclePhase.VALIDATE)
+public class ToolchainMojo implements org.apache.maven.api.plugin.Mojo {
+
private static final Object LOCK = new Object();
/**
*/
@Component
- private ToolchainManagerPrivate toolchainManagerPrivate;
+ private ToolchainManager toolchainManager;
/**
* The current build session instance. This is used for toolchain manager API calls.
*/
- @Parameter(defaultValue = "${session}", readonly = true, required = true)
- private MavenSession session;
+ @Component
+ private Session session;
+
+ @Component
+ private Log log;
/**
* Toolchains requirements, specified by one
@@ -68,16 +68,18 @@ public class ToolchainMojo extends AbstractMojo {
* element for each required toolchain.
*/
@Parameter(required = true)
- private ToolchainsRequirement toolchains;
+ private XmlNode toolchains;
@Override
- public void execute() throws MojoExecutionException, MojoFailureException {
+ public void execute() throws MojoException {
if (toolchains == null) {
// should not happen since parameter is required...
getLog().warn("No toolchains requirements configured.");
return;
}
+ ToolchainsRequirement toolchains = new ToolchainsRequirement(this.toolchains);
+
List nonMatchedTypes = new ArrayList<>();
for (Map.Entry> entry :
@@ -101,7 +103,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
getLog().error(buff.toString());
- throw new MojoFailureException(buff.toString() + System.lineSeparator()
+ throw new MojoException(buff.toString() + System.lineSeparator()
+ "Please make sure you define the required toolchains in your ~/.m2/toolchains.xml file.");
}
}
@@ -111,7 +113,7 @@ protected String getToolchainRequirementAsString(String type, Map param : params.entrySet()) {
@@ -125,14 +127,14 @@ protected String getToolchainRequirementAsString(String type, Map params) throws MojoExecutionException {
+ protected boolean selectToolchain(String type, Map params) throws MojoException {
getLog().info("Required toolchain: " + getToolchainRequirementAsString(type, params));
int typeFound = 0;
try {
- ToolchainPrivate[] tcs = getToolchains(type);
+ List tcs = getToolchains(type);
- for (ToolchainPrivate tc : tcs) {
+ for (Toolchain tc : tcs) {
if (!type.equals(tc.getType())) {
// useful because of MNG-5716
continue;
@@ -145,14 +147,14 @@ protected boolean selectToolchain(String type, Map params) throw
// store matching toolchain to build context
synchronized (LOCK) {
- toolchainManagerPrivate.storeToolchainToBuildContext(tc, session);
+ toolchainManager.storeToolchainToBuildContext(session, tc);
}
return true;
}
}
- } catch (MisconfiguredToolchainException ex) {
- throw new MojoExecutionException("Misconfigured toolchains.", ex);
+ } catch (ToolchainManagerException ex) {
+ throw new MojoException("Misconfigured toolchains.", ex);
}
getLog().error("No toolchain " + ((typeFound == 0) ? "found" : ("matched from " + typeFound + " found"))
@@ -161,8 +163,11 @@ protected boolean selectToolchain(String type, Map params) throw
return false;
}
- private ToolchainPrivate[] getToolchains(String type)
- throws MojoExecutionException, MisconfiguredToolchainException {
- return toolchainManagerPrivate.getToolchainsForType(type, session);
+ private List getToolchains(String type) {
+ return toolchainManager.getToolchainsForType(session, type);
+ }
+
+ public Log getLog() {
+ return log;
}
}
diff --git a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsRequirement.java b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsRequirement.java
index 2016ce1..d8f5620 100644
--- a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsRequirement.java
+++ b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsRequirement.java
@@ -19,18 +19,37 @@
package org.apache.maven.plugins.toolchain;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
+import org.apache.maven.api.xml.XmlNode;
+
/**
* Type for plugin's toolchain attribute representing toolchains requirements.
*
* @author mkleint
- * @see ToolchainConverter the custom Plexus converter to instantiate this class
*/
public final class ToolchainsRequirement {
Map> toolchains;
+ public ToolchainsRequirement(XmlNode node) {
+ Map> toolchains = new HashMap<>();
+ for (XmlNode child : node.getChildren()) {
+ Map cfg = new LinkedHashMap<>();
+ for (XmlNode e : child.getChildren()) {
+ cfg.put(e.getName(), e.getValue());
+ }
+ toolchains.put(child.getName(), cfg);
+ }
+ this.toolchains = toolchains;
+ }
+
+ public ToolchainsRequirement(Map> toolchains) {
+ this.toolchains = toolchains;
+ }
+
public Map> getToolchains() {
return Collections.unmodifiableMap(toolchains);
}
diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml
deleted file mode 100644
index 8d96957..0000000
--- a/src/main/resources/META-INF/plexus/components.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-
-
-
-
-
- org.codehaus.plexus.component.configurator.ComponentConfigurator
- toolchains-requirement-configurator
- org.codehaus.plexus.component.configurator.BasicComponentConfigurator
-
-
- org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup
- toolchains-requirement-configurator
-
-
-
-
-
- org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup
- toolchains-requirement-configurator
- org.codehaus.plexus.component.configurator.converters.lookup.DefaultConverterLookup
-
-
- org.codehaus.plexus.component.configurator.converters.ConfigurationConverter
- ToolchainsRequirement
- customConverters
-
-
-
-
-
- org.codehaus.plexus.component.configurator.converters.ConfigurationConverter
- ToolchainsRequirement
- org.apache.maven.plugins.toolchain.ToolchainConverter
-
-
-