Skip to content

Commit

Permalink
All Pico services should default to a lesser than DEFAULT_WEIGHT (#6590)
Browse files Browse the repository at this point in the history
* fix for issue# 6583
  • Loading branch information
trentjeff authored Apr 13, 2023
1 parent 1e25876 commit abd96ba
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i>internal</i> 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}.
Expand Down Expand Up @@ -96,13 +97,13 @@ default int realizedRunLevel() {
Optional<Double> 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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigBeanBuilderValidator<?>> INSTANCE = LazyValue.create(DefaultConfigBuilderValidator::new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigBeanRegistry> INSTANCE = LazyValue.create(DefaultPicoConfigBeanRegistry::new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigResolver> INSTANCE = LazyValue.create(DefaultConfigResolver::new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<StringValueParser> INSTANCE = LazyValue.create(DefaultStringValueParser::new);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
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;
import io.helidon.pico.spi.PicoServicesProvider;

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
Expand All @@ -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<DefaultPicoServices> INSTANCE = new AtomicReference<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HelloPicoWorldImpl> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,25 @@
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<PicoWorldImpl> {
private static final DefaultServiceInfo serviceInfo =
DefaultServiceInfo.builder()
.serviceTypeName(getServiceTypeName())
.activatorTypeName(PicoWorldImpl$$picoActivator.class.getName())
.addExternalContractsImplemented(PicoWorld.class.getName())
.addScopeTypeName(Singleton.class.getName())
.declaredWeight(ServiceInfo.DEFAULT_WEIGHT)
.declaredWeight(DEFAULT_PICO_WEIGHT)
.build();

public static final PicoWorldImpl$$picoActivator INSTANCE = new PicoWorldImpl$$picoActivator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

import static io.helidon.common.types.DefaultTypeName.create;
import static io.helidon.common.types.DefaultTypeName.createFromTypeName;
import static io.helidon.pico.api.ServiceInfoBasics.DEFAULT_PICO_WEIGHT;
import static io.helidon.pico.tools.CommonUtils.first;
import static io.helidon.pico.tools.CommonUtils.hasValue;
import static io.helidon.pico.tools.CommonUtils.toFlatName;
Expand All @@ -85,7 +86,7 @@
* {@link ActivatorCreatorRequest#codeGenPaths()} for details.
*/
@Singleton
@Weight(Weighted.DEFAULT_WEIGHT)
@Weight(DEFAULT_PICO_WEIGHT)
public class DefaultActivatorCreator extends AbstractCreator implements ActivatorCreator, Weighted {
/**
* The suffix name for the service type activator class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

import io.helidon.builder.processor.tools.BuilderTypeTools;
import io.helidon.common.Weight;
import io.helidon.common.Weighted;
import io.helidon.common.types.AnnotationAndValue;
import io.helidon.common.types.DefaultTypeName;
import io.helidon.common.types.TypeName;
Expand All @@ -51,13 +50,14 @@
import jakarta.inject.Provider;
import jakarta.inject.Singleton;

import static io.helidon.pico.api.ServiceInfoBasics.DEFAULT_PICO_WEIGHT;
import static io.helidon.pico.runtime.ServiceUtils.isQualifiedInjectionTarget;

/**
* The default implementation for {@link io.helidon.pico.tools.spi.ApplicationCreator}.
*/
@Singleton
@Weight(Weighted.DEFAULT_WEIGHT)
@Weight(DEFAULT_PICO_WEIGHT)
public class DefaultApplicationCreator extends AbstractCreator implements ApplicationCreator {
/**
* The prefix to add before the generated "Application" class name (i.e., "Pico$$" in the "Pico$$Application").
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import io.helidon.common.LazyValue;
import io.helidon.common.Weight;
import io.helidon.common.Weighted;
import io.helidon.common.types.TypeName;
import io.helidon.pico.api.DependenciesInfo;
import io.helidon.pico.api.InjectionPointInfo;
Expand All @@ -47,6 +46,7 @@
import jakarta.inject.Singleton;

import static io.helidon.common.types.DefaultTypeName.createFromTypeName;
import static io.helidon.pico.api.ServiceInfoBasics.DEFAULT_PICO_WEIGHT;
import static io.helidon.pico.tools.TypeTools.createInjectionPointInfo;
import static io.helidon.pico.tools.TypeTools.createQualifierAndValueSet;
import static io.helidon.pico.tools.TypeTools.createTypeNameFromClassInfo;
Expand All @@ -63,7 +63,7 @@
* The default implementation of {@link io.helidon.pico.tools.spi.ExternalModuleCreator}.
*/
@Singleton
@Weight(Weighted.DEFAULT_WEIGHT)
@Weight(DEFAULT_PICO_WEIGHT)
public class DefaultExternalModuleCreator extends AbstractCreator implements ExternalModuleCreator {
private final LazyValue<ScanResult> scan = LazyValue.create(ReflectionHandler.INSTANCE.scan());
private final ServicesToProcess services = ServicesToProcess.servicesInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ScanResult> SCAN = LazyValue.create(ReflectionHandler.INSTANCE::scan);
Expand Down

0 comments on commit abd96ba

Please sign in to comment.