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

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

Introduction

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

Prototype

public void setAggregator(boolean aggregator) 

Source Link

Usage

From source file:org.efaps.maven_java5.EfapsAnnotationDescriptorExtractor.java

License:Open Source License

/**
 * Scan given class name for a mojo (using the annotations).
 *
 * @param _cl         class loader/*from  w w  w.  j av a  2s  . com*/
 * @param _className  class name
 * @return mojo descriptor, or <code>null</code> if the given class is not a
 *         mojo
 * @throws InvalidPluginDescriptorException
 */
private MojoDescriptor scan(final ClassLoader _cl, final String _className)
        throws InvalidPluginDescriptorException {
    final MojoDescriptor mojoDescriptor;
    Class<?> c;
    try {
        c = _cl.loadClass(_className);
    } catch (final ClassNotFoundException e) {
        throw new InvalidPluginDescriptorException("Error scanning class " + _className, e);
    }

    final Goal goalAnno = c.getAnnotation(Goal.class);
    if (goalAnno == null) {
        getLogger().debug("  Not a mojo: " + c.getName());
        mojoDescriptor = null;
    } else {
        mojoDescriptor = new MojoDescriptor();
        mojoDescriptor.setRole(Mojo.ROLE);
        mojoDescriptor.setImplementation(c.getName());
        mojoDescriptor.setLanguage("java");
        mojoDescriptor.setInstantiationStrategy(goalAnno.instantiationStrategy());
        mojoDescriptor.setExecutionStrategy(goalAnno.executionStrategy());
        mojoDescriptor.setGoal(goalAnno.name());
        mojoDescriptor.setAggregator(goalAnno.aggregator());
        mojoDescriptor.setDependencyResolutionRequired(goalAnno.requiresDependencyResolutionScope());
        mojoDescriptor.setDirectInvocationOnly(goalAnno.requiresDirectInvocation());
        mojoDescriptor.setProjectRequired(goalAnno.requiresProject());
        mojoDescriptor.setOnlineRequired(goalAnno.requiresOnline());
        mojoDescriptor.setInheritedByDefault(goalAnno.inheritByDefault());

        if (!Phase.VOID.equals(goalAnno.defaultPhase())) {
            mojoDescriptor.setPhase(goalAnno.defaultPhase().key());
        }

        final Deprecated deprecatedAnno = c.getAnnotation(Deprecated.class);

        if (deprecatedAnno != null) {
            mojoDescriptor.setDeprecated("true");
        }

        final Execute executeAnno = c.getAnnotation(Execute.class);

        if (executeAnno != null) {
            final String lifecycle = nullify(executeAnno.lifecycle());
            mojoDescriptor.setExecuteLifecycle(lifecycle);

            if (Phase.VOID.equals(executeAnno.phase())) {
                mojoDescriptor.setExecutePhase(executeAnno.phase().key());
            }

            final String customPhase = executeAnno.customPhase();

            if (customPhase.length() > 0) {
                if (!Phase.VOID.equals(executeAnno.phase())) {
                    getLogger().warn("Custom phase is overriding \"phase\" field.");
                }
                if (lifecycle == null) {
                    getLogger().warn(
                            "Setting a custom phase without a lifecycle is prone to error. If the phase is not custom, set the \"phase\" field instead.");
                }
                mojoDescriptor.setExecutePhase(executeAnno.customPhase());
            }

            mojoDescriptor.setExecuteGoal(nullify(executeAnno.goal()));
        }

        Class<?> cur = c;
        while (!Object.class.equals(cur)) {
            attachFieldParameters(cur, mojoDescriptor);
            cur = cur.getSuperclass();
        }

        if (getLogger().isDebugEnabled()) {
            getLogger().debug("  Component found: " + mojoDescriptor.getHumanReadableKey());
        }
    }

    return mojoDescriptor;
}

From source file:org.sourcepit.maven.bootstrap.core.AbstractBootstrapper.java

License:Apache License

private void ensureDependenciesAreResolved(MavenSession session) {
    final MojoDescriptor mojoDescriptor = new MojoDescriptor();
    mojoDescriptor.setAggregator(false);
    // mojoDescriptor.setDependencyCollectionRequired(getDependencyResolutionRequired());
    mojoDescriptor.setDependencyResolutionRequired(getDependencyResolutionRequired());

    final MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);

    final DependencyContext dependencyContext = mojoExecutor.newDependencyContext(session,
            Collections.singletonList(mojoExecution));

    try {/*  w w w.j a v  a2  s .c  o  m*/
        mojoExecutor.ensureDependenciesAreResolved(mojoDescriptor, session, dependencyContext);
    } catch (LifecycleExecutionException e) {
        throw new IllegalStateException(e);
    }
}