All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jerkar.tool.JkBuildPlugin Maven / Gradle / Ivy

There is a newer version: 0.7.0.RELEASE
Show newest version
package org.jerkar.tool;

import org.jerkar.api.depmanagement.JkDependencies;
import org.jerkar.api.depmanagement.JkDependencyResolver;

/**
 * A plugin base class to extend to alter {@link JkBuild} object.
 *
 * @author Jerome Angibaud
 */
public abstract class JkBuildPlugin {

    /**
     * Returns the class this plugin is made for.
     */
    public Class baseBuildClass() {
        return JkBuild.class;
    }

    /**
     * Configure this plugin according the build instance it is applied on.
     */
    public abstract void configure(JkBuild build);

    /**
     * Override this method if this plugin does something while
     * {@link JkBuild#verify} is invoked.
     */
    protected void verify() {
        // Do nothing by default
    }

    /**
     * Override this method if this plugin does something while {@link JkBuild#scaffold()}
     * is invoked.
     */
    protected void scaffold() {
        // Do nothing by default
    }

    /**
     * Override this method if this plugin needs to alter the dependency resolver.
     *
     * @see JkBuildDependencySupport#dependencyResolver()
     */
    protected JkDependencyResolver alterDependencyResolver(JkDependencyResolver original) {
        return original;
    }

    /**
     * Override this method if the plugin need to alter the dependencies.
     *
     * @see JkBuildDependencySupport#dependencies
     */
    protected JkDependencies alterDependencies(JkDependencies original) {
        return original;
    }


    static void applyVerify(Iterable plugins) {
        for (final JkBuildPlugin plugin : plugins) {
            plugin.verify();
        }
    }

    static JkDependencyResolver applyDependencyResolver(
            Iterable plugins, JkDependencyResolver original) {
        JkDependencyResolver result = original;
        for (final JkBuildPlugin plugin : plugins) {
            result = plugin.alterDependencyResolver(original);
        }
        return result;
    }

    static JkDependencies applyDependencies(Iterable plugins,
            JkDependencies original) {
        JkDependencies result = original;
        for (final JkBuildPlugin plugin : plugins) {
            result = plugin.alterDependencies(original);
        }
        return result;
    }

    static void applyScaffold(Iterable plugins) {
        for (final JkBuildPlugin plugin : plugins) {
            plugin.scaffold();
        }
    }

    @Override
    public String toString() {
        return this.getClass().getSimpleName() + " : " + JkOptions.fieldOptionsToString(this);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy