Search in sources :

Example 21 with PluginDescriptor

use of org.apache.maven.plugin.descriptor.PluginDescriptor 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()));
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) File(java.io.File) Plugin(org.apache.maven.model.Plugin)

Example 22 with PluginDescriptor

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

the class ScalaCompilerSupport method getAnalysisCacheMap.

protected Map<File, File> getAnalysisCacheMap() {
    HashMap<File, File> map = new HashMap<File, File>();
    String scalaPluginKey = ((PluginDescriptor) getPluginContext().get("pluginDescriptor")).getPluginLookupKey();
    for (MavenProject project1 : reactorProjects) {
        Plugin plugin = project1.getPlugin(scalaPluginKey);
        if (plugin != null) {
            Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
            Xpp3Dom analysisCache = (configuration != null) ? configuration.getChild("analysisCacheFile") : null;
            File analysisCacheFile = (analysisCache != null) ? new File(analysisCache.getValue()) : defaultAnalysisCacheFile(project1);
            File classesDirectory = new File(project1.getBuild().getOutputDirectory());
            map.put(classesDirectory.getAbsoluteFile(), analysisCacheFile.getAbsoluteFile());
            Xpp3Dom testAnalysisCache = (configuration != null) ? configuration.getChild("testAnalysisCacheFile") : null;
            File testAnalysisCacheFile = (testAnalysisCache != null) ? new File(testAnalysisCache.getValue()) : defaultTestAnalysisCacheFile(project1);
            File testClassesDirectory = new File(project1.getBuild().getTestOutputDirectory());
            map.put(testClassesDirectory.getAbsoluteFile(), testAnalysisCacheFile.getAbsoluteFile());
        }
    }
    return map;
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File) Plugin(org.apache.maven.model.Plugin)

Example 23 with PluginDescriptor

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

the class CheckstyleViolationCheckMojoTest method doTestPlainOutputFile.

private void doTestPlainOutputFile(boolean failsOnError) throws Exception {
    File pluginXmlFile = new File(getBasedir(), "src/test/plugin-configs/check-plugin-plain-output.xml");
    Mojo mojo = lookupMojo("check", pluginXmlFile);
    assertNotNull("Mojo found.", mojo);
    PluginDescriptor descriptorStub = new PluginDescriptor();
    descriptorStub.setGroupId("org.apache.maven.plugins");
    descriptorStub.setArtifactId("maven-checkstyle-plugin");
    setVariableValueToObject(mojo, "plugin", descriptorStub);
    setVariableValueToObject(mojo, "failsOnError", failsOnError);
    mojo.execute();
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) Mojo(org.apache.maven.plugin.Mojo) CheckstyleViolationCheckMojo(org.apache.maven.plugins.checkstyle.CheckstyleViolationCheckMojo) File(java.io.File)

Example 24 with PluginDescriptor

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

the class CompilerMojoTestCase method getMockMojoExecution.

private MojoExecution getMockMojoExecution() {
    MojoDescriptor md = new MojoDescriptor();
    md.setGoal("compile");
    MojoExecution me = new MojoExecution(md);
    PluginDescriptor pd = new PluginDescriptor();
    pd.setArtifactId("maven-compiler-plugin");
    md.setPluginDescriptor(pd);
    return me;
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) MojoExecution(org.apache.maven.plugin.MojoExecution)

Example 25 with PluginDescriptor

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

the class DescribeMojo method isReportGoal.

/**
 * Determines if this Mojo should be used as a report or not. This resolves the plugin project along with all of its
 * transitive dependencies to determine if the Java class of this goal implements <code>MavenReport</code>.
 *
 * @param md Mojo descriptor
 * @return Whether or not this goal should be used as a report.
 */
private boolean isReportGoal(MojoDescriptor md) {
    PluginDescriptor pd = md.getPluginDescriptor();
    List<URL> urls = new ArrayList<URL>();
    ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
    pbr.setRemoteRepositories(remoteRepositories);
    pbr.setResolveDependencies(true);
    pbr.setProject(null);
    pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
    try {
        Artifact jar = artifactResolver.resolveArtifact(pbr, toArtifactCoordinate(pd, "jar")).getArtifact();
        Artifact pom = artifactResolver.resolveArtifact(pbr, toArtifactCoordinate(pd, "pom")).getArtifact();
        MavenProject project = projectBuilder.build(pom.getFile(), pbr).getProject();
        urls.add(jar.getFile().toURI().toURL());
        for (Object artifact : project.getCompileClasspathElements()) {
            urls.add(new File((String) artifact).toURI().toURL());
        }
        ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader());
        return MavenReport.class.isAssignableFrom(Class.forName(md.getImplementation(), false, classLoader));
    } catch (Exception e) {
        getLog().warn("Couldn't identify if this goal is a report goal: " + e.getMessage());
        return false;
    }
}
Also used : ArrayList(java.util.ArrayList) URL(java.net.URL) Artifact(org.apache.maven.artifact.Artifact) PluginVersionResolutionException(org.apache.maven.plugin.version.PluginVersionResolutionException) NoPluginFoundForPrefixException(org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) MavenProject(org.apache.maven.project.MavenProject) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

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