1 package org.apache.maven.lifecycle.internal;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.apache.maven.execution.MavenSession;
26 import org.apache.maven.model.Plugin;
27 import org.apache.maven.model.PluginManagement;
28 import org.apache.maven.plugin.version.DefaultPluginVersionRequest;
29 import org.apache.maven.plugin.version.PluginVersionRequest;
30 import org.apache.maven.plugin.version.PluginVersionResolutionException;
31 import org.apache.maven.plugin.version.PluginVersionResolver;
32 import org.apache.maven.project.MavenProject;
33 import org.codehaus.plexus.component.annotations.Component;
34 import org.codehaus.plexus.component.annotations.Requirement;
35
36
37
38
39
40
41
42 @Component( role = LifecyclePluginResolver.class )
43 public class LifecyclePluginResolver
44 {
45 @Requirement
46 private PluginVersionResolver pluginVersionResolver;
47
48 public LifecyclePluginResolver( PluginVersionResolver pluginVersionResolver )
49 {
50 this.pluginVersionResolver = pluginVersionResolver;
51 }
52
53 public LifecyclePluginResolver()
54 {
55 }
56
57 public void resolveMissingPluginVersions( MavenProject project, MavenSession session )
58 throws PluginVersionResolutionException
59 {
60 Map<String, String> versions = new HashMap<>( 64 );
61
62 for ( Plugin plugin : project.getBuildPlugins() )
63 {
64 if ( plugin.getVersion() == null )
65 {
66 PluginVersionRequest request = new DefaultPluginVersionRequest( plugin, session.getRepositorySession(),
67 project.getRemotePluginRepositories() );
68 plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
69 }
70 versions.put( plugin.getKey(), plugin.getVersion() );
71 }
72
73 PluginManagement pluginManagement = project.getPluginManagement();
74 if ( pluginManagement != null )
75 {
76 for ( Plugin plugin : pluginManagement.getPlugins() )
77 {
78 if ( plugin.getVersion() == null )
79 {
80 plugin.setVersion( versions.get( plugin.getKey() ) );
81 if ( plugin.getVersion() == null )
82 {
83 PluginVersionRequest request =
84 new DefaultPluginVersionRequest( plugin, session.getRepositorySession(),
85 project.getRemotePluginRepositories() );
86 plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
87 }
88 }
89 }
90 }
91 }
92 }