PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/maven-3.0.5/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecycleExecutionPlanCalculator.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 695 lines | 518 code | 129 blank | 48 comment | 84 complexity | 13fd28dcb00dda511593ccef13bd55d6 MD5 | raw file
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  3. * agreements. See the NOTICE file distributed with this work for additional information regarding
  4. * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
  5. * "License"); you may not use this file except in compliance with the License. You may obtain a
  6. * copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software distributed under the License
  11. * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  12. * or implied. See the License for the specific language governing permissions and limitations under
  13. * the License.
  14. */
  15. package org.apache.maven.lifecycle.internal;
  16. import java.io.IOException;
  17. import java.util.ArrayList;
  18. import java.util.Collection;
  19. import java.util.Collections;
  20. import java.util.HashSet;
  21. import java.util.LinkedHashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.TreeMap;
  25. import org.apache.maven.execution.MavenSession;
  26. import org.apache.maven.lifecycle.DefaultLifecycles;
  27. import org.apache.maven.lifecycle.DefaultSchedules;
  28. import org.apache.maven.lifecycle.Lifecycle;
  29. import org.apache.maven.lifecycle.LifecycleNotFoundException;
  30. import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
  31. import org.apache.maven.lifecycle.MavenExecutionPlan;
  32. import org.apache.maven.model.Plugin;
  33. import org.apache.maven.model.PluginExecution;
  34. import org.apache.maven.plugin.BuildPluginManager;
  35. import org.apache.maven.plugin.InvalidPluginDescriptorException;
  36. import org.apache.maven.plugin.MojoExecution;
  37. import org.apache.maven.plugin.MojoNotFoundException;
  38. import org.apache.maven.plugin.PluginDescriptorParsingException;
  39. import org.apache.maven.plugin.PluginNotFoundException;
  40. import org.apache.maven.plugin.PluginResolutionException;
  41. import org.apache.maven.plugin.descriptor.MojoDescriptor;
  42. import org.apache.maven.plugin.descriptor.Parameter;
  43. import org.apache.maven.plugin.descriptor.PluginDescriptor;
  44. import org.apache.maven.plugin.lifecycle.Execution;
  45. import org.apache.maven.plugin.lifecycle.Phase;
  46. import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
  47. import org.apache.maven.plugin.version.PluginVersionResolutionException;
  48. import org.apache.maven.plugin.version.PluginVersionResolver;
  49. import org.apache.maven.project.MavenProject;
  50. import org.codehaus.plexus.component.annotations.Component;
  51. import org.codehaus.plexus.component.annotations.Requirement;
  52. import org.codehaus.plexus.util.StringUtils;
  53. import org.codehaus.plexus.util.xml.Xpp3Dom;
  54. import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
  55. /**
  56. * @since 3.0
  57. * @author Benjamin Bentmann
  58. * @author Kristian Rosenvold (Extract class)
  59. * <p/>
  60. * NOTE: This class is not part of any public api and can be changed or deleted without prior notice.
  61. */
  62. @Component( role = LifecycleExecutionPlanCalculator.class )
  63. public class DefaultLifecycleExecutionPlanCalculator
  64. implements LifecycleExecutionPlanCalculator
  65. {
  66. @Requirement
  67. private PluginVersionResolver pluginVersionResolver;
  68. @Requirement
  69. private BuildPluginManager pluginManager;
  70. @Requirement
  71. private DefaultLifecycles defaultLifeCycles;
  72. @Requirement
  73. private DefaultSchedules defaultSchedules;
  74. @Requirement
  75. private MojoDescriptorCreator mojoDescriptorCreator;
  76. @Requirement
  77. private LifecyclePluginResolver lifecyclePluginResolver;
  78. @SuppressWarnings( { "UnusedDeclaration" } )
  79. public DefaultLifecycleExecutionPlanCalculator()
  80. {
  81. }
  82. public DefaultLifecycleExecutionPlanCalculator( BuildPluginManager pluginManager,
  83. DefaultLifecycles defaultLifeCycles,
  84. MojoDescriptorCreator mojoDescriptorCreator,
  85. LifecyclePluginResolver lifecyclePluginResolver,
  86. DefaultSchedules defaultSchedules )
  87. {
  88. this.pluginManager = pluginManager;
  89. this.defaultLifeCycles = defaultLifeCycles;
  90. this.mojoDescriptorCreator = mojoDescriptorCreator;
  91. this.lifecyclePluginResolver = lifecyclePluginResolver;
  92. this.defaultSchedules = defaultSchedules;
  93. }
  94. public MavenExecutionPlan calculateExecutionPlan( MavenSession session, MavenProject project, List<Object> tasks, boolean setup )
  95. throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
  96. PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
  97. NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
  98. {
  99. lifecyclePluginResolver.resolveMissingPluginVersions( project, session );
  100. final List<MojoExecution> executions = calculateMojoExecutions( session, project, tasks );
  101. if ( setup )
  102. {
  103. setupMojoExecutions( session, project, executions );
  104. }
  105. final List<ExecutionPlanItem> planItem = defaultSchedules.createExecutionPlanItem( project, executions );
  106. return new MavenExecutionPlan( planItem, defaultLifeCycles );
  107. }
  108. public MavenExecutionPlan calculateExecutionPlan( MavenSession session, MavenProject project, List<Object> tasks )
  109. throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
  110. PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
  111. NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException
  112. {
  113. return calculateExecutionPlan( session, project, tasks, true );
  114. }
  115. private void setupMojoExecutions( MavenSession session, MavenProject project, List<MojoExecution> mojoExecutions )
  116. throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
  117. MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException,
  118. LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
  119. {
  120. for ( MojoExecution mojoExecution : mojoExecutions )
  121. {
  122. setupMojoExecution( session, project, mojoExecution );
  123. }
  124. }
  125. public void setupMojoExecution( MavenSession session, MavenProject project, MojoExecution mojoExecution )
  126. throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
  127. MojoNotFoundException, InvalidPluginDescriptorException, NoPluginFoundForPrefixException,
  128. LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
  129. {
  130. MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
  131. if ( mojoDescriptor == null )
  132. {
  133. mojoDescriptor =
  134. pluginManager.getMojoDescriptor( mojoExecution.getPlugin(), mojoExecution.getGoal(),
  135. project.getRemotePluginRepositories(),
  136. session.getRepositorySession() );
  137. mojoExecution.setMojoDescriptor( mojoDescriptor );
  138. }
  139. populateMojoExecutionConfiguration( project, mojoExecution,
  140. MojoExecution.Source.CLI.equals( mojoExecution.getSource() ) );
  141. finalizeMojoConfiguration( mojoExecution );
  142. calculateForkedExecutions( mojoExecution, session, project, new HashSet<MojoDescriptor>() );
  143. }
  144. public List<MojoExecution> calculateMojoExecutions( MavenSession session, MavenProject project,
  145. List<Object> tasks )
  146. throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
  147. MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
  148. PluginVersionResolutionException, LifecyclePhaseNotFoundException
  149. {
  150. final List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
  151. for ( Object task : tasks )
  152. {
  153. if ( task instanceof GoalTask )
  154. {
  155. String pluginGoal = ( (GoalTask) task ).pluginGoal;
  156. MojoDescriptor mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor( pluginGoal, session, project );
  157. MojoExecution mojoExecution =
  158. new MojoExecution( mojoDescriptor, "default-cli", MojoExecution.Source.CLI );
  159. mojoExecutions.add( mojoExecution );
  160. }
  161. else if ( task instanceof LifecycleTask )
  162. {
  163. String lifecyclePhase = ( (LifecycleTask) task ).getLifecyclePhase();
  164. Map<String, List<MojoExecution>> phaseToMojoMapping =
  165. calculateLifecycleMappings( session, project, lifecyclePhase );
  166. for ( List<MojoExecution> mojoExecutionsFromLifecycle : phaseToMojoMapping.values() )
  167. {
  168. mojoExecutions.addAll( mojoExecutionsFromLifecycle );
  169. }
  170. }
  171. else
  172. {
  173. throw new IllegalStateException( "unexpected task " + task );
  174. }
  175. }
  176. return mojoExecutions;
  177. }
  178. private Map<String, List<MojoExecution>> calculateLifecycleMappings( MavenSession session, MavenProject project,
  179. String lifecyclePhase )
  180. throws LifecyclePhaseNotFoundException, PluginNotFoundException, PluginResolutionException,
  181. PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException
  182. {
  183. /*
  184. * Determine the lifecycle that corresponds to the given phase.
  185. */
  186. Lifecycle lifecycle = defaultLifeCycles.get( lifecyclePhase );
  187. if ( lifecycle == null )
  188. {
  189. throw new LifecyclePhaseNotFoundException(
  190. "Unknown lifecycle phase \"" + lifecyclePhase + "\". You must specify a valid lifecycle phase" +
  191. " or a goal in the format <plugin-prefix>:<goal> or" +
  192. " <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: " +
  193. defaultLifeCycles.getLifecyclePhaseList() + ".", lifecyclePhase );
  194. }
  195. /*
  196. * Initialize mapping from lifecycle phase to bound mojos. The key set of this map denotes the phases the caller
  197. * is interested in, i.e. all phases up to and including the specified phase.
  198. */
  199. Map<String, Map<Integer, List<MojoExecution>>> mappings =
  200. new LinkedHashMap<String, Map<Integer, List<MojoExecution>>>();
  201. for ( String phase : lifecycle.getPhases() )
  202. {
  203. Map<Integer, List<MojoExecution>> phaseBindings = new TreeMap<Integer, List<MojoExecution>>();
  204. mappings.put( phase, phaseBindings );
  205. if ( phase.equals( lifecyclePhase ) )
  206. {
  207. break;
  208. }
  209. }
  210. /*
  211. * Grab plugin executions that are bound to the selected lifecycle phases from project. The effective model of
  212. * the project already contains the plugin executions induced by the project's packaging type. Remember, all
  213. * phases of interest and only those are in the lifecyle mapping, if a phase has no value in the map, we are not
  214. * interested in any of the executions bound to it.
  215. */
  216. for ( Plugin plugin : project.getBuild().getPlugins() )
  217. {
  218. for ( PluginExecution execution : plugin.getExecutions() )
  219. {
  220. // if the phase is specified then I don't have to go fetch the plugin yet and pull it down
  221. // to examine the phase it is associated to.
  222. if ( execution.getPhase() != null )
  223. {
  224. Map<Integer, List<MojoExecution>> phaseBindings = mappings.get( execution.getPhase() );
  225. if ( phaseBindings != null )
  226. {
  227. for ( String goal : execution.getGoals() )
  228. {
  229. MojoExecution mojoExecution = new MojoExecution( plugin, goal, execution.getId() );
  230. mojoExecution.setLifecyclePhase( execution.getPhase() );
  231. addMojoExecution( phaseBindings, mojoExecution, execution.getPriority() );
  232. }
  233. }
  234. }
  235. // if not then i need to grab the mojo descriptor and look at the phase that is specified
  236. else
  237. {
  238. for ( String goal : execution.getGoals() )
  239. {
  240. MojoDescriptor mojoDescriptor =
  241. pluginManager.getMojoDescriptor( plugin, goal, project.getRemotePluginRepositories(),
  242. session.getRepositorySession() );
  243. Map<Integer, List<MojoExecution>> phaseBindings = mappings.get( mojoDescriptor.getPhase() );
  244. if ( phaseBindings != null )
  245. {
  246. MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, execution.getId() );
  247. mojoExecution.setLifecyclePhase( mojoDescriptor.getPhase() );
  248. addMojoExecution( phaseBindings, mojoExecution, execution.getPriority() );
  249. }
  250. }
  251. }
  252. }
  253. }
  254. Map<String, List<MojoExecution>> lifecycleMappings = new LinkedHashMap<String, List<MojoExecution>>();
  255. for ( Map.Entry<String, Map<Integer, List<MojoExecution>>> entry : mappings.entrySet() )
  256. {
  257. List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
  258. for ( List<MojoExecution> executions : entry.getValue().values() )
  259. {
  260. mojoExecutions.addAll( executions );
  261. }
  262. lifecycleMappings.put( entry.getKey(), mojoExecutions );
  263. }
  264. return lifecycleMappings;
  265. }
  266. private void addMojoExecution( Map<Integer, List<MojoExecution>> phaseBindings, MojoExecution mojoExecution,
  267. int priority )
  268. {
  269. List<MojoExecution> mojoExecutions = phaseBindings.get( priority );
  270. if ( mojoExecutions == null )
  271. {
  272. mojoExecutions = new ArrayList<MojoExecution>();
  273. phaseBindings.put( priority, mojoExecutions );
  274. }
  275. mojoExecutions.add( mojoExecution );
  276. }
  277. private void populateMojoExecutionConfiguration( MavenProject project, MojoExecution mojoExecution,
  278. boolean allowPluginLevelConfig )
  279. {
  280. String g = mojoExecution.getGroupId();
  281. String a = mojoExecution.getArtifactId();
  282. Plugin plugin = findPlugin( g, a, project.getBuildPlugins() );
  283. if ( plugin == null && project.getPluginManagement() != null )
  284. {
  285. plugin = findPlugin( g, a, project.getPluginManagement().getPlugins() );
  286. }
  287. if ( plugin != null )
  288. {
  289. PluginExecution pluginExecution =
  290. findPluginExecution( mojoExecution.getExecutionId(), plugin.getExecutions() );
  291. Xpp3Dom pomConfiguration = null;
  292. if ( pluginExecution != null )
  293. {
  294. pomConfiguration = (Xpp3Dom) pluginExecution.getConfiguration();
  295. }
  296. else if ( allowPluginLevelConfig )
  297. {
  298. pomConfiguration = (Xpp3Dom) plugin.getConfiguration();
  299. }
  300. Xpp3Dom mojoConfiguration = ( pomConfiguration != null ) ? new Xpp3Dom( pomConfiguration ) : null;
  301. mojoConfiguration = Xpp3Dom.mergeXpp3Dom( mojoExecution.getConfiguration(), mojoConfiguration );
  302. mojoExecution.setConfiguration( mojoConfiguration );
  303. }
  304. }
  305. private Plugin findPlugin( String groupId, String artifactId, Collection<Plugin> plugins )
  306. {
  307. for ( Plugin plugin : plugins )
  308. {
  309. if ( artifactId.equals( plugin.getArtifactId() ) && groupId.equals( plugin.getGroupId() ) )
  310. {
  311. return plugin;
  312. }
  313. }
  314. return null;
  315. }
  316. private PluginExecution findPluginExecution( String executionId, Collection<PluginExecution> executions )
  317. {
  318. if ( StringUtils.isNotEmpty( executionId ) )
  319. {
  320. for ( PluginExecution execution : executions )
  321. {
  322. if ( executionId.equals( execution.getId() ) )
  323. {
  324. return execution;
  325. }
  326. }
  327. }
  328. return null;
  329. }
  330. /**
  331. * Post-processes the effective configuration for the specified mojo execution. This step discards all parameters
  332. * from the configuration that are not applicable to the mojo and injects the default values for any missing
  333. * parameters.
  334. *
  335. * @param mojoExecution The mojo execution whose configuration should be finalized, must not be {@code null}.
  336. */
  337. private void finalizeMojoConfiguration( MojoExecution mojoExecution )
  338. {
  339. MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
  340. Xpp3Dom executionConfiguration = mojoExecution.getConfiguration();
  341. if ( executionConfiguration == null )
  342. {
  343. executionConfiguration = new Xpp3Dom( "configuration" );
  344. }
  345. Xpp3Dom defaultConfiguration = getMojoConfiguration( mojoDescriptor );
  346. Xpp3Dom finalConfiguration = new Xpp3Dom( "configuration" );
  347. if ( mojoDescriptor.getParameters() != null )
  348. {
  349. for ( Parameter parameter : mojoDescriptor.getParameters() )
  350. {
  351. Xpp3Dom parameterConfiguration = executionConfiguration.getChild( parameter.getName() );
  352. if ( parameterConfiguration == null )
  353. {
  354. parameterConfiguration = executionConfiguration.getChild( parameter.getAlias() );
  355. }
  356. Xpp3Dom parameterDefaults = defaultConfiguration.getChild( parameter.getName() );
  357. parameterConfiguration =
  358. Xpp3Dom.mergeXpp3Dom( parameterConfiguration, parameterDefaults, Boolean.TRUE );
  359. if ( parameterConfiguration != null )
  360. {
  361. parameterConfiguration = new Xpp3Dom( parameterConfiguration, parameter.getName() );
  362. if ( StringUtils.isEmpty( parameterConfiguration.getAttribute( "implementation" ) ) &&
  363. StringUtils.isNotEmpty( parameter.getImplementation() ) )
  364. {
  365. parameterConfiguration.setAttribute( "implementation", parameter.getImplementation() );
  366. }
  367. finalConfiguration.addChild( parameterConfiguration );
  368. }
  369. }
  370. }
  371. mojoExecution.setConfiguration( finalConfiguration );
  372. }
  373. private Xpp3Dom getMojoConfiguration( MojoDescriptor mojoDescriptor )
  374. {
  375. return MojoDescriptorCreator.convert( mojoDescriptor );
  376. }
  377. public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
  378. throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
  379. PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
  380. LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
  381. {
  382. calculateForkedExecutions( mojoExecution, session, session.getCurrentProject(), new HashSet<MojoDescriptor>() );
  383. }
  384. private void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session, MavenProject project,
  385. Collection<MojoDescriptor> alreadyForkedExecutions )
  386. throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
  387. PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
  388. LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
  389. {
  390. MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
  391. if ( !mojoDescriptor.isForking() )
  392. {
  393. return;
  394. }
  395. if ( !alreadyForkedExecutions.add( mojoDescriptor ) )
  396. {
  397. return;
  398. }
  399. List<MavenProject> forkedProjects =
  400. LifecycleDependencyResolver.getProjects( project, session, mojoDescriptor.isAggregator() );
  401. for ( MavenProject forkedProject : forkedProjects )
  402. {
  403. if ( forkedProject != project )
  404. {
  405. lifecyclePluginResolver.resolveMissingPluginVersions( forkedProject, session );
  406. }
  407. List<MojoExecution> forkedExecutions;
  408. if ( StringUtils.isNotEmpty( mojoDescriptor.getExecutePhase() ) )
  409. {
  410. forkedExecutions =
  411. calculateForkedLifecycle( mojoExecution, session, forkedProject, alreadyForkedExecutions );
  412. }
  413. else
  414. {
  415. forkedExecutions =
  416. calculateForkedGoal( mojoExecution, session, forkedProject, alreadyForkedExecutions );
  417. }
  418. mojoExecution.setForkedExecutions( BuilderCommon.getKey( forkedProject ), forkedExecutions );
  419. }
  420. alreadyForkedExecutions.remove( mojoDescriptor );
  421. }
  422. private List<MojoExecution> calculateForkedLifecycle( MojoExecution mojoExecution, MavenSession session,
  423. MavenProject project,
  424. Collection<MojoDescriptor> alreadyForkedExecutions )
  425. throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
  426. PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
  427. LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
  428. {
  429. MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
  430. String forkedPhase = mojoDescriptor.getExecutePhase();
  431. Map<String, List<MojoExecution>> lifecycleMappings =
  432. calculateLifecycleMappings( session, project, forkedPhase );
  433. for ( List<MojoExecution> forkedExecutions : lifecycleMappings.values() )
  434. {
  435. for ( MojoExecution forkedExecution : forkedExecutions )
  436. {
  437. if ( forkedExecution.getMojoDescriptor() == null )
  438. {
  439. MojoDescriptor forkedMojoDescriptor =
  440. pluginManager.getMojoDescriptor( forkedExecution.getPlugin(), forkedExecution.getGoal(),
  441. project.getRemotePluginRepositories(),
  442. session.getRepositorySession() );
  443. forkedExecution.setMojoDescriptor( forkedMojoDescriptor );
  444. }
  445. populateMojoExecutionConfiguration( project, forkedExecution, false );
  446. }
  447. }
  448. injectLifecycleOverlay( lifecycleMappings, mojoExecution, session, project );
  449. List<MojoExecution> mojoExecutions = new ArrayList<MojoExecution>();
  450. for ( List<MojoExecution> forkedExecutions : lifecycleMappings.values() )
  451. {
  452. for ( MojoExecution forkedExecution : forkedExecutions )
  453. {
  454. if ( !alreadyForkedExecutions.contains( forkedExecution.getMojoDescriptor() ) )
  455. {
  456. finalizeMojoConfiguration( forkedExecution );
  457. calculateForkedExecutions( forkedExecution, session, project, alreadyForkedExecutions );
  458. mojoExecutions.add( forkedExecution );
  459. }
  460. }
  461. }
  462. return mojoExecutions;
  463. }
  464. private void injectLifecycleOverlay( Map<String, List<MojoExecution>> lifecycleMappings,
  465. MojoExecution mojoExecution, MavenSession session, MavenProject project )
  466. throws PluginDescriptorParsingException, LifecycleNotFoundException, MojoNotFoundException,
  467. PluginNotFoundException, PluginResolutionException, NoPluginFoundForPrefixException,
  468. InvalidPluginDescriptorException, PluginVersionResolutionException
  469. {
  470. MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
  471. PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
  472. String forkedLifecycle = mojoDescriptor.getExecuteLifecycle();
  473. if ( StringUtils.isEmpty( forkedLifecycle ) )
  474. {
  475. return;
  476. }
  477. org.apache.maven.plugin.lifecycle.Lifecycle lifecycleOverlay;
  478. try
  479. {
  480. lifecycleOverlay = pluginDescriptor.getLifecycleMapping( forkedLifecycle );
  481. }
  482. catch ( IOException e )
  483. {
  484. throw new PluginDescriptorParsingException( pluginDescriptor.getPlugin(), pluginDescriptor.getSource(), e );
  485. }
  486. catch ( XmlPullParserException e )
  487. {
  488. throw new PluginDescriptorParsingException( pluginDescriptor.getPlugin(), pluginDescriptor.getSource(), e );
  489. }
  490. if ( lifecycleOverlay == null )
  491. {
  492. throw new LifecycleNotFoundException( forkedLifecycle );
  493. }
  494. for ( Phase phase : lifecycleOverlay.getPhases() )
  495. {
  496. List<MojoExecution> forkedExecutions = lifecycleMappings.get( phase.getId() );
  497. if ( forkedExecutions != null )
  498. {
  499. for ( Execution execution : phase.getExecutions() )
  500. {
  501. for ( String goal : execution.getGoals() )
  502. {
  503. MojoDescriptor forkedMojoDescriptor;
  504. if ( goal.indexOf( ':' ) < 0 )
  505. {
  506. forkedMojoDescriptor = pluginDescriptor.getMojo( goal );
  507. if ( forkedMojoDescriptor == null )
  508. {
  509. throw new MojoNotFoundException( goal, pluginDescriptor );
  510. }
  511. }
  512. else
  513. {
  514. forkedMojoDescriptor = mojoDescriptorCreator.getMojoDescriptor( goal, session, project );
  515. }
  516. MojoExecution forkedExecution =
  517. new MojoExecution( forkedMojoDescriptor, mojoExecution.getExecutionId() );
  518. Xpp3Dom forkedConfiguration = (Xpp3Dom) execution.getConfiguration();
  519. forkedExecution.setConfiguration( forkedConfiguration );
  520. populateMojoExecutionConfiguration( project, forkedExecution, true );
  521. forkedExecutions.add( forkedExecution );
  522. }
  523. }
  524. Xpp3Dom phaseConfiguration = (Xpp3Dom) phase.getConfiguration();
  525. if ( phaseConfiguration != null )
  526. {
  527. for ( MojoExecution forkedExecution : forkedExecutions )
  528. {
  529. Xpp3Dom forkedConfiguration = forkedExecution.getConfiguration();
  530. forkedConfiguration = Xpp3Dom.mergeXpp3Dom( phaseConfiguration, forkedConfiguration );
  531. forkedExecution.setConfiguration( forkedConfiguration );
  532. }
  533. }
  534. }
  535. }
  536. }
  537. // org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
  538. //TODO: take repo mans into account as one may be aggregating prefixes of many
  539. //TODO: collect at the root of the repository, read the one at the root, and fetch remote if something is missing
  540. // or the user forces the issue
  541. private List<MojoExecution> calculateForkedGoal( MojoExecution mojoExecution, MavenSession session,
  542. MavenProject project,
  543. Collection<MojoDescriptor> alreadyForkedExecutions )
  544. throws MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
  545. PluginDescriptorParsingException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
  546. LifecyclePhaseNotFoundException, LifecycleNotFoundException, PluginVersionResolutionException
  547. {
  548. MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
  549. PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
  550. String forkedGoal = mojoDescriptor.getExecuteGoal();
  551. MojoDescriptor forkedMojoDescriptor = pluginDescriptor.getMojo( forkedGoal );
  552. if ( forkedMojoDescriptor == null )
  553. {
  554. throw new MojoNotFoundException( forkedGoal, pluginDescriptor );
  555. }
  556. if ( alreadyForkedExecutions.contains( forkedMojoDescriptor ) )
  557. {
  558. return Collections.emptyList();
  559. }
  560. MojoExecution forkedExecution = new MojoExecution( forkedMojoDescriptor, forkedGoal );
  561. populateMojoExecutionConfiguration( project, forkedExecution, true );
  562. finalizeMojoConfiguration( forkedExecution );
  563. calculateForkedExecutions( forkedExecution, session, project, alreadyForkedExecutions );
  564. return Collections.singletonList( forkedExecution );
  565. }
  566. }