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 9dae82f3..511fbcb4 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 @@ -88,15 +88,15 @@ public final void execute() throws IOException { FileCollection classpath = getOptimizerClasspath().plus(getClasspath()); spec.setClasspath(aotClasspath); spec.getMainClass().set("io.micronaut.aot.cli.Main"); - List args = new ArrayList<>(Arrays.asList( - "--classpath", classpath.getAsPath(), - "--runtime", getTargetRuntime().get().name().toUpperCase(), - "--package", getTargetPackage().get() + var args = new ArrayList<>(Arrays.asList( + "--classpath", classpath.getAsPath(), + "--runtime", getTargetRuntime().get().name().toUpperCase(), + "--package", getTargetPackage().get() )); maybeAddOptimizerClasspath(args, getClasspath()); configureExtraArguments(args); boolean useArgFile = true; - try (PrintWriter wrt = new PrintWriter(new FileWriter(argFile))) { + try (var wrt = new PrintWriter(new FileWriter(argFile))) { args.forEach(arg -> wrt.println(escapeArg(arg))); } catch (IOException e) { useArgFile = false; @@ -107,7 +107,7 @@ public final void execute() throws IOException { spec.args(args); } getLogger().info("Running AOT optimizer {} with parameters: {}", useArgFile ? "using arg file" : "directly", args); - List jvmArgs = new ArrayList<>(); + var jvmArgs = new ArrayList(); if (Boolean.TRUE.equals(getDebug().get())) { getLogger().info("Running with debug enabled"); jvmArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"); 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 66fb5b67..9cfc6cb4 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 @@ -49,7 +49,7 @@ static void registerShadowJar(Project project, Jar mainJar = tasks.named("jar", Jar.class).get(); shadow.getManifest().inheritFrom(mainJar.getManifest()); if (javaApplication != null) { - // This is the reason why we use an afterEvalute: + // This is the reason why we use an afterEvaluate: // The shadow plugin apparently does something with attributes, // breaking support for providers shadow.getManifest().getAttributes().put("Main-Class", javaApplication.getMainClass().get()); diff --git a/aot-plugin/src/main/java/io/micronaut/gradle/aot/MergeServiceFiles.java b/aot-plugin/src/main/java/io/micronaut/gradle/aot/MergeServiceFiles.java index 97937fa6..87a99ab2 100644 --- a/aot-plugin/src/main/java/io/micronaut/gradle/aot/MergeServiceFiles.java +++ b/aot-plugin/src/main/java/io/micronaut/gradle/aot/MergeServiceFiles.java @@ -62,8 +62,8 @@ public void execute() { for (Map.Entry> entry : perService.entrySet()) { String serviceType = entry.getKey(); List files = entry.getValue(); - File mergedServiceFile = new File(outputDir, serviceType); - try (PrintWriter wrt = new PrintWriter(new OutputStreamWriter(new FileOutputStream(mergedServiceFile), StandardCharsets.UTF_8))) { + var mergedServiceFile = new File(outputDir, serviceType); + try (var wrt = new PrintWriter(new OutputStreamWriter(new FileOutputStream(mergedServiceFile), StandardCharsets.UTF_8))) { for (File file : files) { Files.readAllLines(file.toPath()).forEach(wrt::println); } 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 c3036fcb..63dfa059 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 @@ -100,9 +100,9 @@ private static void stringParameter(Properties props, String parameter, Property @TaskAction void writeConfigFile() { - Properties props = new Properties(); + var props = new Properties(); if (getUserConfiguration().isPresent()) { - try (InputStream in = new FileInputStream(getUserConfiguration().getAsFile().get())) { + try (var in = new FileInputStream(getUserConfiguration().getAsFile().get())) { props.load(in); } catch (IOException e) { throw new GradleException("Unable to parse configuration file", e); @@ -152,12 +152,7 @@ void writeConfigFile() { String content = baos.toString(); try (var writer = new PrintWriter(Files.newBufferedWriter(outputFile.toPath()))) { content.lines() - .filter(line -> { - if (line.startsWith("#") && !line.contains(GENERATED_BY_GRADLE_COMMENT)) { - return false; - } - return true; - }) + .filter(line -> !line.startsWith("#") || line.contains(GENERATED_BY_GRADLE_COMMENT)) .forEach(writer::println); } catch (IOException e) { throw new GradleException("Unable to write output file: " + outputFile, e); 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 4eb003d8..eebea817 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 @@ -56,6 +56,7 @@ import org.gradle.api.tasks.TaskProvider; import org.gradle.api.tasks.application.CreateStartScripts; import org.gradle.api.tasks.bundling.Jar; +import org.jetbrains.annotations.NotNull; import javax.inject.Inject; import java.io.File; @@ -71,7 +72,6 @@ import static org.codehaus.groovy.runtime.StringGroovyMethods.capitalize; import static org.gradle.api.plugins.JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME; -@SuppressWarnings("Convert2Lambda") public abstract class MicronautAotPlugin implements Plugin { public static final String DEFAULT_AOT_VERSION = Versions.AOT_VERSION; @@ -214,7 +214,7 @@ private void registerDockerImage(Project project, TaskProvider optimizedJar Attributes attrs = manifest.getAttributes(); attrs.put("Main-Class", javaApplication.getMainClass()); attrs.put("Class-Path", project.getProviders().provider(() -> { - List classpath = new ArrayList<>(); + var classpath = new ArrayList(); Configuration runtimeClasspath = project.getConfigurations() .getByName(RUNTIME_CLASSPATH_CONFIGURATION_NAME); @@ -316,18 +316,15 @@ private void registerJavaExecOptimizedRun(Project project, // https://github.com/micronaut-projects/micronaut-gradle-plugin/issues/385 task.getOutputs().upToDateWhen(t -> false); task.setClasspath(project.files(jarTask, optimizedRuntimeClasspath)); - task.doFirst(new Action<>() { - @Override - public void execute(Task t) { - if (task.getLogger().isDebugEnabled()) { - task.getLogger().debug( - "Running optimized entry point: {}\nClasspath:\n {}", - task.getMainClass().get(), task.getClasspath().getFiles() - .stream() - .map(File::getName) - .collect(Collectors.joining("\n ")) - ); - } + task.doFirst(t -> { + if (task.getLogger().isDebugEnabled()) { + task.getLogger().debug( + "Running optimized entry point: {}\nClasspath:\n {}", + task.getMainClass().get(), task.getClasspath().getFiles() + .stream() + .map(File::getName) + .collect(Collectors.joining("\n ")) + ); } }); }); @@ -419,7 +416,7 @@ private JarExclusionSpec(Provider filterFile, } @Override - public void execute(FileCopyDetails details) { + public void execute(@NotNull FileCopyDetails details) { if (excludes == null) { File resourceFilter = filterFile.get().getAsFile(); try { @@ -444,15 +441,10 @@ private static String normalizePath(String path) { } } - private static final class Configurations { - private final Configuration aotOptimizerRuntimeClasspath; - private final Configuration aotApplication; - private final Configuration aotApplicationClasspath; - - private Configurations(Configuration aotOptimizerRuntimeClasspath, Configuration aotApplication, Configuration aotApplicationClasspath) { - this.aotOptimizerRuntimeClasspath = aotOptimizerRuntimeClasspath; - this.aotApplication = aotApplication; - this.aotApplicationClasspath = aotApplicationClasspath; - } + private record Configurations( + Configuration aotOptimizerRuntimeClasspath, + Configuration aotApplication, + Configuration aotApplicationClasspath + ) { } } 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 ab56d0b3..db010cef 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 @@ -31,7 +31,7 @@ protected void configureExtraArguments(List args) { @Override protected void onSuccess(File outputDir) { - File sampleFile = new File(outputDir, getTargetRuntime().map(runtime -> runtime.getSimpleName() + ".properties").orElse("sample.properties").get()); + var sampleFile = new File(outputDir, getTargetRuntime().map(runtime -> runtime.getSimpleName() + ".properties").orElse("sample.properties").get()); if (sampleFile.exists()) { getLogger().lifecycle("Sample configuration file written to {}", Strings.clickableUrl(sampleFile)); } diff --git a/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCCheckpointDockerfile.java b/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCCheckpointDockerfile.java index 91624b09..3b7e72d8 100644 --- a/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCCheckpointDockerfile.java +++ b/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCCheckpointDockerfile.java @@ -137,7 +137,7 @@ private void setupInstructions(List additionalInstructions) { getInstructions().addAll(additionalInstructions); if (getInstructions().get().stream().noneMatch(instruction -> instruction.getKeyword().equals(EntryPointInstruction.KEYWORD))) { entryPoint(getArgs().map(strings -> { - List newList = new ArrayList<>(strings.size() + 3); + var newList = new ArrayList(strings.size() + 3); newList.add("/home/app/checkpoint.sh"); newList.addAll(strings); return newList; @@ -160,7 +160,7 @@ void setupDockerfileInstructions() { */ void setupTaskPostEvaluate() { // Get any custom instructions the user may or may not have entered, but ignoring our 'from' placeholder - List additionalInstructions = new ArrayList<>(getInstructions().get().subList(1, getInstructions().get().size())); + var additionalInstructions = new ArrayList<>(getInstructions().get().subList(1, getInstructions().get().size())); // Reset the instructions to empty getInstructions().set(new ArrayList<>()); setupInstructions(additionalInstructions); @@ -170,11 +170,13 @@ static void setupResources(CRaCCheckpointDockerfile task) { String workDir = DEFAULT_WORKING_DIR; task.workingDir(workDir); task.instruction("# Add required libraries"); - task.runCommand("apt-get update && apt-get install -y \\\n" + - " curl \\\n" + - " jq \\\n" + - " libnl-3-200 \\\n" + - " && rm -rf /var/lib/apt/lists/*"); + task.runCommand(""" + apt-get update && apt-get install -y \\ + curl \\ + jq \\ + libnl-3-200 \\ + && rm -rf /var/lib/apt/lists/* + """); task.instruction("# Install latest CRaC OpenJDK"); // Limit the architecture, Azul doesn't support x86_64 https://api.azul.com/metadata/v1/docs/swagger diff --git a/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCFinalDockerfile.java b/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCFinalDockerfile.java index 6e23afbc..9594763c 100644 --- a/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCFinalDockerfile.java +++ b/crac-plugin/src/main/java/io/micronaut/gradle/crac/CRaCFinalDockerfile.java @@ -92,9 +92,11 @@ private void setupResources() { String workDir = DEFAULT_WORKING_DIR; workingDir(workDir); instruction("# Add required libraries"); - runCommand("apt-get update && apt-get install -y \\\n" + - " libnl-3-200 \\\n" + - " && rm -rf /var/lib/apt/lists/*"); + runCommand(""" + apt-get update && apt-get install -y \\ + libnl-3-200 \\ + && rm -rf /var/lib/apt/lists/* + """); instruction("# Copy CRaC JDK from the checkpoint image (to save a download)"); copyFile("--from=" + createCheckpointImageName(getProject()) + " /azul-crac-jdk", "/azul-crac-jdk"); instruction("# Copy layers"); diff --git a/crac-plugin/src/main/java/io/micronaut/gradle/crac/MicronautCRaCPlugin.java b/crac-plugin/src/main/java/io/micronaut/gradle/crac/MicronautCRaCPlugin.java index 563dd134..ebc1ecc3 100644 --- a/crac-plugin/src/main/java/io/micronaut/gradle/crac/MicronautCRaCPlugin.java +++ b/crac-plugin/src/main/java/io/micronaut/gradle/crac/MicronautCRaCPlugin.java @@ -16,12 +16,10 @@ import io.micronaut.gradle.docker.DockerBuildStrategy; import io.micronaut.gradle.docker.model.MicronautDockerImage; import io.micronaut.gradle.docker.tasks.BuildLayersTask; -import org.gradle.api.Action; import org.gradle.api.GradleException; import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.Plugin; import org.gradle.api.Project; -import org.gradle.api.Task; import org.gradle.api.file.RegularFile; import org.gradle.api.plugins.ExtensionContainer; import org.gradle.api.plugins.PluginManager; @@ -64,7 +62,7 @@ private void configurePlugin(Project project) { ExtensionContainer extensions = project.getExtensions(); MicronautExtension micronautExtension = extensions.getByType(MicronautExtension.class); CRaCConfiguration configuration = createCRaCConfiguration(project); - NamedDomainObjectContainer dockerImages = (NamedDomainObjectContainer) micronautExtension.getExtensions().findByName("dockerImages"); + var dockerImages = (NamedDomainObjectContainer) micronautExtension.getExtensions().findByName("dockerImages"); createCheckpointDockerImage(project, dockerImages.findByName("main"), configuration); } @@ -209,19 +207,16 @@ private CheckpointTasksOfNote configureCheckpointDockerBuild(Project project, task.getContainerId().set(start.flatMap(DockerExistingContainer::getContainerId)); task.getSink().fileValue(checkpointFile); // Do not use lambda, or it's not compatible with Gradle's config cache - task.doLast(new Action<>() { - @Override - public void execute(Task t) { - List lines; - try { - lines = Files.readAllLines(checkpointFile.toPath()); - } catch (IOException e) { - throw new GradleException("Checkpoint container failed"); - } - lines.forEach(task.getLogger()::lifecycle); - if (lines.stream().noneMatch(l -> l.contains("Snapshotting complete"))) { - throw new GradleException("Checkpoint container failed"); - } + task.doLast(t -> { + List lines; + try { + lines = Files.readAllLines(checkpointFile.toPath()); + } catch (IOException e) { + throw new GradleException("Checkpoint container failed"); + } + lines.forEach(task.getLogger()::lifecycle); + if (lines.stream().noneMatch(l -> l.contains("Snapshotting complete"))) { + throw new GradleException("Checkpoint container failed"); } }); }); @@ -233,22 +228,15 @@ static String createCheckpointImageName(Project project) { return (project.getRootProject().getName() + project.getPath() + "-checkpoint").replace(":", "-"); } - private static class CheckpointTasksOfNote { - - private final TaskProvider checkpointDockerBuild; - private final TaskProvider start; - - private CheckpointTasksOfNote( - @Nullable TaskProvider checkpointDockerBuild, - TaskProvider start - ) { - this.checkpointDockerBuild = checkpointDockerBuild; - this.start = start; - } + private record CheckpointTasksOfNote( + @Nullable + TaskProvider checkpointDockerBuild, + TaskProvider start + ) { Optional> getCheckpointDockerBuild() { - return Optional.ofNullable(checkpointDockerBuild); - } + return Optional.ofNullable(checkpointDockerBuild); + } } private Optional> configureFinalDockerBuild(Project project, @@ -289,13 +277,10 @@ private Optional> configureFinalDockerBuild(Pr } task.getImages().set(Collections.singletonList(project.getName())); task.getInputDir().set(dockerFileTask.flatMap(Dockerfile::getDestDir)); - task.doLast(new Action<>() { - @Override - public void execute(Task t) { - t.getLogger().warn("**********************************************************"); - t.getLogger().warn(" CRaC checkpoint files may contain sensitive information."); - t.getLogger().warn("**********************************************************"); - } + task.doLast(t -> { + t.getLogger().warn("**********************************************************"); + t.getLogger().warn(" CRaC checkpoint files may contain sensitive information."); + t.getLogger().warn("**********************************************************"); }); }); diff --git a/crac-plugin/src/main/java/io/micronaut/gradle/crac/TeeStringWriter.java b/crac-plugin/src/main/java/io/micronaut/gradle/crac/TeeStringWriter.java index c8b0018d..3d3028aa 100644 --- a/crac-plugin/src/main/java/io/micronaut/gradle/crac/TeeStringWriter.java +++ b/crac-plugin/src/main/java/io/micronaut/gradle/crac/TeeStringWriter.java @@ -1,6 +1,7 @@ package io.micronaut.gradle.crac; import org.gradle.api.logging.Logger; +import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.io.StringWriter; @@ -18,7 +19,7 @@ public TeeStringWriter(Logger logger) { @Override @SuppressWarnings("java:S2629") // This is done by Gradle - public void write(char[] cbuf, int off, int len) { + public void write(char @NotNull [] cbuf, int off, int len) { delegate.write(cbuf, off, len); logger.lifecycle(new String(cbuf, off, len).trim()); } diff --git a/crac-plugin/src/main/java/io/micronaut/gradle/crac/tasks/CheckpointScriptTask.java b/crac-plugin/src/main/java/io/micronaut/gradle/crac/tasks/CheckpointScriptTask.java index a7ccc1b7..b8b8462b 100644 --- a/crac-plugin/src/main/java/io/micronaut/gradle/crac/tasks/CheckpointScriptTask.java +++ b/crac-plugin/src/main/java/io/micronaut/gradle/crac/tasks/CheckpointScriptTask.java @@ -57,15 +57,15 @@ void perform() throws IOException { Provider checkpointFile = getOutputDir().file("checkpoint.sh"); Path checkpointScriptPath = checkpointFile.get().getAsFile().toPath(); - FilterSet filterSet = new FilterSet(); + var filterSet = new FilterSet(); filterSet.addFilter("READINESS", getPreCheckpointReadinessCommand().get()); - try (InputStream stream = getCheckpointFile().isPresent() ? + try (var stream = getCheckpointFile().isPresent() ? Files.newInputStream(getCheckpointFile().get().getAsFile().toPath()) : CheckpointScriptTask.class.getResourceAsStream("/checkpoint.sh"); - Reader reader = new InputStreamReader(stream); - BufferedReader bufferedReader = new BufferedReader(reader); - BufferedWriter writer = Files.newBufferedWriter(checkpointScriptPath, StandardCharsets.UTF_8)) { + var bufferedReader = new BufferedReader(new InputStreamReader(stream)); + BufferedWriter writer = Files.newBufferedWriter(checkpointScriptPath, StandardCharsets.UTF_8) + ) { String line; while ((line = bufferedReader.readLine()) != null) { writer.write(filterSet.replaceTokens(line)); 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 076b00d2..79381635 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 @@ -201,11 +201,11 @@ private TaskProvider createMainRunnerJar(Project project, TaskContainer tas jar.from(dirs); jar.manifest(manifest -> { - Map attrs = new HashMap<>(2); + var attrs = new HashMap(2); JavaApplication javaApplication = project.getExtensions().getByType(JavaApplication.class); attrs.put("Main-Class", javaApplication.getMainClass()); attrs.put("Class-Path", project.getProviders().provider(() -> { - List classpath = new ArrayList<>(); + var classpath = new ArrayList(); Configuration runtimeClasspath = project.getConfigurations() .getByName(RUNTIME_CLASSPATH_CONFIGURATION_NAME); @@ -355,12 +355,7 @@ private TaskProvider configureNativeDockerBuild(Project p ); task.getRemotePath().set("/function/function.zip"); task.getHostPath().set(lambdaZip); - task.doLast(new Action<>() { - @Override - public void execute(Task task1) { - project.getLogger().lifecycle("AWS Lambda ZIP built: {}", lambdaZip.get()); - } - }); + task.doLast(task1 -> 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 88c356c7..b5c6ebc1 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 @@ -160,7 +160,7 @@ protected void setupInstructions(List additionalInstructions) { getInstructions().addAll(additionalInstructions); if (getInstructions().get().stream().noneMatch(instruction -> instruction.getKeyword().equals(EntryPointInstruction.KEYWORD))) { entryPoint(getArgs().map(strings -> { - List newList = new ArrayList<>(strings.size() + 3); + var newList = new ArrayList(strings.size() + 3); newList.add("java"); newList.addAll(strings); newList.add("-jar"); @@ -185,7 +185,7 @@ public void setupDockerfileInstructions() { */ public void setupTaskPostEvaluate() { // Get any custom instructions the user may or may not have entered, but ignoring our 'from' placeholder - List additionalInstructions = new ArrayList<>(getInstructions().get().subList(1, getInstructions().get().size())); + var additionalInstructions = new ArrayList<>(getInstructions().get().subList(1, getInstructions().get().size())); // Reset the instructions to empty getInstructions().set(new ArrayList<>()); setupInstructions(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 99557dec..280f7b36 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 @@ -16,7 +16,6 @@ import org.gradle.api.Action; import org.gradle.api.JavaVersion; import org.gradle.api.Project; -import org.gradle.api.Task; import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.ProjectLayout; @@ -37,6 +36,7 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion; import org.gradle.jvm.toolchain.JavaLauncher; import org.gradle.jvm.toolchain.JavaToolchainService; +import org.jetbrains.annotations.NotNull; import javax.inject.Inject; import java.io.IOException; @@ -223,6 +223,7 @@ public NativeImageDockerfile() { .map(bniT -> { NativeImageOptions delegate = bniT.getOptions().get(); return new NativeImageOptions() { + @NotNull @Override public String getName() { return delegate.getName(); @@ -419,13 +420,9 @@ public DirectoryProperty getPgoProfilesDirectory() { }) ); - //noinspection Convert2Lambda - doLast(new Action<>() { - @Override - public void execute(Task task) { - java.io.File f = getDestFile().get().getAsFile(); - getLogger().lifecycle("Dockerfile written to: {}", f.getAbsolutePath()); - } + doLast(task -> { + java.io.File f = getDestFile().get().getAsFile(); + getLogger().lifecycle("Dockerfile written to: {}", f.getAbsolutePath()); }); } @@ -455,7 +452,7 @@ public void create() throws IOException { // Everything done in this method MUST be lazy, so use providers as much as possible private void setupInstructions(List additionalInstructions) { DockerBuildStrategy buildStrategy = getBuildStrategy().get(); - BaseImageForBuildStrategyResolver imageResolver = new BaseImageForBuildStrategyResolver(buildStrategy); + var imageResolver = new BaseImageForBuildStrategyResolver(buildStrategy); Provider baseImageProvider = getProviders().provider(() -> new From(imageResolver.get())); if (buildStrategy == DockerBuildStrategy.LAMBDA) { from(new From(imageResolver.resolve()).withStage("graalvm")); @@ -488,7 +485,7 @@ private void setupInstructions(List additionalInstructions) { String workDir = getTargetWorkingDirectory().get(); runCommand("mkdir " + workDir + "/config-dirs"); getInstructions().addAll(getNativeImageOptions().map(options -> { - DockerResourceConfigDirectoryNamer namer = new DockerResourceConfigDirectoryNamer(); + var namer = new DockerResourceConfigDirectoryNamer(); return options.getConfigurationFileDirectories() .getFiles() .stream() @@ -501,7 +498,7 @@ private void setupInstructions(List additionalInstructions) { } )); getInstructions().addAll(getNativeImageOptions().map(options -> { - DockerResourceConfigDirectoryNamer namer = new DockerResourceConfigDirectoryNamer(); + var namer = new DockerResourceConfigDirectoryNamer(); return options.getConfigurationFileDirectories() .getFiles() .stream() @@ -519,7 +516,7 @@ private void setupInstructions(List additionalInstructions) { copyFile(new CopyFile(workDir + "/application", "/function/func").withStage("graalvm")); copyFile(new CopyFile("/function/runtime/lib/*", ".").withStage("fnfdk")); entryPoint(getArgs().map(strings -> { - List newList = new ArrayList<>(strings.size() + 1); + var newList = new ArrayList(strings.size() + 1); newList.add("./func"); newList.addAll(strings); newList.add("-Djava.library.path=/function"); @@ -537,7 +534,7 @@ private void setupInstructions(List additionalInstructions) { runCommand("dnf install -y zip"); copyFile(new CopyFile(workDir + "/application", "/function/func").withStage("builder")); String funcCmd = String.join(" ", getArgs().map(strings -> { - List newList = new ArrayList<>(strings.size() + 1); + var newList = new ArrayList(strings.size() + 1); newList.add("./func"); newList.addAll(strings); newList.add("-Djava.library.path=$(pwd)"); @@ -556,7 +553,7 @@ private void setupInstructions(List additionalInstructions) { getInstructions().addAll(additionalInstructions); copyFile(new CopyFile(workDir + "/application", "/app/application").withStage("graalvm")); entryPoint(getArgs().map(strings -> { - List newList = new ArrayList<>(strings.size() + 1); + var newList = new ArrayList(strings.size() + 1); newList.add("/app/application"); newList.addAll(strings); return newList; @@ -591,7 +588,7 @@ protected List buildActualCommandLine(Provider executable, Docke options.getMainClass().set(nativeLambdaExtension.getLambdaRuntimeClassName()); } } - List commandLine = new ArrayList<>(); + var commandLine = new ArrayList(); commandLine.add("native-image"); List args = buildNativeImageCommandLineArgs(executable, options); commandLine.addAll(args); @@ -660,7 +657,7 @@ private void prepareNativeImageOptions(NativeImageOptions options) { options.getSystemProperties().set(originalOptions.flatMap(NativeImageOptions::getSystemProperties)); options.getExcludeConfigArgs().set(originalOptions.flatMap(NativeImageOptions::getExcludeConfigArgs).map(this::remapExcludeConfigArgs)); options.getRichOutput().set(false); - DockerResourceConfigDirectoryNamer namer = new DockerResourceConfigDirectoryNamer(); + var namer = new DockerResourceConfigDirectoryNamer(); Provider> remappedConfigDirectories = originalOptions.map(orig -> orig.getConfigurationFileDirectories() .getFiles() .stream() @@ -715,7 +712,7 @@ private NativeImageOptions newNativeImageOptions(String name) { * This is executed post project evaluation */ void setupNativeImageTaskPostEvaluate() { - List additionalInstructions = new ArrayList<>(getInstructions().get()); + var additionalInstructions = new ArrayList<>(getInstructions().get()); // Reset the instructions to empty getInstructions().set(new ArrayList<>()); setupInstructions(additionalInstructions); @@ -755,7 +752,7 @@ private String getProjectFnVersion() { return "latest"; } - private class BaseImageForBuildStrategyResolver { + protected class BaseImageForBuildStrategyResolver { private final DockerBuildStrategy strategy; private String resolved; diff --git a/docker-plugin/src/main/java/io/micronaut/gradle/docker/editor/DefaultEditor.java b/docker-plugin/src/main/java/io/micronaut/gradle/docker/editor/DefaultEditor.java index 8fa519b1..72c85198 100644 --- a/docker-plugin/src/main/java/io/micronaut/gradle/docker/editor/DefaultEditor.java +++ b/docker-plugin/src/main/java/io/micronaut/gradle/docker/editor/DefaultEditor.java @@ -128,21 +128,17 @@ public List getLines() { return Collections.unmodifiableList(lines); } - private static class Boundaries { - private final Integer start; - private final Integer end; - - private Boundaries(Integer start, Integer end) { - this.start = start; - this.end = end; - } + private record Boundaries( + Integer start, + Integer end + ) { public Optional getStart() { - return Optional.ofNullable(start); - } + return Optional.ofNullable(start); + } public Optional getEnd() { - return Optional.ofNullable(end); - } + return Optional.ofNullable(end); + } } } diff --git a/docker-plugin/src/main/java/io/micronaut/gradle/docker/model/DefaultMicronautDockerImage.java b/docker-plugin/src/main/java/io/micronaut/gradle/docker/model/DefaultMicronautDockerImage.java index 51fc2841..007500ec 100644 --- a/docker-plugin/src/main/java/io/micronaut/gradle/docker/model/DefaultMicronautDockerImage.java +++ b/docker-plugin/src/main/java/io/micronaut/gradle/docker/model/DefaultMicronautDockerImage.java @@ -18,6 +18,7 @@ import org.gradle.api.Action; import org.gradle.api.model.ObjectFactory; import org.gradle.api.tasks.Internal; +import org.jetbrains.annotations.NotNull; import javax.inject.Inject; @@ -30,6 +31,7 @@ public DefaultMicronautDockerImage(String name) { this.name = name; } + @NotNull @Override @Internal public String getName() { diff --git a/docker-plugin/src/main/java/io/micronaut/gradle/docker/tasks/PrepareDockerContext.java b/docker-plugin/src/main/java/io/micronaut/gradle/docker/tasks/PrepareDockerContext.java index 4c6eb149..520c5613 100644 --- a/docker-plugin/src/main/java/io/micronaut/gradle/docker/tasks/PrepareDockerContext.java +++ b/docker-plugin/src/main/java/io/micronaut/gradle/docker/tasks/PrepareDockerContext.java @@ -47,7 +47,7 @@ public abstract class PrepareDockerContext extends DefaultTask { @TaskAction void copy() { - DockerResourceConfigDirectoryNamer namer = new DockerResourceConfigDirectoryNamer(); + var namer = new DockerResourceConfigDirectoryNamer(); for (File directory : getInputDirectories().getFiles()) { if (directory.exists()) { getFileOperations().copy(spec -> spec.into(getOutputDirectory().dir(namer.determineNameFor(directory))).from(directory)); diff --git a/gradle.properties b/gradle.properties index 965fcb30..96890e7c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,14 @@ projectVersion=4.4.5-SNAPSHOT projectGroup=io.micronaut.gradle + +title=Micronaut Gradle plugin +projectDesc=Gradle plugin for integrating of Micronaut applications +projectUrl=https://micronaut.io githubBranch=master +githubSlug=micronaut-projects/micronaut-gradle-plugin + +org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8 +org.gradle.configuration-cache=false +org.gradle.configuration-cache.parallel=false org.gradle.caching=true org.gradle.parallel=true -org.gradle.jvmargs=-Xmx768m -githubSlug=micronaut-projects/micronaut-gradle-plugin diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index df97d72b..94113f20 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/AnnotationProcessing.java b/minimal-plugin/src/main/java/io/micronaut/gradle/AnnotationProcessing.java index ec8c872e..2279f0d6 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/AnnotationProcessing.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/AnnotationProcessing.java @@ -26,7 +26,7 @@ public class AnnotationProcessing implements AnnotationProcessingConfigBuilder { private final SourceSetConfigurer sourceSetConfigurer; public static void showAdditionalSourceSetDeprecationWarning(SourceSet sourceSet) { - LOGGER.warn("Source set '{}' was declared using the additionalSourcesets property. Please use sourceSet(...) instead.", sourceSet.getName()); + LOGGER.warn("Source set '{}' was declared using the additionalSourceSets property. Please use sourceSet(...) instead.", sourceSet.getName()); } @Inject diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/ApplicationClasspathInspector.java b/minimal-plugin/src/main/java/io/micronaut/gradle/ApplicationClasspathInspector.java index 3d870d75..3e79e088 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/ApplicationClasspathInspector.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/ApplicationClasspathInspector.java @@ -53,7 +53,7 @@ public Set getResolvedClasspathNames() { @TaskAction void inspect() throws IOException { - try (PrintWriter writer = new PrintWriter(new FileWriter(getReportFile().get().getAsFile()))) { + try (var writer = new PrintWriter(new FileWriter(getReportFile().get().getAsFile()))) { Set resources = getResources().getFiles(); if (resources.stream().anyMatch(ApplicationClasspathInspector::isYamlConfigurationFile)) { writer.println("YAML configuration file detected"); diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautExtension.java b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautExtension.java index fd0bc552..7fb8690b 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautExtension.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautExtension.java @@ -181,7 +181,7 @@ static Map> mapOf(Object... values) { throw new IllegalArgumentException("Number of arguments should be an even number representing the keys and values"); } - Map> answer = new LinkedHashMap<>(len / 2); + var answer = new LinkedHashMap>(len / 2); int i = 0; while (i < values.length - 1) { answer.put(values[i++].toString(), (List) values[i++]); diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautMinimalApplicationPlugin.java b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautMinimalApplicationPlugin.java index a5aa8319..a168b531 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautMinimalApplicationPlugin.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/MicronautMinimalApplicationPlugin.java @@ -18,10 +18,8 @@ import io.micronaut.gradle.graalvm.GraalUtil; import io.micronaut.gradle.internal.AutomaticDependency; import org.apache.tools.ant.taskdefs.condition.Os; -import org.gradle.api.Action; import org.gradle.api.Plugin; import org.gradle.api.Project; -import org.gradle.api.Task; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.artifacts.dsl.DependencyHandler; @@ -111,21 +109,18 @@ private void configureJavaExecTasks(Project project, Configuration developmentOn if (project.getGradle().getStartParameter().isContinuous() || Boolean.getBoolean(INTERNAL_CONTINUOUS_FLAG)) { SourceSet sourceSet = sourceSets.findByName("main"); if (sourceSet != null) { - Map sysProps = new LinkedHashMap<>(); + var sysProps = new LinkedHashMap(); sysProps.put("micronaut.io.watch.restart", true); sysProps.put("micronaut.io.watch.enabled", true); - //noinspection Convert2Lambda - javaExec.doFirst(new Action<>() { - @Override - public void execute(Task workaroundEagerSystemProps) { - String watchPaths = sourceSet - .getAllSource() - .getSrcDirs() - .stream() - .map(File::getPath) - .collect(Collectors.joining(",")); - javaExec.systemProperty("micronaut.io.watch.paths", watchPaths); - } + + javaExec.doFirst(workaroundEagerSystemProps -> { + String watchPaths = sourceSet + .getAllSource() + .getSrcDirs() + .stream() + .map(File::getPath) + .collect(Collectors.joining(",")); + javaExec.systemProperty("micronaut.io.watch.paths", watchPaths); }); javaExec.systemProperties( sysProps @@ -161,7 +156,7 @@ private void configureLogging(Project p) { exit: for (File srcDir : srcDirs) { for (Map.Entry entry : LOGGER_CONFIG_FILE_TO_DEPENDENCY.entrySet()) { - File loggerConfigFile = new File(srcDir, entry.getKey()); + var loggerConfigFile = new File(srcDir, entry.getKey()); if (loggerConfigFile.exists()) { dependencyHandler.add(sourceSet.getRuntimeOnlyConfigurationName(), entry.getValue()); break exit; diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/internal/AutomaticDependency.java b/minimal-plugin/src/main/java/io/micronaut/gradle/internal/AutomaticDependency.java index 3a64620e..d5695491 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/internal/AutomaticDependency.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/internal/AutomaticDependency.java @@ -56,7 +56,7 @@ public void applyTo(Project p) { return List.of(); } if (versionProperty.isPresent()) { - Property provider = (Property) micronautExtension.getExtensions().findByName(versionProperty.get().dslName()); + var provider = (Property) micronautExtension.getExtensions().findByName(versionProperty.get().dslName()); if (provider != null && provider.isPresent()) { return List.of(dependencyHandler.create(coordinates + ":" + provider.get())); } diff --git a/minimal-plugin/src/main/java/io/micronaut/gradle/internal/VersionCatalogLookupCache.java b/minimal-plugin/src/main/java/io/micronaut/gradle/internal/VersionCatalogLookupCache.java index e4f96a66..5cad2602 100644 --- a/minimal-plugin/src/main/java/io/micronaut/gradle/internal/VersionCatalogLookupCache.java +++ b/minimal-plugin/src/main/java/io/micronaut/gradle/internal/VersionCatalogLookupCache.java @@ -27,8 +27,8 @@ /** * This class is used as a workaround for very poor performance * of version catalog scanning in Gradle. - * See https://github.com/micronaut-projects/micronaut-gradle-plugin/issues/932 - * and https://github.com/gradle/gradle/pull/27444/files + * See Issue + * and PR */ class VersionCatalogLookupCache implements AutoCloseable { private final AtomicReference oldCatalog = new AtomicReference<>(); diff --git a/minimal-plugin/src/test/groovy/io/micronaut/gradle/MicronautDeprecationsPluginSpec.groovy b/minimal-plugin/src/test/groovy/io/micronaut/gradle/MicronautDeprecationsPluginSpec.groovy index a6bc0acd..a0a4610b 100644 --- a/minimal-plugin/src/test/groovy/io/micronaut/gradle/MicronautDeprecationsPluginSpec.groovy +++ b/minimal-plugin/src/test/groovy/io/micronaut/gradle/MicronautDeprecationsPluginSpec.groovy @@ -38,7 +38,7 @@ class MicronautDeprecationsPluginSpec extends AbstractGradleBuildSpec { def task = result.task(":assemble") then: - result.output.contains("Source set 'custom' was declared using the additionalSourcesets property. Please use sourceSet(...) instead.") + result.output.contains("Source set 'custom' was declared using the additionalSourceSets property. Please use sourceSet(...) instead.") task.outcome == TaskOutcome.SUCCESS } @@ -76,7 +76,7 @@ class MicronautDeprecationsPluginSpec extends AbstractGradleBuildSpec { def task = result.task(":assemble") then: - !result.output.contains("Source set 'custom' was declared using the additionalSourcesets property. Please use sourceSet(...) instead.") + !result.output.contains("Source set 'custom' was declared using the additionalSourceSets property. Please use sourceSet(...) instead.") task.outcome == TaskOutcome.SUCCESS } } diff --git a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/OpenApiSpec.java b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/OpenApiSpec.java index 2cf74c97..5f7d6fdd 100644 --- a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/OpenApiSpec.java +++ b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/OpenApiSpec.java @@ -18,8 +18,6 @@ import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.MapProperty; import org.gradle.api.provider.Property; -import org.gradle.api.tasks.Input; -import org.gradle.api.tasks.Optional; public interface OpenApiSpec { 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 63730b89..30201ff1 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 @@ -41,7 +41,7 @@ public class LenientVersionCatalogParser { private final VersionCatalogTomlModel model = new VersionCatalogTomlModel(); public static List splitToList(String coordinates) { - List result = new ArrayList<>(3); + var result = new ArrayList(3); String[] split = coordinates.split(":"); for (int i = 0, splitLength = split.length; i < splitLength; i++) { String part = split[i]; @@ -53,7 +53,7 @@ public static List splitToList(String coordinates) { } public void parse(InputStream in) throws IOException { - RichVersionParser strictVersionParser = new RichVersionParser(); + var strictVersionParser = new RichVersionParser(); TomlParseResult result = Toml.parse(in); TomlTable librariesTable = result.getTable(LIBRARIES_KEY); TomlTable versionsTable = result.getTable(VERSIONS_KEY); @@ -124,7 +124,7 @@ private void parseLibrary(String alias, TomlTable librariesTable, RichVersionPar String name = splitted.get(1); String version = splitted.get(2); RichVersion rich = strictVersionParser.parse(version); - VersionModel versionModel = new VersionModel(null, rich, position); + var versionModel = new VersionModel(null, rich, position); model.addLibrary(new Library( alias, group, @@ -174,11 +174,11 @@ private void parseLibrary(String alias, TomlTable librariesTable, RichVersionPar } private void parseVersion(String alias, TomlTable versionsTable, RichVersionParser strictVersionParser) { - String require = null; - String strictly = null; - String prefer = null; - List rejectedVersions = null; - Boolean rejectAll = null; + String require; + String strictly; + String prefer; + List rejectedVersions; + Boolean rejectAll; Object version = versionsTable.get(alias); TomlPosition position = versionsTable.inputPositionOf(alias); if (version instanceof String versionStr) { diff --git a/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/Library.java b/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/Library.java index 8f2d1661..08fdabf4 100644 --- a/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/Library.java +++ b/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/Library.java @@ -17,45 +17,18 @@ import org.tomlj.TomlPosition; -public class Library { - private final String alias; - private final String group; - private final String name; - private final VersionModel version; - private final TomlPosition position; - - public Library(String alias, String group, String name, VersionModel version, TomlPosition position) { - this.alias = alias; - this.group = group; - this.name = name; - this.version = version; - this.position = position; - } - - public String getAlias() { - return alias; - } - - public String getGroup() { - return group; - } - - public String getName() { - return name; - } +public record Library( + String alias, + String group, + String name, + VersionModel version, + TomlPosition position +) { public String getModule() { return group + ":" + name; } - public VersionModel getVersion() { - return version; - } - - public TomlPosition getPosition() { - return position; - } - @Override public boolean equals(Object o) { if (this == o) { 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 633d5de3..08140b58 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 @@ -64,10 +64,10 @@ private static void registerMicronautVersionCatalog(Settings settings, Provider< drm.versionCatalogs(vcs -> { vcs.create("mn", catalog -> catalog.from("io.micronaut.platform:micronaut-platform:" + micronautVersion)); vcs.configureEach(catalog -> { - File catalogOverrideFile = new File(settings.getSettingsDir(), "gradle/" + catalog.getName() + "-" + OVERRIDE_VERSIONS_TOML_FILE); + var catalogOverrideFile = new File(settings.getSettingsDir(), "gradle/" + catalog.getName() + "-" + OVERRIDE_VERSIONS_TOML_FILE); if (catalogOverrideFile.exists()) { - LenientVersionCatalogParser parser = new LenientVersionCatalogParser(); - try (InputStream in = new FileInputStream(catalogOverrideFile)) { + var parser = new LenientVersionCatalogParser(); + try (var in = new FileInputStream(catalogOverrideFile)) { parser.parse(in); VersionCatalogTomlModel model = parser.getModel(); fixupMicronautCatalogWith(catalog, model); @@ -84,8 +84,8 @@ private static void registerMicronautVersionCatalog(Settings settings, Provider< private static void fixupMicronautCatalogWith(VersionCatalogBuilder catalog, VersionCatalogTomlModel model) { model.getVersionsTable().forEach(versionModel -> { - RichVersion version = versionModel.getVersion(); - String reference = versionModel.getReference(); + RichVersion version = versionModel.version(); + String reference = versionModel.reference(); if (reference != null) { catalog.version(reference, vc -> { String strictly = version.getStrictly(); @@ -128,7 +128,7 @@ private Provider createMicronautVersionProvider(Settings settings, Provi private Provider readFromVersionCatalog(Settings settings) { ProviderFactory providers = settings.getProviders(); - File catalogFile = new File(settings.getSettingsDir(), "gradle/libs.versions.toml"); + var catalogFile = new File(settings.getSettingsDir(), "gradle/libs.versions.toml"); return providers.fileContents(getDefaultGradleVersionCatalogFile().fileValue(catalogFile)) .getAsBytes() .map(libsFile -> { 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 70909c9b..112369df 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 @@ -41,7 +41,7 @@ public class VersionCatalogTomlModel { public void addLibrary(Library library) { libraries.add(library); gaToLibrary.put(library.getModule(), library); - String versionRef = library.getVersion().getReference(); + String versionRef = library.version().reference(); if (versionRef != null) { Set librariesByVersionRef = versionAliasToModules.computeIfAbsent(versionRef, e -> new HashSet<>()); librariesByVersionRef.add(library); @@ -49,11 +49,11 @@ public void addLibrary(Library library) { } public void addVersion(VersionModel version) { - if (version.getReference() == null || version.getVersion() == null) { + if (version.reference() == null || version.version() == null) { throw new IllegalArgumentException("version.getReference() is null or version.getVersion() is null"); } versions.add(version); - versionAliasToVersion.put(version.getReference(), version); + versionAliasToVersion.put(version.reference(), version); } public Optional findLibrary(String group, String name) { diff --git a/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/VersionModel.java b/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/VersionModel.java index 0ce65e37..ae5aee84 100644 --- a/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/VersionModel.java +++ b/platform-catalog-plugin/src/main/java/io/micronaut/gradle/catalog/VersionModel.java @@ -15,36 +15,16 @@ */ package io.micronaut.gradle.catalog; -import java.util.Objects; - import org.tomlj.TomlPosition; import javax.annotation.Nullable; +import java.util.Objects; -public class VersionModel { - private final String reference; - private final RichVersion version; - private final TomlPosition position; - - public VersionModel(@Nullable String reference, @Nullable RichVersion version, TomlPosition position) { - this.reference = reference; - this.version = version; - this.position = position; - } - - @Nullable - public String getReference() { - return reference; - } - - @Nullable - public RichVersion getVersion() { - return version; - } - - public TomlPosition getPosition() { - return position; - } +public record VersionModel( + @Nullable String reference, + @Nullable RichVersion version, + TomlPosition position +) { @Override public boolean equals(Object o) {