From 6305cabb251a43dc325a9dc8f9697e7de089107d Mon Sep 17 00:00:00 2001 From: 0utplay Date: Sun, 22 Sep 2024 12:16:58 +0200 Subject: [PATCH 1/8] chore: start update to aerogel v3 --- .../DefaultDocumentFactoryRegistry.java | 2 +- .../driver/event/DefaultEventManager.java | 2 +- .../event/DefaultRegisteredEventListener.java | 4 +- .../driver/inject/DefaultInjectionLayer.java | 77 +++++++++++----- .../driver/inject/InjectUtil.java | 45 ++++----- .../driver/inject/InjectionLayer.java | 41 +++++---- .../driver/inject/InjectionLayerProvider.java | 92 ++++++++++--------- .../inject/UncloseableInjectionLayer.java | 25 +++-- .../driver/module/DefaultModuleProvider.java | 23 +++-- .../driver/module/DefaultModuleTaskEntry.java | 4 +- .../driver/module/DefaultModuleWrapper.java | 8 +- .../driver/module/ModuleURLClassLoader.java | 10 +- .../driver/module/ModuleWrapper.java | 6 +- .../driver/module/driver/DriverModule.java | 42 +++++---- .../netty/buffer/NettyDataBufFactory.java | 2 +- .../rpc/defaults/DefaultRPCFactory.java | 2 +- .../handler/DefaultRPCHandlerRegistry.java | 2 +- .../defaults/object/DefaultObjectMapper.java | 2 +- .../ObjectMapperInjectRegistration.java | 8 +- .../registry/DefaultServiceRegistry.java | 45 ++++----- .../api/PlatformPluginInfo.java | 16 ++-- .../defaults/BasePlatformPluginManager.java | 3 +- .../defaults/DefaultPlatformPluginInfo.java | 4 +- .../bukkit/BukkitPlatformPluginManager.java | 16 ++-- .../BungeeCordPlatformPluginManager.java | 9 +- .../LimboLoohpPlatformPluginManager.java | 8 +- .../MinestomPlatformPluginManager.java | 37 ++++---- .../nukkit/NukkitPlatformPluginManager.java | 26 +++--- .../sponge/SpongePlatformPluginManager.java | 42 ++++----- .../VelocityPlatformPluginManager.java | 12 +-- .../WaterDogPlatformPluginManager.java | 22 ++--- gradle/libs.versions.toml | 2 +- .../bridge/node/NodeBridgeManagement.java | 4 +- .../bridge/node/player/NodePlayerManager.java | 4 +- .../docker/DockerizedServicesModule.java | 5 +- .../signs/node/NodeSignManagement.java | 2 +- .../node/NodeSyncProxyManagement.java | 2 +- .../java/eu/cloudnetservice/node/Node.java | 8 +- .../node/boot/BootFactories.java | 2 +- .../cloudnetservice/node/boot/Bootstrap.java | 21 ++--- .../defaults/DefaultLocalNodeServer.java | 2 +- .../defaults/DefaultNodeServerProvider.java | 2 +- .../cluster/sync/DefaultDataSyncRegistry.java | 2 +- .../defaults/DefaultCommandProvider.java | 2 +- .../node/config/JsonConfiguration.java | 2 +- .../node/console/JLine3Console.java | 2 +- .../node/log/QueuedConsoleLogAppender.java | 9 +- .../node/module/util/ModuleUpdateUtil.java | 2 +- .../provider/NodeClusterNodeProvider.java | 2 +- .../NodeGroupConfigurationProvider.java | 7 +- .../node/provider/NodeMessenger.java | 2 +- .../provider/NodeServiceTaskProvider.java | 6 +- .../defaults/DefaultCloudServiceManager.java | 4 +- .../defaults/NodeCloudServiceFactory.java | 4 +- .../template/NodeTemplateStorageProvider.java | 2 +- .../java/eu/cloudnetservice/wrapper/Main.java | 25 ++--- .../DocumentWrapperConfiguration.java | 2 +- .../holder/WrapperServiceInfoHolder.java | 2 +- .../wrapper/inject/BootFactories.java | 2 +- .../wrapper/inject/RPCFactories.java | 2 +- .../wrapper/provider/WrapperMessenger.java | 2 +- 61 files changed, 396 insertions(+), 376 deletions(-) diff --git a/driver/src/main/java/eu/cloudnetservice/driver/document/defaults/DefaultDocumentFactoryRegistry.java b/driver/src/main/java/eu/cloudnetservice/driver/document/defaults/DefaultDocumentFactoryRegistry.java index 927b86a90f..988ef98a99 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/document/defaults/DefaultDocumentFactoryRegistry.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/document/defaults/DefaultDocumentFactoryRegistry.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.driver.document.defaults; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.document.DocumentFactory; import eu.cloudnetservice.driver.document.DocumentFactoryRegistry; import eu.cloudnetservice.driver.document.empty.EmptyDocumentFactory; diff --git a/driver/src/main/java/eu/cloudnetservice/driver/event/DefaultEventManager.java b/driver/src/main/java/eu/cloudnetservice/driver/event/DefaultEventManager.java index c04486547e..b726f33f07 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/event/DefaultEventManager.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/event/DefaultEventManager.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.driver.event; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.inject.InjectionLayer; import jakarta.inject.Singleton; import java.lang.reflect.Modifier; diff --git a/driver/src/main/java/eu/cloudnetservice/driver/event/DefaultRegisteredEventListener.java b/driver/src/main/java/eu/cloudnetservice/driver/event/DefaultRegisteredEventListener.java index 27ecf9911a..c3c2f571bc 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/event/DefaultRegisteredEventListener.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/event/DefaultRegisteredEventListener.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.driver.event; -import dev.derklaro.aerogel.Element; +import dev.derklaro.aerogel.binding.key.BindingKey; import dev.derklaro.reflexion.MethodAccessor; import dev.derklaro.reflexion.Reflexion; import eu.cloudnetservice.driver.inject.InjectUtil; @@ -40,7 +40,7 @@ final class DefaultRegisteredEventListener implements RegisteredEventListener { private final EventListener eventListener; private final String methodName; - private final Element[] methodArguments; + private final BindingKey[] methodArguments; private final MethodAccessor methodAccessor; private final InjectionLayer injectionLayer; diff --git a/driver/src/main/java/eu/cloudnetservice/driver/inject/DefaultInjectionLayer.java b/driver/src/main/java/eu/cloudnetservice/driver/inject/DefaultInjectionLayer.java index ff126aa2b7..59920fccc1 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/inject/DefaultInjectionLayer.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/inject/DefaultInjectionLayer.java @@ -16,32 +16,39 @@ package eu.cloudnetservice.driver.inject; -import dev.derklaro.aerogel.Element; -import dev.derklaro.aerogel.InjectionContext; import dev.derklaro.aerogel.Injector; -import dev.derklaro.aerogel.SpecifiedInjector; -import dev.derklaro.aerogel.auto.runtime.AutoAnnotationRegistry; -import dev.derklaro.aerogel.binding.BindingConstructor; -import dev.derklaro.aerogel.internal.context.util.ContextInstanceResolveHelper; +import dev.derklaro.aerogel.auto.AerogelAutoModule; +import dev.derklaro.aerogel.binding.DynamicBinding; +import dev.derklaro.aerogel.binding.UninstalledBinding; +import dev.derklaro.aerogel.binding.key.BindingKey; +import dev.derklaro.aerogel.internal.context.scope.InjectionContextProvider; +import jakarta.inject.Provider; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import java.util.function.Consumer; import lombok.NonNull; import org.jetbrains.annotations.UnknownNullability; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The default implementation for of an injector layer. * - * @param injector the injector to use for the layer. - * @param autoRegistry the auto registry to use for the layer. - * @param name the name of this injection layer. - * @param the type of injector this layer uses. + * @param injector the injector to use for the layer. + * @param autoModule the auto registry to use for the layer. + * @param name the name of this injection layer. + * @param the type of injector this layer uses. * @since 4.0 */ record DefaultInjectionLayer( @NonNull I injector, - @NonNull AutoAnnotationRegistry autoRegistry, + @NonNull AerogelAutoModule autoModule, @NonNull String name ) implements InjectionLayer { + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultInjectionLayer.class); + /** * {@inheritDoc} */ @@ -62,8 +69,8 @@ record DefaultInjectionLayer( * {@inheritDoc} */ @Override - public @UnknownNullability T instance(@NonNull Element element) { - return this.injector.instance(element); + public @UnknownNullability T instance(@NonNull BindingKey bindingKey) { + return this.injector.instance(bindingKey); } /** @@ -73,26 +80,41 @@ record DefaultInjectionLayer( @SuppressWarnings("unchecked") public @UnknownNullability T instance( @NonNull Class type, - @NonNull Consumer builder + @NonNull Consumer, Provider>> overrides ) { // get the binding associated with the given type & construct a context builder - var element = Element.forType(type); + var element = BindingKey.of(type); var binding = this.injector.binding(element); - var contextBuilder = InjectionContext.builder(type, binding.provider(element)); - // apply the builder decorator to the builder - builder.accept(contextBuilder); + // construct the map and decorate it using the consumer + Map, Provider> overridesMap = new HashMap<>(); + overrides.accept(overridesMap); + + var contextScope = InjectionContextProvider.provider().enterContextScope(this.injector, binding, overridesMap); // resolve the instance - return (T) ContextInstanceResolveHelper.resolveInstanceAndRemoveContext(contextBuilder.build()); + return contextScope.executeScoped(() -> { + try { + return (T) contextScope.context().resolveInstance(); + } finally { + if (contextScope.context().root()) { + contextScope.context().finishConstruction(); + } + } + }); } /** * {@inheritDoc} */ @Override - public void install(@NonNull BindingConstructor constructor) { - this.injector.install(constructor); + public void install(@NonNull UninstalledBinding binding) { + this.injector.installBinding(binding); + } + + @Override + public void install(@NonNull DynamicBinding binding) { + this.injector.installBinding(binding); } /** @@ -101,7 +123,13 @@ public void install(@NonNull BindingConstructor constructor) { @Override public void installAutoConfigureBindings(@NonNull ClassLoader loader, @NonNull String component) { var fileName = String.format(AUTO_CONFIGURE_FILE_NAME_FORMAT, component); - this.autoRegistry.installBindings(loader, fileName, this.injector); + try (var stream = loader.getResourceAsStream(fileName)) { + if (stream != null) { + this.autoModule.deserializeBindings(stream, loader).installBindings(this.injector); + } + } catch (IOException exception) { + LOGGER.warn("Unable to auto configure bindings for component {} with file {}", component, fileName, exception); + } } /** @@ -127,9 +155,10 @@ public void installAutoConfigureBindings(@NonNull ClassLoader loader, @NonNull S @Override public void close() { // remove the bindings from the parent injector if needed - if (this.injector instanceof SpecifiedInjector specifiedInjector) { + // TODO aerogel + /*if (this.injector instanceof Target specifiedInjector) { specifiedInjector.removeConstructedBindings(); - } + }*/ // remove this injector from the registry InjectionLayerProvider.REGISTRY.unregisterLayer(this); diff --git a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectUtil.java b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectUtil.java index 7ef40838d6..ef2c663152 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectUtil.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectUtil.java @@ -17,15 +17,12 @@ package eu.cloudnetservice.driver.inject; import com.google.common.base.Preconditions; -import dev.derklaro.aerogel.AerogelException; -import dev.derklaro.aerogel.Element; -import dev.derklaro.aerogel.binding.BindingBuilder; -import dev.derklaro.aerogel.binding.BindingConstructor; -import dev.derklaro.aerogel.internal.util.ElementHelper; +import dev.derklaro.aerogel.Injector; +import dev.derklaro.aerogel.binding.UninstalledBinding; +import dev.derklaro.aerogel.binding.key.BindingKey; import java.lang.reflect.Parameter; import java.lang.reflect.Type; import java.util.Arrays; -import java.util.Objects; import lombok.NonNull; import org.jetbrains.annotations.ApiStatus; @@ -38,7 +35,7 @@ public final class InjectUtil { private static final Object[] EMPTY_INSTANCE_ARRAY = new Object[0]; - private static final Element[] EMPTY_ELEMENT_ARRAY = new Element[0]; + private static final BindingKey[] EMPTY_ELEMENT_ARRAY = new BindingKey[0]; private InjectUtil() { throw new UnsupportedOperationException(); @@ -51,7 +48,7 @@ private InjectUtil() { * @return an array of element each representing a given parameter, in order. * @throws NullPointerException if the given parameter array is null. */ - public static @NonNull Element[] buildElementsForParameters(@NonNull Parameter[] parameters) { + public static @NonNull BindingKey[] buildElementsForParameters(@NonNull Parameter[] parameters) { return buildElementsForParameters(parameters, 0); } @@ -63,7 +60,7 @@ private InjectUtil() { * @return an array of element each representing a given parameter, in order. * @throws NullPointerException if the given parameter array is null. */ - public static @NonNull Element[] buildElementsForParameters(@NonNull Parameter[] parameters, int offset) { + public static @NonNull BindingKey[] buildElementsForParameters(@NonNull Parameter[] parameters, int offset) { // return an empty element array if the given parameters are empty if (parameters.length <= offset) { return EMPTY_ELEMENT_ARRAY; @@ -71,10 +68,10 @@ private InjectUtil() { // construct the element array var params = Arrays.copyOfRange(parameters, offset, parameters.length); - var elements = new Element[params.length]; + var elements = new BindingKey[params.length]; for (int i = 0; i < params.length; i++) { var parameter = params[i]; - elements[i] = ElementHelper.buildElement(parameter, parameter.getDeclaredAnnotations()); + elements[i] = BindingKey.of(parameter.getParameterizedType()).selectQualifier(parameter.getAnnotations()); } return elements; } @@ -86,9 +83,11 @@ private InjectUtil() { * @param elements the elements to get the instances of. * @return the instances represented by the given elements, in order. * @throws NullPointerException if the given injection layer or elements array is null. - * @throws AerogelException if an exception occurs while constructing a requested instance. */ - public static @NonNull Object[] findAllInstances(@NonNull InjectionLayer layer, @NonNull Element[] elements) { + public static @NonNull Object[] findAllInstances( + @NonNull InjectionLayer layer, + @NonNull BindingKey[] elements + ) { return findAllInstances(layer, elements, 0); } @@ -101,11 +100,10 @@ private InjectUtil() { * @return the instances represented by the given elements, in order. * @throws NullPointerException if the given injection layer or elements array is null. * @throws IllegalArgumentException if the given offset is smaller than zero. - * @throws AerogelException if an exception occurs while constructing a requested instance. */ public static @NonNull Object[] findAllInstances( @NonNull InjectionLayer layer, - @NonNull Element[] elements, + @NonNull BindingKey[] elements, int offset ) { Preconditions.checkArgument(offset >= 0, "offset must be >= 0"); @@ -137,16 +135,11 @@ private InjectUtil() { * @throws NullPointerException if the given type or value is null. * @throws IndexOutOfBoundsException if the given type array is empty. */ - public static @NonNull BindingConstructor createFixedBinding(@NonNull Object value, @NonNull Type... types) { - Objects.checkIndex(0, types.length); - - // extract the root binding type - if (types.length == 1) { - // only one type given, no need for further checks - return BindingBuilder.create().bindFully(types[0]).toInstance(value); - } else { - // bind all given types fully - return BindingBuilder.create().bindAllFully(types).toInstance(value); - } + public static @NonNull UninstalledBinding createFixedBinding( + @NonNull Injector injector, + @NonNull Object value, + @NonNull Type type + ) { + return injector.createBindingBuilder().bind(type).toInstance(value); } } diff --git a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayer.java b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayer.java index cdd631daed..4bd9881ee2 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayer.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayer.java @@ -17,14 +17,14 @@ package eu.cloudnetservice.driver.inject; import com.google.common.base.Preconditions; -import dev.derklaro.aerogel.AerogelException; -import dev.derklaro.aerogel.Element; -import dev.derklaro.aerogel.InjectionContext; import dev.derklaro.aerogel.Injector; -import dev.derklaro.aerogel.SpecifiedInjector; -import dev.derklaro.aerogel.binding.BindingConstructor; +import dev.derklaro.aerogel.TargetedInjectorBuilder; +import dev.derklaro.aerogel.binding.DynamicBinding; +import dev.derklaro.aerogel.binding.UninstalledBinding; +import dev.derklaro.aerogel.binding.key.BindingKey; import eu.cloudnetservice.common.Named; -import java.util.function.BiConsumer; +import jakarta.inject.Provider; +import java.util.Map; import java.util.function.Consumer; import lombok.NonNull; import org.jetbrains.annotations.UnknownNullability; @@ -116,10 +116,10 @@ public sealed interface InjectionLayer * @throws NullPointerException if the given parent layer, name or configurator is null. * @throws IllegalArgumentException if the given name is invalid or the parent layer is the boot layer. */ - static @NonNull InjectionLayer specifiedChild( + static @NonNull InjectionLayer specifiedChild( @NonNull InjectionLayer parent, @NonNull String name, - @NonNull BiConsumer, SpecifiedInjector> configurator + @NonNull Consumer configurator ) { Preconditions.checkArgument(parent != boot(), "Parent of a specified layer cannot be the boot layer"); return InjectionLayerProvider.specifiedChild(parent, name, configurator); @@ -171,14 +171,16 @@ public sealed interface InjectionLayer * @return the name of this layer. */ @Override - @NonNull String name(); + @NonNull + String name(); /** * Gets the underlying injector of this layer. * * @return the underlying injector of this layer. */ - @NonNull I injector(); + @NonNull + I injector(); /** * Convince method to create or get the instance of the given class type. @@ -189,39 +191,44 @@ public sealed interface InjectionLayer * @throws NullPointerException if the given type is null. * @throws AerogelException if no binding is present and no runtime binding can be created. */ - @UnknownNullability T instance(@NonNull Class type); + @UnknownNullability + T instance(@NonNull Class type); /** * Convince method to create or get the instance of the given element. * - * @param element the element of the type to get. + * @param bindingKey the element of the type to get. * @param the type of the return value modeled by the given element. * @return the constructed instance of the class type, may be null. * @throws NullPointerException if the given element is null. * @throws AerogelException if no binding is present and no runtime binding can be created. */ - @UnknownNullability T instance(@NonNull Element element); + @UnknownNullability + T instance(@NonNull BindingKey bindingKey); /** * Convince method to create or get the instance of the given type, while allowing to specifically influence the * injection context. * * @param type the type of the element to get. - * @param builder the builder to configure the injection context for the operation. + * @param overrides the builder to configure the injection context for the operation. * @param the type of the return value modeled by the given element. * @return the constructed instance of the class type, may be null. * @throws NullPointerException if the given type or builder is null. * @throws AerogelException if no binding is present and no runtime binding can be created. */ - @UnknownNullability T instance(@NonNull Class type, @NonNull Consumer builder); + @UnknownNullability + T instance(@NonNull Class type, @NonNull Consumer, Provider>> overrides); /** * Installs the binding constructed by the given bindings constructor to this injection layer. * - * @param constructor the constructor to install. + * @param binding the constructor to install. * @throws NullPointerException if the given constructor is null or the constructor constructs a null value. */ - void install(@NonNull BindingConstructor constructor); + void install(@NonNull UninstalledBinding binding); + + void install(@NonNull DynamicBinding binding); /** * Installs the autoconfiguration bindings for the given component. For this method to work the autoconfiguration diff --git a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayerProvider.java b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayerProvider.java index 56f9d99cb4..e9be575cc7 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayerProvider.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayerProvider.java @@ -16,17 +16,15 @@ package eu.cloudnetservice.driver.inject; -import dev.derklaro.aerogel.Element; import dev.derklaro.aerogel.Injector; -import dev.derklaro.aerogel.SpecifiedInjector; -import dev.derklaro.aerogel.auto.runtime.AutoAnnotationRegistry; -import dev.derklaro.aerogel.binding.BindingBuilder; -import dev.derklaro.aerogel.binding.BindingConstructor; -import dev.derklaro.aerogel.util.Qualifiers; +import dev.derklaro.aerogel.TargetedInjectorBuilder; +import dev.derklaro.aerogel.auto.AerogelAutoModule; +import dev.derklaro.aerogel.binding.UninstalledBinding; import eu.cloudnetservice.common.util.StringUtil; import io.leangen.geantyref.TypeFactory; +import jakarta.inject.Provider; +import java.lang.reflect.Type; import java.util.ServiceLoader; -import java.util.function.BiConsumer; import java.util.function.Consumer; import lombok.NonNull; @@ -40,17 +38,14 @@ final class InjectionLayerProvider { // the boot layer registry static final InjectionLayerRegistry REGISTRY = new InjectionLayerRegistry(); // generic elements - private static final Element RAW_ELEMENT = Element.forType(InjectionLayer.class); - private static final Element GENERIC_ELEMENT = Element.forType(TypeFactory.parameterizedClass( + @SuppressWarnings("rawtypes") + private static final Class RAW_ELEMENT = InjectionLayer.class; + private static final Type GENERIC_ELEMENT = TypeFactory.parameterizedClass( InjectionLayer.class, - TypeFactory.unboundWildcard())); + TypeFactory.unboundWildcard()); // specified elements - private static final Element INJECTOR_ELEMENT = Element.forType(TypeFactory.parameterizedClass( - InjectionLayer.class, - Injector.class)); - private static final Element SPECIFIED_INJECTOR_ELEMENT = Element.forType(TypeFactory.parameterizedClass( - InjectionLayer.class, - SpecifiedInjector.class)); + private static final Type INJECTOR_ELEMENT = TypeFactory.parameterizedClass(InjectionLayer.class, Injector.class); + private static InjectionLayer boot; private static InjectionLayer ext; @@ -120,19 +115,27 @@ private InjectionLayerProvider() { * @throws NullPointerException if the given parent layer, name or configurator is null. * @throws IllegalArgumentException if the given name is invalid. */ - public static @NonNull InjectionLayer specifiedChild( + public static @NonNull InjectionLayer specifiedChild( @NonNull InjectionLayer parent, @NonNull String name, - @NonNull BiConsumer, SpecifiedInjector> configurator + @NonNull Consumer configurator ) { - var childInjector = parent.injector().newSpecifiedInjector(); - return configuredLayer(name, childInjector, - ((Consumer>) layer -> registerBindings( - layer, - SPECIFIED_INJECTOR_ELEMENT, - name, - ($, constructor) -> childInjector.installSpecified(constructor)) - ).andThen(layer -> configurator.accept(layer, childInjector))); + var childInjector = parent.injector().createTargetedInjectorBuilder(); + var layerHolder = new Object() { + InjectionLayer layer; + }; + registerBindings( + parent.injector(), + () -> layerHolder.layer, + name, + childInjector::installBinding); + + // build and configure the layer + configurator.accept(childInjector); + layerHolder.layer = new DefaultInjectionLayer<>(childInjector.build(), AerogelAutoModule.newInstance(), name); + + // return the new layer + return layerHolder.layer; } /** @@ -153,9 +156,11 @@ private InjectionLayerProvider() { @NonNull InjectionLayer parent, @NonNull String name ) { - var childInjector = parent.injector().newChildInjector(); - return configuredLayer(name, childInjector, - layer -> registerBindings(layer, INJECTOR_ELEMENT, name, InjectionLayer::install)); + var childInjector = parent.injector().createChildInjector(); + return configuredLayer( + name, + childInjector, + layer -> registerBindings(childInjector, () -> layer, name, layer::install)); } /** @@ -169,9 +174,11 @@ private InjectionLayerProvider() { */ public static @NonNull InjectionLayer fresh(@NonNull String name) { return configuredLayer(name, layer -> { - layer.install(BindingBuilder.create().bind(RAW_ELEMENT).toInstance(layer)); - layer.install(BindingBuilder.create().bind(GENERIC_ELEMENT).toInstance(layer)); - layer.install(BindingBuilder.create().bind(INJECTOR_ELEMENT).toInstance(layer)); + var injector = layer.injector(); + var bindingBuilder = injector.createBindingBuilder(); + injector.installBinding(bindingBuilder.bind(RAW_ELEMENT).toInstance(layer)); + injector.installBinding(bindingBuilder.bind(GENERIC_ELEMENT).toInstance(layer)); + injector.installBinding(bindingBuilder.bind(INJECTOR_ELEMENT).toInstance(layer)); }); } @@ -212,7 +219,7 @@ private InjectionLayerProvider() { validateName(name); // build and configure the layer - var layer = new DefaultInjectionLayer<>(injector, AutoAnnotationRegistry.newRegistry(), name); + var layer = new DefaultInjectionLayer<>(injector, AerogelAutoModule.newInstance(), name); configurator.accept(layer); // return the new layer @@ -294,19 +301,14 @@ private static void validateName(@NonNull String name) { } private static void registerBindings( - @NonNull InjectionLayer layer, - @NonNull Element mainElement, + @NonNull Injector injector, + @NonNull Provider> layer, @NonNull String name, - @NonNull BiConsumer, BindingConstructor> registerFunction + @NonNull Consumer> register ) { - registerFunction.accept(layer, BindingBuilder.create() - .bind(RAW_ELEMENT.requireAnnotation(Qualifiers.named(name))) - .toInstance(layer)); - registerFunction.accept(layer, BindingBuilder.create() - .bind(GENERIC_ELEMENT.requireAnnotation(Qualifiers.named(name))) - .toInstance(layer)); - registerFunction.accept(layer, BindingBuilder.create() - .bind(mainElement.requireAnnotation(Qualifiers.named(name))) - .toInstance(layer)); + var bindingBuilder = injector.createBindingBuilder(); + register.accept(bindingBuilder.bind(RAW_ELEMENT).qualifiedWithName(name).toProvider(layer)); + register.accept(bindingBuilder.bind(GENERIC_ELEMENT).qualifiedWithName(name).toProvider(layer)); + register.accept(bindingBuilder.bind(INJECTOR_ELEMENT).qualifiedWithName(name).toProvider(layer)); } } diff --git a/driver/src/main/java/eu/cloudnetservice/driver/inject/UncloseableInjectionLayer.java b/driver/src/main/java/eu/cloudnetservice/driver/inject/UncloseableInjectionLayer.java index ecf7de31ab..2ca6dc5f58 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/inject/UncloseableInjectionLayer.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/inject/UncloseableInjectionLayer.java @@ -16,10 +16,12 @@ package eu.cloudnetservice.driver.inject; -import dev.derklaro.aerogel.Element; -import dev.derklaro.aerogel.InjectionContext; import dev.derklaro.aerogel.Injector; -import dev.derklaro.aerogel.binding.BindingConstructor; +import dev.derklaro.aerogel.binding.DynamicBinding; +import dev.derklaro.aerogel.binding.UninstalledBinding; +import dev.derklaro.aerogel.binding.key.BindingKey; +import jakarta.inject.Provider; +import java.util.Map; import java.util.function.Consumer; import lombok.NonNull; import org.jetbrains.annotations.UnknownNullability; @@ -62,8 +64,8 @@ record UncloseableInjectionLayer(@NonNull InjectionLayer * {@inheritDoc} */ @Override - public @UnknownNullability T instance(@NonNull Element element) { - return this.parent.instance(element); + public @UnknownNullability T instance(@NonNull BindingKey bindingKey) { + return this.parent.instance(bindingKey); } /** @@ -72,17 +74,22 @@ record UncloseableInjectionLayer(@NonNull InjectionLayer @Override public @UnknownNullability T instance( @NonNull Class type, - @NonNull Consumer builder + @NonNull Consumer, Provider>> overrides ) { - return this.parent.instance(type, builder); + return this.parent.instance(type, overrides); } /** * {@inheritDoc} */ @Override - public void install(@NonNull BindingConstructor constructor) { - this.parent.install(constructor); + public void install(@NonNull UninstalledBinding binding) { + this.parent.install(binding); + } + + @Override + public void install(@NonNull DynamicBinding binding) { + this.parent.install(binding); } /** diff --git a/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleProvider.java b/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleProvider.java index a1ef87b9d0..b1e0b51206 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleProvider.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleProvider.java @@ -17,10 +17,8 @@ package eu.cloudnetservice.driver.module; import com.google.common.base.Preconditions; -import dev.derklaro.aerogel.Element; -import dev.derklaro.aerogel.auto.Provides; -import dev.derklaro.aerogel.binding.BindingBuilder; -import dev.derklaro.aerogel.util.Qualifiers; +import dev.derklaro.aerogel.auto.annotation.Provides; +import dev.derklaro.aerogel.binding.key.BindingKey; import eu.cloudnetservice.common.io.FileUtil; import eu.cloudnetservice.common.jvm.JavaVersion; import eu.cloudnetservice.common.tuple.Tuple2; @@ -65,9 +63,8 @@ public class DefaultModuleProvider implements ModuleProvider { protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultModuleProvider.class); protected static final ModuleDependencyLoader DEFAULT_DEP_LOADER = new DefaultModuleDependencyLoader(DEFAULT_LIB_DIR); - private static final Element MODULE_CONFIGURATION_ELEMENT = Element.forType(ModuleConfiguration.class); - private static final Element DATA_DIRECTORY_ELEMENT = Element.forType(Path.class) - .requireAnnotation(Qualifiers.named("dataDirectory")); + private static final Class DATA_DIRECTORY_KEY = Path.class; + private static final BindingKey MODULE_CONFIG_KEY = BindingKey.of(ModuleConfiguration.class); protected final Collection modules = new CopyOnWriteArrayList<>(); @@ -205,12 +202,14 @@ public void moduleDependencyLoader(@NonNull ModuleDependencyLoader moduleDepende // create the injection layer for the module var externalLayer = InjectionLayer.ext(); - var moduleLayer = InjectionLayer.specifiedChild(externalLayer, "module", (layer, injector) -> { - injector.installSpecified(BindingBuilder.create() - .bind(DATA_DIRECTORY_ELEMENT) + var moduleLayer = InjectionLayer.specifiedChild(externalLayer, "module", builder -> { + var bindingBuilder = externalLayer.injector().createBindingBuilder(); + builder.installBinding(bindingBuilder + .bind(DATA_DIRECTORY_KEY) + .qualifiedWithName("dataDirectory") .toInstance(dataDirectory)); - injector.installSpecified(BindingBuilder.create() - .bind(MODULE_CONFIGURATION_ELEMENT) + builder.installBinding(bindingBuilder + .bind(MODULE_CONFIG_KEY) .toInstance(moduleConfiguration)); }); diff --git a/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleTaskEntry.java b/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleTaskEntry.java index 6c4b32f006..2f1c45be43 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleTaskEntry.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleTaskEntry.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.driver.module; -import dev.derklaro.aerogel.Element; +import dev.derklaro.aerogel.binding.key.BindingKey; import dev.derklaro.reflexion.MethodAccessor; import dev.derklaro.reflexion.Reflexion; import eu.cloudnetservice.driver.inject.InjectUtil; @@ -41,7 +41,7 @@ public class DefaultModuleTaskEntry implements ModuleTaskEntry { protected final MethodAccessor methodAccessor; // information for injection - protected final Element[] paramTypes; + protected final BindingKey[] paramTypes; protected final InjectionLayer injectionLayer; // information about the task diff --git a/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleWrapper.java b/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleWrapper.java index 953a419c84..c00fb029b7 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleWrapper.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/module/DefaultModuleWrapper.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.driver.module; -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.driver.module.util.ModuleDependencyUtil; import java.io.IOException; @@ -65,7 +65,7 @@ public class DefaultModuleWrapper implements ModuleWrapper { private final URLClassLoader classLoader; private final Set dependingModules; private final ModuleConfiguration moduleConfiguration; - private final InjectionLayer moduleInjectionLayer; + private final InjectionLayer moduleInjectionLayer; private final Lock moduleLifecycleUpdateLock = new ReentrantLock(); private final Map> tasks = new EnumMap<>(ModuleLifeCycle.class); @@ -93,7 +93,7 @@ public DefaultModuleWrapper( @NonNull URLClassLoader classLoader, @NonNull Set dependingModules, @NonNull ModuleConfiguration moduleConfiguration, - @NonNull InjectionLayer moduleInjectionLayer + @NonNull InjectionLayer moduleInjectionLayer ) throws URISyntaxException { this.source = source; this.module = module; @@ -278,7 +278,7 @@ public DefaultModuleWrapper( * {@inheritDoc} */ @Override - public @NonNull InjectionLayer injectionLayer() { + public @NonNull InjectionLayer injectionLayer() { return this.moduleInjectionLayer; } diff --git a/driver/src/main/java/eu/cloudnetservice/driver/module/ModuleURLClassLoader.java b/driver/src/main/java/eu/cloudnetservice/driver/module/ModuleURLClassLoader.java index 1c090820cd..492002acb8 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/module/ModuleURLClassLoader.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/module/ModuleURLClassLoader.java @@ -17,7 +17,7 @@ package eu.cloudnetservice.driver.module; import com.google.common.collect.ObjectArrays; -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.driver.inject.InjectionLayerHolder; import java.io.IOException; @@ -38,7 +38,7 @@ * @since 4.0 */ @ApiStatus.Internal -public class ModuleURLClassLoader extends URLClassLoader implements InjectionLayerHolder { +public class ModuleURLClassLoader extends URLClassLoader implements InjectionLayerHolder { /** * All loaders which were created and of which the associated module is still loaded. @@ -50,7 +50,7 @@ public class ModuleURLClassLoader extends URLClassLoader implements InjectionLay ClassLoader.registerAsParallelCapable(); } - protected final InjectionLayer injectionLayer; + protected final InjectionLayer injectionLayer; /** * Creates an instance of this FinalizeURLClassLoader. @@ -63,7 +63,7 @@ public class ModuleURLClassLoader extends URLClassLoader implements InjectionLay public ModuleURLClassLoader( @NonNull URL moduleFileUrl, @NonNull Set moduleDependencyUrls, - @NonNull InjectionLayer injectionLayer + @NonNull InjectionLayer injectionLayer ) { super( ObjectArrays.concat(moduleFileUrl, moduleDependencyUrls.toArray(new URL[0])), @@ -114,7 +114,7 @@ public void close() throws IOException { * {@inheritDoc} */ @Override - public @NonNull InjectionLayer injectionLayer() { + public @NonNull InjectionLayer injectionLayer() { return this.injectionLayer; } diff --git a/driver/src/main/java/eu/cloudnetservice/driver/module/ModuleWrapper.java b/driver/src/main/java/eu/cloudnetservice/driver/module/ModuleWrapper.java index b9dc19d0d7..9a0a5eafbb 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/module/ModuleWrapper.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/module/ModuleWrapper.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.driver.module; -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.driver.inject.InjectionLayerHolder; import java.net.URI; @@ -36,7 +36,7 @@ * @see ModuleLifeCycle * @since 4.0 */ -public interface ModuleWrapper extends InjectionLayerHolder { +public interface ModuleWrapper extends InjectionLayerHolder { /** * Get all module tasks which were detected in the main class of the module. @@ -171,5 +171,5 @@ public interface ModuleWrapper extends InjectionLayerHolder { * @return the injection layer of the module. */ @Override - @NonNull InjectionLayer injectionLayer(); + @NonNull InjectionLayer injectionLayer(); } diff --git a/driver/src/main/java/eu/cloudnetservice/driver/module/driver/DriverModule.java b/driver/src/main/java/eu/cloudnetservice/driver/module/driver/DriverModule.java index 958e8ecfb6..87738f3f07 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/module/driver/DriverModule.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/module/driver/DriverModule.java @@ -16,9 +16,7 @@ package eu.cloudnetservice.driver.module.driver; -import dev.derklaro.aerogel.Element; -import dev.derklaro.aerogel.InjectionContext; -import dev.derklaro.aerogel.util.Qualifiers; +import dev.derklaro.aerogel.binding.key.BindingKey; import eu.cloudnetservice.driver.document.Document; import eu.cloudnetservice.driver.document.DocumentFactory; import eu.cloudnetservice.driver.document.DocumentParseException; @@ -27,8 +25,12 @@ import eu.cloudnetservice.driver.module.Module; import eu.cloudnetservice.driver.module.ModuleTask; import eu.cloudnetservice.driver.module.ModuleWrapper; +import jakarta.inject.Named; +import jakarta.inject.Provider; +import java.lang.annotation.Annotation; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; import lombok.NonNull; @@ -44,8 +46,18 @@ */ public class DriverModule extends DefaultModule { - protected static final Element CONFIG_PATH_ELEMENT = Element.forType(Path.class) - .requireAnnotation(Qualifiers.named("configPath")); + private static final BindingKey CONFIG_BINDING_KEY = BindingKey.of(Path.class).withQualifier(new Named() { + + @Override + public Class annotationType() { + return Named.class; + } + + @Override + public String value() { + return "configPath"; + } + }); /** * Reads the configuration file of this module from the default or overridden configuration path (via module.json) @@ -124,9 +136,8 @@ public void writeConfig(@NonNull Document config) { * @param the type of the configuration model. * @param the type modeling the class which should be instantiated. * @return the constructed instance of the given type, constructed with the configuration known to the context. - * @throws NullPointerException if one of the given parameters is null. - * @throws ModuleConfigurationInvalidException if the reader is unable to read the configuration from the file. - * @throws dev.derklaro.aerogel.AerogelException if no binding for T is present and no JIT binding can be created. + * @throws NullPointerException if one of the given parameters is null. + * @throws ModuleConfigurationInvalidException if the reader is unable to read the configuration from the file. */ public @NonNull T readConfigAndInstantiate( @NonNull InjectionLayer injectionLayer, @@ -166,26 +177,25 @@ public void writeConfig(@NonNull Document config) { * @param the type of the configuration model. * @param the type modeling the class which should be instantiated. * @return the constructed instance of the given type, constructed with the configuration known to the context. - * @throws NullPointerException if one of the given parameters is null. - * @throws ModuleConfigurationInvalidException if the reader is unable to read the configuration from the file. - * @throws dev.derklaro.aerogel.AerogelException if no binding for T is present and no JIT binding can be created. + * @throws NullPointerException if one of the given parameters is null. + * @throws ModuleConfigurationInvalidException if the reader is unable to read the configuration from the file. */ public @NonNull T readConfigAndInstantiate( @NonNull InjectionLayer injectionLayer, @NonNull Class configModelType, @NonNull Supplier defaultConfigFactory, @NonNull Class classToInstantiate, - @NonNull Consumer builderDecorator, + @NonNull Consumer, Provider>> builderDecorator, @NonNull DocumentFactory documentFactory ) { // read the config var config = this.readConfig(configModelType, defaultConfigFactory, documentFactory); - return injectionLayer.instance(classToInstantiate, builder -> { + return injectionLayer.instance(classToInstantiate, overrides -> { // write the default elements to the builder - builder.override(configModelType, config); - builder.override(CONFIG_PATH_ELEMENT, this.configPath()); + overrides.put(BindingKey.of(configModelType), () -> config); + overrides.put(CONFIG_BINDING_KEY, this::configPath); // apply the custom modifier - builderDecorator.accept(builder); + builderDecorator.accept(overrides); }); } diff --git a/driver/src/main/java/eu/cloudnetservice/driver/network/netty/buffer/NettyDataBufFactory.java b/driver/src/main/java/eu/cloudnetservice/driver/network/netty/buffer/NettyDataBufFactory.java index 4a63c388ef..2c4a390ed4 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/network/netty/buffer/NettyDataBufFactory.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/network/netty/buffer/NettyDataBufFactory.java @@ -17,7 +17,7 @@ package eu.cloudnetservice.driver.network.netty.buffer; import com.google.common.base.Preconditions; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.network.buffer.DataBuf; import eu.cloudnetservice.driver.network.buffer.DataBufFactory; import eu.cloudnetservice.driver.network.netty.NettyUtil; diff --git a/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/DefaultRPCFactory.java b/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/DefaultRPCFactory.java index 7c16eaab89..c28828f0e4 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/DefaultRPCFactory.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/DefaultRPCFactory.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.driver.network.rpc.defaults; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.network.buffer.DataBufFactory; import eu.cloudnetservice.driver.network.rpc.RPCSender; import eu.cloudnetservice.driver.network.rpc.defaults.generation.DefaultRPCImplementationBuilder; diff --git a/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/handler/DefaultRPCHandlerRegistry.java b/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/handler/DefaultRPCHandlerRegistry.java index d07e97db6a..7b24437298 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/handler/DefaultRPCHandlerRegistry.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/handler/DefaultRPCHandlerRegistry.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.driver.network.rpc.defaults.handler; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.network.rpc.handler.RPCHandler; import eu.cloudnetservice.driver.network.rpc.handler.RPCHandlerRegistry; import jakarta.inject.Singleton; diff --git a/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/DefaultObjectMapper.java b/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/DefaultObjectMapper.java index 6f7f20ac08..8968db1f08 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/DefaultObjectMapper.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/DefaultObjectMapper.java @@ -21,7 +21,7 @@ import com.github.benmanes.caffeine.cache.Scheduler; import com.google.common.collect.ImmutableMap; import com.google.common.reflect.TypeToken; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.tuple.Tuple2; import eu.cloudnetservice.driver.document.Document; import eu.cloudnetservice.driver.network.buffer.DataBuf; diff --git a/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/ObjectMapperInjectRegistration.java b/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/ObjectMapperInjectRegistration.java index 4e61598261..9badbda949 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/ObjectMapperInjectRegistration.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/ObjectMapperInjectRegistration.java @@ -16,7 +16,6 @@ package eu.cloudnetservice.driver.network.rpc.defaults.object; -import dev.derklaro.aerogel.binding.BindingBuilder; import eu.cloudnetservice.driver.inject.BootLayerConfigurator; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.driver.network.rpc.object.ObjectMapper; @@ -34,10 +33,7 @@ public final class ObjectMapperInjectRegistration implements BootLayerConfigurat */ @Override public void configureBootLayer(@NonNull InjectionLayer bootLayer) { - var bindingConstructor = BindingBuilder.create() - .bind(ObjectMapper.class) - .bindFully(DefaultObjectMapper.class) - .toInstance(DefaultObjectMapper.DEFAULT_MAPPER); - bootLayer.install(bindingConstructor); + var builder = bootLayer.injector().createBindingBuilder(); + bootLayer.install(builder.bind(ObjectMapper.class).toInstance(DefaultObjectMapper.DEFAULT_MAPPER)); } } diff --git a/driver/src/main/java/eu/cloudnetservice/driver/registry/DefaultServiceRegistry.java b/driver/src/main/java/eu/cloudnetservice/driver/registry/DefaultServiceRegistry.java index bd4557e037..76bc3a4fdb 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/registry/DefaultServiceRegistry.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/registry/DefaultServiceRegistry.java @@ -18,11 +18,10 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; -import dev.derklaro.aerogel.auto.Provides; -import dev.derklaro.aerogel.binding.BindingBuilder; -import dev.derklaro.aerogel.internal.reflect.TypeUtil; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.driver.registry.injection.Service; +import io.leangen.geantyref.GenericTypeReflector; import jakarta.inject.Inject; import jakarta.inject.Singleton; import java.util.Collection; @@ -45,34 +44,24 @@ public class DefaultServiceRegistry implements ServiceRegistry { @Inject public DefaultServiceRegistry(@NonNull InjectionLayer injectionLayer) { - var bindingConstructor = BindingBuilder.create() - .bindMatching(element -> { - // ensure that the element has at least one special requirement (like the Service annotation) - if (element.hasSpecialRequirements()) { - return element.requiredAnnotations() - .stream() - .anyMatch(predicate -> predicate.annotationType().equals(Service.class)); + var builder = injectionLayer.injector().createBindingBuilder(); + var dynamicBinding = builder.bindDynamically() + .annotationPresent(Service.class) + .toKeyedBindingProvider((key, scopedBuilder) -> { + var annotation = (Service) key.qualifierAnnotation().orElseThrow(); + var serviceClass = GenericTypeReflector.erase(key.type()); + var serviceName = annotation.name(); + + Object result; + if (serviceName.isEmpty()) { + result = this.firstProvider(serviceClass); } else { - return false; + result = this.provider(serviceClass, serviceName); } - }).toLazyProvider((element, $) -> () -> { - // get the predicate for the Service annotation - return element.requiredAnnotations().stream() - .filter(predicate -> predicate.annotationType().equals(Service.class)) - .findFirst() - .map(annotationPredicate -> { - var annotationValues = annotationPredicate.annotationValues(); - var serviceClass = TypeUtil.rawType(element.componentType()); - var serviceName = (String) annotationValues.get("name"); - - if (serviceName.isEmpty()) { - return this.firstProvider(serviceClass); - } else { - return this.provider(serviceClass, serviceName); - } - }).orElse(null); + + return scopedBuilder.toInstance(result); }); - injectionLayer.install(bindingConstructor); + injectionLayer.install(dynamicBinding); } /** diff --git a/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/PlatformPluginInfo.java b/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/PlatformPluginInfo.java index 2564aede29..5f7c71c92b 100644 --- a/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/PlatformPluginInfo.java +++ b/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/PlatformPluginInfo.java @@ -16,19 +16,23 @@ package eu.cloudnetservice.ext.platforminject.api; -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayerHolder; import lombok.NonNull; -public interface PlatformPluginInfo extends InjectionLayerHolder { +public interface PlatformPluginInfo extends InjectionLayerHolder { - @NonNull I id(); + @NonNull + I id(); - @NonNull T platformData(); + @NonNull + T platformData(); - @NonNull P platformPluginInstance(); + @NonNull + P platformPluginInstance(); - @NonNull Class platformPluginClass(); + @NonNull + Class platformPluginClass(); void close(); } diff --git a/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/defaults/BasePlatformPluginManager.java b/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/defaults/BasePlatformPluginManager.java index 5448f2685f..df4e9de8e7 100644 --- a/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/defaults/BasePlatformPluginManager.java +++ b/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/defaults/BasePlatformPluginManager.java @@ -17,7 +17,6 @@ package eu.cloudnetservice.ext.platforminject.api.defaults; import dev.derklaro.aerogel.Injector; -import dev.derklaro.aerogel.SpecifiedInjector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.ext.platforminject.api.PlatformEntrypoint; import eu.cloudnetservice.ext.platforminject.api.PlatformPluginInfo; @@ -135,5 +134,5 @@ protected void configureInjectionLayer(@NonNull InjectionLayer layer, @NonNul } } - protected abstract @NonNull InjectionLayer createInjectionLayer(@NonNull T platformData); + protected abstract @NonNull InjectionLayer createInjectionLayer(@NonNull T platformData); } diff --git a/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/defaults/DefaultPlatformPluginInfo.java b/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/defaults/DefaultPlatformPluginInfo.java index db37c505d6..808f3a7111 100644 --- a/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/defaults/DefaultPlatformPluginInfo.java +++ b/ext/platform-inject-support/api/src/main/java/eu/cloudnetservice/ext/platforminject/api/defaults/DefaultPlatformPluginInfo.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.ext.platforminject.api.defaults; -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.ext.platforminject.api.PlatformEntrypoint; import eu.cloudnetservice.ext.platforminject.api.PlatformPluginInfo; @@ -25,7 +25,7 @@ public record DefaultPlatformPluginInfo( @NonNull I id, @NonNull T platformData, - @NonNull InjectionLayer injectionLayer, + @NonNull InjectionLayer injectionLayer, @NonNull P platformPluginInstance, @NonNull Class platformPluginClass ) implements PlatformPluginInfo { diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bukkit/BukkitPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bukkit/BukkitPlatformPluginManager.java index fdd138f5f1..3002e4e542 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bukkit/BukkitPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bukkit/BukkitPlatformPluginManager.java @@ -16,10 +16,9 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.bukkit; -import static eu.cloudnetservice.driver.inject.InjectUtil.createFixedBinding; import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.ext.platforminject.api.defaults.BasePlatformPluginManager; import eu.cloudnetservice.ext.platforminject.api.util.FunctionalUtil; @@ -40,14 +39,15 @@ public BukkitPlatformPluginManager() { } @Override - protected @NonNull InjectionLayer createInjectionLayer(@NonNull JavaPlugin platformData) { + protected @NonNull InjectionLayer createInjectionLayer(@NonNull JavaPlugin platformData) { return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { // install bindings for the platform - layer.install(createFixedBinding(platformData.getServer(), Server.class)); - layer.install(createFixedBinding(platformData.getServer().getScheduler(), BukkitScheduler.class)); - layer.install(createFixedBinding(platformData.getServer().getPluginManager(), PluginManager.class)); - layer.install(createFixedBinding(platformData.getServer().getServicesManager(), ServicesManager.class)); - layer.install(createFixedBinding(platformData.getServer().getScoreboardManager(), ScoreboardManager.class)); + var builder = injector.createBindingBuilder(); + layer.install(builder.bind(Server.class).toInstance(platformData.getServer())); + layer.install(builder.bind(BukkitScheduler.class).toInstance(platformData.getServer().getScheduler())); + layer.install(builder.bind(PluginManager.class).toInstance(platformData.getServer().getPluginManager())); + layer.install(builder.bind(ServicesManager.class).toInstance(platformData.getServer().getServicesManager())); + layer.install(builder.bind(ScoreboardManager.class).toInstance(platformData.getServer().getScoreboardManager())); // install the bindings which are specific to the plugin injector.installSpecified(fixedBindingWithBound(platformData, Plugin.class, PluginBase.class, JavaPlugin.class)); diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bungeecord/BungeeCordPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bungeecord/BungeeCordPlatformPluginManager.java index ecc96a566d..03da0d5d34 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bungeecord/BungeeCordPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bungeecord/BungeeCordPlatformPluginManager.java @@ -16,7 +16,6 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.bungeecord; -import static eu.cloudnetservice.driver.inject.InjectUtil.createFixedBinding; import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; import dev.derklaro.aerogel.SpecifiedInjector; @@ -40,10 +39,10 @@ public BungeeCordPlatformPluginManager() { protected @NonNull InjectionLayer createInjectionLayer(@NonNull Plugin platformData) { return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { // install bindings for the platform - layer.install(createFixedBinding(platformData.getProxy(), ProxyServer.class)); - layer.install(createFixedBinding(platformData.getProxy().getConfig(), ProxyConfig.class)); - layer.install(createFixedBinding(platformData.getProxy().getScheduler(), TaskScheduler.class)); - layer.install(createFixedBinding(platformData.getProxy().getPluginManager(), PluginManager.class)); + layer.install(bindingBuilder.bind(ProxyServer.class).toInstance(platformData.getProxy())); + layer.install(bindingBuilder.bind(ProxyConfig.class).toInstance(platformData.getProxy().getConfig())); + layer.install(bindingBuilder.bind(TaskScheduler.class).toInstance(platformData.getProxy().getScheduler())); + layer.install(bindingBuilder.bind(PluginManager.class).toInstance(platformData.getProxy().getPluginManager())); // install the bindings which are specific to the plugin injector.installSpecified(fixedBindingWithBound(platformData, Plugin.class)); diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/limboloohp/LimboLoohpPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/limboloohp/LimboLoohpPlatformPluginManager.java index a3ce99b2a5..75faec18b0 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/limboloohp/LimboLoohpPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/limboloohp/LimboLoohpPlatformPluginManager.java @@ -40,10 +40,10 @@ public LimboLoohpPlatformPluginManager() { protected @NonNull InjectionLayer createInjectionLayer(@NonNull LimboPlugin platformData) { return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { // install bindings for the platform - layer.install(createFixedBinding(platformData.getServer(), Limbo.class)); - layer.install(createFixedBinding(platformData.getServer().getPluginManager(), PluginManager.class)); - layer.install(createFixedBinding(platformData.getServer().getEventsManager(), EventsManager.class)); - layer.install(createFixedBinding(platformData.getServer().getScheduler(), LimboScheduler.class)); + layer.install(bindingBuilder.bind(Limbo.class).toInstance(platformData.getServer())); + layer.install(bindingBuilder.bind(PluginManager.class).toInstance(platformData.getServer().getPluginManager())); + layer.install(bindingBuilder.bind(EventsManager.class).toInstance(platformData.getServer().getEventsManager())); + layer.install(bindingBuilder.bind(LimboScheduler.class).toInstance(platformData.getServer().getScheduler())); // install the bindings which are specific to the plugin injector.installSpecified(fixedBindingWithBound(platformData, LimboPlugin.class)); diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/minestom/MinestomPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/minestom/MinestomPlatformPluginManager.java index 919a09e2a7..fc3ff17920 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/minestom/MinestomPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/minestom/MinestomPlatformPluginManager.java @@ -16,7 +16,6 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.minestom; -import static eu.cloudnetservice.driver.inject.InjectUtil.createFixedBinding; import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; import dev.derklaro.aerogel.SpecifiedInjector; @@ -56,24 +55,24 @@ public MinestomPlatformPluginManager() { protected @NonNull InjectionLayer createInjectionLayer(@NonNull Extension platformData) { return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { // install bindings for the platform - layer.install(createFixedBinding(MinecraftServer.process(), ServerProcess.class)); - layer.install(createFixedBinding(platformData.getLogger(), ComponentLogger.class)); - layer.install(createFixedBinding(MinecraftServer.getTagManager(), TagManager.class)); - layer.install(createFixedBinding(MinecraftServer.getTeamManager(), TeamManager.class)); - layer.install(createFixedBinding(MinecraftServer.getBlockManager(), BlockManager.class)); - layer.install(createFixedBinding(MinecraftServer.getRecipeManager(), RecipeManager.class)); - layer.install(createFixedBinding(MinecraftServer.getBossBarManager(), BossBarManager.class)); - layer.install(createFixedBinding(MinecraftServer.getCommandManager(), CommandManager.class)); - layer.install(createFixedBinding(MinecraftServer.getPacketProcessor(), PacketProcessor.class)); - layer.install(createFixedBinding(MinecraftServer.getInstanceManager(), InstanceManager.class)); - layer.install(createFixedBinding(MinecraftServer.getExceptionManager(), ExceptionManager.class)); - layer.install(createFixedBinding(MinecraftServer.getBenchmarkManager(), BenchmarkManager.class)); - layer.install(createFixedBinding(MinecraftServer.getSchedulerManager(), SchedulerManager.class)); - layer.install(createFixedBinding(MinecraftServer.getConnectionManager(), ConnectionManager.class)); - layer.install(createFixedBinding(ExtensionBootstrap.getExtensionManager(), ExtensionManager.class)); - layer.install(createFixedBinding(MinecraftServer.getGlobalEventHandler(), GlobalEventHandler.class)); - layer.install(createFixedBinding(MinecraftServer.getAdvancementManager(), AdvancementManager.class)); - layer.install(createFixedBinding(MinecraftServer.getPacketListenerManager(), PacketListenerManager.class)); + layer.install(bindingBuilder.bind(ServerProcess.class).toInstance(MinecraftServer.process())); + layer.install(bindingBuilder.bind(ComponentLogger.class).toInstance(platformData.getLogger())); + layer.install(bindingBuilder.bind(TagManager.class).toInstance(MinecraftServer.getTagManager())); + layer.install(bindingBuilder.bind(TeamManager.class).toInstance(MinecraftServer.getTeamManager())); + layer.install(bindingBuilder.bind(BlockManager.class).toInstance(MinecraftServer.getBlockManager())); + layer.install(bindingBuilder.bind(RecipeManager.class).toInstance(MinecraftServer.getRecipeManager())); + layer.install(bindingBuilder.bind(BossBarManager.class).toInstance(MinecraftServer.getBossBarManager())); + layer.install(bindingBuilder.bind(CommandManager.class).toInstance(MinecraftServer.getCommandManager())); + layer.install(bindingBuilder.bind(PacketProcessor.class).toInstance(MinecraftServer.getPacketProcessor())); + layer.install(bindingBuilder.bind(InstanceManager.class).toInstance(MinecraftServer.getInstanceManager())); + layer.install(bindingBuilder.bind(ExceptionManager.class).toInstance(MinecraftServer.getExceptionManager())); + layer.install(bindingBuilder.bind(BenchmarkManager.class).toInstance(MinecraftServer.getBenchmarkManager())); + layer.install(bindingBuilder.bind(SchedulerManager.class).toInstance(MinecraftServer.getSchedulerManager())); + layer.install(bindingBuilder.bind(ConnectionManager.class).toInstance(MinecraftServer.getConnectionManager())); + layer.install(bindingBuilder.bind(ExtensionManager.class).toInstance(ExtensionBootstrap.getExtensionManager())); + layer.install(bindingBuilder.bind(GlobalEventHandler.class).toInstance(MinecraftServer.getGlobalEventHandler())); + layer.install(bindingBuilder.bind(AdvancementManager.class).toInstance(MinecraftServer.getAdvancementManager())); + layer.install(bindingBuilder.bind(PacketListenerManager.class).toInstance(MinecraftServer.getPacketListenerManager())); // install the bindings which are specific to the plugin injector.installSpecified(fixedBindingWithBound(platformData, Extension.class)); diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/nukkit/NukkitPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/nukkit/NukkitPlatformPluginManager.java index 538dbd7b6e..a7025afeb6 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/nukkit/NukkitPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/nukkit/NukkitPlatformPluginManager.java @@ -16,7 +16,6 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.nukkit; -import static eu.cloudnetservice.driver.inject.InjectUtil.createFixedBinding; import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; import cn.nukkit.Server; @@ -28,7 +27,7 @@ import cn.nukkit.plugin.service.ServiceManager; import cn.nukkit.resourcepacks.ResourcePackManager; import cn.nukkit.scheduler.ServerScheduler; -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.ext.platforminject.api.defaults.BasePlatformPluginManager; import eu.cloudnetservice.ext.platforminject.api.util.FunctionalUtil; @@ -41,19 +40,22 @@ public NukkitPlatformPluginManager() { } @Override - protected @NonNull InjectionLayer createInjectionLayer(@NonNull PluginBase platformData) { - return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { + protected @NonNull InjectionLayer createInjectionLayer(@NonNull PluginBase platformData) { + return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", targetedBuilder -> { // install bindings for the platform - layer.install(createFixedBinding(platformData.getServer(), Server.class)); - layer.install(createFixedBinding(platformData.getServer().getCommandMap(), CommandMap.class)); - layer.install(createFixedBinding(platformData.getServer().getScheduler(), ServerScheduler.class)); - layer.install(createFixedBinding(platformData.getServer().getPluginManager(), PluginManager.class)); - layer.install(createFixedBinding(platformData.getServer().getServiceManager(), ServiceManager.class)); - layer.install(createFixedBinding(platformData.getServer().getCraftingManager(), CraftingManager.class)); - layer.install(createFixedBinding(platformData.getServer().getResourcePackManager(), ResourcePackManager.class)); + var layer = BASE_INJECTION_LAYER; + var builder = layer.injector().createBindingBuilder(); + layer.install(builder.bind(Server.class).toInstance(platformData.getServer())); + layer.install(builder.bind(CommandMap.class).toInstance(platformData.getServer().getCommandMap())); + layer.install(builder.bind(ServerScheduler.class).toInstance(platformData.getServer().getScheduler())); + layer.install(builder.bind(PluginManager.class).toInstance(platformData.getServer().getPluginManager())); + layer.install(builder.bind(ServiceManager.class).toInstance(platformData.getServer().getServiceManager())); + layer.install(builder.bind(CraftingManager.class).toInstance(platformData.getServer().getCraftingManager())); + layer.install(builder.bind(ResourcePackManager.class) + .toInstance(platformData.getServer().getResourcePackManager())); // install the bindings which are specific to the plugin - injector.installSpecified(fixedBindingWithBound(platformData, PluginBase.class, Plugin.class)); + targetedBuilder.installBinding(fixedBindingWithBound(platformData, PluginBase.class, Plugin.class)); }); } } diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/sponge/SpongePlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/sponge/SpongePlatformPluginManager.java index 84d8066618..8592ac59e6 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/sponge/SpongePlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/sponge/SpongePlatformPluginManager.java @@ -76,29 +76,29 @@ public SpongePlatformPluginManager() { .toInstance(Sponge.game().asyncScheduler())); // game bindings - layer.install(createFixedBinding(Sponge.game(), Game.class)); - layer.install(createFixedBinding(Sponge.game().platform(), Platform.class)); - layer.install(createFixedBinding(Sponge.game().dataManager(), DataManager.class)); - layer.install(createFixedBinding(Sponge.game().eventManager(), EventManager.class)); - layer.install(createFixedBinding(Sponge.game().configManager(), ConfigManager.class)); - layer.install(createFixedBinding(Sponge.game().pluginManager(), PluginManager.class)); - layer.install(createFixedBinding(Sponge.game().channelManager(), ChannelManager.class)); - layer.install(createFixedBinding(Sponge.game().builderProvider(), BuilderProvider.class)); - layer.install(createFixedBinding(Sponge.game().factoryProvider(), FactoryProvider.class)); - layer.install(createFixedBinding(Sponge.game().metricsConfigManager(), MetricsConfigManager.class)); - layer.install(createFixedBinding(Sponge.game().serviceProvider(), ServiceProvider.GameScoped.class)); + layer.install(bindingBuilder.bind(Game.class).toInstance(Sponge.game())); + layer.install(bindingBuilder.bind(Platform.class).toInstance(Sponge.game().platform())); + layer.install(bindingBuilder.bind(DataManager.class).toInstance(Sponge.game().dataManager())); + layer.install(bindingBuilder.bind(EventManager.class).toInstance(Sponge.game().eventManager())); + layer.install(bindingBuilder.bind(ConfigManager.class).toInstance(Sponge.game().configManager())); + layer.install(bindingBuilder.bind(PluginManager.class).toInstance(Sponge.game().pluginManager())); + layer.install(bindingBuilder.bind(ChannelManager.class).toInstance(Sponge.game().channelManager())); + layer.install(bindingBuilder.bind(BuilderProvider.class).toInstance(Sponge.game().builderProvider())); + layer.install(bindingBuilder.bind(FactoryProvider.class).toInstance(Sponge.game().factoryProvider())); + layer.install(bindingBuilder.bind(MetricsConfigManager.class).toInstance(Sponge.game().metricsConfigManager())); + layer.install(bindingBuilder.bind(ServiceProvider.GameScoped.class).toInstance(Sponge.game().serviceProvider())); // server bindings - layer.install(createFixedBinding(Sponge.server().mapStorage(), MapStorage.class)); - layer.install(createFixedBinding(Sponge.server().userManager(), UserManager.class)); - layer.install(createFixedBinding(Sponge.server().worldManager(), WorldManager.class)); - layer.install(createFixedBinding(Sponge.server(), Server.class, RegistryHolder.class)); - layer.install(createFixedBinding(Sponge.server().recipeManager(), RecipeManager.class)); - layer.install(createFixedBinding(Sponge.server().teleportHelper(), TeleportHelper.class)); - layer.install(createFixedBinding(Sponge.server().commandManager(), CommandManager.class)); - layer.install(createFixedBinding(Sponge.server().packRepository(), PackRepository.class)); - layer.install(createFixedBinding(Sponge.server().resourceManager(), ResourceManager.class)); - layer.install(createFixedBinding(Sponge.server().causeStackManager(), CauseStackManager.class)); + layer.install(bindingBuilder.bind(MapStorage.class).toInstance(Sponge.server().mapStorage())); + layer.install(bindingBuilder.bind(UserManager.class).toInstance(Sponge.server().userManager())); + layer.install(bindingBuilder.bind(WorldManager.class).toInstance(Sponge.server().worldManager())); + layer.install(bindingBuilder.bind(RegistryHolder.class).toInstance(Sponge.server(), Server.class)); + layer.install(bindingBuilder.bind(RecipeManager.class).toInstance(Sponge.server().recipeManager())); + layer.install(bindingBuilder.bind(TeleportHelper.class).toInstance(Sponge.server().teleportHelper())); + layer.install(bindingBuilder.bind(CommandManager.class).toInstance(Sponge.server().commandManager())); + layer.install(bindingBuilder.bind(PackRepository.class).toInstance(Sponge.server().packRepository())); + layer.install(bindingBuilder.bind(ResourceManager.class).toInstance(Sponge.server().resourceManager())); + layer.install(bindingBuilder.bind(CauseStackManager.class).toInstance(Sponge.server().causeStackManager())); layer.install(createFixedBinding( Sponge.server().gameProfileManager(), GameProfileManager.class, GameProfileProvider.class)); diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java index a7a1bbddb7..753cea8dc2 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java @@ -47,12 +47,12 @@ public VelocityPlatformPluginManager() { ) { return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { // install bindings for the platform - layer.install(createFixedBinding(platformData.platformInstance(), ProxyServer.class)); - layer.install(createFixedBinding(platformData.platformInstance().getScheduler(), Scheduler.class)); - layer.install(createFixedBinding(platformData.platformInstance().getEventManager(), EventManager.class)); - layer.install(createFixedBinding(platformData.platformInstance().getPluginManager(), PluginManager.class)); - layer.install(createFixedBinding(platformData.platformInstance().getCommandManager(), CommandManager.class)); - layer.install(createFixedBinding(platformData.platformInstance().getChannelRegistrar(), ChannelRegistrar.class)); + layer.install(bindingBuilder.bind(ProxyServer.class).toInstance(platformData.platformInstance())); + layer.install(bindingBuilder.bind(Scheduler.class).toInstance(platformData.platformInstance().getScheduler())); + layer.install(bindingBuilder.bind(EventManager.class).toInstance(platformData.platformInstance().getEventManager())); + layer.install(bindingBuilder.bind(PluginManager.class).toInstance(platformData.platformInstance().getPluginManager())); + layer.install(bindingBuilder.bind(CommandManager.class).toInstance(platformData.platformInstance().getCommandManager())); + layer.install(bindingBuilder.bind(ChannelRegistrar.class).toInstance(platformData.platformInstance().getChannelRegistrar())); // install the bindings which are specific to the plugin injector.installSpecified(createFixedBinding(platformData.container(), PluginContainer.class)); diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/waterdog/WaterDogPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/waterdog/WaterDogPlatformPluginManager.java index 7fdb356b32..b23fc9c0c4 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/waterdog/WaterDogPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/waterdog/WaterDogPlatformPluginManager.java @@ -47,17 +47,17 @@ public WaterDogPlatformPluginManager() { protected @NonNull InjectionLayer createInjectionLayer(@NonNull Plugin platformData) { return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { // install bindings for the platform - layer.install(createFixedBinding(platformData.getProxy(), ProxyServer.class)); - layer.install(createFixedBinding(platformData.getProxy().getLogger(), MainLogger.class)); - layer.install(createFixedBinding(platformData.getProxy().getCommandMap(), CommandMap.class)); - layer.install(createFixedBinding(platformData.getProxy().getPackManager(), PackManager.class)); - layer.install(createFixedBinding(platformData.getProxy().getLanguageConfig(), LangConfig.class)); - layer.install(createFixedBinding(platformData.getProxy().getEventManager(), EventManager.class)); - layer.install(createFixedBinding(platformData.getProxy().getPlayerManager(), PlayerManager.class)); - layer.install(createFixedBinding(platformData.getProxy().getServerInfoMap(), ServerInfoMap.class)); - layer.install(createFixedBinding(platformData.getProxy().getPluginManager(), PluginManager.class)); - layer.install(createFixedBinding(platformData.getProxy().getScheduler(), WaterdogScheduler.class)); - layer.install(createFixedBinding(platformData.getProxy().getConfigurationManager(), ConfigurationManager.class)); + layer.install(bindingBuilder.bind(ProxyServer.class).toInstance(platformData.getProxy())); + layer.install(bindingBuilder.bind(MainLogger.class).toInstance(platformData.getProxy().getLogger())); + layer.install(bindingBuilder.bind(CommandMap.class).toInstance(platformData.getProxy().getCommandMap())); + layer.install(bindingBuilder.bind(PackManager.class).toInstance(platformData.getProxy().getPackManager())); + layer.install(bindingBuilder.bind(LangConfig.class).toInstance(platformData.getProxy().getLanguageConfig())); + layer.install(bindingBuilder.bind(EventManager.class).toInstance(platformData.getProxy().getEventManager())); + layer.install(bindingBuilder.bind(PlayerManager.class).toInstance(platformData.getProxy().getPlayerManager())); + layer.install(bindingBuilder.bind(ServerInfoMap.class).toInstance(platformData.getProxy().getServerInfoMap())); + layer.install(bindingBuilder.bind(PluginManager.class).toInstance(platformData.getProxy().getPluginManager())); + layer.install(bindingBuilder.bind(WaterdogScheduler.class).toInstance(platformData.getProxy().getScheduler())); + layer.install(bindingBuilder.bind(ConfigurationManager.class).toInstance(platformData.getProxy().getConfigurationManager())); // install the bindings which are specific to the plugin injector.installSpecified(fixedBindingWithBound(platformData, Plugin.class)); diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 393177e884..0d449a4034 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -39,7 +39,7 @@ mysqlConnector = "9.0.0" oshi = "6.6.3" vavr = "0.10.4" sshj = "0.38.0" -aerogel = "2.1.0" +aerogel = "3.0.0-SNAPSHOT" awsSdk = "2.27.9" unirest = "4.4.4" caffeine = "3.1.8" diff --git a/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/NodeBridgeManagement.java b/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/NodeBridgeManagement.java index b9642f006a..9efd1ff180 100644 --- a/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/NodeBridgeManagement.java +++ b/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/NodeBridgeManagement.java @@ -16,8 +16,8 @@ package eu.cloudnetservice.modules.bridge.node; -import dev.derklaro.aerogel.PostConstruct; -import dev.derklaro.aerogel.auto.Provides; + +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.channel.ChannelMessage; import eu.cloudnetservice.driver.document.Document; import eu.cloudnetservice.driver.event.EventManager; diff --git a/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/player/NodePlayerManager.java b/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/player/NodePlayerManager.java index c75af07c33..127ba38cbc 100644 --- a/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/player/NodePlayerManager.java +++ b/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/player/NodePlayerManager.java @@ -20,8 +20,8 @@ import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.Striped; -import dev.derklaro.aerogel.PostConstruct; -import dev.derklaro.aerogel.auto.Provides; + +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.channel.ChannelMessage; import eu.cloudnetservice.driver.document.Document; import eu.cloudnetservice.driver.event.EventManager; diff --git a/modules/dockerized-services/src/main/java/eu/cloudnetservice/modules/docker/DockerizedServicesModule.java b/modules/dockerized-services/src/main/java/eu/cloudnetservice/modules/docker/DockerizedServicesModule.java index 7a7e317f1c..698f4910fc 100644 --- a/modules/dockerized-services/src/main/java/eu/cloudnetservice/modules/docker/DockerizedServicesModule.java +++ b/modules/dockerized-services/src/main/java/eu/cloudnetservice/modules/docker/DockerizedServicesModule.java @@ -86,9 +86,10 @@ public void registerServiceFactory( var dockerClient = DockerClientImpl.getInstance(clientConfig, dockerHttpClient); // construct the factory instance & register it in the service manager - var factory = moduleInjectionLayer.instance(DockerizedLocalCloudServiceFactory.class, builder -> { + var factory = moduleInjectionLayer.instance(DockerizedLocalCloudServiceFactory.class, map -> { + map builder.override(Element.forType(DockerClient.class), dockerClient); - builder.override(Element.forType(DockerConfiguration.class), this.configuration); + map.override(Element.forType(DockerConfiguration.class), this.configuration); }); serviceManager.addCloudServiceFactory(this.configuration.factoryName(), factory); } diff --git a/modules/signs/src/main/java/eu/cloudnetservice/modules/signs/node/NodeSignManagement.java b/modules/signs/src/main/java/eu/cloudnetservice/modules/signs/node/NodeSignManagement.java index 5489d325e9..3098ecbaa7 100644 --- a/modules/signs/src/main/java/eu/cloudnetservice/modules/signs/node/NodeSignManagement.java +++ b/modules/signs/src/main/java/eu/cloudnetservice/modules/signs/node/NodeSignManagement.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.modules.signs.node; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.database.Database; import eu.cloudnetservice.driver.database.DatabaseProvider; import eu.cloudnetservice.driver.document.Document; diff --git a/modules/syncproxy/src/main/java/eu/cloudnetservice/modules/syncproxy/node/NodeSyncProxyManagement.java b/modules/syncproxy/src/main/java/eu/cloudnetservice/modules/syncproxy/node/NodeSyncProxyManagement.java index 1a61fca59a..a4205e4e86 100644 --- a/modules/syncproxy/src/main/java/eu/cloudnetservice/modules/syncproxy/node/NodeSyncProxyManagement.java +++ b/modules/syncproxy/src/main/java/eu/cloudnetservice/modules/syncproxy/node/NodeSyncProxyManagement.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.modules.syncproxy.node; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.document.Document; import eu.cloudnetservice.driver.event.EventManager; import eu.cloudnetservice.driver.network.rpc.factory.RPCFactory; diff --git a/node/src/main/java/eu/cloudnetservice/node/Node.java b/node/src/main/java/eu/cloudnetservice/node/Node.java index 4c988beca0..ad939d8be1 100644 --- a/node/src/main/java/eu/cloudnetservice/node/Node.java +++ b/node/src/main/java/eu/cloudnetservice/node/Node.java @@ -17,7 +17,6 @@ package eu.cloudnetservice.node; import dev.derklaro.aerogel.Order; -import dev.derklaro.aerogel.binding.BindingBuilder; import eu.cloudnetservice.common.language.I18n; import eu.cloudnetservice.common.log.io.LogOutputStream; import eu.cloudnetservice.driver.channel.ChannelMessage; @@ -225,10 +224,9 @@ private void initializeDatabaseProvider( } // bind the provider for dependency injection - var binding = BindingBuilder.create() - .bindAll(DatabaseProvider.class, NodeDatabaseProvider.class) - .toInstance(provider); - bootLayer.install(binding); + var builder = bootLayer.injector().createBindingBuilder(); + bootLayer.install(builder.bind(DatabaseProvider.class).toInstance(provider)); + bootLayer.install(builder.bind(NodeDatabaseProvider.class).toInstance(provider)); // register the rpc handler for the database provider var dbProviderHandler = rpcFactory.newRPCHandlerBuilder(DatabaseProvider.class).targetInstance(provider).build(); diff --git a/node/src/main/java/eu/cloudnetservice/node/boot/BootFactories.java b/node/src/main/java/eu/cloudnetservice/node/boot/BootFactories.java index d6e9db0168..cd522b987d 100644 --- a/node/src/main/java/eu/cloudnetservice/node/boot/BootFactories.java +++ b/node/src/main/java/eu/cloudnetservice/node/boot/BootFactories.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.node.boot; -import dev.derklaro.aerogel.auto.Factory; +import dev.derklaro.aerogel.auto.annotation.Factory; import eu.cloudnetservice.driver.CloudNetVersion; import eu.cloudnetservice.driver.ComponentInfo; import eu.cloudnetservice.driver.DriverEnvironment; diff --git a/node/src/main/java/eu/cloudnetservice/node/boot/Bootstrap.java b/node/src/main/java/eu/cloudnetservice/node/boot/Bootstrap.java index 75330bd396..628aaf399c 100644 --- a/node/src/main/java/eu/cloudnetservice/node/boot/Bootstrap.java +++ b/node/src/main/java/eu/cloudnetservice/node/boot/Bootstrap.java @@ -18,9 +18,6 @@ import ch.qos.logback.classic.Logger; import com.google.common.collect.Lists; -import dev.derklaro.aerogel.Element; -import dev.derklaro.aerogel.binding.BindingBuilder; -import dev.derklaro.aerogel.util.Qualifiers; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.node.Node; import io.leangen.geantyref.TypeFactory; @@ -48,21 +45,17 @@ public static void main(@NonNull String[] args) throws Throwable { var rootLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); // initial bindings which we cannot (or it makes no sense to) construct - bootInjectLayer.install(BindingBuilder.create() - .bind(Element.forType(org.slf4j.Logger.class).requireAnnotation(Qualifiers.named("root"))) - .toInstance(rootLogger)); - bootInjectLayer.install(BindingBuilder.create() - .bind(Element.forType(Instant.class).requireAnnotation(Qualifiers.named("startInstant"))) - .toInstance(startInstant)); - bootInjectLayer.install(BindingBuilder.create() - .bind(Element.forType(ScheduledExecutorService.class).requireAnnotation(Qualifiers.named("taskScheduler"))) + var builder = bootInjectLayer.injector().createBindingBuilder(); + bootInjectLayer.install(builder.bind(org.slf4j.Logger.class).qualifiedWithName("root").toInstance(rootLogger)); + bootInjectLayer.install(builder.bind(Instant.class).qualifiedWithName("startInstant").toInstance(startInstant)); + bootInjectLayer.install(builder + .bind(ScheduledExecutorService.class) + .qualifiedWithName("taskScheduler") .toInstance(Executors.newScheduledThreadPool(2))); // console arguments var type = TypeFactory.parameterizedClass(List.class, String.class); - bootInjectLayer.install(BindingBuilder.create() - .bind(Element.forType(type).requireAnnotation(Qualifiers.named("consoleArgs"))) - .toInstance(Lists.newArrayList(args))); + bootInjectLayer.install(builder.bind(type).qualifiedWithName("consoleArgs").toInstance(Lists.newArrayList(args))); // boot CloudNet bootInjectLayer.instance(Node.class); diff --git a/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultLocalNodeServer.java b/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultLocalNodeServer.java index 6ed2389230..083b88b502 100644 --- a/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultLocalNodeServer.java +++ b/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultLocalNodeServer.java @@ -17,7 +17,7 @@ package eu.cloudnetservice.node.cluster.defaults; import com.google.common.base.Preconditions; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.concurrent.TaskUtil; import eu.cloudnetservice.driver.CloudNetVersion; import eu.cloudnetservice.driver.cluster.NetworkClusterNode; diff --git a/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultNodeServerProvider.java b/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultNodeServerProvider.java index be69aeb5ad..937279dce4 100644 --- a/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultNodeServerProvider.java +++ b/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultNodeServerProvider.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.node.cluster.defaults; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.channel.ChannelMessage; import eu.cloudnetservice.driver.cluster.NetworkCluster; import eu.cloudnetservice.driver.cluster.NetworkClusterNode; diff --git a/node/src/main/java/eu/cloudnetservice/node/cluster/sync/DefaultDataSyncRegistry.java b/node/src/main/java/eu/cloudnetservice/node/cluster/sync/DefaultDataSyncRegistry.java index c3229f435e..9bfc750bfb 100644 --- a/node/src/main/java/eu/cloudnetservice/node/cluster/sync/DefaultDataSyncRegistry.java +++ b/node/src/main/java/eu/cloudnetservice/node/cluster/sync/DefaultDataSyncRegistry.java @@ -17,7 +17,7 @@ package eu.cloudnetservice.node.cluster.sync; import com.google.common.primitives.Ints; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.concurrent.TaskUtil; import eu.cloudnetservice.common.language.I18n; import eu.cloudnetservice.driver.network.buffer.DataBuf; diff --git a/node/src/main/java/eu/cloudnetservice/node/command/defaults/DefaultCommandProvider.java b/node/src/main/java/eu/cloudnetservice/node/command/defaults/DefaultCommandProvider.java index 06113fb5bd..99a5a01803 100644 --- a/node/src/main/java/eu/cloudnetservice/node/command/defaults/DefaultCommandProvider.java +++ b/node/src/main/java/eu/cloudnetservice/node/command/defaults/DefaultCommandProvider.java @@ -20,7 +20,7 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Multimaps; import com.google.common.collect.SetMultimap; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.language.I18n; import eu.cloudnetservice.common.util.StringUtil; import eu.cloudnetservice.driver.command.CommandInfo; diff --git a/node/src/main/java/eu/cloudnetservice/node/config/JsonConfiguration.java b/node/src/main/java/eu/cloudnetservice/node/config/JsonConfiguration.java index 1360af396e..abf240e486 100644 --- a/node/src/main/java/eu/cloudnetservice/node/config/JsonConfiguration.java +++ b/node/src/main/java/eu/cloudnetservice/node/config/JsonConfiguration.java @@ -18,7 +18,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import dev.derklaro.aerogel.auto.Factory; +import dev.derklaro.aerogel.auto.annotation.Factory; import eu.cloudnetservice.common.io.FileUtil; import eu.cloudnetservice.common.util.StringUtil; import eu.cloudnetservice.driver.cluster.NetworkCluster; diff --git a/node/src/main/java/eu/cloudnetservice/node/console/JLine3Console.java b/node/src/main/java/eu/cloudnetservice/node/console/JLine3Console.java index 49cfe849c3..434cc8dbe5 100644 --- a/node/src/main/java/eu/cloudnetservice/node/console/JLine3Console.java +++ b/node/src/main/java/eu/cloudnetservice/node/console/JLine3Console.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.node.console; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.node.Node; import eu.cloudnetservice.node.console.animation.AbstractConsoleAnimation; import eu.cloudnetservice.node.console.handler.ConsoleInputHandler; diff --git a/node/src/main/java/eu/cloudnetservice/node/log/QueuedConsoleLogAppender.java b/node/src/main/java/eu/cloudnetservice/node/log/QueuedConsoleLogAppender.java index c37bb283c2..1a6a1a6ba1 100644 --- a/node/src/main/java/eu/cloudnetservice/node/log/QueuedConsoleLogAppender.java +++ b/node/src/main/java/eu/cloudnetservice/node/log/QueuedConsoleLogAppender.java @@ -18,7 +18,6 @@ import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.ConsoleAppender; -import dev.derklaro.aerogel.binding.BindingBuilder; import eu.cloudnetservice.driver.event.EventManager; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.node.event.log.LoggingEntryEvent; @@ -41,11 +40,15 @@ public final class QueuedConsoleLogAppender extends ConsoleAppender cachedQueuedLogEntries = new ConcurrentLinkedQueue<>(); public QueuedConsoleLogAppender() { - this.eventManager = InjectionLayer.boot().instance(EventManager.class); + var bootLayer = InjectionLayer.boot(); + this.eventManager = bootLayer.instance(EventManager.class); // we have to install the binding for the log appender ourselves because this class gets constructed by logback, // but we need the access in other classes - InjectionLayer.boot().install(BindingBuilder.create().bind(QueuedConsoleLogAppender.class).toInstance(this)); + bootLayer.install(bootLayer.injector() + .createBindingBuilder() + .bind(QueuedConsoleLogAppender.class) + .toInstance(this)); } public @NonNull Queue cachedLogEntries() { diff --git a/node/src/main/java/eu/cloudnetservice/node/module/util/ModuleUpdateUtil.java b/node/src/main/java/eu/cloudnetservice/node/module/util/ModuleUpdateUtil.java index 7c4f5b9d35..85212293d5 100644 --- a/node/src/main/java/eu/cloudnetservice/node/module/util/ModuleUpdateUtil.java +++ b/node/src/main/java/eu/cloudnetservice/node/module/util/ModuleUpdateUtil.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.node.module.util; -import dev.derklaro.aerogel.auto.Factory; +import dev.derklaro.aerogel.auto.annotation.Factory; import eu.cloudnetservice.common.io.FileUtil; import eu.cloudnetservice.driver.document.DocumentFactory; import eu.cloudnetservice.node.module.ModulesHolder; diff --git a/node/src/main/java/eu/cloudnetservice/node/provider/NodeClusterNodeProvider.java b/node/src/main/java/eu/cloudnetservice/node/provider/NodeClusterNodeProvider.java index 0a18633d85..ccf2b27f08 100644 --- a/node/src/main/java/eu/cloudnetservice/node/provider/NodeClusterNodeProvider.java +++ b/node/src/main/java/eu/cloudnetservice/node/provider/NodeClusterNodeProvider.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.node.provider; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.concurrent.TaskUtil; import eu.cloudnetservice.driver.channel.ChannelMessage; import eu.cloudnetservice.driver.cluster.NetworkClusterNode; diff --git a/node/src/main/java/eu/cloudnetservice/node/provider/NodeGroupConfigurationProvider.java b/node/src/main/java/eu/cloudnetservice/node/provider/NodeGroupConfigurationProvider.java index 08bc446934..678c710da8 100644 --- a/node/src/main/java/eu/cloudnetservice/node/provider/NodeGroupConfigurationProvider.java +++ b/node/src/main/java/eu/cloudnetservice/node/provider/NodeGroupConfigurationProvider.java @@ -16,8 +16,7 @@ package eu.cloudnetservice.node.provider; -import dev.derklaro.aerogel.PostConstruct; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.Named; import eu.cloudnetservice.common.io.FileUtil; import eu.cloudnetservice.driver.channel.ChannelMessage; @@ -96,7 +95,7 @@ public NodeGroupConfigurationProvider( this.upgrade(); } - @PostConstruct + @Inject private void loadGroups() { // load the groups if (Files.exists(GROUP_DIRECTORY_PATH)) { @@ -106,7 +105,7 @@ private void loadGroups() { } } - @PostConstruct + @Inject private void registerChannelMessageListener() { this.eventManager.registerListener(GroupChannelMessageListener.class); } diff --git a/node/src/main/java/eu/cloudnetservice/node/provider/NodeMessenger.java b/node/src/main/java/eu/cloudnetservice/node/provider/NodeMessenger.java index 4f1764bfcc..1892f625e9 100644 --- a/node/src/main/java/eu/cloudnetservice/node/provider/NodeMessenger.java +++ b/node/src/main/java/eu/cloudnetservice/node/provider/NodeMessenger.java @@ -17,7 +17,7 @@ package eu.cloudnetservice.node.provider; import com.google.common.collect.Iterables; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.concurrent.CountingTask; import eu.cloudnetservice.common.concurrent.TaskUtil; import eu.cloudnetservice.driver.channel.ChannelMessage; diff --git a/node/src/main/java/eu/cloudnetservice/node/provider/NodeServiceTaskProvider.java b/node/src/main/java/eu/cloudnetservice/node/provider/NodeServiceTaskProvider.java index 616151a5a2..b7976f280c 100644 --- a/node/src/main/java/eu/cloudnetservice/node/provider/NodeServiceTaskProvider.java +++ b/node/src/main/java/eu/cloudnetservice/node/provider/NodeServiceTaskProvider.java @@ -16,8 +16,8 @@ package eu.cloudnetservice.node.provider; -import dev.derklaro.aerogel.PostConstruct; -import dev.derklaro.aerogel.auto.Provides; + +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.Named; import eu.cloudnetservice.common.io.FileUtil; import eu.cloudnetservice.common.jvm.JavaVersion; @@ -107,7 +107,7 @@ private void loadTasks(@NonNull DefaultInstallation installation) { } } - @PostConstruct + @Inject private void registerTaskChannelListener() { this.eventManager.registerListener(TaskChannelMessageListener.class); } diff --git a/node/src/main/java/eu/cloudnetservice/node/service/defaults/DefaultCloudServiceManager.java b/node/src/main/java/eu/cloudnetservice/node/service/defaults/DefaultCloudServiceManager.java index 140bfda50d..70756deb3a 100644 --- a/node/src/main/java/eu/cloudnetservice/node/service/defaults/DefaultCloudServiceManager.java +++ b/node/src/main/java/eu/cloudnetservice/node/service/defaults/DefaultCloudServiceManager.java @@ -19,8 +19,8 @@ import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import com.google.common.collect.ComparisonChain; -import dev.derklaro.aerogel.PostConstruct; -import dev.derklaro.aerogel.auto.Provides; + +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.Named; import eu.cloudnetservice.common.tuple.Tuple2; import eu.cloudnetservice.driver.event.EventManager; diff --git a/node/src/main/java/eu/cloudnetservice/node/service/defaults/NodeCloudServiceFactory.java b/node/src/main/java/eu/cloudnetservice/node/service/defaults/NodeCloudServiceFactory.java index 108608c01a..05de134013 100644 --- a/node/src/main/java/eu/cloudnetservice/node/service/defaults/NodeCloudServiceFactory.java +++ b/node/src/main/java/eu/cloudnetservice/node/service/defaults/NodeCloudServiceFactory.java @@ -16,8 +16,8 @@ package eu.cloudnetservice.node.service.defaults; -import dev.derklaro.aerogel.PostConstruct; -import dev.derklaro.aerogel.auto.Provides; + +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.concurrent.TaskUtil; import eu.cloudnetservice.driver.channel.ChannelMessage; import eu.cloudnetservice.driver.channel.ChannelMessageTarget; diff --git a/node/src/main/java/eu/cloudnetservice/node/template/NodeTemplateStorageProvider.java b/node/src/main/java/eu/cloudnetservice/node/template/NodeTemplateStorageProvider.java index c6c6be39c0..06fe43b21e 100644 --- a/node/src/main/java/eu/cloudnetservice/node/template/NodeTemplateStorageProvider.java +++ b/node/src/main/java/eu/cloudnetservice/node/template/NodeTemplateStorageProvider.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.node.template; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.Named; import eu.cloudnetservice.driver.network.rpc.factory.RPCFactory; import eu.cloudnetservice.driver.network.rpc.handler.RPCHandlerRegistry; diff --git a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/Main.java b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/Main.java index 116035f234..c505d97ca1 100644 --- a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/Main.java +++ b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/Main.java @@ -17,9 +17,6 @@ package eu.cloudnetservice.wrapper; import com.google.common.collect.Lists; -import dev.derklaro.aerogel.Element; -import dev.derklaro.aerogel.binding.BindingBuilder; -import dev.derklaro.aerogel.util.Qualifiers; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.wrapper.transform.ClassTransformerRegistry; import io.leangen.geantyref.TypeFactory; @@ -47,27 +44,21 @@ public static void main(@NonNull String... args) throws Throwable { var rootLogger = LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); // initial bindings which we cannot (or it makes no sense to) construct - bootInjectLayer.install(BindingBuilder.create() - .bind(Element.forType(org.slf4j.Logger.class).requireAnnotation(Qualifiers.named("root"))) - .toInstance(rootLogger)); - bootInjectLayer.install(BindingBuilder.create() - .bind(Element.forType(Instant.class).requireAnnotation(Qualifiers.named("startInstant"))) - .toInstance(startInstant)); - bootInjectLayer.install(BindingBuilder.create() - .bind(Element.forType(ScheduledExecutorService.class).requireAnnotation(Qualifiers.named("taskScheduler"))) + var builder = bootInjectLayer.injector().createBindingBuilder(); + bootInjectLayer.install(builder.bind(org.slf4j.Logger.class).qualifiedWithName("root").toInstance(rootLogger)); + bootInjectLayer.install(builder.bind(Instant.class).qualifiedWithName("startInstant").toInstance(startInstant)); + bootInjectLayer.install(builder + .bind(ScheduledExecutorService.class) + .qualifiedWithName("taskScheduler") .toInstance(Executors.newScheduledThreadPool(2))); // bind the transformer registry here - we *could* provided it by constructing, but we don't // want to expose the Instrumentation instance - bootInjectLayer.install(BindingBuilder.create() - .bind(ClassTransformerRegistry.class) - .toInstance(Premain.transformerRegistry)); + bootInjectLayer.install(builder.bind(ClassTransformerRegistry.class).toInstance(Premain.transformerRegistry)); // console arguments var type = TypeFactory.parameterizedClass(List.class, String.class); - bootInjectLayer.install(BindingBuilder.create() - .bind(Element.forType(type).requireAnnotation(Qualifiers.named("consoleArgs"))) - .toInstance(Lists.newArrayList(args))); + bootInjectLayer.install(builder.bind(type).qualifiedWithName("consoleArgs").toInstance(Lists.newArrayList(args))); // boot the wrapper bootInjectLayer.instance(Wrapper.class); diff --git a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/configuration/DocumentWrapperConfiguration.java b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/configuration/DocumentWrapperConfiguration.java index 924ca7bbcb..0048e8de4b 100644 --- a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/configuration/DocumentWrapperConfiguration.java +++ b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/configuration/DocumentWrapperConfiguration.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.wrapper.configuration; -import dev.derklaro.aerogel.auto.Factory; +import dev.derklaro.aerogel.auto.annotation.Factory; import eu.cloudnetservice.driver.document.DocumentFactory; import eu.cloudnetservice.driver.network.HostAndPort; import eu.cloudnetservice.driver.network.ssl.SSLConfiguration; diff --git a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/holder/WrapperServiceInfoHolder.java b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/holder/WrapperServiceInfoHolder.java index bc059047fc..8d2e9743c2 100644 --- a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/holder/WrapperServiceInfoHolder.java +++ b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/holder/WrapperServiceInfoHolder.java @@ -17,7 +17,7 @@ package eu.cloudnetservice.wrapper.holder; import com.google.common.base.Preconditions; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.channel.ChannelMessage; import eu.cloudnetservice.driver.document.Document; import eu.cloudnetservice.driver.event.EventManager; diff --git a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/inject/BootFactories.java b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/inject/BootFactories.java index 615b360cf2..232e5f28a0 100644 --- a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/inject/BootFactories.java +++ b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/inject/BootFactories.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.wrapper.inject; -import dev.derklaro.aerogel.auto.Factory; +import dev.derklaro.aerogel.auto.annotation.Factory; import eu.cloudnetservice.driver.ComponentInfo; import eu.cloudnetservice.driver.DriverEnvironment; import eu.cloudnetservice.driver.network.NetworkClient; diff --git a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/inject/RPCFactories.java b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/inject/RPCFactories.java index 87b6518187..ef052a2bae 100644 --- a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/inject/RPCFactories.java +++ b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/inject/RPCFactories.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.wrapper.inject; -import dev.derklaro.aerogel.auto.Factory; +import dev.derklaro.aerogel.auto.annotation.Factory; import eu.cloudnetservice.driver.ComponentInfo; import eu.cloudnetservice.driver.database.DatabaseProvider; import eu.cloudnetservice.driver.network.NetworkClient; diff --git a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/provider/WrapperMessenger.java b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/provider/WrapperMessenger.java index 172b589d3e..36ad1dd15d 100644 --- a/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/provider/WrapperMessenger.java +++ b/wrapper-jvm/src/main/java/eu/cloudnetservice/wrapper/provider/WrapperMessenger.java @@ -16,7 +16,7 @@ package eu.cloudnetservice.wrapper.provider; -import dev.derklaro.aerogel.auto.Provides; +import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.channel.ChannelMessage; import eu.cloudnetservice.driver.network.NetworkClient; import eu.cloudnetservice.driver.network.def.PacketServerChannelMessage; From 4ebaca73e1224b813fa50f80b7fa875d307009b4 Mon Sep 17 00:00:00 2001 From: 0utplay Date: Sun, 22 Sep 2024 14:26:49 +0200 Subject: [PATCH 2/8] chore: update to aerogel v3 --- .../driver/inject/InjectUtil.java | 46 ++++--------- .../registry/DefaultServiceRegistry.java | 2 +- .../TestInjectionLayerConfigurator.java | 2 + .../processor/BindingClassGenerator.java | 37 +++++------ .../bukkit/BukkitPlatformPluginManager.java | 11 ++-- .../BungeeCordPlatformPluginManager.java | 12 ++-- .../fabric/FabricPlatformPluginManager.java | 11 ++-- .../LimboLoohpPlatformPluginManager.java | 13 ++-- .../MinestomPlatformPluginManager.java | 48 +++++++------- .../nukkit/NukkitPlatformPluginManager.java | 21 +++--- .../sponge/SpongePlatformPluginManager.java | 66 ++++++++++--------- .../VelocityPlatformPluginManager.java | 34 +++++----- .../WaterDogPlatformPluginManager.java | 16 ++--- .../runtime/util/BindingUtil.java | 37 ----------- .../bridge/node/NodeBridgeManagement.java | 2 +- .../bridge/node/player/NodePlayerManager.java | 5 +- .../docker/DockerizedServicesModule.java | 9 ++- .../signs/node/CloudNetSignsModule.java | 8 ++- .../defaults/DefaultNodeServerProvider.java | 8 +-- .../defaults/DefaultCloudServiceManager.java | 3 +- .../defaults/NodeCloudServiceFactory.java | 2 +- .../node/command/CommandProviderTest.java | 6 +- 22 files changed, 168 insertions(+), 231 deletions(-) delete mode 100644 ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/util/BindingUtil.java diff --git a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectUtil.java b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectUtil.java index ef2c663152..ced820c97b 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectUtil.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectUtil.java @@ -17,11 +17,8 @@ package eu.cloudnetservice.driver.inject; import com.google.common.base.Preconditions; -import dev.derklaro.aerogel.Injector; -import dev.derklaro.aerogel.binding.UninstalledBinding; import dev.derklaro.aerogel.binding.key.BindingKey; import java.lang.reflect.Parameter; -import java.lang.reflect.Type; import java.util.Arrays; import lombok.NonNull; import org.jetbrains.annotations.ApiStatus; @@ -79,67 +76,50 @@ private InjectUtil() { /** * Finds all instances that are requested by the given element array in the given injection layer. * - * @param layer the layer to retrieve the needed instances from. - * @param elements the elements to get the instances of. + * @param layer the layer to retrieve the needed instances from. + * @param keys the keys to get the instances of. * @return the instances represented by the given elements, in order. * @throws NullPointerException if the given injection layer or elements array is null. */ public static @NonNull Object[] findAllInstances( @NonNull InjectionLayer layer, - @NonNull BindingKey[] elements + @NonNull BindingKey[] keys ) { - return findAllInstances(layer, elements, 0); + return findAllInstances(layer, keys, 0); } /** * Finds all instances that are requested by the given element array in the given injection layer. * - * @param layer the layer to retrieve the needed instances from. - * @param elements the elements to get the instances of. - * @param offset the offset to start writing the elements from in the resulting array, must be bigger than zero. + * @param layer the layer to retrieve the needed instances from. + * @param keys the keys to get the instances of. + * @param offset the offset to start writing the elements from in the resulting array, must be bigger than zero. * @return the instances represented by the given elements, in order. * @throws NullPointerException if the given injection layer or elements array is null. * @throws IllegalArgumentException if the given offset is smaller than zero. */ public static @NonNull Object[] findAllInstances( @NonNull InjectionLayer layer, - @NonNull BindingKey[] elements, + @NonNull BindingKey[] keys, int offset ) { Preconditions.checkArgument(offset >= 0, "offset must be >= 0"); // return an empty array if the offset is 0 and no elements are present - if (elements.length == 0 && offset == 0) { + if (keys.length == 0 && offset == 0) { return EMPTY_INSTANCE_ARRAY; } // return an array of the expected size if an offset is present but no elements are present - if (elements.length == 0) { + if (keys.length == 0) { return new Object[offset]; } // find the instances - var instances = new Object[elements.length + offset]; - for (int i = 0; i < elements.length; i++) { - instances[i + offset] = layer.instance(elements[i]); + var instances = new Object[keys.length + offset]; + for (int i = 0; i < keys.length; i++) { + instances[i + offset] = layer.instance(keys[i]); } return instances; } - - /** - * Creates a fixed binding constructor without setting any required name or annotation. It is only based on the type. - * - * @param value the value that is bound to the type. - * @param types the types to bind the given value to. - * @return the new binding constructor. - * @throws NullPointerException if the given type or value is null. - * @throws IndexOutOfBoundsException if the given type array is empty. - */ - public static @NonNull UninstalledBinding createFixedBinding( - @NonNull Injector injector, - @NonNull Object value, - @NonNull Type type - ) { - return injector.createBindingBuilder().bind(type).toInstance(value); - } } diff --git a/driver/src/main/java/eu/cloudnetservice/driver/registry/DefaultServiceRegistry.java b/driver/src/main/java/eu/cloudnetservice/driver/registry/DefaultServiceRegistry.java index 76bc3a4fdb..5ba31796cf 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/registry/DefaultServiceRegistry.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/registry/DefaultServiceRegistry.java @@ -59,7 +59,7 @@ public DefaultServiceRegistry(@NonNull InjectionLayer injectionLayer) { result = this.provider(serviceClass, serviceName); } - return scopedBuilder.toInstance(result); + return scopedBuilder.toProvider(() -> result); }); injectionLayer.install(dynamicBinding); } diff --git a/driver/src/test/java/eu/cloudnetservice/driver/TestInjectionLayerConfigurator.java b/driver/src/test/java/eu/cloudnetservice/driver/TestInjectionLayerConfigurator.java index c2410a9e3a..9ad1c14941 100644 --- a/driver/src/test/java/eu/cloudnetservice/driver/TestInjectionLayerConfigurator.java +++ b/driver/src/test/java/eu/cloudnetservice/driver/TestInjectionLayerConfigurator.java @@ -26,6 +26,8 @@ private TestInjectionLayerConfigurator() { public static void loadAutoconfigureBindings() { var bootInjectionLayer = InjectionLayer.boot(); + // the tests re-use the same jvm and we need to clear the binding between runs + bootInjectionLayer.injector().bindingRegistry().unregister(_ -> true); bootInjectionLayer.installAutoConfigureBindings(TestInjectionLayerConfigurator.class.getClassLoader(), "driver"); } } diff --git a/ext/platform-inject-support/processor/src/main/java/eu/cloudnetservice/ext/platforminject/processor/BindingClassGenerator.java b/ext/platform-inject-support/processor/src/main/java/eu/cloudnetservice/ext/platforminject/processor/BindingClassGenerator.java index 2087d037ea..f18ee69a64 100644 --- a/ext/platform-inject-support/processor/src/main/java/eu/cloudnetservice/ext/platforminject/processor/BindingClassGenerator.java +++ b/ext/platform-inject-support/processor/src/main/java/eu/cloudnetservice/ext/platforminject/processor/BindingClassGenerator.java @@ -25,7 +25,6 @@ import eu.cloudnetservice.ext.platforminject.api.inject.BindingsInstaller; import eu.cloudnetservice.ext.platforminject.processor.util.GeantyrefUtil; import eu.cloudnetservice.ext.platforminject.processor.util.TypeUtil; -import java.lang.reflect.Type; import java.util.Collection; import java.util.Set; import java.util.stream.Stream; @@ -39,8 +38,6 @@ final class BindingClassGenerator { INJECTION_LAYER, TypeUtil.UNBOUNDED_WILDCARD); - private static final ClassName BINDING_BUILDER = ClassName.get("dev.derklaro.aerogel.binding", "BindingBuilder"); - public static @NonNull TypeSpec buildBindingClass( @NonNull String className, @NonNull Collection bindingData @@ -51,12 +48,12 @@ final class BindingClassGenerator { .addModifiers(Modifier.PUBLIC) .addParameter(GENERIC_INJECTION_LAYER, "l"); + applyBindings.addCode(CodeBlock.of("var builder = l.injector().createBindingBuilder();")); + // apply each binding for (var binding : bindingData) { // build the layer install code block for the raw types - var rawTypesGetter = binding.providingElements().stream() - .map(type -> CodeBlock.of("$T.class", type)) - .collect(CodeBlock.joining(", ")); + var rawTypesGetter = binding.providingElements().stream().map(type -> CodeBlock.of("$T.class", type)); // build the layer install block for the generic types, if any var genericElements = binding.providedGenericElements(); @@ -82,20 +79,18 @@ final class BindingClassGenerator { // only add the generic constructor return Stream.of(genericTypeConstructor); - }) - .collect(CodeBlock.joining(", ")); - - // concat the raw and generic bindings - var fullTypesGetter = CodeBlock.of("{$L, $L}", rawTypesGetter, genericTypesGetter); - - // install all bindings to the layer - var layerInstallGenericBlock = buildLayerInstallBlock(fullTypesGetter, binding.boundElement()); - applyBindings.addCode(layerInstallGenericBlock); - } else { - // there are only the raw bindings - var layerInstallRawBlock = buildLayerInstallBlock(rawTypesGetter, binding.boundElement()); - applyBindings.addCode(layerInstallRawBlock); + }); + + genericTypesGetter.forEach(block -> { + // install all bindings to the layer + var layerInstallGenericBlock = buildLayerInstallBlock(block, binding.boundElement()); + applyBindings.addCode(layerInstallGenericBlock); + }); } + rawTypesGetter.forEach(block -> { + var layerInstallRawBlock = buildLayerInstallBlock(block, binding.boundElement()); + applyBindings.addCode(layerInstallRawBlock); + }); } // build the class @@ -111,9 +106,7 @@ final class BindingClassGenerator { @NonNull ClassName boundElement ) { // build the block which actually adds the binding to the layer - var constructorBuild = CodeBlock.of("$T.create().bindAllFully(new $T[]$L).toConstructing($T.class)", - BINDING_BUILDER, - Type.class, + var constructorBuild = CodeBlock.of("builder.bind($L).toConstructingClass($T.class)", typeGetterBlock, boundElement); return CodeBlock.of("l.install($L);", constructorBuild); diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bukkit/BukkitPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bukkit/BukkitPlatformPluginManager.java index 3002e4e542..fdf04f1959 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bukkit/BukkitPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bukkit/BukkitPlatformPluginManager.java @@ -16,8 +16,6 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.bukkit; -import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; - import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.ext.platforminject.api.defaults.BasePlatformPluginManager; @@ -40,9 +38,10 @@ public BukkitPlatformPluginManager() { @Override protected @NonNull InjectionLayer createInjectionLayer(@NonNull JavaPlugin platformData) { - return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { + return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", targetedBuilder -> { // install bindings for the platform - var builder = injector.createBindingBuilder(); + var layer = BASE_INJECTION_LAYER; + var builder = layer.injector().createBindingBuilder(); layer.install(builder.bind(Server.class).toInstance(platformData.getServer())); layer.install(builder.bind(BukkitScheduler.class).toInstance(platformData.getServer().getScheduler())); layer.install(builder.bind(PluginManager.class).toInstance(platformData.getServer().getPluginManager())); @@ -50,7 +49,9 @@ public BukkitPlatformPluginManager() { layer.install(builder.bind(ScoreboardManager.class).toInstance(platformData.getServer().getScoreboardManager())); // install the bindings which are specific to the plugin - injector.installSpecified(fixedBindingWithBound(platformData, Plugin.class, PluginBase.class, JavaPlugin.class)); + targetedBuilder.installBinding(builder.bind(Plugin.class).toInstance(platformData)); + targetedBuilder.installBinding(builder.bind(PluginBase.class).toInstance(platformData)); + targetedBuilder.installBinding(builder.bind(JavaPlugin.class).toInstance(platformData)); }); } } diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bungeecord/BungeeCordPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bungeecord/BungeeCordPlatformPluginManager.java index 03da0d5d34..face9297c8 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bungeecord/BungeeCordPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/bungeecord/BungeeCordPlatformPluginManager.java @@ -16,9 +16,7 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.bungeecord; -import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; - -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.ext.platforminject.api.defaults.BasePlatformPluginManager; import eu.cloudnetservice.ext.platforminject.api.util.FunctionalUtil; @@ -36,16 +34,18 @@ public BungeeCordPlatformPluginManager() { } @Override - protected @NonNull InjectionLayer createInjectionLayer(@NonNull Plugin platformData) { - return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { + protected @NonNull InjectionLayer createInjectionLayer(@NonNull Plugin platformData) { + return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", targetedBuilder -> { // install bindings for the platform + var layer = BASE_INJECTION_LAYER; + var bindingBuilder = layer.injector().createBindingBuilder(); layer.install(bindingBuilder.bind(ProxyServer.class).toInstance(platformData.getProxy())); layer.install(bindingBuilder.bind(ProxyConfig.class).toInstance(platformData.getProxy().getConfig())); layer.install(bindingBuilder.bind(TaskScheduler.class).toInstance(platformData.getProxy().getScheduler())); layer.install(bindingBuilder.bind(PluginManager.class).toInstance(platformData.getProxy().getPluginManager())); // install the bindings which are specific to the plugin - injector.installSpecified(fixedBindingWithBound(platformData, Plugin.class)); + targetedBuilder.installBinding(bindingBuilder.bind(Plugin.class).toInstance(platformData)); }); } } diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/fabric/FabricPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/fabric/FabricPlatformPluginManager.java index e2074d1e35..37f34b7900 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/fabric/FabricPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/fabric/FabricPlatformPluginManager.java @@ -16,9 +16,7 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.fabric; -import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; - -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.ext.platforminject.api.defaults.BasePlatformPluginManager; import eu.cloudnetservice.ext.platforminject.api.util.FunctionalUtil; @@ -31,10 +29,13 @@ public FabricPlatformPluginManager() { } @Override - protected @NonNull InjectionLayer createInjectionLayer(@NonNull Object platformData) { + protected @NonNull InjectionLayer createInjectionLayer(@NonNull Object platformData) { return InjectionLayer.specifiedChild( BASE_INJECTION_LAYER, "plugin", - (layer, injector) -> injector.installSpecified(fixedBindingWithBound(platformData, platformData.getClass()))); + targetedBuilder -> { + var bindingBuilder = BASE_INJECTION_LAYER.injector().createBindingBuilder(); + targetedBuilder.installBinding(bindingBuilder.bind(Object.class).toInstance(platformData)); + }); } } diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/limboloohp/LimboLoohpPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/limboloohp/LimboLoohpPlatformPluginManager.java index 75faec18b0..beeec0a6b3 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/limboloohp/LimboLoohpPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/limboloohp/LimboLoohpPlatformPluginManager.java @@ -16,15 +16,12 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.limboloohp; -import static eu.cloudnetservice.driver.inject.InjectUtil.createFixedBinding; -import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; - import com.loohp.limbo.Limbo; import com.loohp.limbo.events.EventsManager; import com.loohp.limbo.plugins.LimboPlugin; import com.loohp.limbo.plugins.PluginManager; import com.loohp.limbo.scheduler.LimboScheduler; -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.ext.platforminject.api.defaults.BasePlatformPluginManager; import eu.cloudnetservice.ext.platforminject.api.util.FunctionalUtil; @@ -37,16 +34,18 @@ public LimboLoohpPlatformPluginManager() { } @Override - protected @NonNull InjectionLayer createInjectionLayer(@NonNull LimboPlugin platformData) { - return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { + protected @NonNull InjectionLayer createInjectionLayer(@NonNull LimboPlugin platformData) { + return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", targetedBuilder -> { // install bindings for the platform + var layer = BASE_INJECTION_LAYER; + var bindingBuilder = layer.injector().createBindingBuilder(); layer.install(bindingBuilder.bind(Limbo.class).toInstance(platformData.getServer())); layer.install(bindingBuilder.bind(PluginManager.class).toInstance(platformData.getServer().getPluginManager())); layer.install(bindingBuilder.bind(EventsManager.class).toInstance(platformData.getServer().getEventsManager())); layer.install(bindingBuilder.bind(LimboScheduler.class).toInstance(platformData.getServer().getScheduler())); // install the bindings which are specific to the plugin - injector.installSpecified(fixedBindingWithBound(platformData, LimboPlugin.class)); + targetedBuilder.installBinding(bindingBuilder.bind(LimboPlugin.class).toInstance(platformData)); }); } } diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/minestom/MinestomPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/minestom/MinestomPlatformPluginManager.java index fc3ff17920..639e1098aa 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/minestom/MinestomPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/minestom/MinestomPlatformPluginManager.java @@ -16,9 +16,7 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.minestom; -import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; - -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.ext.platforminject.api.defaults.BasePlatformPluginManager; import eu.cloudnetservice.ext.platforminject.api.util.FunctionalUtil; @@ -52,30 +50,32 @@ public MinestomPlatformPluginManager() { } @Override - protected @NonNull InjectionLayer createInjectionLayer(@NonNull Extension platformData) { - return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { + protected @NonNull InjectionLayer createInjectionLayer(@NonNull Extension platformData) { + return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", targetedBuilder -> { // install bindings for the platform - layer.install(bindingBuilder.bind(ServerProcess.class).toInstance(MinecraftServer.process())); - layer.install(bindingBuilder.bind(ComponentLogger.class).toInstance(platformData.getLogger())); - layer.install(bindingBuilder.bind(TagManager.class).toInstance(MinecraftServer.getTagManager())); - layer.install(bindingBuilder.bind(TeamManager.class).toInstance(MinecraftServer.getTeamManager())); - layer.install(bindingBuilder.bind(BlockManager.class).toInstance(MinecraftServer.getBlockManager())); - layer.install(bindingBuilder.bind(RecipeManager.class).toInstance(MinecraftServer.getRecipeManager())); - layer.install(bindingBuilder.bind(BossBarManager.class).toInstance(MinecraftServer.getBossBarManager())); - layer.install(bindingBuilder.bind(CommandManager.class).toInstance(MinecraftServer.getCommandManager())); - layer.install(bindingBuilder.bind(PacketProcessor.class).toInstance(MinecraftServer.getPacketProcessor())); - layer.install(bindingBuilder.bind(InstanceManager.class).toInstance(MinecraftServer.getInstanceManager())); - layer.install(bindingBuilder.bind(ExceptionManager.class).toInstance(MinecraftServer.getExceptionManager())); - layer.install(bindingBuilder.bind(BenchmarkManager.class).toInstance(MinecraftServer.getBenchmarkManager())); - layer.install(bindingBuilder.bind(SchedulerManager.class).toInstance(MinecraftServer.getSchedulerManager())); - layer.install(bindingBuilder.bind(ConnectionManager.class).toInstance(MinecraftServer.getConnectionManager())); - layer.install(bindingBuilder.bind(ExtensionManager.class).toInstance(ExtensionBootstrap.getExtensionManager())); - layer.install(bindingBuilder.bind(GlobalEventHandler.class).toInstance(MinecraftServer.getGlobalEventHandler())); - layer.install(bindingBuilder.bind(AdvancementManager.class).toInstance(MinecraftServer.getAdvancementManager())); - layer.install(bindingBuilder.bind(PacketListenerManager.class).toInstance(MinecraftServer.getPacketListenerManager())); + var layer = BASE_INJECTION_LAYER; + var builder = layer.injector().createBindingBuilder(); + layer.install(builder.bind(ServerProcess.class).toInstance(MinecraftServer.process())); + layer.install(builder.bind(ComponentLogger.class).toInstance(platformData.getLogger())); + layer.install(builder.bind(TagManager.class).toInstance(MinecraftServer.getTagManager())); + layer.install(builder.bind(TeamManager.class).toInstance(MinecraftServer.getTeamManager())); + layer.install(builder.bind(BlockManager.class).toInstance(MinecraftServer.getBlockManager())); + layer.install(builder.bind(RecipeManager.class).toInstance(MinecraftServer.getRecipeManager())); + layer.install(builder.bind(BossBarManager.class).toInstance(MinecraftServer.getBossBarManager())); + layer.install(builder.bind(CommandManager.class).toInstance(MinecraftServer.getCommandManager())); + layer.install(builder.bind(PacketProcessor.class).toInstance(MinecraftServer.getPacketProcessor())); + layer.install(builder.bind(InstanceManager.class).toInstance(MinecraftServer.getInstanceManager())); + layer.install(builder.bind(ExceptionManager.class).toInstance(MinecraftServer.getExceptionManager())); + layer.install(builder.bind(BenchmarkManager.class).toInstance(MinecraftServer.getBenchmarkManager())); + layer.install(builder.bind(SchedulerManager.class).toInstance(MinecraftServer.getSchedulerManager())); + layer.install(builder.bind(ConnectionManager.class).toInstance(MinecraftServer.getConnectionManager())); + layer.install(builder.bind(ExtensionManager.class).toInstance(ExtensionBootstrap.getExtensionManager())); + layer.install(builder.bind(GlobalEventHandler.class).toInstance(MinecraftServer.getGlobalEventHandler())); + layer.install(builder.bind(AdvancementManager.class).toInstance(MinecraftServer.getAdvancementManager())); + layer.install(builder.bind(PacketListenerManager.class).toInstance(MinecraftServer.getPacketListenerManager())); // install the bindings which are specific to the plugin - injector.installSpecified(fixedBindingWithBound(platformData, Extension.class)); + targetedBuilder.installBinding(builder.bind(Extension.class).toInstance(platformData)); }); } } diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/nukkit/NukkitPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/nukkit/NukkitPlatformPluginManager.java index a7025afeb6..1a4fcf0b1b 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/nukkit/NukkitPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/nukkit/NukkitPlatformPluginManager.java @@ -16,8 +16,6 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.nukkit; -import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; - import cn.nukkit.Server; import cn.nukkit.command.CommandMap; import cn.nukkit.inventory.CraftingManager; @@ -44,18 +42,19 @@ public NukkitPlatformPluginManager() { return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", targetedBuilder -> { // install bindings for the platform var layer = BASE_INJECTION_LAYER; + var server = platformData.getServer(); var builder = layer.injector().createBindingBuilder(); - layer.install(builder.bind(Server.class).toInstance(platformData.getServer())); - layer.install(builder.bind(CommandMap.class).toInstance(platformData.getServer().getCommandMap())); - layer.install(builder.bind(ServerScheduler.class).toInstance(platformData.getServer().getScheduler())); - layer.install(builder.bind(PluginManager.class).toInstance(platformData.getServer().getPluginManager())); - layer.install(builder.bind(ServiceManager.class).toInstance(platformData.getServer().getServiceManager())); - layer.install(builder.bind(CraftingManager.class).toInstance(platformData.getServer().getCraftingManager())); - layer.install(builder.bind(ResourcePackManager.class) - .toInstance(platformData.getServer().getResourcePackManager())); + layer.install(builder.bind(Server.class).toInstance(server)); + layer.install(builder.bind(CommandMap.class).toInstance(server.getCommandMap())); + layer.install(builder.bind(ServerScheduler.class).toInstance(server.getScheduler())); + layer.install(builder.bind(PluginManager.class).toInstance(server.getPluginManager())); + layer.install(builder.bind(ServiceManager.class).toInstance(server.getServiceManager())); + layer.install(builder.bind(CraftingManager.class).toInstance(server.getCraftingManager())); + layer.install(builder.bind(ResourcePackManager.class).toInstance(server.getResourcePackManager())); // install the bindings which are specific to the plugin - targetedBuilder.installBinding(fixedBindingWithBound(platformData, PluginBase.class, Plugin.class)); + targetedBuilder.installBinding(builder.bind(Plugin.class).toInstance(platformData)); + targetedBuilder.installBinding(builder.bind(PluginBase.class).toInstance(platformData)); }); } } diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/sponge/SpongePlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/sponge/SpongePlatformPluginManager.java index 8592ac59e6..243c36d60d 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/sponge/SpongePlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/sponge/SpongePlatformPluginManager.java @@ -16,13 +16,7 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.sponge; -import static eu.cloudnetservice.driver.inject.InjectUtil.createFixedBinding; -import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; - -import dev.derklaro.aerogel.Element; -import dev.derklaro.aerogel.SpecifiedInjector; -import dev.derklaro.aerogel.binding.BindingBuilder; -import dev.derklaro.aerogel.util.Qualifiers; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.ext.platforminject.api.defaults.BasePlatformPluginManager; import eu.cloudnetservice.ext.platforminject.api.mapping.Container; @@ -62,17 +56,20 @@ public SpongePlatformPluginManager() { } @Override - protected @NonNull InjectionLayer createInjectionLayer( + protected @NonNull InjectionLayer createInjectionLayer( @NonNull Container platformData ) { - return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { + return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", targetedBuilder -> { // scheduler bindings - var schedulerElement = Element.forType(Scheduler.class); - layer.install(BindingBuilder.create() - .bind(schedulerElement.requireAnnotation(Qualifiers.named("sync"))) + var layer = BASE_INJECTION_LAYER; + var bindingBuilder = layer.injector().createBindingBuilder(); + layer.install(bindingBuilder + .bind(Scheduler.class) + .qualifiedWithName("sync") .toInstance(Sponge.server().scheduler())); - layer.install(BindingBuilder.create() - .bind(schedulerElement.requireAnnotation(Qualifiers.named("async"))) + layer.install(bindingBuilder + .bind(Scheduler.class) + .qualifiedWithName("async") .toInstance(Sponge.game().asyncScheduler())); // game bindings @@ -89,26 +86,31 @@ public SpongePlatformPluginManager() { layer.install(bindingBuilder.bind(ServiceProvider.GameScoped.class).toInstance(Sponge.game().serviceProvider())); // server bindings - layer.install(bindingBuilder.bind(MapStorage.class).toInstance(Sponge.server().mapStorage())); - layer.install(bindingBuilder.bind(UserManager.class).toInstance(Sponge.server().userManager())); - layer.install(bindingBuilder.bind(WorldManager.class).toInstance(Sponge.server().worldManager())); - layer.install(bindingBuilder.bind(RegistryHolder.class).toInstance(Sponge.server(), Server.class)); - layer.install(bindingBuilder.bind(RecipeManager.class).toInstance(Sponge.server().recipeManager())); - layer.install(bindingBuilder.bind(TeleportHelper.class).toInstance(Sponge.server().teleportHelper())); - layer.install(bindingBuilder.bind(CommandManager.class).toInstance(Sponge.server().commandManager())); - layer.install(bindingBuilder.bind(PackRepository.class).toInstance(Sponge.server().packRepository())); - layer.install(bindingBuilder.bind(ResourceManager.class).toInstance(Sponge.server().resourceManager())); - layer.install(bindingBuilder.bind(CauseStackManager.class).toInstance(Sponge.server().causeStackManager())); - layer.install(createFixedBinding( - Sponge.server().gameProfileManager(), - GameProfileManager.class, GameProfileProvider.class)); - layer.install(createFixedBinding( - Sponge.server().serviceProvider(), - ServiceProvider.ServerScoped.class, ServiceProvider.class)); + var server = Sponge.server(); + layer.install(bindingBuilder.bind(Server.class).toInstance(server)); + layer.install(bindingBuilder.bind(RegistryHolder.class).toInstance(server)); + layer.install(bindingBuilder.bind(MapStorage.class).toInstance(server.mapStorage())); + layer.install(bindingBuilder.bind(UserManager.class).toInstance(server.userManager())); + layer.install(bindingBuilder.bind(WorldManager.class).toInstance(server.worldManager())); + layer.install(bindingBuilder.bind(RecipeManager.class).toInstance(server.recipeManager())); + layer.install(bindingBuilder.bind(TeleportHelper.class).toInstance(server.teleportHelper())); + layer.install(bindingBuilder.bind(CommandManager.class).toInstance(server.commandManager())); + layer.install(bindingBuilder.bind(PackRepository.class).toInstance(server.packRepository())); + layer.install(bindingBuilder.bind(ResourceManager.class).toInstance(server.resourceManager())); + layer.install(bindingBuilder.bind(CauseStackManager.class).toInstance(server.causeStackManager())); + layer.install(bindingBuilder.bind(GameProfileManager.class).toInstance(server.gameProfileManager())); + layer.install(bindingBuilder.bind(GameProfileProvider.class).toInstance(server.gameProfileManager())); + layer.install(bindingBuilder.bind(ServiceProvider.class).toInstance(server.serviceProvider())); + layer.install(bindingBuilder.bind(ServiceProvider.ServerScoped.class).toInstance(server.serviceProvider())); // install the bindings which are specific to the plugin - injector.installSpecified(fixedBindingWithBound(platformData.pluginInstance())); - injector.installSpecified(createFixedBinding(platformData.container(), PluginContainer.class)); + targetedBuilder.installBinding(bindingBuilder + .bind(Object.class) + .qualifiedWithName("plugin") + .toInstance(platformData.pluginInstance())); + targetedBuilder.installBinding(bindingBuilder + .bind(PluginContainer.class) + .toInstance(platformData.container())); }); } } diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java index 753cea8dc2..2b9d410e71 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java @@ -16,8 +16,6 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.velocity; -import static eu.cloudnetservice.driver.inject.InjectUtil.createFixedBinding; - import com.velocitypowered.api.command.CommandManager; import com.velocitypowered.api.event.EventManager; import com.velocitypowered.api.plugin.PluginContainer; @@ -25,10 +23,7 @@ import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.messages.ChannelRegistrar; import com.velocitypowered.api.scheduler.Scheduler; -import dev.derklaro.aerogel.Element; -import dev.derklaro.aerogel.SpecifiedInjector; -import dev.derklaro.aerogel.binding.BindingBuilder; -import dev.derklaro.aerogel.util.Qualifiers; +import dev.derklaro.aerogel.Injector; import eu.cloudnetservice.driver.inject.InjectionLayer; import eu.cloudnetservice.ext.platforminject.api.defaults.BasePlatformPluginManager; import eu.cloudnetservice.ext.platforminject.api.mapping.PlatformedContainer; @@ -42,23 +37,26 @@ public VelocityPlatformPluginManager() { } @Override - protected @NonNull InjectionLayer createInjectionLayer( + protected @NonNull InjectionLayer createInjectionLayer( @NonNull PlatformedContainer platformData ) { - return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { + return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", targetedBuilder -> { // install bindings for the platform - layer.install(bindingBuilder.bind(ProxyServer.class).toInstance(platformData.platformInstance())); - layer.install(bindingBuilder.bind(Scheduler.class).toInstance(platformData.platformInstance().getScheduler())); - layer.install(bindingBuilder.bind(EventManager.class).toInstance(platformData.platformInstance().getEventManager())); - layer.install(bindingBuilder.bind(PluginManager.class).toInstance(platformData.platformInstance().getPluginManager())); - layer.install(bindingBuilder.bind(CommandManager.class).toInstance(platformData.platformInstance().getCommandManager())); - layer.install(bindingBuilder.bind(ChannelRegistrar.class).toInstance(platformData.platformInstance().getChannelRegistrar())); + var layer = BASE_INJECTION_LAYER; + var bindingBuilder = layer.injector().createBindingBuilder(); + var proxyServer = platformData.platformInstance(); + layer.install(bindingBuilder.bind(ProxyServer.class).toInstance(proxyServer)); + layer.install(bindingBuilder.bind(Scheduler.class).toInstance(proxyServer.getScheduler())); + layer.install(bindingBuilder.bind(EventManager.class).toInstance(proxyServer.getEventManager())); + layer.install(bindingBuilder.bind(PluginManager.class).toInstance(proxyServer.getPluginManager())); + layer.install(bindingBuilder.bind(CommandManager.class).toInstance(proxyServer.getCommandManager())); + layer.install(bindingBuilder.bind(ChannelRegistrar.class).toInstance(proxyServer.getChannelRegistrar())); // install the bindings which are specific to the plugin - injector.installSpecified(createFixedBinding(platformData.container(), PluginContainer.class)); - injector.installSpecified(BindingBuilder.create() - .bind(Element.forType(Object.class).requireAnnotation(Qualifiers.named("plugin"))) - .toInstance(platformData.pluginInstance())); + targetedBuilder.installBinding(bindingBuilder.bind(PluginContainer.class).toInstance(platformData.container())); + targetedBuilder.installBinding(bindingBuilder.bind(Object.class) + .qualifiedWithName("plugin") + .toInstance(proxyServer)); }); } } diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/waterdog/WaterDogPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/waterdog/WaterDogPlatformPluginManager.java index b23fc9c0c4..9fd1e5f5fc 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/waterdog/WaterDogPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/waterdog/WaterDogPlatformPluginManager.java @@ -16,10 +16,7 @@ package eu.cloudnetservice.ext.platforminject.runtime.platform.waterdog; -import static eu.cloudnetservice.driver.inject.InjectUtil.createFixedBinding; -import static eu.cloudnetservice.ext.platforminject.runtime.util.BindingUtil.fixedBindingWithBound; - -import dev.derklaro.aerogel.SpecifiedInjector; +import dev.derklaro.aerogel.Injector; import dev.waterdog.waterdogpe.ProxyServer; import dev.waterdog.waterdogpe.command.CommandMap; import dev.waterdog.waterdogpe.event.EventManager; @@ -44,9 +41,11 @@ public WaterDogPlatformPluginManager() { } @Override - protected @NonNull InjectionLayer createInjectionLayer(@NonNull Plugin platformData) { - return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", (layer, injector) -> { + protected @NonNull InjectionLayer createInjectionLayer(@NonNull Plugin platformData) { + return InjectionLayer.specifiedChild(BASE_INJECTION_LAYER, "plugin", targetedBuilder -> { // install bindings for the platform + var layer = BASE_INJECTION_LAYER; + var bindingBuilder = layer.injector().createBindingBuilder(); layer.install(bindingBuilder.bind(ProxyServer.class).toInstance(platformData.getProxy())); layer.install(bindingBuilder.bind(MainLogger.class).toInstance(platformData.getProxy().getLogger())); layer.install(bindingBuilder.bind(CommandMap.class).toInstance(platformData.getProxy().getCommandMap())); @@ -57,10 +56,11 @@ public WaterDogPlatformPluginManager() { layer.install(bindingBuilder.bind(ServerInfoMap.class).toInstance(platformData.getProxy().getServerInfoMap())); layer.install(bindingBuilder.bind(PluginManager.class).toInstance(platformData.getProxy().getPluginManager())); layer.install(bindingBuilder.bind(WaterdogScheduler.class).toInstance(platformData.getProxy().getScheduler())); - layer.install(bindingBuilder.bind(ConfigurationManager.class).toInstance(platformData.getProxy().getConfigurationManager())); + layer.install(bindingBuilder.bind(ConfigurationManager.class) + .toInstance(platformData.getProxy().getConfigurationManager())); // install the bindings which are specific to the plugin - injector.installSpecified(fixedBindingWithBound(platformData, Plugin.class)); + targetedBuilder.installBinding(bindingBuilder.bind(Plugin.class).toInstance(platformData)); }); } } diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/util/BindingUtil.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/util/BindingUtil.java deleted file mode 100644 index c603e6e972..0000000000 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/util/BindingUtil.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2019-2024 CloudNetService team & contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package eu.cloudnetservice.ext.platforminject.runtime.util; - -import dev.derklaro.aerogel.binding.BindingBuilder; -import dev.derklaro.aerogel.binding.BindingConstructor; -import lombok.NonNull; - -public final class BindingUtil { - - private BindingUtil() { - throw new UnsupportedOperationException(); - } - - public static @NonNull BindingConstructor fixedBindingWithBound(@NonNull Object object, @NonNull Class... other) { - // check if there are other types supplied - if (other.length == 0) { - return BindingBuilder.create().toInstance(object); - } else { - return BindingBuilder.create().bindFully(object.getClass()).bindAllFully(other).toInstance(object); - } - } -} diff --git a/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/NodeBridgeManagement.java b/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/NodeBridgeManagement.java index 9efd1ff180..0609033e54 100644 --- a/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/NodeBridgeManagement.java +++ b/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/NodeBridgeManagement.java @@ -80,7 +80,7 @@ public NodeBridgeManagement( rpcHandlerRegistry.registerHandler(rpcHandler); } - @PostConstruct + @Inject private void registerListener() { this.eventManager.registerListener(NodeBridgeChannelMessageListener.class); this.eventManager.registerListener(NodeSetupListener.class); diff --git a/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/player/NodePlayerManager.java b/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/player/NodePlayerManager.java index 127ba38cbc..5c04dd8f0c 100644 --- a/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/player/NodePlayerManager.java +++ b/modules/bridge/src/main/java/eu/cloudnetservice/modules/bridge/node/player/NodePlayerManager.java @@ -20,7 +20,6 @@ import com.github.benmanes.caffeine.cache.LoadingCache; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.Striped; - import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.driver.channel.ChannelMessage; import eu.cloudnetservice.driver.document.Document; @@ -126,12 +125,12 @@ public NodePlayerManager( .build()); } - @PostConstruct + @Inject private void registerPlayerCommand() { this.commandProvider.register(PlayersCommand.class); } - @PostConstruct + @Inject private void registerListeners() { this.eventManager.registerListener(BridgeLocalProxyPlayerDisconnectListener.class); this.eventManager.registerListener(NodePlayerChannelMessageListener.class); diff --git a/modules/dockerized-services/src/main/java/eu/cloudnetservice/modules/docker/DockerizedServicesModule.java b/modules/dockerized-services/src/main/java/eu/cloudnetservice/modules/docker/DockerizedServicesModule.java index 698f4910fc..68ca3c3737 100644 --- a/modules/dockerized-services/src/main/java/eu/cloudnetservice/modules/docker/DockerizedServicesModule.java +++ b/modules/dockerized-services/src/main/java/eu/cloudnetservice/modules/docker/DockerizedServicesModule.java @@ -20,7 +20,7 @@ import com.github.dockerjava.core.DefaultDockerClientConfig; import com.github.dockerjava.core.DockerClientImpl; import com.github.dockerjava.httpclient5.ApacheDockerHttpClient; -import dev.derklaro.aerogel.Element; +import dev.derklaro.aerogel.binding.key.BindingKey; import eu.cloudnetservice.driver.document.Document; import eu.cloudnetservice.driver.document.DocumentFactory; import eu.cloudnetservice.driver.inject.InjectionLayer; @@ -86,10 +86,9 @@ public void registerServiceFactory( var dockerClient = DockerClientImpl.getInstance(clientConfig, dockerHttpClient); // construct the factory instance & register it in the service manager - var factory = moduleInjectionLayer.instance(DockerizedLocalCloudServiceFactory.class, map -> { - map - builder.override(Element.forType(DockerClient.class), dockerClient); - map.override(Element.forType(DockerConfiguration.class), this.configuration); + var factory = moduleInjectionLayer.instance(DockerizedLocalCloudServiceFactory.class, overrides -> { + overrides.put(BindingKey.of(DockerClient.class), () -> dockerClient); + overrides.put(BindingKey.of(DockerConfiguration.class), () -> this.configuration); }); serviceManager.addCloudServiceFactory(this.configuration.factoryName(), factory); } diff --git a/modules/signs/src/main/java/eu/cloudnetservice/modules/signs/node/CloudNetSignsModule.java b/modules/signs/src/main/java/eu/cloudnetservice/modules/signs/node/CloudNetSignsModule.java index 90794be5d2..f09ecd5b84 100644 --- a/modules/signs/src/main/java/eu/cloudnetservice/modules/signs/node/CloudNetSignsModule.java +++ b/modules/signs/src/main/java/eu/cloudnetservice/modules/signs/node/CloudNetSignsModule.java @@ -16,6 +16,7 @@ package eu.cloudnetservice.modules.signs.node; +import dev.derklaro.aerogel.binding.key.BindingKey; import eu.cloudnetservice.driver.database.Database; import eu.cloudnetservice.driver.database.DatabaseProvider; import eu.cloudnetservice.driver.event.EventManager; @@ -81,9 +82,10 @@ public void handleInitialization( ) { var management = layer.instance( NodeSignManagement.class, - builder -> builder - .override(SignsConfiguration.class, this.configuration) - .override(Database.class, this.database)); + overrides -> { + overrides.put(BindingKey.of(SignsConfiguration.class), () -> this.configuration); + overrides.put(BindingKey.of(Database.class), () -> this.database); + }); management.registerToServiceRegistry(serviceRegistry); commandProvider.register(SignCommand.class); diff --git a/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultNodeServerProvider.java b/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultNodeServerProvider.java index 937279dce4..a26fc5c7e1 100644 --- a/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultNodeServerProvider.java +++ b/node/src/main/java/eu/cloudnetservice/node/cluster/defaults/DefaultNodeServerProvider.java @@ -17,6 +17,7 @@ package eu.cloudnetservice.node.cluster.defaults; import dev.derklaro.aerogel.auto.annotation.Provides; +import dev.derklaro.aerogel.binding.key.BindingKey; import eu.cloudnetservice.driver.channel.ChannelMessage; import eu.cloudnetservice.driver.cluster.NetworkCluster; import eu.cloudnetservice.driver.cluster.NetworkClusterNode; @@ -146,13 +147,12 @@ public void registerNodes(@NonNull NetworkCluster cluster) { public void registerNode(@NonNull NetworkClusterNode clusterNode) { var server = InjectionLayer.boot().instance( RemoteNodeServer.class, - builder -> { + overrides -> { var cloudServiceFactoryAllocatorType = TypeFactory.parameterizedClass( RPCImplementationBuilder.InstanceAllocator.class, CloudServiceFactory.class); - builder - .override(NetworkClusterNode.class, clusterNode) - .override(cloudServiceFactoryAllocatorType, this.cloudServiceFactoryAllocator); + overrides.put(BindingKey.of(NetworkClusterNode.class), () -> clusterNode); + overrides.put(BindingKey.of(cloudServiceFactoryAllocatorType), () -> this.cloudServiceFactoryAllocator); }); this.nodeServers.add(server); } diff --git a/node/src/main/java/eu/cloudnetservice/node/service/defaults/DefaultCloudServiceManager.java b/node/src/main/java/eu/cloudnetservice/node/service/defaults/DefaultCloudServiceManager.java index 70756deb3a..22543035ed 100644 --- a/node/src/main/java/eu/cloudnetservice/node/service/defaults/DefaultCloudServiceManager.java +++ b/node/src/main/java/eu/cloudnetservice/node/service/defaults/DefaultCloudServiceManager.java @@ -19,7 +19,6 @@ import com.github.benmanes.caffeine.cache.Cache; import com.github.benmanes.caffeine.cache.Caffeine; import com.google.common.collect.ComparisonChain; - import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.Named; import eu.cloudnetservice.common.tuple.Tuple2; @@ -181,7 +180,7 @@ public DefaultCloudServiceManager( }, TickLoop.TPS); } - @PostConstruct + @Inject private void registerDefaultServiceFactory() { this.addCloudServiceFactory("jvm", JVMLocalCloudServiceFactory.class); } diff --git a/node/src/main/java/eu/cloudnetservice/node/service/defaults/NodeCloudServiceFactory.java b/node/src/main/java/eu/cloudnetservice/node/service/defaults/NodeCloudServiceFactory.java index 05de134013..70b4bcedec 100644 --- a/node/src/main/java/eu/cloudnetservice/node/service/defaults/NodeCloudServiceFactory.java +++ b/node/src/main/java/eu/cloudnetservice/node/service/defaults/NodeCloudServiceFactory.java @@ -85,7 +85,7 @@ public NodeCloudServiceFactory( handlerRegistry.registerHandler(rpcHandler); } - @PostConstruct + @Inject private void registerServiceChannelListener() { this.eventManager.registerListener(ServiceChannelMessageListener.class); } diff --git a/node/src/test/java/eu/cloudnetservice/node/command/CommandProviderTest.java b/node/src/test/java/eu/cloudnetservice/node/command/CommandProviderTest.java index f14899ac5e..e678a3f696 100644 --- a/node/src/test/java/eu/cloudnetservice/node/command/CommandProviderTest.java +++ b/node/src/test/java/eu/cloudnetservice/node/command/CommandProviderTest.java @@ -16,7 +16,6 @@ package eu.cloudnetservice.node.command; -import dev.derklaro.aerogel.binding.BindingBuilder; import eu.cloudnetservice.common.concurrent.TaskUtil; import eu.cloudnetservice.driver.event.DefaultEventManager; import eu.cloudnetservice.driver.event.EventManager; @@ -46,8 +45,9 @@ public final class CommandProviderTest { public static void initCommandProvider() { // install the required bindings to construct the command provider var layer = InjectionLayer.boot(); - layer.install(BindingBuilder.create().bind(EventManager.class).toConstructing(DefaultEventManager.class)); - layer.install(BindingBuilder.create().bind(CommandProvider.class).toConstructing(DefaultCommandProvider.class)); + var builder = layer.injector().createBindingBuilder(); + layer.install(builder.bind(EventManager.class).toConstructingClass(DefaultEventManager.class)); + layer.install(builder.bind(CommandProvider.class).toConstructingClass(DefaultCommandProvider.class)); // get the command provider instance commandProvider = layer.instance(CommandProvider.class); From 361eca734fdf4891ecc8b4c1c3027f85b9bafa0a Mon Sep 17 00:00:00 2001 From: 0utplay Date: Mon, 23 Sep 2024 15:49:33 +0200 Subject: [PATCH 3/8] chore: correct code generation for new aerogel update --- .../processor/BindingClassGenerator.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/ext/platform-inject-support/processor/src/main/java/eu/cloudnetservice/ext/platforminject/processor/BindingClassGenerator.java b/ext/platform-inject-support/processor/src/main/java/eu/cloudnetservice/ext/platforminject/processor/BindingClassGenerator.java index f18ee69a64..50bfd43a38 100644 --- a/ext/platform-inject-support/processor/src/main/java/eu/cloudnetservice/ext/platforminject/processor/BindingClassGenerator.java +++ b/ext/platform-inject-support/processor/src/main/java/eu/cloudnetservice/ext/platforminject/processor/BindingClassGenerator.java @@ -26,7 +26,9 @@ import eu.cloudnetservice.ext.platforminject.processor.util.GeantyrefUtil; import eu.cloudnetservice.ext.platforminject.processor.util.TypeUtil; import java.util.Collection; +import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import java.util.stream.Stream; import javax.lang.model.element.Modifier; import lombok.NonNull; @@ -53,7 +55,9 @@ final class BindingClassGenerator { // apply each binding for (var binding : bindingData) { // build the layer install code block for the raw types - var rawTypesGetter = binding.providingElements().stream().map(type -> CodeBlock.of("$T.class", type)); + var rawTypesGetter = binding.providingElements().stream() + .map(type -> CodeBlock.of("$T.class", type)) + .collect(Collectors.toList()); // build the layer install block for the generic types, if any var genericElements = binding.providedGenericElements(); @@ -79,18 +83,14 @@ final class BindingClassGenerator { // only add the generic constructor return Stream.of(genericTypeConstructor); - }); + }).toList(); - genericTypesGetter.forEach(block -> { - // install all bindings to the layer - var layerInstallGenericBlock = buildLayerInstallBlock(block, binding.boundElement()); - applyBindings.addCode(layerInstallGenericBlock); - }); + + rawTypesGetter.addAll(genericTypesGetter); } - rawTypesGetter.forEach(block -> { - var layerInstallRawBlock = buildLayerInstallBlock(block, binding.boundElement()); - applyBindings.addCode(layerInstallRawBlock); - }); + + var layerInstallRawBlock = buildLayerInstallBlock(rawTypesGetter, binding.boundElement()); + applyBindings.addCode(layerInstallRawBlock); } // build the class @@ -102,14 +102,19 @@ final class BindingClassGenerator { } private static @NonNull CodeBlock buildLayerInstallBlock( - @NonNull CodeBlock typeGetterBlock, + @NonNull List bindingBlocks, @NonNull ClassName boundElement ) { // build the block which actually adds the binding to the layer - var constructorBuild = CodeBlock.of("builder.bind($L).toConstructingClass($T.class)", - typeGetterBlock, - boundElement); - return CodeBlock.of("l.install($L);", constructorBuild); + var constructorBuild = CodeBlock.builder().add("builder.bind($L)", bindingBlocks.getFirst()); + if (bindingBlocks.size() > 1) { + for (int i = 1; i < bindingBlocks.size(); i++) { + constructorBuild.add(".andBind($L)", bindingBlocks.get(i)); + } + } + + constructorBuild.add(".toConstructingClass($T.class)", boundElement); + return CodeBlock.of("l.install($L);", constructorBuild.build()); } public record ParsedBindingData( From d0e5ab55218d7dec7db5267f6edbc83c8d3fa2bd Mon Sep 17 00:00:00 2001 From: 0utplay Date: Tue, 24 Sep 2024 20:26:44 +0200 Subject: [PATCH 4/8] chore: resolve first issues --- build.gradle.kts | 1 + .../driver/inject/DefaultInjectionLayer.java | 14 +++++--------- .../rpc/defaults/object/DefaultObjectMapper.java | 2 -- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 7891abf95e..ec874294a6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -118,6 +118,7 @@ subprojects { if (project.path != ":launcher:java8" && project.path != ":launcher:patcher") { options.compilerArgs.add("--enable-preview") options.compilerArgs.add("-Xlint:-deprecation,-unchecked,-preview") + options.compilerArgs.add("-proc:full") } } diff --git a/driver/src/main/java/eu/cloudnetservice/driver/inject/DefaultInjectionLayer.java b/driver/src/main/java/eu/cloudnetservice/driver/inject/DefaultInjectionLayer.java index 59920fccc1..70d5ef8e97 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/inject/DefaultInjectionLayer.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/inject/DefaultInjectionLayer.java @@ -24,13 +24,12 @@ import dev.derklaro.aerogel.internal.context.scope.InjectionContextProvider; import jakarta.inject.Provider; import java.io.IOException; +import java.io.UncheckedIOException; import java.util.HashMap; import java.util.Map; import java.util.function.Consumer; import lombok.NonNull; import org.jetbrains.annotations.UnknownNullability; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * The default implementation for of an injector layer. @@ -47,8 +46,6 @@ record DefaultInjectionLayer( @NonNull String name ) implements InjectionLayer { - private static final Logger LOGGER = LoggerFactory.getLogger(DefaultInjectionLayer.class); - /** * {@inheritDoc} */ @@ -128,7 +125,9 @@ public void installAutoConfigureBindings(@NonNull ClassLoader loader, @NonNull S this.autoModule.deserializeBindings(stream, loader).installBindings(this.injector); } } catch (IOException exception) { - LOGGER.warn("Unable to auto configure bindings for component {} with file {}", component, fileName, exception); + throw new UncheckedIOException( + String.format("Unable to auto configure bindings for component %s with file %s", component, fileName), + exception); } } @@ -155,10 +154,7 @@ public void installAutoConfigureBindings(@NonNull ClassLoader loader, @NonNull S @Override public void close() { // remove the bindings from the parent injector if needed - // TODO aerogel - /*if (this.injector instanceof Target specifiedInjector) { - specifiedInjector.removeConstructedBindings(); - }*/ + this.injector.close(); // remove this injector from the registry InjectionLayerProvider.REGISTRY.unregisterLayer(this); diff --git a/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/DefaultObjectMapper.java b/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/DefaultObjectMapper.java index 8968db1f08..53376f0ae0 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/DefaultObjectMapper.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/network/rpc/defaults/object/DefaultObjectMapper.java @@ -21,7 +21,6 @@ import com.github.benmanes.caffeine.cache.Scheduler; import com.google.common.collect.ImmutableMap; import com.google.common.reflect.TypeToken; -import dev.derklaro.aerogel.auto.annotation.Provides; import eu.cloudnetservice.common.tuple.Tuple2; import eu.cloudnetservice.driver.document.Document; import eu.cloudnetservice.driver.network.buffer.DataBuf; @@ -111,7 +110,6 @@ * @since 4.0 */ @Singleton -@Provides(ObjectMapper.class) public class DefaultObjectMapper implements ObjectMapper { public static final ObjectMapper DEFAULT_MAPPER; From 5f6f985a794f4130396a75291378d31439b4c06a Mon Sep 17 00:00:00 2001 From: 0utplay Date: Tue, 24 Sep 2024 22:09:58 +0200 Subject: [PATCH 5/8] chore: combine bindings for same types --- .../driver/inject/InjectionLayerProvider.java | 15 +++++++++------ .../main/java/eu/cloudnetservice/node/Node.java | 3 +-- .../command/defaults/AerogelInjectionService.java | 11 ++++++++++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayerProvider.java b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayerProvider.java index e9be575cc7..7379309281 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayerProvider.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayerProvider.java @@ -176,9 +176,10 @@ private InjectionLayerProvider() { return configuredLayer(name, layer -> { var injector = layer.injector(); var bindingBuilder = injector.createBindingBuilder(); - injector.installBinding(bindingBuilder.bind(RAW_ELEMENT).toInstance(layer)); - injector.installBinding(bindingBuilder.bind(GENERIC_ELEMENT).toInstance(layer)); - injector.installBinding(bindingBuilder.bind(INJECTOR_ELEMENT).toInstance(layer)); + injector.installBinding(bindingBuilder.bind(RAW_ELEMENT) + .andBind(GENERIC_ELEMENT) + .andBind(INJECTOR_ELEMENT) + .toInstance(layer)); }); } @@ -307,8 +308,10 @@ private static void registerBindings( @NonNull Consumer> register ) { var bindingBuilder = injector.createBindingBuilder(); - register.accept(bindingBuilder.bind(RAW_ELEMENT).qualifiedWithName(name).toProvider(layer)); - register.accept(bindingBuilder.bind(GENERIC_ELEMENT).qualifiedWithName(name).toProvider(layer)); - register.accept(bindingBuilder.bind(INJECTOR_ELEMENT).qualifiedWithName(name).toProvider(layer)); + register.accept(bindingBuilder.bind(RAW_ELEMENT) + .andBind(GENERIC_ELEMENT) + .andBind(INJECTOR_ELEMENT) + .qualifiedWithName(name) + .toProvider(layer)); } } diff --git a/node/src/main/java/eu/cloudnetservice/node/Node.java b/node/src/main/java/eu/cloudnetservice/node/Node.java index ad939d8be1..1d5f8113ee 100644 --- a/node/src/main/java/eu/cloudnetservice/node/Node.java +++ b/node/src/main/java/eu/cloudnetservice/node/Node.java @@ -225,8 +225,7 @@ private void initializeDatabaseProvider( // bind the provider for dependency injection var builder = bootLayer.injector().createBindingBuilder(); - bootLayer.install(builder.bind(DatabaseProvider.class).toInstance(provider)); - bootLayer.install(builder.bind(NodeDatabaseProvider.class).toInstance(provider)); + bootLayer.install(builder.bind(DatabaseProvider.class).andBind(NodeDatabaseProvider.class).toInstance(provider)); // register the rpc handler for the database provider var dbProviderHandler = rpcFactory.newRPCHandlerBuilder(DatabaseProvider.class).targetInstance(provider).build(); diff --git a/node/src/main/java/eu/cloudnetservice/node/command/defaults/AerogelInjectionService.java b/node/src/main/java/eu/cloudnetservice/node/command/defaults/AerogelInjectionService.java index 8ebcb3d806..f982606bc0 100644 --- a/node/src/main/java/eu/cloudnetservice/node/command/defaults/AerogelInjectionService.java +++ b/node/src/main/java/eu/cloudnetservice/node/command/defaults/AerogelInjectionService.java @@ -23,10 +23,14 @@ import org.incendo.cloud.injection.InjectionRequest; import org.incendo.cloud.injection.InjectionService; import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Singleton final class AerogelInjectionService implements InjectionService { + private static final Logger LOGGER = LoggerFactory.getLogger(AerogelInjectionService.class); + @Override public @Nullable Object handle(@NonNull InjectionRequest request) { // get the associated data from the input values @@ -34,6 +38,11 @@ final class AerogelInjectionService implements InjectionService { var injectionLayer = InjectionLayer.findLayerOf(targetClass); // get the instance of the given class from the injection layer - return injectionLayer.instance(targetClass); + try { + return injectionLayer.instance(targetClass); + } catch (Exception exception) { + LOGGER.trace("Unable to construct type {} using aerogel injection service", request.injectedClass(), exception); + return null; + } } } From 2a52e70399cb57af9ddbf16661b9b9cc909aa660 Mon Sep 17 00:00:00 2001 From: 0utplay Date: Tue, 24 Sep 2024 23:30:52 +0200 Subject: [PATCH 6/8] fix: bind correct instance on velocity plugins --- .../platform/velocity/VelocityPlatformPluginManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java index 2b9d410e71..a147ab2bfc 100644 --- a/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java +++ b/ext/platform-inject-support/runtime/src/main/java/eu/cloudnetservice/ext/platforminject/runtime/platform/velocity/VelocityPlatformPluginManager.java @@ -56,7 +56,7 @@ public VelocityPlatformPluginManager() { targetedBuilder.installBinding(bindingBuilder.bind(PluginContainer.class).toInstance(platformData.container())); targetedBuilder.installBinding(bindingBuilder.bind(Object.class) .qualifiedWithName("plugin") - .toInstance(proxyServer)); + .toInstance(platformData.pluginInstance())); }); } } From e5180ceed640ef233c0554fadb1f969a652346bc Mon Sep 17 00:00:00 2001 From: 0utplay Date: Mon, 7 Oct 2024 22:01:51 +0200 Subject: [PATCH 7/8] chore: docs --- .../driver/inject/InjectionLayer.java | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayer.java b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayer.java index 4bd9881ee2..0103483e32 100644 --- a/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayer.java +++ b/driver/src/main/java/eu/cloudnetservice/driver/inject/InjectionLayer.java @@ -24,6 +24,7 @@ import dev.derklaro.aerogel.binding.key.BindingKey; import eu.cloudnetservice.common.Named; import jakarta.inject.Provider; +import java.io.UncheckedIOException; import java.util.Map; import java.util.function.Consumer; import lombok.NonNull; @@ -189,19 +190,17 @@ public sealed interface InjectionLayer * @param the type of the class modeled by the given class object. * @return the constructed instance of the class type, may be null. * @throws NullPointerException if the given type is null. - * @throws AerogelException if no binding is present and no runtime binding can be created. */ @UnknownNullability T instance(@NonNull Class type); /** - * Convince method to create or get the instance of the given element. + * Convince method to create or get the instance of the given binding key. * - * @param bindingKey the element of the type to get. - * @param the type of the return value modeled by the given element. + * @param bindingKey the binding key for the instance to resolve. + * @param the type of the return value modeled by the given binding key. * @return the constructed instance of the class type, may be null. - * @throws NullPointerException if the given element is null. - * @throws AerogelException if no binding is present and no runtime binding can be created. + * @throws NullPointerException if the given binding key is null. */ @UnknownNullability T instance(@NonNull BindingKey bindingKey); @@ -210,24 +209,31 @@ public sealed interface InjectionLayer * Convince method to create or get the instance of the given type, while allowing to specifically influence the * injection context. * - * @param type the type of the element to get. - * @param overrides the builder to configure the injection context for the operation. - * @param the type of the return value modeled by the given element. + * @param type the type of the element to get. + * @param overrides the overrides for the binding key and the value to use as override. + * @param the type of the return value modeled by the given element. * @return the constructed instance of the class type, may be null. * @throws NullPointerException if the given type or builder is null. - * @throws AerogelException if no binding is present and no runtime binding can be created. */ @UnknownNullability T instance(@NonNull Class type, @NonNull Consumer, Provider>> overrides); /** - * Installs the binding constructed by the given bindings constructor to this injection layer. + * Installs the uninstalled binding into the underlying injector. * - * @param binding the constructor to install. - * @throws NullPointerException if the given constructor is null or the constructor constructs a null value. + * @param binding the binding to install. + * @throws NullPointerException if the given binding is null. */ void install(@NonNull UninstalledBinding binding); + /** + * Installs a dynamic binding into the underlying injector. The dynamic binding can be used to provide bindings based + * on the presence of annotations and other matching criteria. Dynamic bindings have a lower priority than + * {@link UninstalledBinding}. + * + * @param binding the dynamic binding to install. + * @throws NullPointerException if the given binding is null. + */ void install(@NonNull DynamicBinding binding); /** @@ -239,7 +245,7 @@ public sealed interface InjectionLayer * @param loader the loader in which the file resource is located. * @param component the name of the component to load the autoconfiguration bindings of. * @throws NullPointerException if the given class loader or component name is null. - * @throws AerogelException if an I/O exception occurs while loading or closing the data stream. + * @throws UncheckedIOException if an I/O error occurs while loading the auto config bindings. */ void installAutoConfigureBindings(@NonNull ClassLoader loader, @NonNull String component); From 0df0c9d1857d8396428879fb4634f0f129440a30 Mon Sep 17 00:00:00 2001 From: 0utplay Date: Thu, 24 Oct 2024 20:06:31 +0200 Subject: [PATCH 8/8] chore: fuck dis --- .../eu/cloudnetservice/modules/mysql/MySQLDatabaseProvider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/database-mysql/src/main/java/eu/cloudnetservice/modules/mysql/MySQLDatabaseProvider.java b/modules/database-mysql/src/main/java/eu/cloudnetservice/modules/mysql/MySQLDatabaseProvider.java index f6b1c087f5..e4e0d761ed 100644 --- a/modules/database-mysql/src/main/java/eu/cloudnetservice/modules/mysql/MySQLDatabaseProvider.java +++ b/modules/database-mysql/src/main/java/eu/cloudnetservice/modules/mysql/MySQLDatabaseProvider.java @@ -132,7 +132,6 @@ public int executeUpdate(@NonNull String query, @NonNull Object... objects) { try (var con = this.connection(); var statement = con.prepareStatement(query)) { // write all parameters for (var i = 0; i < objects.length; i++) { - statement.setObject(); statement.setString(i + 1, Objects.toString(objects[i])); }