From a1ac6660ec16c0e9f094d29eb710665483210988 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Wed, 17 Apr 2024 22:04:35 +0200 Subject: [PATCH] Ignore smart-builder core extension, if present. (#916) Add new daemon param to ignore some extensions, make default to ignore takari-smart-builder as it is used by mvnd itself as well. Fixes #912 --- .../mvnd/client/DaemonParameters.java | 20 ++++++++++++++++++- .../mvndaemon/mvnd/common/Environment.java | 12 +++++++++++ .../main/distro/bin/mvnd-bash-completion.bash | 2 +- 3 files changed, 32 insertions(+), 2 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 b294b9d70..1dab82a5c 100644 --- a/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java +++ b/client/src/main/java/org/mvndaemon/mvnd/client/DaemonParameters.java @@ -30,11 +30,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Properties; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; import java.util.function.Function; @@ -480,9 +482,25 @@ private static List readCoreExtensionsDescriptor(Path multiModule return Collections.emptyList(); } CoreExtensionsStaxReader parser = new CoreExtensionsStaxReader(); + List extensions; try (InputStream is = Files.newInputStream(extensionsFile)) { - return parser.read(is).getExtensions(); + extensions = parser.read(is).getExtensions(); } + return filterCoreExtensions(extensions); + } + + private static List filterCoreExtensions(List coreExtensions) { + Set exclusions = new HashSet<>(); + String exclusionsString = + systemProperty(Environment.MVND_CORE_EXTENSIONS_EXCLUDE).asString(); + if (exclusionsString != null) { + exclusions.addAll(Arrays.stream(exclusionsString.split(",")) + .filter(e -> e != null && !e.trim().isEmpty()) + .collect(Collectors.toList())); + } + return coreExtensions.stream() + .filter(e -> !exclusions.contains(e.getGroupId() + ":" + e.getArtifactId())) + .collect(Collectors.toList()); } private static Properties loadProperties(Path path) { 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 ac0e9a6c5..29faa6af9 100644 --- a/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java +++ b/common/src/main/java/org/mvndaemon/mvnd/common/Environment.java @@ -213,6 +213,18 @@ public enum Environment { * Internal option to specify the list of maven extension to register. */ MVND_CORE_EXTENSIONS("mvnd.coreExtensions", null, null, OptionType.STRING, Flags.DISCRIMINATING | Flags.INTERNAL), + /** + * Internal option to specify comma separated list of maven extension G:As to exclude (to not load them from + * .mvn/extensions.xml). This option makes possible for example that a project that with vanilla Maven would + * use takari-smart-builder extension, remain buildable with mvnd (where use of this extension would cause issues). + * Value is expected as comma separated {@code g1:a1,g2:a2} pairs. + */ + MVND_CORE_EXTENSIONS_EXCLUDE( + "mvnd.coreExtensionsExclude", + null, + "io.takari.maven:takari-smart-builder", + OptionType.STRING, + Flags.OPTIONAL), /** * The -Xms value to pass to the daemon. * This option takes precedence over options specified in -Dmvnd.jvmArgs. diff --git a/dist/src/main/distro/bin/mvnd-bash-completion.bash b/dist/src/main/distro/bin/mvnd-bash-completion.bash index 473eca900..ade2f771d 100755 --- a/dist/src/main/distro/bin/mvnd-bash-completion.bash +++ b/dist/src/main/distro/bin/mvnd-bash-completion.bash @@ -218,7 +218,7 @@ _mvnd() local mvnd_opts="-1" local mvnd_long_opts="--color|--completion|--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.daemonStorage|-Dmvnd.debug|-Dmvnd.debug.address|-Dmvnd.duplicateDaemonGracePeriod|-Dmvnd.enableAssertions|-Dmvnd.expirationCheckDelay|-Dmvnd.home|-Dmvnd.idleTimeout|-Dmvnd.jvmArgs|-Dmvnd.keepAlive|-Dmvnd.logPurgePeriod|-Dmvnd.maxHeapSize|-Dmvnd.maxLostKeepAlive|-Dmvnd.minHeapSize|-Dmvnd.minThreads|-Dmvnd.noBuffering|-Dmvnd.noDaemon|-Dmvnd.noModelCache|-Dmvnd.pluginRealmEvictPattern|-Dmvnd.propertiesPath|-Dmvnd.rawStreams|-Dmvnd.registry|-Dmvnd.rollingWindowSize|-Dmvnd.serial|-Dmvnd.socketConnectTimeout|-Dmvnd.socketFamily|-Dmvnd.threadStackSize|-Dmvnd.threads|-Dstyle.color|-Duser.dir|-Duser.home" + 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.home|-Dmvnd.idleTimeout|-Dmvnd.jvmArgs|-Dmvnd.keepAlive|-Dmvnd.logPurgePeriod|-Dmvnd.maxHeapSize|-Dmvnd.maxLostKeepAlive|-Dmvnd.minHeapSize|-Dmvnd.minThreads|-Dmvnd.noBuffering|-Dmvnd.noDaemon|-Dmvnd.noModelCache|-Dmvnd.pluginRealmEvictPattern|-Dmvnd.propertiesPath|-Dmvnd.rawStreams|-Dmvnd.registry|-Dmvnd.rollingWindowSize|-Dmvnd.serial|-Dmvnd.socketConnectTimeout|-Dmvnd.socketFamily|-Dmvnd.threadStackSize|-Dmvnd.threads|-Dstyle.color|-Duser.dir|-Duser.home" 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-version|--version|--debug|${mvnd_long_opts}"