From abd96baeee22ad95ff2007819ef64dc831ab48d4 Mon Sep 17 00:00:00 2001 From: Jeff Trent Date: Thu, 13 Apr 2023 14:59:05 -0400 Subject: [PATCH] All Pico services should default to a lesser than DEFAULT_WEIGHT (#6590) * fix for issue# 6583 --- .../config/processor/ConfigBeanBuilderCreator.java | 2 +- .../builder/config/spi/HelidonConfigResolver.java | 2 +- .../builder/processor/tools/BuilderTypeTools.java | 2 +- .../tools/DefaultBuilderCreatorProvider.java | 2 +- .../java/io/helidon/pico/api/ServiceInfoBasics.java | 11 ++++++----- .../DefaultConfigBeanBuilderValidatorProvider.java | 5 +++-- .../runtime/DefaultConfigBeanRegistryProvider.java | 5 +++-- .../runtime/DefaultConfigResolverProvider.java | 5 +++-- .../runtime/DefaultStringValueParserProvider.java | 5 +++-- .../pico/runtime/DefaultPicoServicesProvider.java | 5 +++-- .../testsubjects/HelloPicoImpl$$picoActivator.java | 3 ++- .../testsubjects/PicoWorldImpl$$picoActivator.java | 7 ++++--- .../helidon/pico/tools/DefaultActivatorCreator.java | 3 ++- .../helidon/pico/tools/DefaultApplicationCreator.java | 4 ++-- .../pico/tools/DefaultExternalModuleCreator.java | 4 ++-- .../helidon/pico/tools/DefaultInterceptorCreator.java | 3 ++- 16 files changed, 39 insertions(+), 29 deletions(-) diff --git a/builder/builder-config-processor/src/main/java/io/helidon/builder/config/processor/ConfigBeanBuilderCreator.java b/builder/builder-config-processor/src/main/java/io/helidon/builder/config/processor/ConfigBeanBuilderCreator.java index f23a0b4200c..b18c365b5d5 100644 --- a/builder/builder-config-processor/src/main/java/io/helidon/builder/config/processor/ConfigBeanBuilderCreator.java +++ b/builder/builder-config-processor/src/main/java/io/helidon/builder/config/processor/ConfigBeanBuilderCreator.java @@ -68,7 +68,7 @@ * @see GeneratedConfigBean * @see GeneratedConfigBeanBuilder */ -@Weight(Weighted.DEFAULT_WEIGHT) +@Weight(Weighted.DEFAULT_WEIGHT - 2) // allow all other creators to take precedence over us... public class ConfigBeanBuilderCreator extends DefaultBuilderCreatorProvider { static final String PICO_CONTRACT_TYPENAME = "io.helidon.pico.api.Contract"; static final String PICO_EXTERNAL_CONTRACT_TYPENAME = "io.helidon.pico.api.ExternalContracts"; diff --git a/builder/builder-config/src/main/java/io/helidon/builder/config/spi/HelidonConfigResolver.java b/builder/builder-config/src/main/java/io/helidon/builder/config/spi/HelidonConfigResolver.java index d8fdcd43e98..7f5f107bd65 100644 --- a/builder/builder-config/src/main/java/io/helidon/builder/config/spi/HelidonConfigResolver.java +++ b/builder/builder-config/src/main/java/io/helidon/builder/config/spi/HelidonConfigResolver.java @@ -40,7 +40,7 @@ * not "full" Helidon config. */ @Singleton -@Weight(Weighted.DEFAULT_WEIGHT - 1) // allow all other creators to take precedence over us... +@Weight(Weighted.DEFAULT_WEIGHT - 2) // allow all other creators to take precedence over us... @SuppressWarnings({"unchecked", "rawtypes"}) public class HelidonConfigResolver implements ConfigResolver, ConfigResolverProvider { diff --git a/builder/processor-tools/src/main/java/io/helidon/builder/processor/tools/BuilderTypeTools.java b/builder/processor-tools/src/main/java/io/helidon/builder/processor/tools/BuilderTypeTools.java index d31ea75cfc7..a8be3d92622 100644 --- a/builder/processor-tools/src/main/java/io/helidon/builder/processor/tools/BuilderTypeTools.java +++ b/builder/processor-tools/src/main/java/io/helidon/builder/processor/tools/BuilderTypeTools.java @@ -62,7 +62,7 @@ * The default implementation for {@link io.helidon.builder.processor.spi.TypeInfoCreatorProvider}. This also contains an abundance of * other useful methods used for annotation processing. */ -@Weight(Weighted.DEFAULT_WEIGHT - 1) +@Weight(Weighted.DEFAULT_WEIGHT - 2) // allow all other creators to take precedence over us... public class BuilderTypeTools implements TypeInfoCreatorProvider { /** * Default constructor. Service loaded. diff --git a/builder/processor-tools/src/main/java/io/helidon/builder/processor/tools/DefaultBuilderCreatorProvider.java b/builder/processor-tools/src/main/java/io/helidon/builder/processor/tools/DefaultBuilderCreatorProvider.java index b91b279e5da..a3437a167e4 100644 --- a/builder/processor-tools/src/main/java/io/helidon/builder/processor/tools/DefaultBuilderCreatorProvider.java +++ b/builder/processor-tools/src/main/java/io/helidon/builder/processor/tools/DefaultBuilderCreatorProvider.java @@ -57,7 +57,7 @@ /** * Default implementation for {@link io.helidon.builder.processor.spi.BuilderCreatorProvider}. */ -@Weight(Weighted.DEFAULT_WEIGHT - 1) // allow all other creators to take precedence over us... +@Weight(Weighted.DEFAULT_WEIGHT - 2) // allow all other creators to take precedence over us... public class DefaultBuilderCreatorProvider implements BuilderCreatorProvider { static final boolean DEFAULT_INCLUDE_META_ATTRIBUTES = true; static final boolean DEFAULT_REQUIRE_LIBRARY_DEPENDENCIES = true; diff --git a/pico/api/src/main/java/io/helidon/pico/api/ServiceInfoBasics.java b/pico/api/src/main/java/io/helidon/pico/api/ServiceInfoBasics.java index 2a9c073be8b..d2cbd9fe57c 100644 --- a/pico/api/src/main/java/io/helidon/pico/api/ServiceInfoBasics.java +++ b/pico/api/src/main/java/io/helidon/pico/api/ServiceInfoBasics.java @@ -32,10 +32,11 @@ public interface ServiceInfoBasics { /** - * Default weight for any weighted component (whether it implements this interface - * or uses {@link io.helidon.common.Weight} annotation). + * Default weight for any internal Pico service component. It is defined to be + * {@link Weighted#DEFAULT_WEIGHT} {@code - 1} in order to allow any other service implementation to + * naturally have a higher weight (since it will use the {@code DEFAULT_WEIGHT} unless explicitly overridden. */ - double DEFAULT_WEIGHT = Weighted.DEFAULT_WEIGHT; + double DEFAULT_PICO_WEIGHT = Weighted.DEFAULT_WEIGHT - 1; /** * The managed service implementation {@link Class}. @@ -96,13 +97,13 @@ default int realizedRunLevel() { Optional declaredWeight(); /** - * The realized weight will use the default weight if no weight was specified directly. + * The realized weight will use {@link Weighted#DEFAULT_WEIGHT} if no weight was specified directly. * * @return the realized weight * @see #declaredWeight() */ default double realizedWeight() { - return declaredWeight().orElse(DEFAULT_WEIGHT); + return declaredWeight().orElse(Weighted.DEFAULT_WEIGHT); } } diff --git a/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigBeanBuilderValidatorProvider.java b/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigBeanBuilderValidatorProvider.java index b0cbe1d14b4..c822a21b956 100644 --- a/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigBeanBuilderValidatorProvider.java +++ b/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigBeanBuilderValidatorProvider.java @@ -20,12 +20,13 @@ import io.helidon.builder.config.spi.ConfigBeanBuilderValidatorProvider; import io.helidon.common.LazyValue; import io.helidon.common.Weight; -import io.helidon.common.Weighted; + +import static io.helidon.pico.api.ServiceInfoBasics.DEFAULT_PICO_WEIGHT; /** * Service-loaded provider for {@link io.helidon.builder.config.spi.ConfigResolverProvider}. */ -@Weight(Weighted.DEFAULT_WEIGHT) +@Weight(DEFAULT_PICO_WEIGHT) public class DefaultConfigBeanBuilderValidatorProvider implements ConfigBeanBuilderValidatorProvider { static final LazyValue> INSTANCE = LazyValue.create(DefaultConfigBuilderValidator::new); diff --git a/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigBeanRegistryProvider.java b/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigBeanRegistryProvider.java index a1e22aa98cd..49c39504c9a 100644 --- a/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigBeanRegistryProvider.java +++ b/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigBeanRegistryProvider.java @@ -20,12 +20,13 @@ import io.helidon.builder.config.spi.HelidonConfigBeanRegistry; import io.helidon.common.LazyValue; import io.helidon.common.Weight; -import io.helidon.common.Weighted; + +import static io.helidon.pico.api.ServiceInfoBasics.DEFAULT_PICO_WEIGHT; /** * Service-loaded provider for {@link ConfigBeanRegistry}. */ -@Weight(Weighted.DEFAULT_WEIGHT) +@Weight(DEFAULT_PICO_WEIGHT) public class DefaultConfigBeanRegistryProvider implements ConfigBeanRegistryProvider { static final LazyValue INSTANCE = LazyValue.create(DefaultPicoConfigBeanRegistry::new); diff --git a/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigResolverProvider.java b/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigResolverProvider.java index eec5346d5f1..1142c170da9 100644 --- a/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigResolverProvider.java +++ b/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultConfigResolverProvider.java @@ -20,12 +20,13 @@ import io.helidon.builder.config.spi.ConfigResolverProvider; import io.helidon.common.LazyValue; import io.helidon.common.Weight; -import io.helidon.common.Weighted; + +import static io.helidon.pico.api.ServiceInfoBasics.DEFAULT_PICO_WEIGHT; /** * Service-loaded provider for {@link ConfigResolverProvider}. */ -@Weight(Weighted.DEFAULT_WEIGHT) +@Weight(DEFAULT_PICO_WEIGHT) public class DefaultConfigResolverProvider implements ConfigResolverProvider { static final LazyValue INSTANCE = LazyValue.create(DefaultConfigResolver::new); diff --git a/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultStringValueParserProvider.java b/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultStringValueParserProvider.java index b95555c2bcb..8476c5b9af2 100644 --- a/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultStringValueParserProvider.java +++ b/pico/configdriven/runtime/src/main/java/io/helidon/pico/configdriven/runtime/DefaultStringValueParserProvider.java @@ -20,12 +20,13 @@ import io.helidon.builder.config.spi.StringValueParserProvider; import io.helidon.common.LazyValue; import io.helidon.common.Weight; -import io.helidon.common.Weighted; + +import static io.helidon.pico.api.ServiceInfoBasics.DEFAULT_PICO_WEIGHT; /** * Service-loaded provider for {@link StringValueParserProvider}. */ -@Weight(Weighted.DEFAULT_WEIGHT) +@Weight(DEFAULT_PICO_WEIGHT) public class DefaultStringValueParserProvider implements StringValueParserProvider { static final LazyValue INSTANCE = LazyValue.create(DefaultStringValueParser::new); diff --git a/pico/runtime/src/main/java/io/helidon/pico/runtime/DefaultPicoServicesProvider.java b/pico/runtime/src/main/java/io/helidon/pico/runtime/DefaultPicoServicesProvider.java index 4a36803394c..f0e7b88e3a5 100644 --- a/pico/runtime/src/main/java/io/helidon/pico/runtime/DefaultPicoServicesProvider.java +++ b/pico/runtime/src/main/java/io/helidon/pico/runtime/DefaultPicoServicesProvider.java @@ -20,7 +20,6 @@ import java.util.concurrent.atomic.AtomicReference; import io.helidon.common.Weight; -import io.helidon.common.Weighted; import io.helidon.pico.api.Bootstrap; import io.helidon.pico.api.PicoServices; import io.helidon.pico.api.Resettable; @@ -28,6 +27,8 @@ import jakarta.inject.Singleton; +import static io.helidon.pico.api.ServiceInfoBasics.DEFAULT_PICO_WEIGHT; + /** * The default implementation for {@link io.helidon.pico.spi.PicoServicesProvider}. * The first instance created (or first after calling deep {@link #reset}) will be the global services instance. The global @@ -36,7 +37,7 @@ * @see io.helidon.pico.api.PicoServices#picoServices() */ @Singleton -@Weight(Weighted.DEFAULT_WEIGHT) +@Weight(DEFAULT_PICO_WEIGHT) public class DefaultPicoServicesProvider implements PicoServicesProvider, Resettable { private static final AtomicReference INSTANCE = new AtomicReference<>(); diff --git a/pico/runtime/src/test/java/io/helidon/pico/runtime/testsubjects/HelloPicoImpl$$picoActivator.java b/pico/runtime/src/test/java/io/helidon/pico/runtime/testsubjects/HelloPicoImpl$$picoActivator.java index db2adf62bee..a167cd9f2ce 100644 --- a/pico/runtime/src/test/java/io/helidon/pico/runtime/testsubjects/HelloPicoImpl$$picoActivator.java +++ b/pico/runtime/src/test/java/io/helidon/pico/runtime/testsubjects/HelloPicoImpl$$picoActivator.java @@ -36,13 +36,14 @@ import static io.helidon.pico.api.ElementInfo.Access; import static io.helidon.pico.api.ElementInfo.ElementKind; +import static io.helidon.pico.api.ServiceInfoBasics.DEFAULT_PICO_WEIGHT; /** * Serves as an exemplar of what will is normally code generated. */ @Generated(value = "example", comments = "API Version: N") @Singleton -@Weight(DefaultServiceInfo.DEFAULT_WEIGHT) +@Weight(DEFAULT_PICO_WEIGHT) @SuppressWarnings({"unchecked", "checkstyle:TypeName"}) public class HelloPicoImpl$$picoActivator extends AbstractServiceProvider { diff --git a/pico/runtime/src/test/java/io/helidon/pico/runtime/testsubjects/PicoWorldImpl$$picoActivator.java b/pico/runtime/src/test/java/io/helidon/pico/runtime/testsubjects/PicoWorldImpl$$picoActivator.java index 1f926b278cf..69816aaada0 100644 --- a/pico/runtime/src/test/java/io/helidon/pico/runtime/testsubjects/PicoWorldImpl$$picoActivator.java +++ b/pico/runtime/src/test/java/io/helidon/pico/runtime/testsubjects/PicoWorldImpl$$picoActivator.java @@ -21,16 +21,17 @@ import io.helidon.common.Weight; import io.helidon.pico.api.DefaultServiceInfo; import io.helidon.pico.api.DependenciesInfo; -import io.helidon.pico.api.ServiceInfo; import io.helidon.pico.runtime.AbstractServiceProvider; import io.helidon.pico.runtime.Dependencies; import jakarta.annotation.Generated; import jakarta.inject.Singleton; +import static io.helidon.pico.api.ServiceInfoBasics.DEFAULT_PICO_WEIGHT; + @Generated(value = "example", comments = "API Version: n") @Singleton -@Weight(DefaultServiceInfo.DEFAULT_WEIGHT) +@Weight(DEFAULT_PICO_WEIGHT) public class PicoWorldImpl$$picoActivator extends AbstractServiceProvider { private static final DefaultServiceInfo serviceInfo = DefaultServiceInfo.builder() @@ -38,7 +39,7 @@ public class PicoWorldImpl$$picoActivator extends AbstractServiceProvider scan = LazyValue.create(ReflectionHandler.INSTANCE.scan()); private final ServicesToProcess services = ServicesToProcess.servicesInstance(); diff --git a/pico/tools/src/main/java/io/helidon/pico/tools/DefaultInterceptorCreator.java b/pico/tools/src/main/java/io/helidon/pico/tools/DefaultInterceptorCreator.java index 10c05ea51f5..70c4b5107c8 100644 --- a/pico/tools/src/main/java/io/helidon/pico/tools/DefaultInterceptorCreator.java +++ b/pico/tools/src/main/java/io/helidon/pico/tools/DefaultInterceptorCreator.java @@ -63,6 +63,7 @@ import jakarta.inject.Singleton; import static io.helidon.common.types.DefaultAnnotationAndValue.create; +import static io.helidon.pico.api.ServiceInfoBasics.DEFAULT_PICO_WEIGHT; import static io.helidon.pico.tools.TypeTools.createAnnotationAndValueFromMirror; import static io.helidon.pico.tools.TypeTools.createAnnotationAndValueListFromAnnotations; import static io.helidon.pico.tools.TypeTools.createAnnotationAndValueSet; @@ -75,7 +76,7 @@ * The default {@link io.helidon.pico.tools.spi.InterceptorCreator} provider in use. */ @Singleton -@Weight(Weighted.DEFAULT_WEIGHT) +@Weight(DEFAULT_PICO_WEIGHT) @SuppressWarnings("unchecked") public class DefaultInterceptorCreator extends AbstractCreator implements InterceptorCreator, Resettable { private static final LazyValue SCAN = LazyValue.create(ReflectionHandler.INSTANCE::scan);