1 package org.apache.maven.plugin.invoker;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.util.ArrayList;
24 import java.util.Arrays;
25 import java.util.Properties;
26
27 import org.apache.maven.shared.invoker.InvocationRequest;
28 import org.codehaus.plexus.util.StringUtils;
29
30
31
32
33
34
35
36 class InvokerProperties
37 {
38
39
40
41
42 private final Properties properties;
43
44
45
46
47 private static final String PROJECT = "invoker.project";
48
49
50
51
52 private static final String GOALS = "invoker.goals";
53
54
55
56
57 private static final String PROFILES = "invoker.profiles";
58
59
60
61
62 private static final String MAVEN_OPTS = "invoker.mavenOpts";
63
64
65
66
67 private static final String FAILURE_BEHAVIOR = "invoker.failureBehavior";
68
69
70
71
72 private static final String NON_RECURSIVE = "invoker.nonRecursive";
73
74
75
76
77 private static final String OFFLINE = "invoker.offline";
78
79
80
81
82 private static final String SYSTEM_PROPERTIES_FILE = "invoker.systemPropertiesFile";
83
84
85
86
87
88 private static final String DEBUG = "invoker.debug";
89
90
91
92
93
94
95
96 public InvokerProperties( Properties properties )
97 {
98 this.properties = ( properties != null ) ? properties : new Properties();
99 }
100
101
102
103
104
105
106 public Properties getProperties()
107 {
108 return this.properties;
109 }
110
111
112
113
114
115
116 public String getJobName()
117 {
118 return this.properties.getProperty( "invoker.name", "" );
119 }
120
121
122
123
124
125
126 public String getJobDescription()
127 {
128 return this.properties.getProperty( "invoker.description", "" );
129 }
130
131
132
133
134
135
136 public String getJreVersion()
137 {
138 return this.properties.getProperty( "invoker.java.version", "" );
139 }
140
141
142
143
144
145
146
147 public String getMavenVersion()
148 {
149 return this.properties.getProperty( "invoker.maven.version", "" );
150 }
151
152
153
154
155
156
157 public String getOsFamily()
158 {
159 return this.properties.getProperty( "invoker.os.family", "" );
160 }
161
162
163
164
165
166
167
168 public boolean isInvocationDefined( int index )
169 {
170 String[] keys =
171 { PROJECT, GOALS, PROFILES, MAVEN_OPTS, FAILURE_BEHAVIOR, NON_RECURSIVE, OFFLINE, SYSTEM_PROPERTIES_FILE, DEBUG };
172 for ( int i = 0; i < keys.length; i++ )
173 {
174 if ( properties.getProperty( keys[i] + '.' + index ) != null )
175 {
176 return true;
177 }
178 }
179 return false;
180 }
181
182
183
184
185
186
187
188
189 public void configureInvocation( InvocationRequest request, int index )
190 {
191 String project = get( PROJECT, index );
192 if ( project != null )
193 {
194 File file = new File( request.getBaseDirectory(), project );
195 if ( file.isFile() )
196 {
197 request.setBaseDirectory( file.getParentFile() );
198 request.setPomFile( file );
199 }
200 else
201 {
202 request.setBaseDirectory( file );
203 request.setPomFile( null );
204 }
205 }
206
207 String goals = get( GOALS, index );
208 if ( goals != null )
209 {
210 request.setGoals( new ArrayList<String>( Arrays.asList( StringUtils.split( goals, ", \t\n\r\f" ) ) ) );
211 }
212
213 String profiles = get( PROFILES, index );
214 if ( profiles != null )
215 {
216 request.setProfiles( new ArrayList<String>( Arrays.asList( StringUtils.split( profiles, ", \t\n\r\f" ) ) ) );
217 }
218
219 String mvnOpts = get( MAVEN_OPTS, index );
220 if ( mvnOpts != null )
221 {
222 request.setMavenOpts( mvnOpts );
223 }
224
225 String failureBehavior = get( FAILURE_BEHAVIOR, index );
226 if ( failureBehavior != null )
227 {
228 request.setFailureBehavior( failureBehavior );
229 }
230
231 String nonRecursive = get( NON_RECURSIVE, index );
232 if ( nonRecursive != null )
233 {
234 request.setRecursive( !Boolean.valueOf( nonRecursive ).booleanValue() );
235 }
236
237 String offline = get( OFFLINE, index );
238 if ( offline != null )
239 {
240 request.setOffline( Boolean.valueOf( offline ).booleanValue() );
241 }
242
243 String debug = get( DEBUG, index );
244 if ( debug != null )
245 {
246 request.setDebug( Boolean.valueOf( debug ).booleanValue() );
247 }
248 }
249
250
251
252
253
254
255
256
257
258 public boolean isExpectedResult( int exitCode, int index )
259 {
260 boolean nonZeroExit = "failure".equalsIgnoreCase( get( "invoker.buildResult", index ) );
261 return ( exitCode != 0 ) == nonZeroExit;
262 }
263
264
265
266
267
268
269
270 public String getSystemPropertiesFile( int index )
271 {
272 return get( SYSTEM_PROPERTIES_FILE, index );
273 }
274
275
276
277
278
279
280
281
282
283
284
285 String get( String key, int index )
286 {
287 if ( index < 0 )
288 {
289 throw new IllegalArgumentException( "invalid invocation index: " + index );
290 }
291
292 String value = properties.getProperty( key + '.' + index );
293 if ( value == null )
294 {
295 value = properties.getProperty( key );
296 }
297 return value;
298 }
299
300 }