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<String>();
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 JavadocReportTest method lookupMojo.
private JavadocReport lookupMojo(File testPom) throws Exception {
JavadocReport mojo = (JavadocReport) lookupMojo("javadoc", testPom);
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setPlugin(new Plugin());
setVariableValueToObject(mojo, "plugin", pluginDescriptor);
return mojo;
}
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);
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setPlugin(new Plugin());
setVariableValueToObject(mojo, "plugin", pluginDescriptor);
mojo.execute();
File generatedFile = new File(getBasedir(), "target/test/unit/test-javadoc-test/target/site/apidocs/maven/AppTest.html");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
}
use of org.apache.maven.model.Plugin in project intellij-plugins by JetBrains.
the class IdeaConfigurationMojo method generateForProject.
private void generateForProject(MavenProject project, List<String> configurators) throws Exception {
MojoExecution flexmojosMojoExecution = null;
MojoExecution flexmojosGeneratorMojoExecution = null;
for (Plugin plugin : project.getBuildPlugins()) {
if (plugin.getGroupId().equals("org.sonatype.flexmojos")) {
if (flexmojosMojoExecution == null && plugin.getArtifactId().equals("flexmojos-maven-plugin")) {
flexmojosMojoExecution = createMojoExecution(plugin, getCompileGoalName(project), project);
} else if (flexmojosGeneratorMojoExecution == null && plugin.getArtifactId().equals("flexmojos-generator-mojo")) {
flexmojosGeneratorMojoExecution = createMojoExecution(plugin, "generate", project);
}
if (flexmojosMojoExecution != null && flexmojosGeneratorMojoExecution != null) {
break;
}
}
}
if (flexmojosMojoExecution == null) {
return;
}
ClassRealm flexmojosPluginRealm = pluginManager.getPluginRealm(session, flexmojosMojoExecution.getMojoDescriptor().getPluginDescriptor());
final ClassLoader classLoader = getClass().getClassLoader();
flexmojosPluginRealm.addURL(new URL(session.getLocalRepository().getUrl() + "com/intellij/flex/maven/idea-configurator/1.5.4/idea-configurator-1.5.4.jar"));
flexmojosPluginRealm.importFrom(classLoader, "com.intellij.flex.maven.FlexConfigGenerator");
flexmojosPluginRealm.importFrom(classLoader, "com.intellij.flex.maven.Utils");
Mojo mojo = null;
try {
mojo = mavenPluginManager.getConfiguredMojo(Mojo.class, session, flexmojosMojoExecution);
for (String configuratorClassName : configurators) {
Class configuratorClass = flexmojosPluginRealm.loadClass(configuratorClassName);
FlexConfigGenerator configurator = (FlexConfigGenerator) configuratorClass.getConstructor(MavenSession.class, File.class).newInstance(session, null);
configurator.preGenerate(project, Flexmojos.getClassifier(mojo));
if ("swc".equals(project.getPackaging())) {
configurator.generate(mojo);
} else {
configurator.generate(mojo, Flexmojos.getSourceFileForSwf(mojo));
}
configurator.postGenerate(project);
}
} finally {
mavenPluginManager.releaseMojo(mojo, mojoExecution);
}
}
use of org.apache.maven.model.Plugin in project sling by apache.
the class MavenBundlePluginProjectConfigurator method isSupportingM2eIncrementalBuild.
@Override
protected boolean isSupportingM2eIncrementalBuild(MavenProject mavenProject, Logger logger) {
Plugin bundlePlugin = mavenProject.getPlugin(MAVEN_BUNDLE_PLUGIN_KEY);
if (bundlePlugin == null) {
logger.warn("maven-bundle-plugin not configured!");
return false;
} else {
// check if m2elipse-tycho is already installed (which supports incremental builds for "bundle" packagings
if (LifecycleMappingFactory.createProjectConfigurator(M2E_TYCHO_EXTENSION_PROJECT_CONFIGURATOR_ID) != null) {
logger.trace("Project configurator with id '" + M2E_TYCHO_EXTENSION_PROJECT_CONFIGURATOR_ID + "' found -> m2e-tycho installed.");
return true;
}
String version = bundlePlugin.getVersion();
if (version == null) {
logger.warn("Could not retrieve used version of maven-bundle-plugin!");
return false;
}
ComparableVersion comparableVersion = new ComparableVersion(version);
// with https://issues.apache.org/jira/browse/FELIX-4009 m2e support for incremental builds was added to maven-bundle-plugin in version 3.2.0
if (comparableVersion.compareTo(new ComparableVersion("3.2.0")) >= 0) {
// therefore check configuration
for (PluginExecution pluginExecution : bundlePlugin.getExecutions()) {
if (!pluginExecution.getGoals().contains("manifest")) {
continue;
}
Xpp3Dom configuration = (Xpp3Dom) pluginExecution.getConfiguration();
Xpp3Dom supportIncrementalBuildConfiguration = configuration.getChild("supportIncrementalBuild");
// https://issues.apache.org/jira/browse/FELIX-3324
Xpp3Dom exportScrConfiguration = configuration.getChild("exportScr");
if (supportIncrementalBuildConfiguration == null || !Boolean.parseBoolean(supportIncrementalBuildConfiguration.getValue())) {
logger.warn("Although using maven-bundle-plugin in a version >= 3.2.0, the incremental build support was not enabled.");
} else if (exportScrConfiguration == null || !Boolean.parseBoolean(exportScrConfiguration.getValue())) {
logger.warn("Although using maven-bundle-plugin in a version >= 3.2.0 with incremental build support enabled, component descriptors are not exported (exportScr=false) .");
} else {
logger.trace("Using maven-bundle-plugin in a version >= 3.2.0 with the incremental build support correctly enabled.");
return true;
}
}
} else {
logger.warn("maven-bundle-plugin in a version < 3.2.0 does not natively support incremental builds.");
}
}
return false;
}
Aggregations