diff --git a/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java b/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java index a2119cea53..ad4531c645 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java +++ b/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java @@ -20,6 +20,7 @@ package org.apache.maven.project; */ import java.io.File; +import java.lang.reflect.Field; import org.apache.maven.artifact.Artifact; import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader; @@ -45,8 +46,10 @@ public class ProjectClasspathTest super.setUp(); ArtifactResolver resolver = getContainer().lookup( ArtifactResolver.class, "classpath" ); - DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)getContainer().lookup(ArtifactDescriptorReader.class); - pomReader.setArtifactResolver( resolver ); + DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader) getContainer().lookup(ArtifactDescriptorReader.class); + Field field = DefaultArtifactDescriptorReader.class.getDeclaredField( "artifactResolver" ); + field.setAccessible( true ); + field.set( pomReader, resolver ); projectBuilder = getContainer().lookup( ProjectBuilder.class, "classpath" ); } diff --git a/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java b/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java index 18deb4332b..b5a0348716 100644 --- a/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java +++ b/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java @@ -19,7 +19,14 @@ import java.io.File; import java.util.Collections; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.bridge.MavenRepositorySystem; +import org.apache.maven.model.building.ModelBuilder; +import org.apache.maven.model.building.ModelProcessor; +import org.codehaus.plexus.logging.Logger; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.impl.RemoteRepositoryManager; +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -28,6 +35,16 @@ import javax.inject.Singleton; public class TestProjectBuilder extends DefaultProjectBuilder { + @Inject + public TestProjectBuilder( + Logger logger, ModelBuilder modelBuilder, ModelProcessor modelProcessor, + ProjectBuildingHelper projectBuildingHelper, MavenRepositorySystem repositorySystem, + RepositorySystem repoSystem, RemoteRepositoryManager repositoryManager, + ProjectDependenciesResolver dependencyResolver ) + { + super( logger, modelBuilder, modelProcessor, projectBuildingHelper, repositorySystem, repoSystem, + repositoryManager, dependencyResolver ); + } @Override public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest configuration ) diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index f80833b2e3..a334e8084c 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -83,42 +83,58 @@ public class DefaultMaven implements Maven { - @Inject - private Logger logger; + private final Logger logger; - @Inject protected ProjectBuilder projectBuilder; - @Inject private LifecycleStarter lifecycleStarter; - @Inject protected PlexusContainer container; - @Inject private ExecutionEventCatapult eventCatapult; - @Inject private LegacySupport legacySupport; - @Inject private SessionScope sessionScope; - @Inject private DefaultRepositorySystemSessionFactory repositorySessionFactory; - @Inject - @Named( GraphBuilder.HINT ) - private GraphBuilder graphBuilder; + private final GraphBuilder graphBuilder; + + private final BuildResumptionAnalyzer buildResumptionAnalyzer; + + private final BuildResumptionDataRepository buildResumptionDataRepository; + + private final SuperPomProvider superPomProvider; @Inject - private BuildResumptionAnalyzer buildResumptionAnalyzer; - - @Inject - private BuildResumptionDataRepository buildResumptionDataRepository; - - @Inject - private SuperPomProvider superPomProvider; + public DefaultMaven( + Logger logger, + ProjectBuilder projectBuilder, + LifecycleStarter lifecycleStarter, + PlexusContainer container, + ExecutionEventCatapult eventCatapult, + LegacySupport legacySupport, + SessionScope sessionScope, + DefaultRepositorySystemSessionFactory repositorySessionFactory, + @Named( GraphBuilder.HINT ) GraphBuilder graphBuilder, + BuildResumptionAnalyzer buildResumptionAnalyzer, + BuildResumptionDataRepository buildResumptionDataRepository, + SuperPomProvider superPomProvider ) + { + this.logger = logger; + this.projectBuilder = projectBuilder; + this.lifecycleStarter = lifecycleStarter; + this.container = container; + this.eventCatapult = eventCatapult; + this.legacySupport = legacySupport; + this.sessionScope = sessionScope; + this.repositorySessionFactory = repositorySessionFactory; + this.graphBuilder = graphBuilder; + this.buildResumptionAnalyzer = buildResumptionAnalyzer; + this.buildResumptionDataRepository = buildResumptionDataRepository; + this.superPomProvider = superPomProvider; + } @Override public MavenExecutionResult execute( MavenExecutionRequest request ) diff --git a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java index 0ee0bee029..4402d7e0ed 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultProjectDependenciesResolver.java @@ -56,11 +56,18 @@ public class DefaultProjectDependenciesResolver implements ProjectDependenciesResolver { - @Inject - private RepositorySystem repositorySystem; + private final RepositorySystem repositorySystem; + + private final ResolutionErrorHandler resolutionErrorHandler; @Inject - private ResolutionErrorHandler resolutionErrorHandler; + public DefaultProjectDependenciesResolver( + RepositorySystem repositorySystem, + ResolutionErrorHandler resolutionErrorHandler ) + { + this.repositorySystem = repositorySystem; + this.resolutionErrorHandler = resolutionErrorHandler; + } public Set resolve( MavenProject project, Collection scopesToResolve, MavenSession session ) throws ArtifactResolutionException, ArtifactNotFoundException diff --git a/maven-core/src/main/java/org/apache/maven/ReactorReader.java b/maven-core/src/main/java/org/apache/maven/ReactorReader.java index 42c41aca58..247632ae75 100644 --- a/maven-core/src/main/java/org/apache/maven/ReactorReader.java +++ b/maven-core/src/main/java/org/apache/maven/ReactorReader.java @@ -67,13 +67,10 @@ class ReactorReader private static final Logger LOGGER = LoggerFactory.getLogger( ReactorReader.class ); - private MavenSession session; - - private Map projectsByGAV; - - private Map> projectsByGA; - - private WorkspaceRepository repository; + private final MavenSession session; + private final Map projectsByGAV; + private final Map> projectsByGA; + private final WorkspaceRepository repository; @Inject ReactorReader( MavenSession session ) diff --git a/maven-core/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java b/maven-core/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java index 9fc0506a9b..70466a7034 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/factory/DefaultArtifactFactory.java @@ -39,8 +39,13 @@ import org.apache.maven.artifact.versioning.VersionRange; public class DefaultArtifactFactory implements ArtifactFactory { + private final ArtifactHandlerManager artifactHandlerManager; + @Inject - private ArtifactHandlerManager artifactHandlerManager; + public DefaultArtifactFactory( ArtifactHandlerManager artifactHandlerManager ) + { + this.artifactHandlerManager = artifactHandlerManager; + } public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ) { diff --git a/maven-core/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java b/maven-core/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java index a3013d46bf..3145d5808a 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/handler/manager/DefaultArtifactHandlerManager.java @@ -39,10 +39,15 @@ public class DefaultArtifactHandlerManager implements ArtifactHandlerManager { - @Inject - private Map artifactHandlers; + private final Map artifactHandlers; - private Map allHandlers = new ConcurrentHashMap<>(); + private final Map allHandlers = new ConcurrentHashMap<>(); + + @Inject + public DefaultArtifactHandlerManager( Map artifactHandlers ) + { + this.artifactHandlers = artifactHandlers; + } public ArtifactHandler getArtifactHandler( String type ) { diff --git a/maven-core/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java b/maven-core/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java index 980bc153a2..78d54415d3 100644 --- a/maven-core/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java +++ b/maven-core/src/main/java/org/apache/maven/eventspy/internal/EventSpyDispatcher.java @@ -40,23 +40,18 @@ import org.eclipse.aether.RepositoryListener; public class EventSpyDispatcher { - @Inject - private Logger logger; + private final Logger logger; - private List eventSpies; + private final List eventSpies; @Inject - public void setEventSpies( List eventSpies ) + public EventSpyDispatcher( Logger logger, List eventSpies ) { + this.logger = logger; // make copy to get rid of needless overhead for dynamic lookups this.eventSpies = new ArrayList<>( eventSpies ); } - public List getEventSpies() - { - return eventSpies; - } - public ExecutionListener chainListener( ExecutionListener listener ) { if ( eventSpies.isEmpty() ) diff --git a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java index c419f17146..63bc4cb515 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java +++ b/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java @@ -77,33 +77,42 @@ import java.util.Properties; @Named public class DefaultRepositorySystemSessionFactory { - @Inject - private Logger logger; + private final Logger logger; + + private final ArtifactHandlerManager artifactHandlerManager; + + private final RepositorySystem repoSystem; + + private final LocalRepositoryManagerFactory simpleLocalRepoMgrFactory; + + private final WorkspaceReader workspaceRepository; + + private final SettingsDecrypter settingsDecrypter; + + private final EventSpyDispatcher eventSpyDispatcher; + + private final MavenRepositorySystem mavenRepositorySystem; @Inject - private ArtifactHandlerManager artifactHandlerManager; - - @Inject - private RepositorySystem repoSystem; - - @Inject - @Nullable - @Named( "simple" ) - private LocalRepositoryManagerFactory simpleLocalRepoMgrFactory; - - @Inject - @Nullable - @Named( "ide" ) - private WorkspaceReader workspaceRepository; - - @Inject - private SettingsDecrypter settingsDecrypter; - - @Inject - private EventSpyDispatcher eventSpyDispatcher; - - @Inject - MavenRepositorySystem mavenRepositorySystem; + public DefaultRepositorySystemSessionFactory( + Logger logger, + ArtifactHandlerManager artifactHandlerManager, + RepositorySystem repoSystem, + @Nullable @Named( "simple" ) LocalRepositoryManagerFactory simpleLocalRepoMgrFactory, + @Nullable @Named( "ide" ) WorkspaceReader workspaceRepository, + SettingsDecrypter settingsDecrypter, + EventSpyDispatcher eventSpyDispatcher, + MavenRepositorySystem mavenRepositorySystem ) + { + this.logger = logger; + this.artifactHandlerManager = artifactHandlerManager; + this.repoSystem = repoSystem; + this.simpleLocalRepoMgrFactory = simpleLocalRepoMgrFactory; + this.workspaceRepository = workspaceRepository; + this.settingsDecrypter = settingsDecrypter; + this.eventSpyDispatcher = eventSpyDispatcher; + this.mavenRepositorySystem = mavenRepositorySystem; + } public DefaultRepositorySystemSession newRepositorySession( MavenExecutionRequest request ) { diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index b164f08504..c8b4c2d766 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -62,33 +62,38 @@ public class DefaultLifecycleExecutor implements LifecycleExecutor { - @Inject - private LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer; + private final LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer; + private final DefaultLifecycles defaultLifeCycles; + private final LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator; + private final LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator; + private final MojoExecutor mojoExecutor; + private final LifecycleStarter lifecycleStarter; + private final MojoDescriptorCreator mojoDescriptorCreator; @Inject - private DefaultLifecycles defaultLifeCycles; - - @Inject - private LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator; - - @Inject - private LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator; - - @Inject - private MojoExecutor mojoExecutor; - - @Inject - private LifecycleStarter lifecycleStarter; - + public DefaultLifecycleExecutor( + LifeCyclePluginAnalyzer lifeCyclePluginAnalyzer, + DefaultLifecycles defaultLifeCycles, + LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator, + LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator, + MojoExecutor mojoExecutor, + LifecycleStarter lifecycleStarter, + MojoDescriptorCreator mojoDescriptorCreator ) + { + this.lifeCyclePluginAnalyzer = lifeCyclePluginAnalyzer; + this.defaultLifeCycles = defaultLifeCycles; + this.lifecycleTaskSegmentCalculator = lifecycleTaskSegmentCalculator; + this.lifecycleExecutionPlanCalculator = lifecycleExecutionPlanCalculator; + this.mojoExecutor = mojoExecutor; + this.lifecycleStarter = lifecycleStarter; + this.mojoDescriptorCreator = mojoDescriptorCreator; + } public void execute( MavenSession session ) { lifecycleStarter.execute( session ); } - @Inject - private MojoDescriptorCreator mojoDescriptorCreator; - // These methods deal with construction intact Plugin object that look like they come from a standard // block in a Maven POM. We have to do some wiggling to pull the sources of information // together and this really shows the problem of constructing a sensible default configuration but diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java index fc64b92af2..f22f028a85 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java @@ -56,7 +56,6 @@ import org.apache.maven.plugin.lifecycle.Execution; import org.apache.maven.plugin.lifecycle.Phase; import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException; import org.apache.maven.plugin.version.PluginVersionResolutionException; -import org.apache.maven.plugin.version.PluginVersionResolver; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; @@ -75,34 +74,38 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException; public class DefaultLifecycleExecutionPlanCalculator implements LifecycleExecutionPlanCalculator { - @Inject - private PluginVersionResolver pluginVersionResolver; + + private final BuildPluginManager pluginManager; + + private final DefaultLifecycles defaultLifeCycles; + + private final MojoDescriptorCreator mojoDescriptorCreator; + + private final LifecyclePluginResolver lifecyclePluginResolver; + + private final LifecycleMappingDelegate standardDelegate; + + private final Map delegates; + + private final Map mojoExecutionConfigurators; @Inject - private BuildPluginManager pluginManager; - - @Inject - private DefaultLifecycles defaultLifeCycles; - - @Inject - private MojoDescriptorCreator mojoDescriptorCreator; - - @Inject - private LifecyclePluginResolver lifecyclePluginResolver; - - @Inject - @Named( DefaultLifecycleMappingDelegate.HINT ) - private LifecycleMappingDelegate standardDelegate; - - @Inject - private Map delegates; - - @Inject - private Map mojoExecutionConfigurators; - - @SuppressWarnings( { "UnusedDeclaration" } ) - public DefaultLifecycleExecutionPlanCalculator() + public DefaultLifecycleExecutionPlanCalculator( + BuildPluginManager pluginManager, + DefaultLifecycles defaultLifeCycles, + MojoDescriptorCreator mojoDescriptorCreator, + LifecyclePluginResolver lifecyclePluginResolver, + @Named( DefaultLifecycleMappingDelegate.HINT ) LifecycleMappingDelegate standardDelegate, + Map delegates, + Map mojoExecutionConfigurators ) { + this.pluginManager = pluginManager; + this.defaultLifeCycles = defaultLifeCycles; + this.mojoDescriptorCreator = mojoDescriptorCreator; + this.lifecyclePluginResolver = lifecyclePluginResolver; + this.standardDelegate = standardDelegate; + this.delegates = delegates; + this.mojoExecutionConfigurators = mojoExecutionConfigurators; } // Only used for testing @@ -115,6 +118,8 @@ public class DefaultLifecycleExecutionPlanCalculator this.defaultLifeCycles = defaultLifeCycles; this.mojoDescriptorCreator = mojoDescriptorCreator; this.lifecyclePluginResolver = lifecyclePluginResolver; + this.standardDelegate = null; + this.delegates = null; this.mojoExecutionConfigurators = Collections.singletonMap( "default", (MojoExecutionConfigurator) new DefaultMojoExecutionConfigurator() ); } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleTaskSegmentCalculator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleTaskSegmentCalculator.java index e98e0fb031..8d4c324a7d 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleTaskSegmentCalculator.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleTaskSegmentCalculator.java @@ -58,14 +58,17 @@ import org.codehaus.plexus.util.StringUtils; public class DefaultLifecycleTaskSegmentCalculator implements LifecycleTaskSegmentCalculator { - @Inject - private MojoDescriptorCreator mojoDescriptorCreator; + private final MojoDescriptorCreator mojoDescriptorCreator; + + private final LifecyclePluginResolver lifecyclePluginResolver; @Inject - private LifecyclePluginResolver lifecyclePluginResolver; - - public DefaultLifecycleTaskSegmentCalculator() + public DefaultLifecycleTaskSegmentCalculator( + MojoDescriptorCreator mojoDescriptorCreator, + LifecyclePluginResolver lifecyclePluginResolver ) { + this.mojoDescriptorCreator = mojoDescriptorCreator; + this.lifecyclePluginResolver = lifecyclePluginResolver; } public List calculateTaskSegments( MavenSession session ) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDebugLogger.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDebugLogger.java index 9ffb3d4441..2feaca5793 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDebugLogger.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDebugLogger.java @@ -52,20 +52,14 @@ import org.codehaus.plexus.util.StringUtils; @Singleton public class LifecycleDebugLogger { + private final Logger logger; + @Inject - private Logger logger; - - - public LifecycleDebugLogger() - { - } - public LifecycleDebugLogger( Logger logger ) { this.logger = logger; } - public void debug( String s ) { logger.debug( s ); diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java index 44d6cef95c..e2a4c73170 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleDependencyResolver.java @@ -67,29 +67,29 @@ import org.eclipse.aether.util.filter.ScopeDependencyFilter; public class LifecycleDependencyResolver { - @Inject - private ProjectDependenciesResolver dependenciesResolver; + private final ProjectDependenciesResolver dependenciesResolver; + + private final Logger logger; + + private final ProjectArtifactFactory artifactFactory; + + private final EventSpyDispatcher eventSpyDispatcher; + + private final ProjectArtifactsCache projectArtifactsCache; @Inject - private Logger logger; - - @Inject - private ProjectArtifactFactory artifactFactory; - - @Inject - private EventSpyDispatcher eventSpyDispatcher; - - @Inject - private ProjectArtifactsCache projectArtifactsCache; - - public LifecycleDependencyResolver() + public LifecycleDependencyResolver( + ProjectDependenciesResolver dependenciesResolver, + Logger logger, + ProjectArtifactFactory artifactFactory, + EventSpyDispatcher eventSpyDispatcher, + ProjectArtifactsCache projectArtifactsCache ) { - } - - public LifecycleDependencyResolver( ProjectDependenciesResolver projectDependenciesResolver, Logger logger ) - { - this.dependenciesResolver = projectDependenciesResolver; + this.dependenciesResolver = dependenciesResolver; this.logger = logger; + this.artifactFactory = artifactFactory; + this.eventSpyDispatcher = eventSpyDispatcher; + this.projectArtifactsCache = projectArtifactsCache; } public static List getProjects( MavenProject project, MavenSession session, boolean aggregator ) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java index 73839fc7c3..a2f90bee17 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleModuleBuilder.java @@ -53,24 +53,25 @@ import org.apache.maven.session.scope.internal.SessionScope; public class LifecycleModuleBuilder { - @Inject - private MojoExecutor mojoExecutor; + private final MojoExecutor mojoExecutor; + private final BuilderCommon builderCommon; + private final ExecutionEventCatapult eventCatapult; + private final ProjectExecutionListener projectExecutionListener; + private final SessionScope sessionScope; @Inject - private BuilderCommon builderCommon; - - @Inject - private ExecutionEventCatapult eventCatapult; - - private ProjectExecutionListener projectExecutionListener; - - @Inject - private SessionScope sessionScope; - - @Inject - public void setProjectExecutionListeners( final List listeners ) + public LifecycleModuleBuilder( + MojoExecutor mojoExecutor, + BuilderCommon builderCommon, + ExecutionEventCatapult eventCatapult, + List listeners, + SessionScope sessionScope ) { + this.mojoExecutor = mojoExecutor; + this.builderCommon = builderCommon; + this.eventCatapult = eventCatapult; this.projectExecutionListener = new CompoundProjectExecutionListener( listeners ); + this.sessionScope = sessionScope; } public void buildProject( MavenSession session, ReactorContext reactorContext, MavenProject currentProject, diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleStarter.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleStarter.java index e3d886d283..06ba60d565 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleStarter.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleStarter.java @@ -48,29 +48,42 @@ import org.codehaus.plexus.logging.Logger; @Singleton public class LifecycleStarter { - @Inject - private ExecutionEventCatapult eventCatapult; + private final ExecutionEventCatapult eventCatapult; + + private final DefaultLifecycles defaultLifeCycles; + + private final Logger logger; + + private final BuildListCalculator buildListCalculator; + + private final LifecycleDebugLogger lifecycleDebugLogger; + + private final LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator; + + private final Map builders; + + private final SessionScope sessionScope; @Inject - private DefaultLifecycles defaultLifeCycles; - - @Inject - private Logger logger; - - @Inject - private BuildListCalculator buildListCalculator; - - @Inject - private LifecycleDebugLogger lifecycleDebugLogger; - - @Inject - private LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator; - - @Inject - private Map builders; - - @Inject - private SessionScope sessionScope; + public LifecycleStarter( + ExecutionEventCatapult eventCatapult, + DefaultLifecycles defaultLifeCycles, + Logger logger, + BuildListCalculator buildListCalculator, + LifecycleDebugLogger lifecycleDebugLogger, + LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator, + Map builders, + SessionScope sessionScope ) + { + this.eventCatapult = eventCatapult; + this.defaultLifeCycles = defaultLifeCycles; + this.logger = logger; + this.buildListCalculator = buildListCalculator; + this.lifecycleDebugLogger = lifecycleDebugLogger; + this.lifecycleTaskSegmentCalculator = lifecycleTaskSegmentCalculator; + this.builders = builders; + this.sessionScope = sessionScope; + } public void execute( MavenSession session ) { diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java index 03eae374e0..e584966f58 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoDescriptorCreator.java @@ -67,29 +67,21 @@ import org.codehaus.plexus.util.xml.Xpp3Dom; public class MojoDescriptorCreator { - @Inject - private Logger logger; + private final Logger logger; + private final PluginVersionResolver pluginVersionResolver; + private final BuildPluginManager pluginManager; + private final PluginPrefixResolver pluginPrefixResolver; + private final LifecyclePluginResolver lifecyclePluginResolver; @Inject - private PluginVersionResolver pluginVersionResolver; - - @Inject - private BuildPluginManager pluginManager; - - @Inject - private PluginPrefixResolver pluginPrefixResolver; - - @Inject - private LifecyclePluginResolver lifecyclePluginResolver; - - public MojoDescriptorCreator() - { - } - - public MojoDescriptorCreator( PluginVersionResolver pluginVersionResolver, BuildPluginManager pluginManager, - PluginPrefixResolver pluginPrefixResolver, - LifecyclePluginResolver lifecyclePluginResolver ) + public MojoDescriptorCreator( + Logger logger, + PluginVersionResolver pluginVersionResolver, + BuildPluginManager pluginManager, + PluginPrefixResolver pluginPrefixResolver, + LifecyclePluginResolver lifecyclePluginResolver ) { + this.logger = logger; this.pluginVersionResolver = pluginVersionResolver; this.pluginManager = pluginManager; this.pluginPrefixResolver = pluginPrefixResolver; diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java index 89fadfdb32..c28f2182b1 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/MojoExecutor.java @@ -67,20 +67,22 @@ import org.codehaus.plexus.util.StringUtils; public class MojoExecutor { - @Inject - private BuildPluginManager pluginManager; + private final BuildPluginManager pluginManager; + private final MavenPluginManager mavenPluginManager; + private final LifecycleDependencyResolver lifeCycleDependencyResolver; + private final ExecutionEventCatapult eventCatapult; @Inject - private MavenPluginManager mavenPluginManager; - - @Inject - private LifecycleDependencyResolver lifeCycleDependencyResolver; - - @Inject - private ExecutionEventCatapult eventCatapult; - - public MojoExecutor() + public MojoExecutor( + BuildPluginManager pluginManager, + MavenPluginManager mavenPluginManager, + LifecycleDependencyResolver lifeCycleDependencyResolver, + ExecutionEventCatapult eventCatapult ) { + this.pluginManager = pluginManager; + this.mavenPluginManager = mavenPluginManager; + this.lifeCycleDependencyResolver = lifeCycleDependencyResolver; + this.eventCatapult = eventCatapult; } public DependencyContext newDependencyContext( MavenSession session, List mojoExecutions ) diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java index d16b27d313..e956dd2c79 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java @@ -71,28 +71,22 @@ import org.codehaus.plexus.logging.Logger; @Singleton public class BuilderCommon { - @Inject - private LifecycleDebugLogger lifecycleDebugLogger; + private final Logger logger; + private final LifecycleDebugLogger lifecycleDebugLogger; + private final LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator; + private final ExecutionEventCatapult eventCatapult; @Inject - private LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator; - - @Inject - private ExecutionEventCatapult eventCatapult; - - @Inject - private Logger logger; - - public BuilderCommon() - { - } - - public BuilderCommon( LifecycleDebugLogger lifecycleDebugLogger, - LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator, Logger logger ) + public BuilderCommon( + Logger logger, + LifecycleDebugLogger lifecycleDebugLogger, + LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator, + ExecutionEventCatapult eventCatapult ) { + this.logger = logger; this.lifecycleDebugLogger = lifecycleDebugLogger; this.lifeCycleExecutionPlanCalculator = lifeCycleExecutionPlanCalculator; - this.logger = logger; + this.eventCatapult = eventCatapult; } public MavenExecutionPlan resolveBuildPlan( MavenSession session, MavenProject project, TaskSegment taskSegment, diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java index 285217f858..fd2676b133 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/MultiThreadedBuilder.java @@ -65,14 +65,14 @@ public class MultiThreadedBuilder implements Builder { - @Inject - private Logger logger; + private final Logger logger; + private final LifecycleModuleBuilder lifecycleModuleBuilder; @Inject - private LifecycleModuleBuilder lifecycleModuleBuilder; - - public MultiThreadedBuilder() + public MultiThreadedBuilder( Logger logger, LifecycleModuleBuilder lifecycleModuleBuilder ) { + this.logger = logger; + this.lifecycleModuleBuilder = lifecycleModuleBuilder; } @Override diff --git a/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java b/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java index 6ffcb06b82..378ebf1e85 100644 --- a/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java +++ b/maven-core/src/main/java/org/apache/maven/model/plugin/DefaultLifecycleBindingsInjector.java @@ -55,10 +55,15 @@ public class DefaultLifecycleBindingsInjector implements LifecycleBindingsInjector { - private LifecycleBindingsMerger merger = new LifecycleBindingsMerger(); + private final LifecycleBindingsMerger merger = new LifecycleBindingsMerger(); + + private final LifeCyclePluginAnalyzer lifecycle; @Inject - private LifeCyclePluginAnalyzer lifecycle; + public DefaultLifecycleBindingsInjector( LifeCyclePluginAnalyzer lifecycle ) + { + this.lifecycle = lifecycle; + } public void injectLifecycleBindings( Model model, ModelBuildingRequest request, ModelProblemCollector problems ) { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java index 15a35eadc1..272371ade0 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java @@ -51,21 +51,22 @@ public class DefaultBuildPluginManager implements BuildPluginManager { - @Inject - private MavenPluginManager mavenPluginManager; + private final MavenPluginManager mavenPluginManager; + private final LegacySupport legacySupport; + private final MojoExecutionScope scope; + private final MojoExecutionListener mojoExecutionListener; @Inject - private LegacySupport legacySupport; - - @Inject - private MojoExecutionScope scope; - - private MojoExecutionListener mojoExecutionListener; - - @Inject - public void setMojoExecutionListeners( final List listeners ) + public DefaultBuildPluginManager( + MavenPluginManager mavenPluginManager, + LegacySupport legacySupport, + MojoExecutionScope scope, + List mojoExecutionListeners ) { - this.mojoExecutionListener = new CompoundMojoExecutionListener( listeners ); + this.mavenPluginManager = mavenPluginManager; + this.legacySupport = legacySupport; + this.scope = scope; + this.mojoExecutionListener = new CompoundMojoExecutionListener( mojoExecutionListeners ); } /** diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java index 7bb19bb0d9..398846eec5 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java @@ -132,48 +132,53 @@ public class DefaultMavenPluginManager */ public static final String KEY_EXTENSIONS_REALMS = DefaultMavenPluginManager.class.getName() + "/extensionsRealms"; - @Inject private Logger logger; - - @Inject private LoggerManager loggerManager; - - @Inject private PlexusContainer container; - - @Inject private ClassRealmManager classRealmManager; - - @Inject private PluginDescriptorCache pluginDescriptorCache; - - @Inject private PluginRealmCache pluginRealmCache; - - @Inject private PluginDependenciesResolver pluginDependenciesResolver; - - @Inject private RuntimeInformation runtimeInformation; - - @Inject private ExtensionRealmCache extensionRealmCache; - - @Inject private PluginVersionResolver pluginVersionResolver; - - @Inject private PluginArtifactsCache pluginArtifactsCache; - - @Inject private MavenPluginValidator pluginValidator; - private ExtensionDescriptorBuilder extensionDescriptorBuilder = new ExtensionDescriptorBuilder(); + private final ExtensionDescriptorBuilder extensionDescriptorBuilder = new ExtensionDescriptorBuilder(); + private final PluginDescriptorBuilder builder = new PluginDescriptorBuilder(); - private PluginDescriptorBuilder builder = new PluginDescriptorBuilder(); + @Inject + public DefaultMavenPluginManager( + Logger logger, + LoggerManager loggerManager, + PlexusContainer container, + ClassRealmManager classRealmManager, + PluginDescriptorCache pluginDescriptorCache, + PluginRealmCache pluginRealmCache, + PluginDependenciesResolver pluginDependenciesResolver, + RuntimeInformation runtimeInformation, + ExtensionRealmCache extensionRealmCache, + PluginVersionResolver pluginVersionResolver, + PluginArtifactsCache pluginArtifactsCache, + MavenPluginValidator pluginValidator ) + { + this.logger = logger; + this.loggerManager = loggerManager; + this.container = container; + this.classRealmManager = classRealmManager; + this.pluginDescriptorCache = pluginDescriptorCache; + this.pluginRealmCache = pluginRealmCache; + this.pluginDependenciesResolver = pluginDependenciesResolver; + this.runtimeInformation = runtimeInformation; + this.extensionRealmCache = extensionRealmCache; + this.pluginVersionResolver = pluginVersionResolver; + this.pluginArtifactsCache = pluginArtifactsCache; + this.pluginValidator = pluginValidator; + } public synchronized PluginDescriptor getPluginDescriptor( Plugin plugin, List repositories, - RepositorySystemSession session ) + RepositorySystemSession session ) throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException { PluginDescriptorCache.Key cacheKey = pluginDescriptorCache.createKey( plugin, repositories, session ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java index 709bd72182..9fa424e268 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java @@ -78,11 +78,15 @@ public class DefaultPluginDependenciesResolver private static final String REPOSITORY_CONTEXT = "plugin"; - @Inject - private Logger logger; + private final Logger logger; + private final RepositorySystem repoSystem; @Inject - private RepositorySystem repoSystem; + public DefaultPluginDependenciesResolver( Logger logger, RepositorySystem repoSystem ) + { + this.logger = logger; + this.repoSystem = repoSystem; + } private Artifact toArtifact( Plugin plugin, RepositorySystemSession session ) { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java index 547e457129..24f71353ae 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java @@ -70,20 +70,26 @@ public class DefaultPluginManager implements PluginManager { - @Inject - private PlexusContainer container; + private final PlexusContainer container; + private final MavenPluginManager pluginManager; + private final PluginVersionResolver pluginVersionResolver; + private final PluginPrefixResolver pluginPrefixResolver; + private final LegacySupport legacySupport; @Inject - private MavenPluginManager pluginManager; - - @Inject - private PluginVersionResolver pluginVersionResolver; - - @Inject - private PluginPrefixResolver pluginPrefixResolver; - - @Inject - private LegacySupport legacySupport; + public DefaultPluginManager( + PlexusContainer container, + MavenPluginManager pluginManager, + PluginVersionResolver pluginVersionResolver, + PluginPrefixResolver pluginPrefixResolver, + LegacySupport legacySupport ) + { + this.container = container; + this.pluginManager = pluginManager; + this.pluginVersionResolver = pluginVersionResolver; + this.pluginPrefixResolver = pluginPrefixResolver; + this.legacySupport = legacySupport; + } public void executeMojo( MavenProject project, MojoExecution execution, MavenSession session ) throws MojoExecutionException, ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException, diff --git a/maven-core/src/main/java/org/apache/maven/plugin/prefix/internal/DefaultPluginPrefixResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/prefix/internal/DefaultPluginPrefixResolver.java index 7b98e80fc0..86ada01cfc 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/prefix/internal/DefaultPluginPrefixResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/prefix/internal/DefaultPluginPrefixResolver.java @@ -68,17 +68,23 @@ public class DefaultPluginPrefixResolver private static final String REPOSITORY_CONTEXT = "plugin"; - @Inject - private Logger logger; + private final Logger logger; + private final BuildPluginManager pluginManager; + private final RepositorySystem repositorySystem; + private final MetadataReader metadataReader; @Inject - private BuildPluginManager pluginManager; - - @Inject - private RepositorySystem repositorySystem; - - @Inject - private MetadataReader metadataReader; + public DefaultPluginPrefixResolver( + Logger logger, + BuildPluginManager pluginManager, + RepositorySystem repositorySystem, + MetadataReader metadataReader ) + { + this.logger = logger; + this.pluginManager = pluginManager; + this.repositorySystem = repositorySystem; + this.metadataReader = metadataReader; + } public PluginPrefixResult resolve( PluginPrefixRequest request ) throws NoPluginFoundForPrefixException diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java index ec72f2ad5a..9517af7d59 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/internal/DefaultPluginVersionResolver.java @@ -81,17 +81,23 @@ public class DefaultPluginVersionResolver private static final Object CACHE_KEY = new Object(); - @Inject - private Logger logger; + private final Logger logger; + private final RepositorySystem repositorySystem; + private final MetadataReader metadataReader; + private final MavenPluginManager pluginManager; @Inject - private RepositorySystem repositorySystem; - - @Inject - private MetadataReader metadataReader; - - @Inject - private MavenPluginManager pluginManager; + public DefaultPluginVersionResolver( + Logger logger, + RepositorySystem repositorySystem, + MetadataReader metadataReader, + MavenPluginManager pluginManager ) + { + this.logger = logger; + this.repositorySystem = repositorySystem; + this.metadataReader = metadataReader; + this.pluginManager = pluginManager; + } public PluginVersionResult resolve( PluginVersionRequest request ) throws PluginVersionResolutionException diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 3aaf8eeb93..80145c586a 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -75,6 +75,7 @@ import org.apache.maven.repository.internal.DefaultModelCache; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.StringUtils; +import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RequestTrace; import org.eclipse.aether.impl.RemoteRepositoryManager; @@ -93,31 +94,36 @@ public class DefaultProjectBuilder implements ProjectBuilder { - @Inject - private Logger logger; + private final Logger logger; + private final ModelBuilder modelBuilder; + private final ModelProcessor modelProcessor; + private final ProjectBuildingHelper projectBuildingHelper; + private final MavenRepositorySystem repositorySystem; + private final org.eclipse.aether.RepositorySystem repoSystem; + private final RemoteRepositoryManager repositoryManager; + private final ProjectDependenciesResolver dependencyResolver; @Inject - private ModelBuilder modelBuilder; - - @Inject - private ModelProcessor modelProcessor; - - @Inject - private ProjectBuildingHelper projectBuildingHelper; - - @Inject - private MavenRepositorySystem repositorySystem; - - @Inject - private org.eclipse.aether.RepositorySystem repoSystem; - - @Inject - private RemoteRepositoryManager repositoryManager; - - @Inject - private ProjectDependenciesResolver dependencyResolver; - - // ---------------------------------------------------------------------- + public DefaultProjectBuilder( + Logger logger, + ModelBuilder modelBuilder, + ModelProcessor modelProcessor, + ProjectBuildingHelper projectBuildingHelper, + MavenRepositorySystem repositorySystem, + RepositorySystem repoSystem, + RemoteRepositoryManager repositoryManager, + ProjectDependenciesResolver dependencyResolver ) + { + this.logger = logger; + this.modelBuilder = modelBuilder; + this.modelProcessor = modelProcessor; + this.projectBuildingHelper = projectBuildingHelper; + this.repositorySystem = repositorySystem; + this.repoSystem = repoSystem; + this.repositoryManager = repositoryManager; + this.dependencyResolver = dependencyResolver; + } +// ---------------------------------------------------------------------- // MavenProjectBuilder Implementation // ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java index e5c89e6f1a..eeb2dbcb25 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuildingHelper.java @@ -68,23 +68,29 @@ public class DefaultProjectBuildingHelper implements ProjectBuildingHelper { - @Inject - private Logger logger; + private final Logger logger; + private final PlexusContainer container; + private final ClassRealmManager classRealmManager; + private final ProjectRealmCache projectRealmCache; + private final RepositorySystem repositorySystem; + private final MavenPluginManager pluginManager; @Inject - private PlexusContainer container; - - @Inject - private ClassRealmManager classRealmManager; - - @Inject - private ProjectRealmCache projectRealmCache; - - @Inject - private RepositorySystem repositorySystem; - - @Inject - private MavenPluginManager pluginManager; + public DefaultProjectBuildingHelper( + Logger logger, + PlexusContainer container, + ClassRealmManager classRealmManager, + ProjectRealmCache projectRealmCache, + RepositorySystem repositorySystem, + MavenPluginManager pluginManager ) + { + this.logger = logger; + this.container = container; + this.classRealmManager = classRealmManager; + this.projectRealmCache = projectRealmCache; + this.repositorySystem = repositorySystem; + this.pluginManager = pluginManager; + } public List createArtifactRepositories( List pomRepositories, List externalRepositories, diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java index 267dc2d0b7..2f6bebf365 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java @@ -62,14 +62,20 @@ public class DefaultProjectDependenciesResolver implements ProjectDependenciesResolver { - @Inject - private Logger logger; + private final Logger logger; + private final RepositorySystem repoSystem; + private final List decorators; @Inject - private RepositorySystem repoSystem; - - @Inject - private List decorators; + public DefaultProjectDependenciesResolver( + Logger logger, + RepositorySystem repoSystem, + List decorators ) + { + this.logger = logger; + this.repoSystem = repoSystem; + this.decorators = decorators; + } public DependencyResolutionResult resolve( DependencyResolutionRequest request ) throws DependencyResolutionException diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMetadataSource.java index 9f22f992e1..fd1c3e05d0 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/DefaultMetadataSource.java @@ -19,9 +19,16 @@ package org.apache.maven.project.artifact; * under the License. */ +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; +import org.apache.maven.plugin.LegacySupport; +import org.apache.maven.project.ProjectBuilder; +import org.codehaus.plexus.logging.Logger; + /** * This realizes the metadata source via the default hint to provide backward-compat with Maven 2.x whose Plexus version * registered component descriptors twice: once keyed by role+roleHint and once keyed by role only. This effectively @@ -34,5 +41,11 @@ import javax.inject.Singleton; public class DefaultMetadataSource extends MavenMetadataSource { - + @Inject + public DefaultMetadataSource( + Logger logger, RepositoryMetadataManager repositoryMetadataManager, ArtifactFactory repositorySystem, + ProjectBuilder projectBuilder, MavenMetadataCache cache, LegacySupport legacySupport ) + { + super( logger, repositoryMetadataManager, repositorySystem, projectBuilder, cache, legacySupport ); + } } diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 271e6d656c..31d239a3cf 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -78,8 +78,6 @@ import org.apache.maven.properties.internal.SystemProperties; import org.apache.maven.repository.internal.MavenWorkspaceReader; import org.apache.maven.repository.legacy.metadata.DefaultMetadataResolutionRequest; import org.apache.maven.repository.legacy.metadata.MetadataResolutionRequest; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.repository.RepositoryPolicy; @@ -94,27 +92,30 @@ import org.eclipse.aether.transfer.ArtifactNotFoundException; public class MavenMetadataSource implements ArtifactMetadataSource { - @Inject - private RepositoryMetadataManager repositoryMetadataManager; - @Inject - private ArtifactFactory repositorySystem; - - //TODO This prevents a cycle in the composition which shows us another problem we need to deal with. - //@Inject - private ProjectBuilder projectBuilder; - - @Inject - private PlexusContainer container; - - @Inject private Logger logger; - - @Inject + private RepositoryMetadataManager repositoryMetadataManager; + private ArtifactFactory repositorySystem; + private ProjectBuilder projectBuilder; private MavenMetadataCache cache; + private LegacySupport legacySupport; @Inject - private LegacySupport legacySupport; + public MavenMetadataSource( + Logger logger, + RepositoryMetadataManager repositoryMetadataManager, + ArtifactFactory repositorySystem, + ProjectBuilder projectBuilder, + MavenMetadataCache cache, + LegacySupport legacySupport ) + { + this.logger = logger; + this.repositoryMetadataManager = repositoryMetadataManager; + this.repositorySystem = repositorySystem; + this.projectBuilder = projectBuilder; + this.cache = cache; + this.legacySupport = legacySupport; + } private void injectSession( MetadataResolutionRequest request ) { @@ -535,24 +536,6 @@ public class MavenMetadataSource return artifacts; } - private ProjectBuilder getProjectBuilder() - { - if ( projectBuilder != null ) - { - return projectBuilder; - } - - try - { - projectBuilder = container.lookup( ProjectBuilder.class ); - } - catch ( ComponentLookupException e ) - { - // Won't happen - } - - return projectBuilder; - } @SuppressWarnings( "checkstyle:methodlength" ) private ProjectRelocation retrieveRelocatedProject( Artifact artifact, MetadataResolutionRequest repositoryRequest ) throws ArtifactMetadataRetrievalException @@ -593,7 +576,7 @@ public class MavenMetadataSource configuration.setSystemProperties( getSystemProperties() ); configuration.setRepositorySession( legacySupport.getRepositorySession() ); - project = getProjectBuilder().build( pomArtifact, configuration ).getProject(); + project = projectBuilder.build( pomArtifact, configuration ).getProject(); } catch ( ProjectBuildingException e ) { diff --git a/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java b/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java index fbb817e699..9c01ba62a4 100644 --- a/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java +++ b/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java @@ -46,11 +46,16 @@ public class DefaultRuntimeInformation implements RuntimeInformation { - @Inject - private Logger logger; + private final Logger logger; private String mavenVersion; + @Inject + public DefaultRuntimeInformation( Logger logger ) + { + this.logger = logger; + } + public String getMavenVersion() { if ( mavenVersion == null ) diff --git a/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java b/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java index 8b127966bb..3c173ec7c5 100644 --- a/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/settings/DefaultMavenSettingsBuilder.java @@ -46,8 +46,13 @@ public class DefaultMavenSettingsBuilder implements MavenSettingsBuilder { + private final SettingsBuilder settingsBuilder; + @Inject - private SettingsBuilder settingsBuilder; + public DefaultMavenSettingsBuilder( SettingsBuilder settingsBuilder ) + { + this.settingsBuilder = settingsBuilder; + } public Settings buildSettings() throws IOException, XmlPullParserException diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManager.java b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManager.java index cfe22cb212..7bb6db6edf 100644 --- a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManager.java +++ b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManager.java @@ -43,11 +43,15 @@ import org.codehaus.plexus.logging.Logger; public class DefaultToolchainManager implements ToolchainManager { - @Inject - Logger logger; + final Logger logger; + final Map factories; @Inject - Map factories; + public DefaultToolchainManager( Logger logger, Map factories ) + { + this.logger = logger; + this.factories = factories; + } @Override public Toolchain getToolchainFromBuildContext( String type, MavenSession session ) diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java index 538c99d235..bfe3a4b383 100644 --- a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java +++ b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.java @@ -23,11 +23,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; import org.apache.maven.execution.MavenSession; import org.apache.maven.toolchain.model.ToolchainModel; +import org.codehaus.plexus.logging.Logger; /** * @author mkleint @@ -40,6 +42,12 @@ public class DefaultToolchainManagerPrivate implements ToolchainManagerPrivate { + @Inject + public DefaultToolchainManagerPrivate( Logger logger, Map factories ) + { + super( logger, factories ); + } + @Override public ToolchainPrivate[] getToolchainsForType( String type, MavenSession context ) throws MisconfiguredToolchainException diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java index 94f3114a09..5bdbccbca3 100644 --- a/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/toolchain/DefaultToolchainsBuilder.java @@ -42,8 +42,13 @@ public class DefaultToolchainsBuilder implements ToolchainsBuilder { + private final Logger logger; + @Inject - private Logger logger; + public DefaultToolchainsBuilder( Logger logger ) + { + this.logger = logger; + } public PersistedToolchains build( File userToolchainsFile ) throws MisconfiguredToolchainException diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilder.java b/maven-core/src/main/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilder.java index 6b337a6dca..66b3aa5f4e 100644 --- a/maven-core/src/main/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/toolchain/building/DefaultToolchainsBuilder.java @@ -53,13 +53,18 @@ import java.util.Map; public class DefaultToolchainsBuilder implements ToolchainsBuilder { - private MavenToolchainMerger toolchainsMerger = new MavenToolchainMerger(); - - @Inject + private final MavenToolchainMerger toolchainsMerger = new MavenToolchainMerger(); private ToolchainsWriter toolchainsWriter; + private ToolchainsReader toolchainsReader; @Inject - private ToolchainsReader toolchainsReader; + public DefaultToolchainsBuilder( + ToolchainsWriter toolchainsWriter, + ToolchainsReader toolchainsReader ) + { + this.toolchainsWriter = toolchainsWriter; + this.toolchainsReader = toolchainsReader; + } @Override public ToolchainsBuildingResult build( ToolchainsBuildingRequest request ) diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/java/JavaToolchainFactory.java b/maven-core/src/main/java/org/apache/maven/toolchain/java/JavaToolchainFactory.java index f2e45a3326..e32e35c3d0 100644 --- a/maven-core/src/main/java/org/apache/maven/toolchain/java/JavaToolchainFactory.java +++ b/maven-core/src/main/java/org/apache/maven/toolchain/java/JavaToolchainFactory.java @@ -51,9 +51,14 @@ public class JavaToolchainFactory implements ToolchainFactory { - @Inject private Logger logger; + @Inject + public JavaToolchainFactory( Logger logger ) + { + this.logger = logger; + } + public ToolchainPrivate createToolchain( ToolchainModel model ) throws MisconfiguredToolchainException { diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/DelegatingMojoExecutionListener.java b/maven-core/src/test/java/org/apache/maven/lifecycle/DelegatingMojoExecutionListener.java index b111969733..6da190c5e7 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/DelegatingMojoExecutionListener.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/DelegatingMojoExecutionListener.java @@ -28,6 +28,7 @@ import javax.inject.Singleton; import org.apache.maven.execution.MojoExecutionEvent; import org.apache.maven.execution.MojoExecutionListener; import org.apache.maven.plugin.MojoExecutionException; +import org.eclipse.sisu.Priority; @Named @Singleton diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java index fe0776e90a..88c2dabaf3 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java @@ -98,8 +98,7 @@ public class BuilderCommonTest public BuilderCommon getBuilderCommon() { final LifecycleDebugLogger debugLogger = new LifecycleDebugLogger( logger ); - return new BuilderCommon( debugLogger, new LifecycleExecutionPlanCalculatorStub(), - logger ); + return new BuilderCommon( logger, debugLogger, new LifecycleExecutionPlanCalculatorStub(), null ); } } diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java index 28d552afec..f669bdbdf5 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java @@ -72,7 +72,7 @@ public class LifecycleExecutionPlanCalculatorTest public static MojoDescriptorCreator createMojoDescriptorCreator() { - return new MojoDescriptorCreator( new PluginVersionResolverStub(), new BuildPluginManagerStub(), + return new MojoDescriptorCreator( null, new PluginVersionResolverStub(), new BuildPluginManagerStub(), new PluginPrefixResolverStub(), new LifecyclePluginResolver( new PluginVersionResolverStub() ) ); } diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleTaskSegmentCalculatorStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleTaskSegmentCalculatorStub.java index ae613cc720..80c4ab7f69 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleTaskSegmentCalculatorStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifecycleTaskSegmentCalculatorStub.java @@ -17,8 +17,10 @@ package org.apache.maven.lifecycle.internal.stub; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.internal.GoalTask; +import org.apache.maven.lifecycle.internal.LifecyclePluginResolver; import org.apache.maven.lifecycle.internal.LifecycleTask; import org.apache.maven.lifecycle.internal.DefaultLifecycleTaskSegmentCalculator; +import org.apache.maven.lifecycle.internal.MojoDescriptorCreator; import org.apache.maven.lifecycle.internal.TaskSegment; import org.apache.maven.plugin.InvalidPluginDescriptorException; import org.apache.maven.plugin.MojoNotFoundException; @@ -43,8 +45,12 @@ public class LifecycleTaskSegmentCalculatorStub public static final String install = "install"; + public LifecycleTaskSegmentCalculatorStub() + { + super( null, null ); + } - public List calculateTaskSegments( MavenSession session, List tasks ) + public List calculateTaskSegments(MavenSession session, List tasks ) throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException, MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException, PluginVersionResolutionException diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java index 250e60d2ef..f0353510fc 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/MojoExecutorStub.java @@ -18,9 +18,13 @@ package org.apache.maven.lifecycle.internal.stub; import org.apache.maven.execution.MavenSession; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.internal.DependencyContext; +import org.apache.maven.lifecycle.internal.ExecutionEventCatapult; +import org.apache.maven.lifecycle.internal.LifecycleDependencyResolver; import org.apache.maven.lifecycle.internal.MojoExecutor; import org.apache.maven.lifecycle.internal.PhaseRecorder; import org.apache.maven.lifecycle.internal.ProjectIndex; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MavenPluginManager; import org.apache.maven.plugin.MojoExecution; import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor; @@ -36,7 +40,16 @@ public class MojoExecutorStub extends MojoExecutor { // This is being lazy instead of making interface - public List executions = Collections.synchronizedList(new ArrayList<>() ); + public final List executions = Collections.synchronizedList(new ArrayList<>() ); + + public MojoExecutorStub( + BuildPluginManager pluginManager, + MavenPluginManager mavenPluginManager, + LifecycleDependencyResolver lifeCycleDependencyResolver, + ExecutionEventCatapult eventCatapult ) + { + super( pluginManager, mavenPluginManager, lifeCycleDependencyResolver, eventCatapult ); + } @Override public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex, diff --git a/maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java b/maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java index d39f4c6eda..e07bf93033 100644 --- a/maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java +++ b/maven-core/src/test/java/org/apache/maven/project/TestMetadataSource.java @@ -25,10 +25,15 @@ import javax.inject.Named; import javax.inject.Singleton; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager; +import org.apache.maven.plugin.LegacySupport; +import org.apache.maven.project.artifact.MavenMetadataCache; import org.apache.maven.project.artifact.MavenMetadataSource; +import org.codehaus.plexus.logging.Logger; @SuppressWarnings( "deprecation" ) @Named( "classpath" ) @@ -36,6 +41,11 @@ import org.apache.maven.project.artifact.MavenMetadataSource; public class TestMetadataSource extends MavenMetadataSource { + + public TestMetadataSource( Logger logger, RepositoryMetadataManager repositoryMetadataManager, ArtifactFactory repositorySystem, ProjectBuilder projectBuilder, MavenMetadataCache cache, LegacySupport legacySupport) { + super( logger, repositoryMetadataManager, repositorySystem, projectBuilder, cache, legacySupport ); + } + @Override public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) diff --git a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivateTest.java b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivateTest.java index 523645f187..cbdf6f5e9e 100644 --- a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivateTest.java +++ b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerPrivateTest.java @@ -60,13 +60,13 @@ public class DefaultToolchainManagerPrivateTest @BeforeEach public void setUp() { - toolchainManager = new DefaultToolchainManagerPrivate(); MockitoAnnotations.initMocks( this ); - toolchainManager.factories = new HashMap<>(); - toolchainManager.factories.put( "basic", toolchainFactory_basicType ); - toolchainManager.factories.put( "rare", toolchainFactory_rareType ); + Map factories = new HashMap<>(); + factories.put( "basic", toolchainFactory_basicType ); + factories.put( "rare", toolchainFactory_rareType ); + toolchainManager = new DefaultToolchainManagerPrivate( logger, factories ); } @Test diff --git a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java index c5b808ffa8..5358a5b629 100644 --- a/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java +++ b/maven-core/src/test/java/org/apache/maven/toolchain/DefaultToolchainManagerTest.java @@ -61,13 +61,12 @@ public class DefaultToolchainManagerTest @BeforeEach public void onSetup() throws Exception { - toolchainManager = new DefaultToolchainManager(); - MockitoAnnotations.initMocks( this ); - toolchainManager.factories = new HashMap<>(); - toolchainManager.factories.put( "basic", toolchainFactory_basicType ); - toolchainManager.factories.put( "rare", toolchainFactory_rareType ); + Map factories = new HashMap<>(); + factories.put( "basic", toolchainFactory_basicType ); + factories.put( "rare", toolchainFactory_rareType ); + toolchainManager = new DefaultToolchainManager( logger, factories ); } @Test diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java b/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java index 5197f32002..ef0c55360c 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/configuration/SettingsXmlConfigurationProcessor.java @@ -73,11 +73,17 @@ public class SettingsXmlConfigurationProcessor private static final Logger LOGGER = LoggerFactory.getLogger( SettingsXmlConfigurationProcessor.class ); - @Inject - private SettingsBuilder settingsBuilder; + private final SettingsBuilder settingsBuilder; + private final SettingsDecrypter settingsDecrypter; @Inject - private SettingsDecrypter settingsDecrypter; + public SettingsXmlConfigurationProcessor( + SettingsBuilder settingsBuilder, + SettingsDecrypter settingsDecrypter ) + { + this.settingsBuilder = settingsBuilder; + this.settingsDecrypter = settingsDecrypter; + } @Override public void process( CliRequest cliRequest ) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java index b16819d640..a45fa2c26b 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilder.java @@ -103,170 +103,321 @@ import org.eclipse.sisu.Nullable; public class DefaultModelBuilder implements ModelBuilder { - @Inject - private ModelProcessor modelProcessor; + private final ModelMerger modelMerger = new FileToRawModelMerger(); + + private final ModelProcessor modelProcessor; + private final ModelValidator modelValidator; + private final ModelNormalizer modelNormalizer; + private final ModelInterpolator modelInterpolator; + private final ModelPathTranslator modelPathTranslator; + private final ModelUrlNormalizer modelUrlNormalizer; + private final SuperPomProvider superPomProvider; + private final InheritanceAssembler inheritanceAssembler; + private final ProfileSelector profileSelector; + private final ProfileInjector profileInjector; + private final PluginManagementInjector pluginManagementInjector; + private final DependencyManagementInjector dependencyManagementInjector; + private final DependencyManagementImporter dependencyManagementImporter; + private final LifecycleBindingsInjector lifecycleBindingsInjector; + private final PluginConfigurationExpander pluginConfigurationExpander; + private final ReportConfigurationExpander reportConfigurationExpander; + private final ReportingConverter reportingConverter; + private final ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator; @Inject - private ModelValidator modelValidator; - - @Inject - private ModelNormalizer modelNormalizer; - - @Inject - private ModelInterpolator modelInterpolator; - - @Inject - private ModelPathTranslator modelPathTranslator; - - @Inject - private ModelUrlNormalizer modelUrlNormalizer; - - @Inject - private SuperPomProvider superPomProvider; - - @Inject - private InheritanceAssembler inheritanceAssembler; - - @Inject - private ProfileSelector profileSelector; - - @Inject - private ProfileInjector profileInjector; - - @Inject - private PluginManagementInjector pluginManagementInjector; - - @Inject - private DependencyManagementInjector dependencyManagementInjector; - - @Inject - private DependencyManagementImporter dependencyManagementImporter; - - @Inject - @Nullable - private LifecycleBindingsInjector lifecycleBindingsInjector; - - @Inject - private PluginConfigurationExpander pluginConfigurationExpander; - - @Inject - private ReportConfigurationExpander reportConfigurationExpander; - - @Inject - private ReportingConverter reportingConverter; - - private ModelMerger modelMerger = new FileToRawModelMerger(); - - @Inject - private ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator; - - public DefaultModelBuilder setModelProcessor( ModelProcessor modelProcessor ) + public DefaultModelBuilder( + ModelProcessor modelProcessor, + ModelValidator modelValidator, + ModelNormalizer modelNormalizer, + ModelInterpolator modelInterpolator, + ModelPathTranslator modelPathTranslator, + ModelUrlNormalizer modelUrlNormalizer, + SuperPomProvider superPomProvider, + InheritanceAssembler inheritanceAssembler, + ProfileSelector profileSelector, + ProfileInjector profileInjector, + PluginManagementInjector pluginManagementInjector, + DependencyManagementInjector dependencyManagementInjector, + DependencyManagementImporter dependencyManagementImporter, + @Nullable LifecycleBindingsInjector lifecycleBindingsInjector, + PluginConfigurationExpander pluginConfigurationExpander, + ReportConfigurationExpander reportConfigurationExpander, + ReportingConverter reportingConverter, + ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator ) { this.modelProcessor = modelProcessor; - return this; + this.modelValidator = modelValidator; + this.modelNormalizer = modelNormalizer; + this.modelInterpolator = modelInterpolator; + this.modelPathTranslator = modelPathTranslator; + this.modelUrlNormalizer = modelUrlNormalizer; + this.superPomProvider = superPomProvider; + this.inheritanceAssembler = inheritanceAssembler; + this.profileSelector = profileSelector; + this.profileInjector = profileInjector; + this.pluginManagementInjector = pluginManagementInjector; + this.dependencyManagementInjector = dependencyManagementInjector; + this.dependencyManagementImporter = dependencyManagementImporter; + this.lifecycleBindingsInjector = lifecycleBindingsInjector; + this.pluginConfigurationExpander = pluginConfigurationExpander; + this.reportConfigurationExpander = reportConfigurationExpander; + this.reportingConverter = reportingConverter; + this.profileActivationFilePathInterpolator = profileActivationFilePathInterpolator; } + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#set + */ + @Deprecated + public DefaultModelBuilder setModelProcessor( ModelProcessor modelProcessor ) + { + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); + } + + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setModelProcessor(ModelProcessor) + */ + @Deprecated public DefaultModelBuilder setModelValidator( ModelValidator modelValidator ) { - this.modelValidator = modelValidator; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setModelNormalizer(ModelNormalizer) + */ + @Deprecated public DefaultModelBuilder setModelNormalizer( ModelNormalizer modelNormalizer ) { - this.modelNormalizer = modelNormalizer; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setModelInterpolator(ModelInterpolator) + */ + @Deprecated public DefaultModelBuilder setModelInterpolator( ModelInterpolator modelInterpolator ) { - this.modelInterpolator = modelInterpolator; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#set + */ + @Deprecated public DefaultModelBuilder setModelPathTranslator( ModelPathTranslator modelPathTranslator ) { - this.modelPathTranslator = modelPathTranslator; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setModelUrlNormalizer(ModelUrlNormalizer) + */ + @Deprecated public DefaultModelBuilder setModelUrlNormalizer( ModelUrlNormalizer modelUrlNormalizer ) { - this.modelUrlNormalizer = modelUrlNormalizer; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setSuperPomProvider(SuperPomProvider) + */ + @Deprecated public DefaultModelBuilder setSuperPomProvider( SuperPomProvider superPomProvider ) { - this.superPomProvider = superPomProvider; - return this; - } - - public DefaultModelBuilder setProfileSelector( ProfileSelector profileSelector ) - { - this.profileSelector = profileSelector; - return this; - } - - public DefaultModelBuilder setProfileInjector( ProfileInjector profileInjector ) - { - this.profileInjector = profileInjector; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setInheritanceAssembler(InheritanceAssembler) + */ + @Deprecated public DefaultModelBuilder setInheritanceAssembler( InheritanceAssembler inheritanceAssembler ) { - this.inheritanceAssembler = inheritanceAssembler; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } - public DefaultModelBuilder setDependencyManagementImporter( DependencyManagementImporter depMgmtImporter ) + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#set + */ + @Deprecated + public DefaultModelBuilder setProfileSelector( ProfileSelector profileSelector ) { - this.dependencyManagementImporter = depMgmtImporter; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } - public DefaultModelBuilder setDependencyManagementInjector( DependencyManagementInjector depMgmtInjector ) + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setProfileInjector(ProfileInjector) + */ + @Deprecated + public DefaultModelBuilder setProfileInjector( ProfileInjector profileInjector ) { - this.dependencyManagementInjector = depMgmtInjector; - return this; - } - - public DefaultModelBuilder setLifecycleBindingsInjector( LifecycleBindingsInjector lifecycleBindingsInjector ) - { - this.lifecycleBindingsInjector = lifecycleBindingsInjector; - return this; - } - - public DefaultModelBuilder setPluginConfigurationExpander( PluginConfigurationExpander pluginConfigurationExpander ) - { - this.pluginConfigurationExpander = pluginConfigurationExpander; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setPluginManagementInjector(PluginManagementInjector) + */ + @Deprecated public DefaultModelBuilder setPluginManagementInjector( PluginManagementInjector pluginManagementInjector ) { - this.pluginManagementInjector = pluginManagementInjector; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setDependencyManagementInjector(DependencyManagementInjector) + */ + @Deprecated + public DefaultModelBuilder setDependencyManagementInjector( + DependencyManagementInjector dependencyManagementInjector ) + { + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); + } + + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setDependencyManagementImporter(DependencyManagementImporter) + */ + @Deprecated + public DefaultModelBuilder setDependencyManagementImporter( + DependencyManagementImporter dependencyManagementImporter ) + { + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); + } + + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setLifecycleBindingsInjector(LifecycleBindingsInjector) + */ + @Deprecated + public DefaultModelBuilder setLifecycleBindingsInjector( LifecycleBindingsInjector lifecycleBindingsInjector ) + { + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); + } + + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setPluginConfigurationExpander(PluginConfigurationExpander) + */ + @Deprecated + public DefaultModelBuilder setPluginConfigurationExpander( PluginConfigurationExpander pluginConfigurationExpander ) + { + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); + } + + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setReportConfigurationExpander(ReportConfigurationExpander) + */ + @Deprecated public DefaultModelBuilder setReportConfigurationExpander( ReportConfigurationExpander reportConfigurationExpander ) { - this.reportConfigurationExpander = reportConfigurationExpander; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setReportingConverter(ReportingConverter) + */ + @Deprecated public DefaultModelBuilder setReportingConverter( ReportingConverter reportingConverter ) { - this.reportingConverter = reportingConverter; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } + /** + * @deprecated since Maven 4 + * @see DefaultModelBuilderFactory#setProfileActivationFilePathInterpolator(ProfileActivationFilePathInterpolator) + */ + @Deprecated public DefaultModelBuilder setProfileActivationFilePathInterpolator( ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator ) { - this.profileActivationFilePathInterpolator = profileActivationFilePathInterpolator; - return this; + return new DefaultModelBuilder( modelProcessor, modelValidator, modelNormalizer, modelInterpolator, + modelPathTranslator, modelUrlNormalizer, superPomProvider, inheritanceAssembler, profileSelector, + profileInjector, pluginManagementInjector, dependencyManagementInjector, dependencyManagementImporter, + lifecycleBindingsInjector, pluginConfigurationExpander, reportConfigurationExpander, + reportingConverter, profileActivationFilePathInterpolator ); } @Override diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilderFactory.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilderFactory.java index 027db20188..6334f1b84b 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilderFactory.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelBuilderFactory.java @@ -19,6 +19,8 @@ package org.apache.maven.model.building; * under the License. */ +import java.util.Arrays; + import org.apache.maven.model.Model; import org.apache.maven.model.composition.DefaultDependencyManagementImporter; import org.apache.maven.model.composition.DependencyManagementImporter; @@ -70,19 +72,151 @@ import org.apache.maven.model.validation.ModelValidator; * A factory to create model builder instances when no dependency injection is available. Note: This class is * only meant as a utility for developers that want to employ the model builder outside of the Maven build system, Maven * plugins should always acquire model builder instances via dependency injection. Developers might want to subclass - * this factory to provide custom implementations for some of the components used by the model builder. + * this factory to provide custom implementations for some of the components used by the model builder, or use the + * builder API to inject custom instances. * * @author Benjamin Bentmann + * @author Guillaume Nodet */ public class DefaultModelBuilderFactory { + private ModelProcessor modelProcessor; + private ModelValidator modelValidator; + private ModelNormalizer modelNormalizer; + private ModelInterpolator modelInterpolator; + private ModelPathTranslator modelPathTranslator; + private ModelUrlNormalizer modelUrlNormalizer; + private SuperPomProvider superPomProvider; + private InheritanceAssembler inheritanceAssembler; + private ProfileSelector profileSelector; + private ProfileInjector profileInjector; + private PluginManagementInjector pluginManagementInjector; + private DependencyManagementInjector dependencyManagementInjector; + private DependencyManagementImporter dependencyManagementImporter; + private LifecycleBindingsInjector lifecycleBindingsInjector; + private PluginConfigurationExpander pluginConfigurationExpander; + private ReportConfigurationExpander reportConfigurationExpander; + private ReportingConverter reportingConverter; + private ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator; + + public DefaultModelBuilderFactory setModelProcessor( ModelProcessor modelProcessor ) + { + this.modelProcessor = modelProcessor; + return this; + } + + public DefaultModelBuilderFactory setModelValidator( ModelValidator modelValidator ) + { + this.modelValidator = modelValidator; + return this; + } + + public DefaultModelBuilderFactory setModelNormalizer( ModelNormalizer modelNormalizer ) + { + this.modelNormalizer = modelNormalizer; + return this; + } + + public DefaultModelBuilderFactory setModelInterpolator( ModelInterpolator modelInterpolator ) + { + this.modelInterpolator = modelInterpolator; + return this; + } + + public DefaultModelBuilderFactory setModelPathTranslator( ModelPathTranslator modelPathTranslator ) + { + this.modelPathTranslator = modelPathTranslator; + return this; + } + + public DefaultModelBuilderFactory setModelUrlNormalizer( ModelUrlNormalizer modelUrlNormalizer ) + { + this.modelUrlNormalizer = modelUrlNormalizer; + return this; + } + + public DefaultModelBuilderFactory setSuperPomProvider( SuperPomProvider superPomProvider ) + { + this.superPomProvider = superPomProvider; + return this; + } + + public DefaultModelBuilderFactory setInheritanceAssembler( InheritanceAssembler inheritanceAssembler ) + { + this.inheritanceAssembler = inheritanceAssembler; + return this; + } + + public DefaultModelBuilderFactory setProfileSelector( ProfileSelector profileSelector ) + { + this.profileSelector = profileSelector; + return this; + } + + public DefaultModelBuilderFactory setProfileInjector( ProfileInjector profileInjector ) + { + this.profileInjector = profileInjector; + return this; + } + + public DefaultModelBuilderFactory setPluginManagementInjector( PluginManagementInjector pluginManagementInjector ) + { + this.pluginManagementInjector = pluginManagementInjector; + return this; + } + + public DefaultModelBuilderFactory setDependencyManagementInjector( + DependencyManagementInjector dependencyManagementInjector ) + { + this.dependencyManagementInjector = dependencyManagementInjector; + return this; + } + + public DefaultModelBuilderFactory setDependencyManagementImporter( + DependencyManagementImporter dependencyManagementImporter ) + { + this.dependencyManagementImporter = dependencyManagementImporter; + return this; + } + + public DefaultModelBuilderFactory setLifecycleBindingsInjector( + LifecycleBindingsInjector lifecycleBindingsInjector ) + { + this.lifecycleBindingsInjector = lifecycleBindingsInjector; + return this; + } + + public DefaultModelBuilderFactory setPluginConfigurationExpander( + PluginConfigurationExpander pluginConfigurationExpander ) + { + this.pluginConfigurationExpander = pluginConfigurationExpander; + return this; + } + + public DefaultModelBuilderFactory setReportConfigurationExpander( + ReportConfigurationExpander reportConfigurationExpander ) + { + this.reportConfigurationExpander = reportConfigurationExpander; + return this; + } + + public DefaultModelBuilderFactory setReportingConverter( ReportingConverter reportingConverter ) + { + this.reportingConverter = reportingConverter; + return this; + } + + public DefaultModelBuilderFactory setProfileActivationFilePathInterpolator( + ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator ) + { + this.profileActivationFilePathInterpolator = profileActivationFilePathInterpolator; + return this; + } + protected ModelProcessor newModelProcessor() { - DefaultModelProcessor processor = new DefaultModelProcessor(); - processor.setModelLocator( newModelLocator() ); - processor.setModelReader( newModelReader() ); - return processor; + return new DefaultModelProcessor( newModelLocator(), newModelReader() ); } protected ModelLocator newModelLocator() @@ -92,33 +226,23 @@ public class DefaultModelBuilderFactory protected ModelReader newModelReader() { - DefaultModelReader reader = new DefaultModelReader(); - reader.setTransformer( newModelSourceTransformer() ); - return reader; + return new DefaultModelReader( newModelSourceTransformer() ); } protected ProfileSelector newProfileSelector() { - DefaultProfileSelector profileSelector = new DefaultProfileSelector(); - - for ( ProfileActivator activator : newProfileActivators() ) - { - profileSelector.addProfileActivator( activator ); - } - - return profileSelector; + return new DefaultProfileSelector( Arrays.asList( newProfileActivators() ) ); } protected ProfileActivator[] newProfileActivators() { return new ProfileActivator[] { new JdkVersionProfileActivator(), new OperatingSystemProfileActivator(), - new PropertyProfileActivator(), new FileProfileActivator() - .setProfileActivationFilePathInterpolator( newProfileActivationFilePathInterpolator() ) }; + new PropertyProfileActivator(), new FileProfileActivator( newProfileActivationFilePathInterpolator() ) }; } protected ProfileActivationFilePathInterpolator newProfileActivationFilePathInterpolator() { - return new ProfileActivationFilePathInterpolator().setPathTranslator( newPathTranslator() ); + return new ProfileActivationFilePathInterpolator( newPathTranslator() ); } protected UrlNormalizer newUrlNormalizer() @@ -135,7 +259,7 @@ public class DefaultModelBuilderFactory { UrlNormalizer normalizer = newUrlNormalizer(); PathTranslator pathTranslator = newPathTranslator(); - return new StringVisitorModelInterpolator().setPathTranslator( pathTranslator ).setUrlNormalizer( normalizer ); + return new StringVisitorModelInterpolator( pathTranslator, normalizer ); } protected ModelValidator newModelValidator() @@ -150,12 +274,12 @@ public class DefaultModelBuilderFactory protected ModelPathTranslator newModelPathTranslator() { - return new DefaultModelPathTranslator().setPathTranslator( newPathTranslator() ); + return new DefaultModelPathTranslator( newPathTranslator() ); } protected ModelUrlNormalizer newModelUrlNormalizer() { - return new DefaultModelUrlNormalizer().setUrlNormalizer( newUrlNormalizer() ); + return new DefaultModelUrlNormalizer( newUrlNormalizer() ); } protected InheritanceAssembler newInheritanceAssembler() @@ -170,7 +294,7 @@ public class DefaultModelBuilderFactory protected SuperPomProvider newSuperPomProvider() { - return new DefaultSuperPomProvider().setModelProcessor( newModelProcessor() ); + return new DefaultSuperPomProvider( newModelProcessor() ); } protected DependencyManagementImporter newDependencyManagementImporter() @@ -220,28 +344,27 @@ public class DefaultModelBuilderFactory */ public DefaultModelBuilder newInstance() { - DefaultModelBuilder modelBuilder = new DefaultModelBuilder(); - - modelBuilder.setModelProcessor( newModelProcessor() ); - modelBuilder.setModelValidator( newModelValidator() ); - modelBuilder.setModelNormalizer( newModelNormalizer() ); - modelBuilder.setModelPathTranslator( newModelPathTranslator() ); - modelBuilder.setModelUrlNormalizer( newModelUrlNormalizer() ); - modelBuilder.setModelInterpolator( newModelInterpolator() ); - modelBuilder.setInheritanceAssembler( newInheritanceAssembler() ); - modelBuilder.setProfileInjector( newProfileInjector() ); - modelBuilder.setProfileSelector( newProfileSelector() ); - modelBuilder.setSuperPomProvider( newSuperPomProvider() ); - modelBuilder.setDependencyManagementImporter( newDependencyManagementImporter() ); - modelBuilder.setDependencyManagementInjector( newDependencyManagementInjector() ); - modelBuilder.setLifecycleBindingsInjector( newLifecycleBindingsInjector() ); - modelBuilder.setPluginManagementInjector( newPluginManagementInjector() ); - modelBuilder.setPluginConfigurationExpander( newPluginConfigurationExpander() ); - modelBuilder.setReportConfigurationExpander( newReportConfigurationExpander() ); - modelBuilder.setReportingConverter( newReportingConverter() ); - modelBuilder.setProfileActivationFilePathInterpolator( newProfileActivationFilePathInterpolator() ); - - return modelBuilder; + return new DefaultModelBuilder( + modelProcessor != null ? modelProcessor : newModelProcessor(), + modelValidator != null ? modelValidator : newModelValidator(), + modelNormalizer != null ? modelNormalizer : newModelNormalizer(), + modelInterpolator != null ? modelInterpolator : newModelInterpolator(), + modelPathTranslator != null ? modelPathTranslator : newModelPathTranslator(), + modelUrlNormalizer != null ? modelUrlNormalizer : newModelUrlNormalizer(), + superPomProvider != null ? superPomProvider : newSuperPomProvider(), + inheritanceAssembler != null ? inheritanceAssembler : newInheritanceAssembler(), + profileSelector != null ? profileSelector : newProfileSelector(), + profileInjector != null ? profileInjector : newProfileInjector(), + pluginManagementInjector != null ? pluginManagementInjector : newPluginManagementInjector(), + dependencyManagementInjector != null ? dependencyManagementInjector : newDependencyManagementInjector(), + dependencyManagementImporter != null ? dependencyManagementImporter : newDependencyManagementImporter(), + lifecycleBindingsInjector != null ? lifecycleBindingsInjector : newLifecycleBindingsInjector(), + pluginConfigurationExpander != null ? pluginConfigurationExpander : newPluginConfigurationExpander(), + reportConfigurationExpander != null ? reportConfigurationExpander : newReportConfigurationExpander(), + reportingConverter != null ? reportingConverter : newReportingConverter(), + profileActivationFilePathInterpolator != null + ? profileActivationFilePathInterpolator : newProfileActivationFilePathInterpolator() + ); } private static class StubLifecycleBindingsInjector diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java index 76370ac4e4..cc2daf8ff0 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/building/DefaultModelProcessor.java @@ -66,22 +66,14 @@ public class DefaultModelProcessor implements ModelProcessor { - @Inject - private ModelLocator locator; + private final ModelLocator locator; + private final ModelReader reader; @Inject - private ModelReader reader; - - public DefaultModelProcessor setModelLocator( ModelLocator locator ) + public DefaultModelProcessor( ModelLocator locator, ModelReader reader ) { this.locator = locator; - return this; - } - - public DefaultModelProcessor setModelReader( ModelReader reader ) - { this.reader = reader; - return this; } @Override diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java index 388671d78d..588b91340b 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/AbstractStringBasedModelInterpolator.java @@ -82,26 +82,14 @@ public abstract class AbstractStringBasedModelInterpolator TRANSLATED_PATH_EXPRESSIONS = translatedPrefixes; } - @Inject - private PathTranslator pathTranslator; + private final PathTranslator pathTranslator; + private final UrlNormalizer urlNormalizer; @Inject - private UrlNormalizer urlNormalizer; - - public AbstractStringBasedModelInterpolator() - { - } - - public AbstractStringBasedModelInterpolator setPathTranslator( PathTranslator pathTranslator ) + public AbstractStringBasedModelInterpolator( PathTranslator pathTranslator, UrlNormalizer urlNormalizer ) { this.pathTranslator = pathTranslator; - return this; - } - - public AbstractStringBasedModelInterpolator setUrlNormalizer( UrlNormalizer urlNormalizer ) - { this.urlNormalizer = urlNormalizer; - return this; } protected List createValueSources( final Model model, final File projectDir, diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java index 93e53b7e54..d775fe3290 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringSearchModelInterpolator.java @@ -26,6 +26,8 @@ import org.apache.maven.model.building.ModelProblem.Severity; import org.apache.maven.model.building.ModelProblem.Version; import org.apache.maven.model.building.ModelProblemCollector; import org.apache.maven.model.building.ModelProblemCollectorRequest; +import org.apache.maven.model.path.PathTranslator; +import org.apache.maven.model.path.UrlNormalizer; import org.codehaus.plexus.interpolation.InterpolationException; import org.codehaus.plexus.interpolation.InterpolationPostProcessor; import org.codehaus.plexus.interpolation.RecursionInterceptor; @@ -46,6 +48,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import javax.inject.Inject; + /** * StringSearchModelInterpolator * @deprecated replaced by StringVisitorModelInterpolator (MNG-6697) @@ -63,6 +67,17 @@ public class StringSearchModelInterpolator String interpolate( String value ); } + @Inject + public StringSearchModelInterpolator( PathTranslator pathTranslator, UrlNormalizer urlNormalizer ) + { + super( pathTranslator, urlNormalizer ); + } + + StringSearchModelInterpolator() + { + super( null, null ); + } + @Override public Model interpolateModel( Model model, File projectDir, ModelBuildingRequest config, ModelProblemCollector problems ) diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolator.java index a12eb1024b..e639a50e34 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolator.java @@ -26,6 +26,7 @@ import java.util.ListIterator; import java.util.Map; import java.util.Properties; +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -71,6 +72,8 @@ import org.apache.maven.model.building.ModelProblem.Severity; import org.apache.maven.model.building.ModelProblem.Version; import org.apache.maven.model.building.ModelProblemCollector; import org.apache.maven.model.building.ModelProblemCollectorRequest; +import org.apache.maven.model.path.PathTranslator; +import org.apache.maven.model.path.UrlNormalizer; import org.codehaus.plexus.interpolation.InterpolationException; import org.codehaus.plexus.interpolation.InterpolationPostProcessor; import org.codehaus.plexus.interpolation.RecursionInterceptor; @@ -88,6 +91,11 @@ import org.codehaus.plexus.util.xml.Xpp3Dom; public class StringVisitorModelInterpolator extends AbstractStringBasedModelInterpolator { + @Inject + public StringVisitorModelInterpolator( PathTranslator pathTranslator, UrlNormalizer urlNormalizer ) + { + super( pathTranslator, urlNormalizer ); + } interface InnerInterpolator { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java b/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java index 1d8b2646ad..eeafabe32f 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/io/DefaultModelReader.java @@ -52,10 +52,10 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException; public class DefaultModelReader implements ModelReader { - @Inject - private ModelSourceTransformer transformer; + private final ModelSourceTransformer transformer; - public void setTransformer( ModelSourceTransformer transformer ) + @Inject + public DefaultModelReader( ModelSourceTransformer transformer ) { this.transformer = transformer; } diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelPathTranslator.java b/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelPathTranslator.java index 26fe10c32d..801499f6ca 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelPathTranslator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelPathTranslator.java @@ -44,13 +44,12 @@ public class DefaultModelPathTranslator implements ModelPathTranslator { - @Inject - private PathTranslator pathTranslator; + private final PathTranslator pathTranslator; - public DefaultModelPathTranslator setPathTranslator( PathTranslator pathTranslator ) + @Inject + public DefaultModelPathTranslator( PathTranslator pathTranslator ) { this.pathTranslator = pathTranslator; - return this; } @Override diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelUrlNormalizer.java b/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelUrlNormalizer.java index 22ace6f56a..92d7bbd316 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelUrlNormalizer.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/path/DefaultModelUrlNormalizer.java @@ -41,13 +41,12 @@ public class DefaultModelUrlNormalizer implements ModelUrlNormalizer { - @Inject - private UrlNormalizer urlNormalizer; + private final UrlNormalizer urlNormalizer; - public DefaultModelUrlNormalizer setUrlNormalizer( UrlNormalizer urlNormalizer ) + @Inject + public DefaultModelUrlNormalizer( UrlNormalizer urlNormalizer ) { this.urlNormalizer = urlNormalizer; - return this; } @Override diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/path/ProfileActivationFilePathInterpolator.java b/maven-model-builder/src/main/java/org/apache/maven/model/path/ProfileActivationFilePathInterpolator.java index c2f815b7f7..41257ac3e9 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/path/ProfileActivationFilePathInterpolator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/path/ProfileActivationFilePathInterpolator.java @@ -41,13 +41,12 @@ import java.io.File; public class ProfileActivationFilePathInterpolator { - @Inject - private PathTranslator pathTranslator; + private final PathTranslator pathTranslator; - public ProfileActivationFilePathInterpolator setPathTranslator( PathTranslator pathTranslator ) + @Inject + public ProfileActivationFilePathInterpolator( PathTranslator pathTranslator ) { this.pathTranslator = pathTranslator; - return this; } /** diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java index 178789f1a0..75dc10f794 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/DefaultProfileSelector.java @@ -47,8 +47,13 @@ public class DefaultProfileSelector implements ProfileSelector { + private final List activators; + @Inject - private List activators = new ArrayList<>(); + public DefaultProfileSelector( List activators ) + { + this.activators = activators; + } public DefaultProfileSelector addProfileActivator( ProfileActivator profileActivator ) { diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java index 923ffd2eb3..999e070bce 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/FileProfileActivator.java @@ -55,14 +55,12 @@ public class FileProfileActivator implements ProfileActivator { - @Inject - private ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator; + private final ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator; - public FileProfileActivator setProfileActivationFilePathInterpolator( - ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator ) + @Inject + public FileProfileActivator( ProfileActivationFilePathInterpolator profileActivationFilePathInterpolator ) { this.profileActivationFilePathInterpolator = profileActivationFilePathInterpolator; - return this; } @Override diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java b/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java index 9d716234f3..31df92fad0 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/superpom/DefaultSuperPomProvider.java @@ -43,18 +43,17 @@ public class DefaultSuperPomProvider implements SuperPomProvider { + private final ModelProcessor modelProcessor; + /** * The cached super POM, lazily created. */ private Model superModel; @Inject - private ModelProcessor modelProcessor; - - public DefaultSuperPomProvider setModelProcessor( ModelProcessor modelProcessor ) + public DefaultSuperPomProvider( ModelProcessor modelProcessor ) { this.modelProcessor = modelProcessor; - return this; } @Override diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java index b499fc06a1..52400d8fe1 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java @@ -61,8 +61,7 @@ public class DefaultInheritanceAssemblerTest public void setUp() throws Exception { - reader = new DefaultModelReader(); - reader.setTransformer( new AbstractModelSourceTransformer() + reader = new DefaultModelReader( new AbstractModelSourceTransformer() { @Override protected AbstractSAXFilter getSAXFilter( Path pomFile, TransformerContext context, diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolatorTest.java index 7c90b07a1b..e4b11cca8c 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringVisitorModelInterpolatorTest.java @@ -23,6 +23,6 @@ public class StringVisitorModelInterpolatorTest extends AbstractModelInterpolato { protected ModelInterpolator createInterpolator() { - return new StringVisitorModelInterpolator(); + return new StringVisitorModelInterpolator( null, null ); } } \ No newline at end of file diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java index c665125e9f..cbdb850d4a 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java @@ -39,25 +39,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; public abstract class AbstractProfileActivatorTest { - private Class activatorClass; - protected T activator; - public AbstractProfileActivatorTest( Class activatorClass ) - { - this.activatorClass = Objects.requireNonNull( activatorClass, "activatorClass cannot be null" );; - } - @BeforeEach - public void setUp() - throws Exception - { - activator = activatorClass.getConstructor().newInstance(); - } + abstract void setUp() throws Exception; @AfterEach - public void tearDown() - throws Exception + void tearDown() throws Exception { activator = null; } diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java index acca98256d..300fc13539 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/FileProfileActivatorTest.java @@ -48,17 +48,11 @@ public class FileProfileActivatorTest extends AbstractProfileActivatorTest { - public JdkVersionProfileActivatorTest() + @Override + @BeforeEach + void setUp() throws Exception { - super( JdkVersionProfileActivator.class ); + activator = new JdkVersionProfileActivator(); } - private Profile newProfile( String jdkVersion ) + private Profile newProfile(String jdkVersion ) { Activation a = new Activation(); a.setJdk( jdkVersion ); diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java index 251ea7d602..72a6775623 100644 --- a/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java +++ b/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java @@ -24,6 +24,7 @@ import java.util.Properties; import org.apache.maven.model.Activation; import org.apache.maven.model.ActivationProperty; import org.apache.maven.model.Profile; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** @@ -35,12 +36,14 @@ public class PropertyProfileActivatorTest extends AbstractProfileActivatorTest { - public PropertyProfileActivatorTest() + @BeforeEach + @Override + void setUp() throws Exception { - super( PropertyProfileActivator.class ); + activator = new PropertyProfileActivator(); } - private Profile newProfile( String key, String value ) + private Profile newProfile(String key, String value ) { ActivationProperty ap = new ActivationProperty(); ap.setName( key ); diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java index 24c8570fc0..147f8b8a3f 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReader.java @@ -73,80 +73,35 @@ import org.slf4j.LoggerFactory; */ @Named @Singleton -public class DefaultArtifactDescriptorReader - implements ArtifactDescriptorReader +public class DefaultArtifactDescriptorReader implements ArtifactDescriptorReader { private static final Logger LOGGER = LoggerFactory.getLogger( DefaultArtifactDescriptorReader.class ); - private RemoteRepositoryManager remoteRepositoryManager; - - private VersionResolver versionResolver; - - private VersionRangeResolver versionRangeResolver; - - private ArtifactResolver artifactResolver; - - private RepositoryEventDispatcher repositoryEventDispatcher; - - private ModelBuilder modelBuilder; - - public DefaultArtifactDescriptorReader() - { - // enable no-arg constructor - } + private final RemoteRepositoryManager remoteRepositoryManager; + private final VersionResolver versionResolver; + private final VersionRangeResolver versionRangeResolver; + private final ArtifactResolver artifactResolver; + private final RepositoryEventDispatcher repositoryEventDispatcher; + private final ModelBuilder modelBuilder; @Inject - DefaultArtifactDescriptorReader( RemoteRepositoryManager remoteRepositoryManager, VersionResolver versionResolver, - VersionRangeResolver versionRangeResolver, ArtifactResolver artifactResolver, - ModelBuilder modelBuilder, RepositoryEventDispatcher repositoryEventDispatcher ) - { - setRemoteRepositoryManager( remoteRepositoryManager ); - setVersionResolver( versionResolver ); - setVersionRangeResolver( versionRangeResolver ); - setArtifactResolver( artifactResolver ); - setModelBuilder( modelBuilder ); - setRepositoryEventDispatcher( repositoryEventDispatcher ); - } - - public DefaultArtifactDescriptorReader setRemoteRepositoryManager( RemoteRepositoryManager remoteRepositoryManager ) + public DefaultArtifactDescriptorReader( + RemoteRepositoryManager remoteRepositoryManager, + VersionResolver versionResolver, + VersionRangeResolver versionRangeResolver, + ArtifactResolver artifactResolver, + ModelBuilder modelBuilder, + RepositoryEventDispatcher repositoryEventDispatcher ) { this.remoteRepositoryManager = Objects.requireNonNull( remoteRepositoryManager, - "remoteRepositoryManager cannot be null" ); - return this; - } - - public DefaultArtifactDescriptorReader setVersionResolver( VersionResolver versionResolver ) - { + "remoteRepositoryManager cannot be null" ); this.versionResolver = Objects.requireNonNull( versionResolver, "versionResolver cannot be null" ); - return this; - } - - /** @since 3.2.2 */ - public DefaultArtifactDescriptorReader setVersionRangeResolver( VersionRangeResolver versionRangeResolver ) - { this.versionRangeResolver = - Objects.requireNonNull( versionRangeResolver, "versionRangeResolver cannot be null" ); - return this; - } - - public DefaultArtifactDescriptorReader setArtifactResolver( ArtifactResolver artifactResolver ) - { + Objects.requireNonNull( versionRangeResolver, "versionRangeResolver cannot be null" ); this.artifactResolver = Objects.requireNonNull( artifactResolver, "artifactResolver cannot be null" ); - return this; - } - - public DefaultArtifactDescriptorReader setRepositoryEventDispatcher( - RepositoryEventDispatcher repositoryEventDispatcher ) - { - this.repositoryEventDispatcher = Objects.requireNonNull( repositoryEventDispatcher, - "repositoryEventDispatcher cannot be null" ); - return this; - } - - public DefaultArtifactDescriptorReader setModelBuilder( ModelBuilder modelBuilder ) - { this.modelBuilder = Objects.requireNonNull( modelBuilder, "modelBuilder cannot be null" ); - return this; + this.repositoryEventDispatcher = Objects.requireNonNull( repositoryEventDispatcher, + "repositoryEventDispatcher cannot be null" ); } public ArtifactDescriptorResult readArtifactDescriptor( RepositorySystemSession session, diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java index f2b736ed34..379d05ce1f 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java @@ -70,46 +70,19 @@ public class DefaultVersionRangeResolver private static final String MAVEN_METADATA_XML = "maven-metadata.xml"; - private MetadataResolver metadataResolver; - - private SyncContextFactory syncContextFactory; - - private RepositoryEventDispatcher repositoryEventDispatcher; - - public DefaultVersionRangeResolver() - { - // enable default constructor - } + private final MetadataResolver metadataResolver; + private final SyncContextFactory syncContextFactory; + private final RepositoryEventDispatcher repositoryEventDispatcher; @Inject - DefaultVersionRangeResolver( MetadataResolver metadataResolver, SyncContextFactory syncContextFactory, - RepositoryEventDispatcher repositoryEventDispatcher ) - { - setMetadataResolver( metadataResolver ); - setSyncContextFactory( syncContextFactory ); - setRepositoryEventDispatcher( repositoryEventDispatcher ); - } - - public DefaultVersionRangeResolver setMetadataResolver( MetadataResolver metadataResolver ) + public DefaultVersionRangeResolver( MetadataResolver metadataResolver, SyncContextFactory syncContextFactory, + RepositoryEventDispatcher repositoryEventDispatcher ) { this.metadataResolver = Objects.requireNonNull( metadataResolver, "metadataResolver cannot be null" ); - return this; - } - - public DefaultVersionRangeResolver setSyncContextFactory( SyncContextFactory syncContextFactory ) - { this.syncContextFactory = Objects.requireNonNull( syncContextFactory, "syncContextFactory cannot be null" ); - return this; - } - - public DefaultVersionRangeResolver setRepositoryEventDispatcher( - RepositoryEventDispatcher repositoryEventDispatcher ) - { this.repositoryEventDispatcher = Objects.requireNonNull( repositoryEventDispatcher, - "repositoryEventDispatcher cannot be null" ); - return this; + "repositoryEventDispatcher cannot be null" ); } - public VersionRangeResult resolveVersionRange( RepositorySystemSession session, VersionRangeRequest request ) throws VersionRangeResolutionException { diff --git a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java index fefd60aec2..e70a8b98aa 100644 --- a/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java +++ b/maven-resolver-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java @@ -81,43 +81,18 @@ public class DefaultVersionResolver private static final String SNAPSHOT = "SNAPSHOT"; - private MetadataResolver metadataResolver; - - private SyncContextFactory syncContextFactory; - - private RepositoryEventDispatcher repositoryEventDispatcher; - - public DefaultVersionResolver() - { - // enable no-arg constructor - } + private final MetadataResolver metadataResolver; + private final SyncContextFactory syncContextFactory; + private final RepositoryEventDispatcher repositoryEventDispatcher; @Inject - DefaultVersionResolver( MetadataResolver metadataResolver, SyncContextFactory syncContextFactory, + public DefaultVersionResolver( MetadataResolver metadataResolver, SyncContextFactory syncContextFactory, RepositoryEventDispatcher repositoryEventDispatcher ) - { - setMetadataResolver( metadataResolver ); - setSyncContextFactory( syncContextFactory ); - setRepositoryEventDispatcher( repositoryEventDispatcher ); - } - - public DefaultVersionResolver setMetadataResolver( MetadataResolver metadataResolver ) { this.metadataResolver = Objects.requireNonNull( metadataResolver, "metadataResolver cannot be null" ); - return this; - } - - public DefaultVersionResolver setSyncContextFactory( SyncContextFactory syncContextFactory ) - { this.syncContextFactory = Objects.requireNonNull( syncContextFactory, "syncContextFactory cannot be null" ); - return this; - } - - public DefaultVersionResolver setRepositoryEventDispatcher( RepositoryEventDispatcher repositoryEventDispatcher ) - { this.repositoryEventDispatcher = Objects.requireNonNull( repositoryEventDispatcher, - "repositoryEventDispatcher cannot be null" ); - return this; + "repositoryEventDispatcher cannot be null" ); } @SuppressWarnings( "checkstyle:methodlength" ) diff --git a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java index a68a42f0db..733fa59c0f 100644 --- a/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java +++ b/maven-resolver-provider/src/test/java/org/apache/maven/repository/internal/DefaultArtifactDescriptorReaderTest.java @@ -19,6 +19,8 @@ package org.apache.maven.repository.internal; * under the License. */ +import java.lang.reflect.Field; + import org.eclipse.aether.RepositoryEvent; import org.eclipse.aether.RepositoryEvent.EventType; import org.eclipse.aether.artifact.DefaultArtifact; @@ -48,7 +50,9 @@ public class DefaultArtifactDescriptorReaderTest ArgumentCaptor event = ArgumentCaptor.forClass( RepositoryEvent.class ); - reader.setRepositoryEventDispatcher( eventDispatcher ); + Field field = DefaultArtifactDescriptorReader.class.getDeclaredField( "repositoryEventDispatcher" ); + field.setAccessible( true ); + field.set( reader, eventDispatcher ); ArtifactDescriptorRequest request = new ArtifactDescriptorRequest();