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