Skip to content

Commit

Permalink
Move off deprecated stuff in UTs
Browse files Browse the repository at this point in the history
All fixed sans maven-compat, it stays mostly unchanged.
  • Loading branch information
cstamas committed Jan 24, 2024
1 parent 94881c1 commit bdc3da8
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.apache.maven.repository.internal.MavenSessionBuilderSupplier;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.testing.PlexusTest;
import org.codehaus.plexus.util.FileUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.LocalRepository;

import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
Expand All @@ -64,7 +63,10 @@ public abstract class AbstractCoreMavenComponentTestCase {
protected PlexusContainer container;

@Inject
protected MavenRepositorySystem repositorySystem;
protected RepositorySystem repositorySystem;

@Inject
protected MavenRepositorySystem mavenRepositorySystem;

@Inject
protected org.apache.maven.project.ProjectBuilder projectBuilder;
Expand Down Expand Up @@ -160,9 +162,11 @@ protected MavenSession createMavenSession(File pom, Properties executionProperti

protected void initRepoSession(ProjectBuildingRequest request) throws Exception {
File localRepoDir = new File(request.getLocalRepository().getBasedir());
LocalRepository localRepo = new LocalRepository(localRepoDir);
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager(new SimpleLocalRepositoryManagerFactory().newInstance(session, localRepo));
LocalRepository localRepo = new LocalRepository(localRepoDir, "simple");
RepositorySystemSession session = new MavenSessionBuilderSupplier(repositorySystem)
.get()
.withLocalRepositories(localRepo)
.build();
request.setRepositorySession(session);
}

Expand All @@ -188,7 +192,7 @@ protected List<ArtifactRepository> getRemoteRepositories() throws InvalidReposit
repository.setReleases(policy);
repository.setSnapshots(policy);

return Arrays.asList(repositorySystem.buildArtifactRepository(repository));
return Arrays.asList(mavenRepositorySystem.buildArtifactRepository(repository));
}

protected List<ArtifactRepository> getPluginArtifactRepositories() throws InvalidRepositoryException {
Expand All @@ -198,7 +202,7 @@ protected List<ArtifactRepository> getPluginArtifactRepositories() throws Invali
protected ArtifactRepository getLocalRepository() throws InvalidRepositoryException {
File repoDir = new File(getBasedir(), "target/local-repo").getAbsoluteFile();

return repositorySystem.createLocalRepository(repoDir);
return mavenRepositorySystem.createLocalRepository(repoDir);
}

protected class ProjectBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.root.RootLocator;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.junit.jupiter.api.Test;
Expand All @@ -37,7 +37,7 @@ public class DefaultSessionTest {

@Test
void testRootDirectoryWithNull() {
RepositorySystemSession rss = MavenRepositorySystemUtils.newSession();
RepositorySystemSession rss = new DefaultRepositorySystemSession(h -> false);
DefaultMavenExecutionRequest mer = new DefaultMavenExecutionRequest();
MavenSession ms = new MavenSession(null, rss, mer, null);
DefaultSession session =
Expand All @@ -51,7 +51,7 @@ void testRootDirectoryWithNull() {

@Test
void testRootDirectory() {
RepositorySystemSession rss = MavenRepositorySystemUtils.newSession();
RepositorySystemSession rss = new DefaultRepositorySystemSession(h -> false);
DefaultMavenExecutionRequest mer = new DefaultMavenExecutionRequest();
MavenSession ms = new MavenSession(null, rss, mer, null);
ms.getRequest().setRootDirectory(Paths.get("myRootDirectory"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.inject.Inject;

import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -47,7 +48,7 @@
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.execution.scope.internal.MojoExecutionScope;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.apache.maven.repository.internal.MavenSessionBuilderSupplier;
import org.apache.maven.rtinfo.RuntimeInformation;
import org.apache.maven.session.scope.internal.SessionScope;
import org.apache.maven.toolchain.DefaultToolchainManagerPrivate;
Expand Down Expand Up @@ -105,7 +106,11 @@ class TestApi {

@BeforeEach
void setup() {
RepositorySystemSession rss = MavenRepositorySystemUtils.newSession();
// create session with any local repo, is redefined anyway below
RepositorySystemSession rss = new MavenSessionBuilderSupplier(repositorySystem)
.get()
.withLocalRepositoryBaseDirectories(new File("target"))
.build();
DefaultMavenExecutionRequest mer = new DefaultMavenExecutionRequest();
DefaultMavenExecutionResult meres = new DefaultMavenExecutionResult();
MavenSession ms = new MavenSession(rss, mer, meres);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.net.MalformedURLException;

import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.testing.PlexusTest;
import org.eclipse.aether.DefaultRepositorySystemSession;
Expand Down Expand Up @@ -57,7 +56,7 @@ protected PlexusContainer getContainer() {
}

public static RepositorySystemSession newMavenRepositorySystemSession(RepositorySystem system) {
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(h -> false);

LocalRepository localRepo = new LocalRepository("target/local-repo");
session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.maven.bridge.MavenRepositorySystem;
import org.apache.maven.model.building.ModelBuildingException;
import org.apache.maven.model.building.ModelProblem;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.testing.PlexusTest;
import org.eclipse.aether.DefaultRepositoryCache;
Expand Down Expand Up @@ -145,7 +144,7 @@ protected ProjectBuildingRequest newBuildingRequest() throws Exception {

protected void initRepoSession(ProjectBuildingRequest request) {
File localRepo = new File(request.getLocalRepository().getBasedir());
DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession();
DefaultRepositorySystemSession repoSession = new DefaultRepositorySystemSession(h -> false);
repoSession.setCache(new DefaultRepositoryCache());
repoSession.setLocalRepositoryManager(new LegacyLocalRepositoryManager(localRepo));
request.setRepositorySession(repoSession);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.apache.maven.model.ReportSet;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.project.harness.PomTestWrapper;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.codehaus.plexus.testing.PlexusTest;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
Expand Down Expand Up @@ -1887,7 +1886,7 @@ private PomTestWrapper buildPom(
? ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0
: ModelBuildingRequest.VALIDATION_LEVEL_STRICT);

DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession();
DefaultRepositorySystemSession repoSession = new DefaultRepositorySystemSession(h -> false);
LocalRepository localRepo =
new LocalRepository(config.getLocalRepository().getBasedir());
repoSession.setLocalRepositoryManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.maven.model.Parent;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.impl.RemoteRepositoryManager;
Expand Down Expand Up @@ -191,7 +190,7 @@ void testResolveDependencySuccessfullyResolvesExistingDependencyUsingHighestVers

private ModelResolver newModelResolver() throws Exception {
final File localRepo = new File(this.getLocalRepository().getBasedir());
final DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession();
final DefaultRepositorySystemSession repoSession = new DefaultRepositorySystemSession(h -> false);
repoSession.setLocalRepositoryManager(new LegacyLocalRepositoryManager(localRepo));

return new ProjectModelResolver(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.harness.PomTestWrapper;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.apache.maven.settings.v4.SettingsStaxReader;
import org.codehaus.plexus.testing.PlexusTest;
import org.eclipse.aether.DefaultRepositorySystemSession;
Expand Down Expand Up @@ -111,7 +110,7 @@ private PomTestWrapper buildPom(String pomPath) throws Exception {
"local", localRepoUrl, new DefaultRepositoryLayout(), null, null));
config.setActiveProfileIds(settings.getActiveProfiles());

DefaultRepositorySystemSession repoSession = MavenRepositorySystemUtils.newSession();
DefaultRepositorySystemSession repoSession = new DefaultRepositorySystemSession(h -> false);
LocalRepository localRepo =
new LocalRepository(config.getLocalRepository().getBasedir());
repoSession.setLocalRepositoryManager(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.inject.Inject;

import java.io.File;
import java.net.MalformedURLException;

import org.apache.maven.repository.internal.util.ConsoleRepositoryListener;
Expand Down Expand Up @@ -55,10 +56,8 @@ protected PlexusContainer getContainer() {
}

public static RepositorySystemSession newMavenRepositorySystemSession(RepositorySystem system) {
SessionBuilder session = MavenRepositorySystemUtils.newSession(
system.createSessionBuilder(), MavenRepositorySystemUtils.newArtifactTypeRegistry());

session.withLocalRepositories(new LocalRepository("target/local-repo"));
SessionBuilder session = new MavenSessionBuilderSupplier(system).get();
session.withLocalRepositories(new LocalRepository(new File("target/local-repo"), "simple"));
session.setTransferListener(new ConsoleTransferListener());
session.setRepositoryListener(new ConsoleRepositoryListener());

Expand Down

0 comments on commit bdc3da8

Please sign in to comment.