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
89
90 public InvokerProperties( Properties properties )
91 {
92 this.properties = ( properties != null ) ? properties : new Properties();
93 }
94
95
96
97
98
99
100 public Properties getProperties()
101 {
102 return this.properties;
103 }
104
105
106
107
108
109
110 public String getJobName()
111 {
112 return this.properties.getProperty( "invoker.name", "" );
113 }
114
115
116
117
118
119
120 public String getJobDescription()
121 {
122 return this.properties.getProperty( "invoker.description", "" );
123 }
124
125
126
127
128
129
130 public String getJreVersion()
131 {
132 return this.properties.getProperty( "invoker.java.version", "" );
133 }
134
135
136
137
138
139
140 public String getOsFamily()
141 {
142 return this.properties.getProperty( "invoker.os.family", "" );
143 }
144
145
146
147
148
149
150
151 public boolean isInvocationDefined( int index )
152 {
153 String[] keys =
154 { PROJECT, GOALS, PROFILES, MAVEN_OPTS, FAILURE_BEHAVIOR, NON_RECURSIVE, OFFLINE, SYSTEM_PROPERTIES_FILE };
155 for ( int i = 0; i < keys.length; i++ )
156 {
157 if ( properties.getProperty( keys[i] + '.' + index ) != null )
158 {
159 return true;
160 }
161 }
162 return false;
163 }
164
165
166
167
168
169
170
171
172 public void configureInvocation( InvocationRequest request, int index )
173 {
174 String project = get( PROJECT, index );
175 if ( project != null )
176 {
177 File file = new File( request.getBaseDirectory(), project );
178 if ( file.isFile() )
179 {
180 request.setBaseDirectory( file.getParentFile() );
181 request.setPomFile( file );
182 }
183 else
184 {
185 request.setBaseDirectory( file );
186 request.setPomFile( null );
187 }
188 }
189
190 String goals = get( GOALS, index );
191 if ( goals != null )
192 {
193 request.setGoals( new ArrayList( Arrays.asList( StringUtils.split( goals, ", \t\n\r\f" ) ) ) );
194 }
195
196 String profiles = get( PROFILES, index );
197 if ( profiles != null )
198 {
199 request.setProfiles( new ArrayList( Arrays.asList( StringUtils.split( profiles, ", \t\n\r\f" ) ) ) );
200 }
201
202 String mvnOpts = get( MAVEN_OPTS, index );
203 if ( mvnOpts != null )
204 {
205 request.setMavenOpts( mvnOpts );
206 }
207
208 String failureBehavior = get( FAILURE_BEHAVIOR, index );
209 if ( failureBehavior != null )
210 {
211 request.setFailureBehavior( failureBehavior );
212 }
213
214 String nonRecursive = get( NON_RECURSIVE, index );
215 if ( nonRecursive != null )
216 {
217 request.setRecursive( !Boolean.valueOf( nonRecursive ).booleanValue() );
218 }
219
220 String offline = get( OFFLINE, index );
221 if ( offline != null )
222 {
223 request.setOffline( Boolean.valueOf( offline ).booleanValue() );
224 }
225 }
226
227
228
229
230
231
232
233
234
235 public boolean isExpectedResult( int exitCode, int index )
236 {
237 boolean nonZeroExit = "failure".equalsIgnoreCase( get( "invoker.buildResult", index ) );
238 return ( exitCode != 0 ) == nonZeroExit;
239 }
240
241
242
243
244
245
246
247 public String getSystemPropertiesFile( int index )
248 {
249 return get( SYSTEM_PROPERTIES_FILE, index );
250 }
251
252
253
254
255
256
257
258
259
260
261
262 String get( String key, int index )
263 {
264 if ( index < 0 )
265 {
266 throw new IllegalArgumentException( "invalid invocation index: " + index );
267 }
268
269 String value = properties.getProperty( key + '.' + index );
270 if ( value == null )
271 {
272 value = properties.getProperty( key );
273 }
274 return value;
275 }
276
277 }