From 364b2faa5137c4994b239670b315d7188d38de0d Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Sat, 9 Mar 2024 22:38:57 +0100 Subject: [PATCH] WIP and simplify --- .../maven/toolbox/plugin/GavTreeMojo.java | 7 ++--- .../maven/toolbox/plugin/TreeMojo.java | 7 ++--- .../maven/toolbox/shared/Toolbox.java | 8 +---- .../toolbox/shared/internal/ToolboxImpl.java | 29 +++++++------------ 4 files changed, 15 insertions(+), 36 deletions(-) diff --git a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/GavTreeMojo.java b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/GavTreeMojo.java index c367219c..0b22e959 100644 --- a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/GavTreeMojo.java +++ b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/GavTreeMojo.java @@ -42,12 +42,9 @@ public class GavTreeMojo extends AbstractMojo { public void execute() throws MojoExecutionException { Runtime runtime = Runtimes.INSTANCE.getRuntime(); try (Context context = runtime.create(ContextOverrides.create().build())) { - Toolbox toolbox = new ToolboxImpl(context.repositorySystem()); - Toolbox.ResolutionScope resolutionScope = - Toolbox.ResolutionScope.valueOf(scope.toUpperCase(Locale.ENGLISH)); + Toolbox toolbox = new ToolboxImpl(context); CollectResult collectResult = toolbox.collectAsDependency( - context.repositorySystemSession(), - resolutionScope, + Toolbox.ResolutionScope.valueOf(scope.toUpperCase(Locale.ENGLISH)), new Dependency(new DefaultArtifact(gav), scope), context.remoteRepositories(), verbose); diff --git a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/TreeMojo.java b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/TreeMojo.java index b2e8f484..9a43e518 100644 --- a/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/TreeMojo.java +++ b/maven-plugin/src/main/java/eu/maveniverse/maven/toolbox/plugin/TreeMojo.java @@ -43,12 +43,9 @@ public void execute() throws MojoExecutionException { try (Context context = runtime.create(ContextOverrides.create().build())) { ArtifactTypeRegistry artifactTypeRegistry = context.repositorySystemSession().getArtifactTypeRegistry(); - Toolbox toolbox = new ToolboxImpl(context.repositorySystem()); - Toolbox.ResolutionScope resolutionScope = - Toolbox.ResolutionScope.valueOf(scope.toUpperCase(Locale.ENGLISH)); + Toolbox toolbox = new ToolboxImpl(context); CollectResult collectResult = toolbox.collectAsProject( - context.repositorySystemSession(), - resolutionScope, + Toolbox.ResolutionScope.valueOf(scope.toUpperCase(Locale.ENGLISH)), RepositoryUtils.toArtifact(mavenProject.getArtifact()), mavenProject.getDependencies().stream() .map(d -> RepositoryUtils.toDependency(d, artifactTypeRegistry)) diff --git a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/Toolbox.java b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/Toolbox.java index 640fee0d..441b800f 100644 --- a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/Toolbox.java +++ b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/Toolbox.java @@ -3,7 +3,6 @@ import eu.maveniverse.maven.toolbox.shared.internal.ScopeDependencySelector; import java.util.Arrays; import java.util.List; -import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.collection.CollectResult; import org.eclipse.aether.collection.DependencyCollectionException; @@ -44,7 +43,6 @@ public ScopeDependencyFilter getScopeDependencyFilter() { * dependencies for given resolution scope. */ CollectResult collectAsProject( - RepositorySystemSession repositorySystemSession, ResolutionScope resolutionScope, Artifact root, List dependencies, @@ -57,7 +55,6 @@ CollectResult collectAsProject( * Collects given existing {@link Dependency} by reusing POM information for given resolution scope. */ CollectResult collectAsDependency( - RepositorySystemSession repositorySystemSession, ResolutionScope resolutionScope, Dependency root, List remoteRepositories, @@ -67,9 +64,6 @@ CollectResult collectAsDependency( /** * Resolves given artifacts from given remote repositories. */ - List resolveArtifacts( - RepositorySystemSession repositorySystemSession, - List artifacts, - List remoteRepositories) + List resolveArtifacts(List artifacts, List remoteRepositories) throws ArtifactResolutionException; } diff --git a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxImpl.java b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxImpl.java index 8fd7c6eb..7c75414c 100644 --- a/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxImpl.java +++ b/shared/src/main/java/eu/maveniverse/maven/toolbox/shared/internal/ToolboxImpl.java @@ -2,12 +2,11 @@ import static java.util.Objects.requireNonNull; +import eu.maveniverse.maven.mima.context.Context; import eu.maveniverse.maven.toolbox.shared.Toolbox; import java.util.ArrayList; import java.util.List; import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; import org.eclipse.aether.RequestTrace; import org.eclipse.aether.artifact.Artifact; import org.eclipse.aether.collection.CollectRequest; @@ -29,15 +28,14 @@ public class ToolboxImpl implements Toolbox { private final Logger logger = LoggerFactory.getLogger(getClass()); - private final RepositorySystem repositorySystem; + private final Context context; - public ToolboxImpl(RepositorySystem repositorySystem) { - this.repositorySystem = requireNonNull(repositorySystem); + public ToolboxImpl(Context context) { + this.context = requireNonNull(context); } @Override public CollectResult collectAsProject( - RepositorySystemSession repositorySystemSession, ResolutionScope resolutionScope, Artifact root, List dependencies, @@ -45,10 +43,9 @@ public CollectResult collectAsProject( List remoteRepositories, boolean verbose) throws DependencyCollectionException { - requireNonNull(repositorySystemSession); requireNonNull(resolutionScope); - DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession); + DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(context.repositorySystemSession()); if (verbose) { session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, ConflictResolver.Verbosity.FULL); session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true); @@ -67,7 +64,7 @@ public CollectResult collectAsProject( collectRequest.setTrace(RequestTrace.newChild(null, collectRequest)); logger.debug("Collecting {}", collectRequest); - CollectResult result = repositorySystem.collectDependencies(session, collectRequest); + CollectResult result = context.repositorySystem().collectDependencies(session, collectRequest); if (resolutionScope.getScopeDependencyFilter() != null) { CloningDependencyVisitor cloning = new CloningDependencyVisitor(); FilteringDependencyVisitor filter = @@ -80,17 +77,15 @@ public CollectResult collectAsProject( @Override public CollectResult collectAsDependency( - RepositorySystemSession repositorySystemSession, ResolutionScope resolutionScope, Dependency root, List remoteRepositories, boolean verbose) throws DependencyCollectionException { - requireNonNull(repositorySystemSession); requireNonNull(resolutionScope); requireNonNull(root); - DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession); + DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(context.repositorySystemSession()); if (verbose) { session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, ConflictResolver.Verbosity.FULL); session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true); @@ -107,7 +102,7 @@ public CollectResult collectAsDependency( collectRequest.setTrace(RequestTrace.newChild(null, collectRequest)); logger.debug("Collecting {}", collectRequest); - CollectResult result = repositorySystem.collectDependencies(session, collectRequest); + CollectResult result = context.repositorySystem().collectDependencies(session, collectRequest); if (resolutionScope.getScopeDependencyFilter() != null) { CloningDependencyVisitor cloning = new CloningDependencyVisitor(); FilteringDependencyVisitor filter = @@ -119,16 +114,12 @@ public CollectResult collectAsDependency( } @Override - public List resolveArtifacts( - RepositorySystemSession repositorySystemSession, - List artifacts, - List remoteRepositories) + public List resolveArtifacts(List artifacts, List remoteRepositories) throws ArtifactResolutionException { - requireNonNull(repositorySystemSession); requireNonNull(artifacts); List artifactRequests = new ArrayList<>(); artifacts.forEach(a -> artifactRequests.add(new ArtifactRequest(a, remoteRepositories, null))); - return repositorySystem.resolveArtifacts(repositorySystemSession, artifactRequests); + return context.repositorySystem().resolveArtifacts(context.repositorySystemSession(), artifactRequests); } }