diff --git a/examples/pico/README.md b/examples/pico/README.md deleted file mode 100644 index 70204793fb6..00000000000 --- a/examples/pico/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# examples-pico - -Helidon Pico was inspired by several DI frameworks (e.g., Hk2, Guice and Dagger, etc.). These examples will serve as a way to learn about the capabilities of Pico by comparing Pico to each of these frameworks. It is recommended to review each example to understand the capabilities of Pico and to see it in action. - -* [book](./book/README.md) - compares Pico to Hk2. -* [car](./car/README.md) - compares Pico to Dagger2. -* [logger](./logger/README.md) - compares Pico to Guice. diff --git a/examples/pico/book/README.md b/examples/pico/book/README.md deleted file mode 100644 index 34e324b6bf3..00000000000 --- a/examples/pico/book/README.md +++ /dev/null @@ -1,152 +0,0 @@ -# pico-examples-car - -This example compares Pico to Jakarta's Hk2. The example is constructed around a virtual library with bookcases, books, and a color wheel on display. This example is different from the other examples in that it combines Hk2 and Pico into the same application. A best practice is to only have one injection framework being used, so this combination is generally not a very realistic example for how a developer would construct their application. Nevertheless, this will be done here in order to convey how the frameworks are similar in some ways while different in other ways. - -Take a momemt to review the code. Note that the generated source code is found under -"./target/generated-sources" for Pico. Generate META-INF is found under "./target/classes". Similarities and differences are listed below. - -# Building and Running -``` -> mvn clean install -> ./run.sh -``` - -# Notable - -1. Both Pico and Hk2 supports jakarta.inject and use annotation processors (see [pom.xml](pom.xml)) to process the injection model in compliance to jsr-330 specifications. But the way they work is very different. Hk2 uses compile-time to determine the set of services in the model, and then at runtime will reflectively analyze those classes for resolving injection point dependencies. Pico, on the other hand, relies 100% on compile-time processing that generates source. In Pico the entire application can be analyzed and verified for completeness (i.e., no missing non-optional dependencies) at compile-time instead of Hk2's approach to perform this at runtime lazily during a service activation - and that validation only happens if the service being looked up is missing its dependencies - which might not happen unless your testing and runtime goes down the path of activating a service that is missing its dependencies. In Pico, when the application is created it is completely bound and verified safeguarding against this possibility. This technique of code generation and binding also leads to better performance of Pico as compared to Hk2, and additionally helps ensure deterministic behavior. - -2. The API programming model between Hk2 and Pico is very similar (see the application). - -* Declaring contracts. Contracts (usually interface types) are a means to lookup or inject into other classes. In the example, there is a contract called BookHolder. Implementation classes of this include: BookCase, EmptyRedBookCase, GreenBookCase, and Library. - -```java -import io.helidon.pico.api.Contract; - -@Contract -@org.jvnet.hk2.annotations.Contract -public interface BookHolder { - Collection getBooks(); -} -``` - -In Hk2's annotation processing the use of Contract or ExternalContract is required to be present. In Pico this is optional when using -Aio.helidon.pico.autoAddNonContractInterfaces=true (see pom). - -* Declaring services. Services (usually concrete class types implementing zero or more contracts) can have zero or more injection points using the standard @Inject annotation. In the below example we see how Library is annotated as a Service for Hk2, while not being necessary for Pico. Pico will naturally resolve any standard Singleton scoped (or ApplicationScoped w/ another -A flag) type, or any service type that contains injection points even without having a Scope annotation. - -``` -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -@ToString -public class Library implements BookHolder { - ... -} -``` - -* Injection points. If we look more closely at the Library class we will see it uses constructor injection. Constructor, setter, and field injection are all supported in both Hk2 and Pico. Note, however, that Pico can only handle public, protected, or package-privates (i.e., no pure private) types and the only for types that are also non-static. This is due to the way Activators are code generated to work with your main service classes. - -``` -@io.helidon.pico.Contract -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -public class Library implements BookHolder { - private List> books; - private List bookHolders; - private ColorWheel colorWheel; - - @Inject - public Library(List> books, List bookHolders, ColorWheel colorWheel) { - this.books = books; - this.bookHolders = bookHolders; - this.colorWheel = colorWheel; - } - - ... -} -``` - -* Pico can handle injection of T, Provider, Optional, and List> while Hk2 can handle T, Provider, Optional, and IterableProvider. Notice how Hk2 does not handle List and yet the annotation processor accepted this form of injection. It is not until runtime that the problem is observed. This type of issue would be found at compile time in Pico. - - -``` - public static void main(String[] args) { - final long memStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long start = System.currentTimeMillis(); - - ServiceLocator locator = ServiceLocatorUtilities.createAndPopulateServiceLocator(); - - try { - ServiceHandle librarySh = locator.getServiceHandle(Library.class); - System.out.println("found a library handle: " + librarySh.getActiveDescriptor()); - Library library = librarySh.getService(); - System.out.println("found a library: " + library); - } catch (Exception e) { - // list injection is not supported in Hk2 - must switch to use IterableProvider instead. - // see https://javaee.github.io/hk2/apidocs/org/glassfish/hk2/api/IterableProvider.html - // and see https://javaee.github.io/hk2/introduction.html - System.out.println("error: " + e.getMessage()); - } - -``` - -* Output from MainHk2 at runtime: - -``` -RUN 1: (HK2) -found a library handle: SystemDescriptor( - implementation=io.helidon.examples.examples.book.Library - contracts={io.helidon.examples.pico.book.Library,io.helidon.examples.pico.book.BookHolder} - scope=jakarta.inject.Singleton - qualifiers={} - descriptorType=CLASS - descriptorVisibility=NORMAL - metadata= - rank=0 - loader=null - proxiable=null - proxyForSameScope=null - analysisName=null - id=12 - locatorId=0 - identityHashCode=99347477 - reified=true) -... -error: A MultiException has 4 exceptions. They are: -1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available in __HK2_Generated_0 for injection at SystemInjecteeImpl(requiredType=List>,parent=Library,qualifiers={},position=0,optional=false,self=false,unqualified=null,940060004) -2. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available in __HK2_Generated_0 for injection at SystemInjecteeImpl(requiredType=List,parent=Library,qualifiers={},position=1,optional=false,self=false,unqualified=null,1121172875) -3. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of io.helidon.examples.pico.book.Library errors were found -4. java.lang.IllegalStateException: Unable to perform operation: resolve on io.helidon.examples.pico.book.Library -``` - -* Output from MainPico at runtime: - -``` -RUN 1: (PICO)) -found a library provider: Library$$picoActivator:io.helidon.examples.pico.book.Library:INIT:[io.helidon.examples.pico.book.BookHolder] -... -library is open: Library(books=[MobyDickInBlue$$picoActivator@50134894:io.helidon.examples.pico.book.MobyDickInBlue@0 : INIT : [io.helidon.examples.pico.book.Book], ParadiseLostInGreen$$picoActivator@28ba21f3:io.helidon.pico.examples.book.ParadiseLostInGreen@0 : INIT : [io.helidon.pico.examples.book.Book], UlyssesInGreen$$picoActivator@2530c12:io.helidon.pico.examples.book.UlyssesInGreen@0 : INIT : [io.helidon.pico.examples.book.Book]], bookHolders=[BookCase(allBooks=[MobyDickInBlue$$picoActivator@50134894:io.helidon.pico.examples.book.MobyDickInBlue@0 : INIT : [io.helidon.pico.examples.book.Book], ParadiseLostInGreen$$picoActivator@28ba21f3:io.helidon.pico.examples.book.ParadiseLostInGreen@0 : INIT : [io.helidon.pico.examples.book.Book], UlyssesInGreen$$picoActivator@2530c12:io.helidon.pico.examples.book.UlyssesInGreen@0 : INIT : [io.helidon.pico.examples.book.Book]]), EmptyRedBookCase(books=[Optional.empty]), GreenBookCase(greenBooks=[ParadiseLostInGreen$$picoActivator@28ba21f3:io.helidon.pico.examples.book.ParadiseLostInGreen@0 : INIT : [io.helidon.pico.examples.book.Book], UlyssesInGreen$$picoActivator@2530c12:io.helidon.pico.examples.book.UlyssesInGreen@0 : INIT : [io.helidon.pico.examples.book.Book]])], colorWheel=ColorWheel(preferredOptionalRedThing=Optional[EmptyRedBookCase(books=[Optional.empty])], preferredOptionalGreenThing=Optional[GreenColor()], preferredOptionalBlueThing=Optional[BlueColor()], preferredProviderRedThing=EmptyRedBookCase$$picoActivator@619a5dff:io.helidon.pico.examples.book.EmptyRedBookCase@16b4a017 : ACTIVE : [io.helidon.pico.examples.book.BookHolder, io.helidon.pico.examples.book.Color, io.helidon.pico.examples.book.RedColor], preferredProviderGreenThing=GreenColor$$picoActivator@7506e922:io.helidon.pico.examples.book.GreenColor@8807e25 : ACTIVE : [io.helidon.pico.examples.book.Color], preferredProviderBlueThing=BlueColor$$picoActivator@25f38edc:io.helidon.pico.examples.book.BlueColor@2a3046da : ACTIVE : [io.helidon.pico.examples.book.Color])) -library: Library(books=[MobyDickInBlue$$picoActivator@50134894:io.helidon.pico.examples.book.MobyDickInBlue@0 : INIT : [io.helidon.pico.examples.book.Book], ParadiseLostInGreen$$picoActivator@28ba21f3:io.helidon.pico.examples.book.ParadiseLostInGreen@0 : INIT : [io.helidon.pico.examples.book.Book], UlyssesInGreen$$picoActivator@2530c12:io.helidon.pico.examples.book.UlyssesInGreen@0 : INIT : [io.helidon.pico.examples.book.Book]], bookHolders=[BookCase(allBooks=[MobyDickInBlue$$picoActivator@50134894:io.helidon.pico.examples.book.MobyDickInBlue@0 : INIT : [io.helidon.pico.examples.book.Book], ParadiseLostInGreen$$picoActivator@28ba21f3:io.helidon.pico.examples.book.ParadiseLostInGreen@0 : INIT : [io.helidon.pico.examples.book.Book], UlyssesInGreen$$picoActivator@2530c12:io.helidon.pico.examples.book.UlyssesInGreen@0 : INIT : [io.helidon.pico.examples.book.Book]]), EmptyRedBookCase(books=[Optional.empty]), GreenBookCase(greenBooks=[ParadiseLostInGreen$$picoActivator@28ba21f3:io.helidon.pico.examples.book.ParadiseLostInGreen@0 : INIT : [io.helidon.pico.examples.book.Book], UlyssesInGreen$$picoActivator@2530c12:io.helidon.pico.examples.book.UlyssesInGreen@0 : INIT : [io.helidon.pico.examples.book.Book]])], colorWheel=ColorWheel(preferredOptionalRedThing=Optional[EmptyRedBookCase(books=[Optional.empty])], preferredOptionalGreenThing=Optional[GreenColor()], preferredOptionalBlueThing=Optional[BlueColor()], preferredProviderRedThing=EmptyRedBookCase$$picoActivator@619a5dff:io.helidon.pico.examples.book.EmptyRedBookCase@16b4a017 : ACTIVE : [io.helidon.pico.examples.book.BookHolder, io.helidon.pico.examples.book.Color, io.helidon.pico.examples.book.RedColor], preferredProviderGreenThing=GreenColor$$picoActivator@7506e922:io.helidon.pico.examples.book.GreenColor@8807e25 : ACTIVE : [io.helidon.pico.examples.book.Color], preferredProviderBlueThing=BlueColor$$picoActivator@25f38edc:io.helidon.pico.examples.book.BlueColor@2a3046da : ACTIVE : [io.helidon.pico.examples.book.Color])) - -``` - -* The output for Pico (see "library is open:") reveals how lifecycle is supported via the use of the standard PostConstruct and PreDestroy annotations. Pico will also display services that have not yet been lazily initialized (see "INIT") vs those services that have been (see "ACTIVE"). Hk2 and Pico behave in similar ways - it will only activate a service when the provider (or ServiceHandle in Hk2) is resolved. Until that time no service will be activated. It is a best practice, therefore, to use Provider<> type injection as much as possible as it will avoid chains of activation at runtime (i.e., every non-provided type injection point will be recursively activated). - -3. Pico generates a suggested module-info.java based upon analysis of your injection/dependency model (see ./target/pico/classes/module-info.java.pico). Hk2 does not have this feature. - -``` -// @Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") -module io.helidon.examples.pico.book { - exports io.helidon.examples.pico.book; - // pico module - Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") - provides io.helidon.pico.Module with io.helidon.examples.pico.book.Pico$$Module; - // pico services - Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") - requires transitive io.helidon.pico; -} -``` - -4. As previously mentioned, both Hk2 and Pico supports PostConstruct and PreDestroy annotations. Additionally, both frameworks offers a notion of RunLevel where RunLevel(value==0) typically represents a "startup" like service. Check the javadoc for details. - -5. Pico can optionally generate the activators (i.e., the DI supporting classes) on an external jar module. See the [logger](../logger) example for details. Hk2 has a similar mechanism called inhabitants generator - see references below. - -# References -* https://javaee.github.io/hk2/introduction.html -* https://javaee.github.io/hk2/getting-started.html diff --git a/examples/pico/book/pom.xml b/examples/pico/book/pom.xml deleted file mode 100644 index 4aea5315c9c..00000000000 --- a/examples/pico/book/pom.xml +++ /dev/null @@ -1,138 +0,0 @@ - - - - - - io.helidon.examples.pico - helidon-examples-pico-project - 4.0.0-SNAPSHOT - ../pom.xml - - 4.0.0 - - io.helidon.examples.pico.book - helidon-examples-pico-book - Helidon Pico Examples - Book (Hk2 and Pico) - - - - 3.0.3 - 5.1.0 - - io.helidon.examples.pico.book.MainHk2 - io.helidon.examples.pico.book.MainPico - - - - - jakarta.annotation - jakarta.annotation-api - - - - - org.junit.jupiter - junit-jupiter-api - test - - - - - org.glassfish.hk2 - hk2-locator - ${version.lib.hk2} - - - - io.helidon.pico - helidon-pico-runtime - - - io.helidon.builder - helidon-builder - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - true - - -Apico.autoAddNonContractInterfaces=false - - - - - org.glassfish.hk2 - hk2-metadata-generator - ${version.lib.hk2} - - - - io.helidon.pico - helidon-pico-processor - ${helidon.version} - - - - - - io.helidon.pico - helidon-pico-maven-plugin - ${helidon.version} - - - compile - compile - - application-create - - - - - ALL - - - - maven-assembly-plugin - - - jar-with-dependencies - - - - - make-assembly - package - - single - - - - - - - - diff --git a/examples/pico/book/run.sh b/examples/pico/book/run.sh deleted file mode 100755 index 8d2f870392b..00000000000 --- a/examples/pico/book/run.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -e -# -# 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. -# - -# mvn clean install -clear -echo "RUN 1: (HK2)" -java -cp target/helidon-examples-pico-book-4.0.0-SNAPSHOT-jar-with-dependencies.jar io.helidon.examples.pico.book.MainHk2 -echo "RUN 2: (HK2)" -java -cp target/helidon-examples-pico-book-4.0.0-SNAPSHOT-jar-with-dependencies.jar io.helidon.examples.pico.book.MainHk2 -echo "========================" -echo "RUN 1: (PICO)" -java -cp target/helidon-examples-pico-book-4.0.0-SNAPSHOT-jar-with-dependencies.jar io.helidon.examples.pico.book.MainPico -echo "RUN 2: (PICO)" -java -cp target/helidon-examples-pico-book-4.0.0-SNAPSHOT-jar-with-dependencies.jar io.helidon.examples.pico.book.MainPico diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Blue.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Blue.java deleted file mode 100644 index 438012ac4dd..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Blue.java +++ /dev/null @@ -1,35 +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. - */ - -package io.helidon.examples.pico.book; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import jakarta.inject.Qualifier; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.ElementType.TYPE; - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target({TYPE, METHOD, FIELD, PARAMETER}) -public @interface Blue { - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/BlueColor.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/BlueColor.java deleted file mode 100644 index 0955ad78354..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/BlueColor.java +++ /dev/null @@ -1,33 +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. - */ - -package io.helidon.examples.pico.book; - -import io.helidon.pico.api.Contract; - -@Contract -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -@jakarta.inject.Named -@Blue -public class BlueColor implements Color { - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Book.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Book.java deleted file mode 100644 index 7597573581e..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Book.java +++ /dev/null @@ -1,29 +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. - */ - -package io.helidon.examples.pico.book; - -import io.helidon.pico.api.Contract; - -@Contract -@org.jvnet.hk2.annotations.Contract -public interface Book { - - String getName(); - - Class getColor(); - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/BookCase.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/BookCase.java deleted file mode 100644 index 30d6c72dfab..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/BookCase.java +++ /dev/null @@ -1,48 +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. - */ - -package io.helidon.examples.pico.book; - -import java.util.Collection; -import java.util.List; - -import io.helidon.pico.api.Contract; - -import jakarta.inject.Inject; -import jakarta.inject.Provider; - -/** - * Demonstrates a field type injection point. - */ -@Contract -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -public class BookCase implements BookHolder { - - @Inject - List> allBooks; - - @Override - public Collection getBooks() { - return allBooks; - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/BookHolder.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/BookHolder.java deleted file mode 100644 index d5f83e691d8..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/BookHolder.java +++ /dev/null @@ -1,29 +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. - */ - -package io.helidon.examples.pico.book; - -import java.util.Collection; - -import io.helidon.pico.api.Contract; - -@Contract -@org.jvnet.hk2.annotations.Contract -public interface BookHolder { - - Collection getBooks(); - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Color.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Color.java deleted file mode 100644 index d2ab70a84f6..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Color.java +++ /dev/null @@ -1,25 +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. - */ - -package io.helidon.examples.pico.book; - -import io.helidon.pico.api.Contract; - -@Contract -@org.jvnet.hk2.annotations.Contract -public interface Color { - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/ColorWheel.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/ColorWheel.java deleted file mode 100644 index 5e909be1703..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/ColorWheel.java +++ /dev/null @@ -1,108 +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. - */ - -package io.helidon.examples.pico.book; - -import java.util.List; -import java.util.Optional; - -import jakarta.inject.Inject; -import jakarta.inject.Provider; - -import static io.helidon.pico.runtime.ServiceUtils.toDescription; -import static io.helidon.pico.runtime.ServiceUtils.toDescriptions; - -/** - * Demonstrates setter type injection points w/ qualifiers & optionals. - */ -@org.jvnet.hk2.annotations.Service -public class ColorWheel { - Optional preferredOptionalRedThing; - Optional preferredOptionalGreenThing; - Optional preferredOptionalBlueThing; - - Provider preferredProviderRedThing; - Provider preferredProviderGreenThing; - Provider preferredProviderBlueThing; - - @Inject - void setPreferredOptionalRedThing(@org.jvnet.hk2.annotations.Optional @Red Optional thing) { - System.out.println("setting optional color wheel red to " + thing); - preferredOptionalRedThing = thing; - } - - @Inject - void setPreferredOptionalGreenThing(@org.jvnet.hk2.annotations.Optional @Green Optional thing) { - System.out.println("setting optional color wheel green to " + thing); - preferredOptionalGreenThing = thing; - } - - @Inject - void setPreferredOptionalBlueThing(@org.jvnet.hk2.annotations.Optional @Blue Optional thing) { - System.out.println("setting optional color wheel blue to " + thing); - preferredOptionalBlueThing = thing; - } - - @Inject - void setPreferredProviderRedThing(@org.jvnet.hk2.annotations.Optional @Red Provider thing) { - System.out.println("setting provider color wheel red to " + toDescription(thing)); - preferredProviderRedThing = thing; - } - - @Inject - void setPreferredProviderGreenThing(@org.jvnet.hk2.annotations.Optional @Green Provider thing) { - System.out.println("setting provider wheel green to " + toDescription(thing)); - preferredProviderGreenThing = thing; - } - - @Inject - void setPreferredBlueThing(@org.jvnet.hk2.annotations.Optional @Blue Provider thing) { - System.out.println("setting provider wheel blue to " + toDescription(thing)); - preferredProviderBlueThing = thing; - } - - @Inject - void setListProviderRedThings(@org.jvnet.hk2.annotations.Optional @Red List> things) { - System.out.println("setting providerList color wheel red to " + (things == null ? "null" : toDescriptions(things))); - } - - @Inject - void setListProviderGreenThings(@org.jvnet.hk2.annotations.Optional @Green List> things) { - System.out.println("setting providerList wheel green to " + (things == null ? "null" : toDescriptions(things))); - } - - @Inject - void setListProviderBlueThings(@org.jvnet.hk2.annotations.Optional @Blue List> things) { - System.out.println("setting providerList wheel blue to " + (things == null ? "null" : toDescriptions(things))); - } - - // not supported by Pico... -// @Inject -// void setIterableProviderRedThings(@org.jvnet.hk2.annotations.Optional @Red IterableProvider things) { -// System.out.println("setting iterableList color wheel red to " + things); -// } -// -// @Inject -// void setIterableProviderGreenThings(@org.jvnet.hk2.annotations.Optional @Green IterableProvider things) { -// System.out.println("setting iterableList wheel green to " + things); -// } -// -// @Inject -// void setIterableProviderBlueThings(@org.jvnet.hk2.annotations.Optional @Blue IterableProvider things) { -// System.out.println("setting iterableList wheel blue to " + things); -// } - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/EmptyRedBookCase.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/EmptyRedBookCase.java deleted file mode 100644 index 8a4ce7c6efa..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/EmptyRedBookCase.java +++ /dev/null @@ -1,50 +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. - */ - -package io.helidon.examples.pico.book; - -import java.util.Collection; -import java.util.Collections; -import java.util.Optional; - -import io.helidon.pico.api.Contract; - -import jakarta.inject.Inject; - -@Contract -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -@Red -public class EmptyRedBookCase extends RedColor implements BookHolder { - - private Collection books; - - @Override - public Collection getBooks() { - return books; - } - - @Inject - public EmptyRedBookCase(@Red Optional preferrredRedBook) { - this.books = Collections.singleton(preferrredRedBook); - } - - @Override - public String toString() { - return getClass().getSimpleName() + "(books=" + getBooks() + ")"; - } - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Green.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Green.java deleted file mode 100644 index 51a1596a5b9..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Green.java +++ /dev/null @@ -1,35 +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. - */ - -package io.helidon.examples.pico.book; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import jakarta.inject.Qualifier; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.ElementType.TYPE; - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target({TYPE, METHOD, FIELD, PARAMETER}) -public @interface Green { - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/GreenBookCase.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/GreenBookCase.java deleted file mode 100644 index ed60dab73e4..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/GreenBookCase.java +++ /dev/null @@ -1,51 +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. - */ - -package io.helidon.examples.pico.book; - -import java.util.Collection; -import java.util.List; - -import io.helidon.pico.api.Contract; - -import jakarta.inject.Inject; -import jakarta.inject.Provider; - -/** - * Demonstrates ctor injection with qualifiers and lists of providers. - */ -@Contract -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -public class GreenBookCase implements BookHolder { - - private final List> greenBooks; - - @Override - public Collection getBooks() { - return greenBooks; - } - - @Inject - GreenBookCase(@Green List> greenBooks) { - this.greenBooks = greenBooks; - } - - @Override - public String toString() { - return getClass().getSimpleName() + "(books=" + getBooks() + ")"; - } -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/GreenColor.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/GreenColor.java deleted file mode 100644 index 051212dd8f5..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/GreenColor.java +++ /dev/null @@ -1,32 +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. - */ - -package io.helidon.examples.pico.book; - -import io.helidon.pico.api.Contract; - -@Contract -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -@jakarta.inject.Named -@Green -public class GreenColor implements Color { - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Library.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Library.java deleted file mode 100644 index 48ff6b58c22..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Library.java +++ /dev/null @@ -1,76 +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. - */ - -package io.helidon.examples.pico.book; - -import java.util.Collection; -import java.util.List; - -import jakarta.annotation.PostConstruct; -import jakarta.annotation.PreDestroy; -import jakarta.inject.Inject; -import jakarta.inject.Provider; - -/** - * Demonstrates constructor injection of various types. - */ -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -public class Library implements BookHolder { - - private List> books; - private List bookHolders; - private ColorWheel colorWheel; - - @Inject - public Library( - List> books, - List bookHolders, - ColorWheel colorWheel) { - this.books = books; - this.bookHolders = bookHolders; - this.colorWheel = colorWheel; - } - - @Override - public Collection getBooks() { - return books; - } - - public Collection getBookHolders() { - return bookHolders; - } - - public ColorWheel getColorWheel() { - return colorWheel; - } - - @PostConstruct - public void postConstruct() { - System.out.println("library is open: " + this); - } - - @PreDestroy - public void preDestroy() { - System.out.println("library is closed: " + this); - } - - @Override - public String toString() { - return getClass().getSimpleName() + "(books=" + getBooks() + ")"; - } - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/MainHk2.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/MainHk2.java deleted file mode 100644 index d8a8ebb9c83..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/MainHk2.java +++ /dev/null @@ -1,54 +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. - */ - -package io.helidon.examples.pico.book; - -import org.glassfish.hk2.api.ServiceHandle; -import org.glassfish.hk2.api.ServiceLocator; -import org.glassfish.hk2.utilities.ServiceLocatorUtilities; - -public class MainHk2 { - - public static void main(String[] args) { - final long memStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long start = System.currentTimeMillis(); - - ServiceLocator locator = ServiceLocatorUtilities.createAndPopulateServiceLocator(); - - try { - ServiceHandle librarySh = locator.getServiceHandle(Library.class); - System.out.println("found a library handle: " + librarySh.getActiveDescriptor()); - Library library = librarySh.getService(); - System.out.println("found a library: " + library); - } catch (Exception e) { - // list injection is not supported in Hk2 - must switch to use IterableProvider instead. - // see https://javaee.github.io/hk2/apidocs/org/glassfish/hk2/api/IterableProvider.html - // and see https://javaee.github.io/hk2/introduction.html - System.out.println("error: " + e.getMessage()); - } - - ServiceHandle colorWheelSh = locator.getServiceHandle(ColorWheel.class); - System.out.println("found a color wheel handle: " + colorWheelSh.getActiveDescriptor()); - ColorWheel library = colorWheelSh.getService(); - System.out.println("color wheel: " + library); - - final long finish = System.currentTimeMillis(); - final long memFinish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - System.out.println("Hk2 Main memory consumption = " + (memFinish - memStart) + " bytes"); - System.out.println("Hk2 Main elapsed time = " + (finish - start) + " ms"); - } - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/MainPico.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/MainPico.java deleted file mode 100644 index 3517d1b3c17..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/MainPico.java +++ /dev/null @@ -1,47 +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. - */ - -package io.helidon.examples.pico.book; - -import io.helidon.pico.api.PicoServices; -import io.helidon.pico.api.ServiceProvider; -import io.helidon.pico.api.Services; - -public class MainPico { - - public static void main(String[] args) { - final long memStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long start = System.currentTimeMillis(); - - Services services = PicoServices.realizedServices(); - - ServiceProvider librarySp = services.lookupFirst(Library.class); - System.out.println("found a library provider: " + librarySp.description()); - Library library = librarySp.get(); - System.out.println("library: " + library); - - ServiceProvider colorWheelSp = services.lookupFirst(ColorWheel.class); - System.out.println("found a color wheel provider: " + colorWheelSp.description()); - ColorWheel colorWheel = colorWheelSp.get(); - System.out.println("color wheel: " + colorWheel); - - final long finish = System.currentTimeMillis(); - final long memFinish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - System.out.println("Pico Main memory consumption = " + (memFinish - memStart) + " bytes"); - System.out.println("Pico Main elapsed time = " + (finish - start) + " ms"); - } - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/MobyDickInBlue.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/MobyDickInBlue.java deleted file mode 100644 index 0633d24c34c..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/MobyDickInBlue.java +++ /dev/null @@ -1,40 +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. - */ - -package io.helidon.examples.pico.book; - -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -@jakarta.inject.Named -@Blue -public class MobyDickInBlue implements Book { - - @Override - public String getName() { - return "Moby Dick"; - } - - @Override - public Class getColor() { - return BlueColor.class; - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/ParadiseLostInGreen.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/ParadiseLostInGreen.java deleted file mode 100644 index 806c8946f4f..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/ParadiseLostInGreen.java +++ /dev/null @@ -1,40 +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. - */ - -package io.helidon.examples.pico.book; - -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -@jakarta.inject.Named -@Green -public class ParadiseLostInGreen implements Book { - - @Override - public String getName() { - return "Paradise Lost"; - } - - @Override - public Class getColor() { - return null; - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Red.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Red.java deleted file mode 100644 index 24b6f5ba99c..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/Red.java +++ /dev/null @@ -1,35 +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. - */ - -package io.helidon.examples.pico.book; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import jakarta.inject.Qualifier; - -import static java.lang.annotation.ElementType.FIELD; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.ElementType.TYPE; - -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target({TYPE, METHOD, FIELD, PARAMETER}) -public @interface Red { - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/RedColor.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/RedColor.java deleted file mode 100644 index 22bc1fb80a2..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/RedColor.java +++ /dev/null @@ -1,33 +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. - */ - -package io.helidon.examples.pico.book; - -import io.helidon.pico.api.Contract; - -@Contract -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -@jakarta.inject.Named -@Red -public class RedColor implements Color { - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/UlyssesInGreen.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/UlyssesInGreen.java deleted file mode 100644 index 4d484779282..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/UlyssesInGreen.java +++ /dev/null @@ -1,40 +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. - */ - -package io.helidon.examples.pico.book; - -@org.jvnet.hk2.annotations.Service -@jakarta.inject.Singleton -@jakarta.inject.Named -@Green -public class UlyssesInGreen implements Book { - - @Override - public String getName() { - return "Ulysses"; - } - - @Override - public Class getColor() { - return GreenColor.class; - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/package-info.java b/examples/pico/book/src/main/java/io/helidon/examples/pico/book/package-info.java deleted file mode 100644 index 4c2a7178c5a..00000000000 --- a/examples/pico/book/src/main/java/io/helidon/examples/pico/book/package-info.java +++ /dev/null @@ -1,20 +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. - */ - -/** - * Pico Book Example. - */ -package io.helidon.examples.pico.book; diff --git a/examples/pico/book/src/main/resources/logging.properties b/examples/pico/book/src/main/resources/logging.properties deleted file mode 100644 index b3e81c5cb71..00000000000 --- a/examples/pico/book/src/main/resources/logging.properties +++ /dev/null @@ -1,20 +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. -# -handlers=java.util.logging.ConsoleHandler -java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS.%1$tL %5$s%6$s%n -# Global logging level. Can be overridden by specific loggers -.level=INFO -io.helidon.nima.level=INFO diff --git a/examples/pico/book/src/test/java/io/helidon/examples/pico/book/MainHk2Test.java b/examples/pico/book/src/test/java/io/helidon/examples/pico/book/MainHk2Test.java deleted file mode 100644 index ab356fca811..00000000000 --- a/examples/pico/book/src/test/java/io/helidon/examples/pico/book/MainHk2Test.java +++ /dev/null @@ -1,33 +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. - */ - -package io.helidon.examples.pico.book; - -import org.junit.jupiter.api.Test; - -public class MainHk2Test { - - @Test - public void testMain() { - final long start = System.currentTimeMillis(); - - MainHk2.main(null); - - final long finish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - System.out.println("Hk2 Junit elapsed time = " + (finish - start) + " ms"); - } - -} diff --git a/examples/pico/book/src/test/java/io/helidon/examples/pico/book/MainPicoTest.java b/examples/pico/book/src/test/java/io/helidon/examples/pico/book/MainPicoTest.java deleted file mode 100644 index 668472596ec..00000000000 --- a/examples/pico/book/src/test/java/io/helidon/examples/pico/book/MainPicoTest.java +++ /dev/null @@ -1,33 +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. - */ - -package io.helidon.examples.pico.book; - -import org.junit.jupiter.api.Test; - -public class MainPicoTest { - - @Test - public void testMain() { - final long start = System.currentTimeMillis(); - - MainPico.main(null); - - final long finish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - System.out.println("Pico Junit elapsed time = " + (finish - start) + " ms"); - } - -} diff --git a/examples/pico/car/README.md b/examples/pico/car/README.md deleted file mode 100644 index 959b94cc358..00000000000 --- a/examples/pico/car/README.md +++ /dev/null @@ -1,220 +0,0 @@ -# pico-examples-car - -This example compares Pico to Google's Dagger 2. It was taken from an example found on the internet (see references below). The example is fairly trivial, but it is sufficient to compare the similarities between the two. - -[dagger2](dagger2) contains the Dagger2 application module. -[pico](pico) contains the Pico application module. - -Unlike the [logger](../logger) example, this example replicates the entire set of classes for each application module. This was done for a few reasons. The primary reason is that while Pico offers the ability to generate the DI supporting module on an external jar (as the logger example demonstrates), Dagger does not provide such an option - the DI module for dagger -only provides for an annotation processor mechanism, thereby requiring the developer to inject the Dagger annotation processor -into the build of the project to generate the DI module at compilation time. The other reason why this was done was to demonstrate -a few variations in the way developers can use Pico for more complicated use cases. - -Review the code to see the similarities and differences. Note that the generated source code is found under -"./target/generated-sources" for each sub application module. Summaries of similarities and differences are listed below. - -# Building and Running -``` -> mvn clean install -> ./run.sh -``` - -# Notable - -1. Pico supports jakarta.inject as well as javax.inject packaging. Dagger 2 (at the time of this writing - see https://github.com/google/dagger/issues/2058) only supports javax.inject. This example uses javax.inject for the Dagger app, and uses jakarta.inject for the Pico app. Functionally, however, both are the same. - -2. The API programming model between Pico and Dagger is fairly different. Pico strives to closely follow the jsr-330 specification and relies heavily on annotation processing to generate *all* of the supporting DI classes, and those classes are hidden as an implementation detail not directly exposed to the (typical) developer. This can be seen by observing Dagger's [VehiclesComponent.java](./dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/VehiclesComponent.java) and [VehiclesModule.java](./dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/VehiclesModule.java) classes - notice the imports as well as the code the developer is expected to write. - -On the Pico side, you will notice that the only #import of Pico is found on the [Vehicle.java](./pico/src/main/java/io/helidon/examples/pico/car/pico/Vehicle.java) class. The @Contract annotation is used to demarcate the Vehcile iterface that Car implements/advertises. All the other imports are using standard javax/jakarta annotations. Pico actually offers an option to advertise all interfaces as contracts (see the pom.xml snippet below). Turning on this switch will allow the @Contract to be removed as well, thereby using 100% standard javax/jakarta types. - -``` - - - - -``` - -There are a few other "forced" examples under Pico which demonstrate additional options available. For example, the [BrandProvider.java](./pico/src/main/java/io/helidon/examples/pico/car/pico/BrandProvider.java) class is the standard means to produce an instance of a Brand. The implementation can choose the cardinality of the instances created. At times, it might be convenient to "know" the injection point consumer requesting the Brand instance, in order to change the cardinality or somehow make it dependent in scope. This option is demonstrated in the [BrandProvider.java](./pico/src/main/java/io/helidon/examples/pico/car/pico/EngineProvider.java) class. - -3. Both Dagger and Pico are using compile-time to generate the DI supporting classes as mentioned above. The code generated between the two, however is a little different. Let's have a closer look: - -The Dagger generated Car_Factory: -```java -@ScopeMetadata -@QualifierMetadata -@DaggerGenerated -@Generated( - value = "dagger.internal.codegen.ComponentProcessor", - comments = "https://dagger.dev" -) -@SuppressWarnings({ - "unchecked", - "rawtypes" -}) -public final class Car_Factory implements Factory { - private final Provider engineProvider; - - private final Provider brandProvider; - - public Car_Factory(Provider engineProvider, Provider brandProvider) { - this.engineProvider = engineProvider; - this.brandProvider = brandProvider; - } - - @Override - public Car get() { - return newInstance(engineProvider.get(), brandProvider.get()); - } - - public static Car_Factory create(Provider engineProvider, Provider brandProvider) { - return new Car_Factory(engineProvider, brandProvider); - } - - public static Car newInstance(Engine engine, Brand brand) { - return new Car(engine, brand); - } -} -``` - -The Pico generated Car$$picoActivator: -```java -/** - * Activator for {@link io.helidon.examples.pico.car.pico.Car}. - */ -// @Singleton -@SuppressWarnings("unchecked") -@Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") -public class Car$$picoActivator - extends io.helidon.pico.runtime.AbstractServiceProvider { - private static final ServiceInfoDefault serviceInfo = - ServiceInfoDefault.builder() - .serviceTypeName(io.helidon.examples.pico.car.pico.Car.class.getName()) - .addContractsImplemented(io.helidon.examples.pico.car.pico.Vehicle.class.getName()) - .activatorTypeName(Car$$picoActivator.class.getName()) - .addScopeTypeName(jakarta.inject.Singleton.class.getName()) - .build(); - - /** - * The global singleton instance for this service provider activator. - */ - public static final Car$$picoActivator INSTANCE = new Car$$picoActivator(); - - /** - * Default activator constructor. - */ - protected Car$$picoActivator() { - serviceInfo(serviceInfo); - } - - /** - * The service type of the managed service. - * - * @return the service type of the managed service - */ - public Class serviceType() { - return io.helidon.examples.pico.car.pico.Car.class; - } - - @Override - public DependenciesInfo dependencies() { - DependenciesInfo deps = Dependencies.builder(io.helidon.examples.pico.car.pico.Car.class.getName()) - .add(CONSTRUCTOR, io.helidon.examples.pico.car.pico.Engine.class, ElementKind.CONSTRUCTOR, 2, Access.PUBLIC).elemOffset(1) - .add(CONSTRUCTOR, io.helidon.examples.pico.car.pico.Brand.class, ElementKind.CONSTRUCTOR, 2, Access.PUBLIC).elemOffset(2) - .build(); - return Dependencies.combine(super.dependencies(), deps); - } - - @Override - protected Car createServiceProvider(Map deps) { - io.helidon.examples.pico.car.pico.Engine c1 = (io.helidon.examples.pico.car.pico.Engine) get(deps, "io.helidon.examples.pico.car.pico.|2(1)"); - io.helidon.examples.pico.car.pico.Brand c2 = (io.helidon.examples.pico.car.pico.Brand) get(deps, "io.helidon.examples.pico.car.pico.|2(2)"); - return new io.helidon.examples.pico.car.pico.Car(c1, c2); - } - -} -``` - -Here is the main difference: - -* Pico attempts to model each service in terms of the contracts/interfaces each service offers, as well as the dependencies (other contracts/interfaces) that it requires. A more elaborate dependency model would additionally include the qualifiers (such as @Named), whether the services are optional, list-based, etc. This model extends down to mention each element (for methods or constructors for example). All of this is generated at compile-time. In this way the Pico Services registry has knowledge of every available service and what it offers and what it requires. These services are left to be lazily activated on-demand. - -4. Pico provides the ability (as demonstrated in the [pom.xml](./pico/pom.xml)) to take the injection model, analyze and validate it, and ultimately bind to the final injection model at assembly time. Using this option provides several key benefits including deterministic behavior, speed & performance enhancements, and helps to ensure the completeness & validity of the entire application's dependency graph at compile time. When this option is applied the Pico$$Application is generated. Here is what it looks like for this example: - -```java -@Generated(value = "io.helidon.pico.maven.plugin.ApplicationCreatorMojo", comments = "version=1") -@Singleton @Named(Pico$$Application.NAME) -public class Pico$$Application implements Application { - static final String NAME = "io.helidon.examples.pico.car.pico"; - - @Override - public Optional named() { - return Optional.of(NAME); - } - - @Override - public String toString() { - return NAME + ":" + getClass().getName(); - } - - @Override - public void configure(ServiceInjectionPlanBinder binder) { - /** - * In module name "io.helidon.examples.pico.car.pico". - * @see {@link io.helidon.examples.pico.car.pico.BrandProvider } - */ - binder.bindTo(io.helidon.examples.pico.car.pico.BrandProvider$$picoActivator.INSTANCE) - .commit(); - - /** - * In module name "io.helidon.examples.pico.car.pico". - * @see {@link io.helidon.examples.pico.car.pico.Car } - */ - binder.bindTo(io.helidon.examples.pico.car.pico.Car$$picoActivator.INSTANCE) - .bind("io.helidon.examples.pico.car.pico.|2(1)", - io.helidon.examples.pico.car.pico.EngineProvider$$picoActivator.INSTANCE) - .bind("io.helidon.examples.pico.car.pico.|2(2)", - io.helidon.examples.pico.car.pico.BrandProvider$$picoActivator.INSTANCE) - .commit(); - - /** - * In module name "io.helidon.examples.pico.car.pico". - * @see {@link io.helidon.examples.pico.car.pico.EngineProvider } - */ - binder.bindTo(io.helidon.examples.pico.car.pico.EngineProvider$$picoActivator.INSTANCE) - .commit(); - - } -} -``` - -At initialization time (and using the default configuration) Pico will use the service loader to attempt to find the Application instance and use that instead of resolving the dependency graph at runtime. Generating the application is optional but recommended for production scenarios. - -5. The Dagger application is considerably smaller in terms of disk and memory footprints. This makes sense considering that the primary driver for Dagger 2 is to be consumed by Android developers who naturally require a liter footprint. Pico, while still small and lite compared to many other options on the i-net, offers more features including: interceptor/interception capabilities, flexible service registry search & resolution semantics, service meta information as described above, lazy activation, circular dependency detection, extensibility, configuration, etc. The default configuration assumes a production use case where the services registry is assumed to be non-dynamic/static in nature. - -On the topic of extensibility - Pico is centered around extensibility of its tooling. The templates use replaceable [handlebars](https://github.com/jknack/handlebars.java), and the generators use service loader. Anyone can either override Pico's reference implementation, or else write an entirely new implementation based upon the API & SPI that Pico provides. - -6. Pico requires less coding as compared to Dagger. In this example the BrandProvider and EngineProvider were contrived in order to demonstrate a nuances of the approach. Generally speaking most of the time the @Singleton annotation (or lack thereof) is all that is needed, depending upon the injection scope required. - -7. Pico offers lifecycle support (see jakarta.annotation.@PostConstruct, jakarta.annotation.@PreDestroy, Pico's @RunLevel - annotations and PicoServices#shutdown()). - -8. Pico generates a suggested module-info.java based upon analysis of your injection/dependency model (see ./target/classes/module-info.java.pico). - -```./target/classes/module-info.java.pico -// @Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") -module io.helidon.examples.pico.car.pico { - exports io.helidon.examples.pico.car.pico; - // pico module - Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") - provides io.helidon.pico.Module with io.helidon.examples.pico.car.pico.Pico$$Module; - // pico external contract usage - Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") - uses jakarta.inject.Provider; - uses io.helidon.pico.InjectionPointProvider; - // pico services - Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") - requires transitive io.helidon.pico; -} -``` - -9. Pico can optionally generate the activators (i.e., the DI supporting classes) on an external jar module. See the [logger](../logger) example for details. - -# References -* https://www.baeldung.com/dagger-2 diff --git a/examples/pico/car/dagger2/pom.xml b/examples/pico/car/dagger2/pom.xml deleted file mode 100644 index 30a2d05d00e..00000000000 --- a/examples/pico/car/dagger2/pom.xml +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - io.helidon.examples.pico.car - helidon-examples-pico-car-project - 4.0.0-SNAPSHOT - ../pom.xml - - 4.0.0 - - helidon-examples-pico-car-dagger2 - Helidon Pico Examples - Car - Dagger2 - - - io.helidon.examples.pico.car.dagger2.Main - - - - - com.google.dagger - dagger - ${version.lib.dagger} - - - io.helidon.builder - helidon-builder - - - jakarta.annotation - jakarta.annotation-api - provided - - - org.junit.jupiter - junit-jupiter-api - test - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - true - - - com.google.dagger - dagger-compiler - ${version.lib.dagger} - - - io.helidon.builder - helidon-builder-processor - ${helidon.version} - - - - - - maven-assembly-plugin - - - jar-with-dependencies - - - - ${mainClass} - - - - - - make-assembly - package - - single - - - - - - org.apache.maven.plugins - maven-jar-plugin - ${version.plugin.jar} - - - - true - libs - ${mainClass} - false - - - - - - org.codehaus.mojo - exec-maven-plugin - ${version.plugin.exec} - - ${mainClass} - - - - - - diff --git a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Brand.java b/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Brand.java deleted file mode 100644 index a5958f0c86e..00000000000 --- a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Brand.java +++ /dev/null @@ -1,26 +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. - */ - -package io.helidon.examples.pico.car.dagger2; - -import io.helidon.builder.Builder; - -@Builder(requireLibraryDependencies = false) -public interface Brand { - - String name(); - -} diff --git a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Car.java b/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Car.java deleted file mode 100644 index c876f655200..00000000000 --- a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Car.java +++ /dev/null @@ -1,57 +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. - */ - -package io.helidon.examples.pico.car.dagger2; - -import javax.inject.Inject; - -public class Car implements Vehicle { - - private Engine engine; - private Brand brand; - - @Inject - public Car( - Engine engine, - Brand brand) { - this.engine = engine; - this.brand = brand; - } - - @Override - public String toString() { - return "Car(engine=" + engine() + ",brand=" + brand() + ")"; - } - - @Override - public Engine engine() { - return engine; - } - - public void engine(Engine engine) { - this.engine = engine; - } - - @Override - public Brand brand() { - return brand; - } - - public void brand(Brand brand) { - this.brand = brand; - } - -} diff --git a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Engine.java b/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Engine.java deleted file mode 100644 index 1fb3165b765..00000000000 --- a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Engine.java +++ /dev/null @@ -1,34 +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. - */ - -package io.helidon.examples.pico.car.dagger2; - -public class Engine { - - public void start() { - System.out.println("Engine started"); - } - - public void stop() { - System.out.println("Engine stopped"); - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Main.java b/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Main.java deleted file mode 100644 index 5449dfb45a9..00000000000 --- a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Main.java +++ /dev/null @@ -1,41 +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. - */ - -package io.helidon.examples.pico.car.dagger2; - -public class Main { - - public static void main(String[] args) { - final long memStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long start = System.currentTimeMillis(); - - if (args.length > 0) { - VehiclesModule.brandName = args[0]; - } - VehiclesComponent component = DaggerVehiclesComponent.create(); - System.out.println("found a car component: " + component); - Car car = component.buildCar(); - System.out.println("found a car: " + car); - car.engine().start(); - car.engine().stop(); - - final long finish = System.currentTimeMillis(); - final long memFinish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - System.out.println("Dagger2 Main memory consumption = " + (memFinish - memStart) + " bytes"); - System.out.println("Dagger2 Main elapsed time = " + (finish - start) + " ms"); - } - -} diff --git a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Vehicle.java b/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Vehicle.java deleted file mode 100644 index 3a03d858afc..00000000000 --- a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/Vehicle.java +++ /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. - */ - -package io.helidon.examples.pico.car.dagger2; - -public interface Vehicle { - Engine engine(); - Brand brand(); -} diff --git a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/VehiclesComponent.java b/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/VehiclesComponent.java deleted file mode 100644 index 7a1c86d7395..00000000000 --- a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/VehiclesComponent.java +++ /dev/null @@ -1,27 +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. - */ - -package io.helidon.examples.pico.car.dagger2; - -import javax.inject.Singleton; - -import dagger.Component; - -@Singleton -@Component(modules = VehiclesModule.class) -public interface VehiclesComponent { - Car buildCar(); -} diff --git a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/VehiclesModule.java b/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/VehiclesModule.java deleted file mode 100644 index 22b4003b454..00000000000 --- a/examples/pico/car/dagger2/src/main/java/io/helidon/examples/pico/car/dagger2/VehiclesModule.java +++ /dev/null @@ -1,45 +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. - */ - -package io.helidon.examples.pico.car.dagger2; - -import javax.inject.Singleton; - -import dagger.Module; -import dagger.Provides; - -@Module -public class VehiclesModule { - - static String brandName; - - @Provides - public Engine provideEngine() { - return new Engine(); - } - - @Provides - @Singleton - public Brand provideBrand() { - return BrandDefault.builder().name(brandName).build(); - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/examples/pico/car/dagger2/src/test/java/io/helidon/examples/pico/car/dagger2/Dagger2Test.java b/examples/pico/car/dagger2/src/test/java/io/helidon/examples/pico/car/dagger2/Dagger2Test.java deleted file mode 100644 index 5c9101da70c..00000000000 --- a/examples/pico/car/dagger2/src/test/java/io/helidon/examples/pico/car/dagger2/Dagger2Test.java +++ /dev/null @@ -1,36 +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. - */ - -package io.helidon.examples.pico.car.dagger2; - -import org.junit.jupiter.api.Test; - -public class Dagger2Test { - - @Test - public void testMain() { - final long memStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long start = System.currentTimeMillis(); - - Main.main(new String[] {"Dagger2"}); - - final long finish = System.currentTimeMillis(); - final long memFinish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - System.out.println("Dagger2 JUnit memory consumption = " + (memFinish - memStart) + " bytes"); - System.out.println("Dagger2 JUnit elapsed time = " + (finish - start) + " ms"); - } - -} diff --git a/examples/pico/car/pico/pom.xml b/examples/pico/car/pico/pom.xml deleted file mode 100644 index 8ac1f90116b..00000000000 --- a/examples/pico/car/pico/pom.xml +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - io.helidon.examples.pico.car - helidon-examples-pico-car-project - 4.0.0-SNAPSHOT - ../pom.xml - - 4.0.0 - - helidon-examples-pico-car-pico - Helidon Pico Examples - Car - Pico - - - io.helidon.examples.pico.car.pico.Main - - - - - io.helidon.pico - helidon-pico-runtime - - - io.helidon.builder - helidon-builder - - - org.junit.jupiter - junit-jupiter-api - test - - - jakarta.inject - jakarta.inject-api - - - - jakarta.annotation - jakarta.annotation-api - provided - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - true - - - - - - - io.helidon.pico - helidon-pico-processor - ${helidon.version} - - - io.helidon.builder - helidon-builder-processor - ${helidon.version} - - - - - - maven-assembly-plugin - - - jar-with-dependencies - - - - ${mainClass} - - - - - - make-assembly - package - - single - - - - - - io.helidon.pico - helidon-pico-maven-plugin - ${helidon.version} - - - compile - compile - - application-create - - - - - ALL - - - - org.apache.maven.plugins - maven-jar-plugin - ${version.plugin.jar} - - - - true - libs - ${mainClass} - false - - - - - - org.codehaus.mojo - exec-maven-plugin - ${version.plugin.exec} - - ${mainClass} - - - - - - diff --git a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Brand.java b/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Brand.java deleted file mode 100644 index 53bba32116e..00000000000 --- a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Brand.java +++ /dev/null @@ -1,26 +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. - */ - -package io.helidon.examples.pico.car.pico; - -import io.helidon.builder.Builder; - -@Builder -public interface Brand { - - String name(); - -} diff --git a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/BrandProvider.java b/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/BrandProvider.java deleted file mode 100644 index 65d6907a1f4..00000000000 --- a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/BrandProvider.java +++ /dev/null @@ -1,31 +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. - */ - -package io.helidon.examples.pico.car.pico; - -import jakarta.inject.Provider; -import jakarta.inject.Singleton; - -@Singleton -public class BrandProvider implements Provider { - static String brandName; - - @Override - public Brand get() { - return BrandDefault.builder().name(brandName).build(); - } - -} diff --git a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Car.java b/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Car.java deleted file mode 100644 index 72f6ade9841..00000000000 --- a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Car.java +++ /dev/null @@ -1,57 +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. - */ - -package io.helidon.examples.pico.car.pico; - -import jakarta.inject.Inject; -import jakarta.inject.Singleton; - -@Singleton -public class Car implements Vehicle { - - private Engine engine; - private Brand brand; - - @Inject - public Car(Engine engine, Brand brand) { - this.engine = engine; - this.brand = brand; - } - - @Override - public String toString() { - return "Car(engine=" + engine() + ",brand=" + brand() + ")"; - } - - @Override - public Engine engine() { - return engine; - } - - public void engine(Engine engine) { - this.engine = engine; - } - - @Override - public Brand brand() { - return brand; - } - - public void brand(Brand brand) { - this.brand = brand; - } - -} diff --git a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Engine.java b/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Engine.java deleted file mode 100644 index fd77d120508..00000000000 --- a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Engine.java +++ /dev/null @@ -1,34 +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. - */ - -package io.helidon.examples.pico.car.pico; - -public class Engine { - - public void start() { - System.out.println("Engine started"); - } - - public void stop() { - System.out.println("Engine stopped"); - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/EngineProvider.java b/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/EngineProvider.java deleted file mode 100644 index 4915528db32..00000000000 --- a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/EngineProvider.java +++ /dev/null @@ -1,39 +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. - */ - -package io.helidon.examples.pico.car.pico; - -import java.util.Optional; - -import io.helidon.pico.api.ContextualServiceQuery; -import io.helidon.pico.api.InjectionPointProvider; - -import jakarta.inject.Singleton; - -@Singleton -public class EngineProvider implements InjectionPointProvider { - - @Override - public Optional first(ContextualServiceQuery query) { - return Optional.of(new Engine()); - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } - -} diff --git a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Main.java b/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Main.java deleted file mode 100644 index 501db0401bc..00000000000 --- a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Main.java +++ /dev/null @@ -1,44 +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. - */ - -package io.helidon.examples.pico.car.pico; - -import io.helidon.pico.api.PicoServices; -import io.helidon.pico.api.ServiceProvider; - -public class Main { - - public static void main(String[] args) { - final long memStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long start = System.currentTimeMillis(); - - if (args.length > 0) { - BrandProvider.brandName = args[0]; - } - ServiceProvider carSp = PicoServices.realizedServices().lookupFirst(Car.class); - System.out.println("found a car provider: " + carSp.description()); - Car car = carSp.get(); - System.out.println("found a car: " + car); - car.engine().start(); - car.engine().stop(); - - final long finish = System.currentTimeMillis(); - final long memFinish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - System.out.println("Pico Main memory consumption = " + (memFinish - memStart) + " bytes"); - System.out.println("Pico Main elapsed time = " + (finish - start) + " ms"); - } - -} diff --git a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Vehicle.java b/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Vehicle.java deleted file mode 100644 index db9236e096d..00000000000 --- a/examples/pico/car/pico/src/main/java/io/helidon/examples/pico/car/pico/Vehicle.java +++ /dev/null @@ -1,25 +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. - */ - -package io.helidon.examples.pico.car.pico; - -import io.helidon.pico.api.Contract; - -@Contract -public interface Vehicle { - Engine engine(); - Brand brand(); -} diff --git a/examples/pico/car/pico/src/test/java/io/helidon/examples/pico/car/pico/PicoTest.java b/examples/pico/car/pico/src/test/java/io/helidon/examples/pico/car/pico/PicoTest.java deleted file mode 100644 index 7b8a7eb8e11..00000000000 --- a/examples/pico/car/pico/src/test/java/io/helidon/examples/pico/car/pico/PicoTest.java +++ /dev/null @@ -1,36 +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. - */ - -package io.helidon.examples.pico.car.pico; - -import org.junit.jupiter.api.Test; - -public class PicoTest { - - @Test - public void testMain() { - final long memStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long start = System.currentTimeMillis(); - - Main.main(new String[] {"Pico"}); - - final long finish = System.currentTimeMillis(); - final long memFinish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - System.out.println("Pico JUnit memory consumption = " + (memFinish - memStart) + " bytes"); - System.out.println("Pico JUnit elapsed time = " + (finish - start) + " ms"); - } - -} diff --git a/examples/pico/car/pom.xml b/examples/pico/car/pom.xml deleted file mode 100644 index 341bbee242e..00000000000 --- a/examples/pico/car/pom.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - io.helidon.examples.pico - helidon-examples-pico-project - 4.0.0-SNAPSHOT - ../pom.xml - - 4.0.0 - - io.helidon.examples.pico.car - helidon-examples-pico-car-project - Helidon Pico Examples - Car - - pom - - - 2.43 - - - - dagger2 - pico - - - diff --git a/examples/pico/car/run.sh b/examples/pico/car/run.sh deleted file mode 100755 index 88e71e39cf7..00000000000 --- a/examples/pico/car/run.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -e -# -# 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. -# - -# mvn clean install -clear -echo "RUN 1: (DAGGER2)" -java -jar dagger2/target/helidon-examples-pico-car-dagger2-4.0.0-SNAPSHOT-jar-with-dependencies.jar dagger2 -echo "RUN 2: (DAGGER2)" -java -jar dagger2/target/helidon-examples-pico-car-dagger2-4.0.0-SNAPSHOT-jar-with-dependencies.jar dagger2 -echo "========================" -echo "RUN 1: (PICO)" -java -jar pico/target/helidon-examples-pico-car-pico-4.0.0-SNAPSHOT-jar-with-dependencies.jar pico -echo "RUN 2: (PICO)" -java -jar pico/target/helidon-examples-pico-car-pico-4.0.0-SNAPSHOT-jar-with-dependencies.jar pico diff --git a/examples/pico/logger/README.md b/examples/pico/logger/README.md deleted file mode 100644 index 1bb2a4e7ab4..00000000000 --- a/examples/pico/logger/README.md +++ /dev/null @@ -1,100 +0,0 @@ -# pico-examples-logger - -## Overview -This example compares Pico to Guice. It was taken from an example found on the internet (see references below). The example is fairly trivial, but it is sufficient to compare the similarities between the two, as well as to demonstrate the performance differences between the two. - -[common](common) contains the core application logic. -[guice](guice) contains the delta for integrating to Guice. -[pico](pico) contains the delta for integrating with Pico. - -Review the code to see the similarities and differences. Note that the generated source code is found under -"./target/generated-sources". Summaries of similarities and differences are listed below. - -# Building and Running -``` -> mvn clean install -> ./run.sh -``` - -The [run.sh](./run.sh) script as shown above will spawn the Guice and Pico built applications twice (1st iteration for warmup). - -:DISCLAIMER: **Results may vary** The below measurements were captured at the time of this revision (see git log) - - -# Notable - -1. Pico supports jakarta.inject as well as javax.inject packaging. Guice (at the time of this writing) only supports javax.inject. This example therefore uses javax.inject in order to compare the two models even though it is recommended all switch to jakarta.inject if possible. - -2. Guice is based upon reflection and at runtime uses it to determine the injection points and dependency graph. Pico is based upon compile-time code generation to generate (in code) the dependency graph. Both, however, support lazy/dynamic activation of services. - -3. Pico provides the ability (as demonstrated in the [pom.xml](./pico/pom.xml)) to bind to the final injection model at assembly time. This option provides several benefits including deterministic behavior, speed & performance, and to helps ensure the completeness & validity of the entire application's dependency graph. Guice does not offer such an option. - -4. Guice is considerable larger in terms of its memory consumption footprint. - -```run.sh -... -Guice Main memory consumption = 13,194,048 bytes -... -Pico Main memory consumption = 7,930,352 bytes -... -``` - -5. Both applications are packaged with all of its transitive compile-time dependencies to showcase the differences in disk size. Pico is considerably smaller in terms of its disk consumption footprint: -``` -> find . | grep dependencies | grep jar | xargs ls -l --rw-r--r-- 1 jtrent staff 3975690 Feb 21 20:43 ./guice/target/helidon-examples-pico-logger-guice-4.0.0-SNAPSHOT-jar-with-dependencies.jar --rw-r--r-- 1 jtrent staff 403936 Feb 21 20:43 ./pico/target/helidon-examples-pico-logger-pico-4.0.0-SNAPSHOT-jar-with-dependencies.jar -``` - -6. Pico is considerably faster in terms of its end-to-end runtime. Mileage will vary. - -```run.sh -... -Guice Main elapsed time = 293 ms -... -Pico Main elapsed time = 184 ms -... -``` - -7. Pico requires less coding as compared to Guice. - -``` -jtrent@jtrent-mac logger % find guice -type f -not -path '*/.*' | grep -v target | wc - 4 4 230 -jtrent@jtrent-mac logger % find pico -type f -not -path '*/.*' | grep -v target | wc - 3 3 149 -``` - -8. Pico offers lifecycle support (see jakarta.annotation.@PostConstruct, jakarta.annotation.@PreDestroy, Pico's @RunLevel - annotations and PicoServices#shutdown()). - -9. Pico generates a suggested module-info.java based upon analysis of your injection/dependency model (see /target/classes/module-info.java.pico). - -```./target/classes/module-info.java.pico -// @Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") -module helidon.examples.pico.logger.common { - exports io.helidon.examples.pico.logger.common; - // pico module - Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") - provides io.helidon.pico.Module with io.helidon.examples.pico.logger.common.Pico$$Module; - // pico external contract usage - Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") - requires helidon.examples.pico.logger.common; - uses io.helidon.examples.pico.logger.common.CommunicationMode; - uses io.helidon.examples.pico.logger.common.Communicator; - uses jakarta.inject.Provider; - uses javax.inject.Provider; - // pico services - Generated(value = "io.helidon.pico.tools.ActivatorCreatorDefault", comments = "version=1") - requires transitive io.helidon.pico.services; -} -``` - -10. Pico can optionally generate the activators (i.e., the DI supporting classes) on an external jar module by using a maven plugin. Notice how [common](./common) is built, and then in the [pico/pom.xml](pico/pom.xml) the maven plugin uses application-create to create the supporting DI around it. That explains why there are no classes other than Main in the pico sub-module. Guice does not offer such an option, and instead requires the developer to write the modules declaring the DI module programmatically. - - -Additionally, and more philosophical in nature, Pico strives to closely adhere to standard JSR-330 constructs as compared to Guice. -To be productive only requires the use of these packages: -* [jakarta.inject](https://javadoc.io/doc/jakarta.inject/jakarta.inject-api/latest/index.html) -* Optionally, [jakarta.annotation](https://javadoc.io/doc/jakarta.annotation/jakarta.annotation-api/latest/jakarta.annotation/jakarta/annotation/package-summary.html) -* Optionally, a few [pico API](../../pico/src/main/java/io/helidon/pico) / annotations. - -# References -* https://www.baeldung.com/guice diff --git a/examples/pico/logger/common/pom.xml b/examples/pico/logger/common/pom.xml deleted file mode 100644 index 39ece1490ac..00000000000 --- a/examples/pico/logger/common/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - io.helidon.examples.pico.logger - helidon-examples-pico-logger-project - 4.0.0-SNAPSHOT - ../pom.xml - - 4.0.0 - - helidon-examples-pico-logger-common - Helidon Pico Examples - Logger - Common - - - - jakarta.inject - jakarta.inject-api - - - - javax.inject - javax.inject - ${javax.injection.version} - - - - javax.annotation - javax.annotation-api - ${javax.annotations.version} - provided - - - diff --git a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/AnotherCommunicationMode.java b/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/AnotherCommunicationMode.java deleted file mode 100644 index 24c87bd581f..00000000000 --- a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/AnotherCommunicationMode.java +++ /dev/null @@ -1,34 +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. - */ - -package io.helidon.examples.pico.logger.common; - -import java.util.logging.Level; -import java.util.logging.Logger; - -@javax.inject.Singleton -public class AnotherCommunicationMode implements CommunicationMode { - - @javax.inject.Inject - Logger logger; - - @Override - public int sendMessage(String message) { - logger.log(Level.INFO, "Sending message '" + message + "' over another (default) communication mode"); - return 1; - } - -} diff --git a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/Communication.java b/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/Communication.java deleted file mode 100644 index f8055090945..00000000000 --- a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/Communication.java +++ /dev/null @@ -1,53 +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. - */ - -package io.helidon.examples.pico.logger.common; - -import java.util.Objects; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class Communication { - - Logger logger; - public Communicator communicator; - - volatile boolean didPostConstruct; - - @javax.inject.Inject - public Communication(Logger logger, Communicator communicator) { - this.logger = logger; - this.communicator = Objects.requireNonNull(communicator); - } - - @javax.annotation.PostConstruct - public void postConstruct() { - logger.log(Level.INFO, "logging is enabled for communication"); - } - - public int sendMessageViaAllModes(String message) { - if (!didPostConstruct) { - logger.log(Level.INFO, "explicitly calling postConstruct"); - postConstruct(); - } - - return communicator.sendMessage(message, "email") - + communicator.sendMessage(message, "sms") - + communicator.sendMessage(message, "im") - + communicator.sendMessage(message, "another"); - } - -} diff --git a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/CommunicationMode.java b/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/CommunicationMode.java deleted file mode 100644 index 50965233e87..00000000000 --- a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/CommunicationMode.java +++ /dev/null @@ -1,23 +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. - */ - -package io.helidon.examples.pico.logger.common; - -public interface CommunicationMode { - - int sendMessage(String message); - -} diff --git a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/Communicator.java b/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/Communicator.java deleted file mode 100644 index 293183a8452..00000000000 --- a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/Communicator.java +++ /dev/null @@ -1,23 +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. - */ - -package io.helidon.examples.pico.logger.common; - -public interface Communicator { - - int sendMessage(String message, String preferredMode); - -} diff --git a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/DefaultCommunicator.java b/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/DefaultCommunicator.java deleted file mode 100644 index ab5e5bd910c..00000000000 --- a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/DefaultCommunicator.java +++ /dev/null @@ -1,53 +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. - */ - -package io.helidon.examples.pico.logger.common; - -public class DefaultCommunicator implements Communicator { - - @javax.inject.Inject - @javax.inject.Named("sms") - public CommunicationMode sms; - - @javax.inject.Inject - @javax.inject.Named("email") - public CommunicationMode email; - - @javax.inject.Inject - @javax.inject.Named("im") - public CommunicationMode im; - - public CommunicationMode defaultCommunication; - - @javax.inject.Inject - public DefaultCommunicator(CommunicationMode defaultCommunication) { - this.defaultCommunication = defaultCommunication; - } - - @Override - public int sendMessage(String message, String preferredMode) { - if ("sms".equals(preferredMode)) { - return sms.sendMessage(message); - } else if ("email".equals(preferredMode)) { - return email.sendMessage(message); - } else if ("im".equals(preferredMode)) { - return im.sendMessage(message); - } else { - return defaultCommunication.sendMessage(message); - } - } - -} diff --git a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/EmailCommunicationMode.java b/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/EmailCommunicationMode.java deleted file mode 100644 index 737fd47b8e9..00000000000 --- a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/EmailCommunicationMode.java +++ /dev/null @@ -1,35 +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. - */ - -package io.helidon.examples.pico.logger.common; - -import java.util.logging.Level; -import java.util.logging.Logger; - -@javax.inject.Singleton -@javax.inject.Named("email") -public class EmailCommunicationMode implements CommunicationMode { - - @javax.inject.Inject - Logger logger; - - @Override - public int sendMessage(String message) { - logger.log(Level.INFO, "Sending message '" + message + "' over email"); - return 1; - } - -} diff --git a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/ImCommunicationMode.java b/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/ImCommunicationMode.java deleted file mode 100644 index 47173b74d19..00000000000 --- a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/ImCommunicationMode.java +++ /dev/null @@ -1,36 +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. - */ - -package io.helidon.examples.pico.logger.common; - -import java.util.logging.Level; -import java.util.logging.Logger; - -@javax.inject.Singleton -@javax.inject.Named("im") -public class ImCommunicationMode implements CommunicationMode { - - @javax.inject.Inject - @jakarta.inject.Inject - Logger logger; - - @Override - public int sendMessage(String message) { - logger.log(Level.INFO, "Sending message '" + message + "' over IM"); - return 1; - } - -} diff --git a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/LoggerProvider.java b/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/LoggerProvider.java deleted file mode 100644 index 5ade91b7ec7..00000000000 --- a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/LoggerProvider.java +++ /dev/null @@ -1,29 +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. - */ - -package io.helidon.examples.pico.logger.common; - -import java.util.logging.Logger; - -@javax.inject.Singleton -public class LoggerProvider implements javax.inject.Provider, jakarta.inject.Provider { - - @Override - public Logger get() { - return Logger.getAnonymousLogger(); - } - -} diff --git a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/SmsCommunicationMode.java b/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/SmsCommunicationMode.java deleted file mode 100644 index baac623eca7..00000000000 --- a/examples/pico/logger/common/src/main/java/io/helidon/examples/pico/logger/common/SmsCommunicationMode.java +++ /dev/null @@ -1,35 +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. - */ - -package io.helidon.examples.pico.logger.common; - -import java.util.logging.Level; -import java.util.logging.Logger; - -@javax.inject.Singleton -@javax.inject.Named("sms") -public class SmsCommunicationMode implements CommunicationMode { - - @javax.inject.Inject - Logger logger; - - @Override - public int sendMessage(String message) { - logger.log(Level.INFO, "Sending message '" + message + "' over SMS"); - return 1; - } - -} diff --git a/examples/pico/logger/guice/pom.xml b/examples/pico/logger/guice/pom.xml deleted file mode 100644 index bff0ffc9d33..00000000000 --- a/examples/pico/logger/guice/pom.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - io.helidon.examples.pico.logger - helidon-examples-pico-logger-project - 4.0.0-SNAPSHOT - ../pom.xml - - 4.0.0 - - helidon-examples-pico-logger-guice - Helidon Pico Examples - Logger - Guice - - - io.helidon.examples.pico.logger.guice.Main - - - - - io.helidon.examples.pico.logger - helidon-examples-pico-logger-common - ${helidon.version} - - - com.google.inject - guice - ${version.lib.guice} - - - org.junit.jupiter - junit-jupiter-api - test - - - - - - - maven-assembly-plugin - - - jar-with-dependencies - - - - ${mainClass} - - - - - - make-assembly - package - - single - - - - - - org.apache.maven.plugins - maven-jar-plugin - ${version.plugin.jar} - - - - true - libs - ${mainClass} - false - - - - - - org.codehaus.mojo - exec-maven-plugin - ${version.plugin.exec} - - ${mainClass} - - - - - - diff --git a/examples/pico/logger/guice/src/main/java/io/helidon/examples/pico/logger/guice/BasicModule.java b/examples/pico/logger/guice/src/main/java/io/helidon/examples/pico/logger/guice/BasicModule.java deleted file mode 100644 index df0735ae792..00000000000 --- a/examples/pico/logger/guice/src/main/java/io/helidon/examples/pico/logger/guice/BasicModule.java +++ /dev/null @@ -1,50 +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. - */ - -package io.helidon.examples.pico.logger.guice; - -import io.helidon.examples.pico.logger.common.AnotherCommunicationMode; -import io.helidon.examples.pico.logger.common.Communication; -import io.helidon.examples.pico.logger.common.CommunicationMode; -import io.helidon.examples.pico.logger.common.Communicator; -import io.helidon.examples.pico.logger.common.DefaultCommunicator; -import io.helidon.examples.pico.logger.common.EmailCommunicationMode; -import io.helidon.examples.pico.logger.common.ImCommunicationMode; -import io.helidon.examples.pico.logger.common.SmsCommunicationMode; - -import com.google.inject.AbstractModule; -import com.google.inject.name.Names; - -public class BasicModule extends AbstractModule { - - @Override - protected void configure() { - try { - bind(Communicator.class).toConstructor(DefaultCommunicator.class.getConstructor(CommunicationMode.class)); - bind(Boolean.class).toInstance(true); - } catch (Exception e) { - throw new RuntimeException(e.getMessage(), e); - } - bind(CommunicationMode.class).to(AnotherCommunicationMode.class); - bind(CommunicationMode.class).annotatedWith(Names.named("default")).to(AnotherCommunicationMode.class); - bind(CommunicationMode.class).annotatedWith(Names.named("im")).to(ImCommunicationMode.class); - bind(CommunicationMode.class).annotatedWith(Names.named("im")).to(ImCommunicationMode.class); - bind(CommunicationMode.class).annotatedWith(Names.named("email")).to(EmailCommunicationMode.class); - bind(CommunicationMode.class).annotatedWith(Names.named("sms")).to(SmsCommunicationMode.class); - bind(Communication.class).asEagerSingleton(); - } - -} diff --git a/examples/pico/logger/guice/src/main/java/io/helidon/examples/pico/logger/guice/Main.java b/examples/pico/logger/guice/src/main/java/io/helidon/examples/pico/logger/guice/Main.java deleted file mode 100644 index c98f25c49ae..00000000000 --- a/examples/pico/logger/guice/src/main/java/io/helidon/examples/pico/logger/guice/Main.java +++ /dev/null @@ -1,59 +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. - */ - -package io.helidon.examples.pico.logger.guice; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import io.helidon.examples.pico.logger.common.Communication; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -public class Main { - - static Injector injector; - static Communication comms; - - public static void main(String[] args){ - final long memStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long start = System.currentTimeMillis(); - - injector = Guice.createInjector(new BasicModule()); - comms = injector.getInstance(Communication.class); - - List messages = Arrays.asList(args); - if (messages.isEmpty()) { - messages = Collections.singletonList("Hello World!"); - } - - AtomicInteger sent = new AtomicInteger(); - messages.forEach((message) -> { - sent.addAndGet(comms.sendMessageViaAllModes(message)); - }); - int count = sent.get(); - System.out.println("finished sending: " + count); - - final long finish = System.currentTimeMillis(); - final long memFinish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - System.out.println("Guice Main memory consumption = " + (memFinish - memStart) + " bytes"); - System.out.println("Guice Main elapsed time = " + (finish - start) + " ms"); - } - -} diff --git a/examples/pico/logger/guice/src/test/java/io/helidon/examples/pico/logger/guice/GuiceTest.java b/examples/pico/logger/guice/src/test/java/io/helidon/examples/pico/logger/guice/GuiceTest.java deleted file mode 100644 index 3b608012118..00000000000 --- a/examples/pico/logger/guice/src/test/java/io/helidon/examples/pico/logger/guice/GuiceTest.java +++ /dev/null @@ -1,49 +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. - */ - -package io.helidon.examples.pico.logger.guice; - -import io.helidon.examples.pico.logger.common.AnotherCommunicationMode; -import io.helidon.examples.pico.logger.common.DefaultCommunicator; -import io.helidon.examples.pico.logger.common.EmailCommunicationMode; -import io.helidon.examples.pico.logger.common.ImCommunicationMode; -import io.helidon.examples.pico.logger.common.SmsCommunicationMode; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class GuiceTest { - - @Test - public void testMain() { - final long memStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long start = System.currentTimeMillis(); - - Main.main(new String[] {"Hello World!"}); - - final long finish = System.currentTimeMillis(); - final long memFinish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - DefaultCommunicator comms = ((DefaultCommunicator) Main.comms.communicator); - assertEquals(SmsCommunicationMode.class, comms.sms.getClass()); - assertEquals(EmailCommunicationMode.class, comms.email.getClass()); - assertEquals(ImCommunicationMode.class, comms.im.getClass()); - assertEquals(AnotherCommunicationMode.class, comms.defaultCommunication.getClass()); - System.out.println("Guice JUnit memory consumption = " + (memFinish - memStart) + " bytes"); - System.out.println("Guice JUnit elapsed time = " + (finish - start) + " ms"); - } - -} diff --git a/examples/pico/logger/pico/pom.xml b/examples/pico/logger/pico/pom.xml deleted file mode 100644 index 711408be0b1..00000000000 --- a/examples/pico/logger/pico/pom.xml +++ /dev/null @@ -1,140 +0,0 @@ - - - - - - io.helidon.examples.pico.logger - helidon-examples-pico-logger-project - 4.0.0-SNAPSHOT - ../pom.xml - - 4.0.0 - - helidon-examples-pico-logger-pico - Helidon Pico Examples - Logger - Pico - - - io.helidon.examples.pico.logger.pico.Main - - - - - io.helidon.examples.pico.logger - helidon-examples-pico-logger-common - ${helidon.version} - - - io.helidon.pico - helidon-pico-runtime - - - io.helidon.builder - helidon-builder - - - jakarta.annotation - jakarta.annotation-api - provided - - - org.junit.jupiter - junit-jupiter-api - test - - - - - - - maven-assembly-plugin - - - jar-with-dependencies - - - - ${mainClass} - - - - - - make-assembly - package - - single - - - - - - io.helidon.pico - helidon-pico-maven-plugin - ${helidon.version} - - - - external-module-create - - - - compile - compile - - application-create - - - - - - io.helidon.examples.pico.logger.common - - helidon.examples.pico.logger.common - ALL - - - - org.apache.maven.plugins - maven-jar-plugin - ${version.plugin.jar} - - - - true - libs - ${mainClass} - false - - - - - - org.codehaus.mojo - exec-maven-plugin - ${version.plugin.exec} - - ${mainClass} - - - - - - diff --git a/examples/pico/logger/pico/src/main/java/io/helidon/examples/pico/logger/pico/Main.java b/examples/pico/logger/pico/src/main/java/io/helidon/examples/pico/logger/pico/Main.java deleted file mode 100644 index 3d4c73dfc04..00000000000 --- a/examples/pico/logger/pico/src/main/java/io/helidon/examples/pico/logger/pico/Main.java +++ /dev/null @@ -1,58 +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. - */ - -package io.helidon.examples.pico.logger.pico; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import io.helidon.examples.pico.logger.common.Communication; -import io.helidon.pico.api.PicoServices; -import io.helidon.pico.api.Services; - -public class Main { - - static Services services; - static Communication comms; - - public static void main(String[] args){ - final long memStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long start = System.currentTimeMillis(); - - PicoServices picoServices = PicoServices.picoServices().get(); - services = picoServices.services(); - comms = services.lookupFirst(Communication.class).get(); - - List messages = Arrays.asList(args); - if (messages.isEmpty()) { - messages = Collections.singletonList("Hello World!"); - } - - AtomicInteger sent = new AtomicInteger(); - messages.forEach((message) -> { - sent.addAndGet(comms.sendMessageViaAllModes(message)); - }); - int count = sent.get(); - System.out.println("finished sending: " + count); - - final long finish = System.currentTimeMillis(); - final long memFinish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - System.out.println("Pico Main memory consumption = " + (memFinish - memStart) + " bytes"); - System.out.println("Pico Main elapsed time = " + (finish - start) + " ms"); - } -} diff --git a/examples/pico/logger/pico/src/test/java/io/helidon/examples/pico/logger/pico/PicoTest.java b/examples/pico/logger/pico/src/test/java/io/helidon/examples/pico/logger/pico/PicoTest.java deleted file mode 100644 index 1017c8918ec..00000000000 --- a/examples/pico/logger/pico/src/test/java/io/helidon/examples/pico/logger/pico/PicoTest.java +++ /dev/null @@ -1,49 +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. - */ - -package io.helidon.examples.pico.logger.pico; - -import io.helidon.examples.pico.logger.common.AnotherCommunicationMode; -import io.helidon.examples.pico.logger.common.DefaultCommunicator; -import io.helidon.examples.pico.logger.common.EmailCommunicationMode; -import io.helidon.examples.pico.logger.common.ImCommunicationMode; -import io.helidon.examples.pico.logger.common.SmsCommunicationMode; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class PicoTest { - - @Test - public void testMain() { - final long memStart = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long start = System.currentTimeMillis(); - - Main.main(new String[] {"Hello World!"}); - - final long finish = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); - final long memFinish = Runtime.getRuntime().totalMemory(); - DefaultCommunicator comms = ((DefaultCommunicator) Main.comms.communicator); - assertEquals(SmsCommunicationMode.class, comms.sms.getClass()); - assertEquals(EmailCommunicationMode.class, comms.email.getClass()); - assertEquals(ImCommunicationMode.class, comms.im.getClass()); - assertEquals(AnotherCommunicationMode.class, comms.defaultCommunication.getClass()); - System.out.println("Pico Junit memory consumption = " + (memFinish - memStart) + " bytes"); - System.out.println("Pico Junit elapsed time = " + (finish - start) + " ms"); - } - -} diff --git a/examples/pico/logger/pom.xml b/examples/pico/logger/pom.xml deleted file mode 100644 index b267b47442b..00000000000 --- a/examples/pico/logger/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - io.helidon.examples.pico - helidon-examples-pico-project - 4.0.0-SNAPSHOT - ../pom.xml - - 4.0.0 - - io.helidon.examples.pico.logger - helidon-examples-pico-logger-project - Helidon Pico Examples - Logger - - pom - - - 5.1.0 - - - 1 - 1.3.2 - - - - common - guice - pico - - - diff --git a/examples/pico/logger/run.sh b/examples/pico/logger/run.sh deleted file mode 100755 index 6ca82cffa03..00000000000 --- a/examples/pico/logger/run.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -e -# -# 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. -# - -# mvn clean install -clear -echo "RUN 1: (GUICE)" -java -jar guice/target/helidon-examples-pico-logger-guice-4.0.0-SNAPSHOT-jar-with-dependencies.jar "hello guice" -echo "RUN 2: (GUICE)" -java -jar guice/target/helidon-examples-pico-logger-guice-4.0.0-SNAPSHOT-jar-with-dependencies.jar "hello guice" -echo "========================" -echo "RUN 1: (PICO)" -java -jar pico/target/helidon-examples-pico-logger-pico-4.0.0-SNAPSHOT-jar-with-dependencies.jar "hello pico" -echo "RUN 2: (PICO)" -java -jar pico/target/helidon-examples-pico-logger-pico-4.0.0-SNAPSHOT-jar-with-dependencies.jar "hello pico" diff --git a/examples/pico/pom.xml b/examples/pico/pom.xml deleted file mode 100644 index 24d45fdb709..00000000000 --- a/examples/pico/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - io.helidon.examples - helidon-examples-project - 4.0.0-SNAPSHOT - ../pom.xml - - - io.helidon.examples.pico - helidon-examples-pico-project - Helidon Examples Pico Project - pom - 4.0.0 - - - book - car - logger - - - diff --git a/examples/pom.xml b/examples/pom.xml index f14135d77aa..532c70d3e3d 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -63,7 +63,6 @@ metrics jbatch nima - pico