diff --git a/devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java b/devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java index 657736e18dc9e7..2f9d498d19dd21 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/CreateApp.java @@ -12,11 +12,11 @@ import io.quarkus.cli.create.TargetGAVGroup; import io.quarkus.cli.create.TargetLanguageGroup; import io.quarkus.devtools.commands.CreateProject.CreateProjectKey; -import io.quarkus.devtools.project.SourceType; import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; import io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler; import io.quarkus.devtools.commands.handlers.CreateProjectCommandHandler; import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.SourceType; import picocli.CommandLine; @CommandLine.Command(name = "app", header = "Create a Quarkus application project.", description = "%n" diff --git a/devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java b/devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java index d17c38360d252a..70fcd130c31fb9 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/CreateCli.java @@ -12,11 +12,11 @@ import io.quarkus.cli.create.TargetGAVGroup; import io.quarkus.cli.create.TargetLanguageGroup; import io.quarkus.devtools.commands.CreateProject.CreateProjectKey; -import io.quarkus.devtools.project.SourceType; import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; import io.quarkus.devtools.commands.handlers.CreateJBangProjectCommandHandler; import io.quarkus.devtools.commands.handlers.CreateProjectCommandHandler; import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.SourceType; import picocli.CommandLine; @CommandLine.Command(name = "cli", header = "Create a Quarkus command-line project.", description = "%n" diff --git a/devtools/cli/src/main/java/io/quarkus/cli/create/BaseCreateCommand.java b/devtools/cli/src/main/java/io/quarkus/cli/create/BaseCreateCommand.java index dc58dcbb4a7a47..439b135dce1cba 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/create/BaseCreateCommand.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/create/BaseCreateCommand.java @@ -17,10 +17,10 @@ import io.quarkus.cli.registry.ToggleRegistryClientMixin; import io.quarkus.devtools.commands.CreateProject.CreateProjectKey; import io.quarkus.devtools.commands.CreateProjectHelper; -import io.quarkus.devtools.project.SourceType; import io.quarkus.devtools.commands.data.QuarkusCommandInvocation; import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.QuarkusProject; +import io.quarkus.devtools.project.SourceType; import io.quarkus.registry.RegistryResolutionException; import picocli.CommandLine; import picocli.CommandLine.Model.CommandSpec; diff --git a/devtools/cli/src/main/java/io/quarkus/cli/create/TargetLanguageGroup.java b/devtools/cli/src/main/java/io/quarkus/cli/create/TargetLanguageGroup.java index 69f0a830d6ccd9..92cc237c0c4867 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/create/TargetLanguageGroup.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/create/TargetLanguageGroup.java @@ -5,9 +5,9 @@ import java.util.stream.Collectors; import io.quarkus.cli.common.OutputOptionMixin; -import io.quarkus.devtools.project.SourceType; import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.JavaVersion; +import io.quarkus.devtools.project.SourceType; import picocli.CommandLine; import picocli.CommandLine.Model.CommandSpec; import picocli.CommandLine.ParameterException; diff --git a/devtools/cli/src/main/java/io/quarkus/cli/registry/RegistryClientMixin.java b/devtools/cli/src/main/java/io/quarkus/cli/registry/RegistryClientMixin.java index 635a851c27ec4e..7739f49d588f55 100644 --- a/devtools/cli/src/main/java/io/quarkus/cli/registry/RegistryClientMixin.java +++ b/devtools/cli/src/main/java/io/quarkus/cli/registry/RegistryClientMixin.java @@ -9,6 +9,7 @@ import io.quarkus.cli.common.TargetQuarkusPlatformGroup; import io.quarkus.devtools.commands.CreateProjectHelper; import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.JavaVersion; import io.quarkus.devtools.project.QuarkusProject; import io.quarkus.devtools.project.QuarkusProjectHelper; import io.quarkus.maven.dependency.ArtifactCoords; @@ -62,7 +63,7 @@ public QuarkusProject createQuarkusProject(Path projectRoot, TargetQuarkusPlatfo + "Use the maven/gradle plugins when working with Quarkus 1.x projects."); } catalog = CreateProjectHelper.completeCatalog(catalog, extensions, QuarkusProjectHelper.artifactResolver()); - return QuarkusProjectHelper.getProject(projectRoot, catalog, buildTool, log); + return QuarkusProjectHelper.getProject(projectRoot, catalog, buildTool, JavaVersion.NA, log); } ExtensionCatalog getExtensionCatalog(TargetQuarkusPlatformGroup targetVersion, OutputOptionMixin log) 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 83f9d2574e8b5a..2f8ce063e2ce75 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 @@ -11,6 +11,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; +import java.util.OptionalInt; import io.quarkus.bootstrap.model.ApplicationModel; import io.quarkus.devtools.commands.UpdateProject; @@ -76,13 +78,20 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws if (!noRewrite) { final BuildTool buildTool = quarkusProject.getExtensionManager().getBuildTool(); String kotlinVersion = getMetadata(targetCatalog, "project", "properties", "kotlin-version"); - + final OptionalInt minJavaVersion = extensionsUpdateInfo.getMinJavaVersion(); + final Optional updateJavaVersion; + if (minJavaVersion.isPresent() + && minJavaVersion.getAsInt() > invocation.getQuarkusProject().getJavaVersion().getAsInt()) { + updateJavaVersion = Optional.of(minJavaVersion.getAsInt()); + } else { + updateJavaVersion = Optional.empty(); + } QuarkusUpdates.ProjectUpdateRequest request = new QuarkusUpdates.ProjectUpdateRequest( buildTool, projectQuarkusPlatformBom.getVersion(), targetPlatformVersion, kotlinVersion, - extensionsUpdateInfo.getMinJavaVersion()); + updateJavaVersion); Path recipe = null; try { recipe = Files.createTempFile("quarkus-project-recipe-", ".yaml"); @@ -91,6 +100,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws final QuarkusUpdatesRepository.FetchResult fetchResult = QuarkusUpdates.createRecipe(invocation.log(), recipe, QuarkusProjectHelper.artifactResolver(), buildTool, updateRecipesVersion, request); + invocation.log().info("OpenRewrite recipe generated: %s", recipe); final String rewritePluginVersion = invocation.getValue(UpdateProject.REWRITE_PLUGIN_VERSION, fetchResult.getRewritePluginVersion()); final boolean rewriteDryRun = invocation.getValue(UpdateProject.REWRITE_DRY_RUN, false); @@ -108,15 +118,6 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws throw new QuarkusCommandException("Error while generating the project update script", e); } catch (QuarkusUpdateException e) { throw new QuarkusCommandException("Error while running the project update script", e); - } finally { - if (recipe != null) { - try { - Files.deleteIfExists(recipe); - } catch (IOException e) { - // ignore - } - } - } } } @@ -179,13 +180,19 @@ private static void logUpdates(QuarkusProject project, ProjectState currentState log.info(""); } - if (extensionsUpdateInfo.isEmpty()) { - if (!platformUpdateInfo.isPlatformUpdatesAvailable()) { - log.info("The project is up-to-date"); - } + if (extensionsUpdateInfo.isUpToDate() && !platformUpdateInfo.isPlatformUpdatesAvailable()) { + log.info("The project is up-to-date"); return; } + if (extensionsUpdateInfo.getMinJavaVersion().isPresent()) { + final Integer extensionsMinJavaVersion = extensionsUpdateInfo.getMinJavaVersion().getAsInt(); + if (extensionsMinJavaVersion > project.getJavaVersion().getAsInt()) { + log.warn("We detected that some of the updated extensions require an update of the Java version to: %s", + extensionsMinJavaVersion); + } + } + for (PlatformInfo platform : platformUpdateInfo.getPlatformImports().values()) { final String provider = platform.getRecommendedProviderKey(); if (!extensionsUpdateInfo.getVersionedManagedExtensions().containsKey(provider) @@ -202,14 +209,15 @@ private static void logUpdates(QuarkusProject project, ProjectState currentState sb.append(" -> remove version (managed)"); log.info(sb.toString()); } - for (ArtifactCoords e : extensionsUpdateInfo.getAddedExtensions().getOrDefault(provider, Collections.emptyList())) { + for (ExtensionUpdateInfo i : extensionsUpdateInfo.getAddedExtensions().getOrDefault(provider, + Collections.emptyList())) { log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, UpdateProjectCommandHandler.ADD, - e.getKey().toGacString())); + i.getRecommendedDependency().getKey().toGacString())); } - for (ArtifactCoords e : extensionsUpdateInfo.getRemovedExtensions().getOrDefault(provider, + for (ExtensionUpdateInfo i : extensionsUpdateInfo.getRemovedExtensions().getOrDefault(provider, Collections.emptyList())) { log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, UpdateProjectCommandHandler.REMOVE, - e.getKey().toGacString())); + i.getCurrentDep().getKey().toGacString())); } log.info(""); } @@ -236,13 +244,7 @@ private static void logUpdates(QuarkusProject project, ProjectState currentState log.info(""); } } - if (extensionsUpdateInfo.getMinJavaVersion().isPresent()) { - final int extensionsMinJavaVersion = extensionsUpdateInfo.getMinJavaVersion().getAsInt(); - if (extensionsMinJavaVersion > project.getJavaVersion().getAsInt()) { - log.warn("We detected that some of the updated extensions require an update of the Java version to: ", - extensionsMinJavaVersion); - } - } + } @SuppressWarnings({ "rawtypes", "unchecked" }) diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ExtensionMapBuilder.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ExtensionMapBuilder.java index e91c09f14670b8..d3b98c4af43ac0 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ExtensionMapBuilder.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ExtensionMapBuilder.java @@ -87,7 +87,8 @@ public ExtensionUpdateInfoBuilder setRecommendedDep(TopExtensionDependency recom } public ExtensionUpdateInfo build() { - return new ExtensionUpdateInfo(currentDep, currentDep.getCatalogMetadata(), resolveRecommendedDep()); + final TopExtensionDependency effectiveRecommendedDep = resolveRecommendedDep(); + return new ExtensionUpdateInfo(currentDep, effectiveRecommendedDep.getCatalogMetadata(), effectiveRecommendedDep); } public TopExtensionDependency resolveRecommendedDep() { diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ProjectExtensionsUpdateInfo.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ProjectExtensionsUpdateInfo.java index a9e488a8bdb885..b25631f6642d96 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ProjectExtensionsUpdateInfo.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ProjectExtensionsUpdateInfo.java @@ -1,37 +1,47 @@ package io.quarkus.devtools.project.update; +import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.OptionalInt; import java.util.stream.Stream; -import io.quarkus.maven.dependency.ArtifactCoords; +import io.quarkus.devtools.project.JavaVersion; import io.quarkus.platform.catalog.processor.ExtensionProcessor; public class ProjectExtensionsUpdateInfo { + private final Map> managedExtensions; final Map> versionedManagedExtensions; - final Map> removedExtensions; - final Map> addedExtensions; + final Map> removedExtensions; + final Map> addedExtensions; final Map> nonPlatformExtensions; - public ProjectExtensionsUpdateInfo(Map> versionedManagedExtensions, - Map> removedExtensions, Map> addedExtensions, + public ProjectExtensionsUpdateInfo(Map> managedExtensions, + Map> versionedManagedExtensions, + Map> removedExtensions, + Map> addedExtensions, Map> nonPlatformExtensionUpdate) { + this.managedExtensions = managedExtensions; this.versionedManagedExtensions = versionedManagedExtensions; this.removedExtensions = removedExtensions; this.addedExtensions = addedExtensions; this.nonPlatformExtensions = nonPlatformExtensionUpdate; } + public Map> getManagedExtensions() { + return managedExtensions; + } + public Map> getVersionedManagedExtensions() { return versionedManagedExtensions; } - public Map> getRemovedExtensions() { + public Map> getRemovedExtensions() { return removedExtensions; } - public Map> getAddedExtensions() { + public Map> getAddedExtensions() { return addedExtensions; } @@ -40,13 +50,18 @@ public Map> getNonPlatformExtensions() { } public OptionalInt getMinJavaVersion() { - return Stream.concat(getVersionedManagedExtensions().values().stream(), getNonPlatformExtensions().values().stream()) - .flatMap(List::stream) - .mapToInt(e -> ExtensionProcessor.getMinimumJavaVersion(e.getRecommendedMetadata())) + return Stream.of(getManagedExtensions().values(), + getVersionedManagedExtensions().values(), + getNonPlatformExtensions().values(), + getAddedExtensions().values()) + .flatMap(Collection::stream) + .flatMap(Collection::stream) + .mapToInt(e -> Optional.ofNullable(ExtensionProcessor.getMinimumJavaVersion(e.getRecommendedMetadata())) + .orElse(JavaVersion.DEFAULT_JAVA_VERSION)) .max(); } - public boolean isEmpty() { + public boolean isUpToDate() { return versionedManagedExtensions.isEmpty() && removedExtensions.isEmpty() && addedExtensions.isEmpty() diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ProjectUpdateInfos.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ProjectUpdateInfos.java index 34443d1a17209f..bb3d978504fdfd 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ProjectUpdateInfos.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ProjectUpdateInfos.java @@ -43,9 +43,10 @@ public static ProjectExtensionsUpdateInfo resolveExtensionsUpdateInfo(ProjectSta info.setRecommendedDep(dep); } } + final Map> managedExtensions = new LinkedHashMap<>(0); final Map> versionedManagedExtensions = new LinkedHashMap<>(0); - final Map> removedExtensions = new LinkedHashMap<>(0); - final Map> addedExtensions = new LinkedHashMap<>(0); + final Map> removedExtensions = new LinkedHashMap<>(0); + final Map> addedExtensions = new LinkedHashMap<>(0); final Map> nonPlatformExtensionUpdates = new LinkedHashMap<>(); for (ExtensionUpdateInfoBuilder infoBuilder : extensionInfo.values()) { final ExtensionUpdateInfo info = infoBuilder.build(); @@ -55,14 +56,14 @@ public static ProjectExtensionsUpdateInfo resolveExtensionsUpdateInfo(ProjectSta if (!info.getCurrentDep().getKey().equals(info.getRecommendedDependency().getKey())) { if (info.getCurrentDep().isPlatformExtension()) { removedExtensions.computeIfAbsent(info.getCurrentDep().getProviderKey(), k -> new ArrayList<>()) - .add(info.getCurrentDep().getArtifact()); + .add(new ExtensionUpdateInfo(info.getCurrentDep(), null, null)); } else { nonPlatformExtensionUpdates.computeIfAbsent(info.getCurrentDep().getProviderKey(), k -> new ArrayList<>()) .add(info); } if (info.getRecommendedDependency().isPlatformExtension()) { addedExtensions.computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()) - .add(info.getRecommendedDependency().getArtifact()); + .add(new ExtensionUpdateInfo(null, info.getRecommendedMetadata(), info.getRecommendedDependency())); } else { nonPlatformExtensionUpdates .computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()) @@ -73,13 +74,18 @@ public static ProjectExtensionsUpdateInfo resolveExtensionsUpdateInfo(ProjectSta versionedManagedExtensions .computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()) .add(info); + } else { + managedExtensions + .computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()) + .add(info); } } else if (!info.getCurrentDep().getVersion().equals(info.getRecommendedDependency().getVersion())) { nonPlatformExtensionUpdates .computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()).add(info); } } - return new ProjectExtensionsUpdateInfo(versionedManagedExtensions, removedExtensions, addedExtensions, + return new ProjectExtensionsUpdateInfo(managedExtensions, versionedManagedExtensions, removedExtensions, + addedExtensions, nonPlatformExtensionUpdates); } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdateRecipeIO.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdateRecipeIO.java index c6f6485ddb0d03..0588ab47baba80 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdateRecipeIO.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdateRecipeIO.java @@ -47,7 +47,7 @@ static String toYaml(QuarkusUpdateRecipe recipe) { q.putAll(QuarkusUpdateRecipe.QUARKUS_RECIPE); List recipeList = new ArrayList<>(); for (RewriteOperation o : recipe.getOperations()) { - recipeList.add(o.toMap(recipe.getBuildTool())); + recipeList.addAll(o.multi(recipe.getBuildTool())); } recipeList.addAll(recipe.getOtherRecipeNames()); q.put(QuarkusUpdateRecipe.RECIPE_LIST_KEY, recipeList); diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdates.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdates.java index 8321adc4813e4e..b5c45ab54e708a 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdates.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdates.java @@ -2,12 +2,13 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.OptionalInt; +import java.util.Optional; import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; import io.quarkus.devtools.messagewriter.MessageWriter; import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.update.rewrite.QuarkusUpdatesRepository.FetchResult; +import io.quarkus.devtools.project.update.rewrite.operations.UpdateJavaVersionOperation; import io.quarkus.devtools.project.update.rewrite.operations.UpdatePropertyOperation; import io.quarkus.devtools.project.update.rewrite.operations.UpgradeGradlePluginOperation; @@ -25,7 +26,10 @@ public static FetchResult createRecipe(MessageWriter log, Path target, MavenArti request.targetVersion); QuarkusUpdateRecipe recipe = new QuarkusUpdateRecipe() .buildTool(request.buildTool); - + if (request.updateJavaVersion.isPresent()) { + final String javaVersion = request.updateJavaVersion.get().toString(); + recipe.addOperation(new UpdateJavaVersionOperation(javaVersion)); + } switch (request.buildTool) { case MAVEN: recipe.addOperation(new UpdatePropertyOperation("quarkus.platform.version", request.targetVersion)) @@ -57,20 +61,20 @@ public static class ProjectUpdateRequest { public final String currentVersion; public final String targetVersion; public final String kotlinVersion; - public final OptionalInt minJavaVersion; + public final Optional updateJavaVersion; public ProjectUpdateRequest(String currentVersion, String targetVersion, String kotlinVersion, - OptionalInt minJavaVersion) { - this(BuildTool.MAVEN, currentVersion, targetVersion, kotlinVersion, minJavaVersion); + Optional updateJavaVersion) { + this(BuildTool.MAVEN, currentVersion, targetVersion, kotlinVersion, updateJavaVersion); } public ProjectUpdateRequest(BuildTool buildTool, String currentVersion, String targetVersion, String kotlinVersion, - OptionalInt minJavaVersion) { + Optional updateJavaVersion) { this.buildTool = buildTool; this.currentVersion = currentVersion; this.targetVersion = targetVersion; this.kotlinVersion = kotlinVersion; - this.minJavaVersion = minJavaVersion; + this.updateJavaVersion = updateJavaVersion; } } } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/RewriteOperation.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/RewriteOperation.java index 7e69d0e4137207..e0557a7aa5b8e8 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/RewriteOperation.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/RewriteOperation.java @@ -1,5 +1,6 @@ package io.quarkus.devtools.project.update.rewrite; +import java.util.List; import java.util.Map; import io.quarkus.devtools.project.BuildTool; @@ -17,5 +18,12 @@ public interface RewriteOperation { * @param buildTool * @return */ - Map toMap(BuildTool buildTool); + default Map single(BuildTool buildTool) { + return Map.of(); + } + + default List> multi(BuildTool buildTool) { + return List.of(single(buildTool)); + } + } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdateDependencyVersionOperation.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdateDependencyVersionOperation.java index ea47c75b415c67..18c6f1c58741be 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdateDependencyVersionOperation.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdateDependencyVersionOperation.java @@ -18,7 +18,7 @@ public UpdateDependencyVersionOperation(String groupId, String artifactId, Strin } @Override - public Map toMap(BuildTool buildTool) { + public Map single(BuildTool buildTool) { switch (buildTool) { case MAVEN: return Map.of("org.openrewrite.maven.UpgradeDependencyVersion", diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdateJavaVersionOperation.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdateJavaVersionOperation.java new file mode 100644 index 00000000000000..ffdd9e194d3a23 --- /dev/null +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdateJavaVersionOperation.java @@ -0,0 +1,36 @@ +package io.quarkus.devtools.project.update.rewrite.operations; + +import java.util.List; +import java.util.Map; + +import io.quarkus.devtools.project.BuildTool; +import io.quarkus.devtools.project.update.rewrite.RewriteOperation; + +public class UpdateJavaVersionOperation implements RewriteOperation { + + private final String newVersion; + + public UpdateJavaVersionOperation(String newVersion) { + this.newVersion = newVersion; + } + + @Override + public List> multi(BuildTool buildTool) { + switch (buildTool) { + case MAVEN: + return List.of( + Map.of("org.openrewrite.maven.ChangePropertyValue", + Map.of("key", "maven.compiler.source", "newValue", newVersion)), + Map.of("org.openrewrite.maven.ChangePropertyValue", + Map.of("key", "maven.compiler.target", "newValue", newVersion)), + Map.of("org.openrewrite.maven.ChangePropertyValue", + Map.of("key", "maven.compiler.release", "newValue", newVersion))); + case GRADLE: + return List.of(Map.of( + "org.openrewrite.gradle.UpdateJavaCompatibility", + Map.of("version", newVersion))); + default: + return List.of(); + } + } +} diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdateManagedDependencyVersionOperation.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdateManagedDependencyVersionOperation.java index 172e077f0a1a2b..1d1dc8677ae9da 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdateManagedDependencyVersionOperation.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdateManagedDependencyVersionOperation.java @@ -18,7 +18,7 @@ public UpdateManagedDependencyVersionOperation(String groupId, String artifactId } @Override - public Map toMap(BuildTool buildTool) { + public Map single(BuildTool buildTool) { switch (buildTool) { case MAVEN: return Map.of("org.openrewrite.maven.ChangeManagedDependencyGroupIdAndArtifactId", diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdatePropertyOperation.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdatePropertyOperation.java index 0929c5a8780ae1..4a8cc0f65c2d3f 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdatePropertyOperation.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpdatePropertyOperation.java @@ -7,8 +7,8 @@ public class UpdatePropertyOperation implements RewriteOperation { - public String key; - public String newValue; + private final String key; + private final String newValue; public UpdatePropertyOperation(String key, String newValue) { this.key = key; @@ -16,7 +16,7 @@ public UpdatePropertyOperation(String key, String newValue) { } @Override - public Map toMap(BuildTool buildTool) { + public Map single(BuildTool buildTool) { switch (buildTool) { case MAVEN: return Map.of("org.openrewrite.maven.ChangePropertyValue", diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpgradeGradlePluginOperation.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpgradeGradlePluginOperation.java index 2fdcbb2a5d71fa..a621df7d7a07ee 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpgradeGradlePluginOperation.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/operations/UpgradeGradlePluginOperation.java @@ -7,8 +7,8 @@ public class UpgradeGradlePluginOperation implements RewriteOperation { - public String pluginIdPattern; - public String newVersion; + private final String pluginIdPattern; + private final String newVersion; public UpgradeGradlePluginOperation(String pluginIdPattern, String newVersion) { this.pluginIdPattern = pluginIdPattern; @@ -16,7 +16,7 @@ public UpgradeGradlePluginOperation(String pluginIdPattern, String newVersion) { } @Override - public Map toMap(BuildTool buildTool) { + public Map single(BuildTool buildTool) { switch (buildTool) { case GRADLE: return Map.of( diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java index 725aa50bb269c3..0530f130015ca4 100644 --- a/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusPluginFunctionalTest.java @@ -20,9 +20,9 @@ import com.google.common.collect.ImmutableMap; import io.quarkus.devtools.commands.CreateProject; -import io.quarkus.devtools.project.SourceType; import io.quarkus.devtools.project.BuildTool; import io.quarkus.devtools.project.QuarkusProjectHelper; +import io.quarkus.devtools.project.SourceType; import io.quarkus.test.devmode.util.DevModeTestUtils; public class QuarkusPluginFunctionalTest extends QuarkusGradleDevToolsTestBase {