From 1a5dc4d2d26b88a1bebd63f05f502872db5b0023 Mon Sep 17 00:00:00 2001 From: altro3 Date: Sun, 3 Dec 2023 15:19:44 +0700 Subject: [PATCH] Sonar code smells fixes --- README.md | 2 +- .../gradle/aot/AbstractMicronautAotCliTask.java | 2 +- .../io/micronaut/gradle/aot/AotShadowSupport.java | 3 +++ .../gradle/aot/MicronautAOTConfigWriterTask.java | 14 ++++++-------- .../micronaut/gradle/aot/MicronautAotPlugin.java | 6 +++--- .../gradle/aot/MicronautAotSampleConfTask.java | 2 +- ...ronaut.internal.build.functional-testing.gradle | 2 +- .../build/sourcegen/SimpleSourceProcessor.java | 1 - .../micronaut/gradle/crac/CRaCConfiguration.java | 2 +- .../gradle/docker/MicronautDockerPlugin.java | 2 +- .../gradle/docker/MicronautDockerfile.java | 2 +- .../gradle/docker/NativeImageDockerfile.java | 2 +- .../io/micronaut/gradle/graalvm/GraalUtil.java | 3 +++ .../gradle/graalvm/MicronautGraalPlugin.java | 5 ++--- .../java/io/micronaut/gradle/LenientGradle.java | 3 +++ .../micronaut/gradle/MicronautComponentPlugin.java | 1 - .../java/io/micronaut/gradle/PluginsHelper.java | 3 +++ .../io/micronaut/gradle/ShadowPluginSupport.java | 3 +++ .../src/main/java/io/micronaut/gradle/Strings.java | 6 +++++- .../io/micronaut/gradle/graalvm/GraalUtil.java | 3 +++ .../openapi/tasks/OpenApiClientWorkAction.java | 1 - .../openapi/tasks/OpenApiServerWorkAction.java | 1 - .../catalog/LenientVersionCatalogParser.java | 13 ++++++------- .../catalog/MicronautCatalogSettingsPlugin.java | 4 ++-- .../gradle/catalog/VersionCatalogTomlModel.java | 4 +++- .../MicronautTestResourcesPlugin.java | 2 +- .../internal/TestResourcesGraalVM.java | 14 ++++++++------ 27 files changed, 62 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 49f5cf43..98d3c4e4 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,4 @@ Documentation for the development version of the plugin can be found [here](http Documentation for the 3.x version of the plugin can be found [here](https://github.com/micronaut-projects/micronaut-gradle-plugin/tree/3.7.x#readme). -Documentation for the 2.x version of the plugin can be found [here](https://github.com/micronaut-projects/micronaut-gradle-plugin/tree/2.0.x#readme). \ No newline at end of file +Documentation for the 2.x version of the plugin can be found [here](https://github.com/micronaut-projects/micronaut-gradle-plugin/tree/2.0.x#readme). diff --git a/aot-plugin/src/main/java/io/micronaut/gradle/aot/AbstractMicronautAotCliTask.java b/aot-plugin/src/main/java/io/micronaut/gradle/aot/AbstractMicronautAotCliTask.java index ae0375bf..9dae82f3 100644 --- a/aot-plugin/src/main/java/io/micronaut/gradle/aot/AbstractMicronautAotCliTask.java +++ b/aot-plugin/src/main/java/io/micronaut/gradle/aot/AbstractMicronautAotCliTask.java @@ -127,7 +127,7 @@ public final void execute() throws IOException { } } finally { onSuccess(outputDir); - argFile.delete(); + Files.delete(argFile.toPath()); } } diff --git a/aot-plugin/src/main/java/io/micronaut/gradle/aot/AotShadowSupport.java b/aot-plugin/src/main/java/io/micronaut/gradle/aot/AotShadowSupport.java index e33fb0c0..66fb5b67 100644 --- a/aot-plugin/src/main/java/io/micronaut/gradle/aot/AotShadowSupport.java +++ b/aot-plugin/src/main/java/io/micronaut/gradle/aot/AotShadowSupport.java @@ -33,6 +33,9 @@ */ class AotShadowSupport { + private AotShadowSupport() { + } + static void registerShadowJar(Project project, ArchiveOperations archiveOperations, TaskContainer tasks, diff --git a/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAOTConfigWriterTask.java b/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAOTConfigWriterTask.java index d86eff72..ee784f06 100644 --- a/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAOTConfigWriterTask.java +++ b/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAOTConfigWriterTask.java @@ -77,23 +77,21 @@ public abstract class MicronautAOTConfigWriterTask extends DefaultTask { private static void booleanOptimization(Properties props, String optimizationId, Provider provider) { if (provider.isPresent()) { String key = optimizationId + ".enabled"; - if (!props.containsKey(key)) { - props.put(key, String.valueOf(provider.get())); - } + props.computeIfAbsent(key, (k) -> String.valueOf(provider.get())); } } private static void stringListParameter(Properties props, String parameter, ListProperty provider) { if (provider.isPresent()) { List elements = provider.get(); - if (!props.containsKey(parameter) && !elements.isEmpty()) { - props.put(parameter, String.join(",", elements)); + if (!elements.isEmpty()) { + props.computeIfAbsent(parameter, (k) -> String.join(",", elements)); } } } private static void stringParameter(Properties props, String parameter, Property provider) { if (provider.isPresent()) { - props.put(parameter, provider.get()); + props.setProperty(parameter, provider.get()); } } @@ -112,10 +110,10 @@ void writeConfigFile() { props.putAll(optimizations.getConfigurationProperties().get()); } if (!props.containsKey(KnownMissingTypesSourceGenerator.OPTION.key())) { - props.put(KnownMissingTypesSourceGenerator.OPTION.key(), String.join(",", MicronautAotPlugin.TYPES_TO_CHECK)); + props.setProperty(KnownMissingTypesSourceGenerator.OPTION.key(), String.join(",", MicronautAotPlugin.TYPES_TO_CHECK)); } if (!props.containsKey(AbstractStaticServiceLoaderSourceGenerator.SERVICE_TYPES)) { - props.put(AbstractStaticServiceLoaderSourceGenerator.SERVICE_TYPES, String.join(",", MicronautAotPlugin.SERVICE_TYPES)); + props.setProperty(AbstractStaticServiceLoaderSourceGenerator.SERVICE_TYPES, String.join(",", MicronautAotPlugin.SERVICE_TYPES)); } booleanOptimization(props, GraalVMOptimizationFeatureSourceGenerator.ID, getForNative()); booleanOptimization(props, LogbackConfigurationSourceGenerator.ID, optimizations.getReplaceLogbackXml()); diff --git a/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAotPlugin.java b/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAotPlugin.java index b4004974..7a265ee0 100644 --- a/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAotPlugin.java +++ b/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAotPlugin.java @@ -160,7 +160,7 @@ private void registerPrepareOptimizationsTasks(Project project, Configurations c } private void registerCreateSamplesTasks(Project project, Configuration optimizerRuntimeClasspath, Configuration applicationClasspath, TaskContainer tasks, AOTExtension aotExtension) { - TaskProvider createAotSampleConfigurationFiles = tasks.register("createAotSampleConfigurationFiles", task -> + TaskProvider createAotSampleConfigurationFiles = tasks.register("createAotSampleConfigurationFiles", task -> task.setDescription("Generates Micronaut AOT sample configuration files") ); for (OptimizerIO.TargetRuntime targetRuntime : OptimizerIO.TargetRuntime.values()) { @@ -325,8 +325,8 @@ private void registerJavaExecOptimizedRun(Project project, public void execute(Task t) { if (task.getLogger().isDebugEnabled()) { task.getLogger().debug( - "Running optimized entry point: " + task.getMainClass().get() + - "\nClasspath:\n " + task.getClasspath().getFiles() + "Running optimized entry point: {}\nClasspath:\n {}", + task.getMainClass().get(), task.getClasspath().getFiles() .stream() .map(File::getName) .collect(Collectors.joining("\n ")) diff --git a/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAotSampleConfTask.java b/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAotSampleConfTask.java index e9136b14..ab56d0b3 100644 --- a/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAotSampleConfTask.java +++ b/aot-plugin/src/main/java/io/micronaut/gradle/aot/MicronautAotSampleConfTask.java @@ -33,7 +33,7 @@ protected void configureExtraArguments(List args) { protected void onSuccess(File outputDir) { File sampleFile = new File(outputDir, getTargetRuntime().map(runtime -> runtime.getSimpleName() + ".properties").orElse("sample.properties").get()); if (sampleFile.exists()) { - System.out.println("Sample configuration file written to " + Strings.clickableUrl(sampleFile)); + getLogger().lifecycle("Sample configuration file written to {}", Strings.clickableUrl(sampleFile)); } } } diff --git a/buildSrc/src/main/groovy/io.micronaut.internal.build.functional-testing.gradle b/buildSrc/src/main/groovy/io.micronaut.internal.build.functional-testing.gradle index 2bb97ac9..6faccf32 100644 --- a/buildSrc/src/main/groovy/io.micronaut.internal.build.functional-testing.gradle +++ b/buildSrc/src/main/groovy/io.micronaut.internal.build.functional-testing.gradle @@ -32,7 +32,7 @@ extensions.create("functionalTesting", FunctionalTestingExtension) def prepareRepository = tasks.register("prepareRepository", Sync) { from configurations.pluginsUnderTest - into file("${buildDir}/aggregatedRepo") + into layout.buildDirectory.dir("aggregatedRepo").get().asFile } tasks.withType(Test).configureEach { Test test -> diff --git a/buildSrc/src/main/groovy/io/micronaut/internal/build/sourcegen/SimpleSourceProcessor.java b/buildSrc/src/main/groovy/io/micronaut/internal/build/sourcegen/SimpleSourceProcessor.java index f58d3cc4..d4c84637 100644 --- a/buildSrc/src/main/groovy/io/micronaut/internal/build/sourcegen/SimpleSourceProcessor.java +++ b/buildSrc/src/main/groovy/io/micronaut/internal/build/sourcegen/SimpleSourceProcessor.java @@ -28,7 +28,6 @@ import org.gradle.api.tasks.TaskAction; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; diff --git a/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCConfiguration.java b/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCConfiguration.java index bc541285..2d167dd7 100644 --- a/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCConfiguration.java +++ b/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCConfiguration.java @@ -37,7 +37,7 @@ public interface CRaCConfiguration { /** * The platform to specify in the FROM instruction defaults to {@value MicronautCRaCPlugin#CRAC_DEFAULT_BASE_IMAGE_PLATFORM}. - * @return the platform (can be removed with {@code platform.convention(null)} in the {@link CRaCConfiguration} extension) + * @return the platform (can be removed with {@code platform.convention(null)} in the CRaCConfiguration extension) * @deprecated use {@link #getArch()} instead */ @SuppressWarnings("java:S6355") // We need Java 8... Java 8 doesn't have forRemoval and since diff --git a/docker-plugin/src/main/java/io/micronaut/gradle/docker/MicronautDockerPlugin.java b/docker-plugin/src/main/java/io/micronaut/gradle/docker/MicronautDockerPlugin.java index afbfd07e..9b6aaa30 100644 --- a/docker-plugin/src/main/java/io/micronaut/gradle/docker/MicronautDockerPlugin.java +++ b/docker-plugin/src/main/java/io/micronaut/gradle/docker/MicronautDockerPlugin.java @@ -310,7 +310,7 @@ private TaskProvider configureNativeDockerBuild(Project p task.doLast(new Action<>() { @Override public void execute(Task task1) { - System.out.println("AWS Lambda ZIP built: " + lambdaZip.get()); + project.getLogger().lifecycle("AWS Lambda ZIP built: {}", lambdaZip.get()); } }); task.finalizedBy(removeContainer); diff --git a/docker-plugin/src/main/java/io/micronaut/gradle/docker/MicronautDockerfile.java b/docker-plugin/src/main/java/io/micronaut/gradle/docker/MicronautDockerfile.java index a9a5d95c..dfc83c80 100644 --- a/docker-plugin/src/main/java/io/micronaut/gradle/docker/MicronautDockerfile.java +++ b/docker-plugin/src/main/java/io/micronaut/gradle/docker/MicronautDockerfile.java @@ -80,7 +80,7 @@ public void create() throws IOException { if (getDockerfileTweaks().isPresent()) { DockerfileEditor.apply(getObjects(), this, getDockerfileTweaks().get()); } - System.out.println("Dockerfile written to: " + getDestFile().get().getAsFile().getAbsolutePath()); + getLogger().lifecycle("Dockerfile written to: {}", getDestFile().get().getAsFile().getAbsolutePath()); } protected void setupInstructions(List additionalInstructions) { diff --git a/docker-plugin/src/main/java/io/micronaut/gradle/docker/NativeImageDockerfile.java b/docker-plugin/src/main/java/io/micronaut/gradle/docker/NativeImageDockerfile.java index 78b0ac2c..dfe8d1ff 100644 --- a/docker-plugin/src/main/java/io/micronaut/gradle/docker/NativeImageDockerfile.java +++ b/docker-plugin/src/main/java/io/micronaut/gradle/docker/NativeImageDockerfile.java @@ -376,7 +376,7 @@ public DirectoryProperty getPgoProfilesDirectory() { @Override public void execute(Task task) { java.io.File f = getDestFile().get().getAsFile(); - System.out.println("Dockerfile written to: " + f.getAbsolutePath()); + getLogger().lifecycle("Dockerfile written to: {}", f.getAbsolutePath()); } }); } diff --git a/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/GraalUtil.java b/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/GraalUtil.java index ec37178a..6a8a8605 100644 --- a/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/GraalUtil.java +++ b/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/GraalUtil.java @@ -7,6 +7,9 @@ */ public final class GraalUtil { + private GraalUtil() { + } + /** * @return Return whether the JVM in use a GraalVM JVM. */ diff --git a/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java b/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java index b87f14dd..c11d0a83 100644 --- a/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java +++ b/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java @@ -85,7 +85,7 @@ public void apply(Project project) { } ); TaskContainer tasks = project.getTasks(); - project.getPluginManager().withPlugin("application", plugin -> { + project.getPluginManager().withPlugin("application", plugin -> tasks.withType(BuildNativeImageTask.class).named("nativeCompile", nativeImageTask -> { MicronautRuntime mr = PluginsHelper.resolveRuntime(project); if (mr.isLambdaProvided()) { @@ -98,8 +98,7 @@ public void apply(Project project) { nativeImageTask.getOptions().get().getMainClass().set(nativeLambdaExtension.getLambdaRuntimeClassName()); } } - }); - }); + })); } private void workaroundForResourcesDirectoryMissing(Project project) { diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/LenientGradle.java b/minimal-plugin/src/main/java/io/micronaut/gradle/LenientGradle.java index 47607517..d917d20a 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/LenientGradle.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/LenientGradle.java @@ -26,6 +26,9 @@ public class LenientGradle { private static final Map>> CLASSES = new ConcurrentHashMap<>(); + private LenientGradle() { + } + private static Optional> findClass(String name) { return CLASSES.computeIfAbsent(name, LenientGradle::loadClass); } diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautComponentPlugin.java b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautComponentPlugin.java index c6dc97ce..cc0047c3 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautComponentPlugin.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautComponentPlugin.java @@ -31,7 +31,6 @@ import org.gradle.api.tasks.testing.Test; import java.io.File; -import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/PluginsHelper.java b/minimal-plugin/src/main/java/io/micronaut/gradle/PluginsHelper.java index b0c73cce..8a1b4c11 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/PluginsHelper.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/PluginsHelper.java @@ -90,6 +90,9 @@ public abstract class PluginsHelper { VALIDATION_VERSION_PROPERTY ); + private PluginsHelper() { + } + public static void maybeAddMicronautPlaformBom(Project p, Configuration configuration) { MicronautExtension micronautExtension = p.getExtensions().findByType(MicronautExtension.class); configuration.getDependencies().addAllLater( diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/ShadowPluginSupport.java b/minimal-plugin/src/main/java/io/micronaut/gradle/ShadowPluginSupport.java index 513bb7ce..85f71bd3 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/ShadowPluginSupport.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/ShadowPluginSupport.java @@ -21,6 +21,9 @@ public class ShadowPluginSupport { public static final String SHADOW_PLUGIN = "com.github.johnrengelman.shadow"; + private ShadowPluginSupport() { + } + public static void withShadowPlugin(Project p, Runnable action) { p.getPluginManager().withPlugin(SHADOW_PLUGIN, unused -> action.run()); } diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/Strings.java b/minimal-plugin/src/main/java/io/micronaut/gradle/Strings.java index 046262d6..1ab1b13c 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/Strings.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/Strings.java @@ -22,8 +22,12 @@ import static java.util.Locale.ENGLISH; public abstract class Strings { + + private Strings() { + } + public static String capitalize(String name) { - if (name == null || name.length() == 0) { + if (name == null || name.isEmpty()) { return name; } return name.substring(0, 1).toUpperCase(ENGLISH) + name.substring(1); diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/graalvm/GraalUtil.java b/minimal-plugin/src/main/java/io/micronaut/gradle/graalvm/GraalUtil.java index ec37178a..6a8a8605 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/graalvm/GraalUtil.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/graalvm/GraalUtil.java @@ -7,6 +7,9 @@ */ public final class GraalUtil { + private GraalUtil() { + } + /** * @return Return whether the JVM in use a GraalVM JVM. */ diff --git a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiClientWorkAction.java b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiClientWorkAction.java index 932f898c..f0f9bc44 100644 --- a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiClientWorkAction.java +++ b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiClientWorkAction.java @@ -18,7 +18,6 @@ import java.util.List; import io.micronaut.openapi.generator.MicronautCodeGeneratorBuilder; -import io.micronaut.openapi.generator.MicronautCodeGeneratorOptionsBuilder.GeneratorLanguage; import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Property; diff --git a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiServerWorkAction.java b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiServerWorkAction.java index 87055bfb..9189e127 100644 --- a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiServerWorkAction.java +++ b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiServerWorkAction.java @@ -16,7 +16,6 @@ package io.micronaut.gradle.openapi.tasks; import io.micronaut.openapi.generator.MicronautCodeGeneratorBuilder; -import io.micronaut.openapi.generator.MicronautCodeGeneratorOptionsBuilder.GeneratorLanguage; import org.gradle.api.provider.Property; diff --git a/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/LenientVersionCatalogParser.java b/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/LenientVersionCatalogParser.java index 320b88e8..63730b89 100644 --- a/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/LenientVersionCatalogParser.java +++ b/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/LenientVersionCatalogParser.java @@ -117,8 +117,8 @@ private static Boolean expectBoolean(TomlTable table, String element) { private void parseLibrary(String alias, TomlTable librariesTable, RichVersionParser strictVersionParser) { Object gav = librariesTable.get(alias); TomlPosition position = librariesTable.inputPositionOf(alias); - if (gav instanceof String) { - List splitted = splitToList((String) gav); + if (gav instanceof String gavStr) { + List splitted = splitToList(gavStr); if (splitted.size() == 3) { String group = splitted.get(0); String name = splitted.get(1); @@ -147,9 +147,8 @@ private void parseLibrary(String alias, TomlTable librariesTable, RichVersionPar } } VersionModel versionModel = null; - if (version instanceof String) { - String require = (String) version; - RichVersion richVersion = strictVersionParser.parse(require); + if (version instanceof String requireVersion) { + RichVersion richVersion = strictVersionParser.parse(requireVersion); versionModel = new VersionModel(null, richVersion, position); } else if (version instanceof TomlTable versionTable) { String versionRef = versionTable.getString("ref"); @@ -182,8 +181,8 @@ private void parseVersion(String alias, TomlTable versionsTable, RichVersionPars Boolean rejectAll = null; Object version = versionsTable.get(alias); TomlPosition position = versionsTable.inputPositionOf(alias); - if (version instanceof String) { - require = (String) version; + if (version instanceof String versionStr) { + require = versionStr; RichVersion richVersion = strictVersionParser.parse(require); model.addVersion(new VersionModel(alias, richVersion, position)); } else if (version instanceof TomlTable versionTable) { diff --git a/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/MicronautCatalogSettingsPlugin.java b/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/MicronautCatalogSettingsPlugin.java index e9fc3ddf..abde21a6 100644 --- a/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/MicronautCatalogSettingsPlugin.java +++ b/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/MicronautCatalogSettingsPlugin.java @@ -136,8 +136,8 @@ private Provider readFromVersionCatalog(Settings settings) { TomlTable versions = toml.getTable("versions"); if (versions != null) { Object micronaut = versions.get("micronaut"); - if (micronaut instanceof String) { - return (String) micronaut; + if (micronaut instanceof String micronautVer) { + return micronautVer; } } return null; diff --git a/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/VersionCatalogTomlModel.java b/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/VersionCatalogTomlModel.java index 98b0eeb0..70909c9b 100644 --- a/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/VersionCatalogTomlModel.java +++ b/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/VersionCatalogTomlModel.java @@ -49,7 +49,9 @@ public void addLibrary(Library library) { } public void addVersion(VersionModel version) { - assert version.getReference() != null && version.getVersion() != null; + if (version.getReference() == null || version.getVersion() == null) { + throw new IllegalArgumentException("version.getReference() is null or version.getVersion() is null"); + } versions.add(version); versionAliasToVersion.put(version.getReference(), version); } diff --git a/test-resources-plugin/src/main/java/io/micronaut/gradle/testresources/MicronautTestResourcesPlugin.java b/test-resources-plugin/src/main/java/io/micronaut/gradle/testresources/MicronautTestResourcesPlugin.java index 10cb80a7..13e04840 100644 --- a/test-resources-plugin/src/main/java/io/micronaut/gradle/testresources/MicronautTestResourcesPlugin.java +++ b/test-resources-plugin/src/main/java/io/micronaut/gradle/testresources/MicronautTestResourcesPlugin.java @@ -334,7 +334,7 @@ static ArrayList parseVersion(String testedVersion) { } return Arrays.stream(version.split("\\.")) .map(String::trim) - .map(s -> s.replaceAll("[^0-9]", "")) + .map(s -> s.replaceAll("\\D", "")) .map(Integer::parseInt) .collect(Collectors.toCollection(ArrayList::new)); } diff --git a/test-resources-plugin/src/main/java/io/micronaut/gradle/testresources/internal/TestResourcesGraalVM.java b/test-resources-plugin/src/main/java/io/micronaut/gradle/testresources/internal/TestResourcesGraalVM.java index 4bac966a..cb9bd607 100644 --- a/test-resources-plugin/src/main/java/io/micronaut/gradle/testresources/internal/TestResourcesGraalVM.java +++ b/test-resources-plugin/src/main/java/io/micronaut/gradle/testresources/internal/TestResourcesGraalVM.java @@ -29,18 +29,20 @@ * issues. */ public final class TestResourcesGraalVM { + public static final String ENABLED_PROPERTY_NAME = "testresources.native"; + private TestResourcesGraalVM() { + } + public static void configure(Project project, Configuration client, TaskProvider internalStart) { GraalVMExtension graalVMExtension = project.getExtensions().findByType(GraalVMExtension.class); - graalVMExtension.getBinaries().all(b -> { - b.getRuntimeArgs().addAll(internalStart.map(task -> { - ServerConnectionParametersProvider provider = new ServerConnectionParametersProvider(task.getSettingsDirectory()); - return provider.asArguments(); - })); - }); + graalVMExtension.getBinaries().all(b -> b.getRuntimeArgs().addAll(internalStart.map(task -> { + ServerConnectionParametersProvider provider = new ServerConnectionParametersProvider(task.getSettingsDirectory()); + return provider.asArguments(); + }))); ProviderFactory providers = project.getProviders(); boolean includeClient = Boolean.TRUE.equals(providers .systemProperty(ENABLED_PROPERTY_NAME)