Skip to content

Commit

Permalink
Do not wrap exceptions if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 22, 2024
1 parent 4195200 commit 3f2ab89
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import java.nio.file.Path;
import java.util.stream.Collectors;
import picocli.CommandLine;

/**
Expand Down Expand Up @@ -47,18 +46,7 @@ protected boolean doCall(Context context) throws Exception {
ToolboxCommando toolboxCommando = getToolboxCommando(context);
return toolboxCommando.copyTransitive(
ResolutionScope.parse(resolutionScope),
gav.stream()
.map(g -> {
try {
return toolboxCommando.loadGav(g, boms);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new RuntimeException(e);
}
})
.collect(Collectors.toList()),
toolboxCommando.loadGavs(gav, boms),
DirectorySink.flat(output, targetPath),
output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import eu.maveniverse.maven.mima.context.Context;
import eu.maveniverse.maven.toolbox.shared.ResolutionScope;
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando;
import java.util.stream.Collectors;
import picocli.CommandLine;

/**
Expand Down Expand Up @@ -55,18 +54,7 @@ protected boolean doCall(Context context) throws Exception {
ToolboxCommando toolboxCommando = getToolboxCommando(context);
return toolboxCommando.resolveTransitive(
ResolutionScope.parse(resolutionScope),
gav.stream()
.map(g -> {
try {
return toolboxCommando.loadGav(g, boms);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new RuntimeException(e);
}
})
.collect(Collectors.toList()),
toolboxCommando.loadGavs(gav, boms),
sources,
javadoc,
signature,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@
import eu.maveniverse.maven.toolbox.shared.internal.ToolboxCommandoImpl;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactDescriptorException;

/**
* The Toolbox Commando, that implements all the commands that are exposed via Mojos or CLI.
* <p>
* This instance manages {@link Context}, corresponding {@link ToolboxResolver} and {@link ToolboxSearchApi}
* and maps one-to-one onto commands. Can be considered something like "high level" API of Toolbox.
* <p>
* Note on error handling: each "commando" method is marked to throw and returns a {@link boolean}.
* If method cleanly returns, the result shows the "successful" outcome of command. If method throws,
* {@link RuntimeException} instances (for example NPE, IAEx, ISEx) mark "bad input", or configuration
* errors. The checked exception instances on the other hand come from corresponding subsystem like
* resolver is. Finally, {@link IOException} is thrown on fatal IO problems.
* Note on error handling: each "commando" method is marked to throw and return a {@link boolean}.
* If method cleanly returns, the result shows the "logical success" of the command (think about it {@code false} means
* "this execution was no-op"). If method throws, {@link RuntimeException} instances (for example NPE, IAEx, ISEx)
* mark "bad input", or configuration related errors. The checked exception instances on the other hand come from
* corresponding subsystem like resolver is. Finally, {@link IOException} is thrown on fatal IO problems.
*/
public interface ToolboxCommando extends Closeable {
/**
Expand All @@ -56,16 +59,30 @@ static ToolboxCommando create(Runtime runtime, Context context) {
// Resolver related commands: they target current context contained RemoteRepository

/**
* Shorthand method, creates {@link ResolutionRoot} our of passed in artifact.
* Shorthand method, creates {@link ResolutionRoot} out of passed in artifact.
*/
default ResolutionRoot loadGav(String gav) throws Exception {
default ResolutionRoot loadGav(String gav) throws ArtifactDescriptorException {
return loadGav(gav, Collections.emptyList());
}

/**
* Shorthand method, creates {@link ResolutionRoot} our of passed in artifact and BOMs.
* Shorthand method, creates {@link ResolutionRoot} out of passed in artifact and BOMs.
*
* @see ToolboxResolver#loadGav(String, Collection)
*/
ResolutionRoot loadGav(String gav, Collection<String> boms) throws Exception;
ResolutionRoot loadGav(String gav, Collection<String> boms) throws ArtifactDescriptorException;

/**
* Shorthand method, creates collection {@link ResolutionRoot}s out of passed in artifacts and BOMs.
*/
default Collection<ResolutionRoot> loadGavs(Collection<String> gav, Collection<String> boms)
throws ArtifactDescriptorException {
List<ResolutionRoot> result = new ArrayList<>(gav.size());
for (String gavEntry : gav) {
result.add(loadGav(gavEntry, boms));
}
return result;
}

boolean classpath(ResolutionScope resolutionScope, ResolutionRoot resolutionRoot, Output output) throws Exception;

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

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.eclipse.aether.artifact.Artifact;
import org.eclipse.aether.collection.CollectResult;
Expand Down Expand Up @@ -55,13 +54,6 @@ public interface ToolboxResolver {
*/
RemoteRepository parseDeploymentRemoteRepository(String spec);

/**
* Shorthand method, creates {@link ResolutionRoot} our of passed in artifact.
*/
default ResolutionRoot loadGav(String gav) throws ArtifactDescriptorException {
return loadGav(gav, Collections.emptyList());
}

/**
* Shorthand method, creates {@link ResolutionRoot} our of passed in artifact and BOMs.
*/
Expand Down

0 comments on commit 3f2ab89

Please sign in to comment.