[MNG-7999] Confine Plexus Container as much as possible (#1367)

This is an ongoing effort to confine Plexus, but also perform a bit of cleanup in Maven Core and around. No logic changes, just replacing Plexus with Lookup (that is a thin wrapper around it), and removing unused members, redundant checks, etc. Module maven-compat omitted on purpose.

---

https://issues.apache.org/jira/browse/MNG-7999
This commit is contained in:
Tamas Cservenak 2024-01-10 13:55:54 +01:00 committed by GitHub
parent 2c06637fb4
commit cfa13f5cc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 274 additions and 199 deletions

View File

@ -20,16 +20,77 @@ package org.apache.maven.api.services;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.maven.api.Service;
import org.apache.maven.api.annotations.Nonnull;
public interface Lookup extends Service {
/**
* Performs a lookup for given typed component.
*
* @param type The component type.
* @return The component.
* @param <T> The component type.
* @throws LookupException if no such component or there is some provisioning related issue.
*/
@Nonnull
<T> T lookup(Class<T> type);
/**
* Performs a lookup for given typed component.
*
* @param type The component type.
* @param name The component name.
* @return The component.
* @param <T> The component type.
* @throws LookupException if no such component or there is some provisioning related issue.
*/
@Nonnull
<T> T lookup(Class<T> type, String name);
/**
* Performs a lookup for optional typed component.
*
* @param type The component type.
* @return Optional carrying component or empty optional if no such component.
* @param <T> The component type.
* @throws LookupException if there is some provisioning related issue.
*/
@Nonnull
<T> Optional<T> lookupOptional(Class<T> type);
/**
* Performs a lookup for optional typed component.
*
* @param type The component type.
* @param name The component name.
* @return Optional carrying component or empty optional if no such component.
* @param <T> The component type.
* @throws LookupException if there is some provisioning related issue.
*/
@Nonnull
<T> Optional<T> lookupOptional(Class<T> type, String name);
/**
* Performs a collection lookup for given typed components.
*
* @param type The component type.
* @return The list of components. The list may be empty if no components found.
* @param <T> The component type.
* @throws LookupException if there is some provisioning related issue.
*/
@Nonnull
<T> List<T> lookupList(Class<T> type);
/**
* Performs a collection lookup for given typed components.
*
* @param type The component type.
* @return The map of components. The map may be empty if no components found.
* @param <T> The component type.
* @throws LookupException if there is some provisioning related issue.
*/
@Nonnull
<T> Map<String, T> lookupMap(Class<T> type);
}

View File

@ -39,6 +39,7 @@ import org.apache.maven.bridge.MavenRepositorySystem;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.internal.impl.DefaultLookup;
import org.apache.maven.internal.impl.DefaultSessionFactory;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.repository.legacy.repository.ArtifactRepositoryFactory;
@ -107,7 +108,7 @@ public abstract class AbstractArtifactComponentTestCase // extends PlexusTestCas
new DefaultSessionFactory(
getContainer().lookup(RepositorySystem.class),
getContainer().lookup(MavenRepositorySystem.class),
getContainer(),
new DefaultLookup(getContainer()),
getContainer().lookup(RuntimeInformation.class))
.getSession(session);

View File

@ -43,6 +43,8 @@ import org.apache.maven.api.Session;
import org.apache.maven.api.model.Model;
import org.apache.maven.api.model.Prerequisites;
import org.apache.maven.api.model.Profile;
import org.apache.maven.api.services.Lookup;
import org.apache.maven.api.services.LookupException;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.execution.BuildResumptionAnalyzer;
import org.apache.maven.execution.BuildResumptionDataRepository;
@ -69,10 +71,7 @@ import org.apache.maven.model.building.Result;
import org.apache.maven.model.superpom.SuperPomProvider;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.session.scope.internal.SessionScope;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession.CloseableSession;
import org.eclipse.aether.repository.WorkspaceReader;
@ -89,19 +88,17 @@ import static java.util.stream.Collectors.toSet;
public class DefaultMaven implements Maven {
private final Logger logger = LoggerFactory.getLogger(getClass());
protected ProjectBuilder projectBuilder;
private final Lookup lookup;
private LifecycleStarter lifecycleStarter;
private final LifecycleStarter lifecycleStarter;
protected PlexusContainer container;
private final ExecutionEventCatapult eventCatapult;
private ExecutionEventCatapult eventCatapult;
private final LegacySupport legacySupport;
private LegacySupport legacySupport;
private final SessionScope sessionScope;
private SessionScope sessionScope;
private DefaultRepositorySystemSessionFactory repositorySessionFactory;
private final DefaultRepositorySystemSessionFactory repositorySessionFactory;
private final GraphBuilder graphBuilder;
@ -118,9 +115,8 @@ public class DefaultMaven implements Maven {
@Inject
@SuppressWarnings("checkstyle:ParameterNumber")
public DefaultMaven(
ProjectBuilder projectBuilder,
Lookup lookup,
LifecycleStarter lifecycleStarter,
PlexusContainer container,
ExecutionEventCatapult eventCatapult,
LegacySupport legacySupport,
SessionScope sessionScope,
@ -130,9 +126,8 @@ public class DefaultMaven implements Maven {
BuildResumptionDataRepository buildResumptionDataRepository,
SuperPomProvider superPomProvider,
DefaultSessionFactory defaultSessionFactory) {
this.projectBuilder = projectBuilder;
this.lookup = lookup;
this.lifecycleStarter = lifecycleStarter;
this.container = container;
this.eventCatapult = eventCatapult;
this.legacySupport = legacySupport;
this.sessionScope = sessionScope;
@ -243,9 +238,9 @@ public class DefaultMaven implements Maven {
}
try {
WorkspaceReader reactorReader = container.lookup(WorkspaceReader.class, ReactorReader.HINT);
WorkspaceReader reactorReader = lookup.lookup(WorkspaceReader.class, ReactorReader.HINT);
chainedWorkspaceReader.setReaders(Collections.singletonList(reactorReader));
} catch (ComponentLookupException e) {
} catch (LookupException e) {
return addExceptionToResult(result, e);
}
@ -266,7 +261,7 @@ public class DefaultMaven implements Maven {
try {
setupWorkspaceReader(session, chainedWorkspaceReader);
} catch (ComponentLookupException e) {
} catch (LookupException e) {
return addExceptionToResult(result, e);
}
try {
@ -328,19 +323,18 @@ public class DefaultMaven implements Maven {
try {
afterSessionEnd(session);
} catch (MavenExecutionException e) {
return addExceptionToResult(result, e);
addExceptionToResult(result, e);
}
}
return result;
}
private void setupWorkspaceReader(MavenSession session, MavenChainedWorkspaceReader chainedWorkspaceReader)
throws ComponentLookupException {
private void setupWorkspaceReader(MavenSession session, MavenChainedWorkspaceReader chainedWorkspaceReader) {
// Desired order of precedence for workspace readers before querying the local artifact repositories
Set<WorkspaceReader> workspaceReaders = new LinkedHashSet<>();
// 1) Reactor workspace reader
WorkspaceReader reactorReader = container.lookup(WorkspaceReader.class, ReactorReader.HINT);
WorkspaceReader reactorReader = lookup.lookup(WorkspaceReader.class, ReactorReader.HINT);
workspaceReaders.add(reactorReader);
// 2) Repository system session-scoped workspace reader
for (WorkspaceReader repoWorkspaceReader : chainedWorkspaceReader.getReaders()) {
@ -435,16 +429,8 @@ public class DefaultMaven implements Maven {
private <T> Collection<T> getExtensionComponents(Collection<MavenProject> projects, Class<T> role) {
Collection<T> foundComponents = new LinkedHashSet<>();
try {
foundComponents.addAll(container.lookupList(role));
} catch (ComponentLookupException e) {
// this is just silly, lookupList should return an empty list!
logger.warn("Failed to lookup {}: {}", role, e.getMessage());
}
foundComponents.addAll(lookup.lookupList(role));
foundComponents.addAll(getProjectScopedExtensionComponents(projects, role));
return foundComponents;
}
@ -464,13 +450,7 @@ public class DefaultMaven implements Maven {
if (projectRealm != null && scannedRealms.add(projectRealm)) {
currentThread.setContextClassLoader(projectRealm);
try {
foundComponents.addAll(container.lookupList(role));
} catch (ComponentLookupException e) {
// this is just silly, lookupList should return an empty list!
logger.warn("Failed to lookup {}: {}", role, e.getMessage());
}
foundComponents.addAll(lookup.lookupList(role));
}
}
return foundComponents;

View File

@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.maven.api.services.Lookup;
import org.apache.maven.eventspy.EventSpy;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.MavenSession;
@ -41,7 +42,6 @@ import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.ProjectArtifact;
import org.apache.maven.repository.internal.MavenWorkspaceReader;
import org.codehaus.plexus.PlexusContainer;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.repository.WorkspaceRepository;
import org.eclipse.aether.util.artifact.ArtifactIdUtils;
@ -504,11 +504,11 @@ class ReactorReader implements MavenWorkspaceReader {
@SuppressWarnings("unused")
static class ReactorReaderSpy implements EventSpy {
final PlexusContainer container;
private final Lookup lookup;
@Inject
ReactorReaderSpy(PlexusContainer container) {
this.container = container;
ReactorReaderSpy(Lookup lookup) {
this.lookup = lookup;
}
@Override
@ -518,7 +518,7 @@ class ReactorReader implements MavenWorkspaceReader {
@SuppressWarnings("checkstyle:MissingSwitchDefault")
public void onEvent(Object event) throws Exception {
if (event instanceof ExecutionEvent) {
ReactorReader reactorReader = container.lookup(ReactorReader.class);
ReactorReader reactorReader = lookup.lookup(ReactorReader.class);
reactorReader.processEvent((ExecutionEvent) event);
}
}

View File

@ -23,8 +23,6 @@ import org.apache.maven.api.plugin.Log;
import org.apache.maven.execution.scope.MojoExecutionScoped;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
/**
* MojoExecutionScopeModule
@ -32,11 +30,7 @@ import org.codehaus.plexus.component.repository.exception.ComponentLookupExcepti
public class MojoExecutionScopeModule extends AbstractModule {
protected final MojoExecutionScope scope;
public MojoExecutionScopeModule(PlexusContainer container) throws ComponentLookupException {
this(container.lookup(MojoExecutionScope.class));
}
protected MojoExecutionScopeModule(MojoExecutionScope scope) {
public MojoExecutionScopeModule(MojoExecutionScope scope) {
this.scope = scope;
}

View File

@ -24,6 +24,8 @@ import javax.inject.Singleton;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import org.apache.maven.api.services.Lookup;
import org.apache.maven.api.services.LookupException;
@ -59,6 +61,30 @@ public class DefaultLookup implements Lookup {
}
}
@Override
public <T> Optional<T> lookupOptional(Class<T> type) {
try {
return Optional.of(container.lookup(type));
} catch (ComponentLookupException e) {
if (e.getCause() instanceof NoSuchElementException) {
return Optional.empty();
}
throw new LookupException(e);
}
}
@Override
public <T> Optional<T> lookupOptional(Class<T> type, String name) {
try {
return Optional.of(container.lookup(type, name));
} catch (ComponentLookupException e) {
if (e.getCause() instanceof NoSuchElementException) {
return Optional.empty();
}
throw new LookupException(e);
}
}
@Override
public <T> List<T> lookupList(Class<T> type) {
try {

View File

@ -35,7 +35,6 @@ import org.apache.maven.api.di.SessionScoped;
import org.apache.maven.api.model.Resource;
import org.apache.maven.api.services.*;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.PlexusContainer;
import org.eclipse.sisu.Typed;
import static org.apache.maven.internal.impl.Utils.map;
@ -47,13 +46,11 @@ public class DefaultProjectManager implements ProjectManager {
private final InternalSession session;
private final ArtifactManager artifactManager;
private final PlexusContainer container;
@Inject
public DefaultProjectManager(InternalSession session, ArtifactManager artifactManager, PlexusContainer container) {
public DefaultProjectManager(InternalSession session, ArtifactManager artifactManager) {
this.session = session;
this.artifactManager = artifactManager;
this.container = container;
}
@Nonnull

View File

@ -32,6 +32,8 @@ import org.apache.maven.RepositoryUtils;
import org.apache.maven.api.*;
import org.apache.maven.api.annotations.Nonnull;
import org.apache.maven.api.annotations.Nullable;
import org.apache.maven.api.services.Lookup;
import org.apache.maven.api.services.LookupException;
import org.apache.maven.api.services.MavenException;
import org.apache.maven.api.settings.Settings;
import org.apache.maven.artifact.repository.ArtifactRepository;
@ -41,8 +43,6 @@ import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
@ -57,7 +57,7 @@ public class DefaultSession extends AbstractSession {
private final RepositorySystem repositorySystem;
private final List<RemoteRepository> repositories;
private final MavenRepositorySystem mavenRepositorySystem;
private final PlexusContainer container;
private final Lookup lookup;
private final RuntimeInformation runtimeInformation;
private final Map<Class<? extends Service>, Service> services = new ConcurrentHashMap<>();
@ -67,7 +67,7 @@ public class DefaultSession extends AbstractSession {
@Nonnull RepositorySystem repositorySystem,
@Nullable List<RemoteRepository> repositories,
@Nonnull MavenRepositorySystem mavenRepositorySystem,
@Nonnull PlexusContainer container,
@Nonnull Lookup lookup,
@Nonnull RuntimeInformation runtimeInformation) {
this.mavenSession = nonNull(session);
this.session = mavenSession.getRepositorySession();
@ -78,7 +78,7 @@ public class DefaultSession extends AbstractSession {
mavenSession.getRequest().getRemoteRepositories(),
r -> getRemoteRepository(RepositoryUtils.toRepo(r)));
this.mavenRepositorySystem = mavenRepositorySystem;
this.container = container;
this.lookup = lookup;
this.runtimeInformation = runtimeInformation;
}
@ -154,11 +154,11 @@ public class DefaultSession extends AbstractSession {
public Map<String, Object> getPluginContext(Project project) {
nonNull(project, "project");
try {
MojoExecution mojoExecution = container.lookup(MojoExecution.class);
MojoExecution mojoExecution = lookup.lookup(MojoExecution.class);
MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
return mavenSession.getPluginContext(pluginDescriptor, ((DefaultProject) project).getProject());
} catch (ComponentLookupException e) {
} catch (LookupException e) {
throw new MavenException("The PluginContext is only available during a mojo execution", e);
}
}
@ -208,14 +208,14 @@ public class DefaultSession extends AbstractSession {
new DefaultRepositorySystemSession(session).setLocalRepositoryManager(localRepositoryManager);
MavenSession newSession = new MavenSession(repoSession, mavenSession.getRequest(), mavenSession.getResult());
return new DefaultSession(
newSession, repositorySystem, repositories, mavenRepositorySystem, container, runtimeInformation);
newSession, repositorySystem, repositories, mavenRepositorySystem, lookup, runtimeInformation);
}
@Nonnull
@Override
public Session withRemoteRepositories(@Nonnull List<RemoteRepository> repositories) {
return new DefaultSession(
mavenSession, repositorySystem, repositories, mavenRepositorySystem, container, runtimeInformation);
mavenSession, repositorySystem, repositories, mavenRepositorySystem, lookup, runtimeInformation);
}
@Nonnull
@ -231,8 +231,8 @@ public class DefaultSession extends AbstractSession {
private Service lookup(Class<? extends Service> c) {
try {
return container.lookup(c);
} catch (ComponentLookupException e) {
return lookup.lookup(c);
} catch (LookupException e) {
NoSuchElementException nsee = new NoSuchElementException(c.getName());
e.initCause(e);
throw nsee;

View File

@ -23,10 +23,10 @@ import javax.inject.Named;
import javax.inject.Singleton;
import org.apache.maven.api.Session;
import org.apache.maven.api.services.Lookup;
import org.apache.maven.bridge.MavenRepositorySystem;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.codehaus.plexus.PlexusContainer;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.SessionData;
@ -35,7 +35,7 @@ import org.eclipse.aether.SessionData;
public class DefaultSessionFactory {
private final RepositorySystem repositorySystem;
private final MavenRepositorySystem mavenRepositorySystem;
private final PlexusContainer plexusContainer;
private final Lookup lookup;
private final RuntimeInformation runtimeInformation;
@Inject
@ -43,11 +43,11 @@ public class DefaultSessionFactory {
public DefaultSessionFactory(
RepositorySystem repositorySystem,
MavenRepositorySystem mavenRepositorySystem,
PlexusContainer plexusContainer,
Lookup lookup,
RuntimeInformation runtimeInformation) {
this.repositorySystem = repositorySystem;
this.mavenRepositorySystem = mavenRepositorySystem;
this.plexusContainer = plexusContainer;
this.lookup = lookup;
this.runtimeInformation = runtimeInformation;
}
@ -58,6 +58,6 @@ public class DefaultSessionFactory {
private Session newSession(MavenSession mavenSession) {
return new DefaultSession(
mavenSession, repositorySystem, null, mavenRepositorySystem, plexusContainer, runtimeInformation);
mavenSession, repositorySystem, null, mavenRepositorySystem, lookup, runtimeInformation);
}
}

View File

@ -26,7 +26,6 @@ import java.nio.file.Path;
import org.apache.maven.api.model.Model;
import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.eclipse.aether.RepositorySystemSession;
/**
@ -36,5 +35,5 @@ import org.eclipse.aether.RepositorySystemSession;
interface ConsumerPomBuilder {
Model build(RepositorySystemSession session, MavenProject project, Path src)
throws ModelBuildingException, ComponentLookupException, IOException, XMLStreamException;
throws ModelBuildingException, IOException, XMLStreamException;
}

View File

@ -41,7 +41,6 @@ import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.v4.MavenStaxWriter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.ProjectArtifact;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.artifact.DefaultArtifact;
@ -113,7 +112,7 @@ class DefaultConsumerPomArtifactTransformer implements ConsumerPomArtifactTransf
}
void transform(MavenProject project, RepositorySystemSession session, Path src, Path tgt)
throws ModelBuildingException, ComponentLookupException, XMLStreamException, IOException {
throws ModelBuildingException, XMLStreamException, IOException {
Model model = builder.build(session, project, src);
write(model, tgt);
}

View File

@ -35,7 +35,6 @@ import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.internal.transformation.TransformationFailedException;
import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.eclipse.aether.RepositorySystemSession;
/**
@ -97,18 +96,13 @@ class TransformedArtifact extends DefaultArtifact {
return null;
}
return target.toFile();
} catch (IOException
| NoSuchAlgorithmException
| XMLStreamException
| ModelBuildingException
| ComponentLookupException e) {
} catch (IOException | NoSuchAlgorithmException | XMLStreamException | ModelBuildingException e) {
throw new TransformationFailedException(e);
}
}
private String mayUpdate()
throws IOException, NoSuchAlgorithmException, XMLStreamException, ModelBuildingException,
ComponentLookupException {
throws IOException, NoSuchAlgorithmException, XMLStreamException, ModelBuildingException {
String result;
Path src = sourcePathProvider.get();
if (src == null) {

View File

@ -31,7 +31,6 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
import org.apache.maven.lifecycle.internal.LifecycleStarter;
import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
import org.apache.maven.lifecycle.internal.MojoExecutor;
import org.apache.maven.lifecycle.internal.ProjectIndex;
import org.apache.maven.lifecycle.internal.TaskSegment;
@ -49,7 +48,7 @@ import org.apache.maven.project.MavenProject;
/**
* A facade that provides lifecycle services to components outside maven core.
*
* <p>
* Note that this component is not normally used from within core itself.
*
*/
@ -63,7 +62,6 @@ public class DefaultLifecycleExecutor implements LifecycleExecutor {
private final LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator;
private final MojoExecutor mojoExecutor;
private final LifecycleStarter lifecycleStarter;
private final MojoDescriptorCreator mojoDescriptorCreator;
@Inject
public DefaultLifecycleExecutor(
@ -72,15 +70,13 @@ public class DefaultLifecycleExecutor implements LifecycleExecutor {
LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator,
LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator,
MojoExecutor mojoExecutor,
LifecycleStarter lifecycleStarter,
MojoDescriptorCreator mojoDescriptorCreator) {
LifecycleStarter lifecycleStarter) {
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) {

View File

@ -30,8 +30,8 @@ import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.apache.maven.api.services.Lookup;
import org.apache.maven.api.services.LookupException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -49,26 +49,26 @@ public class DefaultLifecycles {
// @Configuration(source="org/apache/maven/lifecycle/lifecycles.xml")
private final PlexusContainer plexusContainer;
private final Lookup lookup;
private Map<String, Lifecycle> customLifecycles;
public DefaultLifecycles() {
this.plexusContainer = null;
this.lookup = null;
}
/**
* @deprecated Rely on {@link #DefaultLifecycles(PlexusContainer)} instead
* @deprecated Rely on {@link #DefaultLifecycles(Lookup)} instead
*/
@Deprecated
public DefaultLifecycles(Map<String, Lifecycle> lifecycles, org.codehaus.plexus.logging.Logger logger) {
this.customLifecycles = lifecycles;
this.plexusContainer = null;
this.lookup = null;
}
@Inject
public DefaultLifecycles(PlexusContainer plexusContainer) {
this.plexusContainer = plexusContainer;
public DefaultLifecycles(Lookup lookup) {
this.lookup = lookup;
}
/**
@ -143,14 +143,14 @@ public class DefaultLifecycles {
private Map<String, Lifecycle> lookupLifecycles() {
// TODO: Remove the following code when maven-compat is gone
// This code is here to ensure maven-compat's EmptyLifecycleExecutor keeps on working.
if (plexusContainer == null) {
if (lookup == null) {
return customLifecycles != null ? customLifecycles : new HashMap<>();
}
// Lifecycles cannot be cached as extensions might add custom lifecycles later in the execution.
try {
return plexusContainer.lookupMap(Lifecycle.class);
} catch (ComponentLookupException e) {
return lookup.lookupMap(Lifecycle.class);
} catch (LookupException e) {
throw new IllegalStateException("Unable to lookup lifecycles from the plexus container", e);
}
}

View File

@ -118,10 +118,7 @@ public class MavenExecutionPlan implements Iterable<ExecutionPlanItem> {
List<ExecutionPlanItem> planItems) {
LinkedHashSet<String> result = new LinkedHashSet<>();
for (ExecutionPlanItem executionPlanItem : planItems) {
final String phase = executionPlanItem.getLifecyclePhase();
if (!result.contains(phase)) {
result.add(phase);
}
result.add(executionPlanItem.getLifecyclePhase());
}
return result;
}

View File

@ -29,6 +29,7 @@ public class BuildThreadFactory implements ThreadFactory {
private static final String PREFIX = "BuilderThread";
@Override
public Thread newThread(Runnable r) {
return new Thread(r, String.format("%s-%d", PREFIX, id.getAndIncrement()));
}

View File

@ -31,24 +31,28 @@ class CompoundProjectExecutionListener implements ProjectExecutionListener {
this.listeners = listeners; // NB this is live injected collection
}
@Override
public void beforeProjectExecution(ProjectExecutionEvent event) throws LifecycleExecutionException {
for (ProjectExecutionListener listener : listeners) {
listener.beforeProjectExecution(event);
}
}
@Override
public void beforeProjectLifecycleExecution(ProjectExecutionEvent event) throws LifecycleExecutionException {
for (ProjectExecutionListener listener : listeners) {
listener.beforeProjectLifecycleExecution(event);
}
}
@Override
public void afterProjectExecutionSuccess(ProjectExecutionEvent event) throws LifecycleExecutionException {
for (ProjectExecutionListener listener : listeners) {
listener.afterProjectExecutionSuccess(event);
}
}
@Override
public void afterProjectExecutionFailure(ProjectExecutionEvent event) {
for (ProjectExecutionListener listener : listeners) {
listener.afterProjectExecutionFailure(event);

View File

@ -44,22 +44,27 @@ class DefaultExecutionEvent implements ExecutionEvent {
this.exception = exception;
}
@Override
public Type getType() {
return type;
}
@Override
public MavenSession getSession() {
return session;
}
@Override
public MavenProject getProject() {
return session.getCurrentProject();
}
@Override
public MojoExecution getMojoExecution() {
return mojoExecution;
}
@Override
public Exception getException() {
return exception;
}

View File

@ -36,10 +36,12 @@ import org.apache.maven.plugin.MojoExecution;
@Singleton
public class DefaultExecutionEventCatapult implements ExecutionEventCatapult {
@Override
public void fire(ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution) {
fire(eventType, session, mojoExecution, null);
}
@Override
public void fire(
ExecutionEvent.Type eventType, MavenSession session, MojoExecution mojoExecution, Exception exception) {
ExecutionListener listener = session.getRequest().getExecutionListener();

View File

@ -106,8 +106,7 @@ public class DefaultLifecycleExecutionPlanCalculator implements LifecycleExecuti
this.lifecyclePluginResolver = lifecyclePluginResolver;
this.standardDelegate = null;
this.delegates = null;
this.mojoExecutionConfigurators =
Collections.singletonMap("default", (MojoExecutionConfigurator) new DefaultMojoExecutionConfigurator());
this.mojoExecutionConfigurators = Collections.singletonMap("default", new DefaultMojoExecutionConfigurator());
}
@Override

View File

@ -60,6 +60,7 @@ public class DefaultLifecycleMappingDelegate implements LifecycleMappingDelegate
this.pluginManager = pluginManager;
}
@Override
public Map<String, List<MojoExecution>> calculateLifecycleMappings(
MavenSession session, MavenProject project, Lifecycle lifecycle, String lifecyclePhase)
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,

View File

@ -26,9 +26,9 @@ import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import org.apache.maven.api.services.Lookup;
import org.apache.maven.api.xml.XmlNode;
import org.apache.maven.lifecycle.DefaultLifecycles;
import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer;
@ -40,8 +40,6 @@ import org.apache.maven.model.InputLocation;
import org.apache.maven.model.InputSource;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -62,14 +60,13 @@ public class DefaultLifecyclePluginAnalyzer implements LifeCyclePluginAnalyzer {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final PlexusContainer plexusContainer;
private final Lookup lookup;
private final DefaultLifecycles defaultLifeCycles;
@Inject
public DefaultLifecyclePluginAnalyzer(
final PlexusContainer plexusContainer, final DefaultLifecycles defaultLifeCycles) {
this.plexusContainer = requireNonNull(plexusContainer);
public DefaultLifecyclePluginAnalyzer(Lookup lookup, DefaultLifecycles defaultLifeCycles) {
this.lookup = requireNonNull(lookup);
this.defaultLifeCycles = requireNonNull(defaultLifeCycles);
}
@ -129,14 +126,7 @@ public class DefaultLifecyclePluginAnalyzer implements LifeCyclePluginAnalyzer {
* from current module and for example not extensions coming from other modules.
*/
private LifecycleMapping lookupLifecycleMapping(final String packaging) {
try {
return plexusContainer.lookup(LifecycleMapping.class, packaging);
} catch (ComponentLookupException e) {
if (e.getCause() instanceof NoSuchElementException) {
return null;
}
throw new RuntimeException(e);
}
return lookup.lookupOptional(LifecycleMapping.class, packaging).orElse(null);
}
private void parseLifecyclePhaseDefinitions(Map<Plugin, Plugin> plugins, String phase, LifecyclePhase goals) {

View File

@ -40,6 +40,8 @@ import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.MavenProject;
import static java.util.Objects.requireNonNull;
/**
* <p>
* Calculates the task segments in the build
@ -62,6 +64,7 @@ public class DefaultLifecycleTaskSegmentCalculator implements LifecycleTaskSegme
this.lifecyclePluginResolver = lifecyclePluginResolver;
}
@Override
public List<TaskSegment> calculateTaskSegments(MavenSession session)
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
@ -69,9 +72,9 @@ public class DefaultLifecycleTaskSegmentCalculator implements LifecycleTaskSegme
MavenProject rootProject = session.getTopLevelProject();
List<String> tasks = session.getGoals();
List<String> tasks = requireNonNull(session.getGoals()); // session never returns null, but empty list
if ((tasks == null || tasks.isEmpty())
if (tasks.isEmpty()
&& (rootProject.getDefaultGoal() != null
&& !rootProject.getDefaultGoal().isEmpty())) {
tasks = Stream.of(rootProject.getDefaultGoal().split("\\s+"))
@ -82,6 +85,7 @@ public class DefaultLifecycleTaskSegmentCalculator implements LifecycleTaskSegme
return calculateTaskSegments(session, tasks);
}
@Override
public List<TaskSegment> calculateTaskSegments(MavenSession session, List<String> tasks)
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
@ -122,6 +126,7 @@ public class DefaultLifecycleTaskSegmentCalculator implements LifecycleTaskSegme
return taskSegments;
}
@Override
public boolean requiresProject(MavenSession session) {
List<String> goals = session.getGoals();
if (goals != null) {

View File

@ -30,6 +30,7 @@ import java.util.stream.Stream;
import org.apache.maven.api.services.MessageBuilder;
import org.apache.maven.api.services.MessageBuilderFactory;
import org.apache.maven.api.xml.XmlNode;
import org.apache.maven.internal.impl.DefaultMessageBuilderFactory;
import org.apache.maven.internal.xml.XmlNodeImpl;
import org.apache.maven.lifecycle.MojoExecutionConfigurator;
import org.apache.maven.model.Plugin;
@ -43,6 +44,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.util.Arrays.stream;
import static java.util.Objects.requireNonNull;
/**
* @since 3.3.1, MNG-5753
@ -52,8 +54,23 @@ import static java.util.Arrays.stream;
public class DefaultMojoExecutionConfigurator implements MojoExecutionConfigurator {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final MessageBuilderFactory messageBuilderFactory;
/**
* Default ctor is used in IT and most probably some 3rd party code. For those cases, we do provide sane defaults
* but given this is a component, injection should be used, replacing direct instantiation.
*
* @deprecated Do not use this ctor directly, inject this component instead.
*/
@Deprecated
public DefaultMojoExecutionConfigurator() {
this.messageBuilderFactory = new DefaultMessageBuilderFactory();
}
@Inject
MessageBuilderFactory messageBuilderFactory;
public DefaultMojoExecutionConfigurator(MessageBuilderFactory messageBuilderFactory) {
this.messageBuilderFactory = requireNonNull(messageBuilderFactory);
}
@Override
public void configure(MavenProject project, MojoExecution mojoExecution, boolean allowPluginLevelConfig) {

View File

@ -18,10 +18,7 @@
*/
package org.apache.maven.lifecycle.internal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.TreeSet;
import java.util.*;
import org.apache.maven.project.MavenProject;
@ -36,8 +33,6 @@ import org.apache.maven.project.MavenProject;
// TODO From a concurrency perspective, this class is not good. The combination of mutable/immutable state is not nice
public class DependencyContext {
private static final Collection<?> UNRESOLVED = Arrays.asList();
private final MavenProject project;
private final Collection<String> scopesToCollectForCurrentProject;
@ -48,7 +43,7 @@ public class DependencyContext {
private final Collection<String> scopesToResolveForAggregatedProjects;
private volatile Collection<?> lastDependencyArtifacts = UNRESOLVED;
private volatile Collection<?> lastDependencyArtifacts = Collections.emptyList();
private volatile int lastDependencyArtifactCount = -1;

View File

@ -346,7 +346,7 @@ public class LifecycleDependencyResolver {
private static class ReactorDependencyFilter implements DependencyFilter {
private Set<String> keys = new HashSet<>();
private final Set<String> keys = new HashSet<>();
ReactorDependencyFilter(Collection<Artifact> artifacts) {
for (Artifact artifact : artifacts) {

View File

@ -35,7 +35,6 @@ import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.lifecycle.internal.builder.BuilderCommon;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.apache.maven.session.scope.internal.SessionScope;
/**
* <p>
@ -54,7 +53,6 @@ public class LifecycleModuleBuilder {
private final ExecutionEventCatapult eventCatapult;
private final ProjectExecutionListener projectExecutionListener;
private final ConsumerPomArtifactTransformer consumerPomArtifactTransformer;
private final SessionScope sessionScope;
@Inject
public LifecycleModuleBuilder(
@ -62,14 +60,12 @@ public class LifecycleModuleBuilder {
BuilderCommon builderCommon,
ExecutionEventCatapult eventCatapult,
List<ProjectExecutionListener> listeners,
ConsumerPomArtifactTransformer consumerPomArtifactTransformer,
SessionScope sessionScope) {
ConsumerPomArtifactTransformer consumerPomArtifactTransformer) {
this.mojoExecutor = mojoExecutor;
this.builderCommon = builderCommon;
this.eventCatapult = eventCatapult;
this.projectExecutionListener = new CompoundProjectExecutionListener(listeners);
this.consumerPomArtifactTransformer = consumerPomArtifactTransformer;
this.sessionScope = sessionScope;
}
public void buildProject(

View File

@ -58,8 +58,6 @@ public class LifecycleStarter {
private final Map<String, Builder> builders;
private final SessionScope sessionScope;
@Inject
public LifecycleStarter(
ExecutionEventCatapult eventCatapult,
@ -75,7 +73,6 @@ public class LifecycleStarter {
this.lifecycleDebugLogger = lifecycleDebugLogger;
this.lifecycleTaskSegmentCalculator = lifecycleTaskSegmentCalculator;
this.builders = builders;
this.sessionScope = sessionScope;
}
public void execute(MavenSession session) {

View File

@ -231,7 +231,7 @@ public class MojoDescriptorCreator {
}
return pluginManager.getMojoDescriptor(
plugin, goal.toString(), project.getRemotePluginRepositories(), session.getRepositorySession());
plugin, goal, project.getRemotePluginRepositories(), session.getRepositorySession());
}
// TODO take repo mans into account as one may be aggregating prefixes of many

View File

@ -76,6 +76,7 @@ public class ProjectBuildList implements Iterable<ProjectSegment> {
.orElse(null);
}
@Override
public Iterator<ProjectSegment> iterator() {
return items.iterator();
}

View File

@ -42,24 +42,36 @@ public class PluginConfigurationException extends Exception {
this.originalMessage = originalMessage;
}
/**
* Ctor left for binary compatibility.
*
* @deprecated Use {@link #PluginConfigurationException(PluginDescriptor, String, Throwable)}
*/
@Deprecated
public PluginConfigurationException(
PluginDescriptor pluginDescriptor, String originalMessage, ExpressionEvaluationException cause) {
super(originalMessage, cause);
this.pluginDescriptor = pluginDescriptor;
this.originalMessage = originalMessage;
this(pluginDescriptor, originalMessage, (Throwable) cause);
}
/**
* Ctor left for binary compatibility.
*
* @deprecated Use {@link #PluginConfigurationException(PluginDescriptor, String, Throwable)}
*/
@Deprecated
public PluginConfigurationException(
PluginDescriptor pluginDescriptor, String originalMessage, ComponentConfigurationException cause) {
super(originalMessage, cause);
this.pluginDescriptor = pluginDescriptor;
this.originalMessage = originalMessage;
this(pluginDescriptor, originalMessage, (Throwable) cause);
}
/**
* Ctor left for binary compatibility.
*
* @deprecated Use {@link #PluginConfigurationException(PluginDescriptor, String, Throwable)}
*/
@Deprecated
public PluginConfigurationException(
PluginDescriptor pluginDescriptor, String originalMessage, ComponentLookupException cause) {
super(originalMessage, cause);
this.pluginDescriptor = pluginDescriptor;
this.originalMessage = originalMessage;
this(pluginDescriptor, originalMessage, (Throwable) cause);
}
}

View File

@ -58,18 +58,26 @@ public class PluginContainerException extends PluginManagerException {
this.pluginRealm = pluginRealm;
}
/**
* Ctor left for binary compatibility.
*
* @deprecated Use {@link #PluginContainerException(Plugin, ClassRealm, String, Throwable)}
*/
@Deprecated
public PluginContainerException(
Plugin plugin, ClassRealm pluginRealm, String message, PlexusConfigurationException e) {
super(plugin, message, e);
this.pluginRealm = pluginRealm;
this(plugin, pluginRealm, message, (Throwable) e);
}
/**
* Ctor left for binary compatibility.
*
* @deprecated Use {@link #PluginContainerException(Plugin, ClassRealm, String, Throwable)}
*/
@Deprecated
public PluginContainerException(
Plugin plugin, ClassRealm pluginRealm, String message, ComponentRepositoryException e) {
super(plugin, message, e);
this.pluginRealm = pluginRealm;
this(plugin, pluginRealm, message, (Throwable) e);
}
public ClassRealm getPluginRealm() {

View File

@ -30,7 +30,6 @@ import org.codehaus.plexus.configuration.PlexusConfigurationException;
/**
* Exception in the plugin manager.
*
*/
public class PluginManagerException extends Exception {
@ -96,20 +95,24 @@ public class PluginManagerException extends Exception {
pluginVersion = plugin.getVersion();
}
/**
* Constructor.
*
* @deprecated Left for binary compatibility.
*/
@Deprecated
public PluginManagerException(Plugin plugin, String message, PlexusConfigurationException cause) {
super(message, cause);
pluginGroupId = plugin.getGroupId();
pluginArtifactId = plugin.getArtifactId();
pluginVersion = plugin.getVersion();
this(plugin, message, (Throwable) cause);
}
/**
* Constructor.
*
* @deprecated Left for binary compatibility.
*/
@Deprecated
public PluginManagerException(Plugin plugin, String message, ComponentRepositoryException cause) {
super(message, cause);
pluginGroupId = plugin.getGroupId();
pluginArtifactId = plugin.getArtifactId();
pluginVersion = plugin.getVersion();
this(plugin, message, (Throwable) cause);
}
public PluginManagerException(
@ -137,12 +140,14 @@ public class PluginManagerException extends Exception {
goal = mojoDescriptor.getGoal();
}
/**
* Constructor.
*
* @deprecated Left for binary compatibility.
*/
@Deprecated
public PluginManagerException(Plugin plugin, String message, PlexusContainerException cause) {
super(message, cause);
pluginGroupId = plugin.getGroupId();
pluginArtifactId = plugin.getArtifactId();
pluginVersion = plugin.getVersion();
this(plugin, message, (Throwable) cause);
}
public PluginManagerException(Plugin plugin, String message, MavenProject project) {

View File

@ -45,6 +45,7 @@ import org.apache.maven.api.xml.XmlNode;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.classrealm.ClassRealmManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.scope.internal.MojoExecutionScope;
import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule;
import org.apache.maven.internal.impl.DefaultMojoExecution;
import org.apache.maven.internal.impl.InternalSession;
@ -83,6 +84,7 @@ import org.apache.maven.plugin.version.PluginVersionResolver;
import org.apache.maven.project.ExtensionDescriptor;
import org.apache.maven.project.ExtensionDescriptorBuilder;
import org.apache.maven.project.MavenProject;
import org.apache.maven.session.scope.internal.SessionScope;
import org.apache.maven.session.scope.internal.SessionScopeModule;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusContainer;
@ -450,8 +452,8 @@ public class DefaultMavenPluginManager implements MavenPluginManager {
}
}
},
new SessionScopeModule(container),
new MojoExecutionScopeModule(container),
new SessionScopeModule(container.lookup(SessionScope.class)),
new MojoExecutionScopeModule(container.lookup(MojoExecutionScope.class)),
new PluginConfigurationModule(plugin.getDelegate()));
} catch (ComponentLookupException | CycleDetectedInComponentGraphException e) {
throw new PluginContainerException(

View File

@ -49,7 +49,6 @@ import org.apache.maven.plugin.MavenPluginManager;
import org.apache.maven.plugin.PluginManagerException;
import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.eclipse.aether.graph.DependencyFilter;
@ -67,7 +66,6 @@ import org.slf4j.LoggerFactory;
@Singleton
public class DefaultProjectBuildingHelper implements ProjectBuildingHelper {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final PlexusContainer container; // TODO not used? Then remove
private final ClassRealmManager classRealmManager;
private final ProjectRealmCache projectRealmCache;
private final MavenRepositorySystem repositorySystem;
@ -75,12 +73,10 @@ public class DefaultProjectBuildingHelper implements ProjectBuildingHelper {
@Inject
public DefaultProjectBuildingHelper(
PlexusContainer container,
ClassRealmManager classRealmManager,
ProjectRealmCache projectRealmCache,
MavenRepositorySystem repositorySystem,
MavenPluginManager pluginManager) {
this.container = container;
this.classRealmManager = classRealmManager;
this.projectRealmCache = projectRealmCache;
this.repositorySystem = repositorySystem;

View File

@ -26,8 +26,6 @@ import org.apache.maven.SessionScoped;
import org.apache.maven.api.Session;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.internal.impl.InternalSession;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
/**
* SessionScopeModule
@ -41,11 +39,7 @@ public class SessionScopeModule extends AbstractModule {
this(new SessionScope());
}
public SessionScopeModule(PlexusContainer container) throws ComponentLookupException {
this(container.lookup(SessionScope.class));
}
private SessionScopeModule(SessionScope scope) {
public SessionScopeModule(SessionScope scope) {
this.scope = scope;
}

View File

@ -114,7 +114,7 @@ class TestApi {
repositorySystem,
Collections.emptyList(),
mavenRepositorySystem,
plexusContainer,
new DefaultLookup(plexusContainer),
runtimeInformation);
DefaultLocalRepository localRepository =
new DefaultLocalRepository(new LocalRepository("target/test-classes/apiv4-repo"));

View File

@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.maven.internal.impl.DefaultLookup;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.testing.PlexusTest;
@ -93,7 +94,7 @@ class DefaultLifecyclesTest {
PlexusContainer mockedPlexusContainer = mock(PlexusContainer.class);
when(mockedPlexusContainer.lookupMap(Lifecycle.class)).thenReturn(lifeCycles);
DefaultLifecycles dl = new DefaultLifecycles(mockedPlexusContainer);
DefaultLifecycles dl = new DefaultLifecycles(new DefaultLookup(mockedPlexusContainer));
assertThat(dl.getLifeCycles().get(0).getId(), is("clean"));
assertThat(dl.getLifeCycles().get(1).getId(), is("default"));

View File

@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.maven.internal.impl.DefaultLookup;
import org.apache.maven.lifecycle.DefaultLifecycles;
import org.apache.maven.lifecycle.Lifecycle;
import org.codehaus.plexus.PlexusContainer;
@ -70,6 +71,6 @@ public class DefaultLifecyclesStub {
PlexusContainer mockedContainer = mock(PlexusContainer.class);
when(mockedContainer.lookupMap(Lifecycle.class)).thenReturn(lifeCycles);
return new DefaultLifecycles(mockedContainer);
return new DefaultLifecycles(new DefaultLookup(mockedContainer));
}
}

View File

@ -44,10 +44,7 @@ import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.internal.impl.AbstractSession;
import org.apache.maven.internal.impl.DefaultMojoExecution;
import org.apache.maven.internal.impl.DefaultProject;
import org.apache.maven.internal.impl.DefaultSession;
import org.apache.maven.internal.impl.*;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.building.DefaultModelBuildingRequest;
@ -394,8 +391,8 @@ public class PluginParameterExpressionEvaluatorV4Test extends AbstractCoreMavenC
mavenSession.getRequest().setRootDirectory(rootDirectory);
mavenSession.getRequest().setTopDirectory(rootDirectory);
DefaultSession session =
new DefaultSession(mavenSession, mock(RepositorySystem.class), null, null, container, null);
DefaultSession session = new DefaultSession(
mavenSession, mock(RepositorySystem.class), null, null, new DefaultLookup(container), null);
MojoExecution mojoExecution = newMojoExecution(session);
@ -434,8 +431,8 @@ public class PluginParameterExpressionEvaluatorV4Test extends AbstractCoreMavenC
}
private DefaultSession newSession() throws Exception {
DefaultSession session =
new DefaultSession(newMavenSession(), mock(RepositorySystem.class), null, null, container, null);
DefaultSession session = new DefaultSession(
newMavenSession(), mock(RepositorySystem.class), null, null, new DefaultLookup(container), null);
return session;
}

View File

@ -79,6 +79,7 @@ import org.apache.maven.execution.MavenExecutionRequestPopulator;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.ProfileActivation;
import org.apache.maven.execution.ProjectActivation;
import org.apache.maven.execution.scope.internal.MojoExecutionScope;
import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule;
import org.apache.maven.extension.internal.CoreExports;
import org.apache.maven.extension.internal.CoreExtensionEntry;
@ -90,6 +91,7 @@ import org.apache.maven.model.root.RootLocator;
import org.apache.maven.project.MavenProject;
import org.apache.maven.properties.internal.EnvironmentUtils;
import org.apache.maven.properties.internal.SystemProperties;
import org.apache.maven.session.scope.internal.SessionScope;
import org.apache.maven.session.scope.internal.SessionScopeModule;
import org.apache.maven.toolchain.building.DefaultToolchainsBuildingRequest;
import org.apache.maven.toolchain.building.ToolchainsBuilder;
@ -705,8 +707,8 @@ public class MavenCli {
for (CoreExtensionEntry extension : extensions) {
container.discoverComponents(
extension.getClassRealm(),
new SessionScopeModule(container),
new MojoExecutionScopeModule(container),
new SessionScopeModule(container.lookup(SessionScope.class)),
new MojoExecutionScopeModule(container.lookup(MojoExecutionScope.class)),
new ExtensionConfigurationModule(extension, extensionSource));
}