1 | |
package org.apache.maven.plugin.surefire; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
import java.io.File; |
22 | |
import java.io.FileInputStream; |
23 | |
import java.io.IOException; |
24 | |
import java.io.InputStream; |
25 | |
import java.util.Collections; |
26 | |
import java.util.Enumeration; |
27 | |
import java.util.Iterator; |
28 | |
import java.util.LinkedHashSet; |
29 | |
import java.util.Map; |
30 | |
import java.util.Properties; |
31 | |
import org.apache.maven.plugin.logging.Log; |
32 | |
import org.apache.maven.surefire.booter.KeyValueSource; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
public class SurefireProperties |
38 | |
extends Properties |
39 | |
implements KeyValueSource |
40 | |
{ |
41 | 3 | private final LinkedHashSet<Object> items = new LinkedHashSet<Object>(); |
42 | |
|
43 | |
public SurefireProperties() |
44 | 0 | { |
45 | 0 | } |
46 | |
|
47 | |
public SurefireProperties( Properties source ) |
48 | 3 | { |
49 | 3 | if ( source != null ) |
50 | |
{ |
51 | 1 | this.putAll( source ); |
52 | |
} |
53 | 3 | } |
54 | |
|
55 | |
@Override |
56 | |
public synchronized Object put( Object key, Object value ) |
57 | |
{ |
58 | 10 | items.add( key ); |
59 | 10 | return super.put( key, value ); |
60 | |
} |
61 | |
|
62 | |
@Override |
63 | |
public synchronized Object remove( Object key ) |
64 | |
{ |
65 | 1 | items.remove( key ); |
66 | 1 | return super.remove( key ); |
67 | |
} |
68 | |
|
69 | |
@Override |
70 | |
public synchronized void clear() |
71 | |
{ |
72 | 0 | items.clear(); |
73 | 0 | super.clear(); |
74 | 0 | } |
75 | |
|
76 | |
public synchronized Enumeration<Object> keys() |
77 | |
{ |
78 | 2 | return Collections.enumeration( items ); |
79 | |
} |
80 | |
|
81 | |
public void copyProperties( Properties source ) |
82 | |
{ |
83 | 0 | if ( source != null ) |
84 | |
{ |
85 | |
|
86 | 0 | for ( Object key : source.keySet() ) |
87 | |
{ |
88 | 0 | Object value = source.get( key ); |
89 | 0 | put( key, value ); |
90 | 0 | } |
91 | |
} |
92 | 0 | } |
93 | |
|
94 | |
private Iterable<Object> getStringKeySet() |
95 | |
{ |
96 | |
|
97 | |
|
98 | 0 | return keySet(); |
99 | |
} |
100 | |
|
101 | |
public void showToLog( org.apache.maven.plugin.logging.Log log, String setting ) |
102 | |
{ |
103 | 0 | for ( Object key : getStringKeySet() ) |
104 | |
{ |
105 | 0 | String value = getProperty( (String) key ); |
106 | 0 | log.debug( "Setting " + setting + " [" + key + "]=[" + value + "]" ); |
107 | 0 | } |
108 | 0 | } |
109 | |
|
110 | |
public void verifyLegalSystemProperties( org.apache.maven.plugin.logging.Log log ) |
111 | |
{ |
112 | 0 | for ( Object key : getStringKeySet() ) |
113 | |
{ |
114 | 0 | if ( "java.library.path".equals( key ) ) |
115 | |
{ |
116 | 0 | log.warn( |
117 | |
"java.library.path cannot be set as system property, use <argLine>-Djava.library.path=...<argLine> instead" ); |
118 | |
} |
119 | |
} |
120 | 0 | } |
121 | |
|
122 | |
|
123 | |
public void copyToSystemProperties() |
124 | |
{ |
125 | |
|
126 | |
|
127 | 0 | for ( Object o : items ) |
128 | |
{ |
129 | 0 | String key = (String) o; |
130 | 0 | String value = getProperty( key ); |
131 | |
|
132 | 0 | System.setProperty( key, value ); |
133 | 0 | } |
134 | 0 | } |
135 | |
|
136 | |
static SurefireProperties calculateEffectiveProperties( Properties systemProperties, File systemPropertiesFile, |
137 | |
Map<String, String> systemPropertyVariables, |
138 | |
Properties userProperties, Log log ) |
139 | |
{ |
140 | 0 | SurefireProperties result = new SurefireProperties(); |
141 | 0 | result.copyProperties( systemProperties ); |
142 | |
|
143 | 0 | if ( systemPropertiesFile != null ) |
144 | |
{ |
145 | 0 | Properties props = new SurefireProperties(); |
146 | |
try |
147 | |
{ |
148 | 0 | InputStream fis = new FileInputStream( systemPropertiesFile ); |
149 | 0 | props.load( fis ); |
150 | 0 | fis.close(); |
151 | |
} |
152 | 0 | catch ( IOException e ) |
153 | |
{ |
154 | 0 | String msg = "The system property file '" + systemPropertiesFile.getAbsolutePath() + "' can't be read."; |
155 | 0 | if ( log.isDebugEnabled() ) |
156 | |
{ |
157 | 0 | log.warn( msg, e ); |
158 | |
} |
159 | |
else |
160 | |
{ |
161 | 0 | log.warn( msg ); |
162 | |
} |
163 | 0 | } |
164 | |
|
165 | 0 | result.copyProperties( props ); |
166 | |
} |
167 | |
|
168 | 0 | copyProperties( result, systemPropertyVariables ); |
169 | 0 | copyProperties( result, systemPropertyVariables ); |
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | 0 | result.copyProperties( userProperties ); |
177 | 0 | return result; |
178 | |
} |
179 | |
|
180 | |
public static void copyProperties( Properties target, Map<String, String> source ) |
181 | |
{ |
182 | 0 | if ( source != null ) |
183 | |
{ |
184 | 0 | for ( String key : source.keySet() ) |
185 | |
{ |
186 | 0 | String value = source.get( key ); |
187 | |
|
188 | 0 | if ( value != null ) |
189 | |
{ |
190 | 0 | target.setProperty( key, value ); |
191 | |
} |
192 | 0 | } |
193 | |
} |
194 | 0 | } |
195 | |
|
196 | |
public void copyTo( Map target ) |
197 | |
{ |
198 | 0 | Iterator iter = keySet().iterator(); |
199 | |
Object key; |
200 | 0 | while ( iter.hasNext() ) |
201 | |
{ |
202 | 0 | key = iter.next(); |
203 | |
|
204 | 0 | target.put( key, get( key ) ); |
205 | |
} |
206 | 0 | } |
207 | |
|
208 | |
|
209 | |
} |