Skip to content

Commit

Permalink
WIP and simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 9, 2024
1 parent a6af792 commit 364b2fa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,7 +43,6 @@ public ScopeDependencyFilter getScopeDependencyFilter() {
* dependencies for given resolution scope.
*/
CollectResult collectAsProject(
RepositorySystemSession repositorySystemSession,
ResolutionScope resolutionScope,
Artifact root,
List<Dependency> dependencies,
Expand All @@ -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<RemoteRepository> remoteRepositories,
Expand All @@ -67,9 +64,6 @@ CollectResult collectAsDependency(
/**
* Resolves given artifacts from given remote repositories.
*/
List<ArtifactResult> resolveArtifacts(
RepositorySystemSession repositorySystemSession,
List<Artifact> artifacts,
List<RemoteRepository> remoteRepositories)
List<ArtifactResult> resolveArtifacts(List<Artifact> artifacts, List<RemoteRepository> remoteRepositories)
throws ArtifactResolutionException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,26 +28,24 @@

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<Dependency> dependencies,
List<Dependency> managedDependencies,
List<RemoteRepository> 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);
Expand All @@ -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 =
Expand All @@ -80,17 +77,15 @@ public CollectResult collectAsProject(

@Override
public CollectResult collectAsDependency(
RepositorySystemSession repositorySystemSession,
ResolutionScope resolutionScope,
Dependency root,
List<RemoteRepository> 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);
Expand All @@ -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 =
Expand All @@ -119,16 +114,12 @@ public CollectResult collectAsDependency(
}

@Override
public List<ArtifactResult> resolveArtifacts(
RepositorySystemSession repositorySystemSession,
List<Artifact> artifacts,
List<RemoteRepository> remoteRepositories)
public List<ArtifactResult> resolveArtifacts(List<Artifact> artifacts, List<RemoteRepository> remoteRepositories)
throws ArtifactResolutionException {
requireNonNull(repositorySystemSession);
requireNonNull(artifacts);

List<ArtifactRequest> 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);
}
}

0 comments on commit 364b2fa

Please sign in to comment.