Skip to content

Commit

Permalink
Ignore smart-builder core extension, if present. (#916)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
cstamas authored Apr 17, 2024
1 parent d5d697c commit a1ac666
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -480,9 +482,25 @@ private static List<CoreExtension> readCoreExtensionsDescriptor(Path multiModule
return Collections.emptyList();
}
CoreExtensionsStaxReader parser = new CoreExtensionsStaxReader();
List<CoreExtension> extensions;
try (InputStream is = Files.newInputStream(extensionsFile)) {
return parser.read(is).getExtensions();
extensions = parser.read(is).getExtensions();
}
return filterCoreExtensions(extensions);
}

private static List<CoreExtension> filterCoreExtensions(List<CoreExtension> coreExtensions) {
Set<String> 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) {
Expand Down
12 changes: 12 additions & 0 deletions common/src/main/java/org/mvndaemon/mvnd/common/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>-Xms</code> value to pass to the daemon.
* This option takes precedence over options specified in <code>-Dmvnd.jvmArgs</code>.
Expand Down
2 changes: 1 addition & 1 deletion dist/src/main/distro/bin/mvnd-bash-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down

0 comments on commit a1ac666

Please sign in to comment.