Search in sources :

Example 1 with PluginInfo

use of org.apache.maven.plugins.help.DescribeMojo.PluginInfo 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 PluginInfo

use of org.apache.maven.plugins.help.DescribeMojo.PluginInfo 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 PluginInfo

use of org.apache.maven.plugins.help.DescribeMojo.PluginInfo 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 4 with PluginInfo

use of org.apache.maven.plugins.help.DescribeMojo.PluginInfo in project maven-plugins by apache.

the class DescribeMojoTest method testParsePluginInfoPluginPrefix.

public void testParsePluginInfoPluginPrefix() throws Throwable {
    DescribeMojo mojo = new DescribeMojo();
    PrivateAccessor.setField(mojo, "plugin", "help");
    PluginInfo pi = (PluginInfo) PrivateAccessor.invoke(mojo, "parsePluginLookupInfo", null, null);
    assertNull(pi.getGroupId());
    assertNull(pi.getArtifactId());
    assertNull(pi.getVersion());
    assertEquals("help", pi.getPrefix());
    PrivateAccessor.setField(mojo, "plugin", "help2:::");
    pi = (PluginInfo) PrivateAccessor.invoke(mojo, "parsePluginLookupInfo", null, null);
    assertEquals("help2", pi.getPrefix());
}
Also used : PluginInfo(org.apache.maven.plugins.help.DescribeMojo.PluginInfo)

Example 5 with PluginInfo

use of org.apache.maven.plugins.help.DescribeMojo.PluginInfo in project maven-plugins by apache.

the class DescribeMojoTest method testLookupPluginDescriptorGMissingA.

public void testLookupPluginDescriptorGMissingA() throws Throwable {
    DescribeMojo mojo = new DescribeMojo();
    PluginInfo pi = new PluginInfo();
    pi.setGroupId("org.test");
    try {
        PrivateAccessor.invoke(mojo, "lookupPluginDescriptor", new Class[] { PluginInfo.class }, new Object[] { pi });
        fail();
    } catch (Exception e) {
        assertTrue(e.getMessage().startsWith("You must specify either"));
    }
}
Also used : PluginInfo(org.apache.maven.plugins.help.DescribeMojo.PluginInfo)

Aggregations

PluginInfo (org.apache.maven.plugins.help.DescribeMojo.PluginInfo)9 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 MavenPluginManagerHelper (org.apache.maven.reporting.exec.MavenPluginManagerHelper)3 PluginVersionResult (org.apache.maven.plugin.version.PluginVersionResult)1 MavenProject (org.apache.maven.project.MavenProject)1