001package org.kuali.maven.plugins.guice; 002 003import static org.kuali.common.jute.base.Precondition.checkNotNull; 004 005import java.util.Map; 006 007import org.apache.maven.plugin.AbstractMojo; 008import org.apache.maven.plugin.logging.Log; 009import org.apache.maven.project.MavenProject; 010import org.apache.maven.settings.Settings; 011 012import com.google.common.collect.ImmutableMap; 013import com.google.inject.AbstractModule; 014import com.google.inject.TypeLiteral; 015 016public class MavenModule extends AbstractModule { 017 018 public MavenModule(GuiceMojo mojo) { 019 this.mojo = checkNotNull(mojo, "mojo"); 020 } 021 022 private final GuiceMojo mojo; 023 024 @Override 025 protected void configure() { 026 bind(MavenProject.class).toInstance(mojo.getProject()); 027 bind(Settings.class).toInstance(mojo.getSettings()); 028 bind(Log.class).toInstance(mojo.getLog()); 029 bind(new TypeLiteral<Map<?, ?>>() {}).annotatedWith(PluginContext.class).toInstance(getPluginContext(mojo)); 030 } 031 032 @SuppressWarnings("unchecked") 033 private Map<?, ?> getPluginContext(AbstractMojo mojo) { 034 if (mojo.getPluginContext() == null) { 035 return ImmutableMap.of(); 036 } else { 037 return ImmutableMap.copyOf(mojo.getPluginContext()); 038 } 039 } 040 041}