CLIng: finish TODO (#1888)

Also clear up javadoc.
This commit is contained in:
Tamas Cservenak 2024-11-07 17:41:13 +01:00 committed by GitHub
parent a836e898b0
commit 457bb8e000
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 31 additions and 7 deletions

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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<MavenOptions, ForkedMavenInvokerRequest>
implements ForkedMavenParser {
@ -55,8 +63,17 @@ public class DefaultForkedMavenParser extends BaseMavenParser<MavenOptions, Fork
protected List<String> 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;
}

View File

@ -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<MavenOptions>, DefaultLocalMavenInvoker.LocalContext>

View File

@ -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<