org.apache.maven.plugin.descriptor.MojoDescriptor#getParameters ( )源码实例Demo

下面列出了org.apache.maven.plugin.descriptor.MojoDescriptor#getParameters ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: 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.
    }

}
 
源代码2 项目: helm-maven-plugin   文件: MojoExtension.java
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext context) throws ParameterResolutionException {
    try {

        // get descriptor

        Class<? extends AbstractHelmMojo> mojoType = (Class<AbstractHelmMojo>) parameterContext.getParameter().getType();
        MojoDescriptor descriptor = mojoDescriptors.get(mojoType);
        assertNotNull(descriptor, "Plugin descriptor for " + mojoType.getSimpleName() + " not found, run 'maven-plugin-plugin:descriptor'.");

        // create mojo with default values

        AbstractHelmMojo mojo = spy(mojoType);
        for (Parameter parameter : descriptor.getParameters()) {
            if (parameter.getDefaultValue() == null || !parameter.isEditable() || parameter.getType().equals("boolean")) {
                continue;
            }
            getField(mojoType, parameter.getName()).set(mojo, resolve(context, parameter.getDefaultValue()));
        }

        // read mojo values from annotations

        MojoProperty[] mojoProperties = ArrayUtils.addAll(
                context.getRequiredTestClass().getAnnotationsByType(MojoProperty.class),
                context.getRequiredTestMethod().getAnnotationsByType(MojoProperty.class));
        for (MojoProperty mojoProperty : mojoProperties) {
            getField(mojoType, mojoProperty.name()).set(mojo, resolve(context, mojoProperty.value()));
        }

        // settings

        getField(mojoType, "settings").set(mojo, new Settings());
        
        // plexus SecDispatcher

        SecDispatcher secDispatcher = spy(DefaultSecDispatcher.class);
        FieldSetter.setField(secDispatcher, DefaultSecDispatcher.class.getDeclaredField("_cipher"), new DefaultPlexusCipher());
        getField(mojoType, "securityDispatcher").set(mojo, secDispatcher);

        // validate that every parameter is set

        for (Parameter paramter : descriptor.getParameters()) {
            if (paramter.isRequired()) {
                assertNotNull(
                        getField(mojoType, paramter.getName()).get(mojo),
                        "Parameter '" + paramter.getName() + "' not set for mojo '" + mojoType.getSimpleName() + "'.");
            }
        }

        return mojo;
    } catch (ReflectiveOperationException | PlexusCipherException e) {
        throw new ParameterResolutionException("Failed to setup mockito.", e);
    }
}