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