Skip to content

Commit

Permalink
Builder: Factory methods should only be generated if returning protot…
Browse files Browse the repository at this point in the history
…ype or builder

Checkstyle fixes
  • Loading branch information
tomas-langer committed Jun 7, 2024
1 parent 49054fd commit f38f722
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion integrations/oci/authentication/instance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>io.helidon.integrations.oci.authentication</groupId>
<artifactId>helidon-integrations-oci-authentication-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
</parent>
<artifactId>helidon-integrations-oci-authentication-instance</artifactId>
<name>Helidon Integrations OCI Authentication Instance</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>io.helidon.integrations.oci.authentication</groupId>
<artifactId>helidon-integrations-oci-authentication-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
</parent>
<artifactId>helidon-integrations-oci-authentication-oke-workload</artifactId>
<name>Helidon Integrations OCI Authentication Workload</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* Support for OCI authentication method based on OKE workload identity.
*/
module io.helidon.integrations.oci.authentication.workload {
module io.helidon.integrations.oci.authentication.okeworkload {
requires io.helidon.common;
requires io.helidon.service.registry;
requires io.helidon.integrations.oci;
Expand Down
4 changes: 2 additions & 2 deletions integrations/oci/authentication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>io.helidon.integrations.oci</groupId>
<artifactId>helidon-integrations-oci-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>

Expand All @@ -36,6 +36,6 @@
<modules>
<module>instance</module>
<module>resource</module>
<module>workload</module>
<module>oke-workload</module>
</modules>
</project>
2 changes: 1 addition & 1 deletion integrations/oci/authentication/resource/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>io.helidon.integrations.oci.authentication</groupId>
<artifactId>helidon-integrations-oci-authentication-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
</parent>
<artifactId>helidon-integrations-oci-authentication-resource</artifactId>
<name>Helidon Integrations OCI Resource Instance</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ interface OciConfigBlueprint {
* <p>
* Known and supported authentication strategies for public OCI:
* <ul>
* <li>{@value #ATN_METHOD_AUTO} - use the list of {@link #allowedAtnMethods()} (in the provided order), and choose
* the first one
* capable of providing data</li>
* <li>{@value #ATN_METHOD_AUTO} - use the list of {@link io.helidon.integrations.oci.OciConfig#allowedAtnMethods()}
* (in the provided order), and choose the first one capable of providing data</li>
* <li>{@value AuthenticationMethodConfig#METHOD} -
* use configuration of the application to obtain values needed to set up connectivity, uses
* {@link com.oracle.bmc.auth.SimpleAuthenticationDetailsProvider}</li>
Expand All @@ -83,36 +82,37 @@ interface OciConfigBlueprint {
String atnMethod();

/**
* List of attempted authentication strategies in case {@link #atnMethod()} is set to {@value #ATN_METHOD_AUTO}.
* List of attempted authentication strategies in case {@link io.helidon.integrations.oci.OciConfig#atnMethod()} is set
* to {@value #ATN_METHOD_AUTO}.
* <p>
* In case the list is empty, all available strategies will be tried, ordered by their {@link io.helidon.common.Weight}
*
* @return list of authentication strategies to be tried
* @see #atnMethod()
* @see io.helidon.integrations.oci.OciConfig#atnMethod()
*/
@Option.Configured
List<String> allowedAtnMethods();

/**
* Config method configuration (if provided and used).
*
* @return information needed for config {@link #atnMethod()}
* @return information needed for config {@link io.helidon.integrations.oci.OciConfig#atnMethod()}
*/
@Option.Configured("authentication.config")
Optional<ConfigMethodConfig> configMethodConfig();

/**
* Config file method configuration (if provided and used).
*
* @return information to customize config for {@link #atnMethod()}
* @return information to customize config for {@link io.helidon.integrations.oci.OciConfig#atnMethod()}
*/
@Option.Configured("authentication.config-file")
Optional<ConfigFileMethodConfig> configFileMethodConfig();

/**
* Session token method configuration (if provided and used).
*
* @return information to customize config for {@link #atnMethod()}
* @return information to customize config for {@link io.helidon.integrations.oci.OciConfig#atnMethod()}
*/
@Option.Configured("authentication.session-token")
Optional<SessionTokenMethodConfig> sessionTokenMethodConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import io.helidon.builder.api.Option;
import io.helidon.builder.api.Prototype;

import com.oracle.bmc.auth.SessionTokenAuthenticationDetailsProvider.SessionTokenAuthenticationDetailsProviderBuilder;

/**
* Configuration of the {@code config} authentication method.
*/
Expand Down Expand Up @@ -121,7 +119,7 @@ interface SessionTokenMethodConfigBlueprint {
* Defaults to 0, to refresh immediately (implemented in the authentication details provider).
*
* @return initial refresh delay
* @see SessionTokenAuthenticationDetailsProviderBuilder#initialRefreshDelay(long)
* @see com.oracle.bmc.auth.SessionTokenAuthenticationDetailsProvider.SessionTokenAuthenticationDetailsProviderBuilder#initialRefreshDelay(long)
*/
@Option.Configured
Optional<Duration> initialRefreshDelay();
Expand All @@ -131,7 +129,7 @@ interface SessionTokenMethodConfigBlueprint {
* Defaults to 55 minutes (implemented in the authentication details provider).
*
* @return refresh period
* @see SessionTokenAuthenticationDetailsProviderBuilder#refreshPeriod(long)
* @see com.oracle.bmc.auth.SessionTokenAuthenticationDetailsProvider.SessionTokenAuthenticationDetailsProviderBuilder#refreshPeriod(long)
*/
@Option.Configured
Optional<Duration> refreshPeriod();
Expand Down
2 changes: 1 addition & 1 deletion integrations/oci/tests/authentication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>helidon-integrations-oci-tests</groupId>
<artifactId>helidon-integrations-oci-tests-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
</parent>

<artifactId>helidon-integrations-oci-tests-authentication</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Copyright (c) 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.
# 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.
#

[DEFAULT]
user=default-user
fingerprint=default-fp
tenancy=default-tenant
region=us-chicago-1
pass_phrase=default-passphrase
key_file=default-private-key

[MY_PROFILE]
user=user
fingerprint=fp
tenancy=tenant
region=us-phoenix-1
pass_phrase=passphrase
key_file=private-key
2 changes: 1 addition & 1 deletion integrations/oci/tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>io.helidon.integrations.oci</groupId>
<artifactId>helidon-integrations-oci-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>

Expand Down

0 comments on commit f38f722

Please sign in to comment.