From 67904f12fdd4be7d4be2823af1594fd733c1864e Mon Sep 17 00:00:00 2001 From: Jonas Rutishauser Date: Mon, 9 Sep 2024 22:13:51 +0200 Subject: [PATCH 1/2] [MNG-8254] Fix registration of DI-powered beans --- .../internal/impl/SisuDiBridgeModule.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java b/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java index eb6789c12bff..4a933b437f8b 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java @@ -39,7 +39,6 @@ import java.util.stream.Collectors; import com.google.inject.AbstractModule; -import com.google.inject.binder.AnnotatedBindingBuilder; import com.google.inject.name.Names; import org.apache.maven.api.di.MojoExecutionScoped; import org.apache.maven.api.di.SessionScoped; @@ -161,19 +160,13 @@ public Supplier getCompiledBinding(Dependency dep) { .sorted(Comparator.comparing(k -> k.getRawType().getName())) .distinct() .forEach(key -> { - Class clazz = key.getRawType(); - Class itf = (clazz.isInterface() - ? null - : (Class) (clazz.getInterfaces().length > 0 ? clazz.getInterfaces()[0] : clazz)); - if (itf != null) { - AnnotatedBindingBuilder binder = bind(itf); - if (key.getQualifier() instanceof String s && !s.isEmpty()) { - binder.annotatedWith(Names.named(s)); - } else if (key.getQualifier() instanceof Annotation a) { - binder.annotatedWith(a); - } - binder.toProvider(() -> injector.getInstance(clazz)); + var mappedKey = (com.google.inject.Key) com.google.inject.Key.get(key.getType()); + if (key.getQualifier() instanceof String s && !s.isEmpty()) { + mappedKey = mappedKey.withAnnotation(Names.named(s)); + } else if (key.getQualifier() instanceof Annotation a) { + mappedKey = mappedKey.withAnnotation(a); } + bind(mappedKey).toProvider(() -> injector.getInstance(key)); }); } From 203489bcd9d60675151ed427677190ae1a9c634b Mon Sep 17 00:00:00 2001 From: Jonas Rutishauser Date: Fri, 13 Sep 2024 21:17:52 +0200 Subject: [PATCH 2/2] Ignore empty bindings --- .../java/org/apache/maven/internal/impl/SisuDiBridgeModule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java b/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java index 4a933b437f8b..a32a8cd7ad3a 100644 --- a/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java +++ b/maven-core/src/main/java/org/apache/maven/internal/impl/SisuDiBridgeModule.java @@ -157,6 +157,7 @@ public Supplier getCompiledBinding(Dependency dep) { loadFromClassLoader(classLoader); injector.getBindings().keySet().stream() .filter(k -> k.getQualifier() != null) + .filter(k -> !injector.getBindings().get(k).isEmpty()) .sorted(Comparator.comparing(k -> k.getRawType().getName())) .distinct() .forEach(key -> {