Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions maven-core/src/main/java/org/apache/maven/DefaultMaven.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.ProjectDependencyGraph;
import org.apache.maven.graph.GraphBuilder;
import org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory;
import org.apache.maven.internal.RepositorySystemSessionFactory;
import org.apache.maven.internal.aether.MavenChainedWorkspaceReader;
import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
import org.apache.maven.lifecycle.internal.LifecycleStarter;
Expand Down Expand Up @@ -91,7 +91,7 @@ public class DefaultMaven implements Maven {
private SessionScope sessionScope;

@Inject
private DefaultRepositorySystemSessionFactory repositorySessionFactory;
private RepositorySystemSessionFactory repositorySessionFactory;

@Inject
@Named(GraphBuilder.HINT)
Expand Down Expand Up @@ -166,7 +166,8 @@ private MavenExecutionResult doExecute(MavenExecutionRequest request) {
// so that @SessionScoped components can be @Injected into AbstractLifecycleParticipants.
//
sessionScope.enter();
try (RepositorySystemSession.CloseableSession repoSession = newRepositorySession(request)) {
try (RepositorySystemSession.CloseableSession repoSession =
newRepositorySessionBuilder(request).build()) {
DefaultRepositorySystemSession mutableSession = new DefaultRepositorySystemSession(repoSession);
MavenSession session = new MavenSession(container, mutableSession, request, result);

Expand Down Expand Up @@ -313,8 +314,13 @@ private void afterSessionEnd(Collection<MavenProject> projects, MavenSession ses
}
}

public RepositorySystemSession.CloseableSession newRepositorySession(MavenExecutionRequest request) {
return repositorySessionFactory.newRepositorySession(request).build();
@Deprecated
public RepositorySystemSession newRepositorySession(MavenExecutionRequest request) {
return newRepositorySessionBuilder(request).build();
}

private RepositorySystemSession.SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request) {
return repositorySessionFactory.newRepositorySessionBuilder(request);
}

private void validateLocalRepository(MavenExecutionRequest request) throws LocalRepositoryNotAccessibleException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.internal;

import org.apache.maven.execution.MavenExecutionRequest;
import org.eclipse.aether.RepositorySystemSession.SessionBuilder;

/**
* Factory for Resolver session.
*
* @since 3.10.0
*/
public interface RepositorySystemSessionFactory {
/**
* Creates "ready to use" session builder instance. The factory does not set up one thing: the
* {@link org.eclipse.aether.repository.WorkspaceReader}s, that is caller duty to figure out. Workspace readers
* should be set up as very last thing before using resolver session, that is built by invoking
* {@link SessionBuilder#build()} method.
*
* @param request The maven execution request, must not be {@code null}.
* @return The session builder "ready to use" without workspace readers.
*/
SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -38,6 +39,7 @@
import org.apache.maven.bridge.MavenRepositorySystem;
import org.apache.maven.eventspy.internal.EventSpyDispatcher;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.internal.RepositorySystemSessionFactory;
import org.apache.maven.model.ModelBase;
import org.apache.maven.repository.internal.MavenSessionBuilderSupplier;
import org.apache.maven.repository.internal.scopes.Maven3ScopeManagerConfiguration;
Expand All @@ -54,6 +56,7 @@
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.eclipse.aether.ConfigurationProperties;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositoryException;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
Expand Down Expand Up @@ -92,8 +95,9 @@
/**
* @since 3.3.0
*/
@Singleton
@Named
public class DefaultRepositorySystemSessionFactory {
public class DefaultRepositorySystemSessionFactory implements RepositorySystemSessionFactory {
/**
* User property for chained LRM: list of "tail" local repository paths (separated by comma), to be used with
* {@link ChainedLocalRepositoryManager}.
Expand Down Expand Up @@ -214,8 +218,18 @@ public class DefaultRepositorySystemSessionFactory {

private final InternalScopeManager scopeManager = new ScopeManagerImpl(Maven3ScopeManagerConfiguration.INSTANCE);

/**
* For legacy consumers; hopefully nobody.
*/
@Deprecated
public DefaultRepositorySystemSession newRepositorySession(MavenExecutionRequest request) {
return new DefaultRepositorySystemSession(
newRepositorySessionBuilder(request).build());
}

@SuppressWarnings("checkstyle:methodlength")
public RepositorySystemSession.SessionBuilder newRepositorySession(MavenExecutionRequest request) {
@Override
public RepositorySystemSession.SessionBuilder newRepositorySessionBuilder(MavenExecutionRequest request) {
Comment thread
cstamas marked this conversation as resolved.
// config
Map<Object, Object> configProps = new LinkedHashMap<>();
configProps.put(ConfigurationProperties.USER_AGENT, getUserAgent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ public BootstrapCoreExtensionManager(
public List<CoreExtensionEntry> loadCoreExtensions(
MavenExecutionRequest request, Set<String> providedArtifacts, List<CoreExtension> extensions)
throws Exception {
try (RepositorySystemSession.CloseableSession repoSession =
repositorySystemSessionFactory.newRepositorySession(request).build()) {
try (RepositorySystemSession.CloseableSession repoSession = repositorySystemSessionFactory
.newRepositorySessionBuilder(request)
.build()) {
List<RemoteRepository> repositories = RepositoryUtils.toRepos(request.getPluginArtifactRepositories());
Interpolator interpolator = createInterpolator(request);

Expand Down