Java 类org.apache.maven.plugin.descriptor.Parameter 实例源码

项目:maven-confluence-plugin    文件:PluginConfluenceDocGenerator.java   
/**
 *
 * @param parameterList
 * @return
 */
private List<Parameter> filterParameters(List<Parameter> parameterList) {
    List<Parameter> filtered = new ArrayList<Parameter>();

    if (parameterList != null) {
        for (Parameter parameter : parameterList) {

            if (parameter.isEditable()) {
                String expression = parameter.getExpression();

                if (expression == null || !expression.startsWith("${component.")) {
                    filtered.add(parameter);
                }
            }
        }
    }

    return filtered;
}
项目:takari-lifecycle    文件:LegacyPluginDescriptors.java   
private static MojoParameter toMojoParameter(Parameter parameter) {
  MojoParameter result = new MojoParameter();

  result.setName(parameter.getName());
  result.setAlias(parameter.getAlias());
  result.setType(parameter.getType());
  result.setRequired(parameter.isRequired());
  result.setEditable(parameter.isEditable());
  result.setDescription(parameter.getDescription());
  result.setDeprecated(parameter.getDeprecated());
  result.setSince(parameter.getSince());
  result.setImplementation(parameter.getImplementation());
  result.setDefaultValue(parameter.getDefaultValue());
  result.setExpression(parameter.getExpression());

  return result;
}
项目:oceano    文件:PluginParameterException.java   
private static String format( List<Parameter> parameters )
{
    StringBuilder buffer = new StringBuilder( 128 );
    if ( parameters != null )
    {
        for ( Parameter parameter : parameters )
        {
            if ( buffer.length() > 0 )
            {
                buffer.append( ", " );
            }
            buffer.append( '\'' ).append( parameter.getName() ).append( '\'' );
        }
    }
    return buffer.toString();
}
项目:oceano    文件:PluginParameterException.java   
public String buildDiagnosticMessage()
{
    StringBuilder messageBuffer = new StringBuilder( 256 );

    List<Parameter> params = getParameters();
    MojoDescriptor mojo = getMojoDescriptor();

    messageBuffer.append( "One or more required plugin parameters are invalid/missing for \'" )
        .append( mojo.getPluginDescriptor().getGoalPrefix() ).append( ":" ).append( mojo.getGoal() )
        .append( "\'\n" );

    int idx = 0;
    for ( Iterator<Parameter> it = params.iterator(); it.hasNext(); idx++ )
    {
        Parameter param = it.next();

        messageBuffer.append( "\n[" ).append( idx ).append( "] " );

        decomposeParameterIntoUserInstructions( mojo, param, messageBuffer );

        messageBuffer.append( "\n" );
    }

    return messageBuffer.toString();
}
项目:oceano    文件:ValidatingConfigurationListener.java   
public ValidatingConfigurationListener( Object mojo, MojoDescriptor mojoDescriptor, ConfigurationListener delegate )
{
    this.mojo = mojo;
    this.delegate = delegate;
    this.missingParameters = new HashMap<String, Parameter>();

    if ( mojoDescriptor.getParameters() != null )
    {
        for ( Parameter param : mojoDescriptor.getParameters() )
        {
            if ( param.isRequired() )
            {
                missingParameters.put( param.getName(), param );
            }
        }
    }
}
项目:wisdom    文件:PluginExtractor.java   
/**
 * Extracts the subset of the given configuration containing only the values accepted by the plugin/goal. The
 * configuration is modified in-place. The the extraction fail the configuration stays unchanged.
 *
 * @param mojo          the Wisdom mojo
 * @param plugin        the plugin object
 * @param goal          the goal / mojo
 * @param configuration the global configuration
 */
public static void extractEligibleConfigurationForGoal(AbstractWisdomMojo mojo,
                                                       Plugin plugin, String goal, Xpp3Dom configuration) {
    try {
        MojoDescriptor descriptor = mojo.pluginManager.getMojoDescriptor(plugin, goal,
                mojo.remoteRepos, mojo.repoSession);
        final List<Parameter> parameters = descriptor.getParameters();
        Xpp3Dom[] children = configuration.getChildren();
        if (children != null) {
            for (int i = children.length - 1; i >= 0; i--) {
                Xpp3Dom child = children[i];
                if (!contains(parameters, child.getName())) {
                    configuration.removeChild(i);
                }
            }
        }
    } catch (Exception e) {
        mojo.getLog().warn("Cannot extract the eligible configuration for goal " + goal + " from the " +
                "configuration");
        mojo.getLog().debug(e);
        // The configuration is not changed.
    }

}
项目:maven-confluence-plugin    文件:PluginConfluenceDocGenerator.java   
/**
 *
 * @param w
 */
