Search in sources :

Example 1 with MojoDescriptor

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

the class CheckPluginDocumentationMojo method checkPackagingSpecificDocumentation.

protected void checkPackagingSpecificDocumentation(MavenProject project, DocumentationReporter reporter) {
    PluginDescriptor descriptor = new PluginDescriptor();
    try {
        mojoScanner.populatePluginDescriptor(project, descriptor);
    } catch (InvalidPluginDescriptorException e) {
        reporter.error("Failed to parse mojo descriptors.\nError: " + e.getMessage());
        descriptor = null;
    } catch (ExtractionException e) {
        reporter.error("Failed to parse mojo descriptors.\nError: " + e.getMessage());
        descriptor = null;
    }
    if (descriptor != null) {
        @SuppressWarnings("unchecked") List<MojoDescriptor> mojos = descriptor.getMojos();
        // ensure that all mojo classes are documented
        if (mojos != null && !mojos.isEmpty()) {
            for (MojoDescriptor mojo : mojos) {
                String mojoDescription = mojo.getDescription();
                if (mojoDescription == null || mojoDescription.trim().length() < MIN_DESCRIPTION_LENGTH) {
                    reporter.error("Mojo: \'" + mojo.getGoal() + "\' is missing a description.");
                }
                @SuppressWarnings("unchecked") List<Parameter> params = mojo.getParameters();
                // ensure that all parameters are documented
                if (params != null && !params.isEmpty()) {
                    for (Parameter param : params) {
                        if (param.getRequirement() == null && param.isEditable()) {
                            String paramDescription = param.getDescription();
                            if (paramDescription == null || paramDescription.trim().length() < MIN_DESCRIPTION_LENGTH) {
                                reporter.error("Parameter: \'" + param.getName() + "\' in mojo: \'" + mojo.getGoal() + "\' is missing a description.");
                            }
                        }
                    }
                }
            }
        }
    }
    checkConfiguredReportPlugins(project, reporter);
    checkProjectSite(project, reporter);
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) ExtractionException(org.apache.maven.tools.plugin.extractor.ExtractionException) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) InvalidPluginDescriptorException(org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException) Parameter(org.apache.maven.plugin.descriptor.Parameter)

Example 2 with MojoDescriptor

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

the class PdfMojo method generateMavenReports.

/**
     * Generate all Maven reports defined in <code>${project.reporting}</code> part
     * only if <code>generateReports</code> is enabled.
     *
     * @param locale not null
     * @throws MojoExecutionException if any
     * @throws IOException if any
     * @since 1.1
     */
private void generateMavenReports(Locale locale) throws MojoExecutionException, IOException {
    if (!includeReports) {
        getLog().info("Skipped report generation.");
        return;
    }
    if (project.getReporting() == null) {
        getLog().info("No report was specified.");
        return;
    }
    for (final ReportPlugin reportPlugin : project.getReporting().getPlugins()) {
        final PluginDescriptor pluginDescriptor = getPluginDescriptor(reportPlugin);
        if (pluginDescriptor != null) {
            List<String> goals = new ArrayList<String>(8);
            for (final ReportSet reportSet : reportPlugin.getReportSets()) {
                for (String goal : reportSet.getReports()) {
                    goals.add(goal);
                }
            }
            List mojoDescriptors = pluginDescriptor.getMojos();
            for (Object mojoDescriptor1 : mojoDescriptors) {
                final MojoDescriptor mojoDescriptor = (MojoDescriptor) mojoDescriptor1;
                if (goals.isEmpty() || (!goals.isEmpty() && goals.contains(mojoDescriptor.getGoal()))) {
                    MavenReport report = getMavenReport(mojoDescriptor);
                    generateMavenReport(report, mojoDescriptor.getPluginDescriptor().getPluginArtifact(), locale);
                }
            }
        }
    }
    // generate project-info report
    if (!getGeneratedMavenReports(locale).isEmpty()) {
        File outDir = new File(getGeneratedSiteDirectoryTmp(), "xdoc");
        if (!locale.getLanguage().equals(defaultLocale.getLanguage())) {
            outDir = new File(new File(getGeneratedSiteDirectoryTmp(), locale.getLanguage()), "xdoc");
        }
        outDir.mkdirs();
        File piReport = new File(outDir, "project-info.xml");
        StringWriter sw = new StringWriter();
        PdfSink sink = new PdfSink(sw);
        ProjectInfoRenderer r = new ProjectInfoRenderer(sink, getGeneratedMavenReports(locale), i18n, locale);
        r.render();
        writeGeneratedReport(sw.toString(), piReport);
    }
    // copy generated site
    copySiteDir(getGeneratedSiteDirectoryTmp(), getSiteDirectoryTmp());
    copySiteDir(generatedSiteDirectory, getSiteDirectoryTmp());
}
Also used : MavenReport(org.apache.maven.reporting.MavenReport) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) ArrayList(java.util.ArrayList) ReportSet(org.apache.maven.model.ReportSet) PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) ReportPlugin(org.apache.maven.model.ReportPlugin) StringWriter(java.io.StringWriter) List(java.util.List) ArrayList(java.util.ArrayList) MailingList(org.apache.maven.model.MailingList) File(java.io.File)

Example 3 with MojoDescriptor

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

the class EvaluateMojo method getEvaluator.

/**
     * @return a lazy loading evaluator object.
     * @throws MojoExecutionException if any
     * @throws MojoFailureException if any reflection exceptions occur or missing components.
     */
