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.Collections;
24 import java.util.HashSet;
25 import java.util.Properties;
26 import java.util.Set;
27 import java.util.concurrent.ConcurrentLinkedDeque;
28
29 import org.apache.maven.surefire.shared.utils.cli.CommandLineException;
30 import org.apache.maven.surefire.shared.utils.cli.CommandLineUtils;
31 import org.apache.maven.surefire.shared.utils.cli.Commandline;
32
33
34
35
36
37
38
39
40 public class OutputStreamFlushableCommandline
41 extends Commandline
42 implements FlushReceiverProvider
43 {
44 private final Collection<String> excludedEnvironmentVariables;
45 private final Set<String> addedEnvironmentVariables;
46 private volatile FlushReceiver flushReceiver;
47
48
49
50
51 public OutputStreamFlushableCommandline()
52 {
53 this( new String[0] );
54 }
55
56 public OutputStreamFlushableCommandline( String[] excludedEnvironmentVariables )
57 {
58 this.excludedEnvironmentVariables = new ConcurrentLinkedDeque<>();
59 addedEnvironmentVariables = new HashSet<>();
60 Collections.addAll( this.excludedEnvironmentVariables, excludedEnvironmentVariables );
61 }
62
63 @Override
64 public void addEnvironment( String name, String value )
65 {
66 super.addEnvironment( name, value );
67 addedEnvironmentVariables.add( name );
68 }
69
70 @Override
71 public final void addSystemEnvironment()
72 {
73 Properties systemEnvVars = CommandLineUtils.getSystemEnvVars();
74
75 for ( String key : systemEnvVars.stringPropertyNames() )
76 {
77 if ( !addedEnvironmentVariables.contains( key ) && !excludedEnvironmentVariables.contains( key ) )
78 {
79 addEnvironment( key, systemEnvVars.getProperty( key ) );
80 }
81 }
82 }
83
84 @Override
85 public Process execute()
86 throws CommandLineException
87 {
88 Process process = super.execute();
89
90 if ( process.getOutputStream() != null )
91 {
92 flushReceiver = new OutputStreamFlushReceiver( process.getOutputStream() );
93 }
94
95 return process;
96 }
97
98 @Override
99 public FlushReceiver getFlushReceiver()
100 {
101 return flushReceiver;
102 }
103 }