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