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.MavenProject;
26  import org.apache.maven.settings.Settings;
27  import org.codehaus.plexus.PlexusContainer;
28  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
29  
30  import java.util.Date;
31  import java.util.List;
32  import java.util.Map;
33  import java.util.Properties;
34  
35  /**
36   * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
37   * @version $Id: MavenSession.java 688884 2008-08-25 21:11:19Z jdcasey $
38   */
39  public class MavenSession
40  {
41      private PlexusContainer container;
42  
43      private ArtifactRepository localRepository;
44  
45      private List goals;
46  
47      private EventDispatcher eventDispatcher;
48  
49      // TODO: make this the central one, get rid of build settings...
50      private final Settings settings;
51  
52      private ReactorManager reactorManager;
53  
54      private final String executionRootDir;
55  
56      private boolean usingPOMsFromFilesystem = true;
57  
58      private final Properties executionProperties;
59  
60      private final Date startTime;
61      
62      private MavenProject currentProject;
63  
64      public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository,
65                           EventDispatcher eventDispatcher, ReactorManager reactorManager, List goals,
66                           String executionRootDir, Properties executionProperties, Date startTime )
67      {
68          this.container = container;
69  
70          this.settings = settings;
71  
72          this.localRepository = localRepository;
73  
74          this.eventDispatcher = eventDispatcher;
75  
76          this.reactorManager = reactorManager;
77  
78          this.goals = goals;
79  
80          this.executionRootDir = executionRootDir;
81  
82          this.executionProperties = executionProperties;
83  
84          this.startTime = startTime;
85      }
86  
87      public Map getPluginContext( PluginDescriptor pluginDescriptor, MavenProject project )
88      {
89          return reactorManager.getPluginContext( pluginDescriptor, project );
90      }
91  
92      public PlexusContainer getContainer()
93      {
94          return container;
95      }
96  
97      public ArtifactRepository getLocalRepository()
98      {
99          return localRepository;
100     }
101 
102     public List getGoals()
103     {
104         return goals;
105     }
106 
107     public Properties getExecutionProperties()
108     {
109         return executionProperties;
110     }
111 
112     // ----------------------------------------------------------------------
113     //
114     // ----------------------------------------------------------------------
115 
116     public Object lookup( String role )
117         throws ComponentLookupException
118     {
119         return container.lookup( role );
120     }
121 
122     public Object lookup( String role, String roleHint )
123         throws ComponentLookupException
124     {
125         return container.lookup( role, roleHint );
126     }
127 
128     public List lookupList( String role )
129         throws ComponentLookupException
130     {
131         return container.lookupList( role );
132     }
133 
134     public Map lookupMap( String role )
135         throws ComponentLookupException
136     {
137         return container.lookupMap( role );
138     }
139 
140     public EventDispatcher getEventDispatcher()
141     {
142         return eventDispatcher;
143     }
144 
145     public Settings getSettings()
146     {
147         return settings;
148     }
149 
150     public List getSortedProjects()
151     {
152         return reactorManager.getSortedProjects();
153     }
154 
155     public String getExecutionRootDirectory()
156     {
157         return executionRootDir;
158     }
159 
160     public void setUsingPOMsFromFilesystem( boolean usingPOMsFromFilesystem )
161     {
162         this.usingPOMsFromFilesystem = usingPOMsFromFilesystem;
163     }
164 
165     public boolean isUsingPOMsFromFilesystem()
166     {
167         return usingPOMsFromFilesystem;
168     }
169 
170     public Date getStartTime()
171     {
172         return startTime;
173     }
174     
175     public void setCurrentProject( MavenProject currentProject )
176     {
177         this.currentProject = currentProject;
178     }
179 
180     /**
181      * Return the current project for use in a mojo execution.
182      */
183     public MavenProject getCurrentProject()
184     {
185         return currentProject;
186     }
187     
188 }