Search in sources :

Example 1 with MavenPluginManagerHelper

use of org.apache.maven.reporting.exec.MavenPluginManagerHelper in project maven-plugins by apache.

the class DescribeMojoTest method testLookupPluginDescriptorGAV.

public void testLookupPluginDescriptorGAV() throws Throwable {
    DescribeMojo mojo = new DescribeMojo();
    PluginInfo pi = new PluginInfo();
    pi.setGroupId("org.test");
    pi.setArtifactId("test");
    pi.setVersion("1.0");
    PluginDescriptor pd = new PluginDescriptor();
    MojoDescriptorCreator mojoDescriptorCreator = mock(MojoDescriptorCreator.class);
    PluginVersionResolver pluginVersionResolver = mock(PluginVersionResolver.class);
    MavenPluginManagerHelper pluginManager = mock(MavenPluginManagerHelper.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);
    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, never()).findPluginForPrefix(any(String.class), any(MavenSession.class));
    verify(pluginVersionResolver, never()).resolve(any(PluginVersionRequest.class));
    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) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MavenSession(org.apache.maven.execution.MavenSession) 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 MavenPluginManagerHelper

use of org.apache.maven.reporting.exec.MavenPluginManagerHelper in project maven-plugins by apache.

the class DescribeMojoTest method testLookupPluginDescriptorPrefixWithVersion.

public void testLookupPluginDescriptorPrefixWithVersion() throws Throwable {
    DescribeMojo mojo = new DescribeMojo();
    PluginInfo pi = new PluginInfo();
    pi.setPrefix("help");
    pi.setVersion("1.0");
    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);
    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);
    when(mojoDescriptorCreator.findPluginForPrefix("help", session)).thenReturn(plugin);
    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);
    verify(pluginVersionResolver, never()).resolve(any(PluginVersionRequest.class));
    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 : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MavenSession(org.apache.maven.execution.MavenSession) PluginVersionResolver(org.apache.maven.plugin.version.PluginVersionResolver) 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 3 with MavenPluginManagerHelper

use of org.apache.maven.reporting.exec.MavenPluginManagerHelper 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)

Aggregations

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