Example usage for org.apache.maven.plugin.descriptor MojoDescriptor getParameters

List of usage examples for org.apache.maven.plugin.descriptor MojoDescriptor getParameters

Introduction

In this page you can find the example usage for org.apache.maven.plugin.descriptor MojoDescriptor getParameters.

Prototype

public List<Parameter> getParameters() 

Source Link

Usage

From source file:com.puppetlabs.geppetto.forge.maven.plugin.AbstractForgeTestMojo.java

License:Open Source License

private void finalizeMojoConfiguration(MojoExecution mojoExecution) {
    MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
    MavenProject project = getMavenSession().getCurrentProject();
    PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
    Plugin plugin = project.getPlugin(pluginDescriptor.getPluginLookupKey());
    pluginDescriptor.setPlugin(plugin);/* w  w  w  . j a v a  2 s .  c  o  m*/

    Xpp3Dom executionConfiguration = mojoExecution.getConfiguration();
    if (executionConfiguration == null)
        executionConfiguration = new Xpp3Dom("configuration");

    Xpp3Dom defaultConfiguration = MojoDescriptorCreator.convert(mojoDescriptor);
    Xpp3Dom finalConfiguration = new Xpp3Dom("configuration");

    if (mojoDescriptor.getParameters() != null) {
        for (Parameter parameter : mojoDescriptor.getParameters()) {
            Xpp3Dom parameterConfiguration = executionConfiguration.getChild(parameter.getName());

            if (parameterConfiguration == null)
                parameterConfiguration = executionConfiguration.getChild(parameter.getAlias());

            Xpp3Dom parameterDefaults = defaultConfiguration.getChild(parameter.getName());
            parameterConfiguration = Xpp3Dom.mergeXpp3Dom(parameterConfiguration, parameterDefaults,
                    Boolean.TRUE);

            if (parameterConfiguration != null) {
                parameterConfiguration = new Xpp3Dom(parameterConfiguration, parameter.getName());

                if (StringUtils.isEmpty(parameterConfiguration.getAttribute("implementation"))
                        && StringUtils.isNotEmpty(parameter.getImplementation())) {
                    parameterConfiguration.setAttribute("implementation", parameter.getImplementation());
                }
                finalConfiguration.addChild(parameterConfiguration);
            }
        }
    }

    if (plugin != null) {
        String goal = mojoExecution.getGoal();
        for (PluginExecution pe : plugin.getExecutions()) {
            if (pe.getGoals().contains(goal)) {
                Xpp3Dom execConfig = (Xpp3Dom) pe.getConfiguration();
                if (execConfig != null)
                    finalConfiguration = Xpp3Dom.mergeXpp3Dom(execConfig, finalConfiguration);
                break;
            }
        }
    }
    mojoExecution.setConfiguration(finalConfiguration);
}

From source file:io.takari.maven.testing.Maven30xRuntime.java

License:Open Source License

protected void finalizeMojoConfiguration(MojoExecution mojoExecution) {
    MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();

    Xpp3Dom executionConfiguration = mojoExecution.getConfiguration();
    if (executionConfiguration == null) {
        executionConfiguration = new Xpp3Dom("configuration");
    }/*  www  .  j a v  a2 s  .  co m*/

    Xpp3Dom defaultConfiguration = MojoDescriptorCreator.convert(mojoDescriptor);

    Xpp3Dom finalConfiguration = new Xpp3Dom("configuration");

    if (mojoDescriptor.getParameters() != null) {
        for (Parameter parameter : mojoDescriptor.getParameters()) {
            Xpp3Dom parameterConfiguration = executionConfiguration.getChild(parameter.getName());

            if (parameterConfiguration == null) {
                parameterConfiguration = executionConfiguration.getChild(parameter.getAlias());
            }

            Xpp3Dom parameterDefaults = defaultConfiguration.getChild(parameter.getName());

            parameterConfiguration = Xpp3Dom.mergeXpp3Dom(parameterConfiguration, parameterDefaults,
                    Boolean.TRUE);

            if (parameterConfiguration != null) {
                parameterConfiguration = new Xpp3Dom(parameterConfiguration, parameter.getName());

                if (StringUtils.isEmpty(parameterConfiguration.getAttribute("implementation"))
                        && StringUtils.isNotEmpty(parameter.getImplementation())) {
                    parameterConfiguration.setAttribute("implementation", parameter.getImplementation());
                }

                finalConfiguration.addChild(parameterConfiguration);
            }
        }
    }

    mojoExecution.setConfiguration(finalConfiguration);
}

From source file:org.eclipse.m2e.editor.xml.internal.mojo.DefaultMojoParameterMetadata.java

License:Open Source License

public List<MojoParameter> loadMojoParameters(PluginDescriptor desc, MojoDescriptor mojo,
        PlexusConfigHelper helper, IProgressMonitor monitor) throws CoreException {

    if (monitor.isCanceled()) {
        return Collections.emptyList();
    }/*  w  w  w. j  a  v  a2s . c  o  m*/
    Class<?> clazz;
    try {
        clazz = mojo.getImplementationClass();
        if (clazz == null) {
            clazz = desc.getClassRealm().loadClass(mojo.getImplementation());
        }
    } catch (ClassNotFoundException | TypeNotPresentException ex) {
        log.warn(ex.getMessage());
        return Collections.emptyList();
    }

    List<Parameter> ps = mojo.getParameters();
    Map<String, Type> properties = helper.getClassProperties(clazz);

    List<MojoParameter> parameters = new ArrayList<>();

    if (ps != null) {
        for (Parameter p : ps) {
            if (monitor.isCanceled()) {
                return Collections.emptyList();
            }
            if (!p.isEditable()) {
                continue;
            }

            Type type = properties.get(p.getName());
            if (type == null) {
                continue;
            }

            helper.addParameter(desc.getClassRealm(), clazz, type, p.getName(), p.getAlias(), parameters,
                    p.isRequired(), p.getExpression(), p.getDescription(), p.getDefaultValue(), monitor);
        }
    }

    return parameters;
}

From source file:org.wisdom.maven.utils.PluginExtractor.java

License:Apache License

/**
 * 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/* w  w  w  .  jav  a 2 s .co m*/
 * @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.
    }

}