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   */
34  public class DefaultInvocationRequest
35      implements InvocationRequest
36  {
37  
38      private File basedir;
39  
40      private boolean debug;
41  
42      private InvocationOutputHandler errorHandler;
43  
44      private ReactorFailureBehavior failureBehavior = ReactorFailureBehavior.FailFast;
45  
46      private List<String> goals;
47  
48      private InputStream inputStream;
49  
50      private boolean interactive;
51  
52      private File localRepository;
53  
54      private boolean offline;
55  
56      private boolean recursive = true;
57  
58      private InvocationOutputHandler outputHandler;
59  
60      private File pomFile;
61  
62      private Properties properties;
63  
64      private boolean showErrors;
65  
66      private boolean updateSnapshots;
67  
68      private boolean shellEnvironmentInherited = true;
69  
70      private File userSettings;
71  
72      private File globalSettings;
73  
74      private File toolchains;
75  
76      private File globalToolchains;
77  
78      private CheckSumPolicy globalChecksumPolicy;
79  
80      private String pomFilename;
81  
82      private File javaHome;
83  
84      private List<String> profiles;
85  
86      private boolean nonPluginUpdates;
87  
88      private Map<String, String> shellEnvironments;
89  
90      private String mavenOpts;
91  
92      private List<String> projects;
93  
94      private boolean alsoMake;
95  
96      private boolean alsoMakeDependents;
97  
98      private String resumeFrom;
99  
100     private boolean showVersion;
101 
102     private String threads;
103 
104     private String builderId;
105 
106     private int timeoutInSeconds = NO_TIMEOUT;
107 
108     private boolean quiet;
109 
110     /**
111      * <p>getBaseDirectory.</p>
112      *
113      * @return a {@link java.io.File} object.
114      */
115     public File getBaseDirectory()
116     {
117         return basedir;
118     }
119 
120     /** {@inheritDoc} */
121     public File getBaseDirectory( File defaultDirectory )
122     {
123         return basedir == null ? defaultDirectory : basedir;
124     }
125 
126     /** {@inheritDoc} */
127     public InvocationOutputHandler getErrorHandler( InvocationOutputHandler defaultHandler )
128     {
129         return errorHandler == null ? defaultHandler : errorHandler;
130     }
131 
132     /**
133      * <p>getReactorFailureBehavior.</p>
134      *
135      * @return a ReactorFailureBehavior object.
136      */
137     public ReactorFailureBehavior getReactorFailureBehavior()
138     {
139         return failureBehavior;
140     }
141 
142     /**
143      * <p>Getter for the field <code>goals</code>.</p>
144      *
145      * @return a {@link java.util.List} object.
146      */
147     public List<String> getGoals()
148     {
149         return goals;
150     }
151 
152     /** {@inheritDoc} */
153     public InputStream getInputStream( InputStream defaultStream )
154     {
155         return inputStream == null ? defaultStream : inputStream;
156     }
157 
158     /** {@inheritDoc} */
159     public File getLocalRepositoryDirectory( File defaultDirectory )
160     {
161         return localRepository == null ? defaultDirectory : localRepository;
162     }
163 
164     /** {@inheritDoc} */
165     public InvocationOutputHandler getOutputHandler( InvocationOutputHandler defaultHandler )
166     {
167         return outputHandler == null ? defaultHandler : outputHandler;
168     }
169 
170     /**
171      * <p>Getter for the field <code>pomFile</code>.</p>
172      *
173      * @return a {@link java.io.File} object.
174      */
175     public File getPomFile()
176     {
177         return pomFile;
178     }
179 
180     /**
181      * <p>Getter for the field <code>properties</code>.</p>
182      *
183      * @return a {@link java.util.Properties} object.
184      */
185     public Properties getProperties()
186     {
187         return properties;
188     }
189 
190     /**
191      * <p>isDebug.</p>
192      *
193      * @return a boolean.
194      */
195     public boolean isDebug()
196     {
197         return debug;
198     }
199 
200     /**
201      * <p>isBatchMode.</p>
202      *
203      * @return a boolean.
204      */
205     public boolean isBatchMode()
206     {
207         return interactive;
208     }
209 
210     /**
211      * <p>isOffline.</p>
212      *
213      * @return a boolean.
214      */
215     public boolean isOffline()
216     {
217         return offline;
218     }
219 
220     /**
221      * <p>isShowErrors.</p>
222      *
223      * @return a boolean.
224      */
225     public boolean isShowErrors()
226     {
227         return showErrors;
228     }
229 
230     /**
231      * <p>isUpdateSnapshots.</p>
232      *
233      * @return a boolean.
234      */
235     public boolean isUpdateSnapshots()
236     {
237         return updateSnapshots;
238     }
239 
240     /**
241      * <p>isRecursive.</p>
242      *
243      * @return a boolean.
244      */
245     public boolean isRecursive()
246     {
247         return recursive;
248     }
249 
250     /** {@inheritDoc} */
251     public InvocationRequest setRecursive( boolean recursive )
252     {
253         this.recursive = recursive;
254         return this;
255     }
256 
257     /** {@inheritDoc} */
258     public InvocationRequest setBaseDirectory( File basedir )
259     {
260         this.basedir = basedir;
261         return this;
262     }
263 
264     /** {@inheritDoc} */
265     public InvocationRequest setDebug( boolean debug )
266     {
267         this.debug = debug;
268         return this;
269     }
270 
271     /** {@inheritDoc} */
272     public InvocationRequest setErrorHandler( InvocationOutputHandler errorHandler )
273     {
274         this.errorHandler = errorHandler;
275         return this;
276     }
277 
278     /**
279      * <p>setReactorFailureBehavior.</p>
280      *
281      * @param failureBehavior a ReactorFailureBehavior object.
282      * @return a {@link org.apache.maven.shared.invoker.InvocationRequest} object.
283      */
284     public InvocationRequest setReactorFailureBehavior( ReactorFailureBehavior failureBehavior )
285     {
286         this.failureBehavior = failureBehavior;
287         return this;
288     }
289 
290     /** {@inheritDoc} */
291     public InvocationRequest setGoals( List<String> goals )
292     {
293         this.goals = goals;
294         return this;
295     }
296 
297     /** {@inheritDoc} */
298     public InvocationRequest setInputStream( InputStream inputStream )
299     {
300         this.inputStream = inputStream;
301         return this;
302     }
303 
304     /** {@inheritDoc} */
305     public InvocationRequest setBatchMode( boolean interactive )
306     {
307         this.interactive = interactive;
308         return this;
309     }
310 
311     /** {@inheritDoc} */
312     public InvocationRequest setLocalRepositoryDirectory( File localRepository )
313     {
314         this.localRepository = localRepository;
315         return this;
316     }
317 
318     /** {@inheritDoc} */
319     public InvocationRequest setOffline( boolean offline )
320     {
321         this.offline = offline;
322         return this;
323     }
324 
325     /** {@inheritDoc} */
326     public InvocationRequest setOutputHandler( InvocationOutputHandler outputHandler )
327     {
328         this.outputHandler = outputHandler;
329         return this;
330     }
331 
332     /** {@inheritDoc} */
333     public InvocationRequest setPomFile( File pomFile )
334     {
335         this.pomFile = pomFile;
336         return this;
337     }
338 
339     /** {@inheritDoc} */
340     public InvocationRequest setProperties( Properties properties )
341     {
342         this.properties = properties;
343         return this;
344     }
345 
346     /** {@inheritDoc} */
347     public InvocationRequest setShowErrors( boolean showErrors )
348     {
349         this.showErrors = showErrors;
350         return this;
351     }
352 
353     /** {@inheritDoc} */
354     public InvocationRequest setUpdateSnapshots( boolean updateSnapshots )
355     {
356         this.updateSnapshots = updateSnapshots;
357         return this;
358     }
359 
360     /**
361      * <p>isShellEnvironmentInherited.</p>
362      *
363      * @see MavenCommandLineBuilder#setShellEnvironment(InvocationRequest, Commandline)
364      * @return a boolean.
365      */
366     public boolean isShellEnvironmentInherited()
367     {
368         return shellEnvironmentInherited;
369     }
370 
371     /** {@inheritDoc} */
372     public InvocationRequest setShellEnvironmentInherited( boolean shellEnvironmentInherited )
373     {
374         this.shellEnvironmentInherited = shellEnvironmentInherited;
375         return this;
376     }
377 
378     /**
379      * <p>Getter for the field <code>javaHome</code>.</p>
380      *
381      * @return a {@link java.io.File} object.
382      */
383     public File getJavaHome()
384     {
385         return javaHome;
386     }
387 
388     /** {@inheritDoc} */
389     public InvocationRequest setJavaHome( File javaHome )
390     {
391         this.javaHome = javaHome;
392         return this;
393     }
394 
395     /**
396      * {@inheritDoc}
397      *
398      * @return a {@link java.io.File} object.
399      */
400     public File getUserSettingsFile()
401     {
402         return userSettings;
403     }
404 
405     /** {@inheritDoc} */
406     public InvocationRequest setUserSettingsFile( File userSettings )
407     {
408         this.userSettings = userSettings;
409         return this;
410     }
411 
412     /**
413      * {@inheritDoc}
414      *
415      * @return a {@link java.io.File} object.
416      */
417     public File getGlobalSettingsFile()
418     {
419         return globalSettings;
420     }
421 
422     /** {@inheritDoc} */
423     public InvocationRequest setGlobalSettingsFile( File globalSettings )
424     {
425         this.globalSettings = globalSettings;
426         return this;
427     }
428 
429     /**
430      * {@inheritDoc}
431      *
432      * @return a {@link java.io.File} object.
433      */
434     public File getToolchainsFile()
435     {
436         return toolchains;
437     }
438 
439     /** {@inheritDoc} */
440     public InvocationRequest setToolchainsFile( File toolchains )
441     {
442         this.toolchains = toolchains;
443         return this;
444     }
445 
446     /**
447      * {@inheritDoc}
448      *
449      * @return a {@link java.io.File} object.
450      */
451     public File getGlobalToolchainsFile()
452     {
453         return globalToolchains;
454     }
455 
456     /** {@inheritDoc} */
457     public InvocationRequest setGlobalToolchainsFile( File toolchains )
458     {
459         this.globalToolchains = toolchains;
460         return this;
461     }
462 
463 
464     /**
465      * {@inheritDoc}
466      *
467      * @return a CheckSumPolicy object.
468      */
469     public CheckSumPolicy getGlobalChecksumPolicy()
470     {
471         return globalChecksumPolicy;
472     }
473 
474     /**
475      * {@inheritDoc}
476      *
477      * @param globalChecksumPolicy a CheckSumPolicy object.
478      * @return a {@link org.apache.maven.shared.invoker.InvocationRequest} object.
479      */
480     public InvocationRequest setGlobalChecksumPolicy( CheckSumPolicy globalChecksumPolicy )
481     {
482         this.globalChecksumPolicy = globalChecksumPolicy;
483         return this;
484     }
485 
486     /**
487      * {@inheritDoc}
488      *
489      * @return a {@link java.lang.String} object.
490      */
491     public String getPomFileName()
492     {
493         return pomFilename;
494     }
495 
496     /** {@inheritDoc} */
497     public InvocationRequest setPomFileName( String pomFilename )
498     {
499         this.pomFilename = pomFilename;
500         return this;
501     }
502 
503     /**
504      * {@inheritDoc}
505      *
506      * @return a {@link java.util.List} object.
507      */
508     public List<String> getProfiles()
509     {
510         return profiles;
511     }
512 
513     /** {@inheritDoc} */
514     public InvocationRequest setProfiles( List<String> profiles )
515     {
516         this.profiles = profiles;
517         return this;
518     }
519 
520     /**
521      * {@inheritDoc}
522      *
523      * @return a boolean.
524      */
525     public boolean isNonPluginUpdates()
526     {
527         return nonPluginUpdates;
528     }
529 
530     /** {@inheritDoc} */
531     public InvocationRequest setNonPluginUpdates( boolean nonPluginUpdates )
532     {
533         this.nonPluginUpdates = nonPluginUpdates;
534         return this;
535     }
536 
537     /** {@inheritDoc} */
538     public InvocationRequest addShellEnvironment( String name, String value )
539     {
540         if ( this.shellEnvironments == null )
541         {
542             this.shellEnvironments = new HashMap<>();
543         }
544         this.shellEnvironments.put( name, value );
545         return this;
546     }
547 
548     /**
549      * <p>Getter for the field <code>shellEnvironments</code>.</p>
550      *
551      * @return a {@link java.util.Map} object.
552      */
553     public Map<String, String> getShellEnvironments()
554     {
555         return shellEnvironments == null ? Collections.<String, String>emptyMap() : shellEnvironments;
556     }
557 
558     /**
559      * <p>Getter for the field <code>mavenOpts</code>.</p>
560      *
561      * @return a {@link java.lang.String} object.
562      */
563     public String getMavenOpts()
564     {
565         return mavenOpts;
566     }
567 
568     /** {@inheritDoc} */
569     public InvocationRequest setMavenOpts( String mavenOpts )
570     {
571         this.mavenOpts = mavenOpts;
572         return this;
573     }
574 
575     /**
576      * <p>isShowVersion.</p>
577      *
578      * @see org.apache.maven.shared.invoker.InvocationRequest#isShowVersion()
579      * @return a boolean.
580      */
581     public boolean isShowVersion()
582     {
583         return this.showVersion;
584     }
585 
586     /** {@inheritDoc} */
587     public InvocationRequest setShowVersion( boolean showVersion )
588     {
589         this.showVersion = showVersion;
590         return this;
591     }
592 
593     /**
594      * {@inheritDoc}
595      *
596      * @return a {@link java.lang.String} object.
597      */
598     public String getThreads()
599     {
600         return threads;
601     }
602 
603     /** {@inheritDoc} */
604     public InvocationRequest setThreads( String threads )
605     {
606         this.threads = threads;
607         return this;
608     }
609 
610     /**
611      * {@inheritDoc}
612      *
613      * @return a {@link java.util.List} object.
614      */
615     public List<String> getProjects()
616     {
617         return projects;
618     }
619 
620     /** {@inheritDoc} */
621     public InvocationRequest setProjects( List<String> projects )
622     {
623         this.projects = projects;
624         return this;
625     }
626 
627     /**
628      * {@inheritDoc}
629      *
630      * @return a boolean.
631      */
632     public boolean isAlsoMake()
633     {
634         return alsoMake;
635     }
636 
637     /** {@inheritDoc} */
638     public InvocationRequest setAlsoMake( boolean alsoMake )
639     {
640         this.alsoMake = alsoMake;
641         return this;
642     }
643 
644     /**
645      * {@inheritDoc}
646      *
647      * @return a boolean.
648      */
649     public boolean isAlsoMakeDependents()
650     {
651         return alsoMakeDependents;
652     }
653 
654     /** {@inheritDoc} */
655     public InvocationRequest setAlsoMakeDependents( boolean alsoMakeDependents )
656     {
657         this.alsoMakeDependents = alsoMakeDependents;
658         return this;
659     }
660 
661     /**
662      * {@inheritDoc}
663      *
664      * @return a {@link java.lang.String} object.
665      */
666     public String getResumeFrom()
667     {
668         return resumeFrom;
669     }
670 
671     /** {@inheritDoc} */
672     public InvocationRequest setResumeFrom( String resumeFrom )
673     {
674         this.resumeFrom = resumeFrom;
675         return this;
676     }
677 
678     /** {@inheritDoc} */
679     public InvocationRequest setBuilder( String id )
680     {
681         this.builderId = id;
682         return this;
683     }
684 
685     /**
686      * {@inheritDoc}
687      *
688      * @return a {@link java.lang.String} object.
689      */
690     public String getBuilder()
691     {
692         return this.builderId;
693     }
694 
695 
696     /** {@inheritDoc} */
697     @Override
698     public int getTimeoutInSeconds()
699     {
700         return timeoutInSeconds;
701     }
702 
703     /** {@inheritDoc} */
704     @Override
705     public void setTimeoutInSeconds( int timeoutInSeconds )
706     {
707         this.timeoutInSeconds = timeoutInSeconds;
708     }
709 
710     /**
711      * {@inheritDoc}
712      *
713      * @return a boolean.
714      * @since 3.1.0
715      */
716     public boolean isQuiet()
717     {
718         return quiet;
719     }
720 
721     /** {@inheritDoc} */
722     public InvocationRequest setQuiet( boolean quiet )
723     {
724         this.quiet = quiet;
725         return this;
726     }
727 }