diff --git a/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java b/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java index 29af62f7..29078e93 100644 --- a/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java +++ b/plexus-compiler-manager/src/main/java/org/codehaus/plexus/compiler/manager/DefaultCompilerManager.java @@ -25,6 +25,7 @@ */ import javax.inject.Inject; import javax.inject.Named; +import javax.inject.Provider; import java.util.Map; @@ -36,19 +37,27 @@ @Named public class DefaultCompilerManager implements CompilerManager { @Inject - private Map compilers; + private Map> compilers; // ---------------------------------------------------------------------- // CompilerManager Implementation // ---------------------------------------------------------------------- public Compiler getCompiler(String compilerId) throws NoSuchCompilerException { - Compiler compiler = compilers.get(compilerId); + // Provider is lazy + // presence of provider means component is present (but not yet constructed) + Provider compiler = compilers.get(compilerId); + // it exists: as provider is found if (compiler == null) { throw new NoSuchCompilerException(compilerId); } - - return compiler; + // provider is lazy: if we are here, it exists but not yet created + try { + return compiler.get(); + } catch (Exception e) { + // if we are here: DI could not construct it: so report proper error + throw new RuntimeException(e); + } } }