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