This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git
commit dade78541c95f14badaed5afb97df14065c58879 Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Thu Nov 7 15:32:34 2024 +0100 Upgrade to 4.0.0-rc-1 (fixes #1203 and #1204) # Conflicts: # pom.xml --- .mvn/maven.config | 3 - .mvn/release-settings.xml | 4 +- .../org/mvndaemon/mvnd/client/DefaultClient.java | 6 +- .../org/mvndaemon/mvnd/client/DefaultClient.java | 5 +- .../mvndaemon/mvnd/client/DaemonParameters.java | 2 +- .../org/mvndaemon/mvnd/common/Environment.java | 2 +- .../maven/cli/CommonsCliDaemonMavenOptions.java | 85 +++------------- .../org/apache/maven/cli/DaemonMavenCling.java | 2 +- .../org/apache/maven/cli/DaemonMavenInvoker.java | 113 +++++++++------------ .../org/apache/maven/cli/DaemonMavenOptions.java | 30 ------ .../org/apache/maven/cli/DaemonMavenParser.java | 30 +----- .../cli/DaemonPlexusContainerCapsuleFactory.java | 10 +- .../maven/cli/LayeredDaemonMavenOptions.java | 59 ----------- .../META-INF/maven/slf4j-configuration.properties | 2 +- pom.xml | 2 +- 15 files changed, 79 insertions(+), 276 deletions(-) diff --git a/.mvn/maven.config b/.mvn/maven.config deleted file mode 100644 index 4230c241..00000000 --- a/.mvn/maven.config +++ /dev/null @@ -1,3 +0,0 @@ --Dmaven.wagon.httpconnectionManager.ttlSeconds=120 --Dmaven.wagon.http.retryHandler.requestSentEnabled=true --Dmaven.wagon.http.retryHandler.count=10 diff --git a/.mvn/release-settings.xml b/.mvn/release-settings.xml index 791682b2..9353e02d 100644 --- a/.mvn/release-settings.xml +++ b/.mvn/release-settings.xml @@ -6,8 +6,8 @@ <id>maven-staging</id> <repositories> <repository> - <id>maven-staging-1</id> - <url>https://repository.apache.org/content/repositories/maven-1859/</url> + <id>maven-staging-rc1</id> + <url>https://repository.apache.org/content/repositories/maven-2247/</url> <releases> <enabled>true</enabled> </releases> diff --git a/client/src/main/java-fallback/org/mvndaemon/mvnd/client/DefaultClient.java b/client/src/main/java-fallback/org/mvndaemon/mvnd/client/DefaultClient.java index 0dd01585..cfcceb71 100644 --- a/client/src/main/java-fallback/org/mvndaemon/mvnd/client/DefaultClient.java +++ b/client/src/main/java-fallback/org/mvndaemon/mvnd/client/DefaultClient.java @@ -18,7 +18,7 @@ */ package org.mvndaemon.mvnd.client; -import org.apache.maven.cli.MavenCli; +import org.apache.maven.cling.MavenCling; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,8 +26,8 @@ public class DefaultClient { public static void main(String[] argv) throws Exception { final Logger LOGGER = LoggerFactory.getLogger(DefaultClient.class); LOGGER.warn("Found old JDK, fallback to the embedded maven!"); - LOGGER.warn("Use JDK 11+ to run maven-mvnd client!"); + LOGGER.warn("Use JDK 17+ to run maven-mvnd client!"); - MavenCli.main(argv); + MavenCling.main(argv); } } diff --git a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java index 7d9a2faa..dfc61897 100644 --- a/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java +++ b/client/src/main/java-mvnd/org/mvndaemon/mvnd/client/DefaultClient.java @@ -69,8 +69,6 @@ public class DefaultClient implements Client { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultClient.class); - private final DaemonParameters parameters; - public static void main(String[] argv) throws Exception { final List<String> args = new ArrayList<>(Arrays.asList(argv)); @@ -224,6 +222,8 @@ public class DefaultClient implements Client { .noneMatch(e -> e.hasCommandLineOption(Collections.singletonList(arg))); } + private final DaemonParameters parameters; + public DefaultClient(DaemonParameters parameters) { // Those options are needed in order to be able to set the environment correctly this.parameters = parameters.withJdkJavaOpts( @@ -484,7 +484,6 @@ public class DefaultClient implements Client { } private DefaultResult(List<String> args, Exception exception, int exitCode) { - super(); this.args = args; this.exception = exception; this.exitCode = exitCode; diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java index 23aaa5d9..9d2a773d 100644 --- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java +++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java @@ -46,7 +46,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.maven.api.cli.extensions.CoreExtension; -import org.apache.maven.cli.internal.extension.io.CoreExtensionsStaxReader; +import org.apache.maven.cling.internal.extension.io.CoreExtensionsStaxReader; import org.mvndaemon.mvnd.common.Environment; import org.mvndaemon.mvnd.common.InterpolationHelper; import org.mvndaemon.mvnd.common.Os; diff --git a/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java b/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java index 55848c53..5615d762 100644 --- a/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java +++ b/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java @@ -104,7 +104,7 @@ public enum Environment { /** Batch mode */ MAVEN_BATCH_MODE(null, null, null, OptionType.BOOLEAN, Flags.INTERNAL, "mvn:-B", "mvn:--batch-mode"), /** Debug */ - MAVEN_DEBUG(null, null, null, OptionType.BOOLEAN, Flags.INTERNAL, "mvn:-X", "mvn:--debug"), + MAVEN_DEBUG(null, null, null, OptionType.BOOLEAN, Flags.INTERNAL, "mvn:-X", "mvn:--verbose"), /** Version */ MAVEN_VERSION(null, null, null, OptionType.BOOLEAN, Flags.INTERNAL, "mvn:-v", "mvn:-version", "mvn:--version"), /** Show version */ diff --git a/daemon/src/main/java/org/apache/maven/cli/CommonsCliDaemonMavenOptions.java b/daemon/src/main/java/org/apache/maven/cli/CommonsCliDaemonMavenOptions.java index eed140a6..a846fab5 100644 --- a/daemon/src/main/java/org/apache/maven/cli/CommonsCliDaemonMavenOptions.java +++ b/daemon/src/main/java/org/apache/maven/cli/CommonsCliDaemonMavenOptions.java @@ -18,35 +18,25 @@ */ package org.apache.maven.cli; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; -import java.util.Collection; +import java.util.ArrayList; 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; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Stream; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; 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)); @@ -56,44 +46,7 @@ public class CommonsCliDaemonMavenOptions extends CommonsCliMavenOptions impleme super(source, cliManager, commandLine); } - public org.apache.commons.cli.Options getOptions() { - return this.cliManager.getOptions(); - } - - private static CommonsCliDaemonMavenOptions interpolate( - CommonsCliDaemonMavenOptions options, 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 : options.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 : options.commandLine.getArgList()) { - commandLineBuilder.addArg(interpolator.interpolate(arg)); - } - return new CommonsCliDaemonMavenOptions( - options.source, (CLIManager) options.cliManager, commandLineBuilder.build()); - } catch (InterpolationException e) { - throw new IllegalArgumentException("Could not interpolate CommonsCliOptions", e); - } - } - - @Override - public DaemonMavenOptions interpolate(Collection<Map<String, String>> properties) { - return interpolate(this, properties); - } - protected static class CLIManager extends CommonsCliMavenOptions.CLIManager { - public static final String RAW_STREAMS = "ras"; - private static final Pattern HTML_TAGS_PATTERN = Pattern.compile("<[^>]*>"); private static final Pattern COLUMNS_DETECTOR_PATTERN = Pattern.compile("^[ ]+[^s]"); private static final Pattern WS_PATTERN = Pattern.compile("\\s+"); @@ -103,28 +56,15 @@ public class CommonsCliDaemonMavenOptions extends CommonsCliMavenOptions impleme } @Override - protected void prepareOptions(Options options) { - super.prepareOptions(options); - options.addOption(Option.builder(RAW_STREAMS) - .longOpt("raw-streams") - .desc("Use raw-streams for daemon communication") - .build()); - } - - @Override - public void displayHelp(String command, PrintWriter pw) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (PrintWriter pww = new PrintWriter(new PrintStream(baos), true, StandardCharsets.UTF_8)) { - super.displayHelp(command, pww); - } - final String mvnHelp = baos.toString(StandardCharsets.UTF_8); - final Matcher m = COLUMNS_DETECTOR_PATTERN.matcher(mvnHelp); + public void displayHelp(String command, Consumer<String> pw) { + List<String> mvnHelp = new ArrayList<>(); + super.displayHelp(command, mvnHelp::add); + final Matcher m = COLUMNS_DETECTOR_PATTERN.matcher(String.join("\n", mvnHelp)); final String indent = m.find() ? m.group() : " "; - final int terminalWidth = getTerminalWidth(); + int terminalWidth = getTerminalWidth() <= 0 ? 74 : getTerminalWidth(); final String lineSeparator = System.lineSeparator(); - final StringBuilder help = - new StringBuilder(mvnHelp).append(lineSeparator).append("mvnd specific options:"); + final StringBuilder help = new StringBuilder().append(lineSeparator).append("mvnd specific options:"); Environment.documentedEntries().forEach(entry -> { final Environment env = entry.getEntry(); @@ -190,9 +130,8 @@ public class CommonsCliDaemonMavenOptions extends CommonsCliMavenOptions impleme spaces(help, indentPos - help.length()); wrap(help, toPlainText(entry.getJavaDoc()), terminalWidth, lineEnd, indent); }); - - pw.print(help); - pw.flush(); + Stream.concat(mvnHelp.stream(), Stream.of(help.toString().split(lineSeparator))) + .forEach(pw); } private static int getTerminalWidth() { diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCling.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCling.java index d2debc27..55690f8f 100644 --- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCling.java +++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCling.java @@ -72,7 +72,7 @@ public class DaemonMavenCling implements DaemonCli { EnvHelper.environment(workingDir, env); System.setProperty("maven.multiModuleProjectDirectory", projectDir); - return invoker.invoke(parser.parse(ParserRequest.builder( + return invoker.invoke(parser.parseInvocation(ParserRequest.builder( "mvnd", "Maven Daemon", args, new ProtoLogger(), new DaemonMessageBuilderFactory()) .cwd(Paths.get(workingDir)) .in(in) diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenInvoker.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenInvoker.java index d2a19c18..6dfdb568 100644 --- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenInvoker.java +++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenInvoker.java @@ -18,68 +18,60 @@ */ package org.apache.maven.cli; -import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; -import java.io.PrintWriter; -import java.nio.charset.StandardCharsets; +import java.util.Optional; +import org.apache.maven.api.cli.InvokerException; +import org.apache.maven.api.cli.InvokerRequest; import org.apache.maven.api.cli.Options; -import org.apache.maven.api.cli.mvn.MavenInvokerRequest; -import org.apache.maven.api.cli.mvn.MavenOptions; -import org.apache.maven.api.services.MavenException; import org.apache.maven.cling.invoker.ContainerCapsuleFactory; import org.apache.maven.cling.invoker.ProtoLookup; -import org.apache.maven.cling.invoker.mvn.resident.DefaultResidentMavenInvoker; +import org.apache.maven.cling.invoker.mvn.resident.ResidentMavenContext; +import org.apache.maven.cling.invoker.mvn.resident.ResidentMavenInvoker; +import org.apache.maven.cling.utils.CLIReportingUtils; +import org.apache.maven.execution.MavenExecutionRequest; import org.apache.maven.jline.MessageUtils; import org.apache.maven.logging.BuildEventListener; import org.apache.maven.logging.LoggingOutputStream; import org.jline.terminal.Terminal; -import org.jline.terminal.impl.ExternalTerminal; +import org.jline.terminal.TerminalBuilder; import org.mvndaemon.mvnd.common.Environment; -public class DaemonMavenInvoker extends DefaultResidentMavenInvoker { +public class DaemonMavenInvoker extends ResidentMavenInvoker { public DaemonMavenInvoker(ProtoLookup protoLookup) { super(protoLookup); } - // TODO: this is a hack, and fixes issue in DefaultResidentMavenInvoker that does not copy TCCL - private ClassLoader tccl; - - protected int doInvoke(LocalContext context) throws Exception { - try { - if (tccl != null) { - context.currentThreadContextClassLoader = tccl; - Thread.currentThread().setContextClassLoader(context.currentThreadContextClassLoader); - } - return super.doInvoke(context); - } finally { - this.tccl = context.currentThreadContextClassLoader; + @Override + protected void createTerminal(ResidentMavenContext context) { + MessageUtils.systemInstall( + builder -> { + builder.streams( + context.invokerRequest.in().orElseThrow(), + context.invokerRequest.out().orElseThrow()); + builder.systemOutput(TerminalBuilder.SystemOutput.ForcedSysOut); + builder.provider(TerminalBuilder.PROP_PROVIDER_EXEC); + if (context.coloredOutput != null) { + builder.color(context.coloredOutput); + } + }, + terminal -> doConfigureWithTerminal(context, terminal)); + context.terminal = MessageUtils.getTerminal(); + context.closeables.add(MessageUtils::systemUninstall); + MessageUtils.registerShutdownHook(); + if (context.coloredOutput != null) { + MessageUtils.setColorEnabled(context.coloredOutput); } } @Override - protected Terminal createTerminal(LocalContext context) { - try { - Terminal terminal = new ExternalTerminal( - "Maven", - "ansi", - context.invokerRequest.in().get(), - context.invokerRequest.out().get(), - StandardCharsets.UTF_8); - doConfigureWithTerminal(context, terminal); - // If raw-streams options has been set, we need to decorate to push back to the client - if (context.invokerRequest.options().rawStreams().orElse(false)) { - BuildEventListener bel = determineBuildEventListener(context); - OutputStream out = context.invokerRequest.out().orElse(null); - System.setOut(out != null ? printStream(out) : new LoggingOutputStream(bel::log).printStream()); - OutputStream err = context.invokerRequest.err().orElse(null); - System.setErr(err != null ? printStream(err) : new LoggingOutputStream(bel::log).printStream()); - } - return terminal; - } catch (IOException e) { - throw new MavenException("Error creating terminal", e); + protected void doConfigureWithTerminal(ResidentMavenContext context, Terminal terminal) { + super.doConfigureWithTerminal(context, terminal); + Optional<Boolean> rawStreams = context.invokerRequest.options().rawStreams(); + if (rawStreams.orElse(false)) { + System.setOut(printStream(context.invokerRequest.out().orElseThrow())); + System.setErr(printStream(context.invokerRequest.err().orElseThrow())); } } @@ -94,22 +86,18 @@ public class DaemonMavenInvoker extends DefaultResidentMavenInvoker { } @Override - protected org.apache.maven.logging.BuildEventListener doDetermineBuildEventListener(LocalContext context) { + protected org.apache.maven.logging.BuildEventListener doDetermineBuildEventListener(ResidentMavenContext context) { return context.invokerRequest.lookup().lookup(BuildEventListener.class); } @Override - protected void helpOrVersionAndMayExit(LocalContext context) throws Exception { - MavenInvokerRequest<MavenOptions> invokerRequest = context.invokerRequest; + protected void helpOrVersionAndMayExit(ResidentMavenContext context) throws Exception { + InvokerRequest invokerRequest = context.invokerRequest; BuildEventListener buildEventListener = context.invokerRequest.parserRequest().lookup().lookup(BuildEventListener.class); if (invokerRequest.options().help().isPresent()) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (PrintWriter pw = new PrintWriter(new PrintStream(baos), true, StandardCharsets.UTF_8)) { - context.invokerRequest.options().displayHelp(invokerRequest.parserRequest(), pw); - } - buildEventListener.log(baos.toString(StandardCharsets.UTF_8)); - throw new ExitException(0); + context.invokerRequest.options().displayHelp(invokerRequest.parserRequest(), buildEventListener::log); + throw new InvokerException.ExitException(0); } if (invokerRequest.options().showVersionAndExit().isPresent()) { if (invokerRequest.options().quiet().orElse(false)) { @@ -117,12 +105,12 @@ public class DaemonMavenInvoker extends DefaultResidentMavenInvoker { } else { buildEventListener.log(CLIReportingUtils.showVersion()); } - throw new ExitException(0); + throw new InvokerException.ExitException(0); } } @Override - protected void preCommands(LocalContext context) throws Exception { + protected void preCommands(ResidentMavenContext context) throws Exception { Options mavenOptions = context.invokerRequest.options(); if (mavenOptions.verbose().orElse(false) || mavenOptions.showVersion().orElse(false)) { context.invokerRequest @@ -134,26 +122,25 @@ public class DaemonMavenInvoker extends DefaultResidentMavenInvoker { } @Override - protected ContainerCapsuleFactory<MavenOptions, MavenInvokerRequest<MavenOptions>, LocalContext> - createContainerCapsuleFactory() { + protected ContainerCapsuleFactory<ResidentMavenContext> createContainerCapsuleFactory() { return new DaemonPlexusContainerCapsuleFactory(); } @Override - protected int doExecute(LocalContext context) throws Exception { + protected int doExecute(ResidentMavenContext context, MavenExecutionRequest request) throws Exception { context.logger.info(MessageUtils.builder() .a("Processing build on daemon ") .strong(Environment.MVND_ID.asString()) .toString()); - context.logger.info("Daemon status dump:"); - context.logger.info("CWD: " + context.invokerRequest.cwd()); - context.logger.info("MAVEN_HOME: " + context.invokerRequest.installationDirectory()); - context.logger.info("USER_HOME: " + context.invokerRequest.userHomeDirectory()); - context.logger.info("topDirectory: " + context.invokerRequest.topDirectory()); - context.logger.info("rootDirectory: " + context.invokerRequest.rootDirectory()); + context.logger.debug("Daemon status dump:"); + context.logger.debug("CWD: " + context.invokerRequest.cwd()); + context.logger.debug("MAVEN_HOME: " + context.invokerRequest.installationDirectory()); + context.logger.debug("USER_HOME: " + context.invokerRequest.userHomeDirectory()); + context.logger.debug("topDirectory: " + context.invokerRequest.topDirectory()); + context.logger.debug("rootDirectory: " + context.invokerRequest.rootDirectory()); try { - return super.doExecute(context); + return super.doExecute(context, request); } finally { LoggingOutputStream.forceFlush(System.out); LoggingOutputStream.forceFlush(System.err); diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenOptions.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenOptions.java deleted file mode 100644 index 969bf8d2..00000000 --- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenOptions.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.cli; - -import java.util.Collection; -import java.util.Map; - -import org.apache.maven.api.cli.mvn.MavenOptions; - -public interface DaemonMavenOptions extends MavenOptions { - - @Override - DaemonMavenOptions interpolate(Collection<Map<String, String>> properties); -} diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenParser.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenParser.java index a3691755..de0a352a 100644 --- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenParser.java +++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenParser.java @@ -26,31 +26,11 @@ import java.util.stream.Stream; import org.apache.commons.cli.ParseException; import org.apache.maven.api.cli.ParserException; import org.apache.maven.api.cli.extensions.CoreExtension; -import org.apache.maven.api.cli.mvn.MavenInvokerRequest; import org.apache.maven.api.cli.mvn.MavenOptions; -import org.apache.maven.cling.invoker.mvn.BaseMavenParser; -import org.apache.maven.cling.invoker.mvn.DefaultMavenInvokerRequest; +import org.apache.maven.cling.invoker.mvn.MavenParser; import org.mvndaemon.mvnd.common.Environment; -public class DaemonMavenParser extends BaseMavenParser<MavenOptions, MavenInvokerRequest<MavenOptions>> { - @Override - protected DefaultMavenInvokerRequest<MavenOptions> getInvokerRequest(LocalContext context) { - return new DefaultMavenInvokerRequest<>( - 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, - (DaemonMavenOptions) context.options); - } - +public class DaemonMavenParser extends MavenParser { @Override protected MavenOptions parseArgs(String source, List<String> args) throws ParserException { try { @@ -60,12 +40,6 @@ public class DaemonMavenParser extends BaseMavenParser<MavenOptions, MavenInvoke } } - @Override - protected MavenOptions assembleOptions(List<MavenOptions> 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)); diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonPlexusContainerCapsuleFactory.java b/daemon/src/main/java/org/apache/maven/cli/DaemonPlexusContainerCapsuleFactory.java index 346faff6..6bbb6136 100644 --- a/daemon/src/main/java/org/apache/maven/cli/DaemonPlexusContainerCapsuleFactory.java +++ b/daemon/src/main/java/org/apache/maven/cli/DaemonPlexusContainerCapsuleFactory.java @@ -25,16 +25,12 @@ import java.util.List; import java.util.Set; import java.util.stream.Stream; -import org.apache.maven.api.cli.mvn.MavenInvokerRequest; -import org.apache.maven.api.cli.mvn.MavenOptions; import org.apache.maven.cling.invoker.PlexusContainerCapsuleFactory; -import org.apache.maven.cling.invoker.mvn.resident.DefaultResidentMavenInvoker; +import org.apache.maven.cling.invoker.mvn.resident.ResidentMavenContext; import org.apache.maven.extension.internal.CoreExtensionEntry; import org.mvndaemon.mvnd.common.Environment; -public class DaemonPlexusContainerCapsuleFactory - extends PlexusContainerCapsuleFactory< - MavenOptions, MavenInvokerRequest<MavenOptions>, DefaultResidentMavenInvoker.LocalContext> { +public class DaemonPlexusContainerCapsuleFactory extends PlexusContainerCapsuleFactory<ResidentMavenContext> { @Override protected Set<String> collectExportedArtifacts( @@ -54,7 +50,7 @@ public class DaemonPlexusContainerCapsuleFactory } @Override - protected List<Path> parseExtClasspath(DefaultResidentMavenInvoker.LocalContext context) throws Exception { + protected List<Path> parseExtClasspath(ResidentMavenContext context) throws Exception { return Stream.of(Environment.MVND_EXT_CLASSPATH.asString().split(",")) .filter(s -> s != null && !s.isEmpty()) .map(Paths::get) diff --git a/daemon/src/main/java/org/apache/maven/cli/LayeredDaemonMavenOptions.java b/daemon/src/main/java/org/apache/maven/cli/LayeredDaemonMavenOptions.java deleted file mode 100644 index 663a874d..00000000 --- a/daemon/src/main/java/org/apache/maven/cli/LayeredDaemonMavenOptions.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.maven.cli; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -import org.apache.maven.cling.invoker.mvn.LayeredMavenOptions; - -public class LayeredDaemonMavenOptions extends LayeredMavenOptions<DaemonMavenOptions> implements DaemonMavenOptions { - public static DaemonMavenOptions layerDaemonMavenOptions(Collection<DaemonMavenOptions> options) { - List<DaemonMavenOptions> o = options.stream().filter(Objects::nonNull).toList(); - if (o.isEmpty()) { - throw new IllegalArgumentException("No options specified (or all were null)"); - } else if (o.size() == 1) { - return o.get(0); - } else { - return new LayeredDaemonMavenOptions(o); - } - } - - private LayeredDaemonMavenOptions(List<DaemonMavenOptions> options) { - super(options); - } - - @Override - public Optional<Boolean> rawStreams() { - return returnFirstPresentOrEmpty(DaemonMavenOptions::rawStreams); - } - - @Override - public DaemonMavenOptions interpolate(Collection<Map<String, String>> properties) { - ArrayList<DaemonMavenOptions> interpolatedOptions = new ArrayList<>(options.size()); - for (DaemonMavenOptions o : options) { - interpolatedOptions.add(o.interpolate(properties)); - } - return layerDaemonMavenOptions(interpolatedOptions); - } -} diff --git a/logging/src/main/resources/META-INF/maven/slf4j-configuration.properties b/logging/src/main/resources/META-INF/maven/slf4j-configuration.properties index 6f99f2a1..2fc1da23 100644 --- a/logging/src/main/resources/META-INF/maven/slf4j-configuration.properties +++ b/logging/src/main/resources/META-INF/maven/slf4j-configuration.properties @@ -17,4 +17,4 @@ # key = Slf4j effective logger factory implementation # value = corresponding o.a.m.cli.logging.Slf4jConfiguration class -org.mvndaemon.mvnd.logging.slf4j.MvndLoggerFactory=org.apache.maven.cli.logging.impl.MavenSimpleConfiguration +org.mvndaemon.mvnd.logging.slf4j.MvndLoggerFactory=org.apache.maven.cling.logging.impl.MavenSimpleConfiguration diff --git a/pom.xml b/pom.xml index 61786a1f..3bd26f34 100644 --- a/pom.xml +++ b/pom.xml @@ -83,7 +83,7 @@ <groovy.version>4.0.24</groovy.version> <jansi.version>2.4.1</jansi.version> <jline.version>3.27.1</jline.version> - <maven.version>4.0.0-beta-5</maven.version> + <maven.version>4.0.0-rc-1</maven.version> <required-maven.version>3.9.9</required-maven.version> <!-- Keep in sync with Maven -->