private PluginParameterExpressionEvaluator getEvaluator() throws MojoExecutionException, MojoFailureException {
    if (evaluator == null) {
        MojoDescriptor mojoDescriptor;
        try {
            mojoDescriptor = mojoDescriptorCreator.getMojoDescriptor("help:evaluate", session, project);
        } catch (Exception e) {
            throw new MojoFailureException("Failure while evaluating.", e);
        }
        MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
        MavenProject currentProject = session.getCurrentProject();
        // synchronize in case another thread wants to fetch the real current project in between
        synchronized (session) {
            session.setCurrentProject(project);
            evaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
            session.setCurrentProject(currentProject);
        }
    }
    return evaluator;
}
Also used : MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) PluginParameterExpressionEvaluator(org.apache.maven.plugin.PluginParameterExpressionEvaluator) MavenProject(org.apache.maven.project.MavenProject) MojoExecution(org.apache.maven.plugin.MojoExecution) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ExpressionEvaluationException(org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 4 with MojoDescriptor

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

the class DescribeMojo method describePlugin.

/**
     * Method for retrieving the plugin description
     *
     * @param pd     contains the plugin description
     * @param buffer contains the information to be displayed or printed
     * @throws MojoFailureException   if any reflection exceptions occur.
     * @throws MojoExecutionException if any
     */
private void describePlugin(PluginDescriptor pd, StringBuilder buffer) throws MojoFailureException, MojoExecutionException {
    append(buffer, pd.getId(), 0);
    buffer.append(LS);
    String name = pd.getName();
    if (name == null) {
        // Can be null because of MPLUGIN-137 (and descriptors generated with maven-plugin-tools-api <= 2.4.3)
        ArtifactCoordinate coordinate = toArtifactCoordinate(pd, "jar");
        ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(session.getProjectBuildingRequest());
        pbr.setRemoteRepositories(remoteRepositories);
        pbr.setProject(null);
        pbr.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
        try {
            Artifact artifact = artifactResolver.resolveArtifact(pbr, coordinate).getArtifact();
            name = projectBuilder.build(artifact, pbr).getProject().getName();
        } catch (Exception e) {
            // oh well, we tried our best.
            getLog().warn("Unable to get the name of the plugin " + pd.getId() + ": " + e.getMessage());
            name = pd.getId();
        }
    }
    append(buffer, "Name", name, 0);
    appendAsParagraph(buffer, "Description", toDescription(pd.getDescription()), 0);
    append(buffer, "Group Id", pd.getGroupId(), 0);
    append(buffer, "Artifact Id", pd.getArtifactId(), 0);
    append(buffer, "Version", pd.getVersion(), 0);
    append(buffer, "Goal Prefix", pd.getGoalPrefix(), 0);
    buffer.append(LS);
    List<MojoDescriptor> mojos = pd.getMojos();
    if (mojos == null) {
        append(buffer, "This plugin has no goals.", 0);
        return;
    }
    if ((detail || medium) && !minimal) {
        append(buffer, "This plugin has " + mojos.size() + " goal" + (mojos.size() > 1 ? "s" : "") + ":", 0);
        buffer.append(LS);
        mojos = new ArrayList<MojoDescriptor>(mojos);
        PluginUtils.sortMojos(mojos);
        for (MojoDescriptor md : mojos) {
            if (detail) {
                describeMojoGuts(md, buffer, true);
            } else {
                describeMojoGuts(md, buffer, false);
            }
            buffer.append(LS);
        }
    }
    if (!detail) {
        buffer.append("For more information, run 'mvn help:describe [...] -Ddetail'");
        buffer.append(LS);
    }
}
Also used : ArtifactCoordinate(org.apache.maven.shared.artifact.ArtifactCoordinate) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) 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)

Example 5 with MojoDescriptor

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

the class DescribeMojo method execute.

// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
/**
     * {@inheritDoc}
     */
public void execute() throws MojoExecutionException, MojoFailureException {
    validateParameters();
    StringBuilder descriptionBuffer = new StringBuilder();
    boolean describePlugin = true;
    if (StringUtils.isNotEmpty(cmd)) {
        describePlugin = describeCommand(descriptionBuffer);
    }
    if (describePlugin) {
        PluginInfo pi = parsePluginLookupInfo();
        PluginDescriptor descriptor = lookupPluginDescriptor(pi);
        if (StringUtils.isNotEmpty(goal)) {
            MojoDescriptor mojo = descriptor.getMojo(goal);
            if (mojo == null) {
                throw new MojoFailureException("The mojo '" + goal + "' does not exist in the plugin '" + pi.getPrefix() + "'");
            }
            describeMojo(mojo, descriptionBuffer);
        } else {
            describePlugin(descriptor, descriptionBuffer);
        }
    }
    writeDescription(descriptionBuffer);
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Aggregations

MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)11 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)4 IOException (java.io.IOException)3 MojoExecution (org.apache.maven.plugin.MojoExecution)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 Parameter (org.apache.maven.plugin.descriptor.Parameter)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 NoPluginFoundForPrefixException (org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException)2 PluginVersionResolutionException (org.apache.maven.plugin.version.PluginVersionResolutionException)2 File (java.io.File)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StringTokenizer (java.util.StringTokenizer)1 Artifact (org.apache.maven.artifact.Artifact)1 Lifecycle (org.apache.maven.lifecycle.Lifecycle)1 LifecycleExecutionPlanCalculator (org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator)1 MailingList (org.apache.maven.model.MailingList)1 PluginExecution (org.apache.maven.model.PluginExecution)1