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