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