diff --git a/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/forked/ForkedMavenInvoker.java b/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/forked/ForkedMavenInvoker.java index 330eea91c5..ee75b2400b 100644 --- a/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/forked/ForkedMavenInvoker.java +++ b/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/forked/ForkedMavenInvoker.java @@ -22,7 +22,7 @@ import org.apache.maven.api.annotations.Experimental; import org.apache.maven.api.cli.mvn.MavenInvoker; /** - * Local Maven invoker. + * Forked Maven invoker. * * @since 4.0.0 */ diff --git a/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/local/LocalMavenInvoker.java b/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/local/LocalMavenInvoker.java index 73d604413e..ed429c2220 100644 --- a/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/local/LocalMavenInvoker.java +++ b/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/local/LocalMavenInvoker.java @@ -24,7 +24,7 @@ import org.apache.maven.api.cli.mvn.MavenInvokerRequest; import org.apache.maven.api.cli.mvn.MavenOptions; /** - * Local Maven invoker. + * Local Maven invoker, it expects all the Maven be present in classpath. * * @since 4.0.0 */ diff --git a/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/resident/ResidentMavenInvoker.java b/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/resident/ResidentMavenInvoker.java index ec9f9e0161..5743c7bb2c 100644 --- a/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/resident/ResidentMavenInvoker.java +++ b/api/maven-api-cli/src/main/java/org/apache/maven/api/cli/mvn/resident/ResidentMavenInvoker.java @@ -25,7 +25,7 @@ import org.apache.maven.api.cli.mvn.MavenInvokerRequest; import org.apache.maven.api.cli.mvn.MavenOptions; /** - * Resident invoker. Instance is shut down when this instance is closed. + * Resident Maven invoker, similar to local. Instance is shut down when this instance is closed. * * @since 4.0.0 */ diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/forked/DefaultForkedMavenParser.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/forked/DefaultForkedMavenParser.java index 1f8173e167..c46164e822 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/forked/DefaultForkedMavenParser.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/forked/DefaultForkedMavenParser.java @@ -18,8 +18,13 @@ */ package org.apache.maven.cling.invoker.mvn.forked; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; import java.nio.file.Path; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import org.apache.commons.cli.ParseException; import org.apache.maven.api.cli.ParserException; @@ -30,6 +35,9 @@ import org.apache.maven.cling.invoker.mvn.BaseMavenParser; import org.apache.maven.cling.invoker.mvn.CommonsCliMavenOptions; import org.apache.maven.cling.invoker.mvn.LayeredMavenOptions; +/** + * Forked invoker that invokes Maven in a child process. + */ public class DefaultForkedMavenParser extends BaseMavenParser implements ForkedMavenParser { @@ -55,8 +63,17 @@ public class DefaultForkedMavenParser extends BaseMavenParser getJvmArguments(Path rootDirectory) { if (rootDirectory != null) { - // TODO: do this - return null; + Path jvmConfig = rootDirectory.resolve(".mvn/jvm.config"); + if (Files.exists(jvmConfig)) { + try { + return Files.readAllLines(jvmConfig).stream() + .filter(l -> !l.isBlank() && !l.startsWith("#")) + .flatMap(l -> Arrays.stream(l.split(" "))) + .collect(Collectors.toList()); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } } return null; } diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/local/DefaultLocalMavenInvoker.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/local/DefaultLocalMavenInvoker.java index 529af514cf..0f68baccda 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/local/DefaultLocalMavenInvoker.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/local/DefaultLocalMavenInvoker.java @@ -24,6 +24,12 @@ import org.apache.maven.api.cli.mvn.local.LocalMavenInvoker; import org.apache.maven.cling.invoker.ProtoLookup; import org.apache.maven.cling.invoker.mvn.DefaultMavenInvoker; +/** + * Local invoker implementation, when Maven CLI is being run. System uses ClassWorld launcher, and class world + * instance is passed in via "enhanced" main method. Hence, this class expects fully setup ClassWorld via constructor. + * + * @see org.apache.maven.cling.MavenCling + */ public class DefaultLocalMavenInvoker extends DefaultMavenInvoker< MavenOptions, MavenInvokerRequest, DefaultLocalMavenInvoker.LocalContext> diff --git a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/resident/DefaultResidentMavenInvoker.java b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/resident/DefaultResidentMavenInvoker.java index 21bb815062..77890e9248 100644 --- a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/resident/DefaultResidentMavenInvoker.java +++ b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/resident/DefaultResidentMavenInvoker.java @@ -29,8 +29,9 @@ import org.apache.maven.cling.invoker.ProtoLookup; import org.apache.maven.cling.invoker.mvn.DefaultMavenInvoker; /** - * Local invoker implementation, when Maven CLI is being run. System uses ClassWorld launcher, and class world - * instance is passed in via "enhanced" main method. Hence, this class expects fully setup ClassWorld via constructor. + * Local resident invoker implementation, similar to "local" but keeps Maven instance resident. This implies, that + * things like environment, system properties, extensions etc. are loaded only once. It is caller duty to ensure + * that subsequent call is right for the resident instance (ie no env change or different extension needed). */ public class DefaultResidentMavenInvoker extends DefaultMavenInvoker<