Skip to content

Commit

Permalink
Move ScopeManager out
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 15, 2024
1 parent 2112435 commit 48dd5cc
Show file tree
Hide file tree
Showing 25 changed files with 41 additions and 1,977 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.Toolbox;
import eu.maveniverse.maven.toolbox.shared.internal.ToolboxImpl;
import eu.maveniverse.maven.toolbox.shared.internal.resolver.ScopeManagerImpl;
import java.io.File;
import java.util.stream.Collectors;
import org.eclipse.aether.artifact.Artifact;
Expand Down Expand Up @@ -52,9 +51,8 @@ protected Integer doCall(Context context) throws Exception {
java.util.List<Dependency> managedDependencies = importBoms(context, boms);
Artifact gav = parseGav(this.gav, managedDependencies);

ScopeManagerImpl scopeManager = createScopeManager(mavenLevel);
ResolutionScope resolutionScope = toResolutionScope(scopeManager, this.resolutionScope);
Toolbox toolbox = new ToolboxImpl(context, scopeManager);
ResolutionScope resolutionScope = toResolutionScope(this.resolutionScope);
Toolbox toolbox = new ToolboxImpl(context);
DependencyResult dependencyResult = toolbox.resolve(
resolutionScope, new Dependency(gav, ""), null, managedDependencies, context.remoteRepositories());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.internal.MavenConfiguration;
import eu.maveniverse.maven.toolbox.shared.internal.resolver.ScopeManagerImpl;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Locale;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
Expand Down Expand Up @@ -85,15 +84,8 @@ protected Artifact parseGav(String gav, java.util.List<Dependency> managedDepend
}
}

protected ScopeManagerImpl createScopeManager(String mavenLevel) {
return new ScopeManagerImpl(
mavenLevel.equalsIgnoreCase("maven3") ? MavenConfiguration.MAVEN3 : MavenConfiguration.MAVEN4);
}

protected ResolutionScope toResolutionScope(ScopeManagerImpl scopeManager, String resolutionScope) {
return scopeManager
.getResolutionScope(resolutionScope)
.orElseThrow(() -> new IllegalArgumentException("unknown resolution scope"));
protected ResolutionScope toResolutionScope(String resolutionScope) {
return ResolutionScope.valueOf(resolutionScope.toUpperCase(Locale.ROOT));
}

@Override
Expand Down
6 changes: 2 additions & 4 deletions cli/src/main/java/eu/maveniverse/maven/toolbox/cli/Tree.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.Toolbox;
import eu.maveniverse.maven.toolbox.shared.internal.ToolboxImpl;
import eu.maveniverse.maven.toolbox.shared.internal.resolver.ScopeManagerImpl;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.collection.CollectResult;
import org.eclipse.aether.graph.Dependency;
Expand Down Expand Up @@ -57,9 +56,8 @@ protected Integer doCall(Context context) throws Exception {
java.util.List<Dependency> managedDependencies = importBoms(context, boms);
Artifact gav = parseGav(this.gav, managedDependencies);

ScopeManagerImpl scopeManager = createScopeManager(mavenLevel);
ResolutionScope resolutionScope = toResolutionScope(scopeManager, this.resolutionScope);
Toolbox toolbox = new ToolboxImpl(context, scopeManager);
ResolutionScope resolutionScope = toResolutionScope(this.resolutionScope);
Toolbox toolbox = new ToolboxImpl(context);
CollectResult collectResult = toolbox.collect(
resolutionScope,
new Dependency(gav, ""),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
import eu.maveniverse.maven.mima.context.Runtimes;
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.Toolbox;
import eu.maveniverse.maven.toolbox.shared.internal.MavenConfiguration;
import eu.maveniverse.maven.toolbox.shared.internal.ToolboxImpl;
import eu.maveniverse.maven.toolbox.shared.internal.resolver.ScopeManagerImpl;
import java.util.Locale;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -59,12 +58,8 @@ public class GavTreeMojo extends AbstractMojo {
public void execute() throws MojoExecutionException, MojoFailureException {
Runtime runtime = Runtimes.INSTANCE.getRuntime();
try (Context context = runtime.create(ContextOverrides.create().build())) {
ScopeManagerImpl scopeManager = new ScopeManagerImpl(
mavenLevel.equalsIgnoreCase("maven3") ? MavenConfiguration.MAVEN3 : MavenConfiguration.MAVEN4);
Toolbox toolbox = new ToolboxImpl(context, scopeManager);
ResolutionScope resolutionScope = scopeManager
.getResolutionScope(scope)
.orElseThrow(() -> new IllegalArgumentException("unknown resolution scope"));
Toolbox toolbox = new ToolboxImpl(context);
ResolutionScope resolutionScope = ResolutionScope.valueOf(scope.toUpperCase(Locale.ROOT));

CollectResult collectResult = toolbox.collect(
resolutionScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
import eu.maveniverse.maven.mima.context.Runtimes;
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.Toolbox;
import eu.maveniverse.maven.toolbox.shared.internal.MavenConfiguration;
import eu.maveniverse.maven.toolbox.shared.internal.ToolboxImpl;
import eu.maveniverse.maven.toolbox.shared.internal.resolver.ScopeManagerImpl;
import java.util.Locale;
import java.util.stream.Collectors;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.plugin.AbstractMojo;
Expand Down Expand Up @@ -58,12 +57,8 @@ public class TreeMojo extends AbstractMojo {
public void execute() throws MojoExecutionException, MojoFailureException {
Runtime runtime = Runtimes.INSTANCE.getRuntime();
try (Context context = runtime.create(ContextOverrides.create().build())) {
ScopeManagerImpl scopeManager = new ScopeManagerImpl(
mavenLevel.equalsIgnoreCase("maven3") ? MavenConfiguration.MAVEN3 : MavenConfiguration.MAVEN4);
Toolbox toolbox = new ToolboxImpl(context, scopeManager);
ResolutionScope resolutionScope = scopeManager
.getResolutionScope(scope)
.orElseThrow(() -> new IllegalArgumentException("unknown resolution scope"));
Toolbox toolbox = new ToolboxImpl(context);
ResolutionScope resolutionScope = ResolutionScope.valueOf(scope.toUpperCase(Locale.ROOT));

ArtifactTypeRegistry artifactTypeRegistry =
context.repositorySystemSession().getArtifactTypeRegistry();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
package eu.maveniverse.maven.toolbox.shared;

/**
* Generic resolution scope.
* Generic resolution scope abstraction.
* <p>
* Uses Maven3 mojo resolution scopes as template.
*/
public interface ResolutionScope {
/**
* The label.
*/
String getId();
public enum ResolutionScope {
NONE,
COMPILE,
COMPILE_PLUS_RUNTIME,
RUNTIME,
RUNTIME_PLUS_SYSTEM,
TEST;
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 48dd5cc

Please sign in to comment.