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..298ba294 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,30 +25,51 @@
*/
import javax.inject.Inject;
import javax.inject.Named;
+import javax.inject.Provider;
import java.util.Map;
import org.codehaus.plexus.compiler.Compiler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author Trygve Laugstøl
*/
@Named
public class DefaultCompilerManager implements CompilerManager {
+ private static final String ERROR_MESSAGE = "Compiler '{}' could not be instantiated or injected properly. "
+ + "Running the build with -Dsisu.debug, looking for exceptions might help.";
+ private static final String ERROR_MESSAGE_DETAIL = "TypeNotPresentException caused by UnsupportedClassVersionError "
+ + "might indicate, that the compiler needs a more recent Java runtime. "
+ + "IllegalArgumentException in ClassReader. might mean, that you need to upgrade Maven.";
+
@Inject
- private Map compilers;
+ private Map> compilers;
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
// ----------------------------------------------------------------------
// CompilerManager Implementation
// ----------------------------------------------------------------------
public Compiler getCompiler(String compilerId) throws NoSuchCompilerException {
- Compiler compiler = compilers.get(compilerId);
+ // Provider is lazy -> presence of provider means compiler is present, but not yet constructed
+ Provider compilerProvider = compilers.get(compilerId);
- if (compiler == null) {
+ if (compilerProvider == null) {
+ // Compiler could not be injected for some reason
+ log.error(ERROR_MESSAGE + " " + ERROR_MESSAGE_DETAIL, compilerId);
throw new NoSuchCompilerException(compilerId);
}
- return compiler;
+ // Provider exists, but compiler was not created yet
+ try {
+ return compilerProvider.get();
+ } catch (Exception e) {
+ // DI could not construct compiler
+ log.error(ERROR_MESSAGE, compilerId);
+ throw new NoSuchCompilerException(compilerId);
+ }
}
}