private void writeParameterTable(ConfluenceWikiWriter w) {
    List<Parameter> parameterList = descriptor.getParameters();

    //remove components and read-only parameters
    List<Parameter> list = filterParameters(parameterList);

    if (list != null && list.size() > 0) {
        writeParameterSummary(list, w);

        writeParameterDetails(list, w);
    }
}
项目:maven-confluence-plugin    文件:PluginConfluenceDocGenerator.java   
/**
 *
 * @param parameterList
 * @param w
 */
private void writeParameterSummary(List<Parameter> parameterList, ConfluenceWikiWriter w) {
    List requiredParams = getParametersByRequired(true, parameterList);
    if (requiredParams.size() > 0) {
        writeParameterList("Required Parameters", requiredParams, w);
    }

    List optionalParams = getParametersByRequired(false, parameterList);
    if (optionalParams.size() > 0) {
        writeParameterList("Optional Parameters", optionalParams, w);
    }
}
项目:maven-confluence-plugin    文件:PluginConfluenceDocGenerator.java   
/**
 *
 * @param required
 * @param parameterList
 * @return
 */
private List<Parameter> getParametersByRequired(boolean required, List<Parameter> parameterList) {
    if( parameterList == null) 
        return Collections.emptyList();

    final List<Parameter> list = new ArrayList<Parameter>();

    for (Parameter parameter : parameterList) {
        if (parameter.isRequired() == required) {
            list.add(parameter);
        }
    }

    return list;
}
项目:takari-lifecycle    文件:LegacyPluginDescriptors.java   
private static MojoDescriptor toMojoDescriptor(org.apache.maven.plugin.descriptor.MojoDescriptor mojo) {
  MojoDescriptor result = new MojoDescriptor();

  result.setGoal(mojo.getGoal());
  result.setDescription(mojo.getDescription());
  result.setSince(mojo.getSince());
  result.setRequiresDependencyResolution(mojo.getDependencyResolutionRequired());
  result.setRequiresDependencyCollection(mojo.getDependencyCollectionRequired());
  result.setRequiresDirectInvocation(mojo.isDirectInvocationOnly());
  result.setRequiresProject(mojo.isProjectRequired());
  result.setRequiresReports(mojo.isRequiresReports());
  result.setAggregator(mojo.isAggregator());
  result.setRequiresOnline(mojo.isOnlineRequired());
  result.setInheritedByDefault(mojo.isInheritedByDefault());
  result.setPhase(mojo.getPhase());
  result.setImplementation(mojo.getImplementation());
  result.setLanguage(mojo.getLanguage());
  result.setConfigurator(mojo.getComponentConfigurator());
  result.setInstantiationStrategy(mojo.getInstantiationStrategy());
  result.setExecutionStrategy(mojo.getExecutionStrategy());
  result.setThreadSafe(mojo.isThreadSafe());
  result.setDeprecated(mojo.getDeprecated());

  List<MojoParameter> parameters = new ArrayList<>();
  if (mojo.getParameters() != null) {
    for (Parameter parameter : mojo.getParameters()) {
      parameters.add(toMojoParameter(parameter));
    }
  }
  result.setParameters(parameters);

  List<MojoRequirement> requirements = new ArrayList<>();
  for (ComponentRequirement requirement : mojo.getRequirements()) {
    requirements.add(toMojoRequirement(requirement));
  }
  result.setRequirements(requirements);

  return result;
}
项目:oceano    文件:PluginParameterException.java   
public PluginParameterException( MojoDescriptor mojo, List<Parameter> parameters )
{
    super( mojo.getPluginDescriptor(), "The parameters " + format( parameters ) + " for goal "
        + mojo.getRoleHint() + " are missing or invalid" );

    this.mojo = mojo;

    this.parameters = parameters;
}
项目:oceano    文件:PluginParameterException.java   
private static void decomposeParameterIntoUserInstructions( MojoDescriptor mojo, Parameter param,
                                                            StringBuilder messageBuffer )
{
    String expression = param.getExpression();

    if ( param.isEditable() )
    {
        messageBuffer.append( "Inside the definition for plugin \'" + mojo.getPluginDescriptor().getArtifactId()
            + "\', specify the following:\n\n<configuration>\n  ...\n  <" + param.getName() + ">VALUE</"
            + param.getName() + ">\n</configuration>" );

        String alias = param.getAlias();
        if ( StringUtils.isNotEmpty( alias ) && !alias.equals( param.getName() ) )
        {
            messageBuffer.append(
                "\n\n-OR-\n\n<configuration>\n  ...\n  <" + alias + ">VALUE</" + alias + ">\n</configuration>\n" );
        }
    }

    if ( StringUtils.isEmpty( expression ) )
    {
        messageBuffer.append( "." );
    }
    else
    {
        if ( param.isEditable() )
        {
            messageBuffer.append( "\n\n-OR-\n\n" );
        }

        //addParameterUsageInfo( expression, messageBuffer );
    }
}
项目:wisdom    文件:PluginExtractor.java   
private static boolean contains(List<Parameter> parameters, String name) {
    for (Parameter parameter : parameters) {
        if (parameter.getName().equalsIgnoreCase(name)) {
            return true;
        }
    }
    return false;
}
项目:oceano    文件:PluginParameterException.java   
public List<Parameter> getParameters()
{
    return parameters;
}
项目:oceano    文件:DefaultMavenPluginManager.java   
private void validateParameters( MojoDescriptor mojoDescriptor, PlexusConfiguration configuration,
                                 ExpressionEvaluator expressionEvaluator )
    throws ComponentConfigurationException, PluginParameterException
{
    if ( mojoDescriptor.getParameters() == null )
    {
        return;
    }

    List<Parameter> invalidParameters = new ArrayList<Parameter>();

    for ( Parameter parameter : mojoDescriptor.getParameters() )
    {
        if ( !parameter.isRequired() )
        {
            continue;
        }

        Object value = null;

        PlexusConfiguration config = configuration.getChild( parameter.getName(), false );
        if ( config != null )
        {
            String expression = config.getValue( null );

            try
            {
                value = expressionEvaluator.evaluate( expression );

                if ( value == null )
                {
                    value = config.getAttribute( "default-value", null );
                }
            }
            catch ( ExpressionEvaluationException e )
            {
                String msg =
                    "Error evaluating the expression '" + expression + "' for configuration value '"
                        + configuration.getName() + "'";
                throw new ComponentConfigurationException( configuration, msg, e );
            }
        }

        if ( value == null && ( config == null || config.getChildCount() <= 0 ) )
        {
            invalidParameters.add( parameter );
        }
    }

    if ( !invalidParameters.isEmpty() )
    {
        throw new PluginParameterException( mojoDescriptor, invalidParameters );
    }
}
项目:oceano    文件:ValidatingConfigurationListener.java   
public Collection<Parameter> getMissingParameters()
{
    return missingParameters.values();
}
项目:maven-confluence-plugin    文件:PluginConfluenceDocGenerator.java   
/**
 *
 * @param parameterList
 * @param w
 */
