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

org.kuali.maven.plugins.guice.MavenModule Maven / Gradle / Ivy

package org.kuali.maven.plugins.guice;

import static org.kuali.common.jute.base.Precondition.checkNotNull;

import java.util.Map;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.apache.maven.settings.Settings;

import com.google.common.collect.ImmutableMap;
import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;

public class MavenModule extends AbstractModule {

    public MavenModule(GuiceMojo mojo) {
        this.mojo = checkNotNull(mojo, "mojo");
    }

    private final GuiceMojo mojo;

    @Override
    protected void configure() {
        bind(MavenProject.class).toInstance(mojo.getProject());
        bind(Settings.class).toInstance(mojo.getSettings());
        bind(Log.class).toInstance(mojo.getLog());
        bind(new TypeLiteral>() {}).annotatedWith(PluginContext.class).toInstance(getPluginContext(mojo));
    }

    @SuppressWarnings("unchecked")
    private Map getPluginContext(AbstractMojo mojo) {
        if (mojo.getPluginContext() == null) {
            return ImmutableMap.of();
        } else {
            return ImmutableMap.copyOf(mojo.getPluginContext());
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy