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