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 1752078 2016-07-10 11:25:08Z khmarbaise $
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 ReactorFailureBehavior failureBehavior = ReactorFailureBehavior.FailFast;
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 File globalToolchains;
78  
79      private CheckSumPolicy globalChecksumPolicy;
80  
81      private String pomFilename;
82  
83      private File javaHome;
84  
85      private List<String> profiles;
86  
87      private boolean nonPluginUpdates;
88  
89      private Map<String, String> shellEnvironments;
90  
91      private String mavenOpts;
92  
93      private List<String> projects;
94  
95      private boolean alsoMake;
96  
97      private boolean alsoMakeDependents;
98  
99      private String resumeFrom;
100 
101     private boolean showVersion;
102 
103     private String threads;
104 
105     private String builderId;
106 
107     public File getBaseDirectory()
108     {
109         return basedir;
110     }
111 
112     public File getBaseDirectory( File defaultDirectory )
113     {
114         return basedir == null ? defaultDirectory : basedir;
115     }
116 
117     public InvocationOutputHandler getErrorHandler( InvocationOutputHandler defaultHandler )
118     {
119         return errorHandler == null ? defaultHandler : errorHandler;
120     }
121 
122     public ReactorFailureBehavior getReactorFailureBehavior()
123     {
124         return failureBehavior;
125     }
126 
127     public List<String> getGoals()
128     {
129         return goals;
130     }
131 
132     public InputStream getInputStream( InputStream defaultStream )
133     {
134         return inputStream == null ? defaultStream : inputStream;
135     }
136 
137     public File getLocalRepositoryDirectory( File defaultDirectory )
138     {
139         return localRepository == null ? defaultDirectory : localRepository;
140     }
141 
142     public InvocationOutputHandler getOutputHandler( InvocationOutputHandler defaultHandler )
143     {
144         return outputHandler == null ? defaultHandler : outputHandler;
145     }
146 
147     public File getPomFile()
148     {
149         return pomFile;
150     }
151 
152     public Properties getProperties()
153     {
154         return properties;
155     }
156 
157     public boolean isDebug()
158     {
159         return debug;
160     }
161 
162     public boolean isBatchMode()
163     {
164         return interactive;
165     }
166 
167     public boolean isOffline()
168     {
169         return offline;
170     }
171 
172     public boolean isShowErrors()
173     {
174         return showErrors;
175     }
176 
177     public boolean isUpdateSnapshots()
178     {
179         return updateSnapshots;
180     }
181 
182     public boolean isRecursive()
183     {
184         return recursive;
185     }
186 
187     public InvocationRequest setRecursive( boolean recursive )
188     {
189         this.recursive = recursive;
190         return this;
191     }
192 
193     public InvocationRequest setBaseDirectory( File basedir )
194     {
195         this.basedir = basedir;
196         return this;
197     }
198 
199     public InvocationRequest setDebug( boolean debug )
200     {
201         this.debug = debug;
202         return this;
203     }
204 
205     public InvocationRequest setErrorHandler( InvocationOutputHandler errorHandler )
206     {
207         this.errorHandler = errorHandler;
208         return this;
209     }
210 
211     public InvocationRequest setReactorFailureBehavior( ReactorFailureBehavior failureBehavior )
212     {
213         this.failureBehavior = failureBehavior;
214         return this;
215     }
216 
217     public InvocationRequest setGoals( List<String> goals )
218     {
219         this.goals = goals;
220         return this;
221     }
222 
223     public InvocationRequest setInputStream( InputStream inputStream )
224     {
225         this.inputStream = inputStream;
226         return this;
227     }
228 
229     public InvocationRequest setBatchMode( boolean interactive )
230     {
231         this.interactive = interactive;
232         return this;
233     }
234 
235     public InvocationRequest setLocalRepositoryDirectory( File localRepository )
236     {
237         this.localRepository = localRepository;
238         return this;
239     }
240 
241     public InvocationRequest setOffline( boolean offline )
242     {
243         this.offline = offline;
244         return this;
245     }
246 
247     public InvocationRequest setOutputHandler( InvocationOutputHandler outputHandler )
248     {
249         this.outputHandler = outputHandler;
250         return this;
251     }
252 
253     public InvocationRequest setPomFile( File pomFile )
254     {
255         this.pomFile = pomFile;
256         return this;
257     }
258 
259     public InvocationRequest setProperties( Properties properties )
260     {
261         this.properties = properties;
262         return this;
263     }
264 
265     public InvocationRequest setShowErrors( boolean showErrors )
266     {
267         this.showErrors = showErrors;
268         return this;
269     }
270 
271     public InvocationRequest setUpdateSnapshots( boolean updateSnapshots )
272     {
273         this.updateSnapshots = updateSnapshots;
274         return this;
275     }
276 
277     /**
278      * @see MavenCommandLineBuilder#setShellEnvironment(InvocationRequest, org.codehaus.plexus.util.cli.Commandline)
279      */
280     public boolean isShellEnvironmentInherited()
281     {
282         return shellEnvironmentInherited;
283     }
284 
285     public InvocationRequest setShellEnvironmentInherited( boolean shellEnvironmentInherited )
286     {
287         this.shellEnvironmentInherited = shellEnvironmentInherited;
288         return this;
289     }
290 
291     public File getJavaHome()
292     {
293         return javaHome;
294     }
295 
296     /**
297      * {@inheritDoc}
298      */
299     public InvocationRequest setJavaHome( File javaHome )
300     {
301         this.javaHome = javaHome;
302         return this;
303     }
304 
305     /**
306      * {@inheritDoc}
307      */
308     public File getUserSettingsFile()
309     {
310         return userSettings;
311     }
312 
313     /**
314      * {@inheritDoc}
315      */
316     public InvocationRequest setUserSettingsFile( File userSettings )
317     {
318         this.userSettings = userSettings;
319         return this;
320     }
321 
322     /**
323      * {@inheritDoc}
324      */
325     public File getGlobalSettingsFile()
326     {
327         return globalSettings;
328     }
329 
330     /**
331      * {@inheritDoc}
332      */
333     public InvocationRequest setGlobalSettingsFile( File globalSettings )
334     {
335         this.globalSettings = globalSettings;
336         return this;
337     }
338 
339     /**
340      * {@inheritDoc}
341      */
342     public File getToolchainsFile()
343     {
344         return toolchains;
345     }
346 
347     /**
348      * {@inheritDoc}
349      */
350     public InvocationRequest setToolchainsFile( File toolchains )
351     {
352         this.toolchains = toolchains;
353         return this;
354     }
355 
356     /**
357      * {@inheritDoc}
358      */
359     public File getGlobalToolchainsFile()
360     {
361         return globalToolchains;
362     }
363 
364     /**
365      * {@inheritDoc}
366      */
367     public InvocationRequest setGlobalToolchainsFile( File toolchains )
368     {
369         this.globalToolchains = toolchains;
370         return this;
371     }
372 
373 
374     /**
375      * {@inheritDoc}
376      */
377     public CheckSumPolicy getGlobalChecksumPolicy()
378     {
379         return globalChecksumPolicy;
380     }
381 
382     /**
383      * {@inheritDoc}
384      */
385     public InvocationRequest setGlobalChecksumPolicy( CheckSumPolicy globalChecksumPolicy )
386     {
387         this.globalChecksumPolicy = globalChecksumPolicy;
388         return this;
389     }
390 
391     /**
392      * {@inheritDoc}
393      */
394     public String getPomFileName()
395     {
396         return pomFilename;
397     }
398 
399     /**
400      * {@inheritDoc}
401      */
402     public InvocationRequest setPomFileName( String pomFilename )
403     {
404         this.pomFilename = pomFilename;
405         return this;
406     }
407 
408     /**
409      * {@inheritDoc}
410      */
411     public List<String> getProfiles()
412     {
413         return profiles;
414     }
415 
416     /**
417      * {@inheritDoc}
418      */
419     public InvocationRequest setProfiles( List<String> profiles )
420     {
421         this.profiles = profiles;
422         return this;
423     }
424 
425     /**
426      * {@inheritDoc}
427      */
428     public boolean isNonPluginUpdates()
429     {
430         return nonPluginUpdates;
431     }
432 
433     /**
434      * {@inheritDoc}
435      */
436     public InvocationRequest setNonPluginUpdates( boolean nonPluginUpdates )
437     {
438         this.nonPluginUpdates = nonPluginUpdates;
439         return this;
440     }
441 
442     public InvocationRequest addShellEnvironment( String name, String value )
443     {
444         if ( this.shellEnvironments == null )
445         {
446             this.shellEnvironments = new HashMap<String, String>();
447         }
448         this.shellEnvironments.put( name, value );
449         return this;
450     }
451 
452     public Map<String, String> getShellEnvironments()
453     {
454         return shellEnvironments == null ? Collections.<String, String>emptyMap() : shellEnvironments;
455     }
456 
457     public String getMavenOpts()
458     {
459         return mavenOpts;
460     }
461 
462     public InvocationRequest setMavenOpts( String mavenOpts )
463     {
464         this.mavenOpts = mavenOpts;
465         return this;
466     }
467 
468     /**
469      * @see org.apache.maven.shared.invoker.InvocationRequest#isShowVersion()
470      */
471     public boolean isShowVersion()
472     {
473         return this.showVersion;
474     }
475 
476     /**
477      * @see org.apache.maven.shared.invoker.InvocationRequest#setShowVersion(boolean)
478      */
479     public InvocationRequest setShowVersion( boolean showVersion )
480     {
481         this.showVersion = showVersion;
482         return this;
483     }
484 
485     /**
486      * {@inheritDoc}
487      */
488     public String getThreads()
489     {
490         return threads;
491     }
492 
493     /**
494      * {@inheritDoc}
495      */
496     public InvocationRequest setThreads( String threads )
497     {
498         this.threads = threads;
499         return this;
500     }
501 
502     /**
503      * {@inheritDoc}
504      */
505     public List<String> getProjects()
506     {
507         return projects;
508     }
509 
510     /**
511      * {@inheritDoc}
512      */
513     public InvocationRequest setProjects( List<String> projects )
514     {
515         this.projects = projects;
516         return this;
517     }
518 
519     /**
520      * {@inheritDoc}
521      */
522     public boolean isAlsoMake()
523     {
524         return alsoMake;
525     }
526 
527     /**
528      * {@inheritDoc}
529      */
530     public InvocationRequest setAlsoMake( boolean alsoMake )
531     {
532         this.alsoMake = alsoMake;
533         return this;
534     }
535 
536     /**
537      * {@inheritDoc}
538      */
539     public boolean isAlsoMakeDependents()
540     {
541         return alsoMakeDependents;
542     }
543 
544     /**
545      * {@inheritDoc}
546      */
547     public InvocationRequest setAlsoMakeDependents( boolean alsoMakeDependents )
548     {
549         this.alsoMakeDependents = alsoMakeDependents;
550         return this;
551     }
552 
553     /**
554      * {@inheritDoc}
555      */
556     public String getResumeFrom()
557     {
558         return resumeFrom;
559     }
560 
561     /**
562      * {@inheritDoc}
563      */
564     public InvocationRequest setResumeFrom( String resumeFrom )
565     {
566         this.resumeFrom = resumeFrom;
567         return this;
568     }
569 
570     /**
571      * {@inheritDoc}
572      */
573     public InvocationRequest setBuilder( String id )
574     {
575         this.builderId = id;
576         return this;
577     }
578 
579     /**
580      * {@inheritDoc}
581      */
582     public String getBuilder()
583     {
584         return this.builderId;
585     }
586 
587 }