diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusUpdate.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusUpdate.java index c47654b99d701..6e33b913d8d3d 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusUpdate.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusUpdate.java @@ -139,7 +139,7 @@ public void logUpdates() { } final UpdateProject invoker = new UpdateProject(quarkusProject); - invoker.latestCatalog(targetCatalog); + invoker.targetCatalog(targetCatalog); if (rewriteUpdateRecipesVersion != null) { invoker.rewriteUpdateRecipesVersion(rewriteUpdateRecipesVersion); } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/UpdateMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/UpdateMojo.java index f2dcb342faf0b..113ca35670cdb 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/UpdateMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/UpdateMojo.java @@ -112,7 +112,7 @@ protected void processProjectState(QuarkusProject quarkusProject) throws MojoExe "Failed to resolve the recommended Quarkus extension catalog from the configured extension registries", e); } final UpdateProject invoker = new UpdateProject(quarkusProject); - invoker.latestCatalog(targetCatalog); + invoker.targetCatalog(targetCatalog); invoker.targetPlatformVersion(platformVersion); invoker.perModule(perModule); invoker.appModel(resolveApplicationModel()); diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/UpdateProject.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/UpdateProject.java index 10cd97549305d..92409437a023d 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/UpdateProject.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/UpdateProject.java @@ -19,7 +19,7 @@ public class UpdateProject { public static final String APP_MODEL = "quarkus.update-project.app-model"; - public static final String LATEST_CATALOG = "quarkus.update-project.latest-catalog"; + public static final String TARGET_CATALOG = "quarkus.update-project.target-catalog"; public static final String PER_MODULE = "quarkus.update-project.per-module"; public static final String NO_REWRITE = "quarkus.update-project.rewrite.disabled"; public static final String TARGET_PLATFORM_VERSION = "quarkus.update-project.target-platform-version"; @@ -38,8 +38,8 @@ public UpdateProject(final QuarkusProject quarkusProject, final MessageWriter me this.invocation = new QuarkusCommandInvocation(quarkusProject, new HashMap<>(), messageWriter); } - public UpdateProject latestCatalog(ExtensionCatalog latestCatalog) { - invocation.setValue(LATEST_CATALOG, requireNonNull(latestCatalog, "latestCatalog is required")); + public UpdateProject targetCatalog(ExtensionCatalog latestCatalog) { + invocation.setValue(TARGET_CATALOG, requireNonNull(latestCatalog, "targetCatalog is required")); return this; } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/UpdateProjectCommandHandler.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/UpdateProjectCommandHandler.java index 7631651898479..b65580726004c 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/UpdateProjectCommandHandler.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/UpdateProjectCommandHandler.java @@ -51,7 +51,7 @@ public class UpdateProjectCommandHandler implements QuarkusCommandHandler { @Override public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws QuarkusCommandException { final ApplicationModel appModel = invocation.getValue(UpdateProject.APP_MODEL); - final ExtensionCatalog latestCatalog = invocation.getValue(UpdateProject.LATEST_CATALOG); + final ExtensionCatalog targetCatalog = invocation.getValue(UpdateProject.TARGET_CATALOG); final String targetPlatformVersion = invocation.getValue(UpdateProject.TARGET_PLATFORM_VERSION); final boolean perModule = invocation.getValue(UpdateProject.PER_MODULE, false); @@ -68,14 +68,18 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws invocation.log().info("Instructions to update this project from '%s' to '%s':", projectQuarkusPlatformBom.getVersion(), targetPlatformVersion); final QuarkusProject quarkusProject = invocation.getQuarkusProject(); - logUpdates(currentState, latestCatalog, false, perModule, quarkusProject.log()); + logUpdates(currentState, targetCatalog, false, perModule, quarkusProject.log()); final boolean noRewrite = invocation.getValue(UpdateProject.NO_REWRITE, false); if (!noRewrite) { final BuildTool buildTool = quarkusProject.getExtensionManager().getBuildTool(); + String kotlinVersion = getMetadata(targetCatalog, "project", "properties", "kotlin-version"); + QuarkusUpdates.ProjectUpdateRequest request = new QuarkusUpdates.ProjectUpdateRequest( buildTool, - projectQuarkusPlatformBom.getVersion(), targetPlatformVersion); + projectQuarkusPlatformBom.getVersion(), + targetPlatformVersion, + kotlinVersion); Path recipe = null; try { recipe = Files.createTempFile("quarkus-project-recipe-", ".yaml"); @@ -534,4 +538,18 @@ boolean isEmpty() { return extensionInfo.isEmpty(); } } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private T getMetadata(ExtensionCatalog catalog, String... path) { + Object currentValue = catalog.getMetadata(); + for (String pathElement : path) { + if (!(currentValue instanceof Map)) { + return null; + } + + currentValue = ((Map) currentValue).get(pathElement); + } + + return (T) currentValue; + } } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/QuarkusUpdates.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/QuarkusUpdates.java index 7f306cdace203..46140c32f074a 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/QuarkusUpdates.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/QuarkusUpdates.java @@ -8,6 +8,7 @@ import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.update.QuarkusUpdatesRepository.FetchResult; import io.quarkus.devtools.project.update.operations.UpdatePropertyOperation; +import io.quarkus.devtools.project.update.operations.UpgradeGradlePluginOperation; public final class QuarkusUpdates { @@ -28,11 +29,17 @@ public static FetchResult createRecipe(MessageWriter log, Path target, MavenArti case MAVEN: recipe.addOperation(new UpdatePropertyOperation("quarkus.platform.version", request.targetVersion)) .addOperation(new UpdatePropertyOperation("quarkus.version", request.targetVersion)); + if (request.kotlinVersion != null) { + recipe.addOperation(new UpdatePropertyOperation("kotlin.version", request.kotlinVersion)); + } break; case GRADLE: case GRADLE_KOTLIN_DSL: recipe.addOperation(new UpdatePropertyOperation("quarkusPlatformVersion", request.targetVersion)) .addOperation(new UpdatePropertyOperation("quarkusPluginVersion", request.targetVersion)); + if (request.kotlinVersion != null) { + recipe.addOperation(new UpgradeGradlePluginOperation("org.jetbrains.kotlin.*", request.kotlinVersion)); + } break; } @@ -48,15 +55,17 @@ public static class ProjectUpdateRequest { public BuildTool buildTool; public String currentVersion; public String targetVersion; + public String kotlinVersion; - public ProjectUpdateRequest(String currentVersion, String targetVersion) { - this(BuildTool.MAVEN, currentVersion, targetVersion); + public ProjectUpdateRequest(String currentVersion, String targetVersion, String kotlinVersion) { + this(BuildTool.MAVEN, currentVersion, targetVersion, kotlinVersion); } - public ProjectUpdateRequest(BuildTool buildTool, String currentVersion, String targetVersion) { + public ProjectUpdateRequest(BuildTool buildTool, String currentVersion, String targetVersion, String kotlinVersion) { this.buildTool = buildTool; this.currentVersion = currentVersion; this.targetVersion = targetVersion; + this.kotlinVersion = kotlinVersion; } } } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/operations/UpgradeGradlePluginOperation.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/operations/UpgradeGradlePluginOperation.java new file mode 100644 index 0000000000000..2ad0899601f87 --- /dev/null +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/operations/UpgradeGradlePluginOperation.java @@ -0,0 +1,29 @@ +package io.quarkus.devtools.project.update.operations; + +import java.util.Map; + +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.update.RewriteOperation; + +public class UpgradeGradlePluginOperation implements RewriteOperation { + + public String pluginIdPattern; + public String newVersion; + + public UpgradeGradlePluginOperation(String pluginIdPattern, String newVersion) { + this.pluginIdPattern = pluginIdPattern; + this.newVersion = newVersion; + } + + @Override + public Map toMap(BuildTool buildTool) { + switch (buildTool) { + case GRADLE: + return Map.of( + "org.openrewrite.gradle.plugins.UpgradePluginVersion", + Map.of("pluginIdPattern", pluginIdPattern, "newVersion", newVersion)); + default: + throw new UnsupportedOperationException("This operation is only supported for Gradle projects"); + } + } +}