View Javadoc
1   package org.apache.maven.shared.invoker;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.io.InputStream;
24  import java.util.Collections;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  import java.util.Properties;
29  
30  /**
31   * Specifies the parameters used to control a Maven invocation.
32   * 
33   * @version $Id: DefaultInvocationRequest.java 1666746 2015-03-14 21:06:58Z rfscholte $
34   */
35  public class DefaultInvocationRequest
36      implements InvocationRequest
37  {
38  
39      private File basedir;
40  
41      private boolean debug;
42  
43      private InvocationOutputHandler errorHandler;
44  
45      private String failureBehavior = REACTOR_FAIL_FAST;
46  
47      private List<String> goals;
48  
49      private InputStream inputStream;
50  
51      private boolean interactive;
52  
53      private File localRepository;
54  
55      private boolean offline;
56  
57      private boolean recursive = true;
58  
59      private InvocationOutputHandler outputHandler;
60  
61      private File pomFile;
62  
63      private Properties properties;
64  
65      private boolean showErrors;
66  
67      private boolean updateSnapshots;
68  
69      private boolean shellEnvironmentInherited = true;
70  
71      private File userSettings;
72  
73      private File globalSettings;
74      
75      private File toolchains;
76  
77      private String globalChecksumPolicy;
78  
79      private String pomFilename;
80  
81      private File javaHome;
82  
83      private List<String> profiles;
84  
85      private boolean nonPluginUpdates;
86  
87      private Map<String, String> shellEnvironments;
88  
89      private String mavenOpts;
90      
91      private boolean activatedReactor;
92  
93      private String[] activatedReactorIncludes, activatedReactorExcludes;
94      
95      private List<String> projects;
96  
97      private boolean alsoMake;
98  
99      private boolean alsoMakeDependents;
100 
101     private String resumeFrom;
102 
103     private boolean showVersion;
104 
105     private String threads;
106 
107     public InvocationRequest activateReactor( String[] includes, String[] excludes )
108     {
109         activatedReactor = true;
110         activatedReactorIncludes = includes;
111         activatedReactorExcludes = excludes;
112         return this;
113     }
114 
115     public File getBaseDirectory()
116     {
117         return basedir;
118     }
119 
120     public File getBaseDirectory( File defaultDirectory )
121     {
122         return basedir == null ? defaultDirectory : basedir;
123     }
124 
125     public InvocationOutputHandler getErrorHandler( InvocationOutputHandler defaultHandler )
126     {
127         return errorHandler == null ? defaultHandler : errorHandler;
128     }
129 
130     public String getFailureBehavior()
131     {
132         return failureBehavior;
133     }
134 
135     public List<String> getGoals()
136     {
137         return goals;
138     }
139 
140     public InputStream getInputStream( InputStream defaultStream )
141     {
142         return inputStream == null ? defaultStream : inputStream;
143     }
144 
145     public File getLocalRepositoryDirectory( File defaultDirectory )
146     {
147         return localRepository == null ? defaultDirectory : localRepository;
148     }
149 
150     public InvocationOutputHandler getOutputHandler( InvocationOutputHandler defaultHandler )
151     {
152         return outputHandler == null ? defaultHandler : outputHandler;
153     }
154 
155     public File getPomFile()
156     {
157         return pomFile;
158     }
159 
160     public Properties getProperties()
161     {
162         return properties;
163     }
164 
165     public boolean isDebug()
166     {
167         return debug;
168     }
169 
170     public boolean isInteractive()
171     {
172         return interactive;
173     }
174 
175     public boolean isOffline()
176     {
177         return offline;
178     }
179 
180     public boolean isShowErrors()
181     {
182         return showErrors;
183     }
184 
185     public boolean isUpdateSnapshots()
186     {
187         return updateSnapshots;
188     }
189 
190     public boolean isRecursive()
191     {
192         return recursive;
193     }
194 
195     public InvocationRequest setRecursive( boolean recursive )
196     {
197         this.recursive = recursive;
198         return this;
199     }
200 
201     public InvocationRequest setBaseDirectory( File basedir )
202     {
203         this.basedir = basedir;
204         return this;
205     }
206 
207     public InvocationRequest setDebug( boolean debug )
208     {
209         this.debug = debug;
210         return this;
211     }
212 
213     public InvocationRequest setErrorHandler( InvocationOutputHandler errorHandler )
214     {
215         this.errorHandler = errorHandler;
216         return this;
217     }
218 
219     public InvocationRequest setFailureBehavior( String failureBehavior )
220     {
221         this.failureBehavior = failureBehavior;
222         return this;
223     }
224 
225     public InvocationRequest setGoals( List<String> goals )
226     {
227         this.goals = goals;
228         return this;
229     }
230 
231     public InvocationRequest setInputStream( InputStream inputStream )
232     {
233         this.inputStream = inputStream;
234         return this;
235     }
236 
237     public InvocationRequest setInteractive( boolean interactive )
238     {
239         this.interactive = interactive;
240         return this;
241     }
242 
243     public InvocationRequest setLocalRepositoryDirectory( File localRepository )
244     {
245         this.localRepository = localRepository;
246         return this;
247     }
248 
249     public InvocationRequest setOffline( boolean offline )
250     {
251         this.offline = offline;
252         return this;
253     }
254 
255     public InvocationRequest setOutputHandler( InvocationOutputHandler outputHandler )
256     {
257         this.outputHandler = outputHandler;
258         return this;
259     }
260 
261     public InvocationRequest setPomFile( File pomFile )
262     {
263         this.pomFile = pomFile;
264         return this;
265     }
266 
267     public InvocationRequest setProperties( Properties properties )
268     {
269         this.properties = properties;
270         return this;
271     }
272 
273     public InvocationRequest setShowErrors( boolean showErrors )
274     {
275         this.showErrors = showErrors;
276         return this;
277     }
278 
279     public InvocationRequest setUpdateSnapshots( boolean updateSnapshots )
280     {
281         this.updateSnapshots = updateSnapshots;
282         return this;
283     }
284 
285     /**
286      * @see MavenCommandLineBuilder#setShellEnvironment(InvocationRequest, org.codehaus.plexus.util.cli.Commandline)
287      */
288     public boolean isShellEnvironmentInherited()
289     {
290         return shellEnvironmentInherited;
291     }
292 
293     public InvocationRequest setShellEnvironmentInherited( boolean shellEnvironmentInherited )
294     {
295         this.shellEnvironmentInherited = shellEnvironmentInherited;
296         return this;
297     }
298 
299     public File getJavaHome()
300     {
301         return javaHome;
302     }
303 
304     public InvocationRequest setJavaHome( File javaHome )
305     {
306         this.javaHome = javaHome;
307         return this;
308     }
309 
310     public File getUserSettingsFile()
311     {
312         return userSettings;
313     }
314     
315     public InvocationRequest setUserSettingsFile( File userSettings )
316     {
317         this.userSettings = userSettings;
318         return this;
319     }
320 
321     public File getGlobalSettingsFile()
322     {
323         return globalSettings;
324     }
325 
326     public InvocationRequest setGlobalSettingsFile( File globalSettings )
327     {
328         this.globalSettings = globalSettings;
329         return this;
330     }
331 
332     public File getToolchainsFile()
333     {
334         return toolchains;
335     }
336     
337     public InvocationRequest setToolchainsFile( File toolchains )
338     {
339         this.toolchains = toolchains;
340         return this;
341     }
342     
343     public String getGlobalChecksumPolicy()
344     {
345         return globalChecksumPolicy;
346     }
347 
348     public InvocationRequest setGlobalChecksumPolicy( String globalChecksumPolicy )
349     {
350         this.globalChecksumPolicy = globalChecksumPolicy;
351         return this;
352     }
353 
354     public String getPomFileName()
355     {
356         return pomFilename;
357     }
358 
359     public InvocationRequest setPomFileName( String pomFilename )
360     {
361         this.pomFilename = pomFilename;
362         return this;
363     }
364 
365     public List<String> getProfiles()
366     {
367         return profiles;
368     }
369 
370     public InvocationRequest setProfiles( List<String> profiles )
371     {
372         this.profiles = profiles;
373         return this;
374     }
375 
376     public boolean isNonPluginUpdates()
377     {
378         return nonPluginUpdates;
379     }
380 
381     public InvocationRequest setNonPluginUpdates( boolean nonPluginUpdates )
382     {
383         this.nonPluginUpdates = nonPluginUpdates;
384         return this;
385     }
386 
387     public InvocationRequest addShellEnvironment( String name, String value )
388     {
389         if ( this.shellEnvironments == null )
390         {
391             this.shellEnvironments = new HashMap<String, String>();
392         }
393         this.shellEnvironments.put( name, value );
394         return this;
395     }
396 
397     public Map<String, String> getShellEnvironments()
398     {
399         return shellEnvironments == null ? Collections.<String, String>emptyMap() : shellEnvironments;
400     }
401 
402     public String getMavenOpts()
403     {
404         return mavenOpts;
405     }
406 
407     public InvocationRequest setMavenOpts( String mavenOpts )
408     {
409         this.mavenOpts = mavenOpts;
410         return this;
411     }
412     
413     public boolean isActivatedReactor()
414     {
415         return activatedReactor;
416     }
417 
418     public String[] getActivatedReactorIncludes()
419     {
420         return activatedReactorIncludes;
421     }
422 
423     public String[] getActivatedReactorExcludes()
424     {
425         return activatedReactorExcludes;
426     }
427 
428     /**
429      * @see org.apache.maven.shared.invoker.InvocationRequest#isShowVersion()
430      */
431     public boolean isShowVersion()
432     {
433         return this.showVersion;
434     }
435 
436     /**
437      * @see org.apache.maven.shared.invoker.InvocationRequest#setShowVersion(boolean)
438      */
439     public InvocationRequest setShowVersion( boolean showVersion )
440     {
441         this.showVersion = showVersion;
442         return this;
443     }
444     
445     /**
446      * {@inheritDoc}
447      */
448     public String getThreads()
449     {
450         return threads;
451     }
452     
453     /**
454      * {@inheritDoc}
455      */
456     public InvocationRequest setThreads( String threads )
457     {
458         this.threads = threads;
459         return this;
460     }
461 
462     /**
463      * {@inheritDoc}
464      */
465     public List<String> getProjects()
466     {
467         return projects;
468     }
469 
470     /**
471      * {@inheritDoc}
472      */
473     public InvocationRequest setProjects( List<String> projects )
474     {
475         this.projects = projects;
476         return this;
477     }
478 
479     /**
480      * {@inheritDoc}
481      */
482     public boolean isAlsoMake()
483     {
484         return alsoMake;
485     }
486 
487     /**
488      * {@inheritDoc}
489      */
490     public InvocationRequest setAlsoMake( boolean alsoMake )
491     {
492         this.alsoMake = alsoMake;
493         return this;
494     }
495 
496     /**
497      * {@inheritDoc}
498      */
499     public boolean isAlsoMakeDependents()
500     {
501         return alsoMakeDependents;
502     }
503 
504     /**
505      * {@inheritDoc}
506      */
507     public InvocationRequest setAlsoMakeDependents( boolean alsoMakeDependents )
508     {
509         this.alsoMakeDependents = alsoMakeDependents;
510         return this;
511     }
512 
513     /**
514      * {@inheritDoc}
515      */
516     public String getResumeFrom()
517     {
518         return resumeFrom;
519     }
520 
521     /**
522      * {@inheritDoc}
523      */
524     public InvocationRequest setResumeFrom( String resumeFrom )
525     {
526         this.resumeFrom = resumeFrom;
527         return this;
528     }
529     
530 }