Skip to content

Commit 66f14d7

Browse files
authored
Pico extensibility support for the OCI SDK (helidon-io#6982)
1 parent cbc9e6e commit 66f14d7

56 files changed

Lines changed: 3652 additions & 19 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bom/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,18 @@
14871487
<version>${helidon.version}</version>
14881488
</dependency>
14891489

1490+
<!-- Pico Integrations related -->
1491+
<dependency>
1492+
<groupId>io.helidon.integrations.oci.sdk</groupId>
1493+
<artifactId>helidon-integrations-oci-sdk-processor</artifactId>
1494+
<version>${helidon.version}</version>
1495+
</dependency>
1496+
<dependency>
1497+
<groupId>io.helidon.integrations.oci.sdk</groupId>
1498+
<artifactId>helidon-integrations-oci-sdk-runtime</artifactId>
1499+
<version>${helidon.version}</version>
1500+
</dependency>
1501+
14901502
</dependencies>
14911503
</dependencyManagement>
14921504
</project>

etc/checkstyle-suppressions.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@
104104
checks=".*"/>
105105
<suppress files="examples/pico/"
106106
checks=".*"/>
107+
<suppress files="integrations/oci/sdk/tests/"
108+
checks=".*"/>
107109

108110
<!-- Java comments, import order and style of the files should be generated by OpenApi Tools. -->
109111
<suppress checks="ConstantName"

integrations/oci/sdk/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# helidon-integrations-oci-sdk
2+
3+
There are two different approaches for [OCI SDK](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/javasdk.htm) integration from Helidon depending upon which type of application you are developing.
4+
* **Helidon MP** (using _CDI_). For this refer to the [cdi](./cdi) module.
5+
* **Helidon SE** (not using _CDI_). For this refer to the information below.
6+
7+
8+
## Helidon Injection Framework and OCI SDK Integration
9+
This section only applies for **Helidon SE** type applications. If you are using **Helidon MP** then this section does not apply to you, and you should instead refer to the [cdi](./cdi) module.
10+
11+
The **Helidon Injection Framework** offers a few different ways to integrate to 3rd party libraries. The **OCI SDK** library, however, is a little different in that a special type/style of fluent builder is needed when using the **OCI SDK**. This means that you can't simply use the _new_ operator when creating instances; you instead need to use the imperative fluent builder style. Fortunately, though, most of the **OCI SDK** follows the same pattern for accessing the API via this fluent builder style. Since the **Helidon Injection Framework** leverages compile-time DI code generation, this arrangement makes it very convenient to generate the correct underpinnings that leverages a template following this fluent builder style.
12+
13+
The net of all of this is that there are two modules that you will need to integrate DI into your **Helidon SE** application.
14+
15+
1. The [processor](./processor) module is required to be on your compiler / APT classpath. It will observe cases where you are _@Inject_ services from the **OCI SDK** and then code-generate the appropriate [Activator](../api/src/main/java/io/helidon/pico/api/Activator.java)s for those injected services. Remember, the _processor_ module only needs APT classpath during compilation - it is not needed at runtime.
16+
17+
2. The [runtime](./runtime) module is required to be on your runtime classpath. This module supplies the default implementation for OCI authentication providers, and OCI extensibility into Helidon.
18+
19+
20+
### MP Modules
21+
* [cdi](./cdi) - required to be added as a normal dependency in your final application.
22+
23+
24+
### Non-MP Modules
25+
* [processor](./processor) - required to be in the APT classpath.
26+
* [runtime](./runtime) - required to be added as a normal dependency in your final application.
27+
* [tests](./tests) - tests for OCI SDK integration.
28+
29+
30+
### Usage
31+
32+
In your pom.xml, add this plugin to be run as part of the compilation phase:
33+
```pom.xml
34+
<plugin>
35+
<groupId>org.apache.maven.plugins</groupId>
36+
<artifactId>maven-compiler-plugin</artifactId>
37+
<configuration>
38+
<forceJavacCompilerUse>true</forceJavacCompilerUse>
39+
<annotationProcessorPaths>
40+
<path>
41+
<groupId>io.helidon.integrations.oci.sdk</groupId>
42+
<artifactId>helidon-integrations-oci-sdk-processor</artifactId>
43+
<version>${helidon.version}</version>
44+
</path>
45+
</annotationProcessorPaths>
46+
</configuration>
47+
</plugin>
48+
```
49+
50+
Add the runtime dependency to your pom.xml, along with any other OCI SDK library that is required by your application:
51+
```pom.xml
52+
<dependency>
53+
<groupId>io.helidon.integrations.oci.sdk</groupId>
54+
<artifactId>helidon-integrations-oci-sdk-runtime</artifactId>
55+
</dependency>
56+
57+
...
58+
<!-- arbitrarily selected OCI libraries - use the libraries appropriate for your application -->
59+
<dependency>
60+
<groupId>com.oracle.oci.sdk</groupId>
61+
<artifactId>oci-java-sdk-ailanguage</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>com.oracle.oci.sdk</groupId>
65+
<artifactId>oci-java-sdk-objectstorage</artifactId>
66+
</dependency>
67+
```
68+
69+
Note that if you are using JPMS (i.e., _module-info.java_), then you will also need to be sure to export the _io.helidon.integrations.generated_ derivative package names from your module(s).
70+
71+
### How it works
72+
See the [InjectionProcessorObserverForOci javadoc](processor/src/main/java/io/helidon/integrations/oci/sdk/processor/InjectionProcessorObserverForOCI.java) for a description. In summary, this processor will observe **OCI SDK** injection points and then code generate **Activators** enabling injection of SDK services in conjuction with the [runtime](./runtime) module on the classpath.

integrations/oci/sdk/cdi/src/main/java/io/helidon/integrations/oci/sdk/cdi/AdpSelectionStrategy.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717

1818
import java.io.FileNotFoundException;
1919
import java.io.IOException;
20-
import java.io.InputStream;
2120
import java.io.UncheckedIOException;
2221
import java.lang.annotation.Annotation;
2322
import java.net.ConnectException;
@@ -134,10 +133,10 @@ SimpleAuthenticationDetailsProviderBuilder produceBuilder(Selector selector, Con
134133
c.get(OCI_AUTH_PASSPHRASE, String.class).or(() -> c.get(OCI_AUTH_PASSPHRASE + "Characters", String.class))
135134
.ifPresent(b::passPhrase);
136135
c.get(OCI_AUTH_PRIVATE_KEY, String.class).or(() -> c.get("oci.auth.privateKey", String.class))
137-
.ifPresentOrElse(pk -> b.privateKeySupplier((Supplier<InputStream>) new StringPrivateKeySupplier(pk)),
138-
() -> b.privateKeySupplier((Supplier<InputStream>) new SimplePrivateKeySupplier(c.get(OCI_AUTH_PRIVATE_KEY + "-path", String.class)
139-
.orElse(c.get("oci.auth.keyFile", String.class)
140-
.orElse(Paths.get(System.getProperty("user.home"), ".oci", "oci_api_key.pem").toString())))));
136+
.ifPresentOrElse(pk -> b.privateKeySupplier(new StringPrivateKeySupplier(pk)),
137+
() -> b.privateKeySupplier(new SimplePrivateKeySupplier(c.get(OCI_AUTH_PRIVATE_KEY + "-path", String.class)
138+
.orElse(c.get("oci.auth.keyFile", String.class)
139+
.orElse(Paths.get(System.getProperty("user.home"), ".oci", "oci_api_key.pem").toString())))));
141140
c.get(OCI_AUTH_REGION, Region.class)
142141
.ifPresent(b::region);
143142
c.get(OCI_AUTH_TENANT_ID, String.class).or(() -> c.get("oci.auth.tenancy", String.class))

integrations/oci/sdk/cdi/src/main/java/io/helidon/integrations/oci/sdk/cdi/OciExtension.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@
7070
* <em>asynchronous service client</em>, or <em>asynchronous service
7171
* client builder</em> from the <a
7272
* href="https://docs.oracle.com/en-us/iaas/tools/java/latest/index.html"
73-
* target="_top">Oracle Cloud Infrastructure Java SDK</a>.
73+
* target="_top">Oracle Cloud Infrastructure Java SDK</a>. It is intended for
74+
* <em>Helidon MP</em>, CDI usage scenarios. For usages other than for
75+
* <em>Helidon MP</em> please refer to
76+
* {@code io.helidon.integrations.oci.sdk.runtime.OciExtension} instead.
7477
*
7578
* <h2>Terminology</h2>
7679
*

integrations/oci/sdk/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333

3434
<modules>
3535
<module>cdi</module>
36+
<module>processor</module>
37+
<module>runtime</module>
38+
<module>tests</module>
3639
</modules>
3740

3841
</project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# helidon-integrations-oci-sdk-processor
2+
3+
Refer to the [helidon-integrations-oci-sdk](../) documentation.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2018, 2023 Oracle and/or its affiliates.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
20+
<project xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<parent>
24+
<groupId>io.helidon.integrations.oci.sdk</groupId>
25+
<artifactId>helidon-integrations-oci-sdk-project</artifactId>
26+
<version>4.0.0-SNAPSHOT</version>
27+
<relativePath>../pom.xml</relativePath>
28+
</parent>
29+
<modelVersion>4.0.0</modelVersion>
30+
31+
<artifactId>helidon-integrations-oci-sdk-processor</artifactId>
32+
<name>Helidon Integrations OCI Injection Processor</name>
33+
34+
<description>Helidon Injection Framework APT support for the OCI SDK</description>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>io.helidon.pico</groupId>
39+
<artifactId>helidon-pico-processor</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>com.github.jknack</groupId>
43+
<artifactId>handlebars</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>io.helidon.common.testing</groupId>
47+
<artifactId>helidon-common-testing-junit5</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.hamcrest</groupId>
52+
<artifactId>hamcrest-all</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.junit.jupiter</groupId>
57+
<artifactId>junit-jupiter-api</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
<dependency>
61+
<groupId>com.oracle.oci.sdk</groupId>
62+
<artifactId>oci-java-sdk-common</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
66+
<!-- Arbitrarily-selected OCI libraries used for testing universal applicability. -->
67+
<dependency>
68+
<groupId>com.oracle.oci.sdk</groupId>
69+
<artifactId>oci-java-sdk-ailanguage</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
<dependency>
73+
<groupId>com.oracle.oci.sdk</groupId>
74+
<artifactId>oci-java-sdk-objectstorage</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
78+
<!-- Streaming OCI library because it is the only OCI service that doesn't quite match the other OCI services' design patterns. -->
79+
<dependency>
80+
<groupId>com.oracle.oci.sdk</groupId>
81+
<artifactId>oci-java-sdk-streaming</artifactId>
82+
<scope>test</scope>
83+
</dependency>
84+
</dependencies>
85+
86+
</project>

0 commit comments

Comments
 (0)