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