1 package org.apache.maven.plugin.surefire.booterclient.lazytestprovider;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Collection;
23 import java.util.HashSet;
24 import java.util.Properties;
25 import java.util.Set;
26 import java.util.concurrent.ConcurrentLinkedDeque;
27
28 import org.apache.maven.surefire.shared.utils.cli.CommandLineUtils;
29
30 import static java.util.Collections.addAll;
31
32
33
34
35
36
37 public class Commandline
38 extends org.apache.maven.surefire.shared.utils.cli.Commandline
39 {
40 private final Collection<String> excludedEnvironmentVariables;
41 private final Set<String> addedEnvironmentVariables;
42
43
44
45
46 public Commandline()
47 {
48 this( new String[0] );
49 }
50
51 public Commandline( String[] excludedEnvironmentVariables )
52 {
53 this.excludedEnvironmentVariables = new ConcurrentLinkedDeque<>();
54 addedEnvironmentVariables = new HashSet<>();
55 addAll( this.excludedEnvironmentVariables, excludedEnvironmentVariables );
56 }
57
58 @Override
59 public void addEnvironment( String name, String value )
60 {
61 super.addEnvironment( name, value );
62 addedEnvironmentVariables.add( name );
63 }
64
65 @Override
66 public final void addSystemEnvironment()
67 {
68 Properties systemEnvVars = CommandLineUtils.getSystemEnvVars();
69
70 for ( String key : systemEnvVars.stringPropertyNames() )
71 {
72 if ( !addedEnvironmentVariables.contains( key ) && !excludedEnvironmentVariables.contains( key ) )
73 {
74 addEnvironment( key, systemEnvVars.getProperty( key ) );
75 }
76 }
77 }
78 }