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