This is an automated email from the ASF dual-hosted git repository. cstamas pushed a commit to branch maven-3.10.2 in repository https://gitbox.apache.org/repos/asf/maven-mvnd.git
commit fff7a81189091386be0a82724fc2e21d063f8ed2 Author: Tamas Cservenak <[email protected]> AuthorDate: Mon Nov 23 20:28:27 2026 +0100 Update to Maven 3.10.2 --- .mvn/wrapper/maven-wrapper.properties | 2 +- README.adoc | 2 +- client/pom.xml | 7 - .../org/mvndaemon/mvnd/client/DefaultClient.java | 2 +- .../org/mvndaemon/mvnd/client/DaemonConnector.java | 2 +- .../mvndaemon/mvnd/client/DaemonParameters.java | 53 ++++-- .../org/mvndaemon/mvnd/client/VersionInfo.java | 6 +- .../client/svm/StaticMDCBinderSubstitution.java | 34 ---- .../mvnd/client/CompletionGeneratorTest.java | 27 +++ .../mvndaemon/mvnd/client/CoreExtensionsTest.java | 62 +++++++ .../org/mvndaemon/mvnd/client/VersionInfoTest.java | 9 +- .../completion-templates/mvnd-bash-completion.bash | 4 +- .../java/org/apache/maven/cli/DaemonMavenCli.java | 196 ++++++++++++--------- .../DaemonNamedLockFactoryAdapterFactoryImpl.java | 50 ------ dist/src/main/distro/bin/mvnd-bash-completion.bash | 4 +- .../org/mvndaemon/mvnd/it/MaxHeapNativeIT.java | 2 +- logging/pom.xml | 14 +- .../logging/smart/ProjectBuildLogAppender.java | 2 +- .../java/org/slf4j/impl/StaticLoggerBinder.java | 82 --------- .../main/java/org/slf4j/impl/StaticMDCBinder.java | 57 ------ .../org/slf4j/{impl => simple}/MvndBaseLogger.java | 2 +- .../slf4j/{impl => simple}/MvndConfiguration.java | 5 +- .../slf4j/{impl => simple}/MvndDaemonLogger.java | 2 +- .../slf4j/{impl => simple}/MvndLoggerFactory.java | 2 +- .../java/org/slf4j/simple/MvndServiceProvider.java | 64 +++++++ .../slf4j/{impl => simple}/MvndSimpleLogger.java | 20 +-- .../META-INF/maven/slf4j-configuration.properties | 2 +- .../org.slf4j.spi.SLF4JServiceProvider} | 4 +- pom.xml | 21 +-- 29 files changed, 349 insertions(+), 390 deletions(-) diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index 216df058..f358bd2e 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1,3 +1,3 @@ wrapperVersion=3.3.4 distributionType=only-script -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.16/apache-maven-3.9.16-bin.zip +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.10.2/apache-maven-3.10.2-bin.zip diff --git a/README.adoc b/README.adoc index 25ec2e28..2e91af2b 100644 --- a/README.adoc +++ b/README.adoc @@ -66,7 +66,7 @@ make sense. With SDKMAN!, the `~/.m2/mvnd.properties` file is typically not need brew install mvndaemon/homebrew-mvnd/mvnd@1 ---- -Note: The tap has two formulae. `mvnd@1` always installs the stable 1.x line, which embeds Maven 3.9.x. +Note: The tap has two formulae. `mvnd@1` always installs the stable 1.x line, which embeds Maven 3.10.x. `mvnd` follows the tap's default line; check its version with `brew info mvndaemon/homebrew-mvnd/mvnd`. === Install using https://www.macports.org[MacPorts] diff --git a/client/pom.xml b/client/pom.xml index 39852b07..cec944c4 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -60,13 +60,6 @@ <artifactId>jul-to-slf4j</artifactId> </dependency> - <!-- GraalVM SVM: provided, uses only to configure native image build --> - <dependency> - <groupId>org.graalvm.nativeimage</groupId> - <artifactId>svm</artifactId> - <scope>provided</scope> - </dependency> - <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> 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 a15f78b8..0ee94f02 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 @@ -57,7 +57,7 @@ import org.mvndaemon.mvnd.common.logging.TerminalOutput; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.bridge.SLF4JBridgeHandler; -import org.slf4j.impl.MvndLoggerFactory; +import org.slf4j.simple.MvndLoggerFactory; public class DefaultClient implements Client { diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java index 5189a1d9..7170a394 100644 --- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java +++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java @@ -58,7 +58,7 @@ import org.mvndaemon.mvnd.common.SocketFamily; import org.mvndaemon.mvnd.common.logging.ClientOutput; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.impl.SimpleLogger; +import org.slf4j.simple.SimpleLogger; import static java.lang.Thread.sleep; import static org.mvndaemon.mvnd.common.DaemonState.Canceled; 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 19b26004..974ae1fc 100644 --- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java +++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java @@ -33,6 +33,7 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Properties; import java.util.Set; @@ -476,11 +477,16 @@ public class DaemonParameters { return String.join(",", cp); } else if (env == Environment.MVND_CORE_EXTENSIONS) { try { - List<String> extensions = readCoreExtensionsDescriptor(multiModuleProjectDirectory()).stream() + Path projectDir = multiModuleProjectDirectory(); + List<String> extensions = readCoreExtensions( + projectDir != null ? projectDir.resolve(EXTENSIONS_FILENAME) : null, + userHome().resolve(".m2/extensions.xml"), + mvndHome().resolve("mvn/conf/extensions.xml")) + .stream() .map(e -> e.getGroupId() + ":" + e.getArtifactId() + ":" + e.getVersion()) .collect(Collectors.toList()); return String.join(";", extensions); - } catch (IOException | XmlPullParserException e) { + } catch (IOException e) { throw new RuntimeException("Unable to parse core extensions", e); } } else { @@ -500,21 +506,40 @@ public class DaemonParameters { return jars; } - private static List<CoreExtension> readCoreExtensionsDescriptor(Path multiModuleProjectDirectory) - throws IOException, XmlPullParserException { - if (multiModuleProjectDirectory == null) { - return Collections.emptyList(); - } - Path extensionsFile = multiModuleProjectDirectory.resolve(EXTENSIONS_FILENAME); - if (!Files.exists(extensionsFile)) { - return Collections.emptyList(); + /** + * Reads the given {@code extensions.xml} files (project, user, installation) and selects one version per + * {@code groupId:artifactId}, the first file having precedence, as Maven 3.10 does. + */ + static List<CoreExtension> readCoreExtensions(Path... extensionsFiles) throws IOException { + Map<String, CoreExtension> selected = new LinkedHashMap<>(); + for (Path extensionsFile : extensionsFiles) { + if (extensionsFile == null || !Files.isRegularFile(extensionsFile)) { + continue; + } + for (CoreExtension extension : readCoreExtensionsDescriptor(extensionsFile)) { + String key = extension.getGroupId() + ":" + extension.getArtifactId(); + CoreExtension conflict = selected.putIfAbsent(key, extension); + if (conflict != null && !Objects.equals(conflict.getVersion(), extension.getVersion())) { + LOG.warn( + "Conflicting extension {}: {} vs {} in {}; using {}", + key, + extension.getVersion(), + conflict.getVersion(), + extensionsFile, + conflict.getId()); + } + } } - CoreExtensionsXpp3Reader parser = new CoreExtensionsXpp3Reader(); - List<CoreExtension> extensions; + return filterCoreExtensions(new ArrayList<>(selected.values())); + } + + private static List<CoreExtension> readCoreExtensionsDescriptor(Path extensionsFile) throws IOException { try (InputStream is = Files.newInputStream(extensionsFile)) { - extensions = parser.read(is).getExtensions(); + return new CoreExtensionsXpp3Reader().read(is).getExtensions(); + } catch (IOException | XmlPullParserException e) { + throw new IOException( + "Unable to parse core extensions descriptor " + extensionsFile + ": " + e.getMessage(), e); } - return filterCoreExtensions(extensions); } private static List<CoreExtension> filterCoreExtensions(List<CoreExtension> coreExtensions) { diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/VersionInfo.java b/client/src/main/java/org/mvndaemon/mvnd/client/VersionInfo.java index 8b5bbfb9..c7c328dc 100644 --- a/client/src/main/java/org/mvndaemon/mvnd/client/VersionInfo.java +++ b/client/src/main/java/org/mvndaemon/mvnd/client/VersionInfo.java @@ -23,6 +23,7 @@ import java.io.InputStream; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; +import java.time.ZoneId; import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -57,7 +58,7 @@ final class VersionInfo { } /** - * Mirrors {@code CLIReportingUtils.showVersion()} of Maven 3.9. + * Mirrors {@code CLIReportingUtils.showVersion()} of Maven 3.10. * * @param mavenLib the {@code mvn/lib} directory of the distribution, may be {@code null} * @param embeddedMavenVersion the Maven version recorded when mvnd was built, used if the Maven jar cannot be read @@ -89,7 +90,8 @@ final class VersionInfo { lines.add("Java version: " + javaVersion + ", vendor: " + javaVendor + ", runtime: " + runtime); lines.add("Default locale: " + Locale.getDefault() + ", platform encoding: " - + sys.getProperty("file.encoding", "<unknown encoding>")); + + sys.getProperty("file.encoding", "<unknown encoding>") + ", time zone: " + + ZoneId.systemDefault().getId()); String osName = sys.getProperty("os.name", ""); lines.add("OS name: \"" + osName.toLowerCase(Locale.ENGLISH) + "\", version: \"" diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/svm/StaticMDCBinderSubstitution.java b/client/src/main/java/org/mvndaemon/mvnd/client/svm/StaticMDCBinderSubstitution.java deleted file mode 100644 index e2371474..00000000 --- a/client/src/main/java/org/mvndaemon/mvnd/client/svm/StaticMDCBinderSubstitution.java +++ /dev/null @@ -1,34 +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.mvndaemon.mvnd.client.svm; - -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import org.slf4j.MDC; -import org.slf4j.impl.StaticMDCBinder; -import org.slf4j.spi.MDCAdapter; - -@TargetClass(MDC.class) -final class StaticMDCBinderSubstitution { - - @Substitute - private static MDCAdapter bwCompatibleGetMDCAdapterFromBinder() throws NoClassDefFoundError { - return StaticMDCBinder.SINGLETON.getMDCA(); - } -} diff --git a/client/src/test/java/org/mvndaemon/mvnd/client/CompletionGeneratorTest.java b/client/src/test/java/org/mvndaemon/mvnd/client/CompletionGeneratorTest.java index a6f3c567..9754d474 100644 --- a/client/src/test/java/org/mvndaemon/mvnd/client/CompletionGeneratorTest.java +++ b/client/src/test/java/org/mvndaemon/mvnd/client/CompletionGeneratorTest.java @@ -23,11 +23,15 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Arrays; +import java.util.Collection; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.commons.cli.Option; +import org.apache.maven.cli.CLIManager; import org.junit.jupiter.api.Test; import org.mvndaemon.mvnd.common.Environment; import org.mvndaemon.mvnd.common.Environment.OptionOrigin; @@ -67,6 +71,29 @@ public class CompletionGeneratorTest { .map(prop -> "-D" + prop) .collect(Collectors.joining("|")); + // Maven options as known to the embedded Maven, plus the options DaemonMavenCli adds on top + final Collection<Option> mavenOptions = new CLIManager() { + Collection<Option> all() { + return options.getOptions(); + } + }.all(); + final String mavenOpts = Stream.concat( + mavenOptions.stream().map(Option::getOpt).filter(Objects::nonNull), Stream.of("r")) + .map(opt -> "-" + opt) + .filter(opt -> !Arrays.asList(shortOpts.split("\\|")).contains(opt)) + .sorted() + .distinct() + .collect(Collectors.joining("|")); + final String mavenLongOpts = Stream.concat( + mavenOptions.stream().map(Option::getLongOpt).filter(Objects::nonNull), Stream.of("resume")) + .map(opt -> "--" + opt) + .filter(opt -> !Arrays.asList(longOpts.split("\\|")).contains(opt)) + .sorted() + .distinct() + .collect(Collectors.joining("|")); + + template = template.replace("%maven_opts%", mavenOpts); + template = template.replace("%maven_long_opts%", mavenLongOpts); template = template.replace("%mvnd_opts%", shortOpts); template = template.replace("%mvnd_long_opts%", longOpts); template = template.replace("%mvnd_properties%", props); diff --git a/client/src/test/java/org/mvndaemon/mvnd/client/CoreExtensionsTest.java b/client/src/test/java/org/mvndaemon/mvnd/client/CoreExtensionsTest.java new file mode 100644 index 00000000..9e770582 --- /dev/null +++ b/client/src/test/java/org/mvndaemon/mvnd/client/CoreExtensionsTest.java @@ -0,0 +1,62 @@ +/* + * 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.mvndaemon.mvnd.client; + +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.maven.cli.internal.extension.model.CoreExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class CoreExtensionsTest { + + @Test + void projectWinsOverUserWinsOverInstallation(@TempDir Path dir) throws Exception { + Path project = write(dir.resolve("project.xml"), ext("g", "a", "1") + ext("g", "p", "1")); + Path user = write(dir.resolve("user.xml"), ext("g", "a", "2") + ext("g", "u", "2")); + Path installation = write(dir.resolve("installation.xml"), ext("g", "u", "3") + ext("g", "i", "3")); + + List<String> ids = + DaemonParameters.readCoreExtensions(project, user, dir.resolve("missing.xml"), installation).stream() + .map(CoreExtension::getId) + .collect(Collectors.toList()); + + assertEquals(List.of("g:a:1", "g:p:1", "g:u:2", "g:i:3"), ids); + } + + @Test + void noFiles() throws Exception { + assertEquals(List.of(), DaemonParameters.readCoreExtensions((Path) null)); + } + + private static String ext(String g, String a, String v) { + return "<extension><groupId>" + g + "</groupId><artifactId>" + a + "</artifactId><version>" + v + + "</version></extension>"; + } + + private static Path write(Path file, String extensions) throws Exception { + return Files.write(file, ("<extensions>" + extensions + "</extensions>").getBytes(StandardCharsets.UTF_8)); + } +} diff --git a/client/src/test/java/org/mvndaemon/mvnd/client/VersionInfoTest.java b/client/src/test/java/org/mvndaemon/mvnd/client/VersionInfoTest.java index 8faf085d..11cf07f1 100644 --- a/client/src/test/java/org/mvndaemon/mvnd/client/VersionInfoTest.java +++ b/client/src/test/java/org/mvndaemon/mvnd/client/VersionInfoTest.java @@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.ZoneId; import java.util.Arrays; import java.util.List; import java.util.Properties; @@ -72,7 +73,9 @@ public class VersionInfoTest { assertEquals("Maven home: " + mavenHome, lines.get(1)); assertEquals("Java version: 17.0.20, vendor: Amazon.com Inc., runtime: " + jdk, lines.get(2)); assertTrue(lines.get(3).startsWith("Default locale: ")); - assertTrue(lines.get(3).endsWith(", platform encoding: UTF-8")); + assertTrue(lines.get(3) + .endsWith(", platform encoding: UTF-8, time zone: " + + ZoneId.systemDefault().getId())); assertEquals("OS name: \"mac os x\", version: \"14.1\", arch: \"aarch64\", family: \"mac\"", lines.get(4)); assertEquals(5, lines.size()); } @@ -105,11 +108,11 @@ public class VersionInfoTest { sys.setProperty("native.encoding", "ISO-8859-2"); assertTrue(VersionInfo.lines(null, "3.9.16", Paths.get("m"), null, sys) .get(3) - .endsWith(", platform encoding: UTF-8")); + .contains(", platform encoding: UTF-8, time zone: ")); sys.remove("file.encoding"); assertTrue(VersionInfo.lines(null, "3.9.16", Paths.get("m"), null, sys) .get(3) - .endsWith(", platform encoding: <unknown encoding>")); + .contains(", platform encoding: <unknown encoding>, time zone: ")); } @Test diff --git a/client/src/test/resources/completion-templates/mvnd-bash-completion.bash b/client/src/test/resources/completion-templates/mvnd-bash-completion.bash index 49f54b30..4fbe7c78 100644 --- a/client/src/test/resources/completion-templates/mvnd-bash-completion.bash +++ b/client/src/test/resources/completion-templates/mvnd-bash-completion.bash @@ -238,8 +238,8 @@ _mvnd() local mvnd_opts="%mvnd_opts%" local mvnd_long_opts="%mvnd_long_opts%" local mvnd_properties="%mvnd_properties%" - local opts="-am|-amd|-B|-C|-c|-cpu|-D|-e|-emp|-ep|-f|-fae|-ff|-fn|-gs|-h|-l|-N|-npr|-npu|-nsu|-o|-P|-pl|-q|-rf|-s|-T|-t|-U|-up|-V|-v|-X|${mvnd_opts}" - local long_opts="--also-make|--also-make-dependents|--batch-mode|--strict-checksums|--lax-checksums|--check-plugin-updates|--define|--errors|--encrypt-master-password|--encrypt-password|--file|--fail-at-end|--fail-fast|--fail-never|--global-settings|--help|--log-file|--non-recursive|--no-plugin-registry|--no-plugin-updates|--no-snapshot-updates|--offline|--activate-profiles|--projects|--quiet|--resume-from|--settings|--threads|--toolchains|--update-snapshots|--update-plugins|--show-v [...] + local opts="%maven_opts%|${mvnd_opts}" + local long_opts="%maven_long_opts%|${mvnd_long_opts}" local common_clean_lifecycle="pre-clean|clean|post-clean" local common_default_lifecycle="validate|initialize|generate-sources|process-sources|generate-resources|process-resources|compile|process-classes|generate-test-sources|process-test-sources|generate-test-resources|process-test-resources|test-compile|process-test-classes|test|prepare-package|package|pre-integration-test|integration-test|post-integration-test|verify|install|deploy" diff --git a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java index fa4fbb21..4032632e 100644 --- a/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java +++ b/daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java @@ -21,7 +21,6 @@ package org.apache.maven.cli; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.IOException; import java.io.PrintStream; import java.nio.charset.Charset; import java.nio.file.Files; @@ -38,6 +37,7 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Properties; +import java.util.ServiceLoader; import java.util.Set; import java.util.StringTokenizer; import java.util.regex.Matcher; @@ -52,6 +52,7 @@ import org.apache.commons.cli.ParseException; import org.apache.commons.cli.UnrecognizedOptionException; import org.apache.maven.InternalErrorException; import org.apache.maven.Maven; +import org.apache.maven.api.services.MessageBuilder; import org.apache.maven.building.FileSource; import org.apache.maven.building.Problem; import org.apache.maven.building.Source; @@ -75,8 +76,11 @@ import org.apache.maven.execution.MavenExecutionResult; import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule; import org.apache.maven.extension.internal.CoreExports; import org.apache.maven.extension.internal.CoreExtensionEntry; +import org.apache.maven.jline.MessageUtils; import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.model.building.ModelProcessor; +import org.apache.maven.model.interpolation.ModelInterpolator; +import org.apache.maven.model.root.RootLocator; import org.apache.maven.plugin.ExtensionRealmCache; import org.apache.maven.plugin.PluginArtifactsCache; import org.apache.maven.plugin.PluginRealmCache; @@ -85,8 +89,6 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.artifact.ProjectArtifactsCache; import org.apache.maven.properties.internal.SystemProperties; import org.apache.maven.session.scope.internal.SessionScopeModule; -import org.apache.maven.shared.utils.logging.MessageBuilder; -import org.apache.maven.shared.utils.logging.MessageUtils; import org.apache.maven.toolchain.building.DefaultToolchainsBuildingRequest; import org.apache.maven.toolchain.building.ToolchainsBuilder; import org.apache.maven.toolchain.building.ToolchainsBuildingResult; @@ -102,6 +104,7 @@ import org.codehaus.plexus.interpolation.AbstractValueSource; import org.codehaus.plexus.interpolation.InterpolationException; import org.codehaus.plexus.interpolation.StringSearchInterpolator; import org.eclipse.aether.DefaultRepositoryCache; +import org.eclipse.aether.repository.RepositoryPolicy; import org.eclipse.aether.transfer.TransferListener; import org.mvndaemon.mvnd.cache.invalidating.InvalidatingExtensionRealmCache; import org.mvndaemon.mvnd.cache.invalidating.InvalidatingPluginArtifactsCache; @@ -122,13 +125,13 @@ import org.mvndaemon.mvnd.transfer.DaemonMavenTransferListener; import org.slf4j.ILoggerFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.slf4j.impl.MvndSimpleLogger; +import org.slf4j.simple.MvndSimpleLogger; import org.slf4j.spi.LocationAwareLogger; import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; import static java.util.Comparator.comparing; -import static org.apache.maven.shared.utils.logging.MessageUtils.buffer; +import static org.apache.maven.jline.MessageUtils.builder; /** * File origin: @@ -154,11 +157,15 @@ public class DaemonMavenCli implements DaemonCli { private static final String DOT_MVN = ".mvn"; - private static final String UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE = "Unable to find the root directory. Create a " - + DOT_MVN + " directory in the project root directory to identify it."; - private static final String MVN_MAVEN_CONFIG = DOT_MVN + "/maven.config"; + /** + * One "distinguished" env variable that we want to make into non-prefixed property, if present. + * + * @see ModelInterpolator + */ + private static final String MAVEN_REPO_CENTRAL_ENV = "env.MAVEN_REPO_CENTRAL"; + public static final String STYLE_COLOR_PROPERTY = "style.color"; public static final String RESUME = "r"; @@ -262,11 +269,9 @@ public class DaemonMavenCli implements DaemonCli { throw new ExitException(1); } File basedir = new File(basedirProperty); - try { - cliRequest.multiModuleProjectDirectory = basedir.getCanonicalFile(); - } catch (IOException e) { - cliRequest.multiModuleProjectDirectory = basedir.getAbsoluteFile(); - } + // Resolve lexically rather than through getCanonicalFile() (MNG-11167) + cliRequest.multiModuleProjectDirectory = + getCanonicalPath(basedir.toPath()).toFile(); } // We need to locate the top level project which may be pointed at using @@ -299,11 +304,14 @@ public class DaemonMavenCli implements DaemonCli { } } topDirectory = getCanonicalPath(topDirectory); - cliRequest.topDirectory = topDirectory; - // We're very early in the process and we don't have the container set up yet, - // so we on searchAcceptableRootDirectory method to find us acceptable directory. - // The method may return null if nothing acceptable found. - cliRequest.rootDirectory = searchAcceptableRootDirectory(topDirectory); + cliRequest.request.setTopDirectory(topDirectory); + // 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 computed through the RootLocator found in the container. + RootLocator rootLocator = + ServiceLoader.load(RootLocator.class).iterator().next(); + cliRequest.request.setRootDirectory(rootLocator.findRoot(topDirectory)); // // Make sure the Maven home directory is an absolute path to save us from confusion with say drive-relative @@ -316,26 +324,8 @@ public class DaemonMavenCli implements DaemonCli { } } - protected boolean isAcceptableRootDirectory(Path path) { - return path != null && Files.isDirectory(path.resolve(DOT_MVN)); - } - - protected Path searchAcceptableRootDirectory(Path path) { - if (path == null) { - return null; - } - if (isAcceptableRootDirectory(path)) { - return path; - } - return searchAcceptableRootDirectory(path.getParent()); - } - private static Path getCanonicalPath(Path path) { - try { - return path.toRealPath(); - } catch (IOException e) { - return getCanonicalPath(path.getParent()).resolve(path.getFileName()); - } + return path.toAbsolutePath().normalize(); } void cli(CliRequest cliRequest) throws Exception { @@ -469,6 +459,9 @@ public class DaemonMavenCli implements DaemonCli { } else if (cliRequest.commandLine.hasOption(CLIManager.BATCH_MODE) || cliRequest.commandLine.hasOption(CLIManager.LOG_FILE)) { MessageUtils.setColorEnabled(false); + } else { + // auto: color only on a detected ANSI terminal; the daemon never detects one (the client resolves auto) + MessageUtils.setColorEnabled(MessageUtils.isTty()); } // LOG STREAMS @@ -507,7 +500,7 @@ public class DaemonMavenCli implements DaemonCli { } } - private void commands(CliRequest cliRequest) { + private void commands(CliRequest cliRequest) throws ExitException { if (cliRequest.showErrors) { slf4jLogger.info("Error stacktraces are turned on."); } @@ -518,16 +511,36 @@ public class DaemonMavenCli implements DaemonCli { slf4jLogger.info("Enabling strict checksum verification on all artifact downloads."); } + // If no goals/phases were specified and there is no POM in the current directory, + // print usage (like `mvn -h`) and exit successfully instead of failing with + // "No goals have been specified for this build." + // When a POM is present the default goal (if any) may apply, so let Maven proceed normally. + // Also skip when -f/--file is specified: the alternate POM existence is validated later, + // and the working directory may legitimately have no pom.xml. + List<String> goals = cliRequest.commandLine.getArgList(); + if (goals.isEmpty() + && modelProcessor != null + && !cliRequest.commandLine.hasOption(CLIManager.ALTERNATE_POM_FILE) + && !cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_PASSWORD) + && !cliRequest.commandLine.hasOption(CLIManager.ENCRYPT_MASTER_PASSWORD)) { + File pom = modelProcessor.locatePom(new File(cliRequest.workingDirectory)); + if (!pom.isFile()) { + buildEventListener.log(MvndHelpFormatter.displayHelp(newCLIManager())); + throw new ExitException(0); + } + } + if (slf4jLogger.isDebugEnabled()) { slf4jLogger.debug("Message scheme: {}", (MessageUtils.isColorEnabled() ? "color" : "plain")); + slf4jLogger.debug("Message terminal: {}", MessageUtils.isTty() ? "ansi" : "none"); if (MessageUtils.isColorEnabled()) { - MessageBuilder buff = MessageUtils.buffer(); + MessageBuilder buff = builder(); buff.a("Message styles: "); - buff.a(MessageUtils.level().debug("debug")).a(' '); - buff.a(MessageUtils.level().info("info")).a(' '); - buff.a(MessageUtils.level().warning("warning")).a(' '); - buff.a(MessageUtils.level().error("error")).a(' '); - + buff.a(builder().trace("trace")).a(' '); + buff.a(builder().debug("debug")).a(' '); + buff.a(builder().info("info")).a(' '); + buff.a(builder().warning("warning")).a(' '); + buff.a(builder().error("error")).a(' '); buff.success("success").a(' '); buff.failure("failure").a(' '); buff.strong("strong").a(' '); @@ -567,9 +580,11 @@ public class DaemonMavenCli implements DaemonCli { } catch (MavenCli.IllegalUseOfUndefinedProperty e) { String message = "ERROR: Illegal use of undefined property: " + e.property; System.err.println(message); - if (cliRequest.rootDirectory == null) { + try { + cliRequest.request.getRootDirectory(); + } catch (IllegalStateException ex) { System.err.println(); - System.err.println(UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE); + System.err.println(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE); } throw new ExitException(1); // user error } @@ -581,17 +596,16 @@ public class DaemonMavenCli implements DaemonCli { @Override public Object getValue(String expression) { if ("session.topDirectory".equals(expression)) { - Path topDirectory = cliRequest.topDirectory; + Path topDirectory = cliRequest.request.getTopDirectory(); if (topDirectory != null) { return topDirectory.toString(); } else { throw new MavenCli.IllegalUseOfUndefinedProperty(expression); } } else if ("session.rootDirectory".equals(expression)) { - Path rootDirectory = cliRequest.rootDirectory; - if (rootDirectory != null) { - return rootDirectory.toString(); - } else { + try { + return cliRequest.request.getRootDirectory(); + } catch (IllegalStateException e) { throw new MavenCli.IllegalUseOfUndefinedProperty(expression); } } @@ -672,6 +686,13 @@ public class DaemonMavenCli implements DaemonCli { .setClassPathScanning(PlexusConstants.SCANNING_INDEX) .setAutoWiring(true) .setJSR250Lifecycle(true) + .setVisibilityPredicateSupplierTransformer(s -> () -> { + if (BootstrapCoreExtensionManager.isContextRealmCoreExtensionRealm()) { + return null; + } else { + return s.get(); + } + }) .setName("maven"); Set<String> exportedArtifacts = new HashSet<>(coreEntry.getExportedArtifacts()); @@ -837,7 +858,7 @@ public class DaemonMavenCli implements DaemonCli { EnvHelper.environment(workingDir, clientEnv); } - private int execute(CliRequest cliRequest) throws MavenExecutionRequestPopulationException { + private int execute(CliRequest cliRequest) throws MavenExecutionRequestPopulationException, ExitException { commands(cliRequest); MavenExecutionRequest request = executionRequestPopulator.populateDefaults(cliRequest.request); @@ -845,7 +866,8 @@ public class DaemonMavenCli implements DaemonCli { eventSpyDispatcher.onEvent(request); - slf4jLogger.info(buffer().a("Processing build on daemon ") + slf4jLogger.info(builder() + .a("Processing build on daemon ") .strong(Environment.MVND_ID.asString()) .toString()); @@ -881,11 +903,12 @@ public class DaemonMavenCli implements DaemonCli { if (!cliRequest.showErrors) { slf4jLogger.error( "To see the full stack trace of the errors, re-run Maven with the {} switch.", - buffer().strong("-e")); + builder().strong("-e")); } if (!slf4jLogger.isDebugEnabled()) { slf4jLogger.error( - "Re-run Maven using the {} switch to enable full debug logging.", buffer().strong("-X")); + "Re-run Maven using the {} switch to enable full debug logging.", + builder().strong("-X")); } if (!references.isEmpty()) { @@ -894,7 +917,7 @@ public class DaemonMavenCli implements DaemonCli { + ", please read the following articles:"); for (Entry<String, String> entry : references.entrySet()) { - slf4jLogger.error("{} {}", buffer().strong(entry.getValue()), entry.getKey()); + slf4jLogger.error("{} {}", builder().strong(entry.getValue()), entry.getKey()); } } @@ -945,7 +968,7 @@ public class DaemonMavenCli implements DaemonCli { private void logBuildResumeHint(String resumeBuildHint) { slf4jLogger.error(""); slf4jLogger.error("After correcting the problems, you can resume the build with the command"); - slf4jLogger.error(buffer().a(" ").strong(resumeBuildHint).toString()); + slf4jLogger.error(builder().a(" ").strong(resumeBuildHint).toString()); } /** @@ -983,9 +1006,9 @@ public class DaemonMavenCli implements DaemonCli { String referenceKey = references.computeIfAbsent(summary.getReference(), k -> "[Help " + (references.size() + 1) + "]"); if (msg.indexOf('\n') < 0) { - msg += " -> " + buffer().strong(referenceKey); + msg += " -> " + builder().strong(referenceKey); } else { - msg += "\n-> " + buffer().strong(referenceKey); + msg += "\n-> " + builder().strong(referenceKey); } } @@ -1212,6 +1235,26 @@ public class DaemonMavenCli implements DaemonCli { noSnapshotUpdates = true; } + boolean updateSnapshots = false; + if (commandLine.hasOption(CLIManager.UPDATE_SNAPSHOTS)) { + updateSnapshots = true; + } + + String artifactsUpdatePolicy = null; + String metadataUpdatePolicy = null; + if (commandLine.hasOption(CLIManager.UPDATE_ARTIFACTS)) { + artifactsUpdatePolicy = RepositoryPolicy.UPDATE_POLICY_ALWAYS; + } + if (artifactsUpdatePolicy == null && commandLine.hasOption(CLIManager.ARTIFACTS_UPDATE_POLICY)) { + artifactsUpdatePolicy = commandLine.getOptionValue(CLIManager.ARTIFACTS_UPDATE_POLICY); + } + if (commandLine.hasOption(CLIManager.UPDATE_METADATA)) { + metadataUpdatePolicy = RepositoryPolicy.UPDATE_POLICY_ALWAYS; + } + if (metadataUpdatePolicy == null && commandLine.hasOption(CLIManager.METADATA_UPDATE_POLICY)) { + metadataUpdatePolicy = commandLine.getOptionValue(CLIManager.METADATA_UPDATE_POLICY); + } + // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- @@ -1239,12 +1282,6 @@ public class DaemonMavenCli implements DaemonCli { request.setOffline(true); } - boolean updateSnapshots = false; - - if (commandLine.hasOption(CLIManager.UPDATE_SNAPSHOTS)) { - updateSnapshots = true; - } - String globalChecksumPolicy = null; if (commandLine.hasOption(CLIManager.CHECKSUM_FAILURE_POLICY)) { @@ -1263,26 +1300,7 @@ public class DaemonMavenCli implements DaemonCli { List<String> inactiveProfiles = new ArrayList<>(); - if (commandLine.hasOption(CLIManager.ACTIVATE_PROFILES)) { - String[] profileOptionValues = commandLine.getOptionValues(CLIManager.ACTIVATE_PROFILES); - if (profileOptionValues != null) { - for (String profileOptionValue : profileOptionValues) { - StringTokenizer profileTokens = new StringTokenizer(profileOptionValue, ","); - - while (profileTokens.hasMoreTokens()) { - String profileAction = profileTokens.nextToken().trim(); - - if (profileAction.startsWith("-") || profileAction.startsWith("!")) { - inactiveProfiles.add(profileAction.substring(1)); - } else if (profileAction.startsWith("+")) { - activeProfiles.add(profileAction.substring(1)); - } else { - activeProfiles.add(profileAction); - } - } - } - } - } + MavenCli.performProfileActivation(commandLine, activeProfiles, inactiveProfiles); ExecutionEventLogger executionEventLogger = new ExecutionEventLogger(); executionListener.init(eventSpyDispatcher.chainListener(executionEventLogger), buildEventListener); @@ -1305,6 +1323,8 @@ public class DaemonMavenCli implements DaemonCli { .setTransferListener(transferListener) // default: batch mode which goes along with interactive .setUpdateSnapshots(updateSnapshots) // default: false .setNoSnapshotUpdates(noSnapshotUpdates) // default: false + .setArtifactsUpdatePolicy(artifactsUpdatePolicy) // default: null + .setMetadataUpdatePolicy(metadataUpdatePolicy) // default: null .setGlobalChecksumPolicy(globalChecksumPolicy) // default: warn .setMultiModuleProjectDirectory(cliRequest.getMultiModuleProjectDirectory()); @@ -1466,6 +1486,12 @@ public class DaemonMavenCli implements DaemonCli { addEnvVars(systemProperties); SystemProperties.addSystemProperties(systemProperties); + // one distinguished env variable: MAVEN_REPO_CENTRAL; if present, we make it into property + if (systemProperties.containsKey(MAVEN_REPO_CENTRAL_ENV)) { + systemProperties.put( + ModelInterpolator.MAVEN_REPO_CENTRAL_KEY, systemProperties.getProperty(MAVEN_REPO_CENTRAL_ENV)); + } + StringSearchInterpolator interpolator = createInterpolator(cliRequest, cliProperties, systemProperties); for (Map.Entry<Object, Object> e : cliProperties.entrySet()) { String name = (String) e.getKey(); diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/syncontext/DaemonNamedLockFactoryAdapterFactoryImpl.java b/daemon/src/main/java/org/mvndaemon/mvnd/syncontext/DaemonNamedLockFactoryAdapterFactoryImpl.java deleted file mode 100644 index 0f65e97c..00000000 --- a/daemon/src/main/java/org/mvndaemon/mvnd/syncontext/DaemonNamedLockFactoryAdapterFactoryImpl.java +++ /dev/null @@ -1,50 +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.mvndaemon.mvnd.syncontext; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - -import java.util.Map; - -import org.eclipse.aether.impl.RepositorySystemLifecycle; -import org.eclipse.aether.internal.impl.synccontext.named.NameMapper; -import org.eclipse.aether.internal.impl.synccontext.named.NameMappers; -import org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactoryImpl; -import org.eclipse.aether.named.NamedLockFactory; -import org.eclipse.aether.named.providers.FileLockNamedLockFactory; -import org.eclipse.sisu.Priority; - -/** - * Mvnd named lock factory implementation: it differs from - * {@link org.eclipse.aether.internal.impl.synccontext.named.NamedLockFactoryAdapterFactoryImpl} only by default values. - */ -@Singleton -@Named -@Priority(10) -public final class DaemonNamedLockFactoryAdapterFactoryImpl extends NamedLockFactoryAdapterFactoryImpl { - @Inject - public DaemonNamedLockFactoryAdapterFactoryImpl( - final Map<String, NamedLockFactory> factories, - final Map<String, NameMapper> nameMappers, - final RepositorySystemLifecycle lifecycle) { - super(factories, FileLockNamedLockFactory.NAME, nameMappers, NameMappers.FILE_GAV_NAME, lifecycle); - } -} diff --git a/dist/src/main/distro/bin/mvnd-bash-completion.bash b/dist/src/main/distro/bin/mvnd-bash-completion.bash index 6b0fcd16..26d1a826 100755 --- a/dist/src/main/distro/bin/mvnd-bash-completion.bash +++ b/dist/src/main/distro/bin/mvnd-bash-completion.bash @@ -238,8 +238,8 @@ _mvnd() local mvnd_opts="-1" local mvnd_long_opts="--color|--completion|--diag|--purge|--raw-streams|--serial|--status|--stop" local mvnd_properties="-Djava.home|-Djdk.java.options|-Dmaven.multiModuleProjectDirectory|-Dmaven.repo.local|-Dmaven.settings|-Dmvnd.buildTime|-Dmvnd.builder|-Dmvnd.cancelConnectTimeout|-Dmvnd.connectTimeout|-Dmvnd.coreExtensionsExclude|-Dmvnd.daemonStorage|-Dmvnd.debug|-Dmvnd.debug.address|-Dmvnd.duplicateDaemonGracePeriod|-Dmvnd.enableAssertions|-Dmvnd.expirationCheckDelay|-Dmvnd.hideBannedProjectSkips|-Dmvnd.home|-Dmvnd.idleTimeout|-Dmvnd.jvmArgs|-Dmvnd.keepAlive|-Dmvnd.logPurgePe [...] - local opts="-am|-amd|-B|-C|-c|-cpu|-D|-e|-emp|-ep|-f|-fae|-ff|-fn|-gs|-h|-l|-N|-npr|-npu|-nsu|-o|-P|-pl|-q|-rf|-s|-T|-t|-U|-up|-V|-v|-X|${mvnd_opts}" - local long_opts="--also-make|--also-make-dependents|--batch-mode|--strict-checksums|--lax-checksums|--check-plugin-updates|--define|--errors|--encrypt-master-password|--encrypt-password|--file|--fail-at-end|--fail-fast|--fail-never|--global-settings|--help|--log-file|--non-recursive|--no-plugin-registry|--no-plugin-updates|--no-snapshot-updates|--offline|--activate-profiles|--projects|--quiet|--resume-from|--settings|--threads|--toolchains|--update-snapshots|--update-plugins|--show-v [...] + local opts="-B|-C|-D|-N|-P|-T|-U|-UA|-UM|-V|-X|-am|-amd|-b|-c|-cpu|-e|-emp|-ep|-f|-fae|-ff|-fn|-gs|-gt|-h|-itr|-l|-llr|-npr|-npu|-nsu|-ntp|-o|-pl|-q|-r|-rf|-s|-t|-up|-v|${mvnd_opts}" + local long_opts="--activate-profiles|--also-make|--also-make-dependents|--artifacts-update-policy|--batch-mode|--builder|--check-plugin-updates|--debug|--define|--encrypt-master-password|--encrypt-password|--errors|--fail-at-end|--fail-fast|--fail-never|--file|--global-settings|--global-toolchains|--help|--ignore-transitive-repositories|--lax-checksums|--legacy-local-repository|--log-file|--metadata-update-policy|--no-plugin-registry|--no-plugin-updates|--no-snapshot-updates|--no-tra [...] local common_clean_lifecycle="pre-clean|clean|post-clean" local common_default_lifecycle="validate|initialize|generate-sources|process-sources|generate-resources|process-resources|compile|process-classes|generate-test-sources|process-test-sources|generate-test-resources|process-test-resources|test-compile|process-test-classes|test|prepare-package|package|pre-integration-test|integration-test|post-integration-test|verify|install|deploy" diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MaxHeapNativeIT.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MaxHeapNativeIT.java index 43a08c20..674840f4 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MaxHeapNativeIT.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/MaxHeapNativeIT.java @@ -31,7 +31,7 @@ import org.mvndaemon.mvnd.assertj.TestClientOutput; import org.mvndaemon.mvnd.client.Client; import org.mvndaemon.mvnd.junit.MvndNativeTest; import org.slf4j.LoggerFactory; -import org.slf4j.impl.MvndSimpleLogger; +import org.slf4j.simple.MvndSimpleLogger; import org.slf4j.spi.LocationAwareLogger; import static org.junit.jupiter.api.Assertions.assertTrue; diff --git a/logging/pom.xml b/logging/pom.xml index 6b38a699..dae8009f 100644 --- a/logging/pom.xml +++ b/logging/pom.xml @@ -38,10 +38,6 @@ <groupId>org.apache.maven</groupId> <artifactId>maven-embedder</artifactId> </dependency> - <dependency> - <groupId>org.apache.maven.shared</groupId> - <artifactId>maven-shared-utils</artifactId> - </dependency> <!-- Logging --> <dependency> @@ -82,14 +78,14 @@ <configuration> <artifactItems> <artifactItem> - <groupId>org.apache.maven</groupId> - <artifactId>maven-slf4j-provider</artifactId> - <version>${maven.version}</version> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>${slf4j.version}</version> <classifier>sources</classifier> </artifactItem> </artifactItems> - <includes>org/apache/maven/logwrapper/*.java,org/slf4j/impl/*.java</includes> - <excludes>**/StaticLoggerBinder.java,**/StaticMDCBinder.java</excludes> + <includes>org/slf4j/simple/*.java</includes> + <excludes>**/SimpleServiceProvider.java</excludes> <outputDirectory>${project.build.directory}/generated-sources/unpack</outputDirectory> </configuration> </execution> diff --git a/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/ProjectBuildLogAppender.java b/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/ProjectBuildLogAppender.java index 15177c7d..fa04d07e 100644 --- a/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/ProjectBuildLogAppender.java +++ b/logging/src/main/java/org/mvndaemon/mvnd/logging/smart/ProjectBuildLogAppender.java @@ -19,7 +19,7 @@ package org.mvndaemon.mvnd.logging.smart; import org.slf4j.MDC; -import org.slf4j.impl.MvndSimpleLogger; +import org.slf4j.simple.MvndSimpleLogger; /** * Forwards log messages to the client. diff --git a/logging/src/main/java/org/slf4j/impl/StaticLoggerBinder.java b/logging/src/main/java/org/slf4j/impl/StaticLoggerBinder.java deleted file mode 100644 index 2ebf87ba..00000000 --- a/logging/src/main/java/org/slf4j/impl/StaticLoggerBinder.java +++ /dev/null @@ -1,82 +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.slf4j.impl; - -import org.slf4j.ILoggerFactory; -import org.slf4j.spi.LoggerFactoryBinder; - -/** - * SLF4J LoggerFactoryBinder implementation using MavenSimpleLogger. - * This class is part of the required classes used to specify an - * SLF4J logger provider implementation. - * - * @since 3.5.1 - */ -public final class StaticLoggerBinder implements LoggerFactoryBinder { - /** - * Declare the version of the SLF4J API this implementation is compiled - * against. The value of this field is usually modified with each release. - */ - // to avoid constant folding by the compiler, this field must *not* be final - @SuppressWarnings({"checkstyle:staticvariablename", "checkstyle:visibilitymodifier"}) - public static String REQUESTED_API_VERSION = "1.7.25"; // !final - - private static final String LOGGER_FACTORY_CLASS_STR = MvndLoggerFactory.class.getName(); - - /** - * The unique instance of this class. - */ - private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder(); - - /** - * The ILoggerFactory instance returned by the {@link #getLoggerFactory} - * method should always be the same object - */ - private final ILoggerFactory loggerFactory; - - /** - * Private constructor to prevent instantiation - */ - private StaticLoggerBinder() { - loggerFactory = new MvndLoggerFactory(); - } - - /** - * Returns the singleton of this class. - */ - public static StaticLoggerBinder getSingleton() { - return SINGLETON; - } - - /** - * Returns the factory. - */ - @Override - public ILoggerFactory getLoggerFactory() { - return loggerFactory; - } - - /** - * Returns the class name. - */ - @Override - public String getLoggerFactoryClassStr() { - return LOGGER_FACTORY_CLASS_STR; - } -} diff --git a/logging/src/main/java/org/slf4j/impl/StaticMDCBinder.java b/logging/src/main/java/org/slf4j/impl/StaticMDCBinder.java deleted file mode 100644 index c264b1d1..00000000 --- a/logging/src/main/java/org/slf4j/impl/StaticMDCBinder.java +++ /dev/null @@ -1,57 +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.slf4j.impl; - -import org.slf4j.helpers.BasicMDCAdapter; -import org.slf4j.spi.MDCAdapter; - -/** - * This implementation is bound to {@link BasicMDCAdapter}. - */ -public class StaticMDCBinder { - - /** - * The unique instance of this class. - */ - public static final StaticMDCBinder SINGLETON = new StaticMDCBinder(); - - private StaticMDCBinder() {} - - /** - * Return the singleton of this class. - * - * @return the StaticMDCBinder singleton - * @since 1.7.14 - */ - public static final StaticMDCBinder getSingleton() { - return SINGLETON; - } - - /** - * Currently this method always returns an instance of - * {@link StaticMDCBinder}. - */ - public MDCAdapter getMDCA() { - return new BasicMDCAdapter(); - } - - public String getMDCAdapterClassStr() { - return BasicMDCAdapter.class.getName(); - } -} diff --git a/logging/src/main/java/org/slf4j/impl/MvndBaseLogger.java b/logging/src/main/java/org/slf4j/simple/MvndBaseLogger.java similarity index 99% rename from logging/src/main/java/org/slf4j/impl/MvndBaseLogger.java rename to logging/src/main/java/org/slf4j/simple/MvndBaseLogger.java index 5e44cefb..3e41e0e9 100644 --- a/logging/src/main/java/org/slf4j/impl/MvndBaseLogger.java +++ b/logging/src/main/java/org/slf4j/simple/MvndBaseLogger.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.slf4j.impl; +package org.slf4j.simple; import org.slf4j.event.LoggingEvent; import org.slf4j.helpers.FormattingTuple; diff --git a/logging/src/main/java/org/slf4j/impl/MvndConfiguration.java b/logging/src/main/java/org/slf4j/simple/MvndConfiguration.java similarity index 92% rename from logging/src/main/java/org/slf4j/impl/MvndConfiguration.java rename to logging/src/main/java/org/slf4j/simple/MvndConfiguration.java index e075a03e..2b14a0b4 100644 --- a/logging/src/main/java/org/slf4j/impl/MvndConfiguration.java +++ b/logging/src/main/java/org/slf4j/simple/MvndConfiguration.java @@ -16,10 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.slf4j.impl; +package org.slf4j.simple; import org.apache.maven.cli.logging.Slf4jConfiguration; import org.slf4j.ILoggerFactory; +import org.slf4j.LoggerFactory; public class MvndConfiguration implements Slf4jConfiguration { @Override @@ -43,7 +44,7 @@ public class MvndConfiguration implements Slf4jConfiguration { @Override public void activate() { - ILoggerFactory lf = StaticLoggerBinder.getSingleton().getLoggerFactory(); + ILoggerFactory lf = LoggerFactory.getILoggerFactory(); if (lf instanceof MvndLoggerFactory) { ((MvndLoggerFactory) lf).reconfigure(); } diff --git a/logging/src/main/java/org/slf4j/impl/MvndDaemonLogger.java b/logging/src/main/java/org/slf4j/simple/MvndDaemonLogger.java similarity index 98% rename from logging/src/main/java/org/slf4j/impl/MvndDaemonLogger.java rename to logging/src/main/java/org/slf4j/simple/MvndDaemonLogger.java index 02977aea..873e2d3e 100644 --- a/logging/src/main/java/org/slf4j/impl/MvndDaemonLogger.java +++ b/logging/src/main/java/org/slf4j/simple/MvndDaemonLogger.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.slf4j.impl; +package org.slf4j.simple; import java.io.PrintStream; import java.io.PrintWriter; diff --git a/logging/src/main/java/org/slf4j/impl/MvndLoggerFactory.java b/logging/src/main/java/org/slf4j/simple/MvndLoggerFactory.java similarity index 98% rename from logging/src/main/java/org/slf4j/impl/MvndLoggerFactory.java rename to logging/src/main/java/org/slf4j/simple/MvndLoggerFactory.java index 4761455f..e24adf6a 100644 --- a/logging/src/main/java/org/slf4j/impl/MvndLoggerFactory.java +++ b/logging/src/main/java/org/slf4j/simple/MvndLoggerFactory.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.slf4j.impl; +package org.slf4j.simple; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; diff --git a/logging/src/main/java/org/slf4j/simple/MvndServiceProvider.java b/logging/src/main/java/org/slf4j/simple/MvndServiceProvider.java new file mode 100644 index 00000000..00917ea9 --- /dev/null +++ b/logging/src/main/java/org/slf4j/simple/MvndServiceProvider.java @@ -0,0 +1,64 @@ +/* + * 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.slf4j.simple; + +import org.slf4j.ILoggerFactory; +import org.slf4j.IMarkerFactory; +import org.slf4j.helpers.BasicMDCAdapter; +import org.slf4j.helpers.BasicMarkerFactory; +import org.slf4j.spi.MDCAdapter; +import org.slf4j.spi.SLF4JServiceProvider; + +/** + * SLF4J service provider for mvnd, using {@link MvndLoggerFactory}. + */ +public class MvndServiceProvider implements SLF4JServiceProvider { + // to avoid constant folding by the compiler, this field must *not* be final + @SuppressWarnings({"checkstyle:staticvariablename", "checkstyle:visibilitymodifier"}) + public static String REQUESTED_API_VERSION = "2.0"; // !final + + private ILoggerFactory loggerFactory; + private final IMarkerFactory markerFactory = new BasicMarkerFactory(); + private final MDCAdapter mdcAdapter = new BasicMDCAdapter(); + + @Override + public ILoggerFactory getLoggerFactory() { + return loggerFactory; + } + + @Override + public IMarkerFactory getMarkerFactory() { + return markerFactory; + } + + @Override + public MDCAdapter getMDCAdapter() { + return mdcAdapter; + } + + @Override + public String getRequestedApiVersion() { + return REQUESTED_API_VERSION; + } + + @Override + public void initialize() { + loggerFactory = new MvndLoggerFactory(); + } +} diff --git a/logging/src/main/java/org/slf4j/impl/MvndSimpleLogger.java b/logging/src/main/java/org/slf4j/simple/MvndSimpleLogger.java similarity index 93% rename from logging/src/main/java/org/slf4j/impl/MvndSimpleLogger.java rename to logging/src/main/java/org/slf4j/simple/MvndSimpleLogger.java index b4463051..5eb2e590 100644 --- a/logging/src/main/java/org/slf4j/impl/MvndSimpleLogger.java +++ b/logging/src/main/java/org/slf4j/simple/MvndSimpleLogger.java @@ -16,15 +16,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.slf4j.impl; +package org.slf4j.simple; import java.util.Date; import java.util.function.Consumer; -import org.apache.maven.shared.utils.logging.MessageBuilder; -import org.apache.maven.shared.utils.logging.MessageUtils; +import org.apache.maven.api.services.MessageBuilder; -import static org.apache.maven.shared.utils.logging.MessageUtils.level; +import static org.apache.maven.jline.MessageUtils.builder; /** * Logger for Maven, that support colorization of levels and stacktraces. This class implements 2 methods introduced in @@ -150,16 +149,16 @@ public class MvndSimpleLogger extends MvndBaseLogger { protected String renderLevel(int level) { switch (level) { case LOG_LEVEL_TRACE: - return level().debug("TRACE"); + return builder().trace("TRACE").build(); case LOG_LEVEL_DEBUG: - return level().debug("DEBUG"); + return builder().debug("DEBUG").build(); case LOG_LEVEL_INFO: - return level().info("INFO"); + return builder().info("INFO").build(); case LOG_LEVEL_WARN: - return level().warning("WARNING"); + return builder().warning("WARNING").build(); case LOG_LEVEL_ERROR: default: - return level().error("ERROR"); + return builder().error("ERROR").build(); } } @@ -167,7 +166,7 @@ public class MvndSimpleLogger extends MvndBaseLogger { if (t == null) { return; } - MessageBuilder builder = MessageUtils.buffer(sb); + MessageBuilder builder = builder(); builder.newline(); builder.failure(t.getClass().getName()); if (t.getMessage() != null) { @@ -177,6 +176,7 @@ public class MvndSimpleLogger extends MvndBaseLogger { builder.newline(); printStackTrace(t, builder, ""); + sb.append(builder.build()); } private void printStackTrace(Throwable t, MessageBuilder builder, String prefix) { 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 ee6529b8..5587ba2f 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.slf4j.impl.MvndLoggerFactory org.slf4j.impl.MvndConfiguration +org.slf4j.simple.MvndLoggerFactory org.slf4j.simple.MvndConfiguration diff --git a/logging/src/main/resources/META-INF/maven/slf4j-configuration.properties b/logging/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider similarity index 80% copy from logging/src/main/resources/META-INF/maven/slf4j-configuration.properties copy to logging/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider index ee6529b8..9f49a3f1 100644 --- a/logging/src/main/resources/META-INF/maven/slf4j-configuration.properties +++ b/logging/src/main/resources/META-INF/services/org.slf4j.spi.SLF4JServiceProvider @@ -15,6 +15,4 @@ # specific language governing permissions and limitations # under the License. -# key = Slf4j effective logger factory implementation -# value = corresponding o.a.m.cli.logging.Slf4jConfiguration class -org.slf4j.impl.MvndLoggerFactory org.slf4j.impl.MvndConfiguration +org.slf4j.simple.MvndServiceProvider diff --git a/pom.xml b/pom.xml index 75331216..224985fa 100644 --- a/pom.xml +++ b/pom.xml @@ -90,16 +90,14 @@ <apiguardian-api.version>1.0.0</apiguardian-api.version> <assertj.version>3.27.7</assertj.version> <commons-compress.version>1.28.0</commons-compress.version> - <!-- cannot upgrade graalvm to 23.0.0 which requires JDK >= 20 --> - <graalvm.version>25.0.5.1</graalvm.version> <graalvm.plugin.version>1.1.19</graalvm.plugin.version> <groovy.version>5.1.3</groovy.version> <jakarta.inject.version>1.0.5</jakarta.inject.version> <jline.version>3.30.17</jline.version> - <maven.version>3.9.16</maven.version> + <maven.version>3.10.2</maven.version> <!-- Keep in sync with Maven --> - <maven.resolver.version>1.9.27</maven.resolver.version> - <slf4j.version>1.7.36</slf4j.version> + <maven.resolver.version>2.0.26</maven.resolver.version> + <slf4j.version>2.0.20</slf4j.version> <sisu.version>1.1.2</sisu.version> <!-- plugin versions a..z --> @@ -146,12 +144,6 @@ <version>${groovy.version}</version> </dependency> - <dependency> - <groupId>org.graalvm.nativeimage</groupId> - <artifactId>svm</artifactId> - <version>${graalvm.version}</version> - </dependency> - <dependency> <groupId>jakarta.inject</groupId> <artifactId>jakarta.inject-api</artifactId> @@ -222,13 +214,6 @@ <version>${maven.resolver.version}</version> </dependency> - <!-- Only for MessageBuilder/MessageUtils --> - <dependency> - <groupId>org.apache.maven.shared</groupId> - <artifactId>maven-shared-utils</artifactId> - <version>3.5.0</version> - </dependency> - <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId>
