diff --git a/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorException.java b/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorException.java index d1c4a918c1f0..022e5e7ade10 100644 --- a/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorException.java +++ b/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorException.java @@ -29,7 +29,7 @@ * @since 4.0.0 */ @Experimental -public class ExecutorException extends RuntimeException { +public class ExecutorException extends Exception { /** * Constructs a new {@code InvokerException} with the specified detail message. * diff --git a/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java b/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java index 70e76da74aad..1a070cac7d0b 100644 --- a/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java +++ b/impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java @@ -168,7 +168,7 @@ default Builder toBuilder() { * also discovered by standard means. */ @Nonnull - static Builder mavenBuilder(@Nullable Path installationDirectory) { + static Builder mavenBuilder(@Nullable Path installationDirectory) throws ExecutorException { return new Builder( MVN, null, @@ -462,7 +462,7 @@ public String toString() { } @Nonnull - static Path discoverInstallationDirectory() { + static Path discoverInstallationDirectory() throws ExecutorException { String mavenHome = System.getProperty("maven.home"); if (mavenHome == null) { throw new ExecutorException("requires maven.home Java System Property set"); @@ -471,7 +471,7 @@ static Path discoverInstallationDirectory() { } @Nonnull - static Path discoverUserHomeDirectory() { + static Path discoverUserHomeDirectory() throws ExecutorException { String userHome = System.getProperty("user.home"); if (userHome == null) { throw new ExecutorException("requires user.home Java System Property set"); diff --git a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/ExecutorHelper.java b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/ExecutorHelper.java index c6dc27feb0ae..db2e333bef0b 100644 --- a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/ExecutorHelper.java +++ b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/ExecutorHelper.java @@ -58,7 +58,7 @@ enum Mode { * properly initialized request builder. */ @Nonnull - ExecutorRequest.Builder executorRequest(); + ExecutorRequest.Builder executorRequest() throws ExecutorException; /** * Executes the request with preferred mode executor. diff --git a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java index 07194c279811..7020f090f285 100644 --- a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java +++ b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutor.java @@ -176,7 +176,7 @@ protected void disposeRuntimeCreatedRealms(Context context) { } } } catch (Exception e) { - throw new ExecutorException("Failed to dispose runtime created realms", e); + throw new RuntimeException(new ExecutorException("Failed to dispose runtime created realms", e)); } } @@ -285,7 +285,7 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) { args.toArray(new String[0]), r.cwd().toString(), stdout, stderr }); } catch (Exception e) { - throw new ExecutorException("Failed to execute", e); + throw new RuntimeException(new ExecutorException("Failed to execute", e)); } }); } else { @@ -313,7 +313,7 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) { r.stdOut().orElse(null), r.stdErr().orElse(null)); } catch (Exception e) { - throw new ExecutorException("Failed to execute", e); + throw new RuntimeException(new ExecutorException("Failed to execute", e)); } }); } @@ -328,7 +328,7 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) { commands, keepAlive); } catch (Exception e) { - throw new ExecutorException("Failed to create executor", e); + throw new RuntimeException(new ExecutorException("Failed to create executor", e)); } finally { Thread.currentThread().setContextClassLoader(originalClassLoader); System.setProperties(originalProperties); @@ -402,7 +402,7 @@ protected void doClose(Context context) throws ExecutorException { } } - protected void validate(ExecutorRequest executorRequest) throws ExecutorException {} + protected void validate(ExecutorRequest ignored) {} protected URLClassLoader createMavenBootClassLoader(Path boot, List extraClasspath) { ArrayList urls = new ArrayList<>(extraClasspath); @@ -413,11 +413,11 @@ protected URLClassLoader createMavenBootClassLoader(Path boot, List extraCl try { urls.add(f.toUri().toURL()); } catch (MalformedURLException e) { - throw new ExecutorException("Failed to build classpath: " + f, e); + throw new RuntimeException(new ExecutorException("Failed to build classpath: " + f, e)); } }); } catch (IOException e) { - throw new ExecutorException("Failed to build classpath: " + e, e); + throw new RuntimeException(new ExecutorException("Failed to build classpath: " + e, e)); } if (urls.isEmpty()) { throw new IllegalArgumentException("Invalid Maven home directory; boot is empty"); diff --git a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java index 9a94ddc2ddfd..1ea636391a8f 100644 --- a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java +++ b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/HelperImpl.java @@ -47,7 +47,8 @@ public HelperImpl( @Nullable Path installationDirectory, @Nullable Path userHomeDirectory, Executor embedded, - Executor forked) { + Executor forked) + throws ExecutorException { this.defaultMode = requireNonNull(defaultMode); this.installationDirectory = installationDirectory != null ? ExecutorRequest.getCanonicalPath(installationDirectory) @@ -68,7 +69,7 @@ public Mode getDefaultMode() { } @Override - public ExecutorRequest.Builder executorRequest() { + public ExecutorRequest.Builder executorRequest() throws ExecutorException { return ExecutorRequest.mavenBuilder(installationDirectory).userHomeDirectory(userHomeDirectory); } @@ -80,12 +81,16 @@ public int execute(Mode mode, ExecutorRequest executorRequest) throws ExecutorEx @Override public String mavenVersion() { return cache.computeIfAbsent("maven.version", k -> { - ExecutorRequest request = executorRequest().build(); - return getExecutor(Mode.AUTO, request).mavenVersion(request); + try { + ExecutorRequest request = executorRequest().build(); + return getExecutor(Mode.AUTO, request).mavenVersion(request); + } catch (ExecutorException e) { + throw new RuntimeException(e); + } }); } - protected Executor getExecutor(Mode mode, ExecutorRequest request) throws ExecutorException { + protected Executor getExecutor(Mode mode, ExecutorRequest request) { return switch (mode) { case AUTO -> getExecutorByRequest(request); case EMBEDDED -> executors.get(Mode.EMBEDDED); diff --git a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/ToolboxTool.java b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/ToolboxTool.java index 1aaa5480180b..aafcac13765a 100644 --- a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/ToolboxTool.java +++ b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/ToolboxTool.java @@ -122,7 +122,7 @@ private ExecutorRequest.Builder mojo(ExecutorRequest.Builder builder, String moj return builder.argument(TOOLBOX + mojo).argument("--quiet").argument("-DforceStdout"); } - private void doExecute(ExecutorRequest.Builder builder) { + private void doExecute(ExecutorRequest.Builder builder) throws ExecutorException { ExecutorRequest request = builder.build(); int ec = helper.execute(request); if (ec != 0) { diff --git a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/MavenExecutorTestSupport.java b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/MavenExecutorTestSupport.java index 98a0d641d2ec..9fb23168ac38 100644 --- a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/MavenExecutorTestSupport.java +++ b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/MavenExecutorTestSupport.java @@ -28,6 +28,7 @@ import org.apache.maven.api.annotations.Nullable; import org.apache.maven.api.cli.Executor; +import org.apache.maven.api.cli.ExecutorException; import org.apache.maven.api.cli.ExecutorRequest; import org.apache.maven.cling.executor.embedded.EmbeddedMavenExecutor; import org.apache.maven.cling.executor.forked.ForkedMavenExecutor; @@ -323,11 +324,11 @@ protected String mavenVersion(ExecutorRequest request) throws Exception { return createAndMemoizeExecutor().mavenVersion(request); } - public static ExecutorRequest.Builder mvn3ExecutorRequestBuilder() { + public static ExecutorRequest.Builder mvn3ExecutorRequestBuilder() throws ExecutorException { return ExecutorRequest.mavenBuilder(Paths.get(System.getProperty("maven3home"))); } - public static ExecutorRequest.Builder mvn4ExecutorRequestBuilder() { + public static ExecutorRequest.Builder mvn4ExecutorRequestBuilder() throws ExecutorException { return ExecutorRequest.mavenBuilder(Paths.get(System.getProperty("maven4home"))); } diff --git a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/ToolboxToolTest.java b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/ToolboxToolTest.java index cd84eaca2f00..d78ec6e1a9e4 100644 --- a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/ToolboxToolTest.java +++ b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/impl/ToolboxToolTest.java @@ -24,6 +24,7 @@ import java.nio.file.Paths; import java.util.Map; +import org.apache.maven.api.cli.ExecutorException; import org.apache.maven.cling.executor.ExecutorHelper; import org.apache.maven.cling.executor.MavenExecutorTestSupport; import org.apache.maven.cling.executor.MimirInfuser; @@ -81,7 +82,7 @@ void dump4(ExecutorHelper.Mode mode) throws Exception { @Timeout(15) @ParameterizedTest @EnumSource(ExecutorHelper.Mode.class) - void version3(ExecutorHelper.Mode mode) { + void version3(ExecutorHelper.Mode mode) throws ExecutorException { ExecutorHelper helper = new HelperImpl( mode, mvn3ExecutorRequestBuilder().build().installationDirectory(), @@ -94,7 +95,7 @@ void version3(ExecutorHelper.Mode mode) { @Timeout(15) @ParameterizedTest @EnumSource(ExecutorHelper.Mode.class) - void version4(ExecutorHelper.Mode mode) { + void version4(ExecutorHelper.Mode mode) throws ExecutorException { ExecutorHelper helper = new HelperImpl( mode, mvn4ExecutorRequestBuilder().build().installationDirectory(), @@ -107,7 +108,7 @@ void version4(ExecutorHelper.Mode mode) { @Timeout(15) @ParameterizedTest @EnumSource(ExecutorHelper.Mode.class) - void localRepository3(ExecutorHelper.Mode mode) { + void localRepository3(ExecutorHelper.Mode mode) throws ExecutorException { ExecutorHelper helper = new HelperImpl( mode, mvn3ExecutorRequestBuilder().build().installationDirectory(), @@ -123,7 +124,7 @@ void localRepository3(ExecutorHelper.Mode mode) { @ParameterizedTest @EnumSource(ExecutorHelper.Mode.class) @Disabled("disable temporarily so that we can get the debug statement") - void localRepository4(ExecutorHelper.Mode mode) { + void localRepository4(ExecutorHelper.Mode mode) throws ExecutorException { ExecutorHelper helper = new HelperImpl( mode, mvn4ExecutorRequestBuilder().build().installationDirectory(), @@ -138,7 +139,7 @@ void localRepository4(ExecutorHelper.Mode mode) { @Timeout(15) @ParameterizedTest @EnumSource(ExecutorHelper.Mode.class) - void artifactPath3(ExecutorHelper.Mode mode) { + void artifactPath3(ExecutorHelper.Mode mode) throws ExecutorException { ExecutorHelper helper = new HelperImpl( mode, mvn3ExecutorRequestBuilder().build().installationDirectory(), @@ -157,7 +158,7 @@ void artifactPath3(ExecutorHelper.Mode mode) { @Timeout(15) @ParameterizedTest @EnumSource(ExecutorHelper.Mode.class) - void artifactPath4(ExecutorHelper.Mode mode) { + void artifactPath4(ExecutorHelper.Mode mode) throws ExecutorException { ExecutorHelper helper = new HelperImpl( mode, mvn4ExecutorRequestBuilder().build().installationDirectory(), @@ -176,7 +177,7 @@ void artifactPath4(ExecutorHelper.Mode mode) { @Timeout(15) @ParameterizedTest @EnumSource(ExecutorHelper.Mode.class) - void metadataPath3(ExecutorHelper.Mode mode) { + void metadataPath3(ExecutorHelper.Mode mode) throws ExecutorException { ExecutorHelper helper = new HelperImpl( mode, mvn3ExecutorRequestBuilder().build().installationDirectory(), @@ -191,7 +192,7 @@ void metadataPath3(ExecutorHelper.Mode mode) { @Timeout(15) @ParameterizedTest @EnumSource(ExecutorHelper.Mode.class) - void metadataPath4(ExecutorHelper.Mode mode) { + void metadataPath4(ExecutorHelper.Mode mode) throws ExecutorException { ExecutorHelper helper = new HelperImpl( mode, mvn4ExecutorRequestBuilder().build().installationDirectory(),