Search in sources :

Example 1 with Parameter

use of org.apache.maven.plugin.descriptor.Parameter 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 Parameter

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

the class DescribeMojoTest method testValidExpression.

public void testValidExpression() throws Exception {
    StringBuilder sb = new StringBuilder();
    MojoDescriptor md = new MojoDescriptor();
    Parameter parameter = new Parameter();
    parameter.setName("name");
    parameter.setExpression("${valid.expression}");
    md.addParameter(parameter);
    String ls = System.getProperty("line.separator");
    try {
        PrivateAccessor.invoke(new DescribeMojo(), "describeMojoParameters", new Class[] { MojoDescriptor.class, StringBuilder.class }, new Object[] { md, sb });
        assertEquals("  Available parameters:" + ls + ls + "    name" + ls + "      User property: valid.expression" + ls + "      (no description available)" + ls, sb.toString());
    } catch (Throwable e) {
        fail(e.getMessage());
    }
}
Also used : MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) Parameter(org.apache.maven.plugin.descriptor.Parameter)

Example 3 with Parameter

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

the class DescribeMojo method describeMojoParameters.

/**
     * Displays parameter information of the Plugin Mojo
     *
     * @param md     contains the description of the Plugin Mojo
     * @param buffer contains information to be printed or displayed
     * @throws MojoFailureException   if any reflection exceptions occur.
     * @throws MojoExecutionException if any
     */
private void describeMojoParameters(MojoDescriptor md, StringBuilder buffer) throws MojoFailureException, MojoExecutionException {
    List<Parameter> params = md.getParameters();
    if (params == null || params.isEmpty()) {
        append(buffer, "This mojo doesn't use any parameters.", 1);
        return;
    }
    params = new ArrayList<Parameter>(params);
    PluginUtils.sortMojoParameters(params);
    append(buffer, "Available parameters:", 1);
    // indent 2
    for (Parameter parameter : params) {
        if (!parameter.isEditable()) {
            continue;
        }
        buffer.append(LS);
        // DGF wouldn't it be nice if this worked?
        String defaultVal = parameter.getDefaultValue();
        if (defaultVal == null) {
            // defaultVal is ALWAYS null, this is a bug in PluginDescriptorBuilder (cf. MNG-4941)
            defaultVal = md.getMojoConfiguration().getChild(parameter.getName()).getAttribute("default-value", null);
        }
        if (StringUtils.isNotEmpty(defaultVal)) {
            defaultVal = " (Default: " + defaultVal + ")";
        } else {
            defaultVal = "";
        }
        append(buffer, parameter.getName() + defaultVal, 2);
        if (parameter.isRequired()) {
            append(buffer, "Required", "true", 3);
        }
        String expression = parameter.getExpression();
        if (StringUtils.isEmpty(expression)) {
            // expression is ALWAYS null, this is a bug in PluginDescriptorBuilder (cf. MNG-4941).
            // Fixed with Maven-3.0.1
            expression = md.getMojoConfiguration().getChild(parameter.getName()).getValue(null);
        }
        if (StringUtils.isNotEmpty(expression)) {
            Matcher matcher = EXPRESSION.matcher(expression);
            if (matcher.matches()) {
                append(buffer, "User property", matcher.group(1), 3);
            } else {
                append(buffer, "Expression", expression, 3);
            }
        }
        append(buffer, toDescription(parameter.getDescription()), 3);
        String deprecation = parameter.getDeprecated();
        if (deprecation != null && deprecation.length() <= 0) {
            deprecation = NO_REASON;
        }
        if (StringUtils.isNotEmpty(deprecation)) {
            append(buffer, "Deprecated. " + deprecation, 3);
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) Parameter(org.apache.maven.plugin.descriptor.Parameter)

Example 4 with Parameter

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

the class DescribeMojoTest method testInvalidExpression.

public void testInvalidExpression() throws Exception {
    StringBuilder sb = new StringBuilder();
    MojoDescriptor md = new MojoDescriptor();
    Parameter parameter = new Parameter();
    parameter.setName("name");
    //this is a defaultValue
    parameter.setExpression("${project.build.directory}/generated-sources/foobar");
    md.addParameter(parameter);
    String ls = System.getProperty("line.separator");
    try {
        PrivateAccessor.invoke(new DescribeMojo(), "describeMojoParameters", new Class[] { MojoDescriptor.class, StringBuilder.class }, new Object[] { md, sb });
        assertEquals("  Available parameters:" + ls + ls + "    name" + ls + "      Expression: ${project.build.directory}/generated-sources/foobar" + ls + "      (no description available)" + ls, sb.toString());
    } catch (Throwable e) {
        fail(e.getMessage());
    }
}
Also used : MojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor) Parameter(org.apache.maven.plugin.descriptor.Parameter)

Aggregations

Parameter (org.apache.maven.plugin.descriptor.Parameter)4 MojoDescriptor (org.apache.maven.plugin.descriptor.MojoDescriptor)3 Matcher (java.util.regex.Matcher)1 InvalidPluginDescriptorException (org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException)1 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)1 ExtractionException (org.apache.maven.tools.plugin.extractor.ExtractionException)1