29
29
import org .apache .maven .shared .utils .StringUtils ;
30
30
import org .junit .jupiter .api .BeforeEach ;
31
31
import org .junit .jupiter .api .Test ;
32
+ import org .junit .jupiter .api .condition .DisabledOnOs ;
33
+ import org .junit .jupiter .api .condition .OS ;
32
34
33
35
import static org .junit .jupiter .api .Assertions .assertEquals ;
36
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
34
37
import static org .junit .jupiter .api .Assertions .assertTrue ;
35
38
36
39
class DefaultInvokerTest {
@@ -42,6 +45,7 @@ class DefaultInvokerTest {
42
45
public void setUp () {
43
46
request .setDebug (true );
44
47
request .setProperties (getProperties ());
48
+ request .setBatchMode (true );
45
49
}
46
50
47
51
@ Test
@@ -184,6 +188,35 @@ void testMavenWrapperInProject() throws Exception {
184
188
}
185
189
}
186
190
191
+ @ Test
192
+ @ DisabledOnOs (OS .WINDOWS ) // mvn 3.6.3 and windows ...
193
+ void notInheritEnvVariables () throws Exception {
194
+
195
+ // ensure that we have env variable in current process
196
+ assertEquals ("test-env-value" , System .getenv ("INVOKER_TEST_ENV_1" ));
197
+
198
+ File basedir = getBasedirForBuild ();
199
+ request .setBaseDirectory (basedir );
200
+ request .addArg ("initialize" );
201
+ request .setShellEnvironmentInherited (false );
202
+ request .addShellEnvironment ("INVOKER_TEST_ENV_2" , "test-env-value-2" );
203
+ // Maven 3.6.3 required JAVA_HOME
204
+ request .addShellEnvironment ("JAVA_HOME" , System .getProperty ("java.home" ));
205
+
206
+ final StringBuilder outlines = new StringBuilder ();
207
+ request .setOutputHandler (line -> outlines .append (line ).append (System .lineSeparator ()));
208
+
209
+ InvocationResult result = invoker .execute (request );
210
+
211
+ String output = outlines .toString ();
212
+ assertEquals (
213
+ 0 ,
214
+ result .getExitCode (),
215
+ () -> "Maven exit code: " + result .getExitCode () + System .lineSeparator () + output .trim ());
216
+ assertFalse (output .contains ("INVOKER_TEST_ENV_1" ));
217
+ assertTrue (output .contains ("INVOKER_TEST_ENV_2=test-env-value-2" ));
218
+ }
219
+
187
220
private Invoker newInvoker () {
188
221
Invoker invoker = new DefaultInvoker ();
189
222
0 commit comments