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