You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2024/05/07 19:43:36 UTC
(maven-invoker) branch MSHARED-971 created (now f5c5b41)
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a change to branch MSHARED-971
in repository https://gitbox.apache.org/repos/asf/maven-invoker.git
at f5c5b41 [MSHARED-971] Add test for inherited environment
This branch includes the following new commits:
new f5c5b41 [MSHARED-971] Add test for inherited environment
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-invoker) 01/01: [MSHARED-971] Add test for inherited environment
Posted by sj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch MSHARED-971
in repository https://gitbox.apache.org/repos/asf/maven-invoker.git
commit f5c5b41118c1601523e417edde29069af4de2acf
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Tue May 7 21:43:17 2024 +0200
[MSHARED-971] Add test for inherited environment
---
pom.xml | 3 ++
.../maven/shared/invoker/DefaultInvokerTest.java | 25 ++++++++++++
.../resources/not-inherit-env-variables/pom.xml | 44 ++++++++++++++++++++++
3 files changed, 72 insertions(+)
diff --git a/pom.xml b/pom.xml
index 74b78e9..863f8da 100644
--- a/pom.xml
+++ b/pom.xml
@@ -105,6 +105,9 @@ under the License.
<maven.home>${maven.home}</maven.home>
<maven.repo.local>${settings.localRepository}</maven.repo.local>
</systemPropertyVariables>
+ <environmentVariables>
+ <INVOKER_TEST_ENV_1>test-env-value</INVOKER_TEST_ENV_1>
+ </environmentVariables>
<excludes>
<exclude>test-build-should*/**</exclude>
</excludes>
diff --git a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
index 6a94b64..0f50fef 100644
--- a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
+++ b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java
@@ -31,6 +31,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class DefaultInvokerTest {
@@ -42,6 +43,7 @@ class DefaultInvokerTest {
public void setUp() {
request.setDebug(true);
request.setProperties(getProperties());
+ request.setBatchMode(true);
}
@Test
@@ -184,6 +186,29 @@ class DefaultInvokerTest {
}
}
+ @Test
+ void notInheritEnvVariables() throws Exception {
+
+ // ensure that we have env variable in current process
+ assertEquals("test-env-value", System.getenv("INVOKER_TEST_ENV_1"));
+
+ File basedir = getBasedirForBuild();
+ request.setBaseDirectory(basedir);
+ request.addArg("initialize");
+ request.setShellEnvironmentInherited(false);
+ request.addShellEnvironment("INVOKER_TEST_ENV_2", "test-env-value-2");
+
+ final StringBuilder outlines = new StringBuilder();
+ request.setOutputHandler(outlines::append);
+
+ InvocationResult result = invoker.execute(request);
+
+ String output = outlines.toString();
+ assertEquals(0, result.getExitCode());
+ assertFalse(output.contains("INVOKER_TEST_ENV_1"));
+ assertTrue(output.contains("INVOKER_TEST_ENV_2=test-env-value-2"));
+ }
+
private Invoker newInvoker() {
Invoker invoker = new DefaultInvoker();
diff --git a/src/test/resources/not-inherit-env-variables/pom.xml b/src/test/resources/not-inherit-env-variables/pom.xml
new file mode 100644
index 0000000..90aee9f
--- /dev/null
+++ b/src/test/resources/not-inherit-env-variables/pom.xml
@@ -0,0 +1,44 @@
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.shared.invoker</groupId>
+ <artifactId>not-inherit-env-variables</artifactId>
+ <packaging>pom</packaging>
+ <version>1</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-help-plugin</artifactId>
+ <version>${version.maven-help-plugin}</version>
+ <executions>
+ <execution>
+ <phase>initialize</phase>
+ <goals>
+ <goal>system</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>