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
43 @Component( role = LifecyclePluginResolver.class )
44 public class LifecyclePluginResolver
45 {
46 @Requirement
47 private PluginVersionResolver pluginVersionResolver;
48
49 public LifecyclePluginResolver( PluginVersionResolver pluginVersionResolver )
50 {
51 this.pluginVersionResolver = pluginVersionResolver;
52 }
53
54 public LifecyclePluginResolver()
55 {
56 }
57
58 public void resolveMissingPluginVersions( MavenProject project, MavenSession session )
59 throws PluginVersionResolutionException
60 {
61 Map<String, String> versions = new HashMap<>( 64 );
62
63 for ( Plugin plugin : project.getBuildPlugins() )
64 {
65 if ( plugin.getVersion() == null )
66 {
67 PluginVersionRequest request = new DefaultPluginVersionRequest( plugin, session.getRepositorySession(),
68 project.getRemotePluginRepositories() );
69 plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
70 }
71 versions.put( plugin.getKey(), plugin.getVersion() );
72 }
73
74 PluginManagement pluginManagement = project.getPluginManagement();
75 if ( pluginManagement != null )
76 {
77 for ( Plugin plugin : pluginManagement.getPlugins() )
78 {
79 if ( plugin.getVersion() == null )
80 {
81 plugin.setVersion( versions.get( plugin.getKey() ) );
82 if ( plugin.getVersion() == null )
83 {
84 PluginVersionRequest request =
85 new DefaultPluginVersionRequest( plugin, session.getRepositorySession(),
86 project.getRemotePluginRepositories() );
87 plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
88 }
89 }
90 }
91 }
92 }
93 }