From 329ebc9a4b522be0f3c4d2b128dd618ba088f0c7 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sun, 12 Jul 2026 19:11:23 +0200 Subject: [PATCH 1/2] Replace Plexus XML configuration with JSR-330 annotated beans MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What changed - Added `@Named("ToolchainsRequirement")` and `@Singleton` annotations to `ToolchainConverter` - Created `ToolchainsComponentConfigurator` extending `BasicComponentConfigurator` — injects `ToolchainConverter` and registers it on initialization - Removed `src/main/resources/META-INF/plexus/components.xml` ## Why - JSR-330 annotations with Sisu replace legacy Plexus XML component descriptors - `sisu-maven-plugin` auto-generates component indexes from annotations, eliminating manual XML maintenance - Cleaner, more maintainable approach with annotations co-located with code ## Testing - All unit tests pass - Sisu index correctly includes both annotated beans - Plugin configuration remains unchanged — `@Mojo(configurator = "toolchains-requirement-configurator")` works as before --- .../plugins/toolchain/ToolchainConverter.java | 19 +++---- .../ToolchainsComponentConfigurator.java | 43 +++++++++++++++ .../toolchain/ToolchainsRequirement.java | 5 ++ .../resources/META-INF/plexus/components.xml | 53 ------------------- 4 files changed, 56 insertions(+), 64 deletions(-) create mode 100644 src/main/java/org/apache/maven/plugins/toolchain/ToolchainsComponentConfigurator.java delete mode 100644 src/main/resources/META-INF/plexus/components.xml 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 2ce0c9f..7277ef8 100644 --- a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainConverter.java +++ b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainConverter.java @@ -18,10 +18,12 @@ */ package org.apache.maven.plugins.toolchain; +import javax.inject.Named; +import javax.inject.Singleton; + 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; @@ -34,6 +36,8 @@ * @author mkleint * @see ToolchainsRequirement */ +@Named("ToolchainsRequirement") +@Singleton public class ToolchainConverter extends AbstractConfigurationConverter { /** @@ -55,20 +59,13 @@ public Object fromConfiguration( Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator, - ConfigurationListener listener) - throws ComponentConfigurationException { + ConfigurationListener listener) { ToolchainsRequirement retValue = new ToolchainsRequirement(); - - processConfiguration(retValue, configuration, expressionEvaluator); - + processConfiguration(retValue, configuration); return retValue; } - private void processConfiguration( - ToolchainsRequirement requirement, - PlexusConfiguration configuration, - ExpressionEvaluator expressionEvaluator) - throws ComponentConfigurationException { + private void processConfiguration(ToolchainsRequirement requirement, PlexusConfiguration configuration) { Map> map = new HashMap<>(); PlexusConfiguration[] tools = configuration.getChildren(); diff --git a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsComponentConfigurator.java b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsComponentConfigurator.java new file mode 100644 index 0000000..f75e3f8 --- /dev/null +++ b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsComponentConfigurator.java @@ -0,0 +1,43 @@ +/* + * 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 javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.codehaus.plexus.component.configurator.BasicComponentConfigurator; +import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter; + +/** + * A configurator for components that handles toolchain requirements specified in Maven configuration. + *

+ * An instance of {@code ConfigurationConverter} for toolchain requirements + * is injected into this configurator, and the required converter is registered + * during the instantiation process. + */ +@Named("toolchains-requirement-configurator") +@Singleton +public class ToolchainsComponentConfigurator extends BasicComponentConfigurator { + + @Inject + public ToolchainsComponentConfigurator(@Named("ToolchainsRequirement") ConfigurationConverter toolchainConverter) { + this.converterLookup.registerConverter(toolchainConverter); + } +} 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..bb93242 100644 --- a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsRequirement.java +++ b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsRequirement.java @@ -42,4 +42,9 @@ public Set getToolchainsTypes() { public Map getParams(String type) { return Collections.unmodifiableMap(toolchains.get(type)); } + + @Override + public String toString() { + return "ToolchainsRequirement{toolchains=" + 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 - - - From 98179e8bd10bd9bca7fd85b91ce9836947cb6382 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Mon, 13 Jul 2026 22:48:18 +0200 Subject: [PATCH 2/2] fix after review --- src/it/select-jdk-toolchain-range/pom.xml | 3 ++- .../select-jdk-toolchain-range/verify.groovy | 23 +++++++++++++++++++ .../ToolchainsComponentConfigurator.java | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/it/select-jdk-toolchain-range/verify.groovy diff --git a/src/it/select-jdk-toolchain-range/pom.xml b/src/it/select-jdk-toolchain-range/pom.xml index 78da66f..eac572d 100644 --- a/src/it/select-jdk-toolchain-range/pom.xml +++ b/src/it/select-jdk-toolchain-range/pom.xml @@ -30,6 +30,7 @@ under the License. UTF-8 + [8,17] @@ -41,7 +42,7 @@ under the License. - [8,17] + ${toolchain.jdk.version} diff --git a/src/it/select-jdk-toolchain-range/verify.groovy b/src/it/select-jdk-toolchain-range/verify.groovy new file mode 100644 index 0000000..0998294 --- /dev/null +++ b/src/it/select-jdk-toolchain-range/verify.groovy @@ -0,0 +1,23 @@ +/* + * 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. + */ + +content = new File(basedir, 'build.log').text + +// property is resolved +assert content.contains('[DEBUG] (f) toolchains = ToolchainsRequirement{toolchains={jdk={version=[8,17]}}}') diff --git a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsComponentConfigurator.java b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsComponentConfigurator.java index f75e3f8..524ca00 100644 --- a/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsComponentConfigurator.java +++ b/src/main/java/org/apache/maven/plugins/toolchain/ToolchainsComponentConfigurator.java @@ -24,6 +24,7 @@ import org.codehaus.plexus.component.configurator.BasicComponentConfigurator; import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter; +import org.codehaus.plexus.component.configurator.converters.lookup.DefaultConverterLookup; /** * A configurator for components that handles toolchain requirements specified in Maven configuration. @@ -38,6 +39,7 @@ public class ToolchainsComponentConfigurator extends BasicComponentConfigurator @Inject public ToolchainsComponentConfigurator(@Named("ToolchainsRequirement") ConfigurationConverter toolchainConverter) { + this.converterLookup = new DefaultConverterLookup(); this.converterLookup.registerConverter(toolchainConverter); } }