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