Skip to content

Commit

Permalink
4.x: Support for OKE Workload identity in OCI integration for Service…
Browse files Browse the repository at this point in the history
… registry (helidon-io#8862)

* Mark service registry as a preview feature
* Make sure suppliers return a new instance each time they are called
* Support for builders of authentication detail providers.
* Documentation update.
* Test some javadoc tags are correctly handled
* Builder: Factory methods should only be generated if returning prototype or builder
* Use Authentication instead of Atn
* Remove usages of "Strategy" and replace with "Method"
  • Loading branch information
tomas-langer authored Jun 25, 2024
1 parent dc01487 commit aa3ab17
Showing 82 changed files with 2,563 additions and 476 deletions.
12 changes: 12 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
@@ -641,6 +641,18 @@
<groupId>io.helidon.integrations.oci</groupId>
<artifactId>helidon-integrations-oci</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.integrations.oci.authentication</groupId>
<artifactId>helidon-integrations-oci-authentication-instance</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.integrations.oci.authentication</groupId>
<artifactId>helidon-integrations-oci-authentication-resource</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.integrations.oci.authentication</groupId>
<artifactId>helidon-integrations-oci-authentication-oke-workload</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.integrations.oci.sdk</groupId>
<artifactId>helidon-integrations-oci-sdk-cdi</artifactId>
15 changes: 15 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
@@ -858,6 +858,21 @@
<artifactId>helidon-integrations-oci</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.integrations.oci.authentication</groupId>
<artifactId>helidon-integrations-oci-authentication-instance</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.integrations.oci.authentication</groupId>
<artifactId>helidon-integrations-oci-authentication-resource</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.integrations.oci.authentication</groupId>
<artifactId>helidon-integrations-oci-authentication-oke-workload</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.integrations.oci.sdk</groupId>
<artifactId>helidon-integrations-oci-sdk-cdi</artifactId>
Original file line number Diff line number Diff line change
@@ -232,7 +232,7 @@ private void process(RoundContext roundContext, TypeInfo blueprint) {
// static X create()
addCreateDefaultMethod(blueprintDef, propertyData, classModel, prototype, ifaceName, typeArgumentString, typeArguments);

generateCustomMethods(customMethods, classModel);
generateCustomMethods(classModel, builderTypeName, prototype, customMethods);

// abstract class BuilderBase...
GenerateAbstractBuilder.generate(classModel,
@@ -366,8 +366,26 @@ private static void generateCustomConstants(CustomMethods customMethods, ClassMo
}
}

private static void generateCustomMethods(CustomMethods customMethods, ClassModel.Builder classModel) {
private static void generateCustomMethods(ClassModel.Builder classModel,
TypeName builderTypeName,
TypeName prototype,
CustomMethods customMethods) {
for (CustomMethods.CustomMethod customMethod : customMethods.factoryMethods()) {
TypeName typeName = customMethod.declaredMethod().returnType();
// there is a chance the typeName does not have a package (if "forward referenced"),
// in that case compare just by classname (leap of faith...)
if (typeName.packageName().isBlank()) {
String className = typeName.className();
if (!(className.equals(prototype.className())
|| className.equals(builderTypeName.className()))) {
// based on class names
continue;
}
} else if (!(typeName.equals(prototype) || typeName.equals(builderTypeName))) {
// we only generate custom factory methods if they return prototype or builder
continue;
}

// prototype definition - custom static factory methods
// static TypeName create(Type type);
CustomMethods.Method generated = customMethod.generatedMethod().method();
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@

package io.helidon.builder.codegen;

import java.net.URI;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Iterator;
@@ -168,6 +170,18 @@ Consumer<ContentBuilder<?>> toDefaultValue(String defaultValue) {
.addContent(defaultValue)
.addContent("\".toCharArray()");
}
if (Types.PATH.equals(typeName)) {
return content -> content.addContent(Paths.class)
.addContent(".get(\"")
.addContent(defaultValue)
.addContent("\")");
}
if (Types.URI.equals(typeName)) {
return content -> content.addContent(URI.class)
.addContent(".create(\"")
.addContent(defaultValue)
.addContent("\")");
}
if (typeName.primitive()) {
if (typeName.fqName().equals("char")) {
return content -> content.addContent("'")
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@

package io.helidon.builder.codegen;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -31,6 +32,8 @@ final class Types {
static final TypeName ARRAY_LIST = TypeName.create(ArrayList.class);
static final TypeName LINKED_HASH_SET = TypeName.create(LinkedHashSet.class);
static final TypeName CHAR_ARRAY = TypeName.create(char[].class);
static final TypeName PATH = TypeName.create(Path.class);
static final TypeName URI = TypeName.create(java.net.URI.class);
static final TypeName SERVICE_REGISTRY = TypeName.create("io.helidon.service.registry.ServiceRegistry");
static final TypeName GLOBAL_SERVICE_REGISTRY = TypeName.create("io.helidon.service.registry.GlobalServiceRegistry");
static final TypeName GENERATED_SERVICE = TypeName.create("io.helidon.service.registry.GeneratedService");
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -84,6 +86,8 @@ void testTypes() {
checkField(toCheck, checked, fields, "ARRAY_LIST", ArrayList.class);
checkField(toCheck, checked, fields, "LINKED_HASH_SET", LinkedHashSet.class);
checkField(toCheck, checked, fields, "CHAR_ARRAY", char[].class);
checkField(toCheck, checked, fields, "PATH", Path.class);
checkField(toCheck, checked, fields, "URI", URI.class);
checkField(toCheck, checked, fields, "SERVICE_REGISTRY", ServiceRegistry.class);
checkField(toCheck, checked, fields, "GLOBAL_SERVICE_REGISTRY", GlobalServiceRegistry.class);
checkField(toCheck, checked, fields, "GENERATED_SERVICE", GeneratedService.class);
Original file line number Diff line number Diff line change
@@ -30,8 +30,9 @@
final class Javadoc {
private static final Pattern JAVADOC_CODE = Pattern.compile("\\{@code (.*?)}");
private static final Pattern JAVADOC_LINK = Pattern.compile("\\{@link (.*?)}");
private static final Pattern JAVADOC_LINKPLAIN = Pattern.compile("\\{@linkplain (.*?)}");
private static final Pattern JAVADOC_VALUE = Pattern.compile("\\{@value (.*?)}");
private static final Pattern JAVADOC_SEE = Pattern.compile("\\{@see (.*?)}");
private static final Pattern JAVADOC_SEE = Pattern.compile("@see (.*?\n)");

private Javadoc() {
}
@@ -44,6 +45,7 @@ private Javadoc() {
* <li>{@code @param} is stripped from the text</li>
* <li>Any {@code @code} section: the code tag is removed, and surrounded with {@code '}</li>
* <li>Any {@code @link} section: the link tag is removed</li>
* <li>Any {@code @linkplain} section: the linkplain tag is removed</li>
* <li>Any {@code @value} section: the value tag is removed, {code #} is replaced with {@code .}</li>
* <li>Any {@code @see} section: the see tag is removed, prefixed with {@code See},
* {code #} is replaced with {@code .}</li>
@@ -65,8 +67,10 @@ static String parse(String docComment) {
}
// replace all {@code xxx} with 'xxx'
javadoc = JAVADOC_CODE.matcher(javadoc).replaceAll(it -> javadocCode(it.group(1)));
// replace all {@link ...} with just the name
// replace all {@link ...} with just the link
javadoc = JAVADOC_LINK.matcher(javadoc).replaceAll(it -> javadocLink(it.group(1)));
// replace all {@link ...} with just the name
javadoc = JAVADOC_LINKPLAIN.matcher(javadoc).replaceAll(it -> javadocLink(it.group(1)));
// replace all {@value ...} with just the reference
javadoc = JAVADOC_VALUE.matcher(javadoc).replaceAll(it -> javadocValue(it.group(1)));
// replace all {@see ...} with just the reference
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,8 @@
@Prototype.Configured
@Description("builder")
interface MyTargetBlueprint extends MyAbstractBlueprint {
String CONSTANT = "42";

@Description("message description")
@Option.Configured
@Option.Default("message")
@@ -39,4 +41,16 @@ interface MyTargetBlueprint extends MyAbstractBlueprint {
@Description("Ignored option")
String ignored();

/**
* Description.
* {@code technical}
* {@link MyTarget#ignored()}
* {@linkplain MyTarget#ignored()}
* {@value #CONSTANT}
*
* @return some value
* @see MyTarget#message()
*/
@Option.Configured
String javadoc();
}
Loading

0 comments on commit aa3ab17

Please sign in to comment.