Skip to content

Commit

Permalink
CLIng: finish TODO (#1888)
Browse files Browse the repository at this point in the history
Also clear up javadoc.
  • Loading branch information
cstamas authored Nov 7, 2024
1 parent a836e89 commit 457bb8e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.apache.maven.api.cli.mvn.MavenInvoker;

/**
* Local Maven invoker.
* Forked Maven invoker.
*
* @since 4.0.0
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +35,9 @@
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 {

Expand All @@ -55,8 +63,17 @@ protected ForkedMavenInvokerRequest getInvokerRequest(LocalContext context) {

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
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<
Expand Down

0 comments on commit 457bb8e

Please sign in to comment.