Skip to content

Commit

Permalink
Simplify daemon options
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Nov 22, 2024
1 parent 8bfe902 commit 3c4a21d
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
package org.apache.maven.cli;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.function.Consumer;
Expand All @@ -33,18 +30,13 @@

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.ParseException;
import org.apache.maven.cling.invoker.mvn.CommonsCliMavenOptions;
import org.apache.maven.jline.MessageUtils;
import org.codehaus.plexus.interpolation.BasicInterpolator;
import org.codehaus.plexus.interpolation.InterpolationException;
import org.mvndaemon.mvnd.common.Environment;
import org.mvndaemon.mvnd.common.OptionType;

import static org.apache.maven.cling.invoker.Utils.createInterpolator;

public class CommonsCliDaemonMavenOptions extends CommonsCliMavenOptions implements DaemonMavenOptions {
public class CommonsCliDaemonMavenOptions extends CommonsCliMavenOptions {
public static CommonsCliDaemonMavenOptions parse(String source, String[] args) throws ParseException {
CLIManager cliManager = new CLIManager();
return new CommonsCliDaemonMavenOptions(source, cliManager, cliManager.parse(args));
Expand All @@ -54,31 +46,6 @@ protected CommonsCliDaemonMavenOptions(String source, CLIManager cliManager, Com
super(source, cliManager, commandLine);
}

@Override
public DaemonMavenOptions interpolate(Collection<Map<String, String>> properties) {
try {
// now that we have properties, interpolate all arguments
BasicInterpolator interpolator = createInterpolator(properties);
CommandLine.Builder commandLineBuilder = new CommandLine.Builder();
commandLineBuilder.setDeprecatedHandler(o -> {});
for (Option option : commandLine.getOptions()) {
if (!CLIManager.USER_PROPERTY.equals(option.getOpt())) {
List<String> values = option.getValuesList();
for (ListIterator<String> it = values.listIterator(); it.hasNext(); ) {
it.set(interpolator.interpolate(it.next()));
}
}
commandLineBuilder.addOption(option);
}
for (String arg : commandLine.getArgList()) {
commandLineBuilder.addArg(interpolator.interpolate(arg));
}
return new CommonsCliDaemonMavenOptions(source, (CLIManager) cliManager, commandLineBuilder.build());
} catch (InterpolationException e) {
throw new IllegalArgumentException("Could not interpolate CommonsCliOptions", e);
}
}

protected static class CLIManager extends CommonsCliMavenOptions.CLIManager {
private static final Pattern HTML_TAGS_PATTERN = Pattern.compile("<[^>]*>");
private static final Pattern COLUMNS_DETECTOR_PATTERN = Pattern.compile("^[ ]+[^s]");
Expand Down
29 changes: 0 additions & 29 deletions daemon/src/main/java/org/apache/maven/cli/DaemonMavenOptions.java

This file was deleted.

29 changes: 1 addition & 28 deletions daemon/src/main/java/org/apache/maven/cli/DaemonMavenParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,13 @@
import java.util.stream.Stream;

import org.apache.commons.cli.ParseException;
import org.apache.maven.api.cli.Options;
import org.apache.maven.api.cli.ParserException;
import org.apache.maven.api.cli.extensions.CoreExtension;
import org.apache.maven.api.cli.mvn.MavenOptions;
import org.apache.maven.cling.invoker.mvn.MavenInvokerRequest;
import org.apache.maven.cling.invoker.mvn.MavenParser;
import org.mvndaemon.mvnd.common.Environment;

public class DaemonMavenParser extends MavenParser {
@Override
protected MavenInvokerRequest getInvokerRequest(LocalContext context) {
return new MavenInvokerRequest(
context.parserRequest,
context.cwd,
context.installationDirectory,
context.userHomeDirectory,
context.userProperties,
context.systemProperties,
context.topDirectory,
context.rootDirectory,
context.parserRequest.in(),
context.parserRequest.out(),
context.parserRequest.err(),
context.extensions,
getJvmArguments(context.rootDirectory),
(DaemonMavenOptions) context.options);
}

@Override
protected MavenOptions parseArgs(String source, List<String> args) throws ParserException {
try {
Expand All @@ -61,12 +40,6 @@ protected MavenOptions parseArgs(String source, List<String> args) throws Parser
}
}

@Override
protected MavenOptions assembleOptions(List<Options> parsedOptions) {
return LayeredDaemonMavenOptions.layerDaemonMavenOptions(
parsedOptions.stream().map(o -> (DaemonMavenOptions) o).toList());
}

@Override
protected Map<String, String> populateSystemProperties(LocalContext context) throws ParserException {
HashMap<String, String> systemProperties = new HashMap<>(super.populateSystemProperties(context));
Expand All @@ -81,7 +54,7 @@ protected Map<String, String> populateSystemProperties(LocalContext context) thr
@Override
protected List<CoreExtension> readCoreExtensionsDescriptor(LocalContext context) {
return Stream.of(Environment.MVND_CORE_EXTENSIONS.asString().split(";"))
.filter(s -> s != null && !s.isEmpty())
.filter(s -> !s.isEmpty())
.map(s -> {
String[] parts = s.split(":");
return CoreExtension.newBuilder()
Expand Down

This file was deleted.

0 comments on commit 3c4a21d

Please sign in to comment.