Feat: collapse maven-executor and apply fixes (#11976)
Changes:
* collapse Maven Executor into single package
* keepAlive is firgiving, but adjusted to Maven 3.10.x (rc-5 fails with 3.10.x)
diff --git a/impl/maven-executor/src/main/java/org/apache/maven/api/cli/Executor.java b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/Executor.java
similarity index 98%
rename from impl/maven-executor/src/main/java/org/apache/maven/api/cli/Executor.java
rename to impl/maven-executor/src/main/java/org/apache/maven/cling/executor/Executor.java
index 90c4391..80107a9 100644
--- a/impl/maven-executor/src/main/java/org/apache/maven/api/cli/Executor.java
+++ b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/Executor.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api.cli;
+package org.apache.maven.cling.executor;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nonnull;
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/cling/executor/ExecutorException.java
similarity index 97%
rename from impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorException.java
rename to impl/maven-executor/src/main/java/org/apache/maven/cling/executor/ExecutorException.java
index d1c4a91..8d8fbfd 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/cling/executor/ExecutorException.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api.cli;
+package org.apache.maven.cling.executor;
import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Nullable;
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 c6dc27f..8aea8b2 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
@@ -19,9 +19,6 @@
package org.apache.maven.cling.executor;
import org.apache.maven.api.annotations.Nonnull;
-import org.apache.maven.api.cli.Executor;
-import org.apache.maven.api.cli.ExecutorException;
-import org.apache.maven.api.cli.ExecutorRequest;
/**
* Helper class for routing Maven execution based on preferences and/or issued execution requests.
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/cling/executor/ExecutorRequest.java
similarity index 99%
rename from impl/maven-executor/src/main/java/org/apache/maven/api/cli/ExecutorRequest.java
rename to impl/maven-executor/src/main/java/org/apache/maven/cling/executor/ExecutorRequest.java
index b056c0f..1e7118f 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/cling/executor/ExecutorRequest.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.maven.api.cli;
+package org.apache.maven.cling.executor;
import java.io.InputStream;
import java.io.OutputStream;
diff --git a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/ExecutorTool.java b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/ExecutorTool.java
index 4bfe4be..4a97767 100644
--- a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/ExecutorTool.java
+++ b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/ExecutorTool.java
@@ -21,8 +21,6 @@
import java.util.Map;
import org.apache.maven.api.annotations.Nullable;
-import org.apache.maven.api.cli.ExecutorException;
-import org.apache.maven.api.cli.ExecutorRequest;
/**
* A tool implementing some common Maven operations.
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 e5eda27..0e2ddaa 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
@@ -45,9 +45,9 @@
import java.util.function.Function;
import java.util.stream.Stream;
-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.Executor;
+import org.apache.maven.cling.executor.ExecutorException;
+import org.apache.maven.cling.executor.ExecutorRequest;
import static java.util.Objects.requireNonNull;
@@ -267,7 +267,11 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) {
throw new IllegalArgumentException(getClass().getSimpleName() + " w/ mvn3 does not support command "
+ executorRequest.command());
}
- keepAlive.add(cliClass.getClassLoader().loadClass("org.fusesource.jansi.internal.JansiLoader"));
+ // 3.9.x
+ mayAddToKeepAlive(keepAlive, cliClass, "org.fusesource.jansi.internal.JansiLoader");
+ // 3.10.x
+ mayAddToKeepAlive(keepAlive, cliClass, "org.jline.nativ.JLineNativeLoader");
+
Constructor<?> newMavenCli = cliClass.getConstructor(classWorld.getClass());
Object mavenCli = newMavenCli.newInstance(classWorld);
Class<?>[] parameterTypes = {String[].class, String.class, PrintStream.class, PrintStream.class};
@@ -292,7 +296,7 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) {
});
} else {
// assume 4.x
- keepAlive.add(cliClass.getClassLoader().loadClass("org.jline.nativ.JLineNativeLoader"));
+ mayAddToKeepAlive(keepAlive, cliClass, "org.jline.nativ.JLineNativeLoader");
for (Map.Entry<String, String> cmdEntry : MVN4_MAIN_CLASSES.entrySet()) {
Class<?> cmdClass = cliClass.getClassLoader().loadClass(cmdEntry.getValue());
Method mainMethod = cmdClass.getMethod(
@@ -337,6 +341,15 @@ protected Context doCreate(Path mavenHome, ExecutorRequest executorRequest) {
}
}
+ private boolean mayAddToKeepAlive(List<Object> keepAlive, Class<?> cliClass, String className) {
+ try {
+ keepAlive.add(cliClass.getClassLoader().loadClass(className));
+ return true;
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ }
+
protected Properties prepareProperties(ExecutorRequest request) {
System.setProperties(null); // this "inits" them!
diff --git a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/forked/ForkedMavenExecutor.java b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/forked/ForkedMavenExecutor.java
index a559a24..4671c74 100644
--- a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/forked/ForkedMavenExecutor.java
+++ b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/forked/ForkedMavenExecutor.java
@@ -33,12 +33,12 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
-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.Executor;
+import org.apache.maven.cling.executor.ExecutorException;
+import org.apache.maven.cling.executor.ExecutorRequest;
import static java.util.Objects.requireNonNull;
-import static org.apache.maven.api.cli.ExecutorRequest.getCanonicalPath;
+import static org.apache.maven.cling.executor.ExecutorRequest.getCanonicalPath;
/**
* Forked executor implementation, that spawns a subprocess with Maven from the installation directory. Very costly
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 8ba932c..d8109ba 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
@@ -23,10 +23,10 @@
import java.util.concurrent.ConcurrentHashMap;
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.Executor;
+import org.apache.maven.cling.executor.ExecutorException;
import org.apache.maven.cling.executor.ExecutorHelper;
+import org.apache.maven.cling.executor.ExecutorRequest;
import static java.util.Objects.requireNonNull;
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 ad2569a..2adc21c 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
@@ -26,9 +26,9 @@
import java.util.Properties;
import java.util.stream.Collectors;
-import org.apache.maven.api.cli.ExecutorException;
-import org.apache.maven.api.cli.ExecutorRequest;
+import org.apache.maven.cling.executor.ExecutorException;
import org.apache.maven.cling.executor.ExecutorHelper;
+import org.apache.maven.cling.executor.ExecutorRequest;
import org.apache.maven.cling.executor.ExecutorTool;
import static java.util.Objects.requireNonNull;
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 028efb0..a2a0952 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,8 +28,6 @@
import eu.maveniverse.maven.mimir.testing.MimirInfuser;
import org.apache.maven.api.annotations.Nullable;
-import org.apache.maven.api.cli.Executor;
-import org.apache.maven.api.cli.ExecutorRequest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
diff --git a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutorTest.java b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutorTest.java
index c214fc6..6433235 100644
--- a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutorTest.java
+++ b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/embedded/EmbeddedMavenExecutorTest.java
@@ -18,7 +18,7 @@
*/
package org.apache.maven.cling.executor.embedded;
-import org.apache.maven.api.cli.Executor;
+import org.apache.maven.cling.executor.Executor;
import org.apache.maven.cling.executor.MavenExecutorTestSupport;
/**
diff --git a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/forked/ForkedMavenExecutorTest.java b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/forked/ForkedMavenExecutorTest.java
index 5555e0b..a1f4362 100644
--- a/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/forked/ForkedMavenExecutorTest.java
+++ b/impl/maven-executor/src/test/java/org/apache/maven/cling/executor/forked/ForkedMavenExecutorTest.java
@@ -18,7 +18,7 @@
*/
package org.apache.maven.cling.executor.forked;
-import org.apache.maven.api.cli.Executor;
+import org.apache.maven.cling.executor.Executor;
import org.apache.maven.cling.executor.MavenExecutorTestSupport;
/**
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 8152f2a..fc85626 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
@@ -25,10 +25,10 @@
import java.util.Map;
import eu.maveniverse.maven.mimir.testing.MimirInfuser;
-import org.apache.maven.api.cli.Executor;
-import org.apache.maven.api.cli.ExecutorRequest;
import org.apache.maven.cling.executor.Environment;
+import org.apache.maven.cling.executor.Executor;
import org.apache.maven.cling.executor.ExecutorHelper;
+import org.apache.maven.cling.executor.ExecutorRequest;
import org.apache.maven.cling.executor.embedded.EmbeddedMavenExecutor;
import org.apache.maven.cling.executor.forked.ForkedMavenExecutor;
import org.apache.maven.cling.executor.internal.HelperImpl;
diff --git a/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java b/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java
index 32bc85f..c0f29a2 100644
--- a/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java
+++ b/its/core-it-support/maven-it-helper/src/main/java/org/apache/maven/it/Verifier.java
@@ -45,8 +45,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
-import org.apache.maven.api.cli.ExecutorException;
-import org.apache.maven.api.cli.ExecutorRequest;
+import org.apache.maven.cling.executor.ExecutorException;
+import org.apache.maven.cling.executor.ExecutorRequest;
import org.apache.maven.cling.executor.ExecutorHelper;
import org.apache.maven.cling.executor.ExecutorTool;
import org.apache.maven.cling.executor.embedded.EmbeddedMavenExecutor;