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 org.apache.maven.artifact.repository.ArtifactRepository;
23  import org.apache.maven.monitor.event.EventDispatcher;
24  import org.apache.maven.plugin.descriptor.PluginDescriptor;
25  import org.apache.maven.project.DefaultProjectBuilderConfiguration;
26  import org.apache.maven.project.MavenProject;
27  import org.apache.maven.project.ProjectBuilderConfiguration;
28  import org.apache.maven.settings.Settings;
29  import org.codehaus.plexus.PlexusContainer;
30  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
31  
32  import java.util.Date;
33  import java.util.List;
34  import java.util.Map;
35  import java.util.Properties;
36  
37  /**
38   * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
39   * @version $Id: MavenSession.java 793745 2009-07-13 23:24:10Z jdcasey $
40   */
41  public class MavenSession
42  {
43      private PlexusContainer container;
44  
45      private ArtifactRepository localRepository;
46  
47      private List goals;
48  
49      private EventDispatcher eventDispatcher;
50  
51      // TODO: make this the central one, get rid of build settings...
52      private final Settings settings;
53  
54      private ReactorManager reactorManager;
55  
56      private final String executionRootDir;
57  
58      private boolean usingPOMsFromFilesystem = true;
59  
60      private final Properties executionProperties;
61  
62      private Properties userProperties;
63  
64      private final Date startTime;
65  
66      private MavenProject currentProject;
67  
68      public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository,
69                           EventDispatcher eventDispatcher, ReactorManager reactorManager, List goals,
70                           String executionRootDir, Properties executionProperties, Date startTime )
71      {
72          this( container, settings, localRepository, eventDispatcher, reactorManager, goals, executionRootDir, executionProperties, null, startTime );
73      }
74  
75      public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository,
76                           EventDispatcher eventDispatcher, ReactorManager reactorManager, List goals,
77                           String executionRootDir, Properties executionProperties, Properties userProperties, Date startTime )
78      {
79          this.container = container;
80  
81          this.settings = settings;
82  
83          this.localRepository = localRepository;
84  
85          this.eventDispatcher = eventDispatcher;
86  
87          this.reactorManager = reactorManager;
88  
89          this.goals = goals;
90  
91          this.executionRootDir = executionRootDir;
92  
93          this.executionProperties = executionProperties;
94  
95          this.userProperties = userProperties;
96  
97          this.startTime = startTime;
98      }
99  
100     public Map getPluginContext( PluginDescriptor pluginDescriptor, MavenProject project )
101     {
102         return reactorManager.getPluginContext( pluginDescriptor, project );
103     }
104 
105     public PlexusContainer getContainer()
106     {
107         return container;
108     }
109 
110     public ArtifactRepository getLocalRepository()
111     {
112         return localRepository;
113     }
114 
115     public List getGoals()
116     {
117         return goals;
118     }
119 
120     public Properties getExecutionProperties()
121     {
122         return executionProperties;
123     }
124 
125     // ----------------------------------------------------------------------
126     //
127     // ----------------------------------------------------------------------
128 
129     public Object lookup( String role )
130         throws ComponentLookupException
131     {
132         return container.lookup( role );
133     }
134 
135     public Object lookup( String role, String roleHint )
136         throws ComponentLookupException
137     {
138         return container.lookup( role, roleHint );
139     }
140 
141     public List lookupList( String role )
142         throws ComponentLookupException
143     {
144         return container.lookupList( role );
145     }
146 
147     public Map lookupMap( String role )
148         throws ComponentLookupException
149     {
150         return container.lookupMap( role );
151     }
152 
153     public EventDispatcher getEventDispatcher()
154     {
155         return eventDispatcher;
156     }
157 
158     public Settings getSettings()
159     {
160         return settings;
161     }
162 
163     public List<MavenProject> getSortedProjects()
164     {
165         return reactorManager.getSortedProjects();
166     }
167 
168     public String getExecutionRootDirectory()
169     {
170         return executionRootDir;
171     }
172 
173     public void setUsingPOMsFromFilesystem( boolean usingPOMsFromFilesystem )
174     {
175         this.usingPOMsFromFilesystem = usingPOMsFromFilesystem;
176     }
177 
178     public boolean isUsingPOMsFromFilesystem()
179     {
180         return usingPOMsFromFilesystem;
181     }
182 
183     public Date getStartTime()
184     {
185         return startTime;
186     }
187 
188     public void setCurrentProject( MavenProject currentProject )
189     {
190         this.currentProject = currentProject;
191     }
192 
193     /**
194      * Return the current project for use in a mojo execution.
195      */
196     public MavenProject getCurrentProject()
197     {
198         return currentProject;
199     }
200 
201 
202     public Properties getUserProperties()
203     {
204         return userProperties;
205     }
206 
207     public void setUserProperties( Properties userProperties )
208     {
209         this.userProperties = userProperties;
210     }
211 
212     /**
213      * NOTE: This varies from {@link DefaultMavenExecutionRequest#getProjectBuilderConfiguration()} in that
214      * it doesn't supply a global profile manager.
215      */
216     public ProjectBuilderConfiguration getProjectBuilderConfiguration()
217     {
218         ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration();
219         config.setLocalRepository( getLocalRepository() )
220               .setExecutionProperties( getExecutionProperties() )
221               .setUserProperties( getUserProperties() )
222               .setBuildStartTime( getStartTime() );
223 
224         return config;
225     }
226 }