Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 21, 2024
1 parent 9bf6561 commit f1af4ed
Show file tree
Hide file tree
Showing 23 changed files with 115 additions and 138 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class Classpath extends ResolverCommandSupport {

@Override
protected boolean doCall(Context context) throws Exception {
ToolboxCommando toolboxCommando = ToolboxCommando.getOrCreate(context);
ToolboxCommando toolboxCommando = getToolboxCommando(context);
return toolboxCommando.classpath(
ResolutionScope.parse(resolutionScope),
toolboxCommando.toolboxResolver().loadGav(gav, boms),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.mima.context.ContextOverrides;
import eu.maveniverse.maven.mima.context.HTTPProxy;
import eu.maveniverse.maven.mima.context.MavenSystemHome;
import eu.maveniverse.maven.mima.context.MavenUserHome;
import eu.maveniverse.maven.mima.context.Runtime;
import eu.maveniverse.maven.mima.context.Runtimes;
import eu.maveniverse.maven.toolbox.shared.Output;
Expand All @@ -33,13 +30,11 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
import org.apache.maven.settings.Proxy;
import org.apache.maven.settings.Settings;
import org.eclipse.aether.repository.RemoteRepository;
import org.jline.jansi.Ansi;
import org.slf4j.helpers.MessageFormatter;
import picocli.CommandLine;
Expand Down Expand Up @@ -142,81 +137,10 @@ protected void push(String key, Object object) {
public String[] getVersion() {
return new String[] {
"MIMA " + getRuntime().version(),
"Toolbox " + ToolboxCommando.getOrCreate(getContext()).getVersion()
"Toolbox " + getToolboxCommando(getContext()).getVersion()
};
}

protected void mayDumpEnv(Runtime runtime, Context context, boolean verbose) {
warn(
"Toolbox {} (MIMA Runtime '{}' version {})",
ToolboxCommando.getOrCreate(getContext()).getVersion(),
runtime.name(),
runtime.version());
warn("=======");
normal(" Maven version {}", runtime.mavenVersion());
normal(" Managed {}", runtime.managedRepositorySystem());
normal(" Basedir {}", context.basedir());
normal(" Offline {}", context.repositorySystemSession().isOffline());

MavenSystemHome mavenSystemHome = context.mavenSystemHome();
normal("");
normal(" MAVEN_HOME {}", mavenSystemHome == null ? "undefined" : mavenSystemHome.basedir());
if (mavenSystemHome != null) {
normal(" settings.xml {}", mavenSystemHome.settingsXml());
normal(" toolchains.xml {}", mavenSystemHome.toolchainsXml());
}

MavenUserHome mavenUserHome = context.mavenUserHome();
normal("");
normal(" USER_HOME {}", mavenUserHome.basedir());
normal(" settings.xml {}", mavenUserHome.settingsXml());
normal(" settings-security.xml {}", mavenUserHome.settingsSecurityXml());
normal(" local repository {}", mavenUserHome.localRepository());

normal("");
normal(" PROFILES");
normal(" Active {}", context.contextOverrides().getActiveProfileIds());
normal(" Inactive {}", context.contextOverrides().getInactiveProfileIds());

normal("");
normal(" REMOTE REPOSITORIES");
for (RemoteRepository repository : context.remoteRepositories()) {
if (repository.getMirroredRepositories().isEmpty()) {
normal(" {}", repository);
} else {
normal(" {}, mirror of", repository);
for (RemoteRepository mirrored : repository.getMirroredRepositories()) {
normal(" {}", mirrored);
}
}
}

if (context.httpProxy() != null) {
HTTPProxy proxy = context.httpProxy();
normal("");
normal(" HTTP PROXY");
normal(" url {}://{}:{}", proxy.getProtocol(), proxy.getHost(), proxy.getPort());
normal(" nonProxyHosts {}", proxy.getNonProxyHosts());
}

if (verbose) {
verbose("");
verbose(" USER PROPERTIES");
context.contextOverrides().getUserProperties().entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.forEach(e -> verbose(" {}={}", e.getKey(), e.getValue()));
verbose(" SYSTEM PROPERTIES");
context.contextOverrides().getSystemProperties().entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.forEach(e -> verbose(" {}={}", e.getKey(), e.getValue()));
verbose(" CONFIG PROPERTIES");
context.contextOverrides().getConfigProperties().entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.forEach(e -> verbose(" {}={}", e.getKey(), e.getValue()));
}
verbose("");
}

protected Runtime getRuntime() {
return (Runtime) getOrCreate(Runtime.class.getName(), Runtimes.INSTANCE::getRuntime);
}
Expand Down Expand Up @@ -461,6 +385,10 @@ protected String getLocation(final StackTraceElement e) {
}
}

protected ToolboxCommando getToolboxCommando(Context context) {
return ToolboxCommando.getOrCreate(getRuntime(), context);
}

@Override
public final Integer call() {
Ansi.setEnabled(!batch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public final class CopyAll extends ResolverCommandSupport {
@Override
protected boolean doCall(Context context) throws Exception {
Path targetPath = target.toAbsolutePath();
ToolboxCommando toolboxCommando = ToolboxCommando.getOrCreate(context);
ToolboxCommando toolboxCommando = getToolboxCommando(context);
return toolboxCommando.copyAll(
ResolutionScope.parse(resolutionScope),
toolboxCommando.toolboxResolver().loadGav(gav, boms),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.Artifacts;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import java.nio.file.Path;
import org.eclipse.aether.deployment.DeploymentException;
import picocli.CommandLine;
Expand Down Expand Up @@ -57,6 +56,6 @@ protected boolean doCall(Context context) throws DeploymentException {
if (javadoc != null) {
artifacts.addJavadoc(javadoc);
}
return ToolboxCommando.getOrCreate(getContext()).deploy(remoteRepositorySpec, artifacts, output);
return getToolboxCommando(context).deploy(remoteRepositorySpec, artifacts, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package eu.maveniverse.maven.toolbox.cli;

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import org.eclipse.aether.deployment.DeploymentException;
import picocli.CommandLine;

Expand All @@ -22,6 +21,6 @@ public final class DeployRecorded extends ResolverCommandSupport {

@Override
protected boolean doCall(Context context) throws DeploymentException {
return ToolboxCommando.getOrCreate(getContext()).deployAllRecorded(remoteRepositorySpec, true, output);
return getToolboxCommando(context).deployAllRecorded(remoteRepositorySpec, true, output);
}
}
3 changes: 1 addition & 2 deletions cli/src/main/java/eu/maveniverse/maven/toolbox/cli/Dump.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
public final class Dump extends CommandSupport {
@Override
protected boolean doCall(Context context) {
mayDumpEnv(getRuntime(), context, true);
return true;
return getToolboxCommando(context).dump(verbose, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package eu.maveniverse.maven.toolbox.cli;

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import java.io.IOException;
import picocli.CommandLine;

Expand Down Expand Up @@ -49,7 +48,7 @@ public final class Exists extends SearchCommandSupport {

@Override
protected boolean doCall(Context context) throws IOException {
return ToolboxCommando.getOrCreate(context)
return getToolboxCommando(context)
.exists(getRemoteRepository(), gav, pom, sources, javadoc, signature, allRequired, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package eu.maveniverse.maven.toolbox.cli;

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import java.io.IOException;
import picocli.CommandLine;

Expand All @@ -23,6 +22,6 @@ public final class Identify extends SearchCommandSupport {

@Override
protected boolean doCall(Context context) throws IOException {
return ToolboxCommando.getOrCreate(context).identify(getRemoteRepository(), target, output);
return getToolboxCommando(context).identify(getRemoteRepository(), target, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.Artifacts;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import java.nio.file.Path;
import org.eclipse.aether.installation.InstallationException;
import picocli.CommandLine;
Expand Down Expand Up @@ -54,6 +53,6 @@ protected boolean doCall(Context context) throws InstallationException {
if (javadoc != null) {
artifacts.addJavadoc(javadoc);
}
return ToolboxCommando.getOrCreate(getContext()).install(artifacts, output);
return getToolboxCommando(context).install(artifacts, output);
}
}
3 changes: 1 addition & 2 deletions cli/src/main/java/eu/maveniverse/maven/toolbox/cli/List.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package eu.maveniverse.maven.toolbox.cli;

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import java.io.IOException;
import picocli.CommandLine;

Expand All @@ -23,6 +22,6 @@ public final class List extends SearchCommandSupport {

@Override
protected boolean doCall(Context context) throws IOException {
return ToolboxCommando.getOrCreate(context).list(getRemoteRepository(), gavoid, output);
return getToolboxCommando(context).list(getRemoteRepository(), gavoid, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package eu.maveniverse.maven.toolbox.cli;

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import picocli.CommandLine;

/**
Expand All @@ -22,6 +21,6 @@ public final class ListAvailablePlugins extends ResolverCommandSupport {

@Override
protected boolean doCall(Context context) throws Exception {
return ToolboxCommando.getOrCreate(context).listAvailablePlugins(groupIds, output);
return getToolboxCommando(context).listAvailablePlugins(groupIds, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class ListRepositories extends ResolverCommandSupport {

@Override
protected boolean doCall(Context context) throws Exception {
ToolboxCommando toolboxCommando = ToolboxCommando.getOrCreate(context);
ToolboxCommando toolboxCommando = getToolboxCommando(context);
return toolboxCommando.listRepositories(
ResolutionScope.parse(resolutionScope),
toolboxCommando.toolboxResolver().loadGav(gav, boms),
Expand Down
3 changes: 1 addition & 2 deletions cli/src/main/java/eu/maveniverse/maven/toolbox/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
Resolve.class,
Search.class,
Tree.class,
Test.class,
Verify.class
},
versionProvider = Main.class,
Expand All @@ -41,7 +40,7 @@
public class Main extends CommandSupport {
@Override
protected boolean doCall(Context context) {
mayDumpEnv(getRuntime(), context, false);
getToolboxCommando(context).dump(false, output);
return new Repl().doCall(context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package eu.maveniverse.maven.toolbox.cli;

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import org.eclipse.aether.resolution.DependencyResolutionException;
import picocli.CommandLine;

Expand All @@ -26,9 +25,9 @@ public final class Record extends ResolverCommandSupport {
@Override
protected boolean doCall(Context context) throws DependencyResolutionException {
if (stop) {
return ToolboxCommando.getOrCreate(context).recordStop(output);
return getToolboxCommando(context).recordStop(output);
} else {
return ToolboxCommando.getOrCreate(context).recordStart(output);
return getToolboxCommando(context).recordStart(output);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final class Resolve extends ResolverCommandSupport {

@Override
protected boolean doCall(Context context) throws Exception {
ToolboxCommando toolboxCommando = ToolboxCommando.getOrCreate(context);
ToolboxCommando toolboxCommando = getToolboxCommando(context);
return toolboxCommando.resolve(
ResolutionScope.parse(resolutionScope),
toolboxCommando.toolboxResolver().loadGav(gav, boms),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package eu.maveniverse.maven.toolbox.cli;

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import java.io.IOException;
import picocli.CommandLine;

Expand All @@ -23,6 +22,6 @@ public final class Search extends SearchCommandSupport {

@Override
protected boolean doCall(Context context) throws IOException {
return ToolboxCommando.getOrCreate(context).search(getRemoteRepository(), expression, output);
return getToolboxCommando(context).search(getRemoteRepository(), expression, output);
}
}
23 changes: 0 additions & 23 deletions cli/src/main/java/eu/maveniverse/maven/toolbox/cli/Test.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class Tree extends ResolverCommandSupport {

@Override
protected boolean doCall(Context context) throws Exception {
ToolboxCommando toolboxCommando = ToolboxCommando.getOrCreate(context);
ToolboxCommando toolboxCommando = getToolboxCommando(context);
return toolboxCommando.tree(
ResolutionScope.parse(resolutionScope),
toolboxCommando.toolboxResolver().loadGav(gav, boms),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package eu.maveniverse.maven.toolbox.cli;

import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import java.io.IOException;
import picocli.CommandLine;

Expand All @@ -26,6 +25,6 @@ public final class Verify extends SearchCommandSupport {

@Override
protected boolean doCall(Context context) throws IOException {
return ToolboxCommando.getOrCreate(context).verify(getRemoteRepository(), gav, sha1, output);
return getToolboxCommando(context).verify(getRemoteRepository(), gav, sha1, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
try (Context context = runtime.create(ContextOverrides.create().build())) {
ResolutionRoot root =
ResolutionRoot.ofLoaded(new DefaultArtifact(gav)).build();
ToolboxCommando.getOrCreate(context)
ToolboxCommando.getOrCreate(runtime, context)
.tree(ResolutionScope.parse(scope), root, false, new Slf4jOutput(logger));
} catch (RuntimeException e) {
throw new MojoExecutionException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
mavenProject,
artifactHandlerManager,
context.repositorySystemSession().getArtifactTypeRegistry());
ToolboxCommando.getOrCreate(context)
ToolboxCommando.getOrCreate(runtime, context)
.tree(ResolutionScope.parse(scope), root, false, new Slf4jOutput(logger));
} catch (RuntimeException e) {
throw new MojoExecutionException(e.getCause());
Expand Down
Loading

0 comments on commit f1af4ed

Please sign in to comment.