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