1 package org.kuali.maven.plugins.guice; 2 3 import static org.kuali.common.jute.base.Precondition.checkNotNull; 4 5 import java.util.Map; 6 7 import org.apache.maven.plugin.AbstractMojo; 8 import org.apache.maven.plugin.logging.Log; 9 import org.apache.maven.project.MavenProject; 10 import org.apache.maven.settings.Settings; 11 12 import com.google.common.collect.ImmutableMap; 13 import com.google.inject.AbstractModule; 14 import com.google.inject.TypeLiteral; 15 16 public class MavenModule extends AbstractModule { 17 18 public MavenModule(GuiceMojo mojo) { 19 this.mojo = checkNotNull(mojo, "mojo"); 20 } 21 22 private final GuiceMojo mojo; 23 24 @Override 25 protected void configure() { 26 bind(MavenProject.class).toInstance(mojo.getProject()); 27 bind(Settings.class).toInstance(mojo.getSettings()); 28 bind(Log.class).toInstance(mojo.getLog()); 29 bind(new TypeLiteral<Map<?, ?>>() {}).annotatedWith(PluginContext.class).toInstance(getPluginContext(mojo)); 30 } 31 32 @SuppressWarnings("unchecked") 33 private Map<?, ?> getPluginContext(AbstractMojo mojo) { 34 if (mojo.getPluginContext() == null) { 35 return ImmutableMap.of(); 36 } else { 37 return ImmutableMap.copyOf(mojo.getPluginContext()); 38 } 39 } 40 41 }