use of org.apache.maven.model.Plugin 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());
}
use of org.apache.maven.model.Plugin in project maven-plugins by apache.
the class AbstractJavadocMojo method getResource.
/**
* @param outputFile not nul
* @param inputResourceName a not null resource in <code>src/main/java</code>, <code>src/main/resources</code> or
* <code>src/main/javadoc</code> or in the Javadoc plugin dependencies.
* @return the resource file absolute path as String
* @since 2.6
*/
private String getResource(File outputFile, String inputResourceName) {
if (inputResourceName.startsWith("/")) {
inputResourceName = inputResourceName.replaceFirst("//*", "");
}
List<String> classPath = new ArrayList<>();
classPath.add(project.getBuild().getSourceDirectory());
URL resourceURL = getResource(classPath, inputResourceName);
if (resourceURL != null) {
getLog().debug(inputResourceName + " found in the main src directory of the project.");
return FileUtils.toFile(resourceURL).getAbsolutePath();
}
classPath.clear();
List<Resource> resources = project.getBuild().getResources();
for (Resource resource : resources) {
classPath.add(resource.getDirectory());
}
resourceURL = getResource(classPath, inputResourceName);
if (resourceURL != null) {
getLog().debug(inputResourceName + " found in the main resources directories of the project.");
return FileUtils.toFile(resourceURL).getAbsolutePath();
}
if (javadocDirectory.exists()) {
classPath.clear();
classPath.add(javadocDirectory.getAbsolutePath());
resourceURL = getResource(classPath, inputResourceName);
if (resourceURL != null) {
getLog().debug(inputResourceName + " found in the main javadoc directory of the project.");
return FileUtils.toFile(resourceURL).getAbsolutePath();
}
}
classPath.clear();
final String pluginId = "org.apache.maven.plugins:maven-javadoc-plugin";
Plugin javadocPlugin = getPlugin(project, pluginId);
if (javadocPlugin != null && javadocPlugin.getDependencies() != null) {
List<Dependency> dependencies = javadocPlugin.getDependencies();
for (Dependency dependency : dependencies) {
JavadocPathArtifact javadocPathArtifact = new JavadocPathArtifact();
javadocPathArtifact.setGroupId(dependency.getGroupId());
javadocPathArtifact.setArtifactId(dependency.getArtifactId());
javadocPathArtifact.setVersion(dependency.getVersion());
Artifact artifact = null;
try {
artifact = createAndResolveArtifact(javadocPathArtifact);
} catch (Exception e) {
logError("Unable to retrieve the dependency: " + dependency + ". Ignored.", e);
}
if (artifact != null && artifact.getFile().exists()) {
classPath.add(artifact.getFile().getAbsolutePath());
}
}
resourceURL = getResource(classPath, inputResourceName);
if (resourceURL != null) {
getLog().debug(inputResourceName + " found in javadoc plugin dependencies.");
try {
JavadocUtil.copyResource(resourceURL, outputFile);
return outputFile.getAbsolutePath();
} catch (IOException e) {
logError("IOException: " + e.getMessage(), e);
}
}
}
getLog().warn("Unable to find the resource '" + inputResourceName + "'. Using default Javadoc resources.");
return null;
}
use of org.apache.maven.model.Plugin in project maven-plugins by apache.
the class TestJavadocReportTest method testTestJavadoc.
/**
* Test the test-javadoc configuration for the plugin
*
* @throws Exception if any
*/
public void testTestJavadoc() throws Exception {
File testPom = new File(getBasedir(), "src/test/resources/unit/test-javadoc-test/test-javadoc-test-plugin-config.xml");
TestJavadocReport mojo = (TestJavadocReport) lookupMojo("test-javadoc", testPom);
MojoExecution mojoExec = new MojoExecution(new Plugin(), "test-javadoc", null);
setVariableValueToObject(mojo, "mojo", mojoExec);
MavenProject currentProject = new MavenProjectStub();
currentProject.setGroupId("GROUPID");
currentProject.setArtifactId("ARTIFACTID");
setVariableValueToObject(mojo, "session", newMavenSession(currentProject));
mojo.execute();
File generatedFile = new File(getBasedir(), "target/test/unit/test-javadoc-test/target/site/apidocs/maven/AppTest.html");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
File options = new File(getBasedir(), "target/test/unit/test-javadoc-test/target/site/apidocs/options");
FileUtils.fileRead(options).contains("junit-3.8.1.jar");
}
use of org.apache.maven.model.Plugin in project maven-plugins by apache.
the class MavenJDOMWriter method iteratePlugin.
// -- void iterateNotifier(Counter, Element, java.util.Collection, java.lang.String, java.lang.String)
/**
* Method iteratePlugin
*
* @param counter
* @param childTag
* @param parentTag
* @param list
* @param parent
*/
protected void iteratePlugin(Counter counter, Element parent, Collection<Plugin> list, java.lang.String parentTag, java.lang.String childTag) {
boolean shouldExist = list != null && list.size() > 0;
Element element = updateElement(counter, parent, parentTag, shouldExist);
if (shouldExist) {
Iterator<?> elIt = element.getChildren(childTag, element.getNamespace()).iterator();
if (!elIt.hasNext()) {
elIt = null;
}
Counter innerCount = new Counter(counter.getDepth() + 1);
for (Plugin value : list) {
Element el;
if (elIt != null && elIt.hasNext()) {
el = (Element) elIt.next();
if (!elIt.hasNext()) {
elIt = null;
}
} else {
el = factory.element(childTag, element.getNamespace());
insertAtPreferredLocation(element, el, innerCount);
}
updatePlugin(value, childTag, innerCount, el);
innerCount.increaseCount();
}
if (elIt != null) {
while (elIt.hasNext()) {
elIt.next();
elIt.remove();
}
}
}
}
use of org.apache.maven.model.Plugin in project bndtools by bndtools.
the class MavenWorkspaceRepository method getBundleFile.
private File getBundleFile(final MavenProject mavenProject) {
String finalName = null;
// first check maven-jar-plugin config first, if it is empty use project.build.finalName
Plugin jarPlugin = mavenProject.getPlugin("org.apache.maven.plugins:maven-jar-plugin");
if (jarPlugin != null) {
Object config = jarPlugin.getConfiguration();
if (config instanceof Xpp3Dom) {
Xpp3Dom dom = (Xpp3Dom) config;
Xpp3Dom finalNameNode = dom.getChild("finalName");
if (finalNameNode != null) {
finalName = finalNameNode.getValue();
}
}
}
if (finalName == null) {
finalName = mavenProject.getBuild().getFinalName();
}
return new File(mavenProject.getBuild().getDirectory(), finalName + ".jar");
}
Aggregations