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 org.apache.maven.execution.MavenSession;
23 import org.apache.maven.model.Plugin;
24 import org.apache.maven.model.PluginManagement;
25 import org.apache.maven.plugin.version.DefaultPluginVersionRequest;
26 import org.apache.maven.plugin.version.PluginVersionRequest;
27 import org.apache.maven.plugin.version.PluginVersionResolutionException;
28 import org.apache.maven.plugin.version.PluginVersionResolver;
29 import org.apache.maven.project.MavenProject;
30 import org.codehaus.plexus.component.annotations.Component;
31 import org.codehaus.plexus.component.annotations.Requirement;
32
33 import java.util.HashMap;
34 import java.util.Map;
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
50 public LifecyclePluginResolver( PluginVersionResolver pluginVersionResolver )
51 {
52 this.pluginVersionResolver = pluginVersionResolver;
53 }
54
55 public LifecyclePluginResolver()
56 {
57 }
58
59 public void resolveMissingPluginVersions( MavenProject project, MavenSession session )
60 throws PluginVersionResolutionException
61 {
62 Map<String, String> versions = new HashMap<>( 64 );
63
64 for ( Plugin plugin : project.getBuildPlugins() )
65 {
66 if ( plugin.getVersion() == null )
67 {
68 PluginVersionRequest request =
69 new DefaultPluginVersionRequest( plugin, session.getRepositorySession(),
70 project.getRemotePluginRepositories() );
71 plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
72 }
73 versions.put( plugin.getKey(), plugin.getVersion() );
74 }
75
76 PluginManagement pluginManagement = project.getPluginManagement();
77 if ( pluginManagement != null )
78 {
79 for ( Plugin plugin : pluginManagement.getPlugins() )
80 {
81 if ( plugin.getVersion() == null )
82 {
83 plugin.setVersion( versions.get( plugin.getKey() ) );
84 if ( plugin.getVersion() == null )
85 {
86 PluginVersionRequest request =
87 new DefaultPluginVersionRequest( plugin, session.getRepositorySession(),
88 project.getRemotePluginRepositories() );
89 plugin.setVersion( pluginVersionResolver.resolve( request ).getVersion() );
90 }
91 }
92 }
93 }
94 }
95 }