Skip to content

Commit

Permalink
Upgrade to Micronaut 4
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Greffier committed Sep 12, 2023
1 parent 8747c0a commit 7d085d6
Show file tree
Hide file tree
Showing 97 changed files with 631 additions and 666 deletions.
24 changes: 15 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id("com.github.johnrengelman.shadow") version "7.1.2"
id("io.micronaut.application") version "3.7.10"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.micronaut.application") version "4.0.3"
id("jacoco")
id("org.sonarqube") version "4.3.0.3225"
id("pl.allegro.tech.build.axion-release") version "1.15.4"
Expand All @@ -18,23 +18,30 @@ dependencies {
annotationProcessor("io.micronaut:micronaut-http-validation")
annotationProcessor("io.micronaut.openapi:micronaut-openapi")
annotationProcessor("io.micronaut.security:micronaut-security-annotations")
annotationProcessor("io.micronaut.serde:micronaut-serde-processor")
annotationProcessor("io.micronaut.validation:micronaut-validation-processor")

implementation("io.micronaut:micronaut-http-client")
implementation("io.micronaut:micronaut-jackson-databind")
implementation("io.micronaut.kafka:micronaut-kafka")
implementation("io.micronaut.reactor:micronaut-reactor")
implementation("io.micronaut.reactor:micronaut-reactor-http-client")
implementation("io.micronaut.security:micronaut-security")
implementation("io.micronaut.security:micronaut-security-jwt")
implementation("io.micronaut.security:micronaut-security-ldap")
implementation("io.micronaut.serde:micronaut-serde-jackson")
implementation("io.micronaut.validation:micronaut-validation")
implementation("io.micronaut.openapi:micronaut-openapi")
implementation("io.swagger.core.v3:swagger-annotations")
implementation("jakarta.annotation:jakarta.annotation-api")
implementation("io.micronaut.openapi:micronaut-openapi")
implementation("io.micronaut.reactor:micronaut-reactor")
implementation("jakarta.validation:jakarta.validation-api")

compileOnly("org.projectlombok:lombok")
compileOnly("com.google.code.findbugs:jsr305") // https://github.com/micronaut-projects/micronaut-core/pull/5691

runtimeOnly("ch.qos.logback:logback-classic")
runtimeOnly("org.yaml:snakeyaml")

testImplementation("io.micronaut:micronaut-http-client")
testImplementation("org.mockito:mockito-core")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:testcontainers")
Expand All @@ -45,7 +52,6 @@ dependencies {
}
testImplementation("org.mockito:mockito-junit-jupiter:5.5.0")
testImplementation("io.projectreactor:reactor-test")

testAnnotationProcessor("org.projectlombok:lombok")
testCompileOnly("org.projectlombok:lombok")
}
Expand Down Expand Up @@ -107,14 +113,14 @@ sonarqube {
jacocoTestReport {
dependsOn test
reports {
html.enabled true
xml.enabled true
html.required = true
xml.required = true
}
}

test {
reports {
html.enabled false
html.required = false
}
}

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
micronautVersion=3.9.2
micronautVersion=4.1.0
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=100000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
24 changes: 16 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand Down
1 change: 1 addition & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand Down
2 changes: 1 addition & 1 deletion micronaut-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ defaultPackage: com.michelin.ns4kafka
testFramework: junit
sourceLanguage: java
buildTool: gradle
features: [annotation-api, app-name, gradle, http-client, java, java-application, junit, kafka, logback, netty-server, openapi, reactor, reactor-http-client, readme, security, security-annotations, security-jwt, security-ldap, shade, yaml]
features: [annotation-api, app-name, gradle, http-client, java, java-application, junit, kafka, logback, lombok, micronaut-aot, micronaut-build, micronaut-http-validation, netty-server, openapi, properties, reactor, reactor-http-client, readme, security, security-annotations, security-jwt, security-ldap, serialization-jackson, shade, test-resources, validation]
40 changes: 40 additions & 0 deletions src/main/java/com/michelin/ns4kafka/config/BeanFactoryConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.michelin.ns4kafka.config;

import io.micronaut.context.annotation.Bean;
import io.micronaut.context.annotation.Factory;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.type.Argument;
import io.micronaut.serde.Decoder;
import io.micronaut.serde.Deserializer;
import io.micronaut.serde.Serializer;
import io.micronaut.serde.exceptions.SerdeException;

import java.io.IOException;
import java.text.NumberFormat;
import java.text.ParseException;

@Factory
public class BeanFactoryConfig {
@Bean
public Deserializer<Number> serializerNumber() {
return new Deserializer<>() {
@Override
public @Nullable Number deserialize(@NonNull Decoder decoder,
@NonNull DecoderContext context,
@NonNull Argument<? super Number> type) throws
IOException {
try {
return NumberFormat.getInstance().parse(decoder.decodeString());
} catch (ParseException e) {
throw new SerdeException("Error decoding number of type " + type + ":" + e.getMessage(), e);
}
}
};
}

@Bean
public Serializer<Number> serializer() {
return (encoder, context, type, value) -> encoder.encodeString(NumberFormat.getInstance().format(value));
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package com.michelin.ns4kafka.controllers;

import com.michelin.ns4kafka.config.AkhqClaimProviderControllerConfig;
import com.michelin.ns4kafka.config.KafkaAsyncExecutorConfig;
import com.michelin.ns4kafka.models.AccessControlEntry;
import com.michelin.ns4kafka.properties.AkhqClaimProviderControllerProperties;
import com.michelin.ns4kafka.properties.KafkaAsyncExecutorProperties;
import com.michelin.ns4kafka.services.AccessControlEntryService;
import com.michelin.ns4kafka.services.NamespaceService;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Post;
import io.micronaut.security.rules.SecurityRule;
import io.micronaut.serde.annotation.Serdeable;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import jakarta.validation.Valid;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;

import javax.annotation.security.RolesAllowed;
import javax.validation.Valid;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
Expand All @@ -31,7 +31,7 @@ public class AkhqClaimProviderController {
private static final List<String> ADMIN_REGEXP = List.of(".*");

@Inject
AkhqClaimProviderControllerConfig config;
AkhqClaimProviderControllerProperties config;

@Inject
AccessControlEntryService accessControlEntryService;
Expand All @@ -40,7 +40,7 @@ public class AkhqClaimProviderController {
NamespaceService namespaceService;

@Inject
List<KafkaAsyncExecutorConfig> managedClusters;
List<KafkaAsyncExecutorProperties> managedClusters;

/**
* List AKHQ claims (v019 and prior)
Expand Down Expand Up @@ -292,19 +292,19 @@ private static void optimizeACL(List<AccessControlEntry> acl) {
.anyMatch(escapedString -> accessControlEntry.getSpec().getResource().startsWith(escapedString)));
}

@Introspected
@Builder
@Getter
@Builder
@Serdeable
public static class AKHQClaimRequest {
String providerType;
String providerName;
String username;
List<String> groups;
}

@Introspected
@Builder
@Getter
@Builder
@Serdeable
public static class AKHQClaimResponse {
private List<String> roles;
private Map<String, List<String>> attributes;
Expand Down Expand Up @@ -335,9 +335,9 @@ public static AKHQClaimResponse ofAdmin(List<String> roles) {
}
}

@Introspected
@Builder
@Getter
@Builder
@Serdeable
public static class AKHQClaimResponseV2 {
private List<String> roles;
private List<String> topicsFilterRegexp;
Expand All @@ -364,9 +364,9 @@ public static AKHQClaimResponseV2 ofAdmin(List<String> roles) {
}
}

@Introspected
@Builder
@Getter
@Builder
@Serdeable
public static class AKHQClaimResponseV3 {
private Map<String, List<Group>> groups;

Expand All @@ -380,7 +380,7 @@ public static AKHQClaimResponseV3 ofAdmin(Map<AccessControlEntry.ResourceType, S

@Data
@Builder
@Introspected
@Serdeable
public static class Group {
private String role;
private List<String> patterns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import io.micronaut.http.annotation.Get;
import io.micronaut.security.authentication.Authentication;
import io.micronaut.security.rules.SecurityRule;
import io.micronaut.serde.annotation.Serdeable;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import javax.annotation.security.RolesAllowed;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

@Tag(name = "Resources", description = "Manage the API resources.")
@RolesAllowed(SecurityRule.IS_ANONYMOUS)
Expand Down Expand Up @@ -170,10 +170,11 @@ public List<ResourceDefinition> list(@Nullable Authentication authentication) {
.toList();
}

@Introspected
@Builder
@Getter
@Setter
@Builder
@Serdeable
@Introspected
public static class ResourceDefinition {
private String kind;
private boolean namespaced;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.validation.Valid;
import jakarta.validation.Valid;
import java.time.Instant;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import jakarta.inject.Inject;
import org.apache.kafka.common.TopicPartition;

import javax.validation.Valid;
import jakarta.validation.Valid;
import java.time.Instant;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import io.micronaut.security.authentication.AuthorizationException;
import lombok.extern.slf4j.Slf4j;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.ElementKind;
import javax.validation.Path;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.ElementKind;
import jakarta.validation.Path;
import java.util.Iterator;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.inject.Inject;

import javax.annotation.security.RolesAllowed;
import javax.validation.Valid;
import jakarta.annotation.security.RolesAllowed;
import jakarta.validation.Valid;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.inject.Inject;

import javax.validation.Valid;
import jakarta.validation.Valid;
import java.time.Instant;
import java.util.Date;
import java.util.List;
Expand Down
Loading

0 comments on commit 7d085d6

Please sign in to comment.