From c5ede2fef8b63cd5c75f8bc2f53aeaa75c629adc Mon Sep 17 00:00:00 2001 From: Joseph Walton Date: Sun, 21 Apr 2019 21:10:45 +1000 Subject: [PATCH] [MNG-6680] Convert Maven Settings Builder to JSR 330 Use @Named and @Singleton throughout, and switch to constructor injection for DefaultSettingsBuilder. This closes #246 --- maven-settings-builder/pom.xml | 10 ++++---- .../building/DefaultSettingsBuilder.java | 24 +++++++++++++------ .../DefaultSettingsBuilderFactory.java | 10 +++----- .../crypto/DefaultSettingsDecrypter.java | 17 +++++++++---- .../settings/io/DefaultSettingsReader.java | 7 ++++-- .../settings/io/DefaultSettingsWriter.java | 7 ++++-- .../validation/DefaultSettingsValidator.java | 7 ++++-- 7 files changed, 52 insertions(+), 30 deletions(-) diff --git a/maven-settings-builder/pom.xml b/maven-settings-builder/pom.xml index 381f5b197b..fb676ca70e 100644 --- a/maven-settings-builder/pom.xml +++ b/maven-settings-builder/pom.xml @@ -46,8 +46,8 @@ under the License. - org.codehaus.plexus - plexus-utils + javax.inject + javax.inject org.codehaus.plexus @@ -55,7 +55,7 @@ under the License. org.codehaus.plexus - plexus-component-annotations + plexus-utils org.apache.maven @@ -70,8 +70,8 @@ under the License. - org.codehaus.plexus - plexus-component-metadata + org.eclipse.sisu + sisu-maven-plugin diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilder.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilder.java index 3cdae7d04f..675ea59162 100644 --- a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilder.java +++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilder.java @@ -27,6 +27,10 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.building.FileSource; import org.apache.maven.building.Source; import org.apache.maven.settings.Settings; @@ -36,8 +40,6 @@ import org.apache.maven.settings.io.SettingsReader; import org.apache.maven.settings.io.SettingsWriter; import org.apache.maven.settings.merge.MavenSettingsMerger; import org.apache.maven.settings.validation.SettingsValidator; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.interpolation.EnvarBasedValueSource; import org.codehaus.plexus.interpolation.InterpolationException; import org.codehaus.plexus.interpolation.InterpolationPostProcessor; @@ -49,21 +51,29 @@ import org.codehaus.plexus.interpolation.RegexBasedInterpolator; * * @author Benjamin Bentmann */ -@Component( role = SettingsBuilder.class ) +@Named +@Singleton public class DefaultSettingsBuilder implements SettingsBuilder { - @Requirement private SettingsReader settingsReader; - @Requirement private SettingsWriter settingsWriter; - @Requirement private SettingsValidator settingsValidator; - private MavenSettingsMerger settingsMerger = new MavenSettingsMerger(); + private final MavenSettingsMerger settingsMerger = new MavenSettingsMerger(); + + @Inject + public DefaultSettingsBuilder( SettingsReader settingsReader, + SettingsWriter settingsWriter, + SettingsValidator settingsValidator ) + { + this.settingsReader = settingsReader; + this.settingsWriter = settingsWriter; + this.settingsValidator = settingsValidator; + } public DefaultSettingsBuilder setSettingsReader( SettingsReader settingsReader ) { diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactory.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactory.java index e728ec5503..805a4c871d 100644 --- a/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactory.java +++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/building/DefaultSettingsBuilderFactory.java @@ -59,13 +59,9 @@ public class DefaultSettingsBuilderFactory */ public DefaultSettingsBuilder newInstance() { - DefaultSettingsBuilder builder = new DefaultSettingsBuilder(); - - builder.setSettingsReader( newSettingsReader() ); - builder.setSettingsWriter( newSettingsWriter() ); - builder.setSettingsValidator( newSettingsValidator() ); - - return builder; + return new DefaultSettingsBuilder( newSettingsReader(), + newSettingsWriter(), + newSettingsValidator() ); } } diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/crypto/DefaultSettingsDecrypter.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/crypto/DefaultSettingsDecrypter.java index 671a20de7d..7d6c8b9b66 100644 --- a/maven-settings-builder/src/main/java/org/apache/maven/settings/crypto/DefaultSettingsDecrypter.java +++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/crypto/DefaultSettingsDecrypter.java @@ -22,13 +22,15 @@ package org.apache.maven.settings.crypto; import java.util.ArrayList; import java.util.List; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Server; import org.apache.maven.settings.building.DefaultSettingsProblem; import org.apache.maven.settings.building.SettingsProblem; import org.apache.maven.settings.building.SettingsProblem.Severity; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException; @@ -37,13 +39,18 @@ import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException; * * @author Benjamin Bentmann */ -@Component( role = SettingsDecrypter.class ) +@Named +@Singleton public class DefaultSettingsDecrypter implements SettingsDecrypter { + private final SecDispatcher securityDispatcher; - @Requirement( hint = "maven" ) - private SecDispatcher securityDispatcher; + @Inject + public DefaultSettingsDecrypter( @Named( "maven" ) SecDispatcher securityDispatcher ) + { + this.securityDispatcher = securityDispatcher; + } @Override public SettingsDecryptionResult decrypt( SettingsDecryptionRequest request ) diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/io/DefaultSettingsReader.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/io/DefaultSettingsReader.java index fa9561371d..6044c0c882 100644 --- a/maven-settings-builder/src/main/java/org/apache/maven/settings/io/DefaultSettingsReader.java +++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/io/DefaultSettingsReader.java @@ -26,9 +26,11 @@ import java.io.Reader; import java.util.Map; import java.util.Objects; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.settings.Settings; import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; -import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -37,7 +39,8 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException; * * @author Benjamin Bentmann */ -@Component( role = SettingsReader.class ) +@Named +@Singleton public class DefaultSettingsReader implements SettingsReader { diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/io/DefaultSettingsWriter.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/io/DefaultSettingsWriter.java index 96af1a340a..10729a2dd8 100644 --- a/maven-settings-builder/src/main/java/org/apache/maven/settings/io/DefaultSettingsWriter.java +++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/io/DefaultSettingsWriter.java @@ -27,9 +27,11 @@ import java.io.Writer; import java.util.Map; import java.util.Objects; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.settings.Settings; import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer; -import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.WriterFactory; /** @@ -37,7 +39,8 @@ import org.codehaus.plexus.util.WriterFactory; * * @author Benjamin Bentmann */ -@Component( role = SettingsWriter.class ) +@Named +@Singleton public class DefaultSettingsWriter implements SettingsWriter { diff --git a/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java b/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java index 1e31f504ff..2aec1e1103 100644 --- a/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java +++ b/maven-settings-builder/src/main/java/org/apache/maven/settings/validation/DefaultSettingsValidator.java @@ -23,6 +23,9 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import javax.inject.Named; +import javax.inject.Singleton; + import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Profile; import org.apache.maven.settings.Repository; @@ -31,13 +34,13 @@ import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; import org.apache.maven.settings.building.SettingsProblem.Severity; import org.apache.maven.settings.building.SettingsProblemCollector; -import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.StringUtils; /** * @author Milos Kleint */ -@Component( role = SettingsValidator.class ) +@Named +@Singleton public class DefaultSettingsValidator implements SettingsValidator {