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