PageRenderTime 28ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/maven-3.0.5/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 396 lines | 287 code | 67 blank | 42 comment | 10 complexity | e86efe699c33ae0838d904802db376a1 MD5 | raw file
  1. package org.apache.maven.execution;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import java.io.File;
  21. import java.util.Arrays;
  22. import java.util.Date;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.Properties;
  26. import java.util.concurrent.ConcurrentHashMap;
  27. import org.apache.maven.artifact.repository.ArtifactRepository;
  28. import org.apache.maven.artifact.repository.RepositoryCache;
  29. import org.apache.maven.monitor.event.EventDispatcher;
  30. import org.apache.maven.plugin.descriptor.PluginDescriptor;
  31. import org.apache.maven.project.MavenProject;
  32. import org.apache.maven.project.ProjectBuildingRequest;
  33. import org.apache.maven.settings.Settings;
  34. import org.codehaus.plexus.PlexusContainer;
  35. import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
  36. import org.sonatype.aether.RepositorySystemSession;
  37. /**
  38. * @author Jason van Zyl
  39. */
  40. public class MavenSession
  41. implements Cloneable
  42. {
  43. private PlexusContainer container;
  44. private MavenExecutionRequest request;
  45. private MavenExecutionResult result;
  46. private RepositorySystemSession repositorySession;
  47. private final Settings settings;
  48. private Properties executionProperties;
  49. private MavenProject currentProject;
  50. /**
  51. * These projects have already been topologically sorted in the {@link org.apache.maven.Maven} component before
  52. * being passed into the session.
  53. */
  54. private List<MavenProject> projects;
  55. private MavenProject topLevelProject;
  56. private ProjectDependencyGraph projectDependencyGraph;
  57. private boolean parallel;
  58. private final Map<String, Map<String, Map<String, Object>>> pluginContextsByProjectAndPluginKey =
  59. new ConcurrentHashMap<String, Map<String, Map<String, Object>>>();
  60. @Deprecated
  61. public MavenSession( PlexusContainer container, MavenExecutionRequest request, MavenExecutionResult result,
  62. MavenProject project )
  63. {
  64. this( container, request, result, Arrays.asList( new MavenProject[]{project} ) );
  65. }
  66. @Deprecated
  67. public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository,
  68. EventDispatcher eventDispatcher, ReactorManager unused, List<String> goals,
  69. String executionRootDir, Properties executionProperties, Date startTime )
  70. {
  71. this( container, settings, localRepository, eventDispatcher, unused, goals, executionRootDir,
  72. executionProperties, null, startTime );
  73. }
  74. @Deprecated
  75. public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository,
  76. EventDispatcher eventDispatcher, ReactorManager unused, List<String> goals,
  77. String executionRootDir, Properties executionProperties, Properties userProperties,
  78. Date startTime )
  79. {
  80. this.container = container;
  81. this.settings = settings;
  82. this.executionProperties = executionProperties;
  83. this.request = new DefaultMavenExecutionRequest();
  84. this.request.setUserProperties( userProperties );
  85. this.request.setLocalRepository( localRepository );
  86. this.request.setGoals( goals );
  87. this.request.setBaseDirectory( ( executionRootDir != null ) ? new File( executionRootDir ) : null );
  88. this.request.setStartTime( startTime );
  89. }
  90. @Deprecated
  91. public MavenSession( PlexusContainer container, MavenExecutionRequest request, MavenExecutionResult result,
  92. List<MavenProject> projects )
  93. {
  94. this.container = container;
  95. this.request = request;
  96. this.result = result;
  97. this.settings = new SettingsAdapter( request );
  98. setProjects( projects );
  99. }
  100. public MavenSession( PlexusContainer container, RepositorySystemSession repositorySession, MavenExecutionRequest request,
  101. MavenExecutionResult result )
  102. {
  103. this.container = container;
  104. this.request = request;
  105. this.result = result;
  106. this.settings = new SettingsAdapter( request );
  107. this.repositorySession = repositorySession;
  108. }
  109. public void setProjects( List<MavenProject> projects )
  110. {
  111. if ( !projects.isEmpty() )
  112. {
  113. this.currentProject = projects.get( 0 );
  114. this.topLevelProject = currentProject;
  115. for ( MavenProject project : projects )
  116. {
  117. if ( project.isExecutionRoot() )
  118. {
  119. topLevelProject = project;
  120. break;
  121. }
  122. }
  123. }
  124. else
  125. {
  126. this.currentProject = null;
  127. this.topLevelProject = null;
  128. }
  129. this.projects = projects;
  130. }
  131. @Deprecated
  132. public PlexusContainer getContainer()
  133. {
  134. return container;
  135. }
  136. @Deprecated
  137. public Object lookup( String role )
  138. throws ComponentLookupException
  139. {
  140. return container.lookup( role );
  141. }
  142. @Deprecated
  143. public Object lookup( String role, String roleHint )
  144. throws ComponentLookupException
  145. {
  146. return container.lookup( role, roleHint );
  147. }
  148. @Deprecated
  149. public List<Object> lookupList( String role )
  150. throws ComponentLookupException
  151. {
  152. return container.lookupList( role );
  153. }
  154. @Deprecated
  155. public Map<String, Object> lookupMap( String role )
  156. throws ComponentLookupException
  157. {
  158. return container.lookupMap( role );
  159. }
  160. @Deprecated
  161. public RepositoryCache getRepositoryCache()
  162. {
  163. return null;
  164. }
  165. public ArtifactRepository getLocalRepository()
  166. {
  167. return request.getLocalRepository();
  168. }
  169. public List<String> getGoals()
  170. {
  171. return request.getGoals();
  172. }
  173. /**
  174. * Gets the user properties to use for interpolation and profile activation. The user properties have been
  175. * configured directly by the user on his discretion, e.g. via the {@code -Dkey=value} parameter on the command
  176. * line.
  177. *
  178. * @return The user properties, never {@code null}.
  179. */
  180. public Properties getUserProperties()
  181. {
  182. return request.getUserProperties();
  183. }
  184. /**
  185. * Gets the system properties to use for interpolation and profile activation. The system properties are collected
  186. * from the runtime environment like {@link System#getProperties()} and environment variables.
  187. *
  188. * @return The system properties, never {@code null}.
  189. */
  190. public Properties getSystemProperties()
  191. {
  192. return request.getSystemProperties();
  193. }
  194. /**
  195. * @deprecated Use either {@link #getUserProperties()} or {@link #getSystemProperties()}.
  196. */
  197. @Deprecated
  198. public Properties getExecutionProperties()
  199. {
  200. if ( executionProperties == null )
  201. {
  202. executionProperties = new Properties();
  203. executionProperties.putAll( request.getSystemProperties() );
  204. executionProperties.putAll( request.getUserProperties() );
  205. }
  206. return executionProperties;
  207. }
  208. public Settings getSettings()
  209. {
  210. return settings;
  211. }
  212. public List<MavenProject> getProjects()
  213. {
  214. return projects;
  215. }
  216. @Deprecated
  217. public List<MavenProject> getSortedProjects()
  218. {
  219. return getProjects();
  220. }
  221. public String getExecutionRootDirectory()
  222. {
  223. return request.getBaseDirectory();
  224. }
  225. public boolean isUsingPOMsFromFilesystem()
  226. {
  227. return request.isProjectPresent();
  228. }
  229. public MavenExecutionRequest getRequest()
  230. {
  231. return request;
  232. }
  233. public void setCurrentProject( MavenProject currentProject )
  234. {
  235. this.currentProject = currentProject;
  236. }
  237. public MavenProject getCurrentProject()
  238. {
  239. return currentProject;
  240. }
  241. public ProjectBuildingRequest getProjectBuildingRequest()
  242. {
  243. return request.getProjectBuildingRequest().setRepositorySession( getRepositorySession() );
  244. }
  245. public List<String> getPluginGroups()
  246. {
  247. return request.getPluginGroups();
  248. }
  249. public boolean isOffline()
  250. {
  251. return request.isOffline();
  252. }
  253. public MavenProject getTopLevelProject()
  254. {
  255. return topLevelProject;
  256. }
  257. public MavenExecutionResult getResult()
  258. {
  259. return result;
  260. }
  261. // Backward compat
  262. public Map<String, Object> getPluginContext( PluginDescriptor plugin, MavenProject project )
  263. {
  264. String projectKey = project.getId();
  265. Map<String, Map<String, Object>> pluginContextsByKey = pluginContextsByProjectAndPluginKey.get( projectKey );
  266. if ( pluginContextsByKey == null )
  267. {
  268. pluginContextsByKey = new ConcurrentHashMap<String, Map<String, Object>>();
  269. pluginContextsByProjectAndPluginKey.put( projectKey, pluginContextsByKey );
  270. }
  271. String pluginKey = plugin.getPluginLookupKey();
  272. Map<String, Object> pluginContext = pluginContextsByKey.get( pluginKey );
  273. if ( pluginContext == null )
  274. {
  275. pluginContext = new ConcurrentHashMap<String, Object>();
  276. pluginContextsByKey.put( pluginKey, pluginContext );
  277. }
  278. return pluginContext;
  279. }
  280. public ProjectDependencyGraph getProjectDependencyGraph()
  281. {
  282. return projectDependencyGraph;
  283. }
  284. public void setProjectDependencyGraph( ProjectDependencyGraph projectDependencyGraph )
  285. {
  286. this.projectDependencyGraph = projectDependencyGraph;
  287. }
  288. public String getReactorFailureBehavior()
  289. {
  290. return request.getReactorFailureBehavior();
  291. }
  292. @Override
  293. public MavenSession clone()
  294. {
  295. try
  296. {
  297. return (MavenSession) super.clone();
  298. }
  299. catch ( CloneNotSupportedException e )
  300. {
  301. throw new RuntimeException( "Bug", e );
  302. }
  303. }
  304. private String getId( MavenProject project )
  305. {
  306. return project.getGroupId() + ':' + project.getArtifactId() + ':' + project.getVersion();
  307. }
  308. @Deprecated
  309. public EventDispatcher getEventDispatcher()
  310. {
  311. return null;
  312. }
  313. public Date getStartTime()
  314. {
  315. return request.getStartTime();
  316. }
  317. public boolean isParallel()
  318. {
  319. return parallel;
  320. }
  321. public void setParallel( boolean parallel )
  322. {
  323. this.parallel = parallel;
  324. }
  325. public RepositorySystemSession getRepositorySession()
  326. {
  327. return repositorySession;
  328. }
  329. }