From 37740692f1ad4f656a5ede6613deb7975bb118f7 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Fri, 22 Apr 2022 11:28:22 +0200 Subject: [PATCH 1/9] Use System.Logger in common. --- .../main/java/io/helidon/common/Errors.java | 11 +++-- .../io/helidon/common/HelidonFeatures.java | 39 ++++++++-------- .../helidon/common/SerializationConfig.java | 44 ++++++++++--------- common/common/src/main/java/module-info.java | 3 +- .../java/io/helidon/common/ErrorsTest.java | 5 +-- .../microprofile/messaging/ChannelRouter.java | 3 +- .../java/io/helidon/security/jwt/JwtTest.java | 3 +- .../helidon/security/jwt/SignedJwtTest.java | 6 +-- .../security/providers/oidc/OidcProvider.java | 21 ++++----- 9 files changed, 68 insertions(+), 67 deletions(-) diff --git a/common/common/src/main/java/io/helidon/common/Errors.java b/common/common/src/main/java/io/helidon/common/Errors.java index b9564a3ef1f..228bad68ea8 100644 --- a/common/common/src/main/java/io/helidon/common/Errors.java +++ b/common/common/src/main/java/io/helidon/common/Errors.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import java.util.List; import java.util.Objects; import java.util.Set; -import java.util.logging.Logger; import java.util.stream.Collectors; /** @@ -115,7 +114,7 @@ public boolean hasHint() { * otherwise. */ - public boolean log(Logger logger) { + public boolean log(System.Logger logger) { if (!isEmpty()) { StringBuilder fatals = new StringBuilder("\n"); StringBuilder warnings = new StringBuilder(); @@ -141,14 +140,14 @@ public boolean log(Logger logger) { if (hasFatal) { fatals.append(warnings).append(hints); - logger.severe("Fatal issues found: " + fatals); + logger.log(System.Logger.Level.ERROR, "Fatal issues found: " + fatals); } else { if (warnings.length() > 0) { - logger.warning("Warnings found: \n" + warnings); + logger.log(System.Logger.Level.WARNING, "Warnings found: \n" + warnings); } if (hints.length() > 0) { - logger.config("Hints found: \n" + hints); + logger.log(System.Logger.Level.TRACE, "Hints found: \n" + hints); } } diff --git a/common/common/src/main/java/io/helidon/common/HelidonFeatures.java b/common/common/src/main/java/io/helidon/common/HelidonFeatures.java index 955c1180d1b..9f82c6da657 100644 --- a/common/common/src/main/java/io/helidon/common/HelidonFeatures.java +++ b/common/common/src/main/java/io/helidon/common/HelidonFeatures.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package io.helidon.common; +import java.lang.System.Logger.Level; import java.util.Comparator; import java.util.EnumMap; import java.util.HashMap; @@ -28,7 +29,6 @@ import java.util.TreeSet; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Logger; import java.util.stream.Collectors; /** @@ -56,8 +56,8 @@ * */ public final class HelidonFeatures { - private static final Logger LOGGER = Logger.getLogger(HelidonFeatures.class.getName()); - private static final Logger EXPERIMENTAL = Logger.getLogger(HelidonFeatures.class.getName() + ".experimental"); + private static final System.Logger LOGGER = System.getLogger(HelidonFeatures.class.getName()); + private static final System.Logger EXPERIMENTAL = System.getLogger(HelidonFeatures.class.getName() + ".experimental"); private static final AtomicBoolean PRINTED = new AtomicBoolean(); private static final AtomicBoolean SCANNED = new AtomicBoolean(); private static final AtomicReference CURRENT_FLAVOR = new AtomicReference<>(); @@ -145,16 +145,16 @@ private static void features(HelidonFlavor flavor, String version, boolean detai Set features = FEATURES.get(currentFlavor); if (null == features) { - LOGGER.info("Helidon " + currentFlavor + " " + version + " has no registered features"); + LOGGER.log(Level.INFO, "Helidon " + currentFlavor + " " + version + " has no registered features"); } else { String featureString = "[" + features.stream() .map(FeatureDescriptor::name) .collect(Collectors.joining(", ")) + "]"; - LOGGER.info("Helidon " + currentFlavor + " " + version + " features: " + featureString); + LOGGER.log(Level.INFO, "Helidon " + currentFlavor + " " + version + " features: " + featureString); } if (details) { - LOGGER.info("Detailed feature tree:"); + LOGGER.log(Level.INFO, "Detailed feature tree:"); FEATURES.get(currentFlavor) .forEach(feature -> printDetails(feature.name(), ROOT_FEATURE_NODES.get(currentFlavor).get(feature.path()[0]), @@ -166,9 +166,11 @@ private static void features(HelidonFlavor flavor, String version, boolean detai ROOT_FEATURE_NODES.get(currentFlavor).get(feature.path()[0]))); if (!allExperimental.isEmpty()) { - EXPERIMENTAL.info("You are using experimental features. These APIs may change, please follow changelog!"); + EXPERIMENTAL.log(Level.INFO, + "You are using experimental features. These APIs may change, please follow changelog!"); allExperimental - .forEach(it -> EXPERIMENTAL.info("\tExperimental feature: " + it.name() + " (" + it.stringPath() + ")")); + .forEach(it -> EXPERIMENTAL.log(Level.INFO, + "\tExperimental feature: " + it.name() + " (" + it.stringPath() + ")")); } } } @@ -184,20 +186,21 @@ private static void gatherExperimental(List allExperimental, * Will scan all features and log errors and warnings for features that have a * native image limitation. * This method is automatically called when building a native image with Helidon. + * * @param classLoader to look for features in */ public static void nativeBuildTime(ClassLoader classLoader) { scan(classLoader); for (FeatureDescriptor feat : ALL_FEATURES) { if (!feat.nativeSupported()) { - LOGGER.severe("Feature '" + feat.name() - + "' for path '" + feat.stringPath() - + "' IS NOT SUPPORTED in native image. Image may still build and run."); + LOGGER.log(Level.ERROR, "Feature '" + feat.name() + + "' for path '" + feat.stringPath() + + "' IS NOT SUPPORTED in native image. Image may still build and run."); } else { if (!feat.nativeDescription().isBlank()) { - LOGGER.warning("Feature '" + feat.name() - + "' for path '" + feat.stringPath() - + "' has limited support in native image: " + feat.nativeDescription()); + LOGGER.log(Level.WARNING, "Feature '" + feat.name() + + "' for path '" + feat.stringPath() + + "' has limited support in native image: " + feat.nativeDescription()); } } } @@ -230,7 +233,7 @@ private static void scan(ClassLoader classLoader) { Set featureDescriptors = FeatureCatalog.get(packageName); if (featureDescriptors == null) { if (packageName.startsWith("io.helidon.")) { - LOGGER.fine("No catalog entry for package " + packageName); + LOGGER.log(Level.TRACE, "No catalog entry for package " + packageName); } } else { featureDescriptors.forEach(HelidonFeatures::register); @@ -244,7 +247,7 @@ private static void scan(ClassLoader classLoader) { if (feature.nativeSupported()) { String desc = feature.nativeDescription(); if (desc != null && !desc.isBlank()) { - LOGGER.warning("Native image for feature " + LOGGER.log(Level.WARNING, "Native image for feature " + feature.name() + "(" + feature.stringPath() @@ -252,7 +255,7 @@ private static void scan(ClassLoader classLoader) { + desc); } } else { - LOGGER.severe("You are using a feature not supported in native image: " + LOGGER.log(Level.ERROR, "You are using a feature not supported in native image: " + feature.name() + "(" + feature.stringPath() diff --git a/common/common/src/main/java/io/helidon/common/SerializationConfig.java b/common/common/src/main/java/io/helidon/common/SerializationConfig.java index 1b37b152c79..fe22d5170db 100644 --- a/common/common/src/main/java/io/helidon/common/SerializationConfig.java +++ b/common/common/src/main/java/io/helidon/common/SerializationConfig.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.ObjectInputFilter; +import java.lang.System.Logger.Level; import java.net.URL; import java.util.Arrays; import java.util.Collections; @@ -30,8 +31,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.stream.Collectors; /** @@ -98,7 +97,7 @@ public final class SerializationConfig { private static final String PROPERTY_FILE = "META-INF/helidon/serial-config.properties"; private static final String REJECT_ALL_PATTERN = "!*"; - private static final Logger LOGGER = Logger.getLogger(SerializationConfig.class.getName()); + private static final System.Logger LOGGER = System.getLogger(SerializationConfig.class.getName()); private static final AtomicReference EXISTING_CONFIG = new AtomicReference<>(); private final ConfigOptions options; @@ -137,7 +136,7 @@ private void configureDefaults() { // we should configure this instance as the global doConfigure(); } else { - LOGGER.log(Level.FINER, "Will not configure defaults, " + LOGGER.log(Level.TRACE, "Will not configure defaults, " + "there is already a serialization config in place: " + EXISTING_CONFIG.get()); } } @@ -184,7 +183,7 @@ private void doConfigure() { AtomicBoolean logged = new AtomicBoolean(); configureTracingFilter(options, it -> { if (it.serialClass() != null && logged.compareAndSet(false, true)) { - LOGGER.warning("Deserialization attempted for class " + it.serialClass().getName() + LOGGER.log(Level.WARNING, "Deserialization attempted for class " + it.serialClass().getName() + ", yet there is no global serial filter configured. " + "To automatically configure" + " a filter, please set system property \"" + PROP_NO_CONFIG_ACTION @@ -194,7 +193,7 @@ private void doConfigure() { }); return; case IGNORE: - LOGGER.finest("Ignoring that there is no global serial filter configured. To automatically configure" + LOGGER.log(Level.DEBUG, "Ignoring that there is no global serial filter configured. To automatically configure" + " a filter, please set system property " + PROP_NO_CONFIG_ACTION + " to \"configure\""); configureTracingFilter(options, null); @@ -210,7 +209,7 @@ private void doConfigure() { Action action = options.onWrongConfig(); if (action == Action.IGNORE) { - LOGGER.finest("Existing serialization config is ignored by Helidon."); + LOGGER.log(Level.DEBUG, "Existing serialization config is ignored by Helidon."); return; } @@ -222,7 +221,7 @@ private void validateExistingFilter(ObjectInputFilter currentFilter, Action acti String currentFilterString = System.getProperty("jdk.serialFilter"); if (currentFilterString == null) { - LOGGER.finest("Programmatic filter configured: " + currentFilter); + LOGGER.log(Level.DEBUG, "Programmatic filter configured: " + currentFilter); // somebody manually configured the filter ObjectInputFilter.Status status = currentFilter.checkInput(new ObjectInputFilter.FilterInfo() { @Override @@ -257,7 +256,7 @@ public long streamBytes() { + REJECT_ALL_PATTERN + "' as the last pattern."); } } else { - LOGGER.finest("System property filter configured: " + currentFilterString); + LOGGER.log(Level.DEBUG, "System property filter configured: " + currentFilterString); // make sure reject-list is for all if (hasRejectAll(currentFilterString)) { // this is OK @@ -282,13 +281,13 @@ private void handleBadFilter(Action action, String message) { case FAIL: throw new IllegalStateException(message); case WARN: - LOGGER.warning(message); + LOGGER.log(Level.WARNING, message); break; case CONFIGURE: throw new IllegalStateException("Cannot reconfigure current global deserialization filter." + " Original message: " + message); case IGNORE: - LOGGER.finest("Ignoring global deserialization filter issue. Original message: " + message); + LOGGER.log(Level.DEBUG, "Ignoring global deserialization filter issue. Original message: " + message); break; default: throw new IllegalStateException("Unexpected action to handle bad global deserialization filter: " + action); @@ -329,7 +328,7 @@ private ObjectInputFilter emptyFilter() { private void configureGlobalFilter(ConfigOptions options) { String pattern = options.filterPattern(); - LOGGER.finest("Using serialization pattern " + pattern); + LOGGER.log(Level.DEBUG, "Using serialization pattern " + pattern); ObjectInputFilter filter = ObjectInputFilter.Config.createFilter(pattern); configureTracingFilter(options, filter); @@ -406,9 +405,10 @@ private static Action configuredAction(String sysProp, Action defaultValue) { .map(String::toLowerCase) .collect(Collectors.toList()); - LOGGER.warning("System property \"" + sysProp + "\" is configured to \"" + property + "\", which is" - + " not a valid Action. Valid actions: " + validActions - + ". Using: " + defaultValue.toString().toLowerCase()); + LOGGER.log(Level.WARNING, + "System property \"" + sysProp + "\" is configured to \"" + property + "\", which is" + + " not a valid Action. Valid actions: " + validActions + + ". Using: " + defaultValue.toString().toLowerCase()); return defaultValue; } @@ -427,9 +427,10 @@ private static TraceOption configuredTrace(TraceOption defaultValue) { .map(String::toLowerCase) .collect(Collectors.toList()); - LOGGER.warning("System property \"" + PROP_TRACE + "\" is configured to \"" + property + "\", which is" - + " not a valid TraceOption. Valid trace options: " + validTraceOptions - + ". Using: " + defaultValue.toString().toLowerCase()); + LOGGER.log(Level.WARNING, + "System property \"" + PROP_TRACE + "\" is configured to \"" + property + "\", which is" + + " not a valid TraceOption. Valid trace options: " + validTraceOptions + + ". Using: " + defaultValue.toString().toLowerCase()); return defaultValue; } @@ -536,7 +537,7 @@ private String getPattern() { String pattern = props.getProperty("pattern"); if (pattern == null) { - LOGGER.warning("Could not find 'pattern' property in " + url); + LOGGER.log(Level.WARNING, "Could not find 'pattern' property in " + url); } else { if (!pattern.isBlank()) { parts.add(pattern); @@ -620,7 +621,7 @@ public String toString() { } private static class TracingObjectInputFilter implements ObjectInputFilter { - private static final Logger LOGGER = Logger.getLogger(TracingObjectInputFilter.class.getName()); + private static final System.Logger LOGGER = System.getLogger(TracingObjectInputFilter.class.getName()); private final Set> reportedClasses = Collections.newSetFromMap(new ConcurrentHashMap<>()); private final ObjectInputFilter delegate; @@ -648,7 +649,8 @@ public Status checkInput(FilterInfo filterInfo) { return result; } } - LOGGER.info(result + LOGGER.log(Level.INFO, + result + " class: " + clazz + ", arrayLength: " + filterInfo.arrayLength() + ", depth: " + filterInfo.depth() diff --git a/common/common/src/main/java/module-info.java b/common/common/src/main/java/module-info.java index 0e107f09b06..7da97db5664 100644 --- a/common/common/src/main/java/module-info.java +++ b/common/common/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ * Helidon Common library. */ module io.helidon.common { + // used only by LogConfig requires java.logging; exports io.helidon.common; diff --git a/common/common/src/test/java/io/helidon/common/ErrorsTest.java b/common/common/src/test/java/io/helidon/common/ErrorsTest.java index d05fa82ae44..33d6a5e66d9 100644 --- a/common/common/src/test/java/io/helidon/common/ErrorsTest.java +++ b/common/common/src/test/java/io/helidon/common/ErrorsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package io.helidon.common; import java.util.Optional; -import java.util.logging.Logger; import org.junit.jupiter.api.Test; @@ -31,7 +30,7 @@ * Unit test for {@link Errors}. */ class ErrorsTest { - private static final Logger LOGGER = Logger.getLogger(ErrorsTest.class.getName()); + private static final System.Logger LOGGER = System.getLogger(ErrorsTest.class.getName()); private static void assertErrorMessage(Optional actual, String expected, String message) { assertThat(actual, not(Optional.empty())); diff --git a/microprofile/messaging/core/src/main/java/io/helidon/microprofile/messaging/ChannelRouter.java b/microprofile/messaging/core/src/main/java/io/helidon/microprofile/messaging/ChannelRouter.java index a1183583c6d..7ed72cc9963 100644 --- a/microprofile/messaging/core/src/main/java/io/helidon/microprofile/messaging/ChannelRouter.java +++ b/microprofile/messaging/core/src/main/java/io/helidon/microprofile/messaging/ChannelRouter.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.logging.Logger; import io.helidon.common.Errors; import io.helidon.config.Config; @@ -43,7 +42,7 @@ * Orchestrator for all found channels, methods and connectors. */ class ChannelRouter { - private static final Logger LOGGER = Logger.getLogger(ChannelRouter.class.getName()); + private static final System.Logger LOGGER = System.getLogger(ChannelRouter.class.getName()); private final Errors.Collector errors = Errors.collector(); private final Config config = (Config) ConfigProvider.getConfig(); diff --git a/security/jwt/src/test/java/io/helidon/security/jwt/JwtTest.java b/security/jwt/src/test/java/io/helidon/security/jwt/JwtTest.java index d5c45211071..4edde93dcad 100644 --- a/security/jwt/src/test/java/io/helidon/security/jwt/JwtTest.java +++ b/security/jwt/src/test/java/io/helidon/security/jwt/JwtTest.java @@ -21,7 +21,6 @@ import java.util.List; import java.util.Optional; import java.util.UUID; -import java.util.logging.Logger; import io.helidon.common.Errors; import io.helidon.security.jwt.jwk.JwkRSA; @@ -35,7 +34,7 @@ * Unit test for {@link Jwt}. */ public class JwtTest { - private static final Logger LOGGER = Logger.getLogger(JwtTest.class.getName()); + private static final System.Logger LOGGER = System.getLogger(JwtTest.class.getName()); @Test public void testBuilderBasicJwt() { diff --git a/security/jwt/src/test/java/io/helidon/security/jwt/SignedJwtTest.java b/security/jwt/src/test/java/io/helidon/security/jwt/SignedJwtTest.java index 3e426f4c815..a6b604e2bb2 100644 --- a/security/jwt/src/test/java/io/helidon/security/jwt/SignedJwtTest.java +++ b/security/jwt/src/test/java/io/helidon/security/jwt/SignedJwtTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package io.helidon.security.jwt; -import java.util.logging.Logger; - import io.helidon.common.Errors; import io.helidon.common.configurable.Resource; import io.helidon.security.jwt.jwk.Jwk; @@ -37,7 +35,7 @@ * Unit test for {@link SignedJwt}. */ public class SignedJwtTest { - private static final Logger LOGGER = Logger.getLogger(SignedJwtTest.class.getName()); + private static final System.Logger LOGGER = System.getLogger(SignedJwtTest.class.getName()); private static final String AUTH_0_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlF6QkNNRE0xUVRJMk1qUkZNVEZETkRCRFJUWXdSa1U0UkRkRU16VTVSVGN3TkRSQk5qaENOUSJ9.eyJpc3MiOiJodHRwczovL2xhbmdvc2guZXUuYXV0aDAuY29tLyIsInN1YiI6ImF1dGgwfDU5NGEzNzJkNDUxN2FmMTA0ZjFiZGUzMCIsImF1ZCI6InliZlBpcnBwUTZaT094U0dLa2pnTWUxa2ZGTGZkbXlQIiwiZXhwIjoxNDk4MDgzOTI2LCJpYXQiOjE0OTgwNDc5MjZ9.nyMs5VfDV7Njd6hnQmbrSp_xVbIdvdP3ChzEtdffH2FWMqeW34gZT7dKJfgirdcBfXD4cDNDF2yjKZTe9-yCLWCFYtrfpvS_nlbt1hVM5ZR2HsGFSKdws0gOTsKCOTnD0SmfiQHCP-tzu87qWcVIwQcm-7AuLSfQ3WPxHAGPcQDOZiJBfcpBN4OGPKF0qq7PdNzBDDHmzpt2TbSsHmnSW-QbWZ1QHr52jsRCl1O_UTYHo2HE3ShE3WWBgYcJdJhgXNkhvJJh95oqmq_bfH5Saw-REmg-roU1bAh_yzFkmVSnhKmzHff432glRxcgDgF87kqJNodMD6UN6wRVt9vAPg"; diff --git a/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/OidcProvider.java b/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/OidcProvider.java index 92e5033326e..597d80a4b5d 100644 --- a/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/OidcProvider.java +++ b/security/providers/oidc/src/main/java/io/helidon/security/providers/oidc/OidcProvider.java @@ -16,6 +16,7 @@ package io.helidon.security.providers.oidc; +import java.lang.System.Logger.Level; import java.lang.annotation.Annotation; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; @@ -33,8 +34,6 @@ import java.util.concurrent.CompletionStage; import java.util.function.BiConsumer; import java.util.function.BiFunction; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -93,7 +92,7 @@ * */ public final class OidcProvider implements AuthenticationProvider, OutboundSecurityProvider { - private static final Logger LOGGER = Logger.getLogger(OidcProvider.class.getName()); + private static final System.Logger LOGGER = System.getLogger(OidcProvider.class.getName()); private final boolean optional; private final OidcConfig oidcConfig; @@ -270,8 +269,8 @@ public CompletionStage authenticate(ProviderRequest prov return cookie.get() .flatMapSingle(it -> validateToken(providerRequest, it)) .onErrorResumeWithSingle(throwable -> { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "Invalid token in cookie", throwable); + if (LOGGER.isLoggable(Level.DEBUG)) { + LOGGER.log(Level.DEBUG, "Invalid token in cookie", throwable); } return Single.just(errorResponse(providerRequest, Http.Status.UNAUTHORIZED_401, @@ -282,14 +281,16 @@ public CompletionStage authenticate(ProviderRequest prov } } } catch (SecurityException e) { - LOGGER.log(Level.FINEST, "Failed to extract token from one of the configured locations", e); + LOGGER.log(Level.DEBUG, "Failed to extract token from one of the configured locations", e); return failOrAbstain("Failed to extract one of the configured tokens" + e); } if (token.isPresent()) { return validateToken(providerRequest, token.get()); } else { - LOGGER.finest(() -> "Missing token, could not find in either of: " + missingLocations); + if (LOGGER.isLoggable(Level.DEBUG)) { + LOGGER.log(Level.DEBUG, "Missing token, could not find in either of: " + missingLocations); + } return CompletableFuture.completedFuture(errorResponse(providerRequest, Http.Status.UNAUTHORIZED_401, null, @@ -469,7 +470,7 @@ private Single validateToken(ProviderRequest providerReq signedJwt = SignedJwt.parseToken(token); } catch (Exception e) { //invalid token - LOGGER.log(Level.FINEST, "Could not parse inbound token", e); + LOGGER.log(Level.DEBUG, "Could not parse inbound token", e); return Single.just(AuthenticationResponse.failed("Invalid token", e)); } @@ -478,7 +479,7 @@ private Single validateToken(ProviderRequest providerReq signedJwt, it)) .onErrorResume(t -> { - LOGGER.log(Level.FINEST, "Failed to validate request", t); + LOGGER.log(Level.DEBUG, "Failed to validate request", t); return AuthenticationResponse.failed("Failed to validate JWT", t); }); } @@ -518,7 +519,7 @@ private AuthenticationResponse processValidationResult(ProviderRequest providerR "Scopes " + missingScopes + " are missing"); } } else { - if (LOGGER.isLoggable(Level.FINEST)) { + if (LOGGER.isLoggable(Level.DEBUG)) { // only log errors when details requested errors.log(LOGGER); validationErrors.log(LOGGER); From ec838ce3c37ae87f82229b50ac725413854cbe85 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Tue, 9 Aug 2022 16:20:56 +0200 Subject: [PATCH 2/9] Switch to System.Logger for common modules (except for reactive) --- .../common/configurable/ObserverManager.java | 5 ++-- .../common/configurable/ResourceImpl.java | 8 +++--- .../common/configurable/ResourceUtil.java | 15 ++--------- .../common/configurable/ThreadPool.java | 26 +++++++++---------- .../configurable/ThreadPoolSupplier.java | 10 +++---- .../configurable/VirtualExecutorUtil.java | 15 +++++------ .../src/main/java/module-info.java | 1 - common/context/src/main/java/module-info.java | 3 +-- common/http/src/main/java/module-info.java | 3 +-- .../java/io/helidon/common/pki/KeyConfig.java | 9 +++---- .../java/io/helidon/common/pki/PemReader.java | 7 +++-- .../java/io/helidon/common/pki/PkiUtil.java | 8 +++--- .../key-util/src/main/java/module-info.java | 4 +-- common/mapper/src/main/java/module-info.java | 3 +-- .../common/media/type/BuiltInsDetector.java | 12 ++++----- .../common/media/type/CustomDetector.java | 11 ++++---- .../helidon/common/media/type/MediaTypes.java | 4 +-- .../media-type/src/main/java/module-info.java | 3 +-- .../serviceloader/HelidonServiceLoader.java | 17 ++++++------ 19 files changed, 69 insertions(+), 95 deletions(-) diff --git a/common/configurable/src/main/java/io/helidon/common/configurable/ObserverManager.java b/common/configurable/src/main/java/io/helidon/common/configurable/ObserverManager.java index fa756bf12f1..90aaf8d1c7a 100644 --- a/common/configurable/src/main/java/io/helidon/common/configurable/ObserverManager.java +++ b/common/configurable/src/main/java/io/helidon/common/configurable/ObserverManager.java @@ -15,6 +15,7 @@ */ package io.helidon.common.configurable; +import java.lang.System.Logger.Level; import java.lang.reflect.Method; import java.util.List; import java.util.Map; @@ -23,8 +24,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.stream.Collectors; import io.helidon.common.LazyValue; @@ -46,7 +45,7 @@ */ class ObserverManager { - private static final Logger LOGGER = Logger.getLogger(ObserverManager.class.getName()); + private static final System.Logger LOGGER = System.getLogger(ObserverManager.class.getName()); private static final LazyValue> OBSERVERS = LazyValue .create(ObserverManager::loadObservers); diff --git a/common/configurable/src/main/java/io/helidon/common/configurable/ResourceImpl.java b/common/configurable/src/main/java/io/helidon/common/configurable/ResourceImpl.java index b03fd628678..c926281570e 100644 --- a/common/configurable/src/main/java/io/helidon/common/configurable/ResourceImpl.java +++ b/common/configurable/src/main/java/io/helidon/common/configurable/ResourceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,16 +19,16 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger.Level; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.logging.Level; -import java.util.logging.Logger; + /** * Implementation of {@link Resource}. */ class ResourceImpl implements Resource { - private static final Logger LOGGER = Logger.getLogger(Resource.class.getName()); + private static final System.Logger LOGGER = System.getLogger(Resource.class.getName()); private final Resource.Source source; private final String location; diff --git a/common/configurable/src/main/java/io/helidon/common/configurable/ResourceUtil.java b/common/configurable/src/main/java/io/helidon/common/configurable/ResourceUtil.java index ba628b90ff9..79653080f55 100644 --- a/common/configurable/src/main/java/io/helidon/common/configurable/ResourceUtil.java +++ b/common/configurable/src/main/java/io/helidon/common/configurable/ResourceUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,6 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; -import java.util.logging.Logger; import io.helidon.config.Config; @@ -40,7 +39,7 @@ final class ResourceUtil { private static final int DEFAULT_PROXY_PORT = 80; private static final Set LOGGED_RESOURCES = new HashSet<>(); - private static final Logger LOGGER = Logger.getLogger(ResourceUtil.class.getName()); + private static final System.Logger LOGGER = System.getLogger(ResourceUtil.class.getName()); private ResourceUtil() { } @@ -152,14 +151,4 @@ static Optional fromConfigResourcePath(Config config) { return config.asString() .map(Resource::create); } - - static void logPrefixed(Config config, String prefix, String type) { - String key = config.key().toString(); - if (LOGGED_RESOURCES.add(key + "." + prefix)) { - LOGGER.warning("Configuration for resource on key '" - + key + "." + prefix + "-" + type - + "' uses old prefixed approach. Please remove the prefix and use '" - + key + "." + prefix + ".resource." + type + "'"); - } - } } diff --git a/common/configurable/src/main/java/io/helidon/common/configurable/ThreadPool.java b/common/configurable/src/main/java/io/helidon/common/configurable/ThreadPool.java index b180e8b74d3..4c29e720be1 100644 --- a/common/configurable/src/main/java/io/helidon/common/configurable/ThreadPool.java +++ b/common/configurable/src/main/java/io/helidon/common/configurable/ThreadPool.java @@ -20,6 +20,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; +import java.lang.System.Logger.Level; import java.lang.management.GarbageCollectorMXBean; import java.lang.management.ManagementFactory; import java.nio.charset.StandardCharsets; @@ -48,8 +49,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.LongAdder; import java.util.function.Predicate; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.management.NotificationEmitter; @@ -59,7 +58,7 @@ * A {@link ThreadPoolExecutor} with an extensible growth policy and queue state accessors. */ public class ThreadPool extends ThreadPoolExecutor { - private static final Logger LOGGER = Logger.getLogger(ThreadPool.class.getName()); + private static final System.Logger LOGGER = System.getLogger(ThreadPool.class.getName()); private static final int MAX_GROWTH_RATE = 100; private final String name; @@ -188,8 +187,8 @@ private ThreadPool(String name, this.growthRate = growthRate; this.rejectionHandler = rejectionHandler; queue.setPool(this); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine(toString()); + if (LOGGER.isLoggable(Level.TRACE)) { + LOGGER.log(Level.TRACE, toString()); } } @@ -346,7 +345,7 @@ public RejectionHandler getRejectedExecutionHandler() { @Override public void setMaximumPoolSize(int maximumPoolSize) { if (maximumPoolSize != getMaximumPoolSize()) { - LOGGER.warning("Maximum pool size cannot be changed in " + this); + LOGGER.log(Level.WARNING, "Maximum pool size cannot be changed in " + this); } } @@ -427,7 +426,7 @@ public void rejectedExecution(Runnable task, ThreadPoolExecutor executor) { // No capacity, so reject - LOGGER.warning(rejectionMessage(executor)); + LOGGER.log(Level.WARNING, rejectionMessage(executor)); rejections.incrementAndGet(); throwException(executor); } @@ -743,8 +742,9 @@ public boolean offer(Runnable task) { // check above is not accurate); in this case, the rejection handler will just add it to // the queue. - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine("Adding a thread, pool size = " + pool.getPoolSize() + ", queue size = " + size()); + if (LOGGER.isLoggable(Level.TRACE)) { + LOGGER.log(Level.TRACE, + "Adding a thread, pool size = " + pool.getPoolSize() + ", queue size = " + size()); } return false; @@ -916,7 +916,7 @@ private String toCsv() { private static void add(Type type, ThreadPool pool, WorkQueue queue) { if (shouldAdd()) { if (!STARTED.getAndSet(true)) { - LOGGER.info("Recording up to " + MAX_EVENTS + " thread pool events"); + LOGGER.log(Level.INFO, "Recording up to " + MAX_EVENTS + " thread pool events"); for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) { final NotificationEmitter emitter = (NotificationEmitter) bean; emitter.addNotificationListener((notification, handback) -> { @@ -946,7 +946,7 @@ private static boolean shouldAdd() { private static void write() { if (!EVENTS.isEmpty() && !WRITTEN.getAndSet(true)) { final Path file = Paths.get(EVENTS_FILE_NAME).toAbsolutePath(); - LOGGER.info("Writing thread pool events to " + file); + LOGGER.log(Level.INFO, "Writing thread pool events to " + file); EVENTS.sort(null); try (OutputStream out = Files.newOutputStream(file, StandardOpenOption.CREATE, @@ -956,9 +956,9 @@ private static void write() { for (Event event : EVENTS) { out.write(event.toCsv().getBytes(StandardCharsets.UTF_8)); } - LOGGER.info("Finished writing thread pool events"); + LOGGER.log(Level.INFO, "Finished writing thread pool events"); } catch (Throwable e) { - LOGGER.warning("failed to write thread pool events" + e); + LOGGER.log(Level.WARNING, "failed to write thread pool events" + e); } } } diff --git a/common/configurable/src/main/java/io/helidon/common/configurable/ThreadPoolSupplier.java b/common/configurable/src/main/java/io/helidon/common/configurable/ThreadPoolSupplier.java index d3686cdf80a..c9244b35b36 100644 --- a/common/configurable/src/main/java/io/helidon/common/configurable/ThreadPoolSupplier.java +++ b/common/configurable/src/main/java/io/helidon/common/configurable/ThreadPoolSupplier.java @@ -21,7 +21,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; -import java.util.logging.Logger; import io.helidon.common.LazyValue; import io.helidon.common.context.Contexts; @@ -34,7 +33,7 @@ * The returned thread pool supports {@link io.helidon.common.context.Context} propagation. */ public final class ThreadPoolSupplier implements Supplier { - private static final Logger LOGGER = Logger.getLogger(ThreadPoolSupplier.class.getName()); + private static final System.Logger LOGGER = System.getLogger(ThreadPoolSupplier.class.getName()); private static final ThreadPool.RejectionHandler DEFAULT_REJECTION_POLICY = new ThreadPool.RejectionHandler(); private static final AtomicInteger DEFAULT_NAME_COUNTER = new AtomicInteger(); private static final int DEFAULT_CORE_POOL_SIZE = 10; @@ -113,7 +112,7 @@ public static ThreadPoolSupplier create(String name) { ExecutorService getThreadPool() { if (useVirtualThreads) { if (VirtualExecutorUtil.isVirtualSupported()) { - LOGGER.fine("Using unbounded virtual executor service for pool " + name); + LOGGER.log(System.Logger.Level.TRACE, "Using unbounded virtual executor service for pool " + name); return ObserverManager.registerExecutorService(this, VirtualExecutorUtil.executorService()); } } @@ -175,7 +174,7 @@ private Builder() { public ThreadPoolSupplier build() { if (name == null) { if (threadNamePrefix == null) { - LOGGER.warning("Neither a thread name prefix nor a pool name specified"); + LOGGER.log(System.Logger.Level.WARNING, "Neither a thread name prefix nor a pool name specified"); threadNamePrefix = DEFAULT_THREAD_NAME_PREFIX; } name = threadNamePrefix + "thread-pool-" + DEFAULT_NAME_COUNTER.incrementAndGet(); @@ -445,7 +444,8 @@ public Builder config(Config config) { } private void warnExperimental(String key) { - LOGGER.warning(String.format("Config key \"executor-service.%s\" is EXPERIMENTAL and subject to change.", key)); + LOGGER.log(System.Logger.Level.WARNING, + String.format("Config key \"executor-service.%s\" is EXPERIMENTAL and subject to change.", key)); } /** diff --git a/common/configurable/src/main/java/io/helidon/common/configurable/VirtualExecutorUtil.java b/common/configurable/src/main/java/io/helidon/common/configurable/VirtualExecutorUtil.java index 723049d0fb1..959928b603b 100644 --- a/common/configurable/src/main/java/io/helidon/common/configurable/VirtualExecutorUtil.java +++ b/common/configurable/src/main/java/io/helidon/common/configurable/VirtualExecutorUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ package io.helidon.common.configurable; +import java.lang.System.Logger.Level; import java.lang.reflect.Method; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.logging.Level; -import java.util.logging.Logger; import io.helidon.common.LazyValue; @@ -29,7 +28,7 @@ * A utility class to handle virtual threads (project Loom). */ final class VirtualExecutorUtil { - private static final Logger LOGGER = Logger.getLogger(VirtualExecutorUtil.class.getName()); + private static final System.Logger LOGGER = System.getLogger(VirtualExecutorUtil.class.getName()); private static final LazyValue SUPPORTED = LazyValue.create(VirtualExecutorUtil::findSupported); private static final LazyValue EXECUTOR_SERVICE = LazyValue.create(VirtualExecutorUtil::findExecutor); // newer and older builds @@ -58,7 +57,7 @@ private static boolean findSupported() { findMethod(); return true; } catch (final ReflectiveOperationException e) { - LOGGER.log(Level.FINEST, "Loom virtual executor service not available", e); + LOGGER.log(Level.DEBUG, "Loom virtual executor service not available", e); } return false; @@ -70,7 +69,7 @@ private static ExecutorService findExecutor() { // and runtime environments (support for GraalVM native image) return (ExecutorService) findMethod().invoke(null); } catch (final ReflectiveOperationException e) { - LOGGER.log(Level.FINEST, "Loom virtual executor service not available", e); + LOGGER.log(Level.DEBUG, "Loom virtual executor service not available", e); } return null; @@ -81,8 +80,8 @@ private static Method findMethod() throws ReflectiveOperationException { for (String methodName : SUPPORTED_METHOD_NAMES) { try { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("Trying Loom executor method Executors." + methodName + "()"); + if (LOGGER.isLoggable(Level.DEBUG)) { + LOGGER.log(Level.DEBUG, "Trying Loom executor method Executors." + methodName + "()"); } return Executors.class.getDeclaredMethod(methodName); } catch (ReflectiveOperationException e) { diff --git a/common/configurable/src/main/java/module-info.java b/common/configurable/src/main/java/module-info.java index 71df572fbda..e32b5adee8d 100644 --- a/common/configurable/src/main/java/module-info.java +++ b/common/configurable/src/main/java/module-info.java @@ -20,7 +20,6 @@ * @see io.helidon.common.configurable.Resource */ module io.helidon.common.configurable { - requires java.logging; requires java.management; requires transitive io.helidon.config; requires io.helidon.common; diff --git a/common/context/src/main/java/module-info.java b/common/context/src/main/java/module-info.java index 533e598b613..f46114f8384 100644 --- a/common/context/src/main/java/module-info.java +++ b/common/context/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ * Helidon Common Context library. */ module io.helidon.common.context { - requires java.logging; requires io.helidon.common; requires io.helidon.common.serviceloader; diff --git a/common/http/src/main/java/module-info.java b/common/http/src/main/java/module-info.java index 5109e7363c3..1e41092c7db 100644 --- a/common/http/src/main/java/module-info.java +++ b/common/http/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ * Helidon Common classes for HTTP server and client. */ module io.helidon.common.http { - requires java.logging; requires io.helidon.common; requires io.helidon.common.context; requires io.helidon.common.reactive; diff --git a/common/key-util/src/main/java/io/helidon/common/pki/KeyConfig.java b/common/key-util/src/main/java/io/helidon/common/pki/KeyConfig.java index 1d884376f7c..b7cbc0e1ef7 100644 --- a/common/key-util/src/main/java/io/helidon/common/pki/KeyConfig.java +++ b/common/key-util/src/main/java/io/helidon/common/pki/KeyConfig.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger.Level; import java.security.KeyStore; import java.security.PrivateKey; import java.security.PublicKey; @@ -29,8 +30,6 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.logging.Level; -import java.util.logging.Logger; import io.helidon.common.configurable.Resource; import io.helidon.common.configurable.ResourceException; @@ -73,7 +72,7 @@ */ public final class KeyConfig { private static final String DEFAULT_PRIVATE_KEY_ALIAS = "1"; - private static final Logger LOGGER = Logger.getLogger(KeyConfig.class.getName()); + private static final System.Logger LOGGER = System.getLogger(KeyConfig.class.getName()); private static final char[] EMPTY_CHARS = new char[0]; private final PrivateKey privateKey; @@ -527,7 +526,7 @@ private Builder updateBuilder(Builder builder) { builder.privateKey(PkiUtil.loadPrivateKey(keyStore, keyAlias, keyPassphrase)); } catch (Exception e) { if (guessing) { - LOGGER.log(Level.FINEST, "Failed to read private key from default alias", e); + LOGGER.log(Level.DEBUG, "Failed to read private key from default alias", e); } else { throw e; } @@ -548,7 +547,7 @@ private Builder updateBuilder(Builder builder) { certChain.forEach(builder::addCertChain); } catch (Exception e) { if (guessing) { - LOGGER.log(Level.FINEST, "Failed to certificate chain from alias \"" + certChainAlias + "\"", e); + LOGGER.log(Level.DEBUG, "Failed to certificate chain from alias \"" + certChainAlias + "\"", e); } else { throw e; } diff --git a/common/key-util/src/main/java/io/helidon/common/pki/PemReader.java b/common/key-util/src/main/java/io/helidon/common/pki/PemReader.java index f3941170e15..3d775c8c151 100644 --- a/common/key-util/src/main/java/io/helidon/common/pki/PemReader.java +++ b/common/key-util/src/main/java/io/helidon/common/pki/PemReader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.lang.System.Logger.Level; import java.nio.charset.StandardCharsets; import java.security.KeyFactory; import java.security.PrivateKey; @@ -34,8 +35,6 @@ import java.util.ArrayList; import java.util.Base64; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -49,7 +48,7 @@ * Reads a PEM file and converts it into a list of DERs so that they are imported into a {@link java.security.KeyStore} easily. */ final class PemReader { - private static final Logger LOGGER = Logger.getLogger(PemReader.class.getName()); + private static final System.Logger LOGGER = System.getLogger(PemReader.class.getName()); private static final Pattern CERT_PATTERN = Pattern.compile( "-+BEGIN\\s+.*CERTIFICATE[^-]*-+(?:\\s|\\r|\\n)+" // Header diff --git a/common/key-util/src/main/java/io/helidon/common/pki/PkiUtil.java b/common/key-util/src/main/java/io/helidon/common/pki/PkiUtil.java index 1fb3a47ce1b..8e32099693f 100644 --- a/common/key-util/src/main/java/io/helidon/common/pki/PkiUtil.java +++ b/common/key-util/src/main/java/io/helidon/common/pki/PkiUtil.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package io.helidon.common.pki; import java.io.InputStream; +import java.lang.System.Logger.Level; import java.security.Key; import java.security.KeyStore; import java.security.KeyStoreException; @@ -29,7 +30,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Objects; -import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -37,7 +37,7 @@ * Utilities to handle PKI keystores, certificates and keys. */ final class PkiUtil { - private static final Logger LOGGER = Logger.getLogger(PkiUtil.class.getName()); + private static final System.Logger LOGGER = System.getLogger(PkiUtil.class.getName()); private PkiUtil() { } @@ -105,7 +105,7 @@ static List loadCertificates(KeyStore keyStore) { X509Certificate cert = (X509Certificate) keyStore.getCertificate(alias); certs.add(cert); - LOGGER.finest(() -> "Added certificate under alis " + alias + " for " + cert + LOGGER.log(Level.DEBUG, () -> "Added certificate under alis " + alias + " for " + cert .getSubjectDN() + " to list of certificates"); } } diff --git a/common/key-util/src/main/java/module-info.java b/common/key-util/src/main/java/module-info.java index ff5d7447ade..61a2668af0d 100644 --- a/common/key-util/src/main/java/module-info.java +++ b/common/key-util/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ * Utilities for PKI configuration and loading of certificates and keys. */ module io.helidon.common.pki { - requires java.logging; - requires transitive io.helidon.common; requires transitive io.helidon.config; requires transitive io.helidon.common.configurable; diff --git a/common/mapper/src/main/java/module-info.java b/common/mapper/src/main/java/module-info.java index 536f1c91630..d24a20055b7 100644 --- a/common/mapper/src/main/java/module-info.java +++ b/common/mapper/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ * Helidon Common Mapper. */ module io.helidon.common.mapper { - requires java.logging; requires transitive io.helidon.common; requires transitive io.helidon.common.serviceloader; diff --git a/common/media-type/src/main/java/io/helidon/common/media/type/BuiltInsDetector.java b/common/media-type/src/main/java/io/helidon/common/media/type/BuiltInsDetector.java index 65373a6cf52..93227f1e578 100644 --- a/common/media-type/src/main/java/io/helidon/common/media/type/BuiltInsDetector.java +++ b/common/media-type/src/main/java/io/helidon/common/media/type/BuiltInsDetector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,12 +17,11 @@ import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger.Level; import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; import io.helidon.common.media.type.spi.MediaTypeDetector; @@ -30,7 +29,8 @@ * Detector for built-in media type mappings. */ class BuiltInsDetector implements MediaTypeDetector { - private static final Logger LOGGER = Logger.getLogger(BuiltInsDetector.class.getName()); + private static final System.Logger LOGGER = System.getLogger(BuiltInsDetector.class.getName()); + private static final Map MAPPINGS = new HashMap<>(); static { try (InputStream builtIns = MediaTypes.class.getResourceAsStream("default-media-types.properties")) { @@ -41,10 +41,10 @@ class BuiltInsDetector implements MediaTypeDetector { MAPPINGS.put(name, properties.getProperty(name)); } } else { - LOGGER.log(Level.SEVERE, "Failed to find default media type mapping resource"); + LOGGER.log(Level.ERROR, "Failed to find default media type mapping resource"); } } catch (IOException e) { - LOGGER.log(Level.SEVERE, "Failed to load default media types mapping", e); + LOGGER.log(Level.ERROR, "Failed to load default media types mapping", e); } } diff --git a/common/media-type/src/main/java/io/helidon/common/media/type/CustomDetector.java b/common/media-type/src/main/java/io/helidon/common/media/type/CustomDetector.java index fcfa2b7c845..6f583014075 100644 --- a/common/media-type/src/main/java/io/helidon/common/media/type/CustomDetector.java +++ b/common/media-type/src/main/java/io/helidon/common/media/type/CustomDetector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,14 +17,13 @@ import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger.Level; import java.net.URL; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; import io.helidon.common.media.type.spi.MediaTypeDetector; @@ -33,7 +32,7 @@ */ class CustomDetector implements MediaTypeDetector { private static final String MEDIA_TYPE_RESOURCE = "META-INF/helidon/media-types.properties"; - private static final Logger LOGGER = Logger.getLogger(CustomDetector.class.getName()); + private static final System.Logger LOGGER = System.getLogger(CustomDetector.class.getName()); private static final Map MAPPINGS = new HashMap<>(); static { @@ -45,7 +44,7 @@ class CustomDetector implements MediaTypeDetector { Enumeration resources = classLoader.getResources(MEDIA_TYPE_RESOURCE); while (resources.hasMoreElements()) { URL url = resources.nextElement(); - LOGGER.finest(() -> "Loading custom media type mapping from: " + url); + LOGGER.log(Level.DEBUG, () -> "Loading custom media type mapping from: " + url); try (InputStream is = url.openStream()) { Properties properties = new Properties(); properties.load(is); @@ -55,7 +54,7 @@ class CustomDetector implements MediaTypeDetector { } } } catch (IOException e) { - LOGGER.log(Level.SEVERE, "Failed to load custom media types mapping", e); + LOGGER.log(Level.ERROR, "Failed to load custom media types mapping", e); } } diff --git a/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java b/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java index cd84772fcd6..b2041d58be6 100644 --- a/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java +++ b/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import java.util.Optional; import java.util.ServiceLoader; import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Logger; import io.helidon.common.media.type.spi.MediaTypeDetector; import io.helidon.common.serviceloader.HelidonServiceLoader; @@ -37,7 +36,6 @@ * */ public final class MediaTypes { - private static final Logger LOGGER = Logger.getLogger(MediaTypes.class.getName()); private static final List DETECTORS; private static final ConcurrentHashMap> CACHE = new ConcurrentHashMap<>(); diff --git a/common/media-type/src/main/java/module-info.java b/common/media-type/src/main/java/module-info.java index c3717cacfb5..6d33fe547ce 100644 --- a/common/media-type/src/main/java/module-info.java +++ b/common/media-type/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,6 @@ * Helidon Common Media Type. */ module io.helidon.common.media.type { - requires java.logging; requires io.helidon.common.serviceloader; exports io.helidon.common.media.type; diff --git a/common/service-loader/src/main/java/io/helidon/common/serviceloader/HelidonServiceLoader.java b/common/service-loader/src/main/java/io/helidon/common/serviceloader/HelidonServiceLoader.java index a414e9d615a..49a7008579b 100644 --- a/common/service-loader/src/main/java/io/helidon/common/serviceloader/HelidonServiceLoader.java +++ b/common/service-loader/src/main/java/io/helidon/common/serviceloader/HelidonServiceLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package io.helidon.common.serviceloader; +import java.lang.System.Logger.Level; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; @@ -24,8 +25,6 @@ import java.util.ServiceLoader; import java.util.Set; import java.util.function.Consumer; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.stream.Collectors; import io.helidon.common.Prioritized; @@ -82,7 +81,7 @@ public final class HelidonServiceLoader implements Iterable { */ public static final String SYSTEM_PROPERTY_EXCLUDE = "io.helidon.common.serviceloader.exclude"; - private static final Logger LOGGER = Logger.getLogger(HelidonServiceLoader.class.getName()); + private static final System.Logger LOGGER = System.getLogger(HelidonServiceLoader.class.getName()); private final List services; @@ -292,7 +291,7 @@ public Builder defaultPriority(int defaultPriority) { private boolean notExcluded(ServiceWithPriority service) { String className = service.instance.getClass().getName(); if (excludedServiceClasses.contains(className)) { - LOGGER.finest(() -> "Excluding service implementation " + className); + LOGGER.log(Level.DEBUG, () -> "Excluding service implementation " + className); return false; } return true; @@ -305,12 +304,12 @@ private List orderByPriority(List> services) { .map(ServiceWithPriority::instance) .collect(Collectors.toList()); - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.finest("Final order of enabled service implementations for service: " + serviceLoader); + if (LOGGER.isLoggable(Level.DEBUG)) { + LOGGER.log(Level.DEBUG, "Final order of enabled service implementations for service: " + serviceLoader); result.stream() .map(Object::getClass) .map(Class::getName) - .forEach(LOGGER::finest); + .forEach(it -> LOGGER.log(Level.DEBUG, it)); } return result; @@ -323,7 +322,7 @@ private void addSystemExcludes() { } for (String exclude : excludes.split(",")) { - LOGGER.finest(() -> "Adding exclude from system properties: " + exclude); + LOGGER.log(Level.DEBUG, () -> "Adding exclude from system properties: " + exclude); addExcludedClassName(exclude); } } From 57f7c7b3bf102292ae566bc71dc272c7a588fc78 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Tue, 9 Aug 2022 17:11:04 +0200 Subject: [PATCH 3/9] Move HelidonServiceLoader to common module. --- CHANGELOG.md | 2 + README.md | 5 + bom/pom.xml | 5 - common/common/pom.xml | 31 ++-- .../helidon/common}/HelidonServiceLoader.java | 8 +- .../java/io/helidon/common}/Priorities.java | 4 +- .../main/java/io/helidon/common/Weight.java} | 30 +++- .../main/java/io/helidon/common/Weighted.java | 57 +++++++ .../main/java/io/helidon/common/Weights.java | 153 ++++++++++++++++++ common/common/src/main/java/module-info.java | 1 + .../common}/HelidonServiceLoaderTest.java | 6 +- .../io/helidon/common}/PrioritiesTest.java | 6 +- .../java/io/helidon/common}/ServiceImpl1.java | 4 +- .../java/io/helidon/common}/ServiceImpl2.java | 6 +- .../java/io/helidon/common}/ServiceImpl3.java | 4 +- .../io/helidon/common}/ServiceInterface.java | 4 +- .../io.helidon.common.ServiceInterface} | 6 +- common/configurable/pom.xml | 4 - common/context/pom.xml | 4 - .../context/ContextAwareExecutorImpl.java | 4 +- common/context/src/main/java/module-info.java | 1 - common/mapper/pom.xml | 4 - .../helidon/common/mapper/MapperManager.java | 10 +- common/mapper/src/main/java/module-info.java | 1 - .../common/mapper/MapperManagerTest.java | 4 +- common/media-type/pom.xml | 2 +- .../helidon/common/media/type/MediaTypes.java | 2 +- .../media-type/src/main/java/module-info.java | 2 +- common/pom.xml | 1 - common/service-loader/pom.xml | 61 ------- .../common/serviceloader/package-info.java | 19 --- config/config-mp/pom.xml | 4 - .../io/helidon/config/mp/MpConfigBuilder.java | 4 +- .../io/helidon/config/mp/MpHelidonSource.java | 2 +- .../config-mp/src/main/java/module-info.java | 1 - .../java/io/helidon/config/BuilderImpl.java | 6 +- .../java/io/helidon/config/MetaConfig.java | 4 +- .../java/io/helidon/config/MetaProviders.java | 4 +- config/config/src/main/java/module-info.java | 2 - dbclient/dbclient/pom.xml | 4 - .../java/io/helidon/dbclient/DbClient.java | 4 +- .../dbclient/DbClientProviderLoader.java | 4 +- .../io/helidon/dbclient/DbMapperManager.java | 6 +- .../dbclient/src/main/java/module-info.java | 1 - .../helidon/dbclient/jdbc/ConnectionPool.java | 4 +- etc/HELIDON_THIRD_PARTY_LICENSES.xml | 1 - .../vault/cdi/VaultCdiExtension.java | 4 +- .../vault/cdi/src/main/java/module-info.java | 1 - integrations/vault/vault/pom.xml | 4 - .../io/helidon/integrations/vault/Vault.java | 4 +- .../helidon/integrations/vault/VaultImpl.java | 4 +- .../vault/src/main/java/module-info.java | 1 - logging/common/pom.xml | 3 +- .../io/helidon/logging/common/HelidonMdc.java | 4 +- logging/common/src/main/java/module-info.java | 4 +- .../native-image.properties | 4 +- .../io/helidon/media/common/MediaContext.java | 2 +- metrics/api/pom.xml | 4 - .../metrics/api/RegistryFactoryManager.java | 2 +- metrics/api/src/main/java/module-info.java | 1 - metrics/metrics/pom.xml | 4 - .../metrics/ExemplarServiceManager.java | 4 +- .../metrics/src/main/java/module-info.java | 1 - .../serviceapi/MetricsSupportManager.java | 4 +- .../src/main/java/module-info.java | 1 - .../config/src/main/java/module-info.java | 1 - microprofile/grpc/core/pom.xml | 4 - .../grpc/core/AbstractServiceBuilder.java | 2 +- .../grpc/core/src/main/java/module-info.java | 1 - microprofile/grpc/metrics/pom.xml | 4 - .../server/AnnotatedServiceConfigurer.java | 2 +- .../grpc/server/GrpcServerCdiExtension.java | 2 +- .../grpc/server/GrpcServiceBuilder.java | 2 +- .../server/src/main/java/module-info.java | 1 - .../health/HealthCdiExtension.java | 2 +- .../health/HealthCheckProvider.java | 2 +- .../health/src/main/java/module-info.java | 1 - microprofile/lra/jax-rs/pom.xml | 4 - .../lra/CoordinatorLocatorService.java | 2 +- .../lra/jax-rs/src/main/java/module-info.java | 1 - microprofile/metrics/pom.xml | 4 - .../metrics/src/main/java/module-info.java | 2 +- microprofile/server/pom.xml | 4 - .../server/src/main/java/module-info.java | 1 - .../security/abac/policy/PolicyValidator.java | 4 +- .../policy/src/main/java/module-info.java | 1 - .../src/main/java/module-info.java | 2 +- security/integration/jersey/pom.xml | 4 - .../integration/jersey/SecurityFilter.java | 2 +- .../jersey/SecurityFilterCommon.java | 2 +- .../jersey/src/main/java/module-info.java | 1 - .../security/providers/abac/AbacProvider.java | 2 +- .../abac/src/main/java/module-info.java | 1 - .../httpauth/HttpBasicAuthProvider.java | 2 +- .../http-auth/src/main/java/module-info.java | 1 - .../java/io/helidon/security/Security.java | 2 +- .../security/src/main/java/module-info.java | 1 - .../jersey/client/ClientTracingFilter.java | 2 +- .../src/main/java/module-info.java | 1 - tracing/opentracing/pom.xml | 4 - .../OpenTracingProviderHelper.java | 2 +- .../src/main/java/module-info.java | 1 - tracing/tracing/pom.xml | 4 - .../helidon/tracing/TracerProviderHelper.java | 2 +- .../tracing/src/main/java/module-info.java | 1 - .../java/io/helidon/webclient/WebClient.java | 2 +- .../WebClientRequestBuilderImpl.java | 2 +- .../webclient/src/main/java/module-info.java | 1 - .../io/helidon/webserver/UpgradeManager.java | 2 +- 109 files changed, 350 insertions(+), 299 deletions(-) rename common/{service-loader/src/main/java/io/helidon/common/serviceloader => common/src/main/java/io/helidon/common}/HelidonServiceLoader.java (98%) rename common/{service-loader/src/main/java/io/helidon/common/serviceloader => common/src/main/java/io/helidon/common}/Priorities.java (97%) rename common/{service-loader/src/main/java/module-info.java => common/src/main/java/io/helidon/common/Weight.java} (50%) create mode 100644 common/common/src/main/java/io/helidon/common/Weighted.java create mode 100644 common/common/src/main/java/io/helidon/common/Weights.java rename common/{service-loader/src/test/java/io/helidon/common/serviceloader => common/src/test/java/io/helidon/common}/HelidonServiceLoaderTest.java (96%) rename common/{service-loader/src/test/java/io/helidon/common/serviceloader => common/src/test/java/io/helidon/common}/PrioritiesTest.java (96%) rename common/{service-loader/src/test/java/io/helidon/common/serviceloader => common/src/test/java/io/helidon/common}/ServiceImpl1.java (88%) rename common/{service-loader/src/test/java/io/helidon/common/serviceloader => common/src/test/java/io/helidon/common}/ServiceImpl2.java (88%) rename common/{service-loader/src/test/java/io/helidon/common/serviceloader => common/src/test/java/io/helidon/common}/ServiceImpl3.java (88%) rename common/{service-loader/src/test/java/io/helidon/common/serviceloader => common/src/test/java/io/helidon/common}/ServiceInterface.java (87%) rename common/{service-loader/src/test/resources/META-INF/services/io.helidon.common.serviceloader.ServiceInterface => common/src/test/resources/META-INF/services/io.helidon.common.ServiceInterface} (79%) delete mode 100644 common/service-loader/pom.xml delete mode 100644 common/service-loader/src/main/java/io/helidon/common/serviceloader/package-info.java diff --git a/CHANGELOG.md b/CHANGELOG.md index b7a5c051b2b..dfd9fb601d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,3 +18,5 @@ We are pleased to announce Helidon 4.0.0 a major release that includes significa ### Notable Changes - Java 19 (with Loom support) as the minimal Java version +- Using System.Logger instead of java util logging (incremental change) +- `HelidonServiceLoader` is now part of `helidon-common` module diff --git a/README.md b/README.md index 2116d4b2589..aa9328a0053 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,11 @@ Helidon supports two programming models: In either case your application is just a Java SE program. +## Early access branch +This branch requires Java 19 early access release with Loom support. +Applications written using this version will require `--enable-preview` to be used when starting JVM. +Kindly use latest official release to work with Java 17, unless you are interested in the newest and greatest! + ## License Helidon is available under Apache License 2.0. diff --git a/bom/pom.xml b/bom/pom.xml index a66436771b9..50cd58edc55 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -606,11 +606,6 @@ helidon-common-key-util ${helidon.version} - - io.helidon.common - helidon-common-service-loader - ${helidon.version} - io.helidon.common helidon-common-media-type diff --git a/common/common/pom.xml b/common/common/pom.xml index 76f00987f22..8cb3f963133 100644 --- a/common/common/pom.xml +++ b/common/common/pom.xml @@ -28,6 +28,24 @@ helidon-common Helidon Common + + + + jakarta.annotation + jakarta.annotation-api + + + org.junit.jupiter + junit-jupiter-api + test + + + org.hamcrest + hamcrest-all + test + + + @@ -71,17 +89,4 @@ - - - - org.junit.jupiter - junit-jupiter-api - test - - - org.hamcrest - hamcrest-all - test - - diff --git a/common/service-loader/src/main/java/io/helidon/common/serviceloader/HelidonServiceLoader.java b/common/common/src/main/java/io/helidon/common/HelidonServiceLoader.java similarity index 98% rename from common/service-loader/src/main/java/io/helidon/common/serviceloader/HelidonServiceLoader.java rename to common/common/src/main/java/io/helidon/common/HelidonServiceLoader.java index 49a7008579b..e702bf300fc 100644 --- a/common/service-loader/src/main/java/io/helidon/common/serviceloader/HelidonServiceLoader.java +++ b/common/common/src/main/java/io/helidon/common/HelidonServiceLoader.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.common.serviceloader; +package io.helidon.common; import java.lang.System.Logger.Level; import java.util.Collections; @@ -27,8 +27,6 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -import io.helidon.common.Prioritized; - /** * Helidon specific support for Java Service Loaders. *

@@ -77,7 +75,7 @@ public final class HelidonServiceLoader implements Iterable { /** * System property used to exclude some implementation from the list of services that are configured for Java Service - * loader or services that are registered using {@link io.helidon.common.serviceloader.HelidonServiceLoader.Builder}. + * loader or services that are registered using {@link HelidonServiceLoader.Builder}. */ public static final String SYSTEM_PROPERTY_EXCLUDE = "io.helidon.common.serviceloader.exclude"; @@ -133,7 +131,7 @@ public List asList() { } /** - * Fluent api builder for {@link io.helidon.common.serviceloader.HelidonServiceLoader}. + * Fluent api builder for {@link HelidonServiceLoader}. * * @param type of the service to be loaded */ diff --git a/common/service-loader/src/main/java/io/helidon/common/serviceloader/Priorities.java b/common/common/src/main/java/io/helidon/common/Priorities.java similarity index 97% rename from common/service-loader/src/main/java/io/helidon/common/serviceloader/Priorities.java rename to common/common/src/main/java/io/helidon/common/Priorities.java index 677a6e3f3bb..f0746c5d3a2 100644 --- a/common/service-loader/src/main/java/io/helidon/common/serviceloader/Priorities.java +++ b/common/common/src/main/java/io/helidon/common/Priorities.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.common.serviceloader; +package io.helidon.common; import java.util.Comparator; import java.util.List; diff --git a/common/service-loader/src/main/java/module-info.java b/common/common/src/main/java/io/helidon/common/Weight.java similarity index 50% rename from common/service-loader/src/main/java/module-info.java rename to common/common/src/main/java/io/helidon/common/Weight.java index f2101b7829a..70a9573dea1 100644 --- a/common/service-loader/src/main/java/module-info.java +++ b/common/common/src/main/java/io/helidon/common/Weight.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,27 @@ * limitations under the License. */ +package io.helidon.common; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + /** - * Helidon Common Service Loader. + * Annotation that can define a type weight. + * The higher the weight, the more important this type is. + * + * @see Weighted + * @see Weights */ -module io.helidon.common.serviceloader { - requires java.logging; - requires io.helidon.common; - requires jakarta.annotation; - - exports io.helidon.common.serviceloader; +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface Weight { + /** + * Weight of this type. + * + * @return weight + */ + double value(); } diff --git a/common/common/src/main/java/io/helidon/common/Weighted.java b/common/common/src/main/java/io/helidon/common/Weighted.java new file mode 100644 index 00000000000..e68bab11d23 --- /dev/null +++ b/common/common/src/main/java/io/helidon/common/Weighted.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. + * + * 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 io.helidon.common; + +/** + * Interface to define that this class is a class with weight. + * One of the uses is for services loaded by a ServiceLoader. + *

+ * A {@code Weighted} with higher weight is more significant than a {@code Weighted} with a + * lower weight. + *

+ * For cases where weight is the same, implementation must define ordering of such {@code Weighted}. + *

+ * Negative weights are not allowed and services using weight should throw an + * {@link IllegalArgumentException} if such a weight is used (unless such a service + * documents the specific usage of a negative weight) + *

+ * A {@code Weighted} with weight {@code 2} is more significant (will be returned before) weight {@code 1}. + */ +public interface Weighted extends Comparable { + /** + * Default weight for any weighted component (whether it implements this interface + * or uses {@link Weight} annotation). + */ + double DEFAULT_WEIGHT = 100; + + /** + * Weight of this class (maybe because it is defined + * dynamically, so it cannot be defined by an annotation). + * If not dynamic, you can use the {@code Weight} + * annotation rather than implementing this interface as long as + * it is supported by the library using this {@code Weighted}. + * + * @return the weight of this service, must be a non-negative number + */ + default double weight() { + return DEFAULT_WEIGHT; + } + + @Override + default int compareTo(Weighted o) { + return Double.compare(o.weight(), this.weight()); + } +} diff --git a/common/common/src/main/java/io/helidon/common/Weights.java b/common/common/src/main/java/io/helidon/common/Weights.java new file mode 100644 index 00000000000..6cd38340e8d --- /dev/null +++ b/common/common/src/main/java/io/helidon/common/Weights.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. + * + * 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 io.helidon.common; + +import java.util.Comparator; +import java.util.List; + +/** + * Weight utilities. + */ +public final class Weights { + private Weights() { + } + + /** + * Find weight from class annotation, or return default if none found. + * + * @param aClass class to analyzed + * @param defaultWeight default weight of this class + * @return weight from {@link Weight} or the default provided + */ + public static double find(Class aClass, double defaultWeight) { + Weight weightAnnot = aClass.getAnnotation(Weight.class); + if (null != weightAnnot) { + return weightAnnot.value(); + } + + return defaultWeight; + } + + /** + * Find weight for an instance. + * First checks if instance is {@link io.helidon.common.Weighted}. If so, + * uses the value from it. + * Then checks for {@link Weight} annotation. + * If none of the above is found, returns the default weight. + * + * @param anObject object to find weight for + * @param defaultWeight default weight to use + * @return weight of the object or default provided + */ + public static double find(Object anObject, double defaultWeight) { + if (anObject instanceof Class) { + return find((Class) anObject, defaultWeight); + } + if (anObject instanceof Weighted) { + return ((Weighted) anObject).weight(); + } + Weight weight = null; + // first go through super classes + Class current = anObject.getClass(); + while (weight == null) { + weight = current.getAnnotation(Weight.class); + current = current.getSuperclass(); + if (current.equals(Object.class)) { + break; + } + } + if (weight == null) { + // then through interfaces (only first level) + Class[] interfaces = anObject.getClass().getInterfaces(); + for (Class anInterface : interfaces) { + weight = anInterface.getAnnotation(Weight.class); + if (weight != null) { + break; + } + } + } + + if (weight == null) { + return defaultWeight; + } + return weight.value(); + } + + /** + * Sort the list based on weights. + *

    + *
  • If element implements {@link io.helidon.common.Weighted}, uses its weight.
  • + *
  • If element is a class and has annotation {@link Weight}, uses its weight
  • + *
  • If element is any object and its class has annotation {@link Weight}, uses its weight
  • + *
+ * + * @param list list to sort + */ + public static void sort(List list) { + list.sort(weightComparator()); + } + + /** + * Returns a comparator for two objects, the classes for which are implementations of + * {@link io.helidon.common.Weighted}, and/or optionally annotated with {@link Weight} + * and which applies a specified default weight if either or both classes lack the annotation. + * + * @param type of object being compared + * @return comparator + */ + public static Comparator weightComparator() { + return (o1, o2) -> { + if (o1 == null) { + return o2 == null ? 0 : 1; + } + if (o2 == null) { + return -1; + } + + double firstWeight = find(o1, -101); + double secondWeight = find(o2, -101); + + if (firstWeight != -101 && secondWeight != -101) { + // both are weighted + if (firstWeight != secondWeight) { + // only return if they differ + return Double.compare(secondWeight, firstWeight); + } + } + + if (firstWeight != -101 && secondWeight != -101) { + return o1.getClass().getName().compareTo(o2.getClass().getName()); + } + + // both are non-null and at least one of them is NOT weighted + if (firstWeight != -101) { + return -1; + } + if (secondWeight != -101) { + return 1; + } + + // compare class names + int result = o1.getClass().getName().compareTo(o2.getClass().getName()); + if (result != 0) { + return result; + } + + // same class, same weight, compare to string (if same, then we consider it to be the same) + return o1.toString().compareTo(o2.toString()); + }; + } +} diff --git a/common/common/src/main/java/module-info.java b/common/common/src/main/java/module-info.java index 7da97db5664..cdc2fb1a5b0 100644 --- a/common/common/src/main/java/module-info.java +++ b/common/common/src/main/java/module-info.java @@ -20,6 +20,7 @@ module io.helidon.common { // used only by LogConfig requires java.logging; + requires jakarta.annotation; exports io.helidon.common; } diff --git a/common/service-loader/src/test/java/io/helidon/common/serviceloader/HelidonServiceLoaderTest.java b/common/common/src/test/java/io/helidon/common/HelidonServiceLoaderTest.java similarity index 96% rename from common/service-loader/src/test/java/io/helidon/common/serviceloader/HelidonServiceLoaderTest.java rename to common/common/src/test/java/io/helidon/common/HelidonServiceLoaderTest.java index 60d68cd9f5e..245c55f4dc6 100644 --- a/common/service-loader/src/test/java/io/helidon/common/serviceloader/HelidonServiceLoaderTest.java +++ b/common/common/src/test/java/io/helidon/common/HelidonServiceLoaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.helidon.common.serviceloader; +package io.helidon.common; import java.util.List; import java.util.ServiceLoader; @@ -28,7 +28,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; /** - * Unit test for {@link io.helidon.common.serviceloader.HelidonServiceLoader}. + * Unit test for {@link HelidonServiceLoader}. */ class HelidonServiceLoaderTest { private static ServiceLoader javaLoader; diff --git a/common/service-loader/src/test/java/io/helidon/common/serviceloader/PrioritiesTest.java b/common/common/src/test/java/io/helidon/common/PrioritiesTest.java similarity index 96% rename from common/service-loader/src/test/java/io/helidon/common/serviceloader/PrioritiesTest.java rename to common/common/src/test/java/io/helidon/common/PrioritiesTest.java index 9dc2078c947..7174ec3f961 100644 --- a/common/service-loader/src/test/java/io/helidon/common/serviceloader/PrioritiesTest.java +++ b/common/common/src/test/java/io/helidon/common/PrioritiesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,13 +14,11 @@ * limitations under the License. */ -package io.helidon.common.serviceloader; +package io.helidon.common; import java.util.ArrayList; import java.util.List; -import io.helidon.common.Prioritized; - import jakarta.annotation.Priority; import org.junit.jupiter.api.Test; diff --git a/common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceImpl1.java b/common/common/src/test/java/io/helidon/common/ServiceImpl1.java similarity index 88% rename from common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceImpl1.java rename to common/common/src/test/java/io/helidon/common/ServiceImpl1.java index 70181682165..b47797ad3c9 100644 --- a/common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceImpl1.java +++ b/common/common/src/test/java/io/helidon/common/ServiceImpl1.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.common.serviceloader; +package io.helidon.common; import jakarta.annotation.Priority; diff --git a/common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceImpl2.java b/common/common/src/test/java/io/helidon/common/ServiceImpl2.java similarity index 88% rename from common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceImpl2.java rename to common/common/src/test/java/io/helidon/common/ServiceImpl2.java index b9d5458868c..155965eec3b 100644 --- a/common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceImpl2.java +++ b/common/common/src/test/java/io/helidon/common/ServiceImpl2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,9 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.common.serviceloader; - -import io.helidon.common.Prioritized; +package io.helidon.common; /** * A service implementation. diff --git a/common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceImpl3.java b/common/common/src/test/java/io/helidon/common/ServiceImpl3.java similarity index 88% rename from common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceImpl3.java rename to common/common/src/test/java/io/helidon/common/ServiceImpl3.java index 9c64299af7d..64c1f96edea 100644 --- a/common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceImpl3.java +++ b/common/common/src/test/java/io/helidon/common/ServiceImpl3.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.common.serviceloader; +package io.helidon.common; import jakarta.annotation.Priority; diff --git a/common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceInterface.java b/common/common/src/test/java/io/helidon/common/ServiceInterface.java similarity index 87% rename from common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceInterface.java rename to common/common/src/test/java/io/helidon/common/ServiceInterface.java index 8e37733e87c..9c02ce54ac7 100644 --- a/common/service-loader/src/test/java/io/helidon/common/serviceloader/ServiceInterface.java +++ b/common/common/src/test/java/io/helidon/common/ServiceInterface.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.common.serviceloader; +package io.helidon.common; /** * Testing Java Service loader service interface. diff --git a/common/service-loader/src/test/resources/META-INF/services/io.helidon.common.serviceloader.ServiceInterface b/common/common/src/test/resources/META-INF/services/io.helidon.common.ServiceInterface similarity index 79% rename from common/service-loader/src/test/resources/META-INF/services/io.helidon.common.serviceloader.ServiceInterface rename to common/common/src/test/resources/META-INF/services/io.helidon.common.ServiceInterface index 3810cc56b04..230b30366a0 100644 --- a/common/service-loader/src/test/resources/META-INF/services/io.helidon.common.serviceloader.ServiceInterface +++ b/common/common/src/test/resources/META-INF/services/io.helidon.common.ServiceInterface @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 Oracle and/or its affiliates. +# Copyright (c) 2019, 2022 Oracle and/or its affiliates. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,5 +14,5 @@ # limitations under the License. # -io.helidon.common.serviceloader.ServiceImpl1 -io.helidon.common.serviceloader.ServiceImpl2 +io.helidon.common.ServiceImpl1 +io.helidon.common.ServiceImpl2 diff --git a/common/configurable/pom.xml b/common/configurable/pom.xml index 7c160b1ff59..04e78e5aa3e 100644 --- a/common/configurable/pom.xml +++ b/common/configurable/pom.xml @@ -58,10 +58,6 @@ provided true
- - io.helidon.common - helidon-common-service-loader - io.helidon.bundles helidon-bundles-config diff --git a/common/context/pom.xml b/common/context/pom.xml index 5378b25ab1f..b446c837ee1 100644 --- a/common/context/pom.xml +++ b/common/context/pom.xml @@ -42,9 +42,5 @@ hamcrest-all test - - io.helidon.common - helidon-common-service-loader - diff --git a/common/context/src/main/java/io/helidon/common/context/ContextAwareExecutorImpl.java b/common/context/src/main/java/io/helidon/common/context/ContextAwareExecutorImpl.java index 141e63d8bc3..e91b82cb6b6 100644 --- a/common/context/src/main/java/io/helidon/common/context/ContextAwareExecutorImpl.java +++ b/common/context/src/main/java/io/helidon/common/context/ContextAwareExecutorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ import java.util.stream.Collectors; import io.helidon.common.context.spi.DataPropagationProvider; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; class ContextAwareExecutorImpl implements ContextAwareExecutorService { diff --git a/common/context/src/main/java/module-info.java b/common/context/src/main/java/module-info.java index f46114f8384..95f35d56e0a 100644 --- a/common/context/src/main/java/module-info.java +++ b/common/context/src/main/java/module-info.java @@ -19,7 +19,6 @@ */ module io.helidon.common.context { requires io.helidon.common; - requires io.helidon.common.serviceloader; exports io.helidon.common.context; exports io.helidon.common.context.spi; diff --git a/common/mapper/pom.xml b/common/mapper/pom.xml index 91dab1528b6..b43e74ad2a1 100644 --- a/common/mapper/pom.xml +++ b/common/mapper/pom.xml @@ -37,10 +37,6 @@ io.helidon.common helidon-common - - io.helidon.common - helidon-common-service-loader - org.junit.jupiter junit-jupiter-api diff --git a/common/mapper/src/main/java/io/helidon/common/mapper/MapperManager.java b/common/mapper/src/main/java/io/helidon/common/mapper/MapperManager.java index 6dd8cf566f3..9d4b2e5b97e 100644 --- a/common/mapper/src/main/java/io/helidon/common/mapper/MapperManager.java +++ b/common/mapper/src/main/java/io/helidon/common/mapper/MapperManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import io.helidon.common.GenericType; import io.helidon.common.Prioritized; import io.helidon.common.mapper.spi.MapperProvider; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; /** * Mapper manager of all configured mappers. @@ -140,8 +140,8 @@ private Builder mapperProviders(HelidonServiceLoader serviceLoad *

* If the same provider implementation would be loaded by Java Service loader, the service loader instance is ignored. * If you need to add a new implementation of the same type, please use the full features - * of the {@link io.helidon.common.serviceloader.HelidonServiceLoader} and invoke - * {@link MapperManager#create(io.helidon.common.serviceloader.HelidonServiceLoader)}. + * of the {@link io.helidon.common.HelidonServiceLoader} and invoke + * {@link MapperManager#create(io.helidon.common.HelidonServiceLoader)}. * * @param provider prioritized mapper provider to use * @return updated builder instance @@ -156,7 +156,7 @@ public Builder addMapperProvider(MapperProvider provider) { * from system service loader with a custom priority. * * @param provider a mapper provider instance - * @param priority priority of the provider (see {@link io.helidon.common.serviceloader.HelidonServiceLoader} + * @param priority priority of the provider (see {@link io.helidon.common.HelidonServiceLoader} * documentation for details about priority handling) * @return updated builder instance * @see #addMapperProvider(io.helidon.common.mapper.spi.MapperProvider) diff --git a/common/mapper/src/main/java/module-info.java b/common/mapper/src/main/java/module-info.java index d24a20055b7..0f540e3fbc3 100644 --- a/common/mapper/src/main/java/module-info.java +++ b/common/mapper/src/main/java/module-info.java @@ -19,7 +19,6 @@ */ module io.helidon.common.mapper { requires transitive io.helidon.common; - requires transitive io.helidon.common.serviceloader; exports io.helidon.common.mapper; exports io.helidon.common.mapper.spi; diff --git a/common/mapper/src/test/java/io/helidon/common/mapper/MapperManagerTest.java b/common/mapper/src/test/java/io/helidon/common/mapper/MapperManagerTest.java index 429091fe52a..71dc5a38f9d 100644 --- a/common/mapper/src/test/java/io/helidon/common/mapper/MapperManagerTest.java +++ b/common/mapper/src/test/java/io/helidon/common/mapper/MapperManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import io.helidon.common.GenericType; import io.helidon.common.mapper.spi.MapperProvider; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import org.junit.jupiter.api.Test; diff --git a/common/media-type/pom.xml b/common/media-type/pom.xml index ebeb2154d93..2b235dd9de1 100644 --- a/common/media-type/pom.xml +++ b/common/media-type/pom.xml @@ -30,7 +30,7 @@ io.helidon.common - helidon-common-service-loader + helidon-common org.junit.jupiter diff --git a/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java b/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java index b2041d58be6..c6892059c44 100644 --- a/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java +++ b/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java @@ -23,8 +23,8 @@ import java.util.ServiceLoader; import java.util.concurrent.ConcurrentHashMap; +import io.helidon.common.HelidonServiceLoader; import io.helidon.common.media.type.spi.MediaTypeDetector; -import io.helidon.common.serviceloader.HelidonServiceLoader; /** * Media type detection based on a resource. diff --git a/common/media-type/src/main/java/module-info.java b/common/media-type/src/main/java/module-info.java index 6d33fe547ce..8bcfd815e57 100644 --- a/common/media-type/src/main/java/module-info.java +++ b/common/media-type/src/main/java/module-info.java @@ -18,7 +18,7 @@ * Helidon Common Media Type. */ module io.helidon.common.media.type { - requires io.helidon.common.serviceloader; + requires io.helidon.common; exports io.helidon.common.media.type; exports io.helidon.common.media.type.spi; diff --git a/common/pom.xml b/common/pom.xml index b444eb0c8e8..813c4ddadd6 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -36,7 +36,6 @@ configurable key-util http - service-loader context mapper media-type diff --git a/common/service-loader/pom.xml b/common/service-loader/pom.xml deleted file mode 100644 index 23ee44709f1..00000000000 --- a/common/service-loader/pom.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - - helidon-common-project - io.helidon.common - 4.0.0-SNAPSHOT - - 4.0.0 - - helidon-common-service-loader - Helidon Common Service Loader - - - Service loader utilities to extend functionality of - Java Service loader. - - - - - io.helidon.common - helidon-common - - - jakarta.annotation - jakarta.annotation-api - - - org.junit.jupiter - junit-jupiter-api - test - - - org.hamcrest - hamcrest-all - test - - - org.mockito - mockito-core - test - - - diff --git a/common/service-loader/src/main/java/io/helidon/common/serviceloader/package-info.java b/common/service-loader/src/main/java/io/helidon/common/serviceloader/package-info.java deleted file mode 100644 index 480fa4baa6e..00000000000 --- a/common/service-loader/src/main/java/io/helidon/common/serviceloader/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. - * - * 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. - */ -/** - * Java Service loader extension. - */ -package io.helidon.common.serviceloader; diff --git a/config/config-mp/pom.xml b/config/config-mp/pom.xml index 3649441b757..1932673a7ab 100644 --- a/config/config-mp/pom.xml +++ b/config/config-mp/pom.xml @@ -42,10 +42,6 @@ io.helidon.common helidon-common - - io.helidon.common - helidon-common-service-loader - io.helidon.config helidon-config diff --git a/config/config-mp/src/main/java/io/helidon/config/mp/MpConfigBuilder.java b/config/config-mp/src/main/java/io/helidon/config/mp/MpConfigBuilder.java index f2787e4bbb4..fc7c66f83ee 100644 --- a/config/config-mp/src/main/java/io/helidon/config/mp/MpConfigBuilder.java +++ b/config/config-mp/src/main/java/io/helidon/config/mp/MpConfigBuilder.java @@ -59,8 +59,8 @@ import java.util.regex.Pattern; import io.helidon.common.Builder; -import io.helidon.common.serviceloader.HelidonServiceLoader; -import io.helidon.common.serviceloader.Priorities; +import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.Priorities; import io.helidon.config.ConfigException; import io.helidon.config.ConfigMappers; import io.helidon.config.ConfigValue; diff --git a/config/config-mp/src/main/java/io/helidon/config/mp/MpHelidonSource.java b/config/config-mp/src/main/java/io/helidon/config/mp/MpHelidonSource.java index cb319a02598..20e6eb48ff1 100644 --- a/config/config-mp/src/main/java/io/helidon/config/mp/MpHelidonSource.java +++ b/config/config-mp/src/main/java/io/helidon/config/mp/MpHelidonSource.java @@ -23,7 +23,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.ConfigException; import io.helidon.config.ConfigHelper; import io.helidon.config.spi.ConfigContent; diff --git a/config/config-mp/src/main/java/module-info.java b/config/config-mp/src/main/java/module-info.java index 6bc7bc51b4d..fe58f813a29 100644 --- a/config/config-mp/src/main/java/module-info.java +++ b/config/config-mp/src/main/java/module-info.java @@ -23,7 +23,6 @@ requires io.helidon.config; requires transitive microprofile.config.api; requires jakarta.annotation; - requires io.helidon.common.serviceloader; requires static io.helidon.config.metadata; exports io.helidon.config.mp; diff --git a/config/config/src/main/java/io/helidon/config/BuilderImpl.java b/config/config/src/main/java/io/helidon/config/BuilderImpl.java index 92c0cd2bedc..76f620e3b27 100644 --- a/config/config/src/main/java/io/helidon/config/BuilderImpl.java +++ b/config/config/src/main/java/io/helidon/config/BuilderImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,8 +33,8 @@ import io.helidon.common.GenericType; import io.helidon.common.Prioritized; -import io.helidon.common.serviceloader.HelidonServiceLoader; -import io.helidon.common.serviceloader.Priorities; +import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.Priorities; import io.helidon.config.ConfigMapperManager.MapperProviders; import io.helidon.config.spi.ConfigContext; import io.helidon.config.spi.ConfigFilter; diff --git a/config/config/src/main/java/io/helidon/config/MetaConfig.java b/config/config/src/main/java/io/helidon/config/MetaConfig.java index 18242394dab..299547a5796 100644 --- a/config/config/src/main/java/io/helidon/config/MetaConfig.java +++ b/config/config/src/main/java/io/helidon/config/MetaConfig.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import java.util.function.Function; import java.util.logging.Logger; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.spi.ChangeWatcher; import io.helidon.config.spi.ConfigParser; import io.helidon.config.spi.ConfigSource; diff --git a/config/config/src/main/java/io/helidon/config/MetaProviders.java b/config/config/src/main/java/io/helidon/config/MetaProviders.java index a077a85bd96..7c0e3dadec0 100644 --- a/config/config/src/main/java/io/helidon/config/MetaProviders.java +++ b/config/config/src/main/java/io/helidon/config/MetaProviders.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import java.util.Set; import java.util.function.Function; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.spi.ChangeWatcher; import io.helidon.config.spi.ChangeWatcherProvider; import io.helidon.config.spi.ConfigSource; diff --git a/config/config/src/main/java/module-info.java b/config/config/src/main/java/module-info.java index c22bf89aee9..65f0efe11b3 100644 --- a/config/config/src/main/java/module-info.java +++ b/config/config/src/main/java/module-info.java @@ -30,8 +30,6 @@ requires transitive io.helidon.common; requires transitive io.helidon.common.media.type; - requires io.helidon.common.serviceloader; - exports io.helidon.config; exports io.helidon.config.spi; diff --git a/dbclient/dbclient/pom.xml b/dbclient/dbclient/pom.xml index 6128f3ece6f..6f9cd3ed0a5 100644 --- a/dbclient/dbclient/pom.xml +++ b/dbclient/dbclient/pom.xml @@ -34,10 +34,6 @@ io.helidon.config helidon-config - - io.helidon.common - helidon-common-service-loader - io.helidon.common helidon-common-context diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java index 7bd6c705d34..ce42ee6c024 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import io.helidon.common.mapper.MapperManager; import io.helidon.common.reactive.Single; import io.helidon.common.reactive.Subscribable; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.dbclient.spi.DbClientProvider; import io.helidon.dbclient.spi.DbClientProviderBuilder; diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClientProviderLoader.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClientProviderLoader.java index 1995dd90a4f..b549d52d14d 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClientProviderLoader.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClientProviderLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import java.util.Optional; import java.util.ServiceLoader; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.dbclient.spi.DbClientProvider; /** diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java index 3748643a373..b27f83b3a1b 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import io.helidon.common.GenericType; import io.helidon.common.mapper.MapperException; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.dbclient.spi.DbMapperProvider; /** @@ -60,7 +60,7 @@ static DbMapperManager create() { } /** - * Create a new mapper manager from customized {@link io.helidon.common.serviceloader.HelidonServiceLoader}. + * Create a new mapper manager from customized {@link io.helidon.common.HelidonServiceLoader}. * * @param serviceLoader service loader to use to read all {@link io.helidon.dbclient.spi.DbMapperProvider} * @return mapper manager diff --git a/dbclient/dbclient/src/main/java/module-info.java b/dbclient/dbclient/src/main/java/module-info.java index c4763cb8339..e3d5ea6ed66 100644 --- a/dbclient/dbclient/src/main/java/module-info.java +++ b/dbclient/dbclient/src/main/java/module-info.java @@ -26,7 +26,6 @@ requires transitive io.helidon.common.context; requires transitive io.helidon.common.mapper; requires transitive io.helidon.common.reactive; - requires transitive io.helidon.common.serviceloader; exports io.helidon.dbclient; exports io.helidon.dbclient.spi; diff --git a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/ConnectionPool.java b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/ConnectionPool.java index 03990b42a86..d6e02c8a291 100644 --- a/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/ConnectionPool.java +++ b/dbclient/jdbc/src/main/java/io/helidon/dbclient/jdbc/ConnectionPool.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.dbclient.jdbc.spi.HikariCpExtensionProvider; diff --git a/etc/HELIDON_THIRD_PARTY_LICENSES.xml b/etc/HELIDON_THIRD_PARTY_LICENSES.xml index a3a4f358941..761148728c1 100644 --- a/etc/HELIDON_THIRD_PARTY_LICENSES.xml +++ b/etc/HELIDON_THIRD_PARTY_LICENSES.xml @@ -1355,7 +1355,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Eclipse Public License 2.0 + GPL v.2 with CPE helidon-bundles-config - helidon-common-service-loader helidon-config helidon-config-hocon helidon-config-mp diff --git a/integrations/vault/cdi/src/main/java/io/helidon/integrations/vault/cdi/VaultCdiExtension.java b/integrations/vault/cdi/src/main/java/io/helidon/integrations/vault/cdi/VaultCdiExtension.java index 8066e1ceafb..7b716955875 100644 --- a/integrations/vault/cdi/src/main/java/io/helidon/integrations/vault/cdi/VaultCdiExtension.java +++ b/integrations/vault/cdi/src/main/java/io/helidon/integrations/vault/cdi/VaultCdiExtension.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import java.util.ServiceLoader; import java.util.Set; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.integrations.vault.Vault; import io.helidon.integrations.vault.spi.InjectionProvider; diff --git a/integrations/vault/cdi/src/main/java/module-info.java b/integrations/vault/cdi/src/main/java/module-info.java index 1f1566063db..4a5ebad038d 100644 --- a/integrations/vault/cdi/src/main/java/module-info.java +++ b/integrations/vault/cdi/src/main/java/module-info.java @@ -29,7 +29,6 @@ requires microprofile.config.api; requires io.helidon.integrations.vault; - requires io.helidon.common.serviceloader; requires io.helidon.microprofile.cdi; exports io.helidon.integrations.vault.cdi; diff --git a/integrations/vault/vault/pom.xml b/integrations/vault/vault/pom.xml index 631b5ef1d76..7592f4b7c07 100644 --- a/integrations/vault/vault/pom.xml +++ b/integrations/vault/vault/pom.xml @@ -35,10 +35,6 @@ io.helidon.common helidon-common - - io.helidon.common - helidon-common-service-loader - io.helidon.integrations.common helidon-integrations-common-rest diff --git a/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/Vault.java b/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/Vault.java index dcc753e2b28..5b57864a7fa 100644 --- a/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/Vault.java +++ b/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/Vault.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import java.util.logging.Logger; import io.helidon.common.http.Http; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.faulttolerance.FaultTolerance; import io.helidon.faulttolerance.FtHandler; diff --git a/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/VaultImpl.java b/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/VaultImpl.java index 7b3dac188cf..69db52766bc 100644 --- a/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/VaultImpl.java +++ b/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/VaultImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import java.util.logging.Logger; import io.helidon.common.LazyValue; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.integrations.common.rest.RestApi; import io.helidon.integrations.vault.spi.AuthMethodProvider; diff --git a/integrations/vault/vault/src/main/java/module-info.java b/integrations/vault/vault/src/main/java/module-info.java index 297d9e8adfb..459305f6be0 100644 --- a/integrations/vault/vault/src/main/java/module-info.java +++ b/integrations/vault/vault/src/main/java/module-info.java @@ -27,7 +27,6 @@ requires io.helidon.webclient; requires io.helidon.media.jsonp; requires io.helidon.faulttolerance; - requires io.helidon.common.serviceloader; requires io.helidon.integrations.common.rest; exports io.helidon.integrations.vault; diff --git a/logging/common/pom.xml b/logging/common/pom.xml index 976cae817d8..4028a80c2dd 100644 --- a/logging/common/pom.xml +++ b/logging/common/pom.xml @@ -30,8 +30,7 @@ io.helidon.common - helidon-common-service-loader + helidon-common - diff --git a/logging/common/src/main/java/io/helidon/logging/common/HelidonMdc.java b/logging/common/src/main/java/io/helidon/logging/common/HelidonMdc.java index d0936e9609d..c0a56a4f30e 100644 --- a/logging/common/src/main/java/io/helidon/logging/common/HelidonMdc.java +++ b/logging/common/src/main/java/io/helidon/logging/common/HelidonMdc.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import java.util.Optional; import java.util.ServiceLoader; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.logging.common.spi.MdcProvider; /** diff --git a/logging/common/src/main/java/module-info.java b/logging/common/src/main/java/module-info.java index 9a3a1fc1d35..592ac4815fb 100644 --- a/logging/common/src/main/java/module-info.java +++ b/logging/common/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ * Helidon logging. */ module io.helidon.logging.common { - requires io.helidon.common.serviceloader; + requires io.helidon.common; exports io.helidon.logging.common; exports io.helidon.logging.common.spi; diff --git a/logging/log4j/src/main/resources/META-INF/native-image/io.helidon.logging/helidon-logging-log4j/native-image.properties b/logging/log4j/src/main/resources/META-INF/native-image/io.helidon.logging/helidon-logging-log4j/native-image.properties index 87dd3480919..0480ffc97f9 100644 --- a/logging/log4j/src/main/resources/META-INF/native-image/io.helidon.logging/helidon-logging-log4j/native-image.properties +++ b/logging/log4j/src/main/resources/META-INF/native-image/io.helidon.logging/helidon-logging-log4j/native-image.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2020 Oracle and/or its affiliates. +# Copyright (c) 2020, 2022 Oracle and/or its affiliates. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -120,9 +120,7 @@ Args=-Dlog4j2.disable.jmx=true \ --initialize-at-build-time=org.apache.logging.slf4j.Log4jLoggerFactory \ --initialize-at-build-time=org.apache.logging.log4j.spi.ThreadContextMapFactory \ --initialize-at-build-time=org.apache.logging.log4j.spi.GarbageFreeSortedArrayThreadContextMap \ - --initialize-at-build-time=io.helidon.common.serviceloader.HelidonServiceLoader \ --initialize-at-build-time=org.apache.logging.log4j.core.util.ClockFactory \ - --initialize-at-build-time=io.helidon.common.serviceloader.HelidonServiceLoader$Builder$ServiceWithPriority \ --initialize-at-build-time=org.apache.logging.log4j.spi.Provider \ --initialize-at-build-time=org.apache.logging.log4j.jul.ApiLogger \ --initialize-at-build-time=org.apache.logging.log4j.jul.CoreLogger \ diff --git a/media/common/src/main/java/io/helidon/media/common/MediaContext.java b/media/common/src/main/java/io/helidon/media/common/MediaContext.java index ad9034a8931..742a414b018 100644 --- a/media/common/src/main/java/io/helidon/media/common/MediaContext.java +++ b/media/common/src/main/java/io/helidon/media/common/MediaContext.java @@ -24,7 +24,7 @@ import java.util.ServiceLoader; import java.util.stream.Collectors; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.config.ConfigSources; import io.helidon.config.metadata.Configured; diff --git a/metrics/api/pom.xml b/metrics/api/pom.xml index 4f610377cc7..fd3e88b49e3 100644 --- a/metrics/api/pom.xml +++ b/metrics/api/pom.xml @@ -33,10 +33,6 @@ - - io.helidon.common - helidon-common-service-loader - io.helidon.common helidon-common-http diff --git a/metrics/api/src/main/java/io/helidon/metrics/api/RegistryFactoryManager.java b/metrics/api/src/main/java/io/helidon/metrics/api/RegistryFactoryManager.java index 8c52fd7ff68..7410bc9d2eb 100644 --- a/metrics/api/src/main/java/io/helidon/metrics/api/RegistryFactoryManager.java +++ b/metrics/api/src/main/java/io/helidon/metrics/api/RegistryFactoryManager.java @@ -23,7 +23,7 @@ import java.util.logging.Logger; import io.helidon.common.LazyValue; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.metrics.api.spi.RegistryFactoryProvider; diff --git a/metrics/api/src/main/java/module-info.java b/metrics/api/src/main/java/module-info.java index 8a4df8d9a7f..8c71ad29e38 100644 --- a/metrics/api/src/main/java/module-info.java +++ b/metrics/api/src/main/java/module-info.java @@ -24,7 +24,6 @@ requires java.logging; requires io.helidon.common.http; - requires io.helidon.common.serviceloader; requires transitive io.helidon.config; requires transitive microprofile.metrics.api; diff --git a/metrics/metrics/pom.xml b/metrics/metrics/pom.xml index 5be381b0a1e..1412af15207 100644 --- a/metrics/metrics/pom.xml +++ b/metrics/metrics/pom.xml @@ -42,10 +42,6 @@ io.helidon.common helidon-common - - io.helidon.common - helidon-common-service-loader - io.helidon.common helidon-common-configurable diff --git a/metrics/metrics/src/main/java/io/helidon/metrics/ExemplarServiceManager.java b/metrics/metrics/src/main/java/io/helidon/metrics/ExemplarServiceManager.java index 065b7e3bcd2..cfdc5e5e4e3 100644 --- a/metrics/metrics/src/main/java/io/helidon/metrics/ExemplarServiceManager.java +++ b/metrics/metrics/src/main/java/io/helidon/metrics/ExemplarServiceManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import java.util.logging.Level; import java.util.logging.Logger; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; /** * Loads the {@link ExemplarService} instance (if any) with the most urgent priority. diff --git a/metrics/metrics/src/main/java/module-info.java b/metrics/metrics/src/main/java/module-info.java index bfccc176041..a446924379d 100644 --- a/metrics/metrics/src/main/java/module-info.java +++ b/metrics/metrics/src/main/java/module-info.java @@ -20,7 +20,6 @@ requires java.logging; requires io.helidon.common; - requires io.helidon.common.serviceloader; requires io.helidon.webserver.cors; requires transitive io.helidon.metrics.api; requires transitive io.helidon.metrics.serviceapi; diff --git a/metrics/service-api/src/main/java/io/helidon/metrics/serviceapi/MetricsSupportManager.java b/metrics/service-api/src/main/java/io/helidon/metrics/serviceapi/MetricsSupportManager.java index 0c89c47673e..9dbdc2e8f2a 100644 --- a/metrics/service-api/src/main/java/io/helidon/metrics/serviceapi/MetricsSupportManager.java +++ b/metrics/service-api/src/main/java/io/helidon/metrics/serviceapi/MetricsSupportManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import java.util.logging.Logger; import io.helidon.common.LazyValue; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.metrics.api.MetricsSettings; import io.helidon.metrics.serviceapi.spi.MetricsSupportProvider; import io.helidon.servicecommon.rest.RestServiceSettings; diff --git a/metrics/service-api/src/main/java/module-info.java b/metrics/service-api/src/main/java/module-info.java index 82a768eea9b..77c4a60f061 100644 --- a/metrics/service-api/src/main/java/module-info.java +++ b/metrics/service-api/src/main/java/module-info.java @@ -20,7 +20,6 @@ requires java.logging; - requires io.helidon.common.serviceloader; requires io.helidon.webserver; requires io.helidon.config.metadata; requires io.helidon.servicecommon.rest; diff --git a/microprofile/config/src/main/java/module-info.java b/microprofile/config/src/main/java/module-info.java index 9a02e8ac82f..6a1672a446b 100644 --- a/microprofile/config/src/main/java/module-info.java +++ b/microprofile/config/src/main/java/module-info.java @@ -28,7 +28,6 @@ requires transitive microprofile.config.api; requires io.helidon.config.mp; requires jakarta.annotation; - requires io.helidon.common.serviceloader; exports io.helidon.microprofile.config; diff --git a/microprofile/grpc/core/pom.xml b/microprofile/grpc/core/pom.xml index ac4aaaca41c..b93e9047ce2 100644 --- a/microprofile/grpc/core/pom.xml +++ b/microprofile/grpc/core/pom.xml @@ -43,10 +43,6 @@ jakarta.enterprise.cdi-api provided - - io.helidon.common - helidon-common-service-loader - io.helidon.microprofile.config helidon-microprofile-config diff --git a/microprofile/grpc/core/src/main/java/io/helidon/microprofile/grpc/core/AbstractServiceBuilder.java b/microprofile/grpc/core/src/main/java/io/helidon/microprofile/grpc/core/AbstractServiceBuilder.java index 2050834900a..deaf6055c15 100644 --- a/microprofile/grpc/core/src/main/java/io/helidon/microprofile/grpc/core/AbstractServiceBuilder.java +++ b/microprofile/grpc/core/src/main/java/io/helidon/microprofile/grpc/core/AbstractServiceBuilder.java @@ -29,7 +29,7 @@ import java.util.logging.Level; import java.util.logging.Logger; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.grpc.core.MarshallerSupplier; import jakarta.annotation.Priority; diff --git a/microprofile/grpc/core/src/main/java/module-info.java b/microprofile/grpc/core/src/main/java/module-info.java index bd347001df2..177c7bbf778 100644 --- a/microprofile/grpc/core/src/main/java/module-info.java +++ b/microprofile/grpc/core/src/main/java/module-info.java @@ -23,7 +23,6 @@ requires transitive io.helidon.grpc.core; requires transitive io.helidon.grpc.client; requires transitive io.helidon.microprofile.config; - requires io.helidon.common.serviceloader; requires transitive jakarta.cdi; diff --git a/microprofile/grpc/metrics/pom.xml b/microprofile/grpc/metrics/pom.xml index 0801c163509..29e350c70a2 100644 --- a/microprofile/grpc/metrics/pom.xml +++ b/microprofile/grpc/metrics/pom.xml @@ -42,10 +42,6 @@ io.helidon.microprofile.grpc helidon-microprofile-grpc-server - - io.helidon.common - helidon-common-service-loader - io.helidon.microprofile.metrics helidon-microprofile-metrics diff --git a/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/AnnotatedServiceConfigurer.java b/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/AnnotatedServiceConfigurer.java index 500f9d4cf67..079aeefde72 100644 --- a/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/AnnotatedServiceConfigurer.java +++ b/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/AnnotatedServiceConfigurer.java @@ -25,7 +25,7 @@ * Implementations of this class are called by the {@link GrpcServiceBuilder} when * it builds a {@link ServiceDescriptor} from an annotated class. Instances of * {@link AnnotatedServiceConfigurer} are discovered using the - * {@link io.helidon.common.serviceloader.HelidonServiceLoader}. This service + * {@link io.helidon.common.HelidonServiceLoader}. This service * loader supports ordering of configurers. */ @FunctionalInterface diff --git a/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServerCdiExtension.java b/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServerCdiExtension.java index 9d02652808d..0025f3bf3b8 100644 --- a/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServerCdiExtension.java +++ b/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServerCdiExtension.java @@ -25,7 +25,7 @@ import java.util.logging.Level; import java.util.logging.Logger; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.config.mp.MpConfig; import io.helidon.grpc.server.GrpcRouting; diff --git a/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServiceBuilder.java b/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServiceBuilder.java index 057a4323b72..f778cc36fcd 100644 --- a/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServiceBuilder.java +++ b/microprofile/grpc/server/src/main/java/io/helidon/microprofile/grpc/server/GrpcServiceBuilder.java @@ -30,7 +30,7 @@ import java.util.stream.Collectors; import io.helidon.common.Builder; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.grpc.core.ContextKeys; import io.helidon.grpc.core.MethodHandler; import io.helidon.grpc.server.MethodDescriptor; diff --git a/microprofile/grpc/server/src/main/java/module-info.java b/microprofile/grpc/server/src/main/java/module-info.java index e1c48e2fee9..dfc4ce0cdb2 100644 --- a/microprofile/grpc/server/src/main/java/module-info.java +++ b/microprofile/grpc/server/src/main/java/module-info.java @@ -23,7 +23,6 @@ requires transitive io.helidon.grpc.server; requires transitive io.helidon.microprofile.grpc.core; - requires io.helidon.common.serviceloader; requires io.helidon.microprofile.server; requires io.helidon.config.mp; diff --git a/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCdiExtension.java b/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCdiExtension.java index aaeaa483056..ddc5014c7d0 100644 --- a/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCdiExtension.java +++ b/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCdiExtension.java @@ -24,7 +24,7 @@ import java.util.logging.Logger; import java.util.stream.Collectors; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.health.HealthSupport; import io.helidon.health.common.BuiltInHealthCheck; diff --git a/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCheckProvider.java b/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCheckProvider.java index 6d653e30bd5..4e566e295b3 100644 --- a/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCheckProvider.java +++ b/microprofile/health/src/main/java/io/helidon/microprofile/health/HealthCheckProvider.java @@ -25,7 +25,7 @@ * A provider of {@link HealthCheck} instances. *

* Instances of {@link HealthCheckProvider} are discovered by the {@link io.helidon.microprofile.health.HealthCdiExtension} - * using the {@link io.helidon.common.serviceloader.HelidonServiceLoader} and all of the + * using the {@link io.helidon.common.HelidonServiceLoader} and all of the * {@link HealthCheck} instances are added to the health endpoint. */ public interface HealthCheckProvider { diff --git a/microprofile/health/src/main/java/module-info.java b/microprofile/health/src/main/java/module-info.java index 4009805a534..983896419b4 100644 --- a/microprofile/health/src/main/java/module-info.java +++ b/microprofile/health/src/main/java/module-info.java @@ -24,7 +24,6 @@ requires java.management; requires io.helidon.common; - requires io.helidon.common.serviceloader; requires io.helidon.health; requires io.helidon.health.common; requires io.helidon.servicecommon.restcdi; diff --git a/microprofile/lra/jax-rs/pom.xml b/microprofile/lra/jax-rs/pom.xml index 0698d3ab78d..dcb3a4b7b26 100644 --- a/microprofile/lra/jax-rs/pom.xml +++ b/microprofile/lra/jax-rs/pom.xml @@ -51,10 +51,6 @@ io.helidon.common helidon-common-reactive - - io.helidon.common - helidon-common-service-loader - io.helidon.jersey helidon-jersey-client diff --git a/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/CoordinatorLocatorService.java b/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/CoordinatorLocatorService.java index e7687720a11..b9648dc9aac 100644 --- a/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/CoordinatorLocatorService.java +++ b/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/CoordinatorLocatorService.java @@ -25,7 +25,7 @@ import java.util.stream.Collectors; import io.helidon.common.Reflected; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.lra.coordinator.client.CoordinatorClient; import jakarta.enterprise.context.ApplicationScoped; diff --git a/microprofile/lra/jax-rs/src/main/java/module-info.java b/microprofile/lra/jax-rs/src/main/java/module-info.java index aff48332bad..34ed2324ed3 100644 --- a/microprofile/lra/jax-rs/src/main/java/module-info.java +++ b/microprofile/lra/jax-rs/src/main/java/module-info.java @@ -33,7 +33,6 @@ requires jakarta.interceptor.api; requires jersey.common; requires io.helidon.lra.coordinator.client; - requires io.helidon.common.serviceloader; uses io.helidon.lra.coordinator.client.CoordinatorClient; diff --git a/microprofile/metrics/pom.xml b/microprofile/metrics/pom.xml index d0fff4a8422..01717d2f804 100644 --- a/microprofile/metrics/pom.xml +++ b/microprofile/metrics/pom.xml @@ -69,10 +69,6 @@ io.helidon.metrics helidon-metrics-service-api - - io.helidon.common - helidon-common-service-loader - io.helidon.metrics helidon-metrics diff --git a/microprofile/metrics/src/main/java/module-info.java b/microprofile/metrics/src/main/java/module-info.java index a5d4de4a3fa..88b604c4306 100644 --- a/microprofile/metrics/src/main/java/module-info.java +++ b/microprofile/metrics/src/main/java/module-info.java @@ -31,9 +31,9 @@ requires io.helidon.servicecommon.restcdi; requires io.helidon.microprofile.server; requires io.helidon.microprofile.config; - requires io.helidon.common.serviceloader; requires transitive io.helidon.metrics.api; requires transitive io.helidon.metrics.serviceapi; + requires io.helidon.webserver; requires transitive microprofile.config.api; requires microprofile.metrics.api; diff --git a/microprofile/server/pom.xml b/microprofile/server/pom.xml index 40dae1304ac..603d6140229 100644 --- a/microprofile/server/pom.xml +++ b/microprofile/server/pom.xml @@ -60,10 +60,6 @@ io.helidon.webserver helidon-webserver-jersey - - io.helidon.common - helidon-common-service-loader - jakarta.interceptor jakarta.interceptor-api diff --git a/microprofile/server/src/main/java/module-info.java b/microprofile/server/src/main/java/module-info.java index a04662a4c50..cd424c8d76e 100644 --- a/microprofile/server/src/main/java/module-info.java +++ b/microprofile/server/src/main/java/module-info.java @@ -35,7 +35,6 @@ requires io.helidon.jersey.media.jsonp; requires java.logging; - requires io.helidon.common.serviceloader; requires io.helidon.webserver.staticcontent; // there is now a hardcoded dependency on Weld, to configure additional bean defining annotation diff --git a/security/abac/policy/src/main/java/io/helidon/security/abac/policy/PolicyValidator.java b/security/abac/policy/src/main/java/io/helidon/security/abac/policy/PolicyValidator.java index 3fecb691b17..8e0177c690c 100644 --- a/security/abac/policy/src/main/java/io/helidon/security/abac/policy/PolicyValidator.java +++ b/security/abac/policy/src/main/java/io/helidon/security/abac/policy/PolicyValidator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ import java.util.logging.Logger; import io.helidon.common.Errors; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.security.EndpointConfig; import io.helidon.security.ProviderRequest; diff --git a/security/abac/policy/src/main/java/module-info.java b/security/abac/policy/src/main/java/module-info.java index 00511f96172..bdfcaf7d691 100644 --- a/security/abac/policy/src/main/java/module-info.java +++ b/security/abac/policy/src/main/java/module-info.java @@ -20,7 +20,6 @@ module io.helidon.security.abac.policy { requires io.helidon.security.providers.abac; requires java.logging; - requires io.helidon.common.serviceloader; exports io.helidon.security.abac.policy; exports io.helidon.security.abac.policy.spi; diff --git a/security/integration/jersey-client/src/main/java/module-info.java b/security/integration/jersey-client/src/main/java/module-info.java index 426431c6f90..55d1b1431ae 100644 --- a/security/integration/jersey-client/src/main/java/module-info.java +++ b/security/integration/jersey-client/src/main/java/module-info.java @@ -24,7 +24,7 @@ requires transitive io.helidon.security; requires transitive io.helidon.security.providers.common; requires transitive io.helidon.security.util; - requires transitive io.helidon.common.serviceloader; + requires transitive jakarta.ws.rs; requires io.helidon.common.context; diff --git a/security/integration/jersey/pom.xml b/security/integration/jersey/pom.xml index 12e17589721..15942bf733e 100644 --- a/security/integration/jersey/pom.xml +++ b/security/integration/jersey/pom.xml @@ -58,10 +58,6 @@ io.helidon.jersey helidon-jersey-common - - io.helidon.common - helidon-common-service-loader - jakarta.ws.rs jakarta.ws.rs-api diff --git a/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecurityFilter.java b/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecurityFilter.java index 2e64ee77d1e..b49a99a40cf 100644 --- a/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecurityFilter.java +++ b/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecurityFilter.java @@ -28,7 +28,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.logging.Logger; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.jersey.common.InvokedResource; import io.helidon.security.AuditEvent; diff --git a/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecurityFilterCommon.java b/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecurityFilterCommon.java index bc1e5dc25ef..f42f9873dd1 100644 --- a/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecurityFilterCommon.java +++ b/security/integration/jersey/src/main/java/io/helidon/security/integration/jersey/SecurityFilterCommon.java @@ -22,7 +22,7 @@ import java.util.ServiceLoader; import java.util.logging.Logger; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.security.AuthenticationResponse; import io.helidon.security.AuthorizationResponse; diff --git a/security/integration/jersey/src/main/java/module-info.java b/security/integration/jersey/src/main/java/module-info.java index 2b33c65847e..75e7e426090 100644 --- a/security/integration/jersey/src/main/java/module-info.java +++ b/security/integration/jersey/src/main/java/module-info.java @@ -25,7 +25,6 @@ requires transitive io.helidon.security.annotations; requires transitive io.helidon.security.providers.common; requires transitive io.helidon.security.util; - requires transitive io.helidon.common.serviceloader; requires transitive jakarta.ws.rs; requires io.helidon.common.context; diff --git a/security/providers/abac/src/main/java/io/helidon/security/providers/abac/AbacProvider.java b/security/providers/abac/src/main/java/io/helidon/security/providers/abac/AbacProvider.java index a6ee33727fe..2179a12492e 100644 --- a/security/providers/abac/src/main/java/io/helidon/security/providers/abac/AbacProvider.java +++ b/security/providers/abac/src/main/java/io/helidon/security/providers/abac/AbacProvider.java @@ -30,7 +30,7 @@ import java.util.stream.Collectors; import io.helidon.common.Errors; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.config.metadata.Configured; import io.helidon.config.metadata.ConfiguredOption; diff --git a/security/providers/abac/src/main/java/module-info.java b/security/providers/abac/src/main/java/module-info.java index 202ded295b2..dc4bfd52acc 100644 --- a/security/providers/abac/src/main/java/module-info.java +++ b/security/providers/abac/src/main/java/module-info.java @@ -21,7 +21,6 @@ requires transitive io.helidon.config; requires transitive io.helidon.common; requires transitive io.helidon.security; - requires io.helidon.common.serviceloader; requires static io.helidon.config.metadata; exports io.helidon.security.providers.abac; diff --git a/security/providers/http-auth/src/main/java/io/helidon/security/providers/httpauth/HttpBasicAuthProvider.java b/security/providers/http-auth/src/main/java/io/helidon/security/providers/httpauth/HttpBasicAuthProvider.java index 78ecee57e70..a2998332440 100644 --- a/security/providers/http-auth/src/main/java/io/helidon/security/providers/httpauth/HttpBasicAuthProvider.java +++ b/security/providers/http-auth/src/main/java/io/helidon/security/providers/httpauth/HttpBasicAuthProvider.java @@ -28,7 +28,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.config.metadata.Configured; import io.helidon.config.metadata.ConfiguredOption; diff --git a/security/providers/http-auth/src/main/java/module-info.java b/security/providers/http-auth/src/main/java/module-info.java index 70dd08169f3..c3db95a2255 100644 --- a/security/providers/http-auth/src/main/java/module-info.java +++ b/security/providers/http-auth/src/main/java/module-info.java @@ -20,7 +20,6 @@ module io.helidon.security.providers.httpauth { requires io.helidon.config; requires io.helidon.common; - requires io.helidon.common.serviceloader; requires io.helidon.security; requires io.helidon.security.providers.common; requires io.helidon.security.util; diff --git a/security/security/src/main/java/io/helidon/security/Security.java b/security/security/src/main/java/io/helidon/security/Security.java index 3b55487d49e..fd3bcd85425 100644 --- a/security/security/src/main/java/io/helidon/security/Security.java +++ b/security/security/src/main/java/io/helidon/security/Security.java @@ -40,7 +40,7 @@ import io.helidon.common.configurable.ThreadPoolSupplier; import io.helidon.common.reactive.Single; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.config.ConfigValue; import io.helidon.config.metadata.Configured; diff --git a/security/security/src/main/java/module-info.java b/security/security/src/main/java/module-info.java index 9866e5a0734..908cd58d077 100644 --- a/security/security/src/main/java/module-info.java +++ b/security/security/src/main/java/module-info.java @@ -33,7 +33,6 @@ requires io.helidon.security.util; requires io.helidon.common.context; - requires io.helidon.common.serviceloader; exports io.helidon.security; exports io.helidon.security.spi; diff --git a/tracing/jersey-client/src/main/java/io/helidon/tracing/jersey/client/ClientTracingFilter.java b/tracing/jersey-client/src/main/java/io/helidon/tracing/jersey/client/ClientTracingFilter.java index c70f58331cf..781e5459c6f 100644 --- a/tracing/jersey-client/src/main/java/io/helidon/tracing/jersey/client/ClientTracingFilter.java +++ b/tracing/jersey-client/src/main/java/io/helidon/tracing/jersey/client/ClientTracingFilter.java @@ -25,7 +25,7 @@ import java.util.ServiceLoader; import io.helidon.common.context.Contexts; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.tracing.HeaderConsumer; import io.helidon.tracing.HeaderProvider; import io.helidon.tracing.Scope; diff --git a/tracing/jersey-client/src/main/java/module-info.java b/tracing/jersey-client/src/main/java/module-info.java index ceec17112ab..4d256f662d9 100644 --- a/tracing/jersey-client/src/main/java/module-info.java +++ b/tracing/jersey-client/src/main/java/module-info.java @@ -32,7 +32,6 @@ requires io.helidon.common; requires io.helidon.common.context; requires io.helidon.webclient.jaxrs; - requires io.helidon.common.serviceloader; exports io.helidon.tracing.jersey.client; diff --git a/tracing/opentracing/pom.xml b/tracing/opentracing/pom.xml index 8e2a81181a5..253d79a5531 100644 --- a/tracing/opentracing/pom.xml +++ b/tracing/opentracing/pom.xml @@ -51,10 +51,6 @@ io.opentracing opentracing-util - - io.helidon.common - helidon-common-service-loader - io.helidon.config helidon-config-metadata diff --git a/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingProviderHelper.java b/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingProviderHelper.java index 746c130d555..412fbe81afb 100644 --- a/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingProviderHelper.java +++ b/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingProviderHelper.java @@ -17,7 +17,7 @@ import java.util.ServiceLoader; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.tracing.opentracing.spi.OpenTracingProvider; /** diff --git a/tracing/opentracing/src/main/java/module-info.java b/tracing/opentracing/src/main/java/module-info.java index d01fe5e4151..6b1473718c1 100644 --- a/tracing/opentracing/src/main/java/module-info.java +++ b/tracing/opentracing/src/main/java/module-info.java @@ -27,7 +27,6 @@ requires io.opentracing.util; requires io.opentracing.api; requires io.opentracing.noop; - requires io.helidon.common.serviceloader; uses io.helidon.tracing.opentracing.spi.OpenTracingProvider; provides io.helidon.tracing.spi.TracerProvider with io.helidon.tracing.opentracing.OpenTracingTracerProvider; diff --git a/tracing/tracing/pom.xml b/tracing/tracing/pom.xml index 4387d137579..617dc83961b 100644 --- a/tracing/tracing/pom.xml +++ b/tracing/tracing/pom.xml @@ -41,10 +41,6 @@ io.helidon.common helidon-common - - io.helidon.common - helidon-common-service-loader - io.helidon.config helidon-config diff --git a/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java b/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java index 3fd01aa0720..33b870817dd 100644 --- a/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java +++ b/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java @@ -19,7 +19,7 @@ import java.util.Optional; import java.util.ServiceLoader; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.tracing.spi.TracerProvider; /** diff --git a/tracing/tracing/src/main/java/module-info.java b/tracing/tracing/src/main/java/module-info.java index 18ac0fbda1c..396c47741d0 100644 --- a/tracing/tracing/src/main/java/module-info.java +++ b/tracing/tracing/src/main/java/module-info.java @@ -21,7 +21,6 @@ */ module io.helidon.tracing { requires io.helidon.common; - requires io.helidon.common.serviceloader; requires io.helidon.config; requires static io.helidon.config.metadata; diff --git a/webclient/webclient/src/main/java/io/helidon/webclient/WebClient.java b/webclient/webclient/src/main/java/io/helidon/webclient/WebClient.java index 53b3b187d18..ddba365b4f2 100644 --- a/webclient/webclient/src/main/java/io/helidon/webclient/WebClient.java +++ b/webclient/webclient/src/main/java/io/helidon/webclient/WebClient.java @@ -28,7 +28,7 @@ import io.helidon.common.context.Context; import io.helidon.common.http.Http; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.media.common.MediaContext; import io.helidon.media.common.MediaContextBuilder; diff --git a/webclient/webclient/src/main/java/io/helidon/webclient/WebClientRequestBuilderImpl.java b/webclient/webclient/src/main/java/io/helidon/webclient/WebClientRequestBuilderImpl.java index 45d4a459043..799ae0b740a 100644 --- a/webclient/webclient/src/main/java/io/helidon/webclient/WebClientRequestBuilderImpl.java +++ b/webclient/webclient/src/main/java/io/helidon/webclient/WebClientRequestBuilderImpl.java @@ -54,7 +54,7 @@ import io.helidon.common.http.MediaType; import io.helidon.common.http.Parameters; import io.helidon.common.reactive.Single; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.media.common.MessageBodyReadableContent; import io.helidon.media.common.MessageBodyReaderContext; import io.helidon.media.common.MessageBodyWriterContext; diff --git a/webclient/webclient/src/main/java/module-info.java b/webclient/webclient/src/main/java/module-info.java index 6b4f86f2e50..c435328323d 100644 --- a/webclient/webclient/src/main/java/module-info.java +++ b/webclient/webclient/src/main/java/module-info.java @@ -28,7 +28,6 @@ requires transitive io.helidon.config; requires transitive io.helidon.media.common; requires io.helidon.common.pki; - requires io.helidon.common.serviceloader; requires io.netty.buffer; requires io.netty.codec; diff --git a/webserver/webserver/src/main/java/io/helidon/webserver/UpgradeManager.java b/webserver/webserver/src/main/java/io/helidon/webserver/UpgradeManager.java index d82d74ff439..ea3b5d9f7ab 100644 --- a/webserver/webserver/src/main/java/io/helidon/webserver/UpgradeManager.java +++ b/webserver/webserver/src/main/java/io/helidon/webserver/UpgradeManager.java @@ -23,7 +23,7 @@ import java.util.ServiceLoader; import java.util.function.Function; -import io.helidon.common.serviceloader.HelidonServiceLoader; +import io.helidon.common.HelidonServiceLoader; import io.helidon.webserver.spi.UpgradeCodecProvider; import io.netty.channel.ChannelHandler; From b95303bed02172db54050b43dc718a61c5e144d4 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Tue, 9 Aug 2022 18:08:49 +0200 Subject: [PATCH 4/9] GeneritType now contains constant for String --- .../java/io/helidon/common/GenericType.java | 7 +++++- .../io/helidon/common/GenericTypeTest.java | 4 ++-- .../common/mapper/MapperManagerTest.java | 24 +++++++++---------- .../common/mapper/ServiceLoaderMapper2.java | 7 +++--- .../io/helidon/security/jwt/JwtHeaders.java | 3 +-- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/common/common/src/main/java/io/helidon/common/GenericType.java b/common/common/src/main/java/io/helidon/common/GenericType.java index c6dd03265ce..6f2596d2a33 100644 --- a/common/common/src/main/java/io/helidon/common/GenericType.java +++ b/common/common/src/main/java/io/helidon/common/GenericType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,6 +62,11 @@ * @param the generic type parameter */ public class GenericType implements Type { + /** + * Generic type for String. + */ + public static final GenericType STRING = GenericType.create(String.class); + private final Type type; private final Class rawType; diff --git a/common/common/src/test/java/io/helidon/common/GenericTypeTest.java b/common/common/src/test/java/io/helidon/common/GenericTypeTest.java index 83820079b9f..86e60886104 100644 --- a/common/common/src/test/java/io/helidon/common/GenericTypeTest.java +++ b/common/common/src/test/java/io/helidon/common/GenericTypeTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ void testNoTypeArguments() { @Test void testIsClass() { - GenericType type = new GenericType(){}; + GenericType type = GenericType.STRING; assertThat(type.isClass(), is(true)); GenericType> type2 = new GenericType>(){}; diff --git a/common/mapper/src/test/java/io/helidon/common/mapper/MapperManagerTest.java b/common/mapper/src/test/java/io/helidon/common/mapper/MapperManagerTest.java index 71dc5a38f9d..ab65781ef66 100644 --- a/common/mapper/src/test/java/io/helidon/common/mapper/MapperManagerTest.java +++ b/common/mapper/src/test/java/io/helidon/common/mapper/MapperManagerTest.java @@ -42,11 +42,11 @@ void testUsingServiceLoader() { assertThat(result, is(10)); // using generic types - result = mm.map(source, ServiceLoaderMapper2.STRING_TYPE, ServiceLoaderMapper2.INTEGER_TYPE); + result = mm.map(source, GenericType.STRING, ServiceLoaderMapper2.INTEGER_TYPE); assertThat(result, is(11)); // search for opposite (use class, find type and vice versa) - Long longResult = mm.map(source, ServiceLoaderMapper2.STRING_TYPE, GenericType.create(Long.class)); + Long longResult = mm.map(source, GenericType.STRING, GenericType.create(Long.class)); assertThat(longResult, is(10L)); // must be the same longResult = mm.map(source, String.class, Long.class); @@ -55,7 +55,7 @@ void testUsingServiceLoader() { Short shortResult = mm.map(source, String.class, Short.class); assertThat(shortResult, is((short) 10)); // must be the same - shortResult = mm.map(source, ServiceLoaderMapper2.STRING_TYPE, ServiceLoaderMapper2.SHORT_TYPE); + shortResult = mm.map(source, GenericType.STRING, ServiceLoaderMapper2.SHORT_TYPE); assertThat(shortResult, is((short) 10)); assertThrows(MapperException.class, () -> mm.map(source, String.class, Object.class)); @@ -75,18 +75,18 @@ void testUsingCustomProviders() { assertThat(result, is(10)); // using generic types - result = mm.map(source, ServiceLoaderMapper2.STRING_TYPE, ServiceLoaderMapper2.INTEGER_TYPE); + result = mm.map(source, GenericType.STRING, ServiceLoaderMapper2.INTEGER_TYPE); assertThat(result, is(10)); // search for opposite (use class, find type and vice versa) - Long longResult = mm.map(source, ServiceLoaderMapper2.STRING_TYPE, GenericType.create(Long.class)); + Long longResult = mm.map(source, GenericType.STRING, GenericType.create(Long.class)); assertThat(longResult, is(10L)); // must be the same longResult = mm.map(source, String.class, Long.class); assertThat(longResult, is(10L)); assertThrows(MapperException.class, () -> mm.map(source, String.class, Short.class)); - assertThrows(MapperException.class, () -> mm.map(source, ServiceLoaderMapper2.STRING_TYPE, + assertThrows(MapperException.class, () -> mm.map(source, GenericType.STRING, ServiceLoaderMapper2.SHORT_TYPE)); assertThrows(MapperException.class, () -> mm.map(source, String.class, Object.class)); } @@ -95,7 +95,7 @@ void testUsingCustomProviders() { void testUsingServiceLoaderAndCustomMappers() { MapperManager mm = MapperManager.builder() .addMapper(String::valueOf, Integer.class, String.class) - .addMapper(String::valueOf, ServiceLoaderMapper2.SHORT_TYPE, ServiceLoaderMapper2.STRING_TYPE) + .addMapper(String::valueOf, ServiceLoaderMapper2.SHORT_TYPE, GenericType.STRING) .build(); String source = "10"; @@ -104,11 +104,11 @@ void testUsingServiceLoaderAndCustomMappers() { assertThat(result, is(10)); // using generic types - result = mm.map(source, ServiceLoaderMapper2.STRING_TYPE, ServiceLoaderMapper2.INTEGER_TYPE); + result = mm.map(source, GenericType.STRING, ServiceLoaderMapper2.INTEGER_TYPE); assertThat(result, is(11)); // search for opposite (use class, find type and vice versa) - Long longResult = mm.map(source, ServiceLoaderMapper2.STRING_TYPE, GenericType.create(Long.class)); + Long longResult = mm.map(source, GenericType.STRING, GenericType.create(Long.class)); assertThat(longResult, is(10L)); // must be the same longResult = mm.map(source, String.class, Long.class); @@ -117,7 +117,7 @@ void testUsingServiceLoaderAndCustomMappers() { Short shortResult = mm.map(source, String.class, Short.class); assertThat(shortResult, is((short) 10)); // must be the same - shortResult = mm.map(source, ServiceLoaderMapper2.STRING_TYPE, ServiceLoaderMapper2.SHORT_TYPE); + shortResult = mm.map(source, GenericType.STRING, ServiceLoaderMapper2.SHORT_TYPE); assertThat(shortResult, is((short) 10)); assertThrows(MapperException.class, () -> mm.map(source, String.class, Object.class)); @@ -125,12 +125,12 @@ void testUsingServiceLoaderAndCustomMappers() { // and add tests for integer and short types String stringResult = mm.map(42, Integer.class, String.class); assertThat(stringResult, is("42")); - stringResult = mm.map(42, GenericType.create(Integer.class), ServiceLoaderMapper2.STRING_TYPE); + stringResult = mm.map(42, GenericType.create(Integer.class), GenericType.STRING); assertThat(stringResult, is("42")); stringResult = mm.map((short)42, Short.class, String.class); assertThat(stringResult, is("42")); - stringResult = mm.map((short)42, ServiceLoaderMapper2.SHORT_TYPE, ServiceLoaderMapper2.STRING_TYPE); + stringResult = mm.map((short)42, ServiceLoaderMapper2.SHORT_TYPE, GenericType.STRING); assertThat(stringResult, is("42")); } } \ No newline at end of file diff --git a/common/mapper/src/test/java/io/helidon/common/mapper/ServiceLoaderMapper2.java b/common/mapper/src/test/java/io/helidon/common/mapper/ServiceLoaderMapper2.java index 8c809ba3f09..96eea7a3840 100644 --- a/common/mapper/src/test/java/io/helidon/common/mapper/ServiceLoaderMapper2.java +++ b/common/mapper/src/test/java/io/helidon/common/mapper/ServiceLoaderMapper2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,6 @@ * Maps String to Integer, and String to Short using type. */ public class ServiceLoaderMapper2 implements MapperProvider { - static final GenericType STRING_TYPE = GenericType.create(String.class); static final GenericType INTEGER_TYPE = GenericType.create(Integer.class); static final GenericType SHORT_TYPE = GenericType.create(Short.class); @@ -35,11 +34,11 @@ public class ServiceLoaderMapper2 implements MapperProvider { @Override public Optional> mapper(GenericType sourceType, GenericType targetType) { - if (sourceType.equals(STRING_TYPE) && targetType.equals(INTEGER_TYPE)) { + if (sourceType.equals(GenericType.STRING) && targetType.equals(INTEGER_TYPE)) { return Optional.of(string -> Integer.parseInt((String)string) + 1); } - if (sourceType.equals(STRING_TYPE) && targetType.equals(SHORT_TYPE)) { + if (sourceType.equals(GenericType.STRING) && targetType.equals(SHORT_TYPE)) { return Optional.of(string -> Short.parseShort((String)string)); } return Optional.empty(); diff --git a/security/jwt/src/main/java/io/helidon/security/jwt/JwtHeaders.java b/security/jwt/src/main/java/io/helidon/security/jwt/JwtHeaders.java index 9e3185596d9..662254ce3ad 100644 --- a/security/jwt/src/main/java/io/helidon/security/jwt/JwtHeaders.java +++ b/security/jwt/src/main/java/io/helidon/security/jwt/JwtHeaders.java @@ -230,7 +230,6 @@ public Optional> audience() { */ public static class Builder implements io.helidon.common.Builder { private static final GenericType> STRING_LIST_TYPE = new GenericType>() { }; - private static final GenericType STRING_TYPE = GenericType.create(String.class); private static final Map> KNOWN_HEADER_CLAIMS; private static final KnownField TYPE_FIELD = KnownField.create("typ", Builder::type); @@ -487,7 +486,7 @@ private KnownField(String name, } static KnownField create(String name, BiConsumer valueConsumer) { - return new KnownField<>(name, Builder.STRING_TYPE, valueConsumer, KnownField::jsonToString); + return new KnownField<>(name, GenericType.STRING, valueConsumer, KnownField::jsonToString); } private static String jsonToString(JsonValue jsonValue) { From 34c70cf931bceb0e78b00e1dab53aa61d7fb04c2 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Tue, 9 Aug 2022 18:08:54 +0200 Subject: [PATCH 5/9] Typo fix --- common/common/src/main/java/io/helidon/common/Builder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/common/src/main/java/io/helidon/common/Builder.java b/common/common/src/main/java/io/helidon/common/Builder.java index 01d4674a777..3a1c65d23cd 100644 --- a/common/common/src/main/java/io/helidon/common/Builder.java +++ b/common/common/src/main/java/io/helidon/common/Builder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ public interface Builder, T> extends Supplier { T build(); /** - * Update the builder in a fluen API way. + * Update the builder in a fluent API way. * * @param consumer consumer of the builder instance * @return updated builder instance From 5c49b8d62fedf4b48bcf697a891f82b560912952 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Wed, 10 Aug 2022 02:03:40 +0200 Subject: [PATCH 6/9] Using Weight instead of Priority in SE --- CHANGELOG.md | 6 +- common/common/pom.xml | 10 +- .../helidon/common/HelidonServiceLoader.java | 165 +++++++++--------- common/common/src/main/java/module-info.java | 1 - .../common/HelidonServiceLoaderTest.java | 4 +- .../java/io/helidon/common/ServiceImpl1.java | 4 +- .../java/io/helidon/common/ServiceImpl2.java | 6 +- .../java/io/helidon/common/ServiceImpl3.java | 4 +- common/configurable/etc/spotbugs/exclude.xml | 4 +- .../context/ContextAwareExecutorImpl.java | 2 +- .../helidon/common/mapper/MapperManager.java | 26 +-- .../helidon/common/media/type/MediaTypes.java | 4 +- .../io/helidon/config/mp/MpConfigBuilder.java | 4 +- ...nvironmentVariablesMetaConfigProvider.java | 1 - .../mp/MpPropertiesMetaConfigProvider.java | 1 - .../MpSystemPropertiesMetaConfigProvider.java | 1 - .../io/helidon/config/mp}/Priorities.java | 10 +- .../io/helidon/config/mp}/Prioritized.java | 4 +- .../io/helidon/config/mp}/PrioritiesTest.java | 2 +- .../java/io/helidon/config/BuilderImpl.java | 65 ++++--- .../java/io/helidon/config/MetaProviders.java | 13 +- .../config/PropertiesConfigParser.java | 20 ++- .../io/helidon/config/spi/ConfigParser.java | 10 +- .../hocon/mp/HoconMpMetaConfigProvider.java | 2 +- .../config/hocon/HoconConfigParser.java | 10 +- .../ObjectConfigMapperProvider.java | 7 +- .../Mappers1ConfigMapperProvider.java | 8 +- ...ppers2Priority100ConfigMapperProvider.java | 8 +- ...ppers2Priority150ConfigMapperProvider.java | 8 +- ...appers2Priority50ConfigMapperProvider.java | 8 +- .../Parsers1Priority100ConfigParser.java | 10 +- .../Parsers1Priority300ConfigParser.java | 9 +- .../yaml/mp/YamlMetaConfigProvider.java | 2 +- .../helidon/config/yaml/YamlConfigParser.java | 13 +- .../io/helidon/config/yaml/package-info.java | 4 +- .../jsonp/JsonProcessingMapperProvider.java | 8 +- .../io/helidon/grpc/core/PriorityBag.java | 14 +- .../io/helidon/grpc/core/PriorityBagTest.java | 21 +-- .../vault/cdi/src/main/java/module-info.java | 2 +- .../vault/src/main/java/module-info.java | 2 +- .../io/helidon/media/common/MediaContext.java | 16 +- .../metrics/api/RegistryFactoryManager.java | 4 +- metrics/api/src/main/java/module-info.java | 2 +- .../serviceapi/MetricsSupportManager.java | 4 +- .../src/main/java/module-info.java | 2 +- .../jwt/auth/JwtAuthAnnotationAnalyzer.java | 8 +- .../server/ServerCdiExtension.java | 2 +- .../policy/src/main/java/module-info.java | 2 +- .../abac/role/RoleAnnotationAnalyzer.java | 8 +- .../src/main/java/module-info.java | 2 +- .../integration/jersey/AnalyzerUnitOne.java | 7 +- .../integration/jersey/AnalyzerUnitTwo.java | 7 +- .../abac/src/main/java/module-info.java | 2 +- .../common/spi/AnnotationAnalyzer.java | 2 +- .../vault/ConfigVaultProviderService.java | 10 +- .../java/io/helidon/security/Security.java | 2 +- .../tracing/jaeger/JaegerTracerProvider.java | 6 +- .../OpenTelemetryTracerProvider.java | 6 +- .../OpenTracingProviderHelper.java | 2 +- .../OpenTracingTracerProvider.java | 6 +- .../TracerResolverProvider.java | 7 +- .../helidon/tracing/TracerProviderHelper.java | 2 +- .../tracing/zipkin/ZipkinTracerProvider.java | 6 +- .../java/io/helidon/webclient/WebClient.java | 2 +- .../WebClientRequestBuilderImpl.java | 2 +- 65 files changed, 303 insertions(+), 319 deletions(-) rename {common/common/src/main/java/io/helidon/common => config/config-mp/src/main/java/io/helidon/config/mp}/Priorities.java (91%) rename {common/common/src/main/java/io/helidon/common => config/config-mp/src/main/java/io/helidon/config/mp}/Prioritized.java (95%) rename {common/common/src/test/java/io/helidon/common => config/config-mp/src/test/java/io/helidon/config/mp}/PrioritiesTest.java (99%) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfd9fb601d2..9df7f79d2fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ We are pleased to announce Helidon 4.0.0 a major release that includes significa ### Notable Changes -- Java 19 (with Loom support) as the minimal Java version +- Java 19 early access (with Loom support) as the minimal Java version - Using System.Logger instead of java util logging (incremental change) - `HelidonServiceLoader` is now part of `helidon-common` module +- Introduction of `@Weight`, `Weighted` and `Weights` instead of `@Priority` and `Prioritized`, to base ordering on a double (allows to fit a component between any other two components), all modules using priority are refactored (except for MicroProfile where required by specifications). + - higher weight means a component is more important + - moved priority related types to MP config (as that is the lowest level MP module) + - replaces all instances in SE that use priority with weight (no dependency on Jakarta, predictible and easy to understand behavior) \ No newline at end of file diff --git a/common/common/pom.xml b/common/common/pom.xml index 8cb3f963133..9db30267e14 100644 --- a/common/common/pom.xml +++ b/common/common/pom.xml @@ -28,12 +28,12 @@ helidon-common Helidon Common + + + 11 + + - - - jakarta.annotation - jakarta.annotation-api - org.junit.jupiter junit-jupiter-api diff --git a/common/common/src/main/java/io/helidon/common/HelidonServiceLoader.java b/common/common/src/main/java/io/helidon/common/HelidonServiceLoader.java index e702bf300fc..1da6fd434d1 100644 --- a/common/common/src/main/java/io/helidon/common/HelidonServiceLoader.java +++ b/common/common/src/main/java/io/helidon/common/HelidonServiceLoader.java @@ -15,9 +15,7 @@ */ package io.helidon.common; -import java.lang.System.Logger.Level; import java.util.Collections; -import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; @@ -27,46 +25,49 @@ import java.util.function.Consumer; import java.util.stream.Collectors; +import static java.lang.System.Logger.Level.TRACE; + /** * Helidon specific support for Java Service Loaders. *

* This service loader: *

    *
  • Can have additional implementations added
  • - *
  • Uses priorities defined either by {@link io.helidon.common.Prioritized} - * or by {@link jakarta.annotation.Priority}
  • + *
  • Uses weights defined either by {@link Weighted} + * or by {@link Weight}
  • *
  • Can have exclusions defined by an exact implementation class name, either - * in {@link Builder#addExcludedClass(Class)} or {@link Builder#addExcludedClassName(String)} or + * in {@link HelidonServiceLoader.Builder#addExcludedClass(Class)} or + * {@link HelidonServiceLoader.Builder#addExcludedClassName(String)} or * by a system property {@value #SYSTEM_PROPERTY_EXCLUDE} that defines * a comma separated list of fully qualified class names to be excluded. * Note that if a class implements more than one service, it would be excluded from all.
  • *
*

- * Note on priority handling + * Note on weight handling *

- * Service priority is defined by: + * Service weight is defined by: *

    - *
  • Value provided in {@link Builder#addService(Object, int)} (if used)
  • - *
  • then by {@link io.helidon.common.Prioritized#priority()} if service implements it
  • - *
  • then by {@link jakarta.annotation.Priority} annotation if present
  • - *
  • otherwise a default priority {@value Prioritized#DEFAULT_PRIORITY} from {@link Prioritized#DEFAULT_PRIORITY} is used
  • + *
  • Value provided in {@link io.helidon.common.HelidonServiceLoader.Builder#addService(Object, double)} (if used)
  • + *
  • then by {@link Weighted#weight()} if service implements it
  • + *
  • then by {@link Weight} annotation if present
  • + *
  • otherwise a default weight {@value Weighted#DEFAULT_WEIGHT} from {@link Weighted#DEFAULT_WEIGHT} is used
  • *
* Example: *
- * {@literal @}Priority(4500)
- * public class MyServiceImpl implements Service, Prioritized {
- *     public int priority() {
+ * {@literal @}Weight(4500)
+ * public class MyServiceImpl implements Service, Weighted {
+ *     public double weight() {
  *         return 6200;
  *     }
  * }
  * 
- * Such a service would have a priority of {@code 6200} as that is more significant than the annotation. + * Such a service would have a weight of {@code 6200} as that is more significant than the annotation. *

- * A service with lower priority number is returned before a service with a higher priority number. - * Services with the same priority have order defined by the order they are in the configured services + * A service with higher weight is returned before a service with a lower weight number. + * Services with the same weight have order defined by the order they are in the configured services * and then as they are loaded from the {@link java.util.ServiceLoader}. - * Negative priorities are not allowed. - * A service with priority {@code 1} will be returned before a service with priority {@code 2}. + * Negative weights are not allowed. + * A service with weight {@code 2} will be returned before a service with weight {@code 2}. * * @param Type of the service to be loaded * @see java.util.ServiceLoader @@ -75,7 +76,7 @@ public final class HelidonServiceLoader implements Iterable { /** * System property used to exclude some implementation from the list of services that are configured for Java Service - * loader or services that are registered using {@link HelidonServiceLoader.Builder}. + * loader or services that are registered using {@link io.helidon.common.HelidonServiceLoader.Builder}. */ public static final String SYSTEM_PROPERTY_EXCLUDE = "io.helidon.common.serviceloader.exclude"; @@ -83,11 +84,15 @@ public final class HelidonServiceLoader implements Iterable { private final List services; + private HelidonServiceLoader(List services) { + this.services = new LinkedList<>(services); + } + /** * Create a builder for customizable service loader. * * @param serviceLoader the Java Service loader used to get service implementations - * @param type of the service + * @param type of the service * @return a new fluent API builder */ public static Builder builder(ServiceLoader serviceLoader) { @@ -95,10 +100,10 @@ public static Builder builder(ServiceLoader serviceLoader) { } /** - * Create a prioritized service loader from a Java Service loader. + * Create a weighted service loader from a Java Service loader. * * @param serviceLoader the Java service loader - * @param type of the service + * @param type of the service * @return service loader with exclusions defined by system properties and no custom services */ public static HelidonServiceLoader create(ServiceLoader serviceLoader) { @@ -106,10 +111,6 @@ public static HelidonServiceLoader create(ServiceLoader serviceLoader) return builder.build(); } - private HelidonServiceLoader(List services) { - this.services = new LinkedList<>(services); - } - @Override public Iterator iterator() { return Collections.unmodifiableList(services) @@ -122,7 +123,7 @@ public void forEach(Consumer action) { } /** - * Provides a list of service implementations in prioritized order. + * Provides a list of service implementations in weighted order. * * @return list of service implementations */ @@ -131,18 +132,18 @@ public List asList() { } /** - * Fluent api builder for {@link HelidonServiceLoader}. + * Fluent api builder for {@link io.helidon.common.HelidonServiceLoader}. * * @param type of the service to be loaded */ public static final class Builder implements io.helidon.common.Builder, HelidonServiceLoader> { private final ServiceLoader serviceLoader; - private final List> customServices = new LinkedList>(); + private final List> customServices = new LinkedList>(); private final Set excludedServiceClasses = new HashSet<>(); private boolean useSysPropExclude = true; private boolean useSystemServiceLoader = true; private boolean replaceImplementations = true; - private int defaultPriority = Prioritized.DEFAULT_PRIORITY; + private double defaultWeight = Weighted.DEFAULT_WEIGHT; private Builder(ServiceLoader serviceLoader) { this.serviceLoader = serviceLoader; @@ -151,23 +152,23 @@ private Builder(ServiceLoader serviceLoader) { @Override public HelidonServiceLoader build() { // first merge the lists together - List> services = new LinkedList<>(customServices); + List> services = new LinkedList<>(customServices); if (useSystemServiceLoader) { Set uniqueImplementations = new HashSet<>(); if (replaceImplementations) { customServices.stream() - .map(ServiceWithPriority::instanceClassName) + .map(ServiceWithWeight::instanceClassName) .forEach(uniqueImplementations::add); } serviceLoader.forEach(service -> { if (replaceImplementations) { if (!uniqueImplementations.contains(service.getClass().getName())) { - services.add(ServiceWithPriority.createFindPriority(service, defaultPriority)); + services.add(ServiceWithWeight.createFindWeight(service, defaultWeight)); } } else { - services.add(ServiceWithPriority.createFindPriority(service, defaultPriority)); + services.add(ServiceWithWeight.createFindWeight(service, defaultWeight)); } }); } @@ -175,12 +176,12 @@ public HelidonServiceLoader build() { if (useSysPropExclude) { addSystemExcludes(); } - List> withoutExclusions = services.stream() + List> withoutExclusions = services.stream() .filter(this::notExcluded) .collect(Collectors.toList()); - // order by priority - return new HelidonServiceLoader<>(orderByPriority(withoutExclusions)); + // order by weight + return new HelidonServiceLoader<>(orderByWeight(withoutExclusions)); } /** @@ -199,7 +200,8 @@ public Builder useSystemExcludes(boolean useSysPropExclude) { /** * When configured to use Java Service loader, then the result is a combination of all service implementations - * loaded from the Java Service loader and those added by {@link #addService(Object)} or {@link #addService(Object, int)}. + * loaded from the Java Service loader and those added by {@link #addService(Object)} or + * {@link #addService(Object, double)}. * When set to {@code false} the Java Service loader is ignored. *

* This defaults to {@code true}. @@ -235,19 +237,19 @@ public Builder replaceImplementations(boolean replace) { * @return updated builder instance */ public Builder addService(T service) { - this.customServices.add(ServiceWithPriority.createFindPriority(service, defaultPriority)); + this.customServices.add(ServiceWithWeight.createFindWeight(service, defaultWeight)); return this; } /** - * Add a custom service implementation to the list of services with a custom priority. + * Add a custom service implementation to the list of services with a custom weight. * - * @param service a new service instance - * @param priority priority to use when ordering service instances + * @param service a new service instance + * @param weight weight to use when ordering service instances * @return updated builder instance */ - public Builder addService(T service, int priority) { - this.customServices.add(ServiceWithPriority.create(service, priority)); + public Builder addService(T service, double weight) { + this.customServices.add(ServiceWithWeight.create(service, weight)); return this; } @@ -276,38 +278,41 @@ public Builder addExcludedClassName(String excludeName) { } /** - * Configure default priority for services that do not have any. + * Configure default weight for services that do not have any. * - * @param defaultPriority default priority to use, defaults to {@link io.helidon.common.Prioritized#DEFAULT_PRIORITY} + * @param defaultWeight default weight to use, defaults to {@link Weighted#DEFAULT_WEIGHT} * @return updated builder instance */ - public Builder defaultPriority(int defaultPriority) { - this.defaultPriority = defaultPriority; + public Builder defaultWeight(double defaultWeight) { + this.defaultWeight = defaultWeight; return this; } - private boolean notExcluded(ServiceWithPriority service) { + private boolean notExcluded(ServiceWithWeight service) { String className = service.instance.getClass().getName(); if (excludedServiceClasses.contains(className)) { - LOGGER.log(Level.DEBUG, () -> "Excluding service implementation " + className); + if (LOGGER.isLoggable(TRACE)) { + LOGGER.log(TRACE, "Excluding service implementation " + className); + } return false; } return true; } - private List orderByPriority(List> services) { - services.sort(ServiceWithPriority.COMPARATOR); + private List orderByWeight(List> services) { + Collections.sort(services); List result = services.stream() - .map(ServiceWithPriority::instance) + .map(ServiceWithWeight::instance) .collect(Collectors.toList()); - if (LOGGER.isLoggable(Level.DEBUG)) { - LOGGER.log(Level.DEBUG, "Final order of enabled service implementations for service: " + serviceLoader); - result.stream() + if (LOGGER.isLoggable(TRACE)) { + List names = result.stream() .map(Object::getClass) .map(Class::getName) - .forEach(it -> LOGGER.log(Level.DEBUG, it)); + .collect(Collectors.toList()); + LOGGER.log(TRACE, "Final order of enabled service implementations for service: " + serviceLoader + "\n" + + String.join("\n", names)); } return result; @@ -320,40 +325,45 @@ private void addSystemExcludes() { } for (String exclude : excludes.split(",")) { - LOGGER.log(Level.DEBUG, () -> "Adding exclude from system properties: " + exclude); + if (LOGGER.isLoggable(TRACE)) { + LOGGER.log(TRACE, "Adding exclude from system properties: " + exclude); + } addExcludedClassName(exclude); } } - private static final class ServiceWithPriority { - public static final Comparator> COMPARATOR = Comparator - .comparingInt(ServiceWithPriority::priority); - + private static final class ServiceWithWeight implements Weighted { private final T instance; - private final int priority; + private final double weight; - private ServiceWithPriority(T instance, int priority) { + private ServiceWithWeight(T instance, double weight) { this.instance = instance; - this.priority = priority; + this.weight = weight; - if (priority < 0) { + if (weight < 0) { throw new IllegalArgumentException("Service: " + instance.getClass().getName() - + " declares a negative priority, which is not allowed. Priority: " - + priority); + + " declares a negative weight, which is not allowed. Weight: " + + weight); } } - private static ServiceWithPriority create(T instance, int priority) { - return new ServiceWithPriority<>(instance, priority); + @Override + public String toString() { + return instance.toString(); + } + + @Override + public double weight() { + return weight; } - private static ServiceWithPriority createFindPriority(T instance, int defaultPriority) { - return new ServiceWithPriority<>(instance, Priorities.find(instance, defaultPriority)); + private static ServiceWithWeight create(T instance, double weight) { + return new ServiceWithWeight<>(instance, weight); } - private int priority() { - return priority; + private static ServiceWithWeight createFindWeight(T instance, double defaultWeight) { + return new ServiceWithWeight<>(instance, Weights.find(instance, defaultWeight)); } private T instance() { @@ -363,11 +373,6 @@ private T instance() { private String instanceClassName() { return instance.getClass().getName(); } - - @Override - public String toString() { - return instance.toString(); - } } } } diff --git a/common/common/src/main/java/module-info.java b/common/common/src/main/java/module-info.java index cdc2fb1a5b0..7da97db5664 100644 --- a/common/common/src/main/java/module-info.java +++ b/common/common/src/main/java/module-info.java @@ -20,7 +20,6 @@ module io.helidon.common { // used only by LogConfig requires java.logging; - requires jakarta.annotation; exports io.helidon.common; } diff --git a/common/common/src/test/java/io/helidon/common/HelidonServiceLoaderTest.java b/common/common/src/test/java/io/helidon/common/HelidonServiceLoaderTest.java index 245c55f4dc6..2dc145ba733 100644 --- a/common/common/src/test/java/io/helidon/common/HelidonServiceLoaderTest.java +++ b/common/common/src/test/java/io/helidon/common/HelidonServiceLoaderTest.java @@ -63,7 +63,7 @@ void testCustomService() { @Test void testCustomServiceWithCustomPrio() { List loaded = HelidonServiceLoader.builder(javaLoader) - .addService(new ServiceImpl3(), 0) + .addService(new ServiceImpl3(), 1024) .build() .asList(); @@ -132,7 +132,7 @@ void testNoUniqueImplementations() { String TEST_STRING = "custom messsage"; List loaded = HelidonServiceLoader.builder(javaLoader) - .addService(new ServiceImpl2(TEST_STRING), 11) + .addService(new ServiceImpl2(TEST_STRING), 1024) .replaceImplementations(false) .build() .asList(); diff --git a/common/common/src/test/java/io/helidon/common/ServiceImpl1.java b/common/common/src/test/java/io/helidon/common/ServiceImpl1.java index b47797ad3c9..f727f1047b2 100644 --- a/common/common/src/test/java/io/helidon/common/ServiceImpl1.java +++ b/common/common/src/test/java/io/helidon/common/ServiceImpl1.java @@ -15,12 +15,10 @@ */ package io.helidon.common; -import jakarta.annotation.Priority; - /** * A service implementation. */ -@Priority(47) +@Weight(12) public class ServiceImpl1 implements ServiceInterface { @Override public String message() { diff --git a/common/common/src/test/java/io/helidon/common/ServiceImpl2.java b/common/common/src/test/java/io/helidon/common/ServiceImpl2.java index 155965eec3b..bcefd9d502c 100644 --- a/common/common/src/test/java/io/helidon/common/ServiceImpl2.java +++ b/common/common/src/test/java/io/helidon/common/ServiceImpl2.java @@ -18,7 +18,7 @@ /** * A service implementation. */ -public class ServiceImpl2 implements ServiceInterface, Prioritized { +public class ServiceImpl2 implements ServiceInterface, Weighted { private final String message; public ServiceImpl2() { @@ -35,7 +35,7 @@ public String message() { } @Override - public int priority() { - return 12; + public double weight() { + return 417; } } diff --git a/common/common/src/test/java/io/helidon/common/ServiceImpl3.java b/common/common/src/test/java/io/helidon/common/ServiceImpl3.java index 64c1f96edea..402542270b8 100644 --- a/common/common/src/test/java/io/helidon/common/ServiceImpl3.java +++ b/common/common/src/test/java/io/helidon/common/ServiceImpl3.java @@ -15,12 +15,10 @@ */ package io.helidon.common; -import jakarta.annotation.Priority; - /** * A service implementation. */ -@Priority(22) +@Weight(22) public class ServiceImpl3 implements ServiceInterface { @Override public String message() { diff --git a/common/configurable/etc/spotbugs/exclude.xml b/common/configurable/etc/spotbugs/exclude.xml index b65246ca15b..b6497f165c2 100644 --- a/common/configurable/etc/spotbugs/exclude.xml +++ b/common/configurable/etc/spotbugs/exclude.xml @@ -1,7 +1,7 @@ - + diff --git a/common/context/src/main/java/io/helidon/common/context/ContextAwareExecutorImpl.java b/common/context/src/main/java/io/helidon/common/context/ContextAwareExecutorImpl.java index e91b82cb6b6..768f89f6a84 100644 --- a/common/context/src/main/java/io/helidon/common/context/ContextAwareExecutorImpl.java +++ b/common/context/src/main/java/io/helidon/common/context/ContextAwareExecutorImpl.java @@ -29,8 +29,8 @@ import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; -import io.helidon.common.context.spi.DataPropagationProvider; import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.context.spi.DataPropagationProvider; class ContextAwareExecutorImpl implements ContextAwareExecutorService { diff --git a/common/mapper/src/main/java/io/helidon/common/mapper/MapperManager.java b/common/mapper/src/main/java/io/helidon/common/mapper/MapperManager.java index 9d4b2e5b97e..5500fd0cea9 100644 --- a/common/mapper/src/main/java/io/helidon/common/mapper/MapperManager.java +++ b/common/mapper/src/main/java/io/helidon/common/mapper/MapperManager.java @@ -20,9 +20,9 @@ import java.util.ServiceLoader; import io.helidon.common.GenericType; -import io.helidon.common.Prioritized; -import io.helidon.common.mapper.spi.MapperProvider; import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.Weighted; +import io.helidon.common.mapper.spi.MapperProvider; /** * Mapper manager of all configured mappers. @@ -177,7 +177,7 @@ public Builder addMapperProvider(MapperProvider provider, int priority) { * @return updated builder instance */ public Builder addMapper(Mapper mapper, Class sourceType, Class targetType) { - return addMapper(mapper, sourceType, targetType, Prioritized.DEFAULT_PRIORITY); + return addMapper(mapper, sourceType, targetType, Weighted.DEFAULT_WEIGHT); } /** @@ -186,12 +186,15 @@ public Builder addMapper(Mapper mapper, Class sourceType, Class< * @param mapper the mapper to map source instances to target instances * @param sourceType class of the source instance * @param targetType class of the target instance - * @param priority order of the mapper usage + * @param weight weight of the mapper * @param type of source * @param type of target * @return updated builder instance */ - public Builder addMapper(Mapper mapper, Class sourceType, Class targetType, int priority) { + public Builder addMapper(Mapper mapper, + Class sourceType, + Class targetType, + double weight) { this.providers.addService(new MapperProvider() { @SuppressWarnings({"unchecked", "ObjectEquality"}) @Override @@ -202,7 +205,7 @@ public Builder addMapper(Mapper mapper, Class sourceType, Class< } return Optional.empty(); } - }, priority); + }, weight); return this; } @@ -217,7 +220,7 @@ public Builder addMapper(Mapper mapper, Class sourceType, Class< * @return updated builder instance */ public Builder addMapper(Mapper mapper, GenericType sourceType, GenericType targetType) { - return addMapper(mapper, sourceType, targetType, Prioritized.DEFAULT_PRIORITY); + return addMapper(mapper, sourceType, targetType, Weighted.DEFAULT_WEIGHT); } /** @@ -226,12 +229,15 @@ public Builder addMapper(Mapper mapper, GenericType sourceType, * @param mapper the mapper to map source instances to target instances * @param sourceType generic type of the source instance * @param targetType generic type of the target instance - * @param priority order of the mapper usage + * @param weight weight of the mapper * @param type of source * @param type of target * @return updated builder instance */ - public Builder addMapper(Mapper mapper, GenericType sourceType, GenericType targetType, int priority) { + public Builder addMapper(Mapper mapper, + GenericType sourceType, + GenericType targetType, + double weight) { this.providers.addService(new MapperProvider() { @Override public Optional> mapper(Class sourceClass, Class targetClass) { @@ -247,7 +253,7 @@ public Builder addMapper(Mapper mapper, GenericType sourceType, } return Optional.empty(); } - }, priority); + }, weight); return this; } diff --git a/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java b/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java index c6892059c44..09263617edf 100644 --- a/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java +++ b/common/media-type/src/main/java/io/helidon/common/media/type/MediaTypes.java @@ -42,8 +42,8 @@ public final class MediaTypes { static { // and load media type detectors DETECTORS = HelidonServiceLoader.builder(ServiceLoader.load(MediaTypeDetector.class)) - .addService(new BuiltInsDetector(), 100100) - .addService(new CustomDetector(), 100000) + .addService(new BuiltInsDetector(), 10) + .addService(new CustomDetector(), 50) .build() .asList(); } diff --git a/config/config-mp/src/main/java/io/helidon/config/mp/MpConfigBuilder.java b/config/config-mp/src/main/java/io/helidon/config/mp/MpConfigBuilder.java index fc7c66f83ee..358cad4708a 100644 --- a/config/config-mp/src/main/java/io/helidon/config/mp/MpConfigBuilder.java +++ b/config/config-mp/src/main/java/io/helidon/config/mp/MpConfigBuilder.java @@ -60,7 +60,6 @@ import io.helidon.common.Builder; import io.helidon.common.HelidonServiceLoader; -import io.helidon.common.Priorities; import io.helidon.config.ConfigException; import io.helidon.config.ConfigMappers; import io.helidon.config.ConfigValue; @@ -95,6 +94,9 @@ class MpConfigBuilder implements Builder, ConfigBuilder .build() .asList(); + // Helidon service loader uses Weight and Weighted by default, we want to use priorities here + Priorities.sort(mpMetaConfigProviders, Prioritized.DEFAULT_PRIORITY); + Map theMap = new HashMap<>(); // ordered by priority for (MpMetaConfigProvider mpMetaConfigProvider : mpMetaConfigProviders) { diff --git a/config/config-mp/src/main/java/io/helidon/config/mp/MpEnvironmentVariablesMetaConfigProvider.java b/config/config-mp/src/main/java/io/helidon/config/mp/MpEnvironmentVariablesMetaConfigProvider.java index 852233612cd..9177f03e4f0 100644 --- a/config/config-mp/src/main/java/io/helidon/config/mp/MpEnvironmentVariablesMetaConfigProvider.java +++ b/config/config-mp/src/main/java/io/helidon/config/mp/MpEnvironmentVariablesMetaConfigProvider.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Set; -import io.helidon.common.Prioritized; import io.helidon.config.Config; import io.helidon.config.mp.spi.MpMetaConfigProvider; diff --git a/config/config-mp/src/main/java/io/helidon/config/mp/MpPropertiesMetaConfigProvider.java b/config/config-mp/src/main/java/io/helidon/config/mp/MpPropertiesMetaConfigProvider.java index 01bf8c81916..7ec766204d6 100644 --- a/config/config-mp/src/main/java/io/helidon/config/mp/MpPropertiesMetaConfigProvider.java +++ b/config/config-mp/src/main/java/io/helidon/config/mp/MpPropertiesMetaConfigProvider.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Set; -import io.helidon.common.Prioritized; import io.helidon.config.Config; import io.helidon.config.mp.spi.MpMetaConfigProvider; diff --git a/config/config-mp/src/main/java/io/helidon/config/mp/MpSystemPropertiesMetaConfigProvider.java b/config/config-mp/src/main/java/io/helidon/config/mp/MpSystemPropertiesMetaConfigProvider.java index 1911848dddb..eca82bde7a2 100644 --- a/config/config-mp/src/main/java/io/helidon/config/mp/MpSystemPropertiesMetaConfigProvider.java +++ b/config/config-mp/src/main/java/io/helidon/config/mp/MpSystemPropertiesMetaConfigProvider.java @@ -19,7 +19,6 @@ import java.util.List; import java.util.Set; -import io.helidon.common.Prioritized; import io.helidon.config.Config; import io.helidon.config.mp.spi.MpMetaConfigProvider; diff --git a/common/common/src/main/java/io/helidon/common/Priorities.java b/config/config-mp/src/main/java/io/helidon/config/mp/Priorities.java similarity index 91% rename from common/common/src/main/java/io/helidon/common/Priorities.java rename to config/config-mp/src/main/java/io/helidon/config/mp/Priorities.java index f0746c5d3a2..cbd1d961a92 100644 --- a/common/common/src/main/java/io/helidon/common/Priorities.java +++ b/config/config-mp/src/main/java/io/helidon/config/mp/Priorities.java @@ -13,13 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.common; +package io.helidon.config.mp; import java.util.Comparator; import java.util.List; -import io.helidon.common.Prioritized; - import jakarta.annotation.Priority; /** @@ -47,7 +45,7 @@ public static int find(Class aClass, int defaultPriority) { /** * Find priority for an instance. - * First checks if instance is {@link io.helidon.common.Prioritized}. If so, + * First checks if instance is {@link Prioritized}. If so, * uses the value from it. * Then checks for {@link Priority} annotation. * If none of the above is found, returns the default priority. @@ -81,7 +79,7 @@ public static void sort(List list) { /** * Sort the list based on priorities. *

    - *
  • If element implements {@link io.helidon.common.Prioritized}, uses its priority.
  • + *
  • If element implements {@link Prioritized}, uses its priority.
  • *
  • If element is a class and has annotation {@link jakarta.annotation.Priority}, uses its priority
  • *
  • If element is any object and its class has annotation {@link jakarta.annotation.Priority}, uses its priority
  • *
@@ -94,7 +92,7 @@ public static void sort(List list, int defaultPriority) { /** * Returns a comparator for two objects, the classes for which are implementations of - * {@link io.helidon.common.Prioritized}, and/or optionally annotated with {@link jakarta.annotation.Priority} + * {@link Prioritized}, and/or optionally annotated with {@link jakarta.annotation.Priority} * and which applies a specified default priority if either or both classes lack the annotation. * * @param type of object being compared diff --git a/common/common/src/main/java/io/helidon/common/Prioritized.java b/config/config-mp/src/main/java/io/helidon/config/mp/Prioritized.java similarity index 95% rename from common/common/src/main/java/io/helidon/common/Prioritized.java rename to config/config-mp/src/main/java/io/helidon/config/mp/Prioritized.java index deecf72984c..c4ea50253df 100644 --- a/common/common/src/main/java/io/helidon/common/Prioritized.java +++ b/config/config-mp/src/main/java/io/helidon/config/mp/Prioritized.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.helidon.common; +package io.helidon.config.mp; /** * Interface to define that this class is a class with priority. diff --git a/common/common/src/test/java/io/helidon/common/PrioritiesTest.java b/config/config-mp/src/test/java/io/helidon/config/mp/PrioritiesTest.java similarity index 99% rename from common/common/src/test/java/io/helidon/common/PrioritiesTest.java rename to config/config-mp/src/test/java/io/helidon/config/mp/PrioritiesTest.java index 7174ec3f961..731797b126d 100644 --- a/common/common/src/test/java/io/helidon/common/PrioritiesTest.java +++ b/config/config-mp/src/test/java/io/helidon/config/mp/PrioritiesTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package io.helidon.common; +package io.helidon.config.mp; import java.util.ArrayList; import java.util.List; diff --git a/config/config/src/main/java/io/helidon/config/BuilderImpl.java b/config/config/src/main/java/io/helidon/config/BuilderImpl.java index 76f620e3b27..82cb1fbcc71 100644 --- a/config/config/src/main/java/io/helidon/config/BuilderImpl.java +++ b/config/config/src/main/java/io/helidon/config/BuilderImpl.java @@ -32,9 +32,9 @@ import java.util.function.Supplier; import io.helidon.common.GenericType; -import io.helidon.common.Prioritized; import io.helidon.common.HelidonServiceLoader; -import io.helidon.common.Priorities; +import io.helidon.common.Weighted; +import io.helidon.common.Weights; import io.helidon.config.ConfigMapperManager.MapperProviders; import io.helidon.config.spi.ConfigContext; import io.helidon.config.spi.ConfigFilter; @@ -338,10 +338,10 @@ private static void addBuiltInMapperServices(List pri // and yet we can still define a service that is only used after these (such as config beans) prioritizedMappers .add(new HelidonMapperWrapper(new InternalMapperProvider(ConfigMappers.essentialMappers(), - "essential"), 200)); + "essential"), 1)); prioritizedMappers .add(new HelidonMapperWrapper(new InternalMapperProvider(ConfigMappers.builtInMappers(), - "built-in"), 200)); + "built-in"), 1)); } @Override @@ -475,7 +475,7 @@ static ConfigMapperManager buildMappers(List prioriti loadMapperServices(prioritizedMappers); } addBuiltInMapperServices(prioritizedMappers); - Priorities.sort(prioritizedMappers); + Collections.sort(prioritizedMappers); // as the mapperProviders.add adds the last as first, we need to reverse order Collections.reverse(prioritizedMappers); @@ -492,14 +492,12 @@ static ConfigMapperManager buildMappers(List prioriti private static void loadMapperServices(List providers) { HelidonServiceLoader.builder(ServiceLoader.load(ConfigMapperProvider.class)) - .defaultPriority(ConfigMapperProvider.PRIORITY) .build() - .forEach(mapper -> providers.add(new HelidonMapperWrapper(mapper, Priorities.find(mapper, 100)))); + .forEach(mapper -> providers.add(new HelidonMapperWrapper(mapper, Weights.find(mapper, 100)))); } private static List loadParserServices() { return HelidonServiceLoader.builder(ServiceLoader.load(ConfigParser.class)) - .defaultPriority(ConfigParser.PRIORITY) .build() .asList(); } @@ -523,7 +521,6 @@ private void addAutoLoadedFilters() { * Map each autoloaded ConfigFilter to a filter-providing function. */ HelidonServiceLoader.builder(ServiceLoader.load(ConfigFilter.class)) - .defaultPriority(ConfigFilter.PRIORITY) .build() .asList() .stream() @@ -531,6 +528,10 @@ private void addAutoLoadedFilters() { .forEach(this::addFilter); } + private interface PrioritizedMapperProvider extends Weighted, + ConfigMapperProvider { + } + /** * {@link ConfigContext} implementation. */ @@ -619,22 +620,18 @@ public String toString() { } } - private interface PrioritizedMapperProvider extends Prioritized, - ConfigMapperProvider { - } - private static final class HelidonMapperWrapper implements PrioritizedMapperProvider { private final ConfigMapperProvider delegate; - private final int priority; + private final double weight; - private HelidonMapperWrapper(ConfigMapperProvider delegate, int priority) { + private HelidonMapperWrapper(ConfigMapperProvider delegate, double weight) { this.delegate = delegate; - this.priority = priority; + this.weight = weight; } @Override - public int priority() { - return priority; + public double weight() { + return weight; } @Override @@ -659,56 +656,56 @@ public Optional> mapper(GenericType t @Override public String toString() { - return priority + ": " + delegate; + return weight + ": " + delegate; } } - private static final class PrioritizedConfigSource implements Prioritized { + private static final class WeightedConfigSource implements Weighted { private final HelidonSourceWithPriority source; private final ConfigContext context; - private PrioritizedConfigSource(HelidonSourceWithPriority source, ConfigContext context) { + private WeightedConfigSource(HelidonSourceWithPriority source, ConfigContext context) { this.source = source; this.context = context; } - private ConfigSourceRuntimeImpl runtime(ConfigContextImpl context) { - return context.sourceRuntimeBase(source.unwrap()); + @Override + public double weight() { + return source.weight(context); } - @Override - public int priority() { - return source.priority(context); + private ConfigSourceRuntimeImpl runtime(ConfigContextImpl context) { + return context.sourceRuntimeBase(source.unwrap()); } } private static final class HelidonSourceWithPriority { private final ConfigSource configSource; - private final Integer explicitPriority; + private final Double explicitWeight; - private HelidonSourceWithPriority(ConfigSource configSource, Integer explicitPriority) { + private HelidonSourceWithPriority(ConfigSource configSource, Double explicitWeight) { this.configSource = configSource; - this.explicitPriority = explicitPriority; + this.explicitWeight = explicitWeight; } ConfigSource unwrap() { return configSource; } - int priority(ConfigContext context) { + double weight(ConfigContext context) { // first - explicit priority. If configured by user, return it - if (null != explicitPriority) { - return explicitPriority; + if (null != explicitWeight) { + return explicitWeight; } // ordinal from data return context.sourceRuntime(configSource) .node("config_priority") .flatMap(node -> node.value() - .map(Integer::parseInt)) + .map(Double::parseDouble)) .orElseGet(() -> { // the config source does not have an ordinal configured, I need to get it from other places - return Priorities.find(configSource, 100); + return Weights.find(configSource, Weighted.DEFAULT_WEIGHT); }); } } diff --git a/config/config/src/main/java/io/helidon/config/MetaProviders.java b/config/config/src/main/java/io/helidon/config/MetaProviders.java index 7c0e3dadec0..1c30190f5a2 100644 --- a/config/config/src/main/java/io/helidon/config/MetaProviders.java +++ b/config/config/src/main/java/io/helidon/config/MetaProviders.java @@ -24,6 +24,7 @@ import java.util.function.Function; import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.Weight; import io.helidon.config.spi.ChangeWatcher; import io.helidon.config.spi.ChangeWatcherProvider; import io.helidon.config.spi.ConfigSource; @@ -35,8 +36,6 @@ import io.helidon.config.spi.RetryPolicy; import io.helidon.config.spi.RetryPolicyProvider; -import jakarta.annotation.Priority; - /** * Access to Java service loaders for config sources, retry policies and polling strategies. */ @@ -163,7 +162,7 @@ public static ChangeWatcher changeWatcher(String type, Config config) { + " Supported types: " + SUPPORTED_CHANGE_WATCHERS)); } - @Priority(Integer.MAX_VALUE) + @Weight(0) private static final class BuiltInChangeWatchers implements ChangeWatcherProvider { private static final String FILE_WATCH = "file"; @@ -183,7 +182,7 @@ public Set supported() { } } - @Priority(Integer.MAX_VALUE) + @Weight(0) private static final class BuiltInPollingStrategyProvider implements PollingStrategyProvider { private static final String REGULAR_TYPE = "regular"; @@ -203,7 +202,7 @@ public Set supported() { } } - @Priority(Integer.MAX_VALUE) + @Weight(0) private static final class BuiltInRetryPolicyProvider implements RetryPolicyProvider { private static final String REPEAT_TYPE = "repeat"; @@ -226,7 +225,7 @@ public Set supported() { } } - @Priority(Integer.MAX_VALUE) + @Weight(0) private static final class BuiltinOverrideSourceProvider implements OverrideSourceProvider { private static final String FILE_TYPE = "file"; private static final String CLASSPATH_TYPE = "classpath"; @@ -256,7 +255,7 @@ public Set supported() { } } - @Priority(Integer.MAX_VALUE) + @Weight(0) private static final class BuiltInConfigSourcesProvider implements ConfigSourceProvider { private static final String SYSTEM_PROPERTIES_TYPE = "system-properties"; private static final String ENVIRONMENT_VARIABLES_TYPE = "environment-variables"; diff --git a/config/config/src/main/java/io/helidon/config/PropertiesConfigParser.java b/config/config/src/main/java/io/helidon/config/PropertiesConfigParser.java index b3b84dd9751..38309917fda 100644 --- a/config/config/src/main/java/io/helidon/config/PropertiesConfigParser.java +++ b/config/config/src/main/java/io/helidon/config/PropertiesConfigParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,12 +19,12 @@ import java.util.Properties; import java.util.Set; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.spi.ConfigNode; import io.helidon.config.spi.ConfigParser; import io.helidon.config.spi.ConfigParserException; -import jakarta.annotation.Priority; - /** * {@link ConfigParser} implementation that parses Java Properties content. *

@@ -33,13 +33,13 @@ * if not {@link io.helidon.config.Config.Builder#disableParserServices() disabled}. * And of course it can be {@link io.helidon.config.Config.Builder#addParser(ConfigParser) registered programmatically}. *

- * Priority of the {@code PropertiesConfigParser} to be used by {@link io.helidon.config.Config.Builder}, - * if loaded automatically as a {@link java.util.ServiceLoader service}, is {@value PRIORITY}. + * Weight of the {@code PropertiesConfigParser} to be used by {@link io.helidon.config.Config.Builder}, + * if loaded automatically as a {@link java.util.ServiceLoader service}, is {@value #WEIGHT}. * * @see io.helidon.config.Config.Builder#addParser(ConfigParser) * @see io.helidon.config.Config.Builder#disableParserServices() */ -@Priority(PropertiesConfigParser.PRIORITY) +@Weight(PropertiesConfigParser.WEIGHT) public class PropertiesConfigParser implements ConfigParser { /** @@ -50,10 +50,16 @@ public class PropertiesConfigParser implements ConfigParser { /** * Priority of the parser used if registered by {@link io.helidon.config.Config.Builder} automatically. */ - public static final int PRIORITY = ConfigParser.PRIORITY + 100; + public static final double WEIGHT = Weighted.DEFAULT_WEIGHT - 10; private static final Set SUPPORTED_MEDIA_TYPES = Set.of(MEDIA_TYPE_TEXT_JAVA_PROPERTIES); + /** + * Required public constructor for {@link java.util.ServiceLoader}. + */ + public PropertiesConfigParser() { + } + @Override public Set supportedMediaTypes() { return SUPPORTED_MEDIA_TYPES; diff --git a/config/config/src/main/java/io/helidon/config/spi/ConfigParser.java b/config/config/src/main/java/io/helidon/config/spi/ConfigParser.java index dfbe70062fe..d8f4a74461e 100644 --- a/config/config/src/main/java/io/helidon/config/spi/ConfigParser.java +++ b/config/config/src/main/java/io/helidon/config/spi/ConfigParser.java @@ -40,8 +40,8 @@ * given {@code Builder} by invoking * {@link io.helidon.config.Config.Builder#disableParserServices()}. *

- * A parser can specify a {@link jakarta.annotation.Priority}. If no priority is - * explicitly assigned, the value of {@value PRIORITY} is assumed. + * A parser can specify a {@link io.helidon.common.Weight}. If no priority is + * explicitly assigned, the value of {@value io.helidon.common.Weighted#DEFAULT_WEIGHT} is assumed. *

* Parser is used by the config system and a config source provides data as an input stream. * @@ -50,12 +50,6 @@ * @see ConfigParsers ConfigParsers - access built-in implementations. */ public interface ConfigParser { - - /** - * Default priority of the parser if registered by {@link io.helidon.config.Config.Builder} automatically. - */ - int PRIORITY = 100; - /** * Returns set of supported media types by the parser. *

diff --git a/config/hocon-mp/src/main/java/io/helidon/config/hocon/mp/HoconMpMetaConfigProvider.java b/config/hocon-mp/src/main/java/io/helidon/config/hocon/mp/HoconMpMetaConfigProvider.java index 258ee448191..449dc4443a1 100644 --- a/config/hocon-mp/src/main/java/io/helidon/config/hocon/mp/HoconMpMetaConfigProvider.java +++ b/config/hocon-mp/src/main/java/io/helidon/config/hocon/mp/HoconMpMetaConfigProvider.java @@ -19,9 +19,9 @@ import java.util.List; import java.util.Set; -import io.helidon.common.Prioritized; import io.helidon.config.Config; import io.helidon.config.mp.MpMetaConfigUtils; +import io.helidon.config.mp.Prioritized; import io.helidon.config.mp.spi.MpMetaConfigProvider; import org.eclipse.microprofile.config.spi.ConfigSource; diff --git a/config/hocon/src/main/java/io/helidon/config/hocon/HoconConfigParser.java b/config/hocon/src/main/java/io/helidon/config/hocon/HoconConfigParser.java index 92620c3eaf3..8f6524e375e 100644 --- a/config/hocon/src/main/java/io/helidon/config/hocon/HoconConfigParser.java +++ b/config/hocon/src/main/java/io/helidon/config/hocon/HoconConfigParser.java @@ -24,6 +24,8 @@ import java.util.Set; import java.util.function.Function; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.ConfigException; import io.helidon.config.spi.ConfigNode.ListNode; import io.helidon.config.spi.ConfigNode.ObjectNode; @@ -36,7 +38,6 @@ import com.typesafe.config.ConfigObject; import com.typesafe.config.ConfigParseOptions; import com.typesafe.config.ConfigResolveOptions; -import jakarta.annotation.Priority; /** * Typesafe (Lightbend) Config (HOCON) {@link ConfigParser} implementation that supports following media types: @@ -49,12 +50,12 @@ * And of course it can be {@link io.helidon.config.Config.Builder#addParser(ConfigParser) registered programmatically}. *

* Priority of the {@code HoconConfigParser} to be used by {@link io.helidon.config.Config.Builder}, - * if loaded automatically as a {@link java.util.ServiceLoader service}, is {@value PRIORITY}. + * if loaded automatically as a {@link java.util.ServiceLoader service}, is {@value WEIGHT}. * * @see io.helidon.config.Config.Builder#addParser(ConfigParser) * @see io.helidon.config.Config.Builder#disableParserServices() */ -@Priority(HoconConfigParser.PRIORITY) +@Weight(HoconConfigParser.WEIGHT) public class HoconConfigParser implements ConfigParser { /** @@ -68,7 +69,8 @@ public class HoconConfigParser implements ConfigParser { /** * Priority of the parser used if registered by {@link io.helidon.config.Config.Builder} automatically. */ - public static final int PRIORITY = ConfigParser.PRIORITY + 100; + public static final double WEIGHT = Weighted.DEFAULT_WEIGHT - 10; + private static final List SUPPORTED_SUFFIXES = List.of("json", "conf"); private static final Set SUPPORTED_MEDIA_TYPES = Set.of(MEDIA_TYPE_APPLICATION_HOCON, MEDIA_TYPE_APPLICATION_JSON); diff --git a/config/object-mapping/src/main/java/io/helidon/config/objectmapping/ObjectConfigMapperProvider.java b/config/object-mapping/src/main/java/io/helidon/config/objectmapping/ObjectConfigMapperProvider.java index e3bd361182c..1b015b722bd 100644 --- a/config/object-mapping/src/main/java/io/helidon/config/objectmapping/ObjectConfigMapperProvider.java +++ b/config/object-mapping/src/main/java/io/helidon/config/objectmapping/ObjectConfigMapperProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import java.util.Optional; import java.util.function.Function; +import io.helidon.common.Weight; import io.helidon.config.Config; import io.helidon.config.objectmapping.ObjectConfigMappers.BuilderConfigMapper; import io.helidon.config.objectmapping.ObjectConfigMappers.ConfigMethodHandleConfigMapper; @@ -27,8 +28,6 @@ import io.helidon.config.objectmapping.ObjectConfigMappers.StringMethodHandleConfigMapper; import io.helidon.config.spi.ConfigMapperProvider; -import jakarta.annotation.Priority; - import static io.helidon.config.objectmapping.ReflectionUtil.findBuilderConstructor; import static io.helidon.config.objectmapping.ReflectionUtil.findBuilderMethod; import static io.helidon.config.objectmapping.ReflectionUtil.findConstructor; @@ -39,7 +38,7 @@ /** * Java beans support for configuration. */ -@Priority(1000) // priority should be low to be one of the last ones used +@Weight(0) // priority should be low to be one of the last ones used public class ObjectConfigMapperProvider implements ConfigMapperProvider { private static final String METHOD_FROM = "from"; private static final String METHOD_OF = "of"; diff --git a/config/tests/module-mappers-1-base/src/main/java/io/helidon/config/tests/module/mappers1/Mappers1ConfigMapperProvider.java b/config/tests/module-mappers-1-base/src/main/java/io/helidon/config/tests/module/mappers1/Mappers1ConfigMapperProvider.java index 3c0f836340f..ed07c03d792 100644 --- a/config/tests/module-mappers-1-base/src/main/java/io/helidon/config/tests/module/mappers1/Mappers1ConfigMapperProvider.java +++ b/config/tests/module-mappers-1-base/src/main/java/io/helidon/config/tests/module/mappers1/Mappers1ConfigMapperProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +21,15 @@ import java.util.function.Function; import java.util.logging.Logger; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.Config; import io.helidon.config.spi.ConfigMapperProvider; -import jakarta.annotation.Priority; - /** * Registers Config mappers for {@link Logger} and {@link Locale}. */ -@Priority(90) // higher than default +@Weight(Weighted.DEFAULT_WEIGHT + 10) // higher than default public class Mappers1ConfigMapperProvider implements ConfigMapperProvider { @Override diff --git a/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority100ConfigMapperProvider.java b/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority100ConfigMapperProvider.java index 4f167983de5..83cc2fb4c1d 100644 --- a/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority100ConfigMapperProvider.java +++ b/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority100ConfigMapperProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +20,15 @@ import java.util.function.Function; import java.util.logging.Logger; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.Config; import io.helidon.config.spi.ConfigMapperProvider; -import jakarta.annotation.Priority; - /** * Registers Config mappers for {@link Logger}. */ -@Priority(100) // default priority +@Weight(Weighted.DEFAULT_WEIGHT) // default priority public class Mappers2Priority100ConfigMapperProvider implements ConfigMapperProvider { @Override diff --git a/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority150ConfigMapperProvider.java b/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority150ConfigMapperProvider.java index 34e41b33867..ccdc3577711 100644 --- a/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority150ConfigMapperProvider.java +++ b/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority150ConfigMapperProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +21,15 @@ import java.util.OptionalInt; import java.util.function.Function; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.Config; import io.helidon.config.spi.ConfigMapperProvider; -import jakarta.annotation.Priority; - /** * Registers config mapper for {@link OptionalInt}, {@link Integer} and {@link java.math.BigInteger}. */ -@Priority(150) // lower than default priority +@Weight(Weighted.DEFAULT_WEIGHT - 50) // lower than default priority public class Mappers2Priority150ConfigMapperProvider implements ConfigMapperProvider { @Override diff --git a/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority50ConfigMapperProvider.java b/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority50ConfigMapperProvider.java index 093bc48acfd..571538be99b 100644 --- a/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority50ConfigMapperProvider.java +++ b/config/tests/module-mappers-2-override/src/main/java/io/helidon/config/tests/module/mappers2/Mappers2Priority50ConfigMapperProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +20,15 @@ import java.util.Map; import java.util.function.Function; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.Config; import io.helidon.config.spi.ConfigMapperProvider; -import jakarta.annotation.Priority; - /** * Registers Config mappers for {@link Locale}. */ -@Priority(50) // higher than default priority +@Weight(Weighted.DEFAULT_WEIGHT + 50) // higher than default priority public class Mappers2Priority50ConfigMapperProvider implements ConfigMapperProvider { @Override diff --git a/config/tests/module-parsers-1-override/src/main/java/io/helidon/config/tests/module/parsers1/Parsers1Priority100ConfigParser.java b/config/tests/module-parsers-1-override/src/main/java/io/helidon/config/tests/module/parsers1/Parsers1Priority100ConfigParser.java index 4feb617d51b..546a3973b1c 100644 --- a/config/tests/module-parsers-1-override/src/main/java/io/helidon/config/tests/module/parsers1/Parsers1Priority100ConfigParser.java +++ b/config/tests/module-parsers-1-override/src/main/java/io/helidon/config/tests/module/parsers1/Parsers1Priority100ConfigParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,16 @@ package io.helidon.config.tests.module.parsers1; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.spi.ConfigNode; import io.helidon.config.spi.ConfigNode.ValueNode; -import jakarta.annotation.Priority; - /** * Testing implementation of {@code text/x-java-properties} media type - * with Priority {@code 100}. + * with Weight {@code 100}. */ -@Priority(100) +@Weight(Weighted.DEFAULT_WEIGHT) public class Parsers1Priority100ConfigParser extends AbstractParsers1ConfigParser { /** diff --git a/config/tests/module-parsers-1-override/src/main/java/io/helidon/config/tests/module/parsers1/Parsers1Priority300ConfigParser.java b/config/tests/module-parsers-1-override/src/main/java/io/helidon/config/tests/module/parsers1/Parsers1Priority300ConfigParser.java index 2352930a56b..d0dafe814f4 100644 --- a/config/tests/module-parsers-1-override/src/main/java/io/helidon/config/tests/module/parsers1/Parsers1Priority300ConfigParser.java +++ b/config/tests/module-parsers-1-override/src/main/java/io/helidon/config/tests/module/parsers1/Parsers1Priority300ConfigParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,15 @@ package io.helidon.config.tests.module.parsers1; +import io.helidon.common.Weight; import io.helidon.config.spi.ConfigNode; import io.helidon.config.spi.ConfigNode.ValueNode; -import jakarta.annotation.Priority; - /** * Testing implementation of {@code text/x-java-properties} media type - * with Priority {@code 300}. + * with Weight {@code 10}. */ -@Priority(300) +@Weight(10) public class Parsers1Priority300ConfigParser extends AbstractParsers1ConfigParser { /** diff --git a/config/yaml-mp/src/main/java/io/helidon/config/yaml/mp/YamlMetaConfigProvider.java b/config/yaml-mp/src/main/java/io/helidon/config/yaml/mp/YamlMetaConfigProvider.java index 88d876464e2..476ba1a7e95 100644 --- a/config/yaml-mp/src/main/java/io/helidon/config/yaml/mp/YamlMetaConfigProvider.java +++ b/config/yaml-mp/src/main/java/io/helidon/config/yaml/mp/YamlMetaConfigProvider.java @@ -19,9 +19,9 @@ import java.util.List; import java.util.Set; -import io.helidon.common.Prioritized; import io.helidon.config.Config; import io.helidon.config.mp.MpMetaConfigUtils; +import io.helidon.config.mp.Prioritized; import io.helidon.config.mp.spi.MpMetaConfigProvider; import org.eclipse.microprofile.config.spi.ConfigSource; diff --git a/config/yaml/src/main/java/io/helidon/config/yaml/YamlConfigParser.java b/config/yaml/src/main/java/io/helidon/config/yaml/YamlConfigParser.java index 1735ee92146..793379d79a8 100644 --- a/config/yaml/src/main/java/io/helidon/config/yaml/YamlConfigParser.java +++ b/config/yaml/src/main/java/io/helidon/config/yaml/YamlConfigParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2021 Oracle and/or its affiliates. + * Copyright (c) 2020, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,13 +22,14 @@ import java.util.Map; import java.util.Set; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.ConfigException; import io.helidon.config.spi.ConfigNode.ListNode; import io.helidon.config.spi.ConfigNode.ObjectNode; import io.helidon.config.spi.ConfigParser; import io.helidon.config.spi.ConfigParserException; -import jakarta.annotation.Priority; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.SafeConstructor; @@ -40,13 +41,13 @@ * if not {@link io.helidon.config.Config.Builder#disableParserServices() disabled}. * And of course it can be {@link io.helidon.config.Config.Builder#addParser(ConfigParser) registered programmatically}. *

- * Priority of the {@code YamlConfigParser} to be used by {@link io.helidon.config.Config.Builder}, - * if loaded automatically as a {@link java.util.ServiceLoader service}, is {@value PRIORITY}. + * Weight of the {@code YamlConfigParser} to be used by {@link io.helidon.config.Config.Builder}, + * if loaded automatically as a {@link java.util.ServiceLoader service}, is {@value WEIGHT}. * * @see io.helidon.config.Config.Builder#addParser(ConfigParser) * @see io.helidon.config.Config.Builder#disableParserServices() */ -@Priority(YamlConfigParser.PRIORITY) +@Weight(YamlConfigParser.WEIGHT) public class YamlConfigParser implements ConfigParser { /** @@ -56,7 +57,7 @@ public class YamlConfigParser implements ConfigParser { /** * Priority of the parser used if registered by {@link io.helidon.config.Config.Builder} automatically. */ - public static final int PRIORITY = ConfigParser.PRIORITY + 100; + public static final double WEIGHT = Weighted.DEFAULT_WEIGHT - 10; private static final Set SUPPORTED_MEDIA_TYPES = Set.of(MEDIA_TYPE_APPLICATION_YAML); private static final List SUPPORTED_SUFFIXES = List.of("yml", "yaml"); diff --git a/config/yaml/src/main/java/io/helidon/config/yaml/package-info.java b/config/yaml/src/main/java/io/helidon/config/yaml/package-info.java index cdc95e413b6..dea4dd7ce5c 100644 --- a/config/yaml/src/main/java/io/helidon/config/yaml/package-info.java +++ b/config/yaml/src/main/java/io/helidon/config/yaml/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ * if not {@link io.helidon.config.Config.Builder#disableParserServices() disabled}. * Priority of the {@code YamlConfigParser} to be used by {@link io.helidon.config.Config.Builder}, * if loaded automatically as a {@link java.util.ServiceLoader service}, - * is {@value io.helidon.config.yaml.YamlConfigParser#PRIORITY}. + * is {@value io.helidon.config.yaml.YamlConfigParser#WEIGHT}. * And of course it can be {@link io.helidon.config.Config.Builder#addParser(io.helidon.config.spi.ConfigParser) * registered programmatically} using {@link io.helidon.config.yaml.YamlConfigParser#create()}. *

diff --git a/dbclient/jsonp/src/main/java/io/helidon/dbclient/jsonp/JsonProcessingMapperProvider.java b/dbclient/jsonp/src/main/java/io/helidon/dbclient/jsonp/JsonProcessingMapperProvider.java index 99b5e0dfddc..9a3c7082b27 100644 --- a/dbclient/jsonp/src/main/java/io/helidon/dbclient/jsonp/JsonProcessingMapperProvider.java +++ b/dbclient/jsonp/src/main/java/io/helidon/dbclient/jsonp/JsonProcessingMapperProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,17 +17,17 @@ import java.util.Optional; -import io.helidon.common.Prioritized; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.dbclient.DbMapper; import io.helidon.dbclient.spi.DbMapperProvider; -import jakarta.annotation.Priority; import jakarta.json.JsonObject; /** * JSON-P mapper provider. */ -@Priority(Prioritized.DEFAULT_PRIORITY) +@Weight(Weighted.DEFAULT_WEIGHT) public class JsonProcessingMapperProvider implements DbMapperProvider { @SuppressWarnings("unchecked") @Override diff --git a/grpc/core/src/main/java/io/helidon/grpc/core/PriorityBag.java b/grpc/core/src/main/java/io/helidon/grpc/core/PriorityBag.java index d66a08cfc58..48ee7300102 100644 --- a/grpc/core/src/main/java/io/helidon/grpc/core/PriorityBag.java +++ b/grpc/core/src/main/java/io/helidon/grpc/core/PriorityBag.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,6 @@ import java.util.TreeMap; import java.util.stream.Stream; -import io.helidon.common.Prioritized; - import jakarta.annotation.Priority; /** @@ -157,13 +155,9 @@ public void addAll(Iterable values, int priority) { */ public void add(T value) { if (value != null) { - int priority; - if (value instanceof Prioritized) { - priority = ((Prioritized) value).priority(); - } else { - Priority annotation = value.getClass().getAnnotation(Priority.class); - priority = annotation == null ? defaultPriority : annotation.value(); - } + Priority annotation = value.getClass().getAnnotation(Priority.class); + int priority = annotation == null ? defaultPriority : annotation.value(); + add(value, priority); } } diff --git a/grpc/core/src/test/java/io/helidon/grpc/core/PriorityBagTest.java b/grpc/core/src/test/java/io/helidon/grpc/core/PriorityBagTest.java index 5076e19c6e3..30acf687d11 100644 --- a/grpc/core/src/test/java/io/helidon/grpc/core/PriorityBagTest.java +++ b/grpc/core/src/test/java/io/helidon/grpc/core/PriorityBagTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ import java.util.Arrays; -import io.helidon.common.Prioritized; - import jakarta.annotation.Priority; import org.junit.jupiter.api.Test; @@ -145,21 +143,12 @@ public static class Value { } - public static class PrioritizedValue - implements Prioritized { - @Override - public int priority() { - return 2; - } + @Priority(2) + public static class PrioritizedValue { } - @Priority(0) - public static class AnnotatedPrioritizedValue - implements Prioritized { - @Override - public int priority() { - return 2; - } + @Priority(2) + public static class AnnotatedPrioritizedValue { } } diff --git a/integrations/vault/cdi/src/main/java/module-info.java b/integrations/vault/cdi/src/main/java/module-info.java index 4a5ebad038d..58f1c43fe37 100644 --- a/integrations/vault/cdi/src/main/java/module-info.java +++ b/integrations/vault/cdi/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/integrations/vault/vault/src/main/java/module-info.java b/integrations/vault/vault/src/main/java/module-info.java index 459305f6be0..3489af70aec 100644 --- a/integrations/vault/vault/src/main/java/module-info.java +++ b/integrations/vault/vault/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/media/common/src/main/java/io/helidon/media/common/MediaContext.java b/media/common/src/main/java/io/helidon/media/common/MediaContext.java index 742a414b018..127b4df2323 100644 --- a/media/common/src/main/java/io/helidon/media/common/MediaContext.java +++ b/media/common/src/main/java/io/helidon/media/common/MediaContext.java @@ -109,9 +109,9 @@ public static class Builder implements io.helidon.common.Builder services = HelidonServiceLoader .builder(ServiceLoader.load(MediaSupportProvider.class)); @@ -279,9 +279,9 @@ public MediaContext build() { this.services.useSystemServiceLoader(discoverServices); } if (registerDefaults) { - this.services.addService(new DefaultsProvider(), DEFAULTS_PRIORITY); + this.services.addService(new DefaultsProvider(), DEFAULTS_WEIGHT); } - this.services.defaultPriority(LOADER_PRIORITY) + this.services.defaultWeight(LOADER_WEIGHT) .addService(config -> new MediaSupport() { @Override public void register(MessageBodyReaderContext readerContext, MessageBodyWriterContext writerContext) { @@ -290,13 +290,13 @@ public void register(MessageBodyReaderContext readerContext, MessageBodyWriterCo builderWriters.forEach(writerContext::registerWriter); builderStreamWriter.forEach(writerContext::registerWriter); } - }, BUILDER_PRIORITY) + }, BUILDER_WEIGHT) .addService(config -> new MediaSupport() { @Override public void register(MessageBodyReaderContext readerContext, MessageBodyWriterContext writerContext) { mediaSupports.forEach(it -> it.register(readerContext, writerContext)); } - }, BUILDER_PRIORITY) + }, BUILDER_WEIGHT) .build() .asList() .stream() @@ -311,7 +311,7 @@ public void register(MessageBodyReaderContext readerContext, MessageBodyWriterCo private void filterServices() { HelidonServiceLoader.builder(ServiceLoader.load(MediaSupportProvider.class)) - .defaultPriority(LOADER_PRIORITY) + .defaultWeight(LOADER_WEIGHT) .build() .asList() .stream() diff --git a/metrics/api/src/main/java/io/helidon/metrics/api/RegistryFactoryManager.java b/metrics/api/src/main/java/io/helidon/metrics/api/RegistryFactoryManager.java index 7410bc9d2eb..7ec912de84b 100644 --- a/metrics/api/src/main/java/io/helidon/metrics/api/RegistryFactoryManager.java +++ b/metrics/api/src/main/java/io/helidon/metrics/api/RegistryFactoryManager.java @@ -22,8 +22,8 @@ import java.util.logging.Level; import java.util.logging.Logger; -import io.helidon.common.LazyValue; import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.LazyValue; import io.helidon.config.Config; import io.helidon.metrics.api.spi.RegistryFactoryProvider; @@ -78,7 +78,7 @@ class RegistryFactoryManager { private static RegistryFactoryProvider loadRegistryFactoryProvider() { RegistryFactoryProvider provider = HelidonServiceLoader.builder(ServiceLoader.load(RegistryFactoryProvider.class)) - .addService(NO_OP_FACTORY_PROVIDER, Integer.MAX_VALUE) + .addService(NO_OP_FACTORY_PROVIDER, 0) .build() .asList() .get(0); diff --git a/metrics/api/src/main/java/module-info.java b/metrics/api/src/main/java/module-info.java index 8c71ad29e38..cae574b7925 100644 --- a/metrics/api/src/main/java/module-info.java +++ b/metrics/api/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/metrics/service-api/src/main/java/io/helidon/metrics/serviceapi/MetricsSupportManager.java b/metrics/service-api/src/main/java/io/helidon/metrics/serviceapi/MetricsSupportManager.java index 9dbdc2e8f2a..1d898ad664a 100644 --- a/metrics/service-api/src/main/java/io/helidon/metrics/serviceapi/MetricsSupportManager.java +++ b/metrics/service-api/src/main/java/io/helidon/metrics/serviceapi/MetricsSupportManager.java @@ -19,8 +19,8 @@ import java.util.logging.Level; import java.util.logging.Logger; -import io.helidon.common.LazyValue; import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.LazyValue; import io.helidon.metrics.api.MetricsSettings; import io.helidon.metrics.serviceapi.spi.MetricsSupportProvider; import io.helidon.servicecommon.rest.RestServiceSettings; @@ -46,7 +46,7 @@ private MetricsSupportManager() { private static MetricsSupportProvider loadMetricsSupportProvider() { MetricsSupportProvider provider = HelidonServiceLoader.builder(ServiceLoader.load(MetricsSupportProvider.class)) - .addService(new MinimalMetricsSupportProviderImpl(), Integer.MAX_VALUE) + .addService(new MinimalMetricsSupportProviderImpl(), 0) .build() .asList() .get(0); diff --git a/metrics/service-api/src/main/java/module-info.java b/metrics/service-api/src/main/java/module-info.java index 77c4a60f061..14cdafc38b9 100644 --- a/metrics/service-api/src/main/java/module-info.java +++ b/metrics/service-api/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/microprofile/jwt-auth/src/main/java/io/helidon/microprofile/jwt/auth/JwtAuthAnnotationAnalyzer.java b/microprofile/jwt-auth/src/main/java/io/helidon/microprofile/jwt/auth/JwtAuthAnnotationAnalyzer.java index 71f50076aab..38548c2fbde 100644 --- a/microprofile/jwt-auth/src/main/java/io/helidon/microprofile/jwt/auth/JwtAuthAnnotationAnalyzer.java +++ b/microprofile/jwt-auth/src/main/java/io/helidon/microprofile/jwt/auth/JwtAuthAnnotationAnalyzer.java @@ -18,11 +18,11 @@ import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; -import io.helidon.common.Prioritized; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.Config; import io.helidon.security.providers.common.spi.AnnotationAnalyzer; -import jakarta.annotation.Priority; import jakarta.annotation.security.RolesAllowed; import org.eclipse.microprofile.auth.LoginConfig; @@ -32,8 +32,8 @@ * Implementation of {@link AnnotationAnalyzer} which checks for {@link LoginConfig} annotation if * JWT Authentication should be enabled. */ -// prioritized to run before RoleAnnotationAnalyzer, so we do not have to handle PermitAll -@Priority(Prioritized.DEFAULT_PRIORITY - 100) +// weighted to run before RoleAnnotationAnalyzer, so we do not have to handle PermitAll +@Weight(Weighted.DEFAULT_WEIGHT + 100) // Helidon service loader loaded and ordered public class JwtAuthAnnotationAnalyzer implements AnnotationAnalyzer { static final String LOGIN_CONFIG_METHOD = "MP-JWT"; diff --git a/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java b/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java index 2899e126b70..919e94c6441 100644 --- a/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java +++ b/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java @@ -39,10 +39,10 @@ import java.util.logging.Logger; import java.util.stream.Collectors; -import io.helidon.common.Prioritized; import io.helidon.common.configurable.ServerThreadPoolSupplier; import io.helidon.common.http.Http; import io.helidon.config.Config; +import io.helidon.config.mp.Prioritized; import io.helidon.microprofile.cdi.BuildTimeStart; import io.helidon.microprofile.cdi.RuntimeStart; import io.helidon.webserver.KeyPerformanceIndicatorSupport; diff --git a/security/abac/policy/src/main/java/module-info.java b/security/abac/policy/src/main/java/module-info.java index bdfcaf7d691..60a9b4f99ec 100644 --- a/security/abac/policy/src/main/java/module-info.java +++ b/security/abac/policy/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/security/abac/role/src/main/java/io/helidon/security/abac/role/RoleAnnotationAnalyzer.java b/security/abac/role/src/main/java/io/helidon/security/abac/role/RoleAnnotationAnalyzer.java index 7bd2cf000a2..14a7f456d63 100644 --- a/security/abac/role/src/main/java/io/helidon/security/abac/role/RoleAnnotationAnalyzer.java +++ b/security/abac/role/src/main/java/io/helidon/security/abac/role/RoleAnnotationAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,17 +17,17 @@ import java.lang.reflect.Method; -import io.helidon.common.Prioritized; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.security.providers.common.spi.AnnotationAnalyzer; -import jakarta.annotation.Priority; import jakarta.annotation.security.PermitAll; /** * Implementation of {@link AnnotationAnalyzer} which checks for {@link PermitAll} annotation if * authentication is needed or not. */ -@Priority(Prioritized.DEFAULT_PRIORITY) +@Weight(Weighted.DEFAULT_WEIGHT) // Helidon service loader loaded and ordered public class RoleAnnotationAnalyzer implements AnnotationAnalyzer { @Override diff --git a/security/integration/jersey-client/src/main/java/module-info.java b/security/integration/jersey-client/src/main/java/module-info.java index 55d1b1431ae..8717772ec4e 100644 --- a/security/integration/jersey-client/src/main/java/module-info.java +++ b/security/integration/jersey-client/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2021 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/AnalyzerUnitOne.java b/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/AnalyzerUnitOne.java index 210ab7c2a07..b176a207744 100644 --- a/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/AnalyzerUnitOne.java +++ b/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/AnalyzerUnitOne.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,13 @@ */ package io.helidon.security.integration.jersey; +import io.helidon.common.Weight; import io.helidon.security.providers.common.spi.AnnotationAnalyzer; -import jakarta.annotation.Priority; - /** * First annotation analyzer. */ -@Priority(10) +@Weight(100) public class AnalyzerUnitOne implements AnnotationAnalyzer { @Override public AnalyzerResponse analyze(Class maybeAnnotated) { diff --git a/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/AnalyzerUnitTwo.java b/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/AnalyzerUnitTwo.java index 4cc06be5415..45710af8624 100644 --- a/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/AnalyzerUnitTwo.java +++ b/security/integration/jersey/src/test/java/io/helidon/security/integration/jersey/AnalyzerUnitTwo.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021 Oracle and/or its affiliates. + * Copyright (c) 2019, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,14 +15,13 @@ */ package io.helidon.security.integration.jersey; +import io.helidon.common.Weight; import io.helidon.security.providers.common.spi.AnnotationAnalyzer; -import jakarta.annotation.Priority; - /** * Second annotation analyzer. */ -@Priority(100) +@Weight(10) public class AnalyzerUnitTwo implements AnnotationAnalyzer { @Override diff --git a/security/providers/abac/src/main/java/module-info.java b/security/providers/abac/src/main/java/module-info.java index dc4bfd52acc..8d1f79e8a71 100644 --- a/security/providers/abac/src/main/java/module-info.java +++ b/security/providers/abac/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/security/providers/common/src/main/java/io/helidon/security/providers/common/spi/AnnotationAnalyzer.java b/security/providers/common/src/main/java/io/helidon/security/providers/common/spi/AnnotationAnalyzer.java index a491a6299b0..8424b86dbed 100644 --- a/security/providers/common/src/main/java/io/helidon/security/providers/common/spi/AnnotationAnalyzer.java +++ b/security/providers/common/src/main/java/io/helidon/security/providers/common/spi/AnnotationAnalyzer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021 Oracle and/or its affiliates. + * Copyright (c) 2018, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/security/providers/config-vault/src/main/java/io/helidon/security/providers/config/vault/ConfigVaultProviderService.java b/security/providers/config-vault/src/main/java/io/helidon/security/providers/config/vault/ConfigVaultProviderService.java index e115632e3b0..93f6545f3f8 100644 --- a/security/providers/config-vault/src/main/java/io/helidon/security/providers/config/vault/ConfigVaultProviderService.java +++ b/security/providers/config-vault/src/main/java/io/helidon/security/providers/config/vault/ConfigVaultProviderService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,17 +16,17 @@ package io.helidon.security.providers.config.vault; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.Config; import io.helidon.security.spi.SecurityProvider; import io.helidon.security.spi.SecurityProviderService; -import jakarta.annotation.Priority; - /** - * Java Service Loader implementation of a {@link io.helidon.security.Security} provider service. + * Java Service Loader implementation of a {@link io.helidon.security.spi.SecurityProviderService} provider service. * Do not instantiate directly. */ -@Priority(5000) +@Weight(Weighted.DEFAULT_WEIGHT - 20) public class ConfigVaultProviderService implements SecurityProviderService { /** * @deprecated do not use, this should only be invoked by Java Service Loader diff --git a/security/security/src/main/java/io/helidon/security/Security.java b/security/security/src/main/java/io/helidon/security/Security.java index fd3bcd85425..bcd3e74d46c 100644 --- a/security/security/src/main/java/io/helidon/security/Security.java +++ b/security/security/src/main/java/io/helidon/security/Security.java @@ -38,9 +38,9 @@ import java.util.function.Supplier; import java.util.stream.Collectors; +import io.helidon.common.HelidonServiceLoader; import io.helidon.common.configurable.ThreadPoolSupplier; import io.helidon.common.reactive.Single; -import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.config.ConfigValue; import io.helidon.config.metadata.Configured; diff --git a/tracing/jaeger/src/main/java/io/helidon/tracing/jaeger/JaegerTracerProvider.java b/tracing/jaeger/src/main/java/io/helidon/tracing/jaeger/JaegerTracerProvider.java index 1398389a520..dcfe79aff7d 100644 --- a/tracing/jaeger/src/main/java/io/helidon/tracing/jaeger/JaegerTracerProvider.java +++ b/tracing/jaeger/src/main/java/io/helidon/tracing/jaeger/JaegerTracerProvider.java @@ -17,7 +17,8 @@ import java.util.Optional; -import io.helidon.common.Prioritized; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.tracing.Span; import io.helidon.tracing.Tracer; import io.helidon.tracing.opentelemetry.HelidonOpenTelemetry; @@ -25,12 +26,11 @@ import io.helidon.tracing.spi.TracerProvider; import io.opentelemetry.context.Context; -import jakarta.annotation.Priority; /** * Jaeger java service. */ -@Priority(Prioritized.DEFAULT_PRIORITY) +@Weight(Weighted.DEFAULT_WEIGHT) public class JaegerTracerProvider implements TracerProvider { @Override public Tracer global() { diff --git a/tracing/opentelemetry/src/main/java/io/helidon/tracing/opentelemetry/OpenTelemetryTracerProvider.java b/tracing/opentelemetry/src/main/java/io/helidon/tracing/opentelemetry/OpenTelemetryTracerProvider.java index 669826b854f..47c32eb19a1 100644 --- a/tracing/opentelemetry/src/main/java/io/helidon/tracing/opentelemetry/OpenTelemetryTracerProvider.java +++ b/tracing/opentelemetry/src/main/java/io/helidon/tracing/opentelemetry/OpenTelemetryTracerProvider.java @@ -21,7 +21,8 @@ import java.util.concurrent.atomic.AtomicReference; import io.helidon.common.LazyValue; -import io.helidon.common.Prioritized; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.common.context.Context; import io.helidon.common.context.Contexts; import io.helidon.tracing.Span; @@ -31,12 +32,11 @@ import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.OpenTelemetry; -import jakarta.annotation.Priority; /** * Service loader provider implementation for {@link io.helidon.tracing.spi.TracerProvider}. */ -@Priority(Prioritized.DEFAULT_PRIORITY + 1000) +@Weight(Weighted.DEFAULT_WEIGHT - 50) public class OpenTelemetryTracerProvider implements TracerProvider { private static final System.Logger LOGGER = System.getLogger(OpenTelemetryTracerProvider.class.getName()); diff --git a/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingProviderHelper.java b/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingProviderHelper.java index 412fbe81afb..9c353ee8d13 100644 --- a/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingProviderHelper.java +++ b/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingProviderHelper.java @@ -26,7 +26,7 @@ final class OpenTracingProviderHelper { private static final OpenTracingProvider TRACER_PROVIDER = HelidonServiceLoader.builder(ServiceLoader.load(OpenTracingProvider.class)) - .addService(NoOpBuilder::create, 100000) + .addService(NoOpBuilder::create, 0) .build() .iterator() .next(); diff --git a/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingTracerProvider.java b/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingTracerProvider.java index 18ec3245651..067031b117a 100644 --- a/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingTracerProvider.java +++ b/tracing/opentracing/src/main/java/io/helidon/tracing/opentracing/OpenTracingTracerProvider.java @@ -17,7 +17,8 @@ import java.util.Optional; -import io.helidon.common.Prioritized; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.tracing.Span; import io.helidon.tracing.Tracer; import io.helidon.tracing.TracerBuilder; @@ -25,13 +26,12 @@ import io.opentracing.noop.NoopSpan; import io.opentracing.util.GlobalTracer; -import jakarta.annotation.Priority; /** * {@link java.util.ServiceLoader} service implementation of {@link io.helidon.tracing.spi.TracerProvider} for Open Tracing * tracers. */ -@Priority(Prioritized.DEFAULT_PRIORITY + 2000) +@Weight(Weighted.DEFAULT_WEIGHT - 50) // low weight, so it is easy to override public class OpenTracingTracerProvider implements TracerProvider { @Override public TracerBuilder createBuilder() { diff --git a/tracing/tracer-resolver/src/main/java/io/helidon/tracing/tracerresolver/TracerResolverProvider.java b/tracing/tracer-resolver/src/main/java/io/helidon/tracing/tracerresolver/TracerResolverProvider.java index 4fad6e91c2d..24d47daa08a 100644 --- a/tracing/tracer-resolver/src/main/java/io/helidon/tracing/tracerresolver/TracerResolverProvider.java +++ b/tracing/tracer-resolver/src/main/java/io/helidon/tracing/tracerresolver/TracerResolverProvider.java @@ -16,17 +16,16 @@ package io.helidon.tracing.tracerresolver; -import io.helidon.common.Prioritized; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.tracing.opentracing.OpenTracingTracerBuilder; import io.helidon.tracing.opentracing.spi.OpenTracingProvider; -import jakarta.annotation.Priority; - /** * Service to use {@link io.opentracing.contrib.tracerresolver.TracerResolver} to find tracer to use with Helidon. */ // lower priority, so this get overridden by specific tracers if present -@Priority(Prioritized.DEFAULT_PRIORITY + 1000) +@Weight(Weighted.DEFAULT_WEIGHT - 60) public class TracerResolverProvider implements OpenTracingProvider { @Override public OpenTracingTracerBuilder createBuilder() { diff --git a/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java b/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java index 33b870817dd..a2907af39df 100644 --- a/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java +++ b/tracing/tracing/src/main/java/io/helidon/tracing/TracerProviderHelper.java @@ -33,7 +33,7 @@ final class TracerProviderHelper { TracerProvider provider = null; try { List allProviders = HelidonServiceLoader.builder(ServiceLoader.load(TracerProvider.class)) - .addService(new NoOpTracerProvider(), 100000) + .addService(new NoOpTracerProvider(), 0) .build() .asList(); diff --git a/tracing/zipkin/src/main/java/io/helidon/tracing/zipkin/ZipkinTracerProvider.java b/tracing/zipkin/src/main/java/io/helidon/tracing/zipkin/ZipkinTracerProvider.java index b254b210c8d..57706e985e9 100644 --- a/tracing/zipkin/src/main/java/io/helidon/tracing/zipkin/ZipkinTracerProvider.java +++ b/tracing/zipkin/src/main/java/io/helidon/tracing/zipkin/ZipkinTracerProvider.java @@ -20,19 +20,19 @@ import java.util.Optional; import java.util.logging.Logger; -import io.helidon.common.Prioritized; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.tracing.HeaderConsumer; import io.helidon.tracing.HeaderProvider; import io.helidon.tracing.opentracing.spi.OpenTracingProvider; import io.opentracing.SpanContext; import io.opentracing.Tracer; -import jakarta.annotation.Priority; /** * Zipkin java service. */ -@Priority(Prioritized.DEFAULT_PRIORITY) +@Weight(Weighted.DEFAULT_WEIGHT) public class ZipkinTracerProvider implements OpenTracingProvider { // original Zipkin headers (comes from old name of Zipkin - "BigBrotherBird", or "B3") static final String X_B3_TRACE_ID = "x-b3-traceid"; diff --git a/webclient/webclient/src/main/java/io/helidon/webclient/WebClient.java b/webclient/webclient/src/main/java/io/helidon/webclient/WebClient.java index ddba365b4f2..8ccb55c327b 100644 --- a/webclient/webclient/src/main/java/io/helidon/webclient/WebClient.java +++ b/webclient/webclient/src/main/java/io/helidon/webclient/WebClient.java @@ -26,9 +26,9 @@ import java.util.concurrent.TimeUnit; import java.util.function.Supplier; +import io.helidon.common.HelidonServiceLoader; import io.helidon.common.context.Context; import io.helidon.common.http.Http; -import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.media.common.MediaContext; import io.helidon.media.common.MediaContextBuilder; diff --git a/webclient/webclient/src/main/java/io/helidon/webclient/WebClientRequestBuilderImpl.java b/webclient/webclient/src/main/java/io/helidon/webclient/WebClientRequestBuilderImpl.java index 799ae0b740a..c444be769c3 100644 --- a/webclient/webclient/src/main/java/io/helidon/webclient/WebClientRequestBuilderImpl.java +++ b/webclient/webclient/src/main/java/io/helidon/webclient/WebClientRequestBuilderImpl.java @@ -44,6 +44,7 @@ import java.util.logging.Logger; import io.helidon.common.GenericType; +import io.helidon.common.HelidonServiceLoader; import io.helidon.common.context.Context; import io.helidon.common.context.Contexts; import io.helidon.common.context.spi.DataPropagationProvider; @@ -54,7 +55,6 @@ import io.helidon.common.http.MediaType; import io.helidon.common.http.Parameters; import io.helidon.common.reactive.Single; -import io.helidon.common.HelidonServiceLoader; import io.helidon.media.common.MessageBodyReadableContent; import io.helidon.media.common.MessageBodyReaderContext; import io.helidon.media.common.MessageBodyWriterContext; From 61efced89847918a6f16eb251b32e24e09f5e9a3 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Wed, 10 Aug 2022 02:07:14 +0200 Subject: [PATCH 7/9] Import order fixes. --- .../dbclient/src/main/java/io/helidon/dbclient/DbClient.java | 2 +- .../src/main/java/io/helidon/dbclient/DbMapperManager.java | 2 +- .../src/main/java/io/helidon/integrations/vault/Vault.java | 2 +- .../src/main/java/io/helidon/integrations/vault/VaultImpl.java | 2 +- .../io/helidon/microprofile/lra/CoordinatorLocatorService.java | 2 +- .../io/helidon/tracing/jersey/client/ClientTracingFilter.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java index ce42ee6c024..43256394121 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbClient.java @@ -21,10 +21,10 @@ import java.util.function.Function; import java.util.function.Supplier; +import io.helidon.common.HelidonServiceLoader; import io.helidon.common.mapper.MapperManager; import io.helidon.common.reactive.Single; import io.helidon.common.reactive.Subscribable; -import io.helidon.common.HelidonServiceLoader; import io.helidon.config.Config; import io.helidon.dbclient.spi.DbClientProvider; import io.helidon.dbclient.spi.DbClientProviderBuilder; diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java index b27f83b3a1b..67199b2428b 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java @@ -20,8 +20,8 @@ import java.util.ServiceLoader; import io.helidon.common.GenericType; -import io.helidon.common.mapper.MapperException; import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.mapper.MapperException; import io.helidon.dbclient.spi.DbMapperProvider; /** diff --git a/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/Vault.java b/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/Vault.java index 5b57864a7fa..3a5f8251245 100644 --- a/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/Vault.java +++ b/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/Vault.java @@ -21,8 +21,8 @@ import java.util.function.Consumer; import java.util.logging.Logger; -import io.helidon.common.http.Http; import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.http.Http; import io.helidon.config.Config; import io.helidon.faulttolerance.FaultTolerance; import io.helidon.faulttolerance.FtHandler; diff --git a/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/VaultImpl.java b/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/VaultImpl.java index 69db52766bc..87694c5d978 100644 --- a/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/VaultImpl.java +++ b/integrations/vault/vault/src/main/java/io/helidon/integrations/vault/VaultImpl.java @@ -22,8 +22,8 @@ import java.util.ServiceLoader; import java.util.logging.Logger; -import io.helidon.common.LazyValue; import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.LazyValue; import io.helidon.config.Config; import io.helidon.integrations.common.rest.RestApi; import io.helidon.integrations.vault.spi.AuthMethodProvider; diff --git a/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/CoordinatorLocatorService.java b/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/CoordinatorLocatorService.java index b9648dc9aac..c0c9c01d192 100644 --- a/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/CoordinatorLocatorService.java +++ b/microprofile/lra/jax-rs/src/main/java/io/helidon/microprofile/lra/CoordinatorLocatorService.java @@ -24,8 +24,8 @@ import java.util.function.Supplier; import java.util.stream.Collectors; -import io.helidon.common.Reflected; import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.Reflected; import io.helidon.lra.coordinator.client.CoordinatorClient; import jakarta.enterprise.context.ApplicationScoped; diff --git a/tracing/jersey-client/src/main/java/io/helidon/tracing/jersey/client/ClientTracingFilter.java b/tracing/jersey-client/src/main/java/io/helidon/tracing/jersey/client/ClientTracingFilter.java index 781e5459c6f..be6a308e1f3 100644 --- a/tracing/jersey-client/src/main/java/io/helidon/tracing/jersey/client/ClientTracingFilter.java +++ b/tracing/jersey-client/src/main/java/io/helidon/tracing/jersey/client/ClientTracingFilter.java @@ -24,8 +24,8 @@ import java.util.Optional; import java.util.ServiceLoader; -import io.helidon.common.context.Contexts; import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.context.Contexts; import io.helidon.tracing.HeaderConsumer; import io.helidon.tracing.HeaderProvider; import io.helidon.tracing.Scope; From 09c6c6b3e62f01ae92080411060a8f2670bb2ea4 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Wed, 10 Aug 2022 11:00:31 +0200 Subject: [PATCH 8/9] Javadoc fixes --- .../java/io/helidon/config/hocon/package-info.java | 6 +++--- .../main/java/io/helidon/dbclient/DbMapperManager.java | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config/hocon/src/main/java/io/helidon/config/hocon/package-info.java b/config/hocon/src/main/java/io/helidon/config/hocon/package-info.java index f83df69976f..51548d11426 100644 --- a/config/hocon/src/main/java/io/helidon/config/hocon/package-info.java +++ b/config/hocon/src/main/java/io/helidon/config/hocon/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates. + * Copyright (c) 2017, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,9 @@ * The parser implementation supports {@link java.util.ServiceLoader}, i.e. {@link io.helidon.config.Config.Builder} * can automatically load and register HOCON ConfigParser instance, * if not {@link io.helidon.config.Config.Builder#disableParserServices() disabled}. - * Priority of the parser to be used by {@link io.helidon.config.Config.Builder}, + * Weight of the parser to be used by {@link io.helidon.config.Config.Builder}, * if loaded automatically as a {@link java.util.ServiceLoader service}, - * is {@value io.helidon.config.hocon.HoconConfigParser#PRIORITY}. + * is {@value io.helidon.config.hocon.HoconConfigParser#WEIGHT}. * And of course it can be {@link io.helidon.config.Config.Builder#addParser(io.helidon.config.spi.ConfigParser) * registered programmatically} using {@link io.helidon.config.hocon.HoconConfigParserBuilder builder API}. *

diff --git a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java index 67199b2428b..6822634fa5b 100644 --- a/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java +++ b/dbclient/dbclient/src/main/java/io/helidon/dbclient/DbMapperManager.java @@ -150,13 +150,13 @@ public Builder addMapperProvider(DbMapperProvider provider) { * Add a mapper provider with custom priority. * * @param provider provider - * @param priority priority to use + * @param weight weight to use * @return updated builder instance - * @see io.helidon.common.Prioritized - * @see jakarta.annotation.Priority + * @see io.helidon.common.Weighted + * @see io.helidon.common.Weight */ - public Builder addMapperProvider(DbMapperProvider provider, int priority) { - this.providers.addService(provider, priority); + public Builder addMapperProvider(DbMapperProvider provider, int weight) { + this.providers.addService(provider, weight); return this; } From 4f3a00ee0066915d5eeca8cd8fe83b48abfa7e87 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Wed, 10 Aug 2022 15:28:44 +0200 Subject: [PATCH 9/9] Use @Weight instead of @Priority for Vault --- .../src/main/java/io/helidon/common/Weights.java | 16 ++++++++++------ .../vault/auths/approle/AppRoleVaultAuth.java | 8 ++++---- .../vault/auths/common/NoVaultAuth.java | 7 +++---- .../vault/auths/k8s/K8sVaultAuth.java | 8 ++++---- .../vault/auths/token/TokenVaultAuth.java | 8 ++++---- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/common/common/src/main/java/io/helidon/common/Weights.java b/common/common/src/main/java/io/helidon/common/Weights.java index 6cd38340e8d..03b23e94da3 100644 --- a/common/common/src/main/java/io/helidon/common/Weights.java +++ b/common/common/src/main/java/io/helidon/common/Weights.java @@ -22,6 +22,9 @@ * Weight utilities. */ public final class Weights { + // used to identify components that do not have a weight + private static final double INVALID_WEIGHT = -101; + private Weights() { } @@ -117,10 +120,10 @@ public static Comparator weightComparator() { return -1; } - double firstWeight = find(o1, -101); - double secondWeight = find(o2, -101); + double firstWeight = find(o1, INVALID_WEIGHT); + double secondWeight = find(o2, INVALID_WEIGHT); - if (firstWeight != -101 && secondWeight != -101) { + if (firstWeight != INVALID_WEIGHT && secondWeight != INVALID_WEIGHT) { // both are weighted if (firstWeight != secondWeight) { // only return if they differ @@ -128,15 +131,16 @@ public static Comparator weightComparator() { } } - if (firstWeight != -101 && secondWeight != -101) { + if (firstWeight != INVALID_WEIGHT && secondWeight != INVALID_WEIGHT) { + // same weight, compare based on class name return o1.getClass().getName().compareTo(o2.getClass().getName()); } // both are non-null and at least one of them is NOT weighted - if (firstWeight != -101) { + if (firstWeight != INVALID_WEIGHT) { return -1; } - if (secondWeight != -101) { + if (secondWeight != INVALID_WEIGHT) { return 1; } diff --git a/integrations/vault/auths/approle/src/main/java/io/helidon/integrations/vault/auths/approle/AppRoleVaultAuth.java b/integrations/vault/auths/approle/src/main/java/io/helidon/integrations/vault/auths/approle/AppRoleVaultAuth.java index a9beba5864e..b57204ba657 100644 --- a/integrations/vault/auths/approle/src/main/java/io/helidon/integrations/vault/auths/approle/AppRoleVaultAuth.java +++ b/integrations/vault/auths/approle/src/main/java/io/helidon/integrations/vault/auths/approle/AppRoleVaultAuth.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ import java.util.Optional; import java.util.logging.Logger; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.Config; import io.helidon.integrations.common.rest.RestApi; import io.helidon.integrations.vault.Vault; @@ -26,12 +28,10 @@ import io.helidon.integrations.vault.auths.common.NoVaultAuth; import io.helidon.integrations.vault.spi.VaultAuth; -import jakarta.annotation.Priority; - /** * Vault authentication for AppRole. */ -@Priority(1000) +@Weight(Weighted.DEFAULT_WEIGHT + 100) public class AppRoleVaultAuth implements VaultAuth { private static final Logger LOGGER = Logger.getLogger(AppRoleVaultAuth.class.getName()); diff --git a/integrations/vault/auths/common/src/main/java/io/helidon/integrations/vault/auths/common/NoVaultAuth.java b/integrations/vault/auths/common/src/main/java/io/helidon/integrations/vault/auths/common/NoVaultAuth.java index 99cbff88891..70be3e31f22 100644 --- a/integrations/vault/auths/common/src/main/java/io/helidon/integrations/vault/auths/common/NoVaultAuth.java +++ b/integrations/vault/auths/common/src/main/java/io/helidon/integrations/vault/auths/common/NoVaultAuth.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,18 +18,17 @@ import java.util.Optional; +import io.helidon.common.Weight; import io.helidon.config.Config; import io.helidon.integrations.common.rest.RestApi; import io.helidon.integrations.vault.Vault; import io.helidon.integrations.vault.VaultApiException; import io.helidon.integrations.vault.spi.VaultAuth; -import jakarta.annotation.Priority; - /** * Java Service Loader implementation for creating an unauthenticated Vault instance. */ -@Priority(10000) +@Weight(1) public class NoVaultAuth implements VaultAuth { /** * Required for service loader. diff --git a/integrations/vault/auths/k8s/src/main/java/io/helidon/integrations/vault/auths/k8s/K8sVaultAuth.java b/integrations/vault/auths/k8s/src/main/java/io/helidon/integrations/vault/auths/k8s/K8sVaultAuth.java index d2b9ea1c30f..c9fe6058f8a 100644 --- a/integrations/vault/auths/k8s/src/main/java/io/helidon/integrations/vault/auths/k8s/K8sVaultAuth.java +++ b/integrations/vault/auths/k8s/src/main/java/io/helidon/integrations/vault/auths/k8s/K8sVaultAuth.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,8 @@ import java.util.Optional; import java.util.logging.Logger; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.Config; import io.helidon.integrations.common.rest.RestApi; import io.helidon.integrations.vault.Vault; @@ -30,12 +32,10 @@ import io.helidon.integrations.vault.auths.common.NoVaultAuth; import io.helidon.integrations.vault.spi.VaultAuth; -import jakarta.annotation.Priority; - /** * Vault authentication for Kubernetes (k8s). */ -@Priority(2000) +@Weight(Weighted.DEFAULT_WEIGHT + 50) public class K8sVaultAuth implements VaultAuth { private static final Logger LOGGER = Logger.getLogger(K8sVaultAuth.class.getName()); diff --git a/integrations/vault/auths/token/src/main/java/io/helidon/integrations/vault/auths/token/TokenVaultAuth.java b/integrations/vault/auths/token/src/main/java/io/helidon/integrations/vault/auths/token/TokenVaultAuth.java index f171109cb3b..9d392301667 100644 --- a/integrations/vault/auths/token/src/main/java/io/helidon/integrations/vault/auths/token/TokenVaultAuth.java +++ b/integrations/vault/auths/token/src/main/java/io/helidon/integrations/vault/auths/token/TokenVaultAuth.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. + * Copyright (c) 2021, 2022 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ import java.util.Optional; import java.util.logging.Logger; +import io.helidon.common.Weight; +import io.helidon.common.Weighted; import io.helidon.config.Config; import io.helidon.integrations.common.rest.RestApi; import io.helidon.integrations.vault.Vault; @@ -26,14 +28,12 @@ import io.helidon.integrations.vault.auths.common.VaultRestApi; import io.helidon.integrations.vault.spi.VaultAuth; -import jakarta.annotation.Priority; - /** * Java Service Loader implementation for authenticating using a token. * You can create a new instance using {@link #builder()}. * To use a custom built instance, use {@link Vault.Builder#addVaultAuth(io.helidon.integrations.vault.spi.VaultAuth)}. */ -@Priority(5000) +@Weight(Weighted.DEFAULT_WEIGHT) public class TokenVaultAuth implements VaultAuth { private static final Logger LOGGER = Logger.getLogger(TokenVaultAuth.class.getName()); private final String token;