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