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);
}
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;
}
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());
}
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());
}
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());
}
Aggregations