From 14b2c924fa3cdae0e58a9271d76cb55a036f4e6a Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Fri, 23 Jun 2023 21:32:32 +0200 Subject: [PATCH 1/3] Helidon main class. --- bom/pom.xml | 5 + .../java/io/helidon/config/ConfigMappers.java | 3 +- .../examples/nima/faulttolerance/FtMain.java | 27 +--- examples/nima/imperative/pom.xml | 16 -- .../nima/imperative/ImperativeMain.java | 4 +- helidon/pom.xml | 39 +++++ helidon/src/main/java/io/helidon/Main.java | 15 ++ .../helidon/spi/HelidonStartupProvider.java | 15 ++ .../micrometer/MeterRegistryFactory.java | 7 +- .../MicrometerBuiltInRegistrySupport.java | 5 +- .../micrometer/MicrometerFeature.java | 5 +- .../MicrometerPrometheusRegistrySupport.java | 5 +- .../servicecommon/ConfiguredTestSupport.java | 3 +- nima/common/api/pom.xml | 43 +++++ .../io/helidon/nima/common/api/Startable.java | 29 ++-- .../helidon/nima/common/api/package-info.java | 20 +++ .../common/api/src/main/java/module-info.java | 24 +++ nima/common/pom.xml | 3 +- nima/nima/pom.xml | 58 +++++++ .../java/io/helidon/nima/ConfigProvider.java | 70 ++++++++ .../main/java/io/helidon/nima/Helidon.java | 149 ++++++++++++++++++ .../src/main/java/io/helidon/nima/Nima.java | 59 ------- nima/nima/src/main/java/module-info.java | 10 ++ .../test/java/io/helidon/nima/NimaTest.java | 64 ++++++++ .../io/helidon/nima/TestConfigSource.java | 44 ++++++ nima/nima/src/test/resources/application.yaml | 22 +++ .../observe/config/ConfigObserveProvider.java | 2 +- .../nima/observe/config/ConfigService.java | 10 +- .../nima/observe/health/HealthFeature.java | 21 +-- .../observe/health/HealthObserveProvider.java | 2 +- .../observe/info/InfoObserveProvider.java | 2 +- .../nima/observe/info/InfoService.java | 2 +- .../nima/observe/log/LogObserveProvider.java | 2 +- .../helidon/nima/observe/log/LogService.java | 2 +- .../metrics/MetricsObserveProvider.java | 2 +- .../helidon/nima/observe/ObserveFeature.java | 10 +- .../nima/observe/spi/ObserveProvider.java | 2 +- .../servicecommon/HelidonFeatureSupport.java | 4 +- nima/tests/integration/imperative/pom.xml | 110 +++++++++++++ .../imperative/ImperativeMain.java | 54 +++++++ .../src/main/resources/application.yaml | 23 +++ .../imperative/ImperativeMainTest.java | 61 +++++++ nima/tests/integration/pom.xml | 1 + .../nima/webserver/cors/CorsSupport.java | 2 +- nima/webserver/webserver/pom.xml | 4 + .../io/helidon/nima/webserver/LoomServer.java | 10 +- .../webserver/src/main/java/module-info.java | 1 + pico/runtime/src/main/java/module-info.java | 1 + pom.xml | 1 + 49 files changed, 899 insertions(+), 174 deletions(-) create mode 100644 helidon/pom.xml create mode 100644 helidon/src/main/java/io/helidon/Main.java create mode 100644 helidon/src/main/java/io/helidon/spi/HelidonStartupProvider.java create mode 100644 nima/common/api/pom.xml rename examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/ConfigService.java => nima/common/api/src/main/java/io/helidon/nima/common/api/Startable.java (54%) create mode 100644 nima/common/api/src/main/java/io/helidon/nima/common/api/package-info.java create mode 100644 nima/common/api/src/main/java/module-info.java create mode 100644 nima/nima/src/main/java/io/helidon/nima/ConfigProvider.java create mode 100644 nima/nima/src/main/java/io/helidon/nima/Helidon.java delete mode 100644 nima/nima/src/main/java/io/helidon/nima/Nima.java create mode 100644 nima/nima/src/test/java/io/helidon/nima/NimaTest.java create mode 100644 nima/nima/src/test/java/io/helidon/nima/TestConfigSource.java create mode 100644 nima/nima/src/test/resources/application.yaml create mode 100644 nima/tests/integration/imperative/pom.xml create mode 100644 nima/tests/integration/imperative/src/main/java/io/helidon/nima/tests/integration/imperative/ImperativeMain.java create mode 100644 nima/tests/integration/imperative/src/main/resources/application.yaml create mode 100644 nima/tests/integration/imperative/src/test/java/io/helidon/nima/tests/integration/imperative/ImperativeMainTest.java diff --git a/bom/pom.xml b/bom/pom.xml index 083bb51b51a..6f53de7a4b1 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -1180,6 +1180,11 @@ helidon-nima ${helidon.version} + + io.helidon.nima.common + helidon-nima-common-api + ${helidon.version} + io.helidon.nima.common helidon-nima-common-tls diff --git a/config/config/src/main/java/io/helidon/config/ConfigMappers.java b/config/config/src/main/java/io/helidon/config/ConfigMappers.java index eba5a4ec568..0713e4b1792 100644 --- a/config/config/src/main/java/io/helidon/config/ConfigMappers.java +++ b/config/config/src/main/java/io/helidon/config/ConfigMappers.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2022 Oracle and/or its affiliates. + * Copyright (c) 2017, 2023 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. @@ -81,6 +81,7 @@ private ConfigMappers() { private static Map, Function> initEssentialMappers() { return Map.of(Config.class, (node) -> node, + io.helidon.common.config.Config.class, (node) -> node, String.class, wrap(value -> value), OptionalInt.class, ConfigMappers::optionalIntEssential, OptionalLong.class, ConfigMappers::optionalLongEssential, diff --git a/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/FtMain.java b/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/FtMain.java index 25b1e1d13f7..f573ffa7a36 100644 --- a/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/FtMain.java +++ b/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/FtMain.java @@ -16,11 +16,7 @@ package io.helidon.examples.nima.faulttolerance; -import io.helidon.config.Config; -import io.helidon.config.ConfigSources; -import io.helidon.logging.common.LogConfig; -import io.helidon.pico.api.Bootstrap; -import io.helidon.pico.api.PicoServices; +import io.helidon.nima.Helidon; /** * Main class of the example, starts Helidon with injection support. @@ -35,25 +31,6 @@ private FtMain() { * @param args ignored */ public static void main(String[] args) { - // TODO move to a helidon-inject-runtime module (or similar) to set everything up - LogConfig.configureRuntime(); - - Config config = Config.builder() - .addSource(ConfigSources.classpath("application.yaml")) - .disableSystemPropertiesSource() - .disableEnvironmentVariablesSource() - .build(); - - ConfigService.config(config); - - Bootstrap bootstrap = Bootstrap.builder() - .config(config) - .build(); - - PicoServices.globalBootstrap(bootstrap); - - PicoServices picoServices = PicoServices.picoServices().get(); - // this line is needed! - picoServices.services(); + Helidon.start(); } } diff --git a/examples/nima/imperative/pom.xml b/examples/nima/imperative/pom.xml index 3ffc0a8e763..0b7a1b0f39a 100644 --- a/examples/nima/imperative/pom.xml +++ b/examples/nima/imperative/pom.xml @@ -35,26 +35,10 @@ - - io.helidon.nima - helidon-nima - io.helidon.nima.webserver helidon-nima-webserver - - io.helidon.pico - helidon-pico-api - - - io.helidon.pico - helidon-pico-runtime - - - io.helidon.pico.configdriven - helidon-pico-configdriven-runtime - io.helidon.config helidon-config-yaml diff --git a/examples/nima/imperative/src/main/java/io/helidon/examples/nima/imperative/ImperativeMain.java b/examples/nima/imperative/src/main/java/io/helidon/examples/nima/imperative/ImperativeMain.java index 84581ae521b..864a9d097d1 100644 --- a/examples/nima/imperative/src/main/java/io/helidon/examples/nima/imperative/ImperativeMain.java +++ b/examples/nima/imperative/src/main/java/io/helidon/examples/nima/imperative/ImperativeMain.java @@ -17,8 +17,8 @@ package io.helidon.examples.nima.imperative; import io.helidon.common.config.Config; +import io.helidon.common.config.GlobalConfig; import io.helidon.common.http.Http; -import io.helidon.nima.Nima; import io.helidon.nima.webserver.WebServer; import io.helidon.nima.webserver.http.HttpRouting; @@ -35,7 +35,7 @@ private ImperativeMain() { * @param args ignored */ public static void main(String[] args) { - Config config = Nima.config(); + Config config = GlobalConfig.config(); WebServer server = WebServer.create(ws -> ws.config(config.get("server")) .routing(ImperativeMain::routing)) diff --git a/helidon/pom.xml b/helidon/pom.xml new file mode 100644 index 00000000000..b3d880e3ecc --- /dev/null +++ b/helidon/pom.xml @@ -0,0 +1,39 @@ + + + + + 4.0.0 + + io.helidon + helidon-project + 4.0.0-SNAPSHOT + + + helidon + Helidon + + Helidon main entry point + + + + io.helidon.common + helidon-common + + + diff --git a/helidon/src/main/java/io/helidon/Main.java b/helidon/src/main/java/io/helidon/Main.java new file mode 100644 index 00000000000..abb6043c6cd --- /dev/null +++ b/helidon/src/main/java/io/helidon/Main.java @@ -0,0 +1,15 @@ +package io.helidon; + +/** + * Main entry point for any Helidon application that is discovering services. + */ +public class Main { + /** + * Start Helidon. + * + * @param args arguments of the application + */ + public static void main(String[] args) { + + } +} diff --git a/helidon/src/main/java/io/helidon/spi/HelidonStartupProvider.java b/helidon/src/main/java/io/helidon/spi/HelidonStartupProvider.java new file mode 100644 index 00000000000..48a8968a5be --- /dev/null +++ b/helidon/src/main/java/io/helidon/spi/HelidonStartupProvider.java @@ -0,0 +1,15 @@ +package io.helidon.spi; + +/** + * {@link java.util.ServiceLoader} provider interface to discover the correct startup type. + * Only the first provider (with the highest {@link io.helidon.common.Weight}) will be used. + * The default startup will create Helidon Injection service registry, and start all services that should be started. + */ +public interface HelidonStartupProvider { + /** + * Start the runtime. + * + * @param arguments command line arguments + */ + void start(String[] arguments); +} diff --git a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java index 9466e4a0c24..d07ec4c4744 100644 --- a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java +++ b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.helidon.integrations.micrometer; import java.util.ArrayList; @@ -27,6 +28,7 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; +import io.helidon.common.config.Config; import io.helidon.common.http.Http; import io.helidon.config.Config; import io.helidon.nima.webserver.http.Handler; @@ -266,7 +268,8 @@ public MeterRegistryFactory build() { public Builder config(Config config) { config.get(BUILTIN_REGISTRIES_CONFIG_KEY) - .ifExists(this::enrollBuiltInRegistries); + .as(Config.class) + .ifPresent(this::enrollBuiltInRegistries); return this; } @@ -357,7 +360,7 @@ private void enrollBuiltInRegistries(Config registriesConfig) { BuiltInRegistryType.valueByName(registryType); MicrometerBuiltInRegistrySupport builtInRegistrySupport = - MicrometerBuiltInRegistrySupport.create(type, registryConfig.asNode()); + MicrometerBuiltInRegistrySupport.create(type, registryConfig.as(Config.class)); candidateBuiltInRegistryTypes.put(type, builtInRegistrySupport); } catch (BuiltInRegistryType.UnrecognizedBuiltInRegistryTypeException e) { diff --git a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerBuiltInRegistrySupport.java b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerBuiltInRegistrySupport.java index f51ff62d3b8..0c18dec8424 100644 --- a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerBuiltInRegistrySupport.java +++ b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerBuiltInRegistrySupport.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.helidon.integrations.micrometer; import java.util.Collections; @@ -20,8 +21,8 @@ import java.util.Optional; import java.util.function.Function; -import io.helidon.config.Config; -import io.helidon.config.ConfigValue; +import io.helidon.common.config.Config; +import io.helidon.common.config.ConfigValue; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.config.MeterRegistryConfig; diff --git a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerFeature.java b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerFeature.java index e1de7217e67..ed7629a9703 100644 --- a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerFeature.java +++ b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerFeature.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. + * Copyright (c) 2022, 2023 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,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.helidon.integrations.micrometer; import java.util.function.Supplier; +import io.helidon.common.config.Config; import io.helidon.common.context.Contexts; -import io.helidon.config.Config; import io.helidon.config.metadata.Configured; import io.helidon.nima.servicecommon.HelidonFeatureSupport; import io.helidon.nima.webserver.http.HttpRouting; diff --git a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerPrometheusRegistrySupport.java b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerPrometheusRegistrySupport.java index 38d309ee4df..644f4fa32b7 100644 --- a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerPrometheusRegistrySupport.java +++ b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MicrometerPrometheusRegistrySupport.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package io.helidon.integrations.micrometer; import java.io.IOException; @@ -21,9 +22,9 @@ import java.util.Optional; import java.util.function.Function; +import io.helidon.common.config.Config; +import io.helidon.common.config.ConfigValue; import io.helidon.common.media.type.MediaTypes; -import io.helidon.config.Config; -import io.helidon.config.ConfigValue; import io.micrometer.core.instrument.MeterRegistry; import io.micrometer.core.instrument.config.MeterRegistryConfig; diff --git a/microprofile/service-common/src/test/java/io/helidon/microprofile/servicecommon/ConfiguredTestSupport.java b/microprofile/service-common/src/test/java/io/helidon/microprofile/servicecommon/ConfiguredTestSupport.java index 647598b0d7d..ef63e539d30 100644 --- a/microprofile/service-common/src/test/java/io/helidon/microprofile/servicecommon/ConfiguredTestSupport.java +++ b/microprofile/service-common/src/test/java/io/helidon/microprofile/servicecommon/ConfiguredTestSupport.java @@ -17,7 +17,6 @@ import java.util.Optional; -import io.helidon.config.Config; import io.helidon.nima.servicecommon.HelidonFeatureSupport; import io.helidon.nima.webserver.http.HttpService; @@ -69,7 +68,7 @@ public ConfiguredTestSupport build() { } @Override - public Builder config(Config config) { + public Builder config(io.helidon.common.config.Config config) { super.config(config); config.get("importance").asInt().ifPresent(this::importance); return this; diff --git a/nima/common/api/pom.xml b/nima/common/api/pom.xml new file mode 100644 index 00000000000..ed2570b5569 --- /dev/null +++ b/nima/common/api/pom.xml @@ -0,0 +1,43 @@ + + + + + 4.0.0 + + + io.helidon.nima.common + helidon-nima-common-project + 4.0.0-SNAPSHOT + ../pom.xml + + + helidon-nima-common-api + Helidon Níma Common API + APIs need for any Níma feature, independent on WebServer + + + + io.helidon.pico + helidon-pico-api + true + + + diff --git a/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/ConfigService.java b/nima/common/api/src/main/java/io/helidon/nima/common/api/Startable.java similarity index 54% rename from examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/ConfigService.java rename to nima/common/api/src/main/java/io/helidon/nima/common/api/Startable.java index a93fdd35459..347e137e3bf 100644 --- a/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/ConfigService.java +++ b/nima/common/api/src/main/java/io/helidon/nima/common/api/Startable.java @@ -14,26 +14,19 @@ * limitations under the License. */ -package io.helidon.examples.nima.faulttolerance; +package io.helidon.nima.common.api; -import io.helidon.config.Config; - -import jakarta.inject.Provider; -import jakarta.inject.Singleton; +import io.helidon.pico.api.Contract; /** - * This service will be part of Níma on Pico module. - * It may use pico to get config sources exposed through pico. + * Some components may require start when Helidon is bootstrapped, such as WebServer (to open server sockets). + * This interface is a Helidon Injection contract, that allows us to discover all startable services and start them + * on boot when desired. */ -@Singleton -class ConfigService implements Provider { - private static volatile Config config; - static void config(Config config) { - ConfigService.config = config; - } - - @Override - public Config get() { - return config; - } +@Contract +public interface Startable { + /** + * Start this service. + */ + void startService(); } diff --git a/nima/common/api/src/main/java/io/helidon/nima/common/api/package-info.java b/nima/common/api/src/main/java/io/helidon/nima/common/api/package-info.java new file mode 100644 index 00000000000..a9fa16d7f36 --- /dev/null +++ b/nima/common/api/src/main/java/io/helidon/nima/common/api/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 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. + */ + +/** + * APIs shared across all Helidon features that are injection based. + */ +package io.helidon.nima.common.api; diff --git a/nima/common/api/src/main/java/module-info.java b/nima/common/api/src/main/java/module-info.java new file mode 100644 index 00000000000..59dc72b949f --- /dev/null +++ b/nima/common/api/src/main/java/module-info.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 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. + */ + +/** + * APIs for Helidon features. + */ +module io.helidon.nima.common.api { + requires static io.helidon.pico.api; + + exports io.helidon.nima.common.api; +} \ No newline at end of file diff --git a/nima/common/pom.xml b/nima/common/pom.xml index 16a7ed5a7ed..e56654387a6 100644 --- a/nima/common/pom.xml +++ b/nima/common/pom.xml @@ -1,7 +1,7 @@ + + 4.0.0 + + io.helidon.nima.tests.integration + helidon-nima-tests-integration-project + 4.0.0-SNAPSHOT + ../pom.xml + + + helidon-nima-tests-integration-imperative + Helidon Níma Tests Integration Imperative + Validation of imperative APIs and their dependencies + + + + io.helidon.nima.webserver + helidon-nima-webserver + + + io.helidon.config + helidon-config-yaml + + + org.junit.jupiter + junit-jupiter-api + test + + + org.hamcrest + hamcrest-all + test + + + io.helidon.nima.testing.junit5 + helidon-nima-testing-junit5-webserver + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + --enable-preview + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-config-not-included + + enforce + + + + + + + io.helidon.pico:helidon-pico-runtime + io.helidon.pico.configdriven:helidon-configdriven-runtime + + + + true + + + + + + + diff --git a/nima/tests/integration/imperative/src/main/java/io/helidon/nima/tests/integration/imperative/ImperativeMain.java b/nima/tests/integration/imperative/src/main/java/io/helidon/nima/tests/integration/imperative/ImperativeMain.java new file mode 100644 index 00000000000..47ec6622f61 --- /dev/null +++ b/nima/tests/integration/imperative/src/main/java/io/helidon/nima/tests/integration/imperative/ImperativeMain.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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.nima.tests.integration.imperative; + +import io.helidon.common.config.Config; +import io.helidon.common.config.GlobalConfig; +import io.helidon.common.http.Http; +import io.helidon.nima.webserver.WebServer; +import io.helidon.nima.webserver.http.HttpRouting; + +/** + * Main class of this example, starts the server. + */ +public final class ImperativeMain { + private ImperativeMain() { + } + + /** + * Start the example. + * + * @param args ignored + */ + public static void main(String[] args) { + Config config = GlobalConfig.config(); + + WebServer server = WebServer.create(ws -> ws.config(config.get("server")) + .routing(ImperativeMain::routing)) + .start(); + + System.out.println("Server started. Server configuration: " + server.prototype()); + } + + static void routing(HttpRouting.Builder routing) { + Http.Method list = Http.Method.create("LIST"); + + routing.get("/", (req, res) -> res.send("Hello World!")) + .route(list, "/", (req, res) -> res.send("lll")) + .route(list, (req, res) -> res.send("listed")); + } +} diff --git a/nima/tests/integration/imperative/src/main/resources/application.yaml b/nima/tests/integration/imperative/src/main/resources/application.yaml new file mode 100644 index 00000000000..0be2a0894dc --- /dev/null +++ b/nima/tests/integration/imperative/src/main/resources/application.yaml @@ -0,0 +1,23 @@ +# +# Copyright (c) 2023 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. +# + +server: + host: "localhost" + port: 0 + sockets: + - name: "admin" + host: "localhost" + port: 0 diff --git a/nima/tests/integration/imperative/src/test/java/io/helidon/nima/tests/integration/imperative/ImperativeMainTest.java b/nima/tests/integration/imperative/src/test/java/io/helidon/nima/tests/integration/imperative/ImperativeMainTest.java new file mode 100644 index 00000000000..1bb63e4c9bd --- /dev/null +++ b/nima/tests/integration/imperative/src/test/java/io/helidon/nima/tests/integration/imperative/ImperativeMainTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2023 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.nima.tests.integration.imperative; + +import io.helidon.nima.testing.junit5.webserver.ServerTest; +import io.helidon.nima.testing.junit5.webserver.SetUpRoute; +import io.helidon.nima.testing.junit5.webserver.Socket; +import io.helidon.nima.webclient.http1.Http1Client; +import io.helidon.nima.webserver.http.HttpRouting; + +import org.junit.jupiter.api.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +@ServerTest +class ImperativeMainTest { + private final Http1Client mainClient; + private final Http1Client adminClient; + + ImperativeMainTest(Http1Client mainClient, @Socket("admin") Http1Client adminClient) { + this.mainClient = mainClient; + this.adminClient = adminClient; + } + + @SetUpRoute + static void setUpRoute(HttpRouting.Builder routing) { + ImperativeMain.routing(routing); + } + + @Test + void testMainSocket() { + testSocket(mainClient); + } + + @Test + void testAdminSocket() { + testSocket(adminClient); + } + + private void testSocket(Http1Client client) { + String response = client.get() + .request(String.class); + + assertThat(response, is("Hello World!")); + } +} \ No newline at end of file diff --git a/nima/tests/integration/pom.xml b/nima/tests/integration/pom.xml index 3ee673d8936..9fca6b3c219 100644 --- a/nima/tests/integration/pom.xml +++ b/nima/tests/integration/pom.xml @@ -40,5 +40,6 @@ observe logging sse + imperative diff --git a/nima/webserver/cors/src/main/java/io/helidon/nima/webserver/cors/CorsSupport.java b/nima/webserver/cors/src/main/java/io/helidon/nima/webserver/cors/CorsSupport.java index 07140a66e5d..a8255754ed4 100644 --- a/nima/webserver/cors/src/main/java/io/helidon/nima/webserver/cors/CorsSupport.java +++ b/nima/webserver/cors/src/main/java/io/helidon/nima/webserver/cors/CorsSupport.java @@ -17,7 +17,7 @@ import java.util.Optional; -import io.helidon.config.Config; +import io.helidon.common.config.Config; import io.helidon.cors.CorsRequestAdapter; import io.helidon.cors.CorsResponseAdapter; import io.helidon.cors.CorsSupportBase; diff --git a/nima/webserver/webserver/pom.xml b/nima/webserver/webserver/pom.xml index 2d06c5cefda..c0186044f86 100644 --- a/nima/webserver/webserver/pom.xml +++ b/nima/webserver/webserver/pom.xml @@ -33,6 +33,10 @@ + + io.helidon.nima.common + helidon-nima-common-api + io.helidon.common helidon-common-http diff --git a/nima/webserver/webserver/src/main/java/io/helidon/nima/webserver/LoomServer.java b/nima/webserver/webserver/src/main/java/io/helidon/nima/webserver/LoomServer.java index 2a10cb1b6da..f773658ab20 100644 --- a/nima/webserver/webserver/src/main/java/io/helidon/nima/webserver/LoomServer.java +++ b/nima/webserver/webserver/src/main/java/io/helidon/nima/webserver/LoomServer.java @@ -43,6 +43,7 @@ import io.helidon.common.context.Context; import io.helidon.common.features.HelidonFeatures; import io.helidon.common.features.api.HelidonFlavor; +import io.helidon.nima.common.api.Startable; import io.helidon.nima.common.tls.Tls; import io.helidon.nima.http.encoding.ContentEncodingContext; import io.helidon.nima.http.media.MediaContext; @@ -52,11 +53,10 @@ import io.helidon.pico.api.ServiceProvider; import io.helidon.pico.configdriven.api.ConfigDriven; -import jakarta.annotation.PostConstruct; import jakarta.inject.Inject; @ConfigDriven(value = WebServerConfigBlueprint.class, activateByDefault = true) -class LoomServer implements WebServer { +class LoomServer implements WebServer, Startable { private static final System.Logger LOGGER = System.getLogger(LoomServer.class.getName()); private static final String EXIT_ON_STARTED_KEY = "exit.on.started"; private static final AtomicInteger WEBSERVER_COUNTER = new AtomicInteger(1); @@ -126,7 +126,11 @@ public WebServerConfig prototype() { return serverConfig; } - @PostConstruct + @Override + public void startService() { + start(); + } + @Override public WebServer start() { HelidonFeatures.flavor(HelidonFlavor.NIMA); diff --git a/nima/webserver/webserver/src/main/java/module-info.java b/nima/webserver/webserver/src/main/java/module-info.java index 3ed71dbe1a0..173118e422e 100644 --- a/nima/webserver/webserver/src/main/java/module-info.java +++ b/nima/webserver/webserver/src/main/java/module-info.java @@ -35,6 +35,7 @@ requires transitive io.helidon.common.security; requires io.helidon.logging.common; requires io.helidon.builder.api; + requires io.helidon.nima.common.api; requires io.helidon.common.features.api; requires io.helidon.common.features; requires io.helidon.common.task; diff --git a/pico/runtime/src/main/java/module-info.java b/pico/runtime/src/main/java/module-info.java index adfda4b7b82..0897c68a5cb 100644 --- a/pico/runtime/src/main/java/module-info.java +++ b/pico/runtime/src/main/java/module-info.java @@ -21,6 +21,7 @@ requires static jakarta.inject; requires static jakarta.annotation; requires io.helidon.builder.api; + // required for compilation of generated types requires transitive io.helidon.common.types; requires io.helidon.common; requires io.helidon.common.config; diff --git a/pom.xml b/pom.xml index c6977858252..710a7559efd 100644 --- a/pom.xml +++ b/pom.xml @@ -179,6 +179,7 @@ parent dependencies bom + helidon applications licensing common From d541198695d9f4e970934517f89744633fe78753 Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Thu, 29 Jun 2023 18:08:59 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Helidon=20Main=20class=20-=20injection=20im?= =?UTF-8?q?plementation=20-=20CDI=20implementation=20-=20refactored=20MP?= =?UTF-8?q?=20apps=20to=20use=20it=20-=20refactored=20N=C3=ADma=20FT=20exa?= =?UTF-8?q?mple=20to=20use=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/mp/pom.xml | 2 +- bom/pom.xml | 15 +-- examples/nima/fault-tolerance/pom.xml | 6 +- .../nima/faulttolerance/GreetEndpoint.java | 1 - .../src/main/resources/application.yaml | 4 +- .../faulttolerance/FaultToleranceTest.java | 8 +- helidon/pom.xml | 4 + helidon/src/main/java/io/helidon/Main.java | 49 ++++++++- .../main/java/io/helidon}/package-info.java | 8 +- .../helidon/spi/HelidonStartupProvider.java | 17 ++- .../java/io/helidon/spi/package-info.java | 9 +- .../src/main/java/module-info.java | 15 ++- .../micrometer/MeterRegistryFactory.java | 1 - microprofile/cdi/pom.xml | 4 + .../microprofile/cdi/CdiStartupProvider.java | 41 +++++++ .../cdi/src/main/java/module-info.java | 4 +- nima/common/api/pom.xml | 43 -------- nima/common/pom.xml | 1 - nima/nima/pom.xml | 103 ------------------ .../java/io/helidon/nima/ConfigProvider.java | 70 ------------ nima/nima/src/main/java/module-info.java | 32 ------ .../test/java/io/helidon/nima/NimaTest.java | 64 ----------- .../io/helidon/nima/TestConfigSource.java | 44 -------- nima/nima/src/test/resources/application.yaml | 22 ---- nima/observe/config/pom.xml | 4 - .../config/src/main/java/module-info.java | 3 +- .../log/src/main/java/module-info.java | 3 +- nima/observe/observe/pom.xml | 4 - .../observe/src/main/java/module-info.java | 3 +- nima/pom.xml | 1 - .../HelidonServerJunitExtension.java | 2 + .../nima/webclient/DefaultDnsResolver.java | 4 + nima/webserver/webserver/pom.xml | 4 - .../io/helidon/nima/webserver/LoomServer.java | 4 +- .../webserver/src/main/java/module-info.java | 1 - pico/api/pom.xml | 4 + .../java/io/helidon/pico/api}/Helidon.java | 32 ++---- .../java/io/helidon/pico}/api/Startable.java | 10 +- pico/api/src/main/java/module-info.java | 1 + pico/runtime/pom.xml | 4 + .../HelidonInjectionStartupProvider.java | 24 ++-- pico/runtime/src/main/java/module-info.java | 3 + 42 files changed, 204 insertions(+), 474 deletions(-) rename {nima/common/api/src/main/java/io/helidon/nima/common/api => helidon/src/main/java/io/helidon}/package-info.java (78%) rename nima/common/api/src/main/java/module-info.java => helidon/src/main/java/io/helidon/spi/package-info.java (73%) rename nima/nima/src/main/java/io/helidon/nima/package-info.java => helidon/src/main/java/module-info.java (66%) create mode 100644 microprofile/cdi/src/main/java/io/helidon/microprofile/cdi/CdiStartupProvider.java delete mode 100644 nima/common/api/pom.xml delete mode 100644 nima/nima/pom.xml delete mode 100644 nima/nima/src/main/java/io/helidon/nima/ConfigProvider.java delete mode 100644 nima/nima/src/main/java/module-info.java delete mode 100644 nima/nima/src/test/java/io/helidon/nima/NimaTest.java delete mode 100644 nima/nima/src/test/java/io/helidon/nima/TestConfigSource.java delete mode 100644 nima/nima/src/test/resources/application.yaml rename {nima/nima/src/main/java/io/helidon/nima => pico/api/src/main/java/io/helidon/pico/api}/Helidon.java (82%) rename {nima/common/api/src/main/java/io/helidon/nima/common => pico/api/src/main/java/io/helidon/pico}/api/Startable.java (70%) rename examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/FtMain.java => pico/runtime/src/main/java/io/helidon/pico/runtime/HelidonInjectionStartupProvider.java (52%) diff --git a/applications/mp/pom.xml b/applications/mp/pom.xml index 38fe118e36a..9dba89cc473 100644 --- a/applications/mp/pom.xml +++ b/applications/mp/pom.xml @@ -36,7 +36,7 @@ 0.14.0 2.7.5.1 6.1.7.Final - io.helidon.microprofile.cdi.Main + io.helidon.Main diff --git a/bom/pom.xml b/bom/pom.xml index 6f53de7a4b1..c02d198d0d2 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -37,6 +37,11 @@ + + io.helidon + helidon + ${helidon.version} + io.helidon.reactive.webserver @@ -1175,16 +1180,6 @@ - - io.helidon.nima - helidon-nima - ${helidon.version} - - - io.helidon.nima.common - helidon-nima-common-api - ${helidon.version} - io.helidon.nima.common helidon-nima-common-tls diff --git a/examples/nima/fault-tolerance/pom.xml b/examples/nima/fault-tolerance/pom.xml index dafd92e4495..11792a43c8f 100644 --- a/examples/nima/fault-tolerance/pom.xml +++ b/examples/nima/fault-tolerance/pom.xml @@ -30,13 +30,13 @@ Helidon Examples Níma Fault Tolerance - io.helidon.examples.nima.faulttolerance.FtMain + io.helidon.Main - io.helidon.nima - helidon-nima + io.helidon + helidon io.helidon.nima.webserver diff --git a/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/GreetEndpoint.java b/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/GreetEndpoint.java index 56c339f96af..8a3699bfea9 100644 --- a/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/GreetEndpoint.java +++ b/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/GreetEndpoint.java @@ -55,7 +55,6 @@ String greet() { String greetNamed(@Endpoint.PathParam("name") String name, @Endpoint.QueryParam(value = "throw", defaultValue = "false") String shouldThrow, @Endpoint.HeaderParam(Http.Header.HOST_STRING) String hostHeader) { - System.out.println(Thread.currentThread().getName()); if ("true".equalsIgnoreCase(shouldThrow)) { throw new PicoException("Failed on purpose"); } diff --git a/examples/nima/fault-tolerance/src/main/resources/application.yaml b/examples/nima/fault-tolerance/src/main/resources/application.yaml index 3f876a8b62c..c0e37455eb5 100644 --- a/examples/nima/fault-tolerance/src/main/resources/application.yaml +++ b/examples/nima/fault-tolerance/src/main/resources/application.yaml @@ -26,4 +26,6 @@ fault-tolerance: myname: executor-name: "platform-executor" other-name: - executor-name: "abcd" \ No newline at end of file + executor-name: "abcd" +pico: + permits-dynamic: true \ No newline at end of file diff --git a/examples/nima/fault-tolerance/src/test/java/io/helidon/examples/nima/faulttolerance/FaultToleranceTest.java b/examples/nima/fault-tolerance/src/test/java/io/helidon/examples/nima/faulttolerance/FaultToleranceTest.java index 9a456be0c41..2bad56e5ee6 100644 --- a/examples/nima/fault-tolerance/src/test/java/io/helidon/examples/nima/faulttolerance/FaultToleranceTest.java +++ b/examples/nima/fault-tolerance/src/test/java/io/helidon/examples/nima/faulttolerance/FaultToleranceTest.java @@ -16,6 +16,7 @@ package io.helidon.examples.nima.faulttolerance; +import io.helidon.Main; import io.helidon.common.http.Http; import io.helidon.nima.webclient.WebClient; import io.helidon.nima.webclient.http1.Http1Client; @@ -39,7 +40,7 @@ class FaultToleranceTest { @BeforeAll static void init() { - FtMain.main(new String[0]); + Main.main(new String[0]); WebServer webServer = PicoServices.realizedServices() .lookup(WebServer.class) .get(); @@ -59,8 +60,8 @@ static void init() { @AfterAll static void shutDown() { - // PicoServices.picoServices() - // .map(PicoServices::shutdown); + PicoServices.picoServices() + .map(PicoServices::shutdown); } @Test @@ -95,7 +96,6 @@ void testGreetNamed() { } @Test - @Disabled void testGreetNamedFallback() { String response = webClient.get("/greet/helidon") .queryParam("throw", "true") diff --git a/helidon/pom.xml b/helidon/pom.xml index b3d880e3ecc..23d331b3152 100644 --- a/helidon/pom.xml +++ b/helidon/pom.xml @@ -35,5 +35,9 @@ io.helidon.common helidon-common + + io.helidon.logging + helidon-logging-common + diff --git a/helidon/src/main/java/io/helidon/Main.java b/helidon/src/main/java/io/helidon/Main.java index abb6043c6cd..bee0c5aa5f0 100644 --- a/helidon/src/main/java/io/helidon/Main.java +++ b/helidon/src/main/java/io/helidon/Main.java @@ -1,15 +1,62 @@ +/* + * Copyright (c) 2023 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; +import java.util.ServiceLoader; + +import io.helidon.common.HelidonServiceLoader; +import io.helidon.logging.common.LogConfig; +import io.helidon.spi.HelidonStartupProvider; + /** - * Main entry point for any Helidon application that is discovering services. + * Main entry point for any Helidon application. + * {@link java.util.ServiceLoader} is used to discover the correct {@link io.helidon.spi.HelidonStartupProvider} + * to start the application (probably either Helidon Injection based application, or a CDI based application). + *

+ * The default option is to start Helidon injection based application. */ public class Main { + static { + LogConfig.initClass(); + } + + private Main() { + } + /** * Start Helidon. + * This method is required to start directly from a command line. * * @param args arguments of the application */ public static void main(String[] args) { + // we always initialize logging + LogConfig.configureRuntime(); + + // this should only be called once in a lifetime of the server, so no need to optimize + var services = HelidonServiceLoader.create(ServiceLoader.load(HelidonStartupProvider.class)) + .asList(); + if (services.isEmpty()) { + throw new IllegalStateException("Helidon Main class can only be called if an startup provider is available. " + + "Please use either Helidon Injection, or Helidon MicroProfile " + + "(or a custom extension). If neither is available, you should use " + + "your own Main class."); + } + services.get(0).start(args); } } diff --git a/nima/common/api/src/main/java/io/helidon/nima/common/api/package-info.java b/helidon/src/main/java/io/helidon/package-info.java similarity index 78% rename from nima/common/api/src/main/java/io/helidon/nima/common/api/package-info.java rename to helidon/src/main/java/io/helidon/package-info.java index a9fa16d7f36..d12d06513ac 100644 --- a/nima/common/api/src/main/java/io/helidon/nima/common/api/package-info.java +++ b/helidon/src/main/java/io/helidon/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Oracle and/or its affiliates. + * Copyright (c) 2022, 2023 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,8 @@ */ /** - * APIs shared across all Helidon features that are injection based. + * Startup of Helidon applications. + * + * @see io.helidon.Main */ -package io.helidon.nima.common.api; +package io.helidon; diff --git a/helidon/src/main/java/io/helidon/spi/HelidonStartupProvider.java b/helidon/src/main/java/io/helidon/spi/HelidonStartupProvider.java index 48a8968a5be..9c293dfe074 100644 --- a/helidon/src/main/java/io/helidon/spi/HelidonStartupProvider.java +++ b/helidon/src/main/java/io/helidon/spi/HelidonStartupProvider.java @@ -1,9 +1,24 @@ +/* + * Copyright (c) 2023 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.spi; /** * {@link java.util.ServiceLoader} provider interface to discover the correct startup type. * Only the first provider (with the highest {@link io.helidon.common.Weight}) will be used. - * The default startup will create Helidon Injection service registry, and start all services that should be started. */ public interface HelidonStartupProvider { /** diff --git a/nima/common/api/src/main/java/module-info.java b/helidon/src/main/java/io/helidon/spi/package-info.java similarity index 73% rename from nima/common/api/src/main/java/module-info.java rename to helidon/src/main/java/io/helidon/spi/package-info.java index 59dc72b949f..ca33f0ebb24 100644 --- a/nima/common/api/src/main/java/module-info.java +++ b/helidon/src/main/java/io/helidon/spi/package-info.java @@ -15,10 +15,7 @@ */ /** - * APIs for Helidon features. + * Extension point to support a single main class ({@link io.helidon.Main}) to start various styles of applications, + * such as Helidon injection based applications, and Helidon MicroProfile applications. */ -module io.helidon.nima.common.api { - requires static io.helidon.pico.api; - - exports io.helidon.nima.common.api; -} \ No newline at end of file +package io.helidon.spi; diff --git a/nima/nima/src/main/java/io/helidon/nima/package-info.java b/helidon/src/main/java/module-info.java similarity index 66% rename from nima/nima/src/main/java/io/helidon/nima/package-info.java rename to helidon/src/main/java/module-info.java index bdbc4b1ba76..8c8a4482393 100644 --- a/nima/nima/src/main/java/io/helidon/nima/package-info.java +++ b/helidon/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. + * Copyright (c) 2023 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,7 +15,14 @@ */ /** - * Main entry point for Níma application. - * Bootstraps required services, which implicitly starts server(s) available. + * Types need to start a Helidon application. */ -package io.helidon.nima; +module io.helidon { + requires io.helidon.common; + requires io.helidon.logging.common; + + exports io.helidon; + exports io.helidon.spi; + + uses io.helidon.spi.HelidonStartupProvider; +} \ No newline at end of file diff --git a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java index d07ec4c4744..daa43ae9271 100644 --- a/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java +++ b/integrations/micrometer/micrometer/src/main/java/io/helidon/integrations/micrometer/MeterRegistryFactory.java @@ -30,7 +30,6 @@ import io.helidon.common.config.Config; import io.helidon.common.http.Http; -import io.helidon.config.Config; import io.helidon.nima.webserver.http.Handler; import io.helidon.nima.webserver.http.ServerRequest; import io.helidon.nima.webserver.http.ServerResponse; diff --git a/microprofile/cdi/pom.xml b/microprofile/cdi/pom.xml index 1431ec0d145..9e457773926 100644 --- a/microprofile/cdi/pom.xml +++ b/microprofile/cdi/pom.xml @@ -32,6 +32,10 @@ Helidon extension of Weld to support ahead of time compilation + + io.helidon + helidon + io.helidon.microprofile.weld diff --git a/microprofile/cdi/src/main/java/io/helidon/microprofile/cdi/CdiStartupProvider.java b/microprofile/cdi/src/main/java/io/helidon/microprofile/cdi/CdiStartupProvider.java new file mode 100644 index 00000000000..68101e1c82b --- /dev/null +++ b/microprofile/cdi/src/main/java/io/helidon/microprofile/cdi/CdiStartupProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023 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.microprofile.cdi; + +import io.helidon.common.Weight; +import io.helidon.common.Weighted; +import io.helidon.spi.HelidonStartupProvider; + +/** + * {@link java.util.ServiceLoader} implementation of a Helidon startup provider. + */ +@Weight(Weighted.DEFAULT_WEIGHT + 100) // must have higher than default, to start CDI and not Helidon Injection +public class CdiStartupProvider implements HelidonStartupProvider { + /** + * Default constructor required by {@link java.util.ServiceLoader}. + * + * @deprecated please do not use directly + */ + @Deprecated + public CdiStartupProvider() { + } + + @Override + public void start(String[] arguments) { + Main.main(arguments); + } +} diff --git a/microprofile/cdi/src/main/java/module-info.java b/microprofile/cdi/src/main/java/module-info.java index a2353c0a20f..29e85da2c44 100644 --- a/microprofile/cdi/src/main/java/module-info.java +++ b/microprofile/cdi/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022 Oracle and/or its affiliates. + * Copyright (c) 2019, 2023 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. @@ -37,6 +37,7 @@ // weld requires jakarta.el.ELResolver on module path requires jakarta.el; + requires io.helidon; requires io.helidon.common; requires io.helidon.logging.common; requires io.helidon.common.features.api; @@ -56,6 +57,7 @@ uses jakarta.enterprise.inject.spi.Extension; + provides io.helidon.spi.HelidonStartupProvider with io.helidon.microprofile.cdi.CdiStartupProvider; provides jakarta.enterprise.inject.se.SeContainerInitializer with io.helidon.microprofile.cdi.HelidonContainerInitializer; provides jakarta.enterprise.inject.spi.CDIProvider with io.helidon.microprofile.cdi.HelidonCdiProvider; diff --git a/nima/common/api/pom.xml b/nima/common/api/pom.xml deleted file mode 100644 index ed2570b5569..00000000000 --- a/nima/common/api/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - 4.0.0 - - - io.helidon.nima.common - helidon-nima-common-project - 4.0.0-SNAPSHOT - ../pom.xml - - - helidon-nima-common-api - Helidon Níma Common API - APIs need for any Níma feature, independent on WebServer - - - - io.helidon.pico - helidon-pico-api - true - - - diff --git a/nima/common/pom.xml b/nima/common/pom.xml index e56654387a6..ec95236a3ff 100644 --- a/nima/common/pom.xml +++ b/nima/common/pom.xml @@ -37,7 +37,6 @@ pom - api tls diff --git a/nima/nima/pom.xml b/nima/nima/pom.xml deleted file mode 100644 index 0783287c462..00000000000 --- a/nima/nima/pom.xml +++ /dev/null @@ -1,103 +0,0 @@ - - - - - 4.0.0 - - - io.helidon.nima - helidon-nima-project - 4.0.0-SNAPSHOT - ../pom.xml - - - helidon-nima - Helidon Níma - - - - jakarta.inject - jakarta.inject-api - - - io.helidon.common - helidon-common - - - io.helidon.nima.common - helidon-nima-common-api - - - io.helidon.config - helidon-config - - - io.helidon.pico - helidon-pico-api - - - io.helidon.pico - helidon-pico-runtime - - - io.helidon.pico.configdriven - helidon-pico-configdriven-runtime - - - io.helidon.config - helidon-config-yaml - test - - - io.helidon.pico - helidon-pico-testing - test - - - org.junit.jupiter - junit-jupiter-api - test - - - org.hamcrest - hamcrest-all - test - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - io.helidon.pico - helidon-pico-processor - ${helidon.version} - - - - - - - diff --git a/nima/nima/src/main/java/io/helidon/nima/ConfigProvider.java b/nima/nima/src/main/java/io/helidon/nima/ConfigProvider.java deleted file mode 100644 index 30d1583ae12..00000000000 --- a/nima/nima/src/main/java/io/helidon/nima/ConfigProvider.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2022, 2023 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.nima; - -import java.util.List; - -import io.helidon.common.config.Config; -import io.helidon.config.spi.ConfigSource; -import io.helidon.pico.api.ExternalContracts; -import io.helidon.pico.api.PicoServices; -import io.helidon.pico.api.ServiceInfoCriteria; -import io.helidon.pico.api.ServiceProvider; - -import jakarta.inject.Inject; -import jakarta.inject.Provider; -import jakarta.inject.Singleton; - -/** - * A provider responsible for constructing a config instance from services and service loader. - */ -@Singleton -@ExternalContracts(Config.class) -class ConfigProvider implements Provider { - private static Config explicitConfig; - private final Config config; - - @Inject - ConfigProvider() { - // this should be moved to constructor injection when we support zero length lists for injection - List> serviceProviders = PicoServices.realizedServices() - .lookupAll(ServiceInfoCriteria - .builder() - .addContractImplemented(ConfigSource.class).build(), false); - - if (explicitConfig == null) { - config = io.helidon.config.Config.builder() - .metaConfig() - .update(it -> serviceProviders.stream() - .map(Provider::get) - .map(ConfigSource.class::cast) - .forEach(it::addSource)) - .build(); - } else { - config = explicitConfig; - } - } - - static void explicitConfig(Config config) { - ConfigProvider.explicitConfig = config; - } - - @Override - public Config get() { - return config; - } -} diff --git a/nima/nima/src/main/java/module-info.java b/nima/nima/src/main/java/module-info.java deleted file mode 100644 index 0fa46a5b0c6..00000000000 --- a/nima/nima/src/main/java/module-info.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2022, 2023 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. - */ -module io.helidon.nima { - requires io.helidon.common; - requires io.helidon.config; - requires io.helidon.logging.common; - requires io.helidon.pico.api; - - requires io.helidon.nima.common.api; - - requires jakarta.inject; - - requires io.helidon.common.types; - requires io.helidon.pico.runtime; - - exports io.helidon.nima; - - provides io.helidon.pico.api.ModuleComponent with io.helidon.nima.Pico$$Module; -} \ No newline at end of file diff --git a/nima/nima/src/test/java/io/helidon/nima/NimaTest.java b/nima/nima/src/test/java/io/helidon/nima/NimaTest.java deleted file mode 100644 index 2849d23a7b2..00000000000 --- a/nima/nima/src/test/java/io/helidon/nima/NimaTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2022, 2023 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.nima; - -import java.util.Optional; - -import io.helidon.common.config.Config; -import io.helidon.common.config.GlobalConfig; -import io.helidon.pico.testing.PicoTestingSupport; - -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.MethodOrderer; -import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -// this test is ordered, as we want to first try without an explicit config, and then with it -@TestMethodOrder(MethodOrderer.OrderAnnotation.class) -class NimaTest { - @AfterEach - void reset() { - PicoTestingSupport.resetAll(); - } - @Order(0) - @Test - void testConfig() { - // value should be overridden using our custom config source - Config config = Helidon.services() - .lookup(Config.class) - .get(); - - assertThat(config.get("app.value").asString().asOptional(), is(Optional.of("source"))); - } - - @Order(1) - @Test - void testExplicitConfig() { - // value should use the config as we provided it - GlobalConfig.config(io.helidon.config.Config::create, true); - - Config config = Helidon.services() - .lookup(Config.class) - .get(); - - assertThat(config.get("app.value").asString().asOptional(), is(Optional.of("file"))); - } -} diff --git a/nima/nima/src/test/java/io/helidon/nima/TestConfigSource.java b/nima/nima/src/test/java/io/helidon/nima/TestConfigSource.java deleted file mode 100644 index 7c17dc60ef5..00000000000 --- a/nima/nima/src/test/java/io/helidon/nima/TestConfigSource.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022, 2023 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.nima; - -import java.util.Optional; - -import io.helidon.common.Weight; -import io.helidon.config.ConfigException; -import io.helidon.config.spi.ConfigContent; -import io.helidon.config.spi.ConfigNode; -import io.helidon.config.spi.ConfigSource; -import io.helidon.config.spi.NodeConfigSource; -import io.helidon.pico.api.ExternalContracts; - -import jakarta.inject.Singleton; - -@Singleton -@Weight(200) -@ExternalContracts(ConfigSource.class) -class TestConfigSource implements NodeConfigSource { - - @Override - public Optional load() throws ConfigException { - return Optional.of(ConfigContent.NodeContent.builder() - .node(ConfigNode.ObjectNode.builder() - .addValue("app.value", "source") - .build()) - .build()); - } -} diff --git a/nima/nima/src/test/resources/application.yaml b/nima/nima/src/test/resources/application.yaml deleted file mode 100644 index dafcabdd7a7..00000000000 --- a/nima/nima/src/test/resources/application.yaml +++ /dev/null @@ -1,22 +0,0 @@ -# -# Copyright (c) 2023 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. -# - -app.value: "file" - -# needed to reset state of service registry in test -pico: - permits-dynamic: true - service-lookup-caching: true diff --git a/nima/observe/config/pom.xml b/nima/observe/config/pom.xml index fe4f4180e48..9b9dbbb1499 100644 --- a/nima/observe/config/pom.xml +++ b/nima/observe/config/pom.xml @@ -29,10 +29,6 @@ - - io.helidon.nima - helidon-nima - io.helidon.nima.observe helidon-nima-observe diff --git a/nima/observe/config/src/main/java/module-info.java b/nima/observe/config/src/main/java/module-info.java index 045ce5ef6ad..c1e05278f61 100644 --- a/nima/observe/config/src/main/java/module-info.java +++ b/nima/observe/config/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. + * Copyright (c) 2022, 2023 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,6 @@ module io.helidon.nima.observe.config { requires transitive io.helidon.nima.observe; requires io.helidon.nima.webserver; - requires io.helidon.nima; requires io.helidon.nima.http.media.jsonp; exports io.helidon.nima.observe.config; diff --git a/nima/observe/log/src/main/java/module-info.java b/nima/observe/log/src/main/java/module-info.java index 2f93cb3ef19..61ee3256b6e 100644 --- a/nima/observe/log/src/main/java/module-info.java +++ b/nima/observe/log/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. + * Copyright (c) 2022, 2023 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,6 @@ module io.helidon.nima.observe.log { requires transitive io.helidon.nima.observe; requires io.helidon.nima.webserver; - requires io.helidon.nima; requires io.helidon.nima.http.media.jsonp; requires java.logging; diff --git a/nima/observe/observe/pom.xml b/nima/observe/observe/pom.xml index de182a06492..0961c914029 100644 --- a/nima/observe/observe/pom.xml +++ b/nima/observe/observe/pom.xml @@ -28,10 +28,6 @@ Helidon Níma Observe - - io.helidon.nima - helidon-nima - io.helidon.nima.webserver helidon-nima-webserver diff --git a/nima/observe/observe/src/main/java/module-info.java b/nima/observe/observe/src/main/java/module-info.java index 917be309f36..f6d72d20a5d 100644 --- a/nima/observe/observe/src/main/java/module-info.java +++ b/nima/observe/observe/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. + * Copyright (c) 2022, 2023 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 @@ requires transitive io.helidon.nima.webserver.cors; requires io.helidon.common.http; requires io.helidon.nima.webserver; - requires io.helidon.nima; exports io.helidon.nima.observe; exports io.helidon.nima.observe.spi; diff --git a/nima/pom.xml b/nima/pom.xml index fe95da7005e..0288aee87d4 100644 --- a/nima/pom.xml +++ b/nima/pom.xml @@ -36,7 +36,6 @@ pom - nima common http webclient diff --git a/nima/testing/junit5/webserver/src/main/java/io/helidon/nima/testing/junit5/webserver/HelidonServerJunitExtension.java b/nima/testing/junit5/webserver/src/main/java/io/helidon/nima/testing/junit5/webserver/HelidonServerJunitExtension.java index 47d6f6f2376..5d161c9f3af 100644 --- a/nima/testing/junit5/webserver/src/main/java/io/helidon/nima/testing/junit5/webserver/HelidonServerJunitExtension.java +++ b/nima/testing/junit5/webserver/src/main/java/io/helidon/nima/testing/junit5/webserver/HelidonServerJunitExtension.java @@ -30,6 +30,7 @@ import java.util.concurrent.ConcurrentHashMap; import io.helidon.common.HelidonServiceLoader; +import io.helidon.common.config.GlobalConfig; import io.helidon.common.context.Context; import io.helidon.common.context.Contexts; import io.helidon.logging.common.LogConfig; @@ -81,6 +82,7 @@ public void beforeAll(ExtensionContext context) { } WebServerConfig.Builder builder = WebServer.builder() + .config(GlobalConfig.config().get("server")) .port(0) .shutdownHook(false) .host("localhost"); diff --git a/nima/webclient/webclient/src/main/java/io/helidon/nima/webclient/DefaultDnsResolver.java b/nima/webclient/webclient/src/main/java/io/helidon/nima/webclient/DefaultDnsResolver.java index e96f438dba7..481ee7980cb 100644 --- a/nima/webclient/webclient/src/main/java/io/helidon/nima/webclient/DefaultDnsResolver.java +++ b/nima/webclient/webclient/src/main/java/io/helidon/nima/webclient/DefaultDnsResolver.java @@ -19,6 +19,7 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import io.helidon.nima.webclient.spi.DnsResolver; @@ -29,6 +30,9 @@ final class DefaultDnsResolver implements DnsResolver { @Override public InetAddress resolveAddress(String hostname, DnsAddressLookup dnsAddressLookup) { + Objects.requireNonNull(hostname); + Objects.requireNonNull(dnsAddressLookup); + return hostnameAddresses.computeIfAbsent(hostname, host -> { try { InetAddress[] processed = dnsAddressLookup.filter(InetAddress.getAllByName(hostname)); diff --git a/nima/webserver/webserver/pom.xml b/nima/webserver/webserver/pom.xml index c0186044f86..2d06c5cefda 100644 --- a/nima/webserver/webserver/pom.xml +++ b/nima/webserver/webserver/pom.xml @@ -33,10 +33,6 @@ - - io.helidon.nima.common - helidon-nima-common-api - io.helidon.common helidon-common-http diff --git a/nima/webserver/webserver/src/main/java/io/helidon/nima/webserver/LoomServer.java b/nima/webserver/webserver/src/main/java/io/helidon/nima/webserver/LoomServer.java index f773658ab20..6af267c306a 100644 --- a/nima/webserver/webserver/src/main/java/io/helidon/nima/webserver/LoomServer.java +++ b/nima/webserver/webserver/src/main/java/io/helidon/nima/webserver/LoomServer.java @@ -43,7 +43,6 @@ import io.helidon.common.context.Context; import io.helidon.common.features.HelidonFeatures; import io.helidon.common.features.api.HelidonFlavor; -import io.helidon.nima.common.api.Startable; import io.helidon.nima.common.tls.Tls; import io.helidon.nima.http.encoding.ContentEncodingContext; import io.helidon.nima.http.media.MediaContext; @@ -51,8 +50,10 @@ import io.helidon.nima.webserver.http.HttpFeature; import io.helidon.nima.webserver.http.HttpRouting; import io.helidon.pico.api.ServiceProvider; +import io.helidon.pico.api.Startable; import io.helidon.pico.configdriven.api.ConfigDriven; +import jakarta.annotation.PreDestroy; import jakarta.inject.Inject; @ConfigDriven(value = WebServerConfigBlueprint.class, activateByDefault = true) @@ -158,6 +159,7 @@ public WebServer start() { } @Override + @PreDestroy public WebServer stop() { try { lifecycleLock.lockInterruptibly(); diff --git a/nima/webserver/webserver/src/main/java/module-info.java b/nima/webserver/webserver/src/main/java/module-info.java index 173118e422e..3ed71dbe1a0 100644 --- a/nima/webserver/webserver/src/main/java/module-info.java +++ b/nima/webserver/webserver/src/main/java/module-info.java @@ -35,7 +35,6 @@ requires transitive io.helidon.common.security; requires io.helidon.logging.common; requires io.helidon.builder.api; - requires io.helidon.nima.common.api; requires io.helidon.common.features.api; requires io.helidon.common.features; requires io.helidon.common.task; diff --git a/pico/api/pom.xml b/pico/api/pom.xml index 48d76f86df8..fb6ae6a902c 100644 --- a/pico/api/pom.xml +++ b/pico/api/pom.xml @@ -42,6 +42,10 @@ io.helidon.common helidon-common-config + + io.helidon.logging + helidon-logging-common + jakarta.inject jakarta.inject-api diff --git a/nima/nima/src/main/java/io/helidon/nima/Helidon.java b/pico/api/src/main/java/io/helidon/pico/api/Helidon.java similarity index 82% rename from nima/nima/src/main/java/io/helidon/nima/Helidon.java rename to pico/api/src/main/java/io/helidon/pico/api/Helidon.java index 7dbb907c781..0c810970fd0 100644 --- a/nima/nima/src/main/java/io/helidon/nima/Helidon.java +++ b/pico/api/src/main/java/io/helidon/pico/api/Helidon.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2023 Oracle and/or its affiliates. + * Copyright (c) 2023 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.nima; +package io.helidon.pico.api; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -22,15 +22,12 @@ import io.helidon.common.config.Config; import io.helidon.common.config.GlobalConfig; import io.helidon.logging.common.LogConfig; -import io.helidon.nima.common.api.Startable; -import io.helidon.pico.api.Bootstrap; -import io.helidon.pico.api.PicoServices; -import io.helidon.pico.api.PicoServicesHolder; -import io.helidon.pico.api.ServiceProvider; -import io.helidon.pico.api.Services; /** - * Main entry point for applications using Helidon Injection service registry. + * Entry point to service registry based Helidon applications. + * + * @see #start() + * @see #serviceRegistry() */ public class Helidon { private static final System.Logger LOGGER = System.getLogger(Helidon.class.getName()); @@ -49,22 +46,13 @@ public class Helidon { private Helidon() { } - /** - * Main method to start Helidon Injection service registry and services that should be initialized at startup. - * - * @param args currently ignored - */ - public static void main(String[] args) { - start(); - } - /** * Initialize Helidon Injection service registry. In case the intent is to also start services, such as WebServer, * see {@link #start()}. * * @return service registry */ - public static Services services() { + public static Services serviceRegistry() { if (REGISTRY_INITIALIZED.compareAndSet(false, true)) { basicInit(); registryInit(false); @@ -85,7 +73,7 @@ public static void start() { basicInit(); registryInit(true); } else { - LOGGER.log(System.Logger.Level.WARNING, "Duplicate call to method Nima.start()."); + LOGGER.log(System.Logger.Level.WARNING, "Duplicate call to method Helidon.start()."); } } @@ -105,10 +93,6 @@ private static void registryInit(boolean bootServices) { boolean explicitConfig = GlobalConfig.configured(); Config bootstrapConfig = GlobalConfig.config(); - if (explicitConfig) { - ConfigProvider.explicitConfig(bootstrapConfig); - } - Bootstrap bootstrap = Bootstrap.builder() .config(bootstrapConfig) .build(); diff --git a/nima/common/api/src/main/java/io/helidon/nima/common/api/Startable.java b/pico/api/src/main/java/io/helidon/pico/api/Startable.java similarity index 70% rename from nima/common/api/src/main/java/io/helidon/nima/common/api/Startable.java rename to pico/api/src/main/java/io/helidon/pico/api/Startable.java index 347e137e3bf..33352f6c596 100644 --- a/nima/common/api/src/main/java/io/helidon/nima/common/api/Startable.java +++ b/pico/api/src/main/java/io/helidon/pico/api/Startable.java @@ -14,14 +14,18 @@ * limitations under the License. */ -package io.helidon.nima.common.api; - -import io.helidon.pico.api.Contract; +package io.helidon.pico.api; /** * Some components may require start when Helidon is bootstrapped, such as WebServer (to open server sockets). * This interface is a Helidon Injection contract, that allows us to discover all startable services and start them * on boot when desired. + *

+ * This contract should be used for cases where the construction of the object (using constructor, and maybe + * {@link jakarta.annotation.PostConstruct} - where we create a fully configured instance) is different from its start + * transition (such as opening sockets, connecting to remote messaging queues, streams, topics, etc.). + * + * @see io.helidon.pico.api.Helidon#start() */ @Contract public interface Startable { diff --git a/pico/api/src/main/java/module-info.java b/pico/api/src/main/java/module-info.java index 68b424f552c..94b0d333ee7 100644 --- a/pico/api/src/main/java/module-info.java +++ b/pico/api/src/main/java/module-info.java @@ -25,6 +25,7 @@ requires transitive io.helidon.builder.api; requires static io.helidon.config.metadata; requires static jakarta.annotation; + requires io.helidon.logging.common; exports io.helidon.pico.api; exports io.helidon.pico.spi; diff --git a/pico/runtime/pom.xml b/pico/runtime/pom.xml index 86afa2e348a..5be492dc3e4 100644 --- a/pico/runtime/pom.xml +++ b/pico/runtime/pom.xml @@ -31,6 +31,10 @@ Helidon Pico Runtime Services + + io.helidon + helidon + io.helidon.pico helidon-pico-api diff --git a/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/FtMain.java b/pico/runtime/src/main/java/io/helidon/pico/runtime/HelidonInjectionStartupProvider.java similarity index 52% rename from examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/FtMain.java rename to pico/runtime/src/main/java/io/helidon/pico/runtime/HelidonInjectionStartupProvider.java index f573ffa7a36..aba9becba9d 100644 --- a/examples/nima/fault-tolerance/src/main/java/io/helidon/examples/nima/faulttolerance/FtMain.java +++ b/pico/runtime/src/main/java/io/helidon/pico/runtime/HelidonInjectionStartupProvider.java @@ -14,23 +14,27 @@ * limitations under the License. */ -package io.helidon.examples.nima.faulttolerance; +package io.helidon.pico.runtime; -import io.helidon.nima.Helidon; +import io.helidon.pico.api.Helidon; +import io.helidon.spi.HelidonStartupProvider; /** - * Main class of the example, starts Helidon with injection support. + * Service provider implementation, should only be used from {@link java.util.ServiceLoader}. + * See {@link io.helidon.pico.api.Helidon} type to discover programmatic API. */ -public final class FtMain { - private FtMain() { - } - +public class HelidonInjectionStartupProvider implements HelidonStartupProvider { /** - * Start the example. + * Required default constructor needed for {@link java.util.ServiceLoader}. * - * @param args ignored + * @deprecated please do not use directly */ - public static void main(String[] args) { + @Deprecated + public HelidonInjectionStartupProvider() { + } + + @Override + public void start(String[] arguments) { Helidon.start(); } } diff --git a/pico/runtime/src/main/java/module-info.java b/pico/runtime/src/main/java/module-info.java index 0897c68a5cb..725f9efe1b2 100644 --- a/pico/runtime/src/main/java/module-info.java +++ b/pico/runtime/src/main/java/module-info.java @@ -27,11 +27,14 @@ requires io.helidon.common.config; requires transitive io.helidon.pico.api; requires static io.helidon.config.metadata; + requires io.helidon; exports io.helidon.pico.runtime; provides io.helidon.pico.spi.PicoServicesProvider with io.helidon.pico.runtime.DefaultPicoServicesProvider; + provides io.helidon.spi.HelidonStartupProvider + with io.helidon.pico.runtime.HelidonInjectionStartupProvider; uses io.helidon.pico.api.ModuleComponent; uses io.helidon.pico.api.Application; From e38696eb7f05497feed141ac37b7365ba717ba2e Mon Sep 17 00:00:00 2001 From: Tomas Langer Date: Thu, 29 Jun 2023 21:51:01 +0200 Subject: [PATCH 3/3] Review fixes. --- helidon/src/main/java/io/helidon/Main.java | 2 +- helidon/src/main/java/io/helidon/spi/package-info.java | 2 +- helidon/src/main/java/module-info.java | 2 +- nima/common/pom.xml | 2 +- pico/api/src/main/java/io/helidon/pico/api/Helidon.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/helidon/src/main/java/io/helidon/Main.java b/helidon/src/main/java/io/helidon/Main.java index bee0c5aa5f0..ee31aa7059e 100644 --- a/helidon/src/main/java/io/helidon/Main.java +++ b/helidon/src/main/java/io/helidon/Main.java @@ -52,7 +52,7 @@ public static void main(String[] args) { .asList(); if (services.isEmpty()) { - throw new IllegalStateException("Helidon Main class can only be called if an startup provider is available. " + throw new IllegalStateException("Helidon Main class can only be called if a startup provider is available. " + "Please use either Helidon Injection, or Helidon MicroProfile " + "(or a custom extension). If neither is available, you should use " + "your own Main class."); diff --git a/helidon/src/main/java/io/helidon/spi/package-info.java b/helidon/src/main/java/io/helidon/spi/package-info.java index ca33f0ebb24..0a31d62ca57 100644 --- a/helidon/src/main/java/io/helidon/spi/package-info.java +++ b/helidon/src/main/java/io/helidon/spi/package-info.java @@ -16,6 +16,6 @@ /** * Extension point to support a single main class ({@link io.helidon.Main}) to start various styles of applications, - * such as Helidon injection based applications, and Helidon MicroProfile applications. + * such as Helidon Injection based applications, and Helidon MicroProfile applications. */ package io.helidon.spi; diff --git a/helidon/src/main/java/module-info.java b/helidon/src/main/java/module-info.java index 8c8a4482393..e1bf80b57f5 100644 --- a/helidon/src/main/java/module-info.java +++ b/helidon/src/main/java/module-info.java @@ -15,7 +15,7 @@ */ /** - * Types need to start a Helidon application. + * Types needed to start a Helidon application. */ module io.helidon { requires io.helidon.common; diff --git a/nima/common/pom.xml b/nima/common/pom.xml index ec95236a3ff..16a7ed5a7ed 100644 --- a/nima/common/pom.xml +++ b/nima/common/pom.xml @@ -1,7 +1,7 @@