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