Example usage for org.apache.maven.plugin Mojo ROLE

List of usage examples for org.apache.maven.plugin Mojo ROLE

Introduction

In this page you can find the example usage for org.apache.maven.plugin Mojo ROLE.

Prototype

String ROLE

To view the source code for org.apache.maven.plugin Mojo ROLE.

Click Source Link

Document

The component role hint for Plexus container

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 ww w.j a  va2s . c om
 * @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;
}