Search in sources :

Example 11 with PluginDescriptor

use of org.apache.maven.plugin.descriptor.PluginDescriptor in project wildfly-swarm by wildfly-swarm.

the class MultiStartMojo method startProject.

@SuppressWarnings("unchecked")
protected void startProject(MavenProject project, String executionId, XmlPlexusConfiguration process) throws InvalidPluginDescriptorException, PluginResolutionException, PluginDescriptorParsingException, PluginNotFoundException, PluginConfigurationException, MojoFailureException, MojoExecutionException, PluginManagerException {
    Plugin plugin = this.project.getPlugin("org.wildfly.swarm:wildfly-swarm-plugin");
    Xpp3Dom config = getConfiguration(project, executionId);
    Xpp3Dom processConfig = getProcessConfiguration(process);
    Xpp3Dom globalConfig = getGlobalConfig();
    Xpp3Dom mergedConfig = Xpp3DomUtils.mergeXpp3Dom(processConfig, config);
    mergedConfig = Xpp3DomUtils.mergeXpp3Dom(mergedConfig, globalConfig);
    PluginDescriptor pluginDescriptor = this.pluginManager.loadPlugin(plugin, project.getRemotePluginRepositories(), this.repositorySystemSession);
    MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo("start");
    MojoExecution mojoExecution = new MojoExecution(mojoDescriptor, mergedConfig);
    mavenSession.setCurrentProject(project);
    this.pluginManager.executeMojo(mavenSession, mojoExecution);
    List<SwarmProcess> launched = (List<SwarmProcess>) mavenSession.getPluginContext(pluginDescriptor, project).get(SWARM_PROCESS);
    List<SwarmProcess> procs = (List<SwarmProcess>) getPluginContext().get(SWARM_PROCESS);
    if (procs == null) {
        procs = new ArrayList<>();
        getPluginContext().put(SWARM_PROCESS, procs);
    }
    procs.addAll(launched);
    mavenSession.setCurrentProject(this.project);
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) MojoExecution(org.apache.maven.plugin.MojoExecution) ArrayList(java.util.ArrayList) List(java.util.List) SwarmProcess(org.wildfly.swarm.tools.exec.SwarmProcess) Plugin(org.apache.maven.model.Plugin)

Example 12 with PluginDescriptor

use of org.apache.maven.plugin.descriptor.PluginDescriptor in project maven-plugins by apache.

the class CheckstyleReportTest method generateReport.

private File generateReport(String pluginXml) throws Exception {
    File pluginXmlFile = new File(getBasedir(), "src/test/plugin-configs/" + pluginXml);
    ResourceBundle bundle = ResourceBundle.getBundle("checkstyle-report", Locale.getDefault(), this.getClassLoader());
    CheckstyleReport mojo = (CheckstyleReport) lookupMojo("checkstyle", pluginXmlFile);
    assertNotNull("Mojo found.", mojo);
    PluginDescriptor descriptorStub = new PluginDescriptor();
    descriptorStub.setGroupId("org.apache.maven.plugins");
    descriptorStub.setArtifactId("maven-checkstyle-plugin");
    setVariableValueToObject(mojo, "plugin", descriptorStub);
    mojo.execute();
    File outputFile = (File) getVariableValueFromObject(mojo, "outputFile");
    assertNotNull("Test output file", outputFile);
    assertTrue("Test output file exists", outputFile.exists());
    String cacheFile = (String) getVariableValueFromObject(mojo, "cacheFile");
    if (cacheFile != null) {
        assertTrue("Test cache file exists", new File(cacheFile).exists());
    }
    MavenReport reportMojo = mojo;
    File outputDir = reportMojo.getReportOutputDirectory();
    Boolean rss = (Boolean) getVariableValueFromObject(mojo, "enableRSS");
    if (rss) {
        File rssFile = new File(outputDir, "checkstyle.rss");
        assertTrue("Test rss file exists", rssFile.exists());
    }
    File useFile = (File) getVariableValueFromObject(mojo, "useFile");
    if (useFile != null) {
        assertTrue("Test useFile exists", useFile.exists());
    }
    String filename = reportMojo.getOutputName() + ".html";
    File outputHtml = new File(outputDir, filename);
    renderer(mojo, outputHtml);
    assertTrue(outputHtml.getAbsolutePath() + " not generated!", outputHtml.exists());
    assertTrue(outputHtml.getAbsolutePath() + " is empty!", outputHtml.length() > 0);
    String htmlString = FileUtils.fileRead(outputHtml);
    boolean searchHeaderFound = (htmlString.indexOf("<h2>" + bundle.getString("report.checkstyle.rules")) > 0);
    Boolean rules = (Boolean) getVariableValueFromObject(mojo, "enableRulesSummary");
    if (rules) {
        assertTrue("Test for Rules Summary", searchHeaderFound);
    } else {
        assertFalse("Test for Rules Summary", searchHeaderFound);
    }
    searchHeaderFound = (htmlString.indexOf("<h2>" + bundle.getString("report.checkstyle.summary")) > 0);
    Boolean severity = (Boolean) getVariableValueFromObject(mojo, "enableSeveritySummary");
    if (severity) {
        assertTrue("Test for Severity Summary", searchHeaderFound);
    } else {
        assertFalse("Test for Severity Summary", searchHeaderFound);
    }
    searchHeaderFound = (htmlString.indexOf("<h2>" + bundle.getString("report.checkstyle.files")) > 0);
    Boolean files = (Boolean) getVariableValueFromObject(mojo, "enableFilesSummary");
    if (files) {
        assertTrue("Test for Files Summary", searchHeaderFound);
    } else {
        assertFalse("Test for Files Summary", searchHeaderFound);
    }
    return outputHtml;
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MavenReport(org.apache.maven.reporting.MavenReport) CheckstyleReport(org.apache.maven.plugins.checkstyle.CheckstyleReport) ResourceBundle(java.util.ResourceBundle) File(java.io.File)

Example 13 with PluginDescriptor

use of org.apache.maven.plugin.descriptor.PluginDescriptor 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 14 with PluginDescriptor

use of org.apache.maven.plugin.descriptor.PluginDescriptor 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 15 with PluginDescriptor

use of org.apache.maven.plugin.descriptor.PluginDescriptor 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

PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)25 Plugin (org.apache.maven.model.Plugin)12 File (java.io.File)7 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 MavenProject (org.apache.maven.project.MavenProject)5 IOException (java.io.IOException)3 URLClassLoader (java.net.URLClassLoader)3 Artifact (org.apache.maven.artifact.Artifact)3 MavenSession (org.apache.maven.execution.MavenSession)3 MojoDescriptorCreator (org.apache.maven.lifecycle.internal.MojoDescriptorCreator)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 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 ArrayList (java.util.ArrayList)2