use of org.apache.maven.plugin.version.PluginVersionRequest in project maven-plugins by apache.
the class DescribeMojoTest method testLookupPluginDescriptorPrefixWithoutVersion.
public void testLookupPluginDescriptorPrefixWithoutVersion() throws Throwable {
DescribeMojo mojo = new DescribeMojo();
PluginInfo pi = new PluginInfo();
pi.setPrefix("help");
Plugin plugin = new Plugin();
plugin.setGroupId("org.test");
plugin.setArtifactId("test");
PluginDescriptor pd = new PluginDescriptor();
MojoDescriptorCreator mojoDescriptorCreator = mock(MojoDescriptorCreator.class);
PluginVersionResolver pluginVersionResolver = mock(PluginVersionResolver.class);
MavenPluginManagerHelper pluginManager = mock(MavenPluginManagerHelper.class);
PluginVersionResult versionResult = mock(PluginVersionResult.class);
MavenSession session = mock(MavenSession.class);
PrivateAccessor.setField(mojo, "mojoDescriptorCreator", mojoDescriptorCreator);
PrivateAccessor.setField(mojo, "pluginVersionResolver", pluginVersionResolver);
PrivateAccessor.setField(mojo, "pluginManager", pluginManager);
PrivateAccessor.setField(mojo, "session", session);
PrivateAccessor.setField(mojo, "project", new MavenProject());
when(mojoDescriptorCreator.findPluginForPrefix("help", session)).thenReturn(plugin);
when(pluginVersionResolver.resolve(any(PluginVersionRequest.class))).thenReturn(versionResult);
when(versionResult.getVersion()).thenReturn("1.0");
when(pluginManager.getPluginDescriptor(any(Plugin.class), eq(session))).thenReturn(pd);
PluginDescriptor returned = (PluginDescriptor) PrivateAccessor.invoke(mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, new Object[] { pi });
assertEquals(pd, returned);
verify(mojoDescriptorCreator).findPluginForPrefix("help", session);
ArgumentCaptor<PluginVersionRequest> versionArgument = ArgumentCaptor.forClass(PluginVersionRequest.class);
verify(pluginVersionResolver).resolve(versionArgument.capture());
assertEquals("org.test", versionArgument.getValue().getGroupId());
assertEquals("test", versionArgument.getValue().getArtifactId());
ArgumentCaptor<Plugin> argument = ArgumentCaptor.forClass(Plugin.class);
verify(pluginManager).getPluginDescriptor(argument.capture(), eq(session));
Plugin capturedPlugin = argument.getValue();
assertEquals("org.test", capturedPlugin.getGroupId());
assertEquals("test", capturedPlugin.getArtifactId());
assertEquals("1.0", capturedPlugin.getVersion());
}
use of org.apache.maven.plugin.version.PluginVersionRequest in project sts4 by spring-projects.
the class MavenBridge method resolvePluginVersion.
public String resolvePluginVersion(String groupId, String artifactId, MavenSession session) throws MavenException {
Plugin plugin = new Plugin();
plugin.setGroupId(groupId);
plugin.setArtifactId(artifactId);
PluginVersionRequest request = new DefaultPluginVersionRequest(plugin, session);
try {
return lookup(PluginVersionResolver.class).resolve(request).getVersion();
} catch (PluginVersionResolutionException ex) {
throw new MavenException(ex);
}
}
Aggregations