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