Search in sources :

Example 1 with PluginVersionRequest

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());
}
Also used : PluginVersionResolver(org.apache.maven.plugin.version.PluginVersionResolver) PluginVersionResult(org.apache.maven.plugin.version.PluginVersionResult) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MavenSession(org.apache.maven.execution.MavenSession) MavenProject(org.apache.maven.project.MavenProject) MojoDescriptorCreator(org.apache.maven.lifecycle.internal.MojoDescriptorCreator) PluginInfo(org.apache.maven.plugins.help.DescribeMojo.PluginInfo) MavenPluginManagerHelper(org.apache.maven.reporting.exec.MavenPluginManagerHelper) PluginVersionRequest(org.apache.maven.plugin.version.PluginVersionRequest) Plugin(org.apache.maven.model.Plugin)

Example 2 with PluginVersionRequest

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);
    }
}
Also used : PluginVersionResolutionException(org.apache.maven.plugin.version.PluginVersionResolutionException) PluginVersionRequest(org.apache.maven.plugin.version.PluginVersionRequest) DefaultPluginVersionRequest(org.apache.maven.plugin.version.DefaultPluginVersionRequest) DefaultPluginVersionRequest(org.apache.maven.plugin.version.DefaultPluginVersionRequest) Plugin(org.apache.maven.model.Plugin)

Aggregations

Plugin (org.apache.maven.model.Plugin)2 PluginVersionRequest (org.apache.maven.plugin.version.PluginVersionRequest)2 MavenSession (org.apache.maven.execution.MavenSession)1 MojoDescriptorCreator (org.apache.maven.lifecycle.internal.MojoDescriptorCreator)1 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)1 DefaultPluginVersionRequest (org.apache.maven.plugin.version.DefaultPluginVersionRequest)1 PluginVersionResolutionException (org.apache.maven.plugin.version.PluginVersionResolutionException)1 PluginVersionResolver (org.apache.maven.plugin.version.PluginVersionResolver)1 PluginVersionResult (org.apache.maven.plugin.version.PluginVersionResult)1 PluginInfo (org.apache.maven.plugins.help.DescribeMojo.PluginInfo)1 MavenProject (org.apache.maven.project.MavenProject)1 MavenPluginManagerHelper (org.apache.maven.reporting.exec.MavenPluginManagerHelper)1