diff --git a/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java b/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java index e6fde18337..7d1a8aaa78 100644 --- a/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java +++ b/maven-cli/src/main/java/org/apache/maven/cling/invoker/BaseParser.java @@ -34,7 +34,6 @@ import java.util.Map; import java.util.Objects; import java.util.Properties; import java.util.ServiceLoader; -import java.util.Set; import java.util.function.Function; import org.apache.maven.api.Constants; @@ -156,8 +155,6 @@ public abstract class BaseParser> } result = getCanonicalPath(Paths.get(mavenHome)); } - // TODO: we still do this but would be cool if this becomes unneeded - System.setProperty(Constants.MAVEN_HOME, result.toString()); return result; } @@ -295,15 +292,6 @@ public abstract class BaseParser> Path propertiesFile = mavenConf.resolve("maven.properties"); MavenPropertiesLoader.loadProperties(userProperties, propertiesFile, callback, false); - // ---------------------------------------------------------------------- - // I'm leaving the setting of system properties here as not to break - // the SystemPropertyProfileActivator. This won't harm embedding. jvz. - // ---------------------------------------------------------------------- - Set sys = SystemProperties.getSystemProperties().stringPropertyNames(); - userProperties.stringPropertyNames().stream() - .filter(k -> !sys.contains(k)) - .forEach(k -> System.setProperty(k, userProperties.getProperty(k))); - return toMap(userProperties); } diff --git a/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java b/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java index 3411c4604d..376e09f086 100644 --- a/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java +++ b/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java @@ -25,6 +25,7 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.nio.file.Files; import java.nio.file.Path; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; @@ -153,7 +154,17 @@ public abstract class LookupInvoker< requireNonNull(invokerRequest); try (C context = createContext(invokerRequest)) { + Properties props = (Properties) System.getProperties().clone(); try { + HashSet sys = + new HashSet<>(invokerRequest.systemProperties().keySet()); + invokerRequest.userProperties().entrySet().stream() + .filter(k -> !sys.contains(k.getKey())) + .forEach(k -> System.setProperty(k.getKey(), k.getValue())); + System.setProperty( + Constants.MAVEN_HOME, + invokerRequest.installationDirectory().toString()); + validate(context); prepare(context); configureLogging(context); @@ -181,6 +192,8 @@ public abstract class LookupInvoker< return execute(context); } catch (Exception e) { throw handleException(context, e); + } finally { + System.setProperties(props); } } } diff --git a/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/DefaultMavenInvoker.java b/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/DefaultMavenInvoker.java index 58d9c388b7..3c8f6bb8f9 100644 --- a/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/DefaultMavenInvoker.java +++ b/maven-cli/src/main/java/org/apache/maven/cling/invoker/mvn/DefaultMavenInvoker.java @@ -110,9 +110,9 @@ public abstract class DefaultMavenInvoker< DefaultMavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest(); mavenExecutionRequest.setRepositoryCache(new DefaultRepositoryCache()); mavenExecutionRequest.setInteractiveMode(true); + mavenExecutionRequest.setCacheTransferError(false); mavenExecutionRequest.setIgnoreInvalidArtifactDescriptor(true); mavenExecutionRequest.setIgnoreMissingArtifactDescriptor(true); - mavenExecutionRequest.setProjectPresent(true); mavenExecutionRequest.setRecursive(true); mavenExecutionRequest.setReactorFailureBehavior(MavenExecutionRequest.REACTOR_FAIL_FAST); mavenExecutionRequest.setStartTime(new Date());