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.execution;
20  
21  import java.io.File;
22  import java.nio.file.Path;
23  import java.util.ArrayList;
24  import java.util.Date;
25  import java.util.HashMap;
26  import java.util.List;
27  import java.util.Map;
28  import java.util.Objects;
29  import java.util.Properties;
30  
31  import org.apache.maven.artifact.repository.ArtifactRepository;
32  import org.apache.maven.eventspy.internal.EventSpyDispatcher;
33  import org.apache.maven.model.Profile;
34  import org.apache.maven.model.root.RootLocator;
35  import org.apache.maven.project.DefaultProjectBuildingRequest;
36  import org.apache.maven.project.ProjectBuildingRequest;
37  import org.apache.maven.properties.internal.SystemProperties;
38  import org.apache.maven.settings.Mirror;
39  import org.apache.maven.settings.Proxy;
40  import org.apache.maven.settings.Server;
41  import org.apache.maven.toolchain.model.ToolchainModel;
42  import org.eclipse.aether.DefaultRepositoryCache;
43  import org.eclipse.aether.RepositoryCache;
44  import org.eclipse.aether.repository.WorkspaceReader;
45  import org.eclipse.aether.transfer.TransferListener;
46  
47  /**
48   * @author Jason van Zyl
49   */
50  public class DefaultMavenExecutionRequest implements MavenExecutionRequest {
51  
52      private RepositoryCache repositoryCache = new DefaultRepositoryCache();
53  
54      private WorkspaceReader workspaceReader;
55  
56      private ArtifactRepository localRepository;
57  
58      private EventSpyDispatcher eventSpyDispatcher;
59  
60      private File localRepositoryPath;
61  
62      private boolean offline = false;
63  
64      private boolean interactiveMode = true;
65  
66      private boolean cacheTransferError;
67  
68      private boolean cacheNotFound;
69  
70      private boolean ignoreTransitiveRepositories;
71  
72      private List<Proxy> proxies;
73  
74      private List<Server> servers;
75  
76      private List<Mirror> mirrors;
77  
78      private List<Profile> profiles;
79  
80      private List<String> pluginGroups;
81  
82      private boolean isProjectPresent = true;
83  
84      // ----------------------------------------------------------------------------
85      // We need to allow per execution user and global settings as the embedder
86      // might be running in a mode where its executing many threads with totally
87      // different settings.
88      // ----------------------------------------------------------------------------
89  
90      private File userSettingsFile;
91  
92      private File globalSettingsFile;
93  
94      private File userToolchainsFile;
95  
96      private File globalToolchainsFile;
97  
98      // ----------------------------------------------------------------------------
99      // Request
100     // ----------------------------------------------------------------------------
101 
102     private File multiModuleProjectDirectory;
103 
104     private File basedir;
105 
106     private List<String> goals;
107 
108     private boolean useReactor = false;
109 
110     private boolean recursive = true;
111 
112     private File pom;
113 
114     private String reactorFailureBehavior = REACTOR_FAIL_FAST;
115 
116     private List<String> selectedProjects;
117 
118     private List<String> excludedProjects;
119 
120     private String resumeFrom;
121 
122     private String makeBehavior;
123 
124     private Properties systemProperties;
125 
126     private Properties userProperties;
127 
128     private Date startTime;
129 
130     private boolean showErrors = false;
131 
132     private List<String> activeProfiles;
133 
134     private List<String> inactiveProfiles;
135 
136     private TransferListener transferListener;
137 
138     private int loggingLevel = LOGGING_LEVEL_INFO;
139 
140     private String globalChecksumPolicy;
141 
142     private boolean updateSnapshots = false;
143 
144     private String artifactsUpdatePolicy = null;
145 
146     private String metadataUpdatePolicy = null;
147 
148     private List<ArtifactRepository> remoteRepositories;
149 
150     private List<ArtifactRepository> pluginArtifactRepositories;
151 
152     private ExecutionListener executionListener;
153 
154     private int degreeOfConcurrency = 1;
155 
156     private String builderId = "singlethreaded";
157 
158     private Map<String, List<ToolchainModel>> toolchains;
159 
160     /**
161      * Suppress SNAPSHOT updates.
162      *
163      * @issue MNG-2681
164      */
165     private boolean noSnapshotUpdates;
166 
167     private boolean useLegacyLocalRepositoryManager = false;
168 
169     private Map<String, Object> data;
170 
171     private Path topDirectory;
172 
173     private Path rootDirectory;
174 
175     public DefaultMavenExecutionRequest() {}
176 
177     public static MavenExecutionRequest copy(MavenExecutionRequest original) {
178         DefaultMavenExecutionRequest copy = new DefaultMavenExecutionRequest();
179         copy.setLocalRepository(original.getLocalRepository());
180         copy.setLocalRepositoryPath(original.getLocalRepositoryPath());
181         copy.setOffline(original.isOffline());
182         copy.setInteractiveMode(original.isInteractiveMode());
183         copy.setCacheNotFound(original.isCacheNotFound());
184         copy.setIgnoreTransitiveRepositories(original.isIgnoreTransitiveRepositories());
185         copy.setCacheTransferError(original.isCacheTransferError());
186         copy.setProxies(original.getProxies());
187         copy.setServers(original.getServers());
188         copy.setMirrors(original.getMirrors());
189         copy.setProfiles(original.getProfiles());
190         copy.setPluginGroups(original.getPluginGroups());
191         copy.setProjectPresent(original.isProjectPresent());
192         copy.setUserSettingsFile(original.getUserSettingsFile());
193         copy.setGlobalSettingsFile(original.getGlobalSettingsFile());
194         copy.setUserToolchainsFile(original.getUserToolchainsFile());
195         copy.setGlobalToolchainsFile(original.getGlobalToolchainsFile());
196         copy.setBaseDirectory((original.getBaseDirectory() != null) ? new File(original.getBaseDirectory()) : null);
197         copy.setGoals(original.getGoals());
198         copy.setRecursive(original.isRecursive());
199         copy.setPom(original.getPom());
200         copy.setSystemProperties(original.getSystemProperties());
201         copy.setUserProperties(original.getUserProperties());
202         copy.setShowErrors(original.isShowErrors());
203         copy.setActiveProfiles(original.getActiveProfiles());
204         copy.setInactiveProfiles(original.getInactiveProfiles());
205         copy.setTransferListener(original.getTransferListener());
206         copy.setLoggingLevel(original.getLoggingLevel());
207         copy.setGlobalChecksumPolicy(original.getGlobalChecksumPolicy());
208         copy.setUpdateSnapshots(original.isUpdateSnapshots());
209         copy.setNoSnapshotUpdates(original.isNoSnapshotUpdates());
210         copy.setArtifactsUpdatePolicy(original.getArtifactsUpdatePolicy());
211         copy.setMetadataUpdatePolicy(original.getMetadataUpdatePolicy());
212         copy.setRemoteRepositories(original.getRemoteRepositories());
213         copy.setPluginArtifactRepositories(original.getPluginArtifactRepositories());
214         copy.setRepositoryCache(original.getRepositoryCache());
215         copy.setWorkspaceReader(original.getWorkspaceReader());
216         copy.setExecutionListener(original.getExecutionListener());
217         copy.setUseLegacyLocalRepository(original.isUseLegacyLocalRepository());
218         copy.setBuilderId(original.getBuilderId());
219 
220         copy.setTopDirectory(original.getTopDirectory());
221         try {
222             copy.setRootDirectory(original.getRootDirectory());
223         } catch (IllegalStateException e) {
224             // ignore during copy
225         }
226 
227         return copy;
228     }
229 
230     @Override
231     public String getBaseDirectory() {
232         if (basedir == null) {
233             return null;
234         }
235 
236         return basedir.getAbsolutePath();
237     }
238 
239     @Override
240     public ArtifactRepository getLocalRepository() {
241         return localRepository;
242     }
243 
244     @Override
245     public File getLocalRepositoryPath() {
246         return localRepositoryPath;
247     }
248 
249     @Override
250     public List<String> getGoals() {
251         if (goals == null) {
252             goals = new ArrayList<>();
253         }
254         return goals;
255     }
256 
257     @Override
258     public Properties getSystemProperties() {
259         if (systemProperties == null) {
260             systemProperties = new Properties();
261         }
262 
263         return systemProperties;
264     }
265 
266     @Override
267     public Properties getUserProperties() {
268         if (userProperties == null) {
269             userProperties = new Properties();
270         }
271 
272         return userProperties;
273     }
274 
275     @Override
276     public File getPom() {
277         return pom;
278     }
279 
280     @Override
281     public String getReactorFailureBehavior() {
282         return reactorFailureBehavior;
283     }
284 
285     @Override
286     public List<String> getSelectedProjects() {
287         if (selectedProjects == null) {
288             selectedProjects = new ArrayList<>();
289         }
290 
291         return selectedProjects;
292     }
293 
294     @Override
295     public List<String> getExcludedProjects() {
296         if (excludedProjects == null) {
297             excludedProjects = new ArrayList<>();
298         }
299 
300         return excludedProjects;
301     }
302 
303     @Override
304     public String getResumeFrom() {
305         return resumeFrom;
306     }
307 
308     @Override
309     public String getMakeBehavior() {
310         return makeBehavior;
311     }
312 
313     @Override
314     public Date getStartTime() {
315         return startTime;
316     }
317 
318     @Override
319     public boolean isShowErrors() {
320         return showErrors;
321     }
322 
323     @Override
324     public boolean isInteractiveMode() {
325         return interactiveMode;
326     }
327 
328     @Override
329     public MavenExecutionRequest setActiveProfiles(List<String> activeProfiles) {
330         if (activeProfiles != null) {
331             this.activeProfiles = new ArrayList<>(activeProfiles);
332         } else {
333             this.activeProfiles = null;
334         }
335 
336         return this;
337     }
338 
339     @Override
340     public MavenExecutionRequest setInactiveProfiles(List<String> inactiveProfiles) {
341         if (inactiveProfiles != null) {
342             this.inactiveProfiles = new ArrayList<>(inactiveProfiles);
343         } else {
344             this.inactiveProfiles = null;
345         }
346 
347         return this;
348     }
349 
350     @Override
351     public MavenExecutionRequest setRemoteRepositories(List<ArtifactRepository> remoteRepositories) {
352         if (remoteRepositories != null) {
353             this.remoteRepositories = new ArrayList<>(remoteRepositories);
354         } else {
355             this.remoteRepositories = null;
356         }
357 
358         return this;
359     }
360 
361     @Override
362     public MavenExecutionRequest setPluginArtifactRepositories(List<ArtifactRepository> pluginArtifactRepositories) {
363         if (pluginArtifactRepositories != null) {
364             this.pluginArtifactRepositories = new ArrayList<>(pluginArtifactRepositories);
365         } else {
366             this.pluginArtifactRepositories = null;
367         }
368 
369         return this;
370     }
371 
372     public void setProjectBuildingConfiguration(ProjectBuildingRequest projectBuildingConfiguration) {
373         this.projectBuildingRequest = projectBuildingConfiguration;
374     }
375 
376     @Override
377     public List<String> getActiveProfiles() {
378         if (activeProfiles == null) {
379             activeProfiles = new ArrayList<>();
380         }
381         return activeProfiles;
382     }
383 
384     @Override
385     public List<String> getInactiveProfiles() {
386         if (inactiveProfiles == null) {
387             inactiveProfiles = new ArrayList<>();
388         }
389         return inactiveProfiles;
390     }
391 
392     @Override
393     public TransferListener getTransferListener() {
394         return transferListener;
395     }
396 
397     @Override
398     public int getLoggingLevel() {
399         return loggingLevel;
400     }
401 
402     @Override
403     public boolean isOffline() {
404         return offline;
405     }
406 
407     @Override
408     public boolean isUpdateSnapshots() {
409         return updateSnapshots;
410     }
411 
412     @Override
413     public boolean isNoSnapshotUpdates() {
414         return noSnapshotUpdates;
415     }
416 
417     @Override
418     public MavenExecutionRequest setArtifactsUpdatePolicy(String policy) {
419         this.artifactsUpdatePolicy = policy;
420         return this;
421     }
422 
423     @Override
424     public String getArtifactsUpdatePolicy() {
425         return artifactsUpdatePolicy;
426     }
427 
428     @Override
429     public MavenExecutionRequest setMetadataUpdatePolicy(String policy) {
430         this.metadataUpdatePolicy = policy;
431         return this;
432     }
433 
434     @Override
435     public String getMetadataUpdatePolicy() {
436         return metadataUpdatePolicy;
437     }
438 
439     @Override
440     public String getGlobalChecksumPolicy() {
441         return globalChecksumPolicy;
442     }
443 
444     @Override
445     public boolean isRecursive() {
446         return recursive;
447     }
448 
449     // ----------------------------------------------------------------------
450     //
451     // ----------------------------------------------------------------------
452 
453     @Override
454     public MavenExecutionRequest setBaseDirectory(File basedir) {
455         this.basedir = basedir;
456 
457         return this;
458     }
459 
460     @Override
461     public MavenExecutionRequest setStartTime(Date startTime) {
462         this.startTime = startTime;
463 
464         return this;
465     }
466 
467     @Override
468     public MavenExecutionRequest setShowErrors(boolean showErrors) {
469         this.showErrors = showErrors;
470 
471         return this;
472     }
473 
474     @Override
475     public MavenExecutionRequest setGoals(List<String> goals) {
476         if (goals != null) {
477             this.goals = new ArrayList<>(goals);
478         } else {
479             this.goals = null;
480         }
481 
482         return this;
483     }
484 
485     @Override
486     public MavenExecutionRequest setLocalRepository(ArtifactRepository localRepository) {
487         this.localRepository = localRepository;
488 
489         if (localRepository != null) {
490             setLocalRepositoryPath(new File(localRepository.getBasedir()).getAbsoluteFile());
491         }
492 
493         return this;
494     }
495 
496     @Override
497     public MavenExecutionRequest setLocalRepositoryPath(File localRepository) {
498         localRepositoryPath = localRepository;
499 
500         return this;
501     }
502 
503     @Override
504     public MavenExecutionRequest setLocalRepositoryPath(String localRepository) {
505         localRepositoryPath = (localRepository != null) ? new File(localRepository) : null;
506 
507         return this;
508     }
509 
510     @Override
511     public MavenExecutionRequest setSystemProperties(Properties properties) {
512         if (properties != null) {
513             this.systemProperties = SystemProperties.copyProperties(properties);
514         } else {
515             this.systemProperties = null;
516         }
517 
518         return this;
519     }
520 
521     @Override
522     public MavenExecutionRequest setUserProperties(Properties userProperties) {
523         if (userProperties != null) {
524             this.userProperties = new Properties();
525             this.userProperties.putAll(userProperties);
526         } else {
527             this.userProperties = null;
528         }
529 
530         return this;
531     }
532 
533     @Override
534     public MavenExecutionRequest setReactorFailureBehavior(String failureBehavior) {
535         reactorFailureBehavior = failureBehavior;
536 
537         return this;
538     }
539 
540     @Override
541     public MavenExecutionRequest setSelectedProjects(List<String> selectedProjects) {
542         if (selectedProjects != null) {
543             this.selectedProjects = new ArrayList<>(selectedProjects);
544         } else {
545             this.selectedProjects = null;
546         }
547 
548         return this;
549     }
550 
551     @Override
552     public MavenExecutionRequest setExcludedProjects(List<String> excludedProjects) {
553         if (excludedProjects != null) {
554             this.excludedProjects = new ArrayList<>(excludedProjects);
555         } else {
556             this.excludedProjects = null;
557         }
558 
559         return this;
560     }
561 
562     @Override
563     public MavenExecutionRequest setResumeFrom(String project) {
564         this.resumeFrom = project;
565 
566         return this;
567     }
568 
569     @Override
570     public MavenExecutionRequest setMakeBehavior(String makeBehavior) {
571         this.makeBehavior = makeBehavior;
572 
573         return this;
574     }
575 
576     @Override
577     public MavenExecutionRequest addActiveProfile(String profile) {
578         if (!getActiveProfiles().contains(profile)) {
579             getActiveProfiles().add(profile);
580         }
581 
582         return this;
583     }
584 
585     @Override
586     public MavenExecutionRequest addInactiveProfile(String profile) {
587         if (!getInactiveProfiles().contains(profile)) {
588             getInactiveProfiles().add(profile);
589         }
590 
591         return this;
592     }
593 
594     @Override
595     public MavenExecutionRequest addActiveProfiles(List<String> profiles) {
596         for (String profile : profiles) {
597             addActiveProfile(profile);
598         }
599 
600         return this;
601     }
602 
603     @Override
604     public MavenExecutionRequest addInactiveProfiles(List<String> profiles) {
605         for (String profile : profiles) {
606             addInactiveProfile(profile);
607         }
608 
609         return this;
610     }
611 
612     public MavenExecutionRequest setUseReactor(boolean reactorActive) {
613         useReactor = reactorActive;
614 
615         return this;
616     }
617 
618     public boolean useReactor() {
619         return useReactor;
620     }
621 
622     /** @deprecated use {@link #setPom(File)} */
623     @Deprecated
624     public MavenExecutionRequest setPomFile(String pomFilename) {
625         if (pomFilename != null) {
626             pom = new File(pomFilename);
627         }
628 
629         return this;
630     }
631 
632     @Override
633     public MavenExecutionRequest setPom(File pom) {
634         this.pom = pom;
635 
636         return this;
637     }
638 
639     @Override
640     public MavenExecutionRequest setInteractiveMode(boolean interactive) {
641         interactiveMode = interactive;
642 
643         return this;
644     }
645 
646     @Override
647     public MavenExecutionRequest setTransferListener(TransferListener transferListener) {
648         this.transferListener = transferListener;
649 
650         return this;
651     }
652 
653     @Override
654     public MavenExecutionRequest setLoggingLevel(int loggingLevel) {
655         this.loggingLevel = loggingLevel;
656 
657         return this;
658     }
659 
660     @Override
661     public MavenExecutionRequest setOffline(boolean offline) {
662         this.offline = offline;
663 
664         return this;
665     }
666 
667     @Override
668     public MavenExecutionRequest setUpdateSnapshots(boolean updateSnapshots) {
669         this.updateSnapshots = updateSnapshots;
670 
671         return this;
672     }
673 
674     @Override
675     public MavenExecutionRequest setNoSnapshotUpdates(boolean noSnapshotUpdates) {
676         this.noSnapshotUpdates = noSnapshotUpdates;
677 
678         return this;
679     }
680 
681     @Override
682     public MavenExecutionRequest setGlobalChecksumPolicy(String globalChecksumPolicy) {
683         this.globalChecksumPolicy = globalChecksumPolicy;
684 
685         return this;
686     }
687 
688     // ----------------------------------------------------------------------------
689     // Settings equivalents
690     // ----------------------------------------------------------------------------
691 
692     @Override
693     public List<Proxy> getProxies() {
694         if (proxies == null) {
695             proxies = new ArrayList<>();
696         }
697         return proxies;
698     }
699 
700     @Override
701     public MavenExecutionRequest setProxies(List<Proxy> proxies) {
702         if (proxies != null) {
703             this.proxies = new ArrayList<>(proxies);
704         } else {
705             this.proxies = null;
706         }
707 
708         return this;
709     }
710 
711     @Override
712     public MavenExecutionRequest addProxy(Proxy proxy) {
713         Objects.requireNonNull(proxy, "proxy cannot be null");
714 
715         for (Proxy p : getProxies()) {
716             if (p.getId() != null && p.getId().equals(proxy.getId())) {
717                 return this;
718             }
719         }
720 
721         getProxies().add(proxy);
722 
723         return this;
724     }
725 
726     @Override
727     public List<Server> getServers() {
728         if (servers == null) {
729             servers = new ArrayList<>();
730         }
731         return servers;
732     }
733 
734     @Override
735     public MavenExecutionRequest setServers(List<Server> servers) {
736         if (servers != null) {
737             this.servers = new ArrayList<>(servers);
738         } else {
739             this.servers = null;
740         }
741 
742         return this;
743     }
744 
745     @Override
746     public MavenExecutionRequest addServer(Server server) {
747         Objects.requireNonNull(server, "server cannot be null");
748 
749         for (Server p : getServers()) {
750             if (p.getId() != null && p.getId().equals(server.getId())) {
751                 return this;
752             }
753         }
754 
755         getServers().add(server);
756 
757         return this;
758     }
759 
760     @Override
761     public List<Mirror> getMirrors() {
762         if (mirrors == null) {
763             mirrors = new ArrayList<>();
764         }
765         return mirrors;
766     }
767 
768     @Override
769     public MavenExecutionRequest setMirrors(List<Mirror> mirrors) {
770         if (mirrors != null) {
771             this.mirrors = new ArrayList<>(mirrors);
772         } else {
773             this.mirrors = null;
774         }
775 
776         return this;
777     }
778 
779     @Override
780     public MavenExecutionRequest addMirror(Mirror mirror) {
781         Objects.requireNonNull(mirror, "mirror cannot be null");
782 
783         for (Mirror p : getMirrors()) {
784             if (p.getId() != null && p.getId().equals(mirror.getId())) {
785                 return this;
786             }
787         }
788 
789         getMirrors().add(mirror);
790 
791         return this;
792     }
793 
794     @Override
795     public List<Profile> getProfiles() {
796         if (profiles == null) {
797             profiles = new ArrayList<>();
798         }
799         return profiles;
800     }
801 
802     @Override
803     public MavenExecutionRequest setProfiles(List<Profile> profiles) {
804         if (profiles != null) {
805             this.profiles = new ArrayList<>(profiles);
806         } else {
807             this.profiles = null;
808         }
809 
810         return this;
811     }
812 
813     @Override
814     public List<String> getPluginGroups() {
815         if (pluginGroups == null) {
816             pluginGroups = new ArrayList<>();
817         }
818 
819         return pluginGroups;
820     }
821 
822     @Override
823     public MavenExecutionRequest setPluginGroups(List<String> pluginGroups) {
824         if (pluginGroups != null) {
825             this.pluginGroups = new ArrayList<>(pluginGroups);
826         } else {
827             this.pluginGroups = null;
828         }
829 
830         return this;
831     }
832 
833     @Override
834     public MavenExecutionRequest addPluginGroup(String pluginGroup) {
835         if (!getPluginGroups().contains(pluginGroup)) {
836             getPluginGroups().add(pluginGroup);
837         }
838 
839         return this;
840     }
841 
842     @Override
843     public MavenExecutionRequest addPluginGroups(List<String> pluginGroups) {
844         for (String pluginGroup : pluginGroups) {
845             addPluginGroup(pluginGroup);
846         }
847 
848         return this;
849     }
850 
851     @Override
852     public MavenExecutionRequest setRecursive(boolean recursive) {
853         this.recursive = recursive;
854 
855         return this;
856     }
857 
858     // calculated from request attributes.
859     private ProjectBuildingRequest projectBuildingRequest;
860 
861     @Override
862     public boolean isProjectPresent() {
863         return isProjectPresent;
864     }
865 
866     @Override
867     public MavenExecutionRequest setProjectPresent(boolean projectPresent) {
868         isProjectPresent = projectPresent;
869 
870         return this;
871     }
872 
873     // Settings files
874 
875     @Override
876     public File getUserSettingsFile() {
877         return userSettingsFile;
878     }
879 
880     @Override
881     public MavenExecutionRequest setUserSettingsFile(File userSettingsFile) {
882         this.userSettingsFile = userSettingsFile;
883 
884         return this;
885     }
886 
887     @Override
888     public File getGlobalSettingsFile() {
889         return globalSettingsFile;
890     }
891 
892     @Override
893     public MavenExecutionRequest setGlobalSettingsFile(File globalSettingsFile) {
894         this.globalSettingsFile = globalSettingsFile;
895 
896         return this;
897     }
898 
899     @Override
900     public File getUserToolchainsFile() {
901         return userToolchainsFile;
902     }
903 
904     @Override
905     public MavenExecutionRequest setUserToolchainsFile(File userToolchainsFile) {
906         this.userToolchainsFile = userToolchainsFile;
907 
908         return this;
909     }
910 
911     @Override
912     public File getGlobalToolchainsFile() {
913         return globalToolchainsFile;
914     }
915 
916     @Override
917     public MavenExecutionRequest setGlobalToolchainsFile(File globalToolchainsFile) {
918         this.globalToolchainsFile = globalToolchainsFile;
919         return this;
920     }
921 
922     @Override
923     public MavenExecutionRequest addRemoteRepository(ArtifactRepository repository) {
924         for (ArtifactRepository repo : getRemoteRepositories()) {
925             if (repo.getId() != null && repo.getId().equals(repository.getId())) {
926                 return this;
927             }
928         }
929 
930         getRemoteRepositories().add(repository);
931 
932         return this;
933     }
934 
935     @Override
936     public List<ArtifactRepository> getRemoteRepositories() {
937         if (remoteRepositories == null) {
938             remoteRepositories = new ArrayList<>();
939         }
940         return remoteRepositories;
941     }
942 
943     @Override
944     public MavenExecutionRequest addPluginArtifactRepository(ArtifactRepository repository) {
945         for (ArtifactRepository repo : getPluginArtifactRepositories()) {
946             if (repo.getId() != null && repo.getId().equals(repository.getId())) {
947                 return this;
948             }
949         }
950 
951         getPluginArtifactRepositories().add(repository);
952 
953         return this;
954     }
955 
956     @Override
957     public List<ArtifactRepository> getPluginArtifactRepositories() {
958         if (pluginArtifactRepositories == null) {
959             pluginArtifactRepositories = new ArrayList<>();
960         }
961         return pluginArtifactRepositories;
962     }
963 
964     // TODO this does not belong here.
965     @Override
966     public ProjectBuildingRequest getProjectBuildingRequest() {
967         if (projectBuildingRequest == null) {
968             projectBuildingRequest = new DefaultProjectBuildingRequest();
969             projectBuildingRequest.setLocalRepository(getLocalRepository());
970             projectBuildingRequest.setSystemProperties(getSystemProperties());
971             projectBuildingRequest.setUserProperties(getUserProperties());
972             projectBuildingRequest.setRemoteRepositories(getRemoteRepositories());
973             projectBuildingRequest.setPluginArtifactRepositories(getPluginArtifactRepositories());
974             projectBuildingRequest.setActiveProfileIds(getActiveProfiles());
975             projectBuildingRequest.setInactiveProfileIds(getInactiveProfiles());
976             projectBuildingRequest.setProfiles(getProfiles());
977             projectBuildingRequest.setProcessPlugins(true);
978             projectBuildingRequest.setBuildStartTime(getStartTime());
979         }
980 
981         return projectBuildingRequest;
982     }
983 
984     @Override
985     public MavenExecutionRequest addProfile(Profile profile) {
986         Objects.requireNonNull(profile, "profile cannot be null");
987 
988         for (Profile p : getProfiles()) {
989             if (p.getId() != null && p.getId().equals(profile.getId())) {
990                 return this;
991             }
992         }
993 
994         getProfiles().add(profile);
995 
996         return this;
997     }
998 
999     @Override
1000     public RepositoryCache getRepositoryCache() {
1001         return repositoryCache;
1002     }
1003 
1004     @Override
1005     public MavenExecutionRequest setRepositoryCache(RepositoryCache repositoryCache) {
1006         this.repositoryCache = repositoryCache;
1007 
1008         return this;
1009     }
1010 
1011     @Override
1012     public ExecutionListener getExecutionListener() {
1013         return executionListener;
1014     }
1015 
1016     @Override
1017     public MavenExecutionRequest setExecutionListener(ExecutionListener executionListener) {
1018         this.executionListener = executionListener;
1019 
1020         return this;
1021     }
1022 
1023     @Override
1024     public void setDegreeOfConcurrency(final int degreeOfConcurrency) {
1025         this.degreeOfConcurrency = degreeOfConcurrency;
1026     }
1027 
1028     @Override
1029     public int getDegreeOfConcurrency() {
1030         return degreeOfConcurrency;
1031     }
1032 
1033     @Override
1034     public WorkspaceReader getWorkspaceReader() {
1035         return workspaceReader;
1036     }
1037 
1038     @Override
1039     public MavenExecutionRequest setWorkspaceReader(WorkspaceReader workspaceReader) {
1040         this.workspaceReader = workspaceReader;
1041         return this;
1042     }
1043 
1044     @Override
1045     public boolean isCacheTransferError() {
1046         return cacheTransferError;
1047     }
1048 
1049     @Override
1050     public MavenExecutionRequest setCacheTransferError(boolean cacheTransferError) {
1051         this.cacheTransferError = cacheTransferError;
1052         return this;
1053     }
1054 
1055     @Override
1056     public boolean isCacheNotFound() {
1057         return cacheNotFound;
1058     }
1059 
1060     @Override
1061     public MavenExecutionRequest setCacheNotFound(boolean cacheNotFound) {
1062         this.cacheNotFound = cacheNotFound;
1063         return this;
1064     }
1065 
1066     @Override
1067     public boolean isIgnoreTransitiveRepositories() {
1068         return ignoreTransitiveRepositories;
1069     }
1070 
1071     @Override
1072     public MavenExecutionRequest setIgnoreTransitiveRepositories(boolean ignoreTransitiveRepositories) {
1073         this.ignoreTransitiveRepositories = ignoreTransitiveRepositories;
1074         return this;
1075     }
1076 
1077     @Override
1078     public boolean isUseLegacyLocalRepository() {
1079         return this.useLegacyLocalRepositoryManager;
1080     }
1081 
1082     @Override
1083     public MavenExecutionRequest setUseLegacyLocalRepository(boolean useLegacyLocalRepositoryManager) {
1084         this.useLegacyLocalRepositoryManager = false;
1085         return this;
1086     }
1087 
1088     @Override
1089     public MavenExecutionRequest setBuilderId(String builderId) {
1090         this.builderId = builderId;
1091         return this;
1092     }
1093 
1094     @Override
1095     public String getBuilderId() {
1096         return builderId;
1097     }
1098 
1099     @Override
1100     public Map<String, List<ToolchainModel>> getToolchains() {
1101         if (toolchains == null) {
1102             toolchains = new HashMap<>();
1103         }
1104         return toolchains;
1105     }
1106 
1107     @Override
1108     public MavenExecutionRequest setToolchains(Map<String, List<ToolchainModel>> toolchains) {
1109         this.toolchains = toolchains;
1110         return this;
1111     }
1112 
1113     @Override
1114     public void setMultiModuleProjectDirectory(File directory) {
1115         this.multiModuleProjectDirectory = directory;
1116     }
1117 
1118     @Override
1119     public File getMultiModuleProjectDirectory() {
1120         return multiModuleProjectDirectory;
1121     }
1122 
1123     @Override
1124     public MavenExecutionRequest setEventSpyDispatcher(EventSpyDispatcher eventSpyDispatcher) {
1125         this.eventSpyDispatcher = eventSpyDispatcher;
1126         return this;
1127     }
1128 
1129     @Override
1130     public EventSpyDispatcher getEventSpyDispatcher() {
1131         return eventSpyDispatcher;
1132     }
1133 
1134     @Override
1135     public Map<String, Object> getData() {
1136         if (data == null) {
1137             data = new HashMap<>();
1138         }
1139 
1140         return data;
1141     }
1142 
1143     @Override
1144     public Path getTopDirectory() {
1145         return topDirectory;
1146     }
1147 
1148     @Override
1149     public MavenExecutionRequest setTopDirectory(Path topDirectory) {
1150         this.topDirectory = topDirectory;
1151         return this;
1152     }
1153 
1154     @Override
1155     public Path getRootDirectory() {
1156         if (rootDirectory == null) {
1157             throw new IllegalStateException(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE);
1158         }
1159         return rootDirectory;
1160     }
1161 
1162     @Override
1163     public MavenExecutionRequest setRootDirectory(Path rootDirectory) {
1164         this.rootDirectory = rootDirectory;
1165         return this;
1166     }
1167 }