private void writeParameterDetails(List<Parameter> parameterList, ConfluenceWikiWriter w) {
    w.printNormalHeading("Parameter Details");

    w.printNewParagraph();

    for (Parameter parameter : parameterList) {

        w.printSmallHeading(createAnchor(parameter.getName(), parameter.getName()));

        String description = parameter.getDescription();
        if (StringUtils.isEmpty(description)) {
            description = "No Description.";
        }

        w.println(decode(description));

        writeDetail("Deprecated", parameter.getDeprecated(), w);

        writeDetail("Type", parameter.getType(), w);

        writeDetail("Since", parameter.getSince(), w);

        if (parameter.isRequired()) {
            writeDetail("Required", "Yes", w);
        } else {
            writeDetail("Required", "No", w);
        }

        writeDetail("Expression", parameter.getExpression(), w);

        writeDetail("Default", parameter.getDefaultValue(), w);

    }

}
项目:maven-confluence-plugin    文件:PluginConfluenceDocGenerator.java   
/**
 *
 * @param title
 * @param parameterList
 * @param w
 */
private void writeParameterList(String title, List<Parameter> parameterList, ConfluenceWikiWriter w) {
    w.printNormalHeading(title);

    w.printNewParagraph();

    w.printf("||%s||%s||%s||\n", "Name", "Type", "Description");

    for (Parameter parameter : parameterList) {

        int index = parameter.getType().lastIndexOf(".");

        w.print('|');

        w.print(createLinkToAnchor(parameter.getName(), parameter.getName()));

        w.print('|');

        w.print(parameter.getType().substring(index + 1));

        w.print('|');

        String description = parameter.getDescription();
        if (StringUtils.isEmpty(description)) {
            description = "No description.";
        }
        if (StringUtils.isNotEmpty(parameter.getDeprecated())) {
            description = "Deprecated. " + description;
        }


        w.print(decode(description).replace("\n\n", "\n"));

        if (StringUtils.isNotEmpty(parameter.getDefaultValue())) {
            w.printf(" Default value is %s", decode(parameter.getDefaultValue()));
        }

        w.println('|');
    }

}