From dc4179fc3ba193e18d84dc090abfe336649d63ed Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 25 Oct 2023 17:03:53 +0200 Subject: [PATCH] Switch to Maven 4.0.0-alpha-8 (#895) --- .../mvnd/client/DaemonParameters.java | 11 +++-- .../org/apache/maven/cli/DaemonMavenCli.java | 47 ++++++++++--------- pom.xml | 4 +- 3 files changed, 33 insertions(+), 29 deletions(-) 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 d14f3e41c..b294b9d70 100644 --- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java +++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java @@ -18,6 +18,8 @@ */ package org.mvndaemon.mvnd.client; +import javax.xml.stream.XMLStreamException; + import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -41,9 +43,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.maven.cli.internal.extension.io.CoreExtensionsStaxReader; import org.apache.maven.cli.internal.extension.model.CoreExtension; -import org.apache.maven.cli.internal.extension.model.io.xpp3.CoreExtensionsXpp3Reader; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.mvndaemon.mvnd.common.Environment; import org.mvndaemon.mvnd.common.InterpolationHelper; import org.mvndaemon.mvnd.common.Os; @@ -449,7 +450,7 @@ private String defaultValue(Environment env) { .map(e -> e.getGroupId() + ":" + e.getArtifactId() + ":" + e.getVersion()) .collect(Collectors.toList()); return String.join(";", extensions); - } catch (IOException | XmlPullParserException e) { + } catch (IOException | XMLStreamException e) { throw new RuntimeException("Unable to parse core extensions", e); } } else { @@ -470,7 +471,7 @@ private static List parseExtClasspath(Path userDir) { } private static List readCoreExtensionsDescriptor(Path multiModuleProjectDirectory) - throws IOException, XmlPullParserException { + throws IOException, XMLStreamException { if (multiModuleProjectDirectory == null) { return Collections.emptyList(); } @@ -478,7 +479,7 @@ private static List readCoreExtensionsDescriptor(Path multiModule if (!Files.exists(extensionsFile)) { return Collections.emptyList(); } - CoreExtensionsXpp3Reader parser = new CoreExtensionsXpp3Reader(); + CoreExtensionsStaxReader parser = new CoreExtensionsStaxReader(); try (InputStream is = Files.newInputStream(extensionsFile)) { return parser.read(is).getExtensions(); } diff --git a/daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java b/daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java index 36bdc7434..9b6e592d4 100644 --- a/daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java +++ b/daemon-m40/src/main/java/org/apache/maven/cli/DaemonMavenCli.java @@ -287,10 +287,10 @@ void initialize(CliRequest cliRequest) throws ExitException { } topDirectory = getCanonicalPath(topDirectory); cliRequest.topDirectory = topDirectory; - // We're very early in the process and we don't have the container set up yet, + // We're very early in the process, and we don't have the container set up yet, // so we rely on the JDK services to eventually look up a custom RootLocator. // This is used to compute {@code session.rootDirectory} but all {@code project.rootDirectory} - // properties will be compute through the RootLocator found in the container. + // properties will be computed through the RootLocator found in the container. RootLocator rootLocator = ServiceLoader.load(RootLocator.class).iterator().next(); Path rootDirectory = rootLocator.findRoot(topDirectory); @@ -495,6 +495,7 @@ private void commands(CliRequest cliRequest) { if (MessageUtils.isColorEnabled()) { MessageBuilder buff = MessageUtils.builder(); buff.a("Message styles: "); + buff.trace("trace").a(' '); buff.debug("debug").a(' '); buff.info("info").a(' '); buff.warning("warning").a(' '); @@ -571,10 +572,11 @@ DefaultPlexusContainer container() throws Exception { .filter(s -> s != null && !s.isEmpty()) .map(s -> { String[] parts = s.split(":"); - CoreExtension ce = new CoreExtension(); - ce.setGroupId(parts[0]); - ce.setArtifactId(parts[1]); - ce.setVersion(parts[2]); + CoreExtension ce = CoreExtension.newBuilder() + .groupId(parts[0]) + .artifactId(parts[1]) + .version(parts[2]) + .build(); return ce; }) .collect(Collectors.toList()); @@ -623,11 +625,18 @@ protected void configure() { container.setLoggerManager(plexusLoggerManager); + AbstractValueSource extensionSource = new AbstractValueSource(false) { + @Override + public Object getValue(String expression) { + return null; + } + }; for (CoreExtensionEntry extension : extensionsEntries) { container.discoverComponents( extension.getClassRealm(), new SessionScopeModule(container), - new MojoExecutionScopeModule(container)); + new MojoExecutionScopeModule(container), + new ExtensionConfigurationModule(extension, extensionSource)); } return container; } @@ -1181,12 +1190,12 @@ private static boolean isRunningOnCI(Properties systemProperties) { } private String determineLocalRepositoryPath(final MavenExecutionRequest request) { - String userDefinedLocalRepo = request.getUserProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); + String userDefinedLocalRepo = request.getUserProperties().getProperty(DaemonMavenCli.LOCAL_REPO_PROPERTY); if (userDefinedLocalRepo != null) { return userDefinedLocalRepo; } - return request.getSystemProperties().getProperty(MavenCli.LOCAL_REPO_PROPERTY); + return request.getSystemProperties().getProperty(DaemonMavenCli.LOCAL_REPO_PROPERTY); } private File determinePom( @@ -1199,22 +1208,16 @@ private File determinePom( alternatePomFile = commandLine.getOptionValue(CLIManager.ALTERNATE_POM_FILE); } + File current = baseDirectory; if (alternatePomFile != null) { - File pom = resolveFile(new File(alternatePomFile), workingDirectory); - if (pom.isDirectory()) { - pom = new File(pom, "pom.xml"); - } - - return pom; - } else if (modelProcessor != null) { - File pom = modelProcessor.locatePom(baseDirectory); - - if (pom.isFile()) { - return pom; - } + current = resolveFile(new File(alternatePomFile), workingDirectory); } - return null; + if (modelProcessor != null) { + return modelProcessor.locateExistingPom(current); + } else { + return current.isFile() ? current : null; + } } // Visible for testing diff --git a/pom.xml b/pom.xml index 05f0310bc..0050b7bac 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ 2.4.0 3.23.0 5.9.2 - 4.0.0-alpha-7 + 4.0.0-alpha-8 3.9.5 ${maven.version} @@ -113,7 +113,7 @@ 3.6.0 1.4.20 1.0 - 0.6.3 + 0.6.4