diff --git a/devtools/cli/src/test/java/io/quarkus/cli/MavenProjectInfoAndUpdateTest.java b/devtools/cli/src/test/java/io/quarkus/cli/MavenProjectInfoAndUpdateTest.java index 53b96e8b33db08..a3c38df41be66a 100644 --- a/devtools/cli/src/test/java/io/quarkus/cli/MavenProjectInfoAndUpdateTest.java +++ b/devtools/cli/src/test/java/io/quarkus/cli/MavenProjectInfoAndUpdateTest.java @@ -61,7 +61,7 @@ void testClean() throws Exception { final Path projectDir = workDir().resolve("acme-clean"); final CliDriver.Result infoResult = run(projectDir, "info"); - + assertThat(infoResult.getExitCode()).isEqualTo(0); assertQuarkusPlatformBoms(infoResult.stdout, "org.acme.quarkus.platform:quarkus-bom:pom:2.0.0 " + UP_TO_DATE_ICON.iconOrMessage(), "org.acme.quarkus.platform:acme-bom:pom:2.0.0 " + UP_TO_DATE_ICON.iconOrMessage()); @@ -72,7 +72,8 @@ void testClean() throws Exception { assertRegistryExtensions(infoResult.stdout, "registry.acme.org", "org.acme:acme-quarkiverse-extension:1.0"); - final CliDriver.Result updateResult = run(projectDir, "update"); + final CliDriver.Result updateResult = run(projectDir, "update", "--no-rewrite"); + assertThat(updateResult.getExitCode()).isEqualTo(0); assertQuarkusPlatformBoms(updateResult.stdout, "org.acme.quarkus.platform:quarkus-bom:pom:2.0.0 " + UP_TO_DATE_ICON.iconOrMessage(), "org.acme.quarkus.platform:acme-bom:pom:2.0.0 " + UP_TO_DATE_ICON.iconOrMessage()); @@ -102,11 +103,15 @@ void testMisalignedPlatformExtensionVersion() throws Exception { assertRegistryExtensions(infoResult.stdout, "registry.acme.org", "org.acme:acme-quarkiverse-extension:1.0"); - final CliDriver.Result rectifyResult = run(projectDir, "update", "--platform-version=1.0.0"); + final CliDriver.Result rectifyResult = run(projectDir, "update", "--platform-version=1.0.0", "--no-rewrite"); + assertThat(rectifyResult.getExitCode()).isEqualTo(0); + assertThat(rectifyResult.stdout) - .contains("[INFO] Update: org.acme.quarkus.platform:acme-quarkus-subatomic:1.0.0 -> remove version (managed)"); + .contains( + "[INFO] Update: org.acme.quarkus.platform:acme-quarkus-subatomic:1.0.0 -> drop version (managed by platform)"); - final CliDriver.Result updateResult = run(projectDir, "update", "-Dquarkus.platform.version=1.0.0"); + final CliDriver.Result updateResult = run(projectDir, "update", "-Dquarkus.platform.version=1.0.0", "--no-rewrite"); + assertThat(updateResult.getExitCode()).isEqualTo(0); assertQuarkusPlatformBomUpdates(updateResult.stdout, ArtifactCoords.pom("org.acme.quarkus.platform", "quarkus-bom", "1.0.0 -> 2.0.0"), ArtifactCoords.pom("org.acme.quarkus.platform", "acme-bom", "1.0.0 -> 2.0.0")); diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/ProjectInfoCommandHandler.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/ProjectInfoCommandHandler.java index e05ade2a0acc4d..cdd44b0d0569f6 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/ProjectInfoCommandHandler.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/ProjectInfoCommandHandler.java @@ -187,7 +187,7 @@ private static boolean logExtensionInfo(TopExtensionDependency dep, boolean rect if (dep.isNonRecommendedVersion()) { sb.append(':').append(dep.getArtifact().getVersion()); if (rectify) { - sb.append(" -> remove version (managed)"); + sb.append(" -> drop version (managed by platform)"); } recommendationsAvailable = true; } else { diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ExtensionUpdateInfo.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ExtensionUpdateInfo.java index de1e0c30b57e4a..82ae78192edf3b 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ExtensionUpdateInfo.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ExtensionUpdateInfo.java @@ -38,6 +38,9 @@ public enum VersionUpdateType { static VersionUpdateType computeVersionUpdateType(TopExtensionDependency currentDep, TopExtensionDependency recommendedDep) { if (currentDep.isPlatformExtension() && recommendedDep.isPlatformExtension()) { + if (currentDep.isNonRecommendedVersion()) { + return RECOMMEND_PLATFORM_MANAGED; + } return PLATFORM_MANAGED; } if (currentDep.isPlatformExtension()) { @@ -87,6 +90,7 @@ public boolean hasKeyChanged() { } public boolean isSimpleVersionUpdate() { - return VersionUpdateType.UPDATE_VERSION.equals(getVersionUpdateType()); + return VersionUpdateType.UPDATE_VERSION.equals(getVersionUpdateType()) + || VersionUpdateType.RECOMMEND_PLATFORM_MANAGED.equals(getVersionUpdateType()); } } diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdateCommand.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdateCommand.java index f8d252621bb8fc..b7ea74069b4641 100644 --- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdateCommand.java +++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdateCommand.java @@ -10,7 +10,9 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -18,6 +20,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import io.quarkus.bootstrap.resolver.maven.options.BootstrapMavenOptions; import io.quarkus.devtools.messagewriter.MessageWriter; import io.quarkus.devtools.project.BuildTool; import io.quarkus.qute.Qute; @@ -75,9 +78,9 @@ private static void runGradleUpdate(MessageWriter log, Path baseDir, String rewr .collect(Collectors.joining(", "))))); } final String gradleBinary = findGradleBinary(baseDir); - String[] command = new String[] { gradleBinary.toString(), "--console", "plain", "--stacktrace", + List command = List.of(gradleBinary.toString(), "--console", "plain", "--stacktrace", "--init-script", - tempInit.toAbsolutePath().toString(), dryRun ? "rewriteDryRun" : "rewriteRun" }; + tempInit.toAbsolutePath().toString(), dryRun ? "rewriteDryRun" : "rewriteRun"); executeCommand(baseDir, command, log); } catch (QuarkusUpdateException e) { throw e; @@ -96,6 +99,26 @@ private static void runGradleUpdate(MessageWriter log, Path baseDir, String rewr } } + private static String getMavenSettingsArg() { + final String mavenSettings = System.getProperty("maven.settings"); + if (mavenSettings != null) { + return Files.exists(Paths.get(mavenSettings)) ? mavenSettings : null; + } + return BootstrapMavenOptions.newInstance().getOptionValue(BootstrapMavenOptions.ALTERNATE_USER_SETTINGS); + } + + private static void propagateSystemPropertyIfSet(String name, List command) { + if (System.getProperties().containsKey(name)) { + final StringBuilder buf = new StringBuilder(); + buf.append("-D").append(name); + final String value = System.getProperty(name); + if (value != null && !value.isEmpty()) { + buf.append("=").append(value); + } + command.add(buf.toString()); + } + } + private static void runMavenUpdate(MessageWriter log, Path baseDir, String rewritePluginVersion, String recipesGAV, Path recipe, boolean dryRun) { @@ -106,32 +129,51 @@ private static void runMavenUpdate(MessageWriter log, Path baseDir, String rewri executeCommand(baseDir, getMavenProcessSourcesCommand(mvnBinary), log); } - private static String[] getMavenProcessSourcesCommand(String mvnBinary) { - return new String[] { mvnBinary, "process-sources" }; + private static List getMavenProcessSourcesCommand(String mvnBinary) { + List command = new ArrayList<>(); + command.add(mvnBinary); + command.add("process-sources"); + final String mavenSettings = getMavenSettingsArg(); + if (mavenSettings != null) { + command.add("-s"); + command.add(mavenSettings); + } + return command; } - private static String[] getMavenUpdateCommand(String mvnBinary, String rewritePluginVersion, String recipesGAV, Path recipe, + private static List getMavenUpdateCommand(String mvnBinary, String rewritePluginVersion, String recipesGAV, + Path recipe, boolean dryRun) { - return new String[] { mvnBinary, - "-e", + final List command = new ArrayList<>(); + command.add(mvnBinary); + command.add("-e"); + command.add( String.format("%s:%s:%s:%s", MAVEN_REWRITE_PLUGIN_GROUP, MAVEN_REWRITE_PLUGIN_ARTIFACT, rewritePluginVersion, - dryRun ? "dryRun" : "run"), - String.format("-DplainTextMasks=%s", ADDITIONAL_SOURCE_FILES), - String.format("-Drewrite.configLocation=%s", recipe.toAbsolutePath()), - String.format("-Drewrite.recipeArtifactCoordinates=%s", recipesGAV), - String.format("-DactiveRecipes=%s", RECIPE_IO_QUARKUS_OPENREWRITE_QUARKUS), - "-Drewrite.pomCacheEnabled=false" }; + dryRun ? "dryRun" : "run")); + command.add(String.format("-DplainTextMasks=%s", ADDITIONAL_SOURCE_FILES)); + command.add(String.format("-Drewrite.configLocation=%s", recipe.toAbsolutePath())); + command.add(String.format("-Drewrite.recipeArtifactCoordinates=%s", recipesGAV)); + command.add(String.format("-DactiveRecipes=%s", RECIPE_IO_QUARKUS_OPENREWRITE_QUARKUS)); + command.add("-Drewrite.pomCacheEnabled=false"); + final String mavenSettings = getMavenSettingsArg(); + if (mavenSettings != null) { + command.add("-s"); + command.add(mavenSettings); + } + return command; } - private static void executeCommand(Path baseDir, String[] command, MessageWriter log) { + private static void executeCommand(Path baseDir, List command, MessageWriter log) { + final List effectiveCommand = new ArrayList<>(command); + propagateSystemPropertyIfSet("maven.repo.local", effectiveCommand); ProcessBuilder processBuilder = new ProcessBuilder(); log.info(""); log.info(""); log.info(""); log.info(" ------------------------------------------------------------------------"); - log.info("Executing:\n" + String.join(" ", command)); + log.info("Executing:\n" + String.join(" ", effectiveCommand)); log.info(""); - processBuilder.command(command); + processBuilder.command(effectiveCommand); try { Process process = processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE) 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 3eb1cfd5e490a6..cedfb6d0fb0d57 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 @@ -58,10 +58,16 @@ public static FetchResult createRecipe(MessageWriter log, Path target, MavenArti for (ExtensionUpdateInfo versionUpdates : request.projectExtensionsUpdateInfo .getSimpleVersionUpdates()) { - recipe.addOperation(new UpdateDependencyVersionOperation( - versionUpdates.getCurrentDep().getArtifact().getGroupId(), - versionUpdates.getCurrentDep().getArtifact().getArtifactId(), - versionUpdates.getRecommendedDependency().getVersion())); + if (versionUpdates.getVersionUpdateType() + .equals(ExtensionUpdateInfo.VersionUpdateType.RECOMMEND_PLATFORM_MANAGED)) { + // Dropping the version is not supported yet by open-rewrite: https://github.com/openrewrite/rewrite/issues/3546 + } else { + recipe.addOperation(new UpdateDependencyVersionOperation( + versionUpdates.getCurrentDep().getArtifact().getGroupId(), + versionUpdates.getCurrentDep().getArtifact().getArtifactId(), + versionUpdates.getRecommendedDependency().getVersion())); + } + } for (String s : result.getRecipes()) { 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 3a8fabb65fd207..5eb197aaadf5f3 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 @@ -20,6 +20,7 @@ public UpdateDependencyVersionOperation(String groupId, String artifactId, Strin @Override public Map single(BuildTool buildTool) { switch (buildTool) { + case GRADLE_KOTLIN_DSL: case GRADLE: return Map.of("org.openrewrite.gradle.UpgradeDependencyVersion", Map.of( 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 index ffdd9e194d3a23..ff862087923cef 100644 --- 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 @@ -25,6 +25,7 @@ public List> multi(BuildTool buildTool) { Map.of("key", "maven.compiler.target", "newValue", newVersion)), Map.of("org.openrewrite.maven.ChangePropertyValue", Map.of("key", "maven.compiler.release", "newValue", newVersion))); + case GRADLE_KOTLIN_DSL: case GRADLE: return List.of(Map.of( "org.openrewrite.gradle.UpdateJavaCompatibility", 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 4a8cc0f65c2d3f..0c9724809aab10 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 @@ -22,6 +22,7 @@ public Map single(BuildTool buildTool) { return Map.of("org.openrewrite.maven.ChangePropertyValue", Map.of("key", key, "newValue", newValue)); case GRADLE: + case GRADLE_KOTLIN_DSL: return Map.of( "org.openrewrite.gradle.AddProperty", Map.of("key", key, "value", newValue, "overwrite", true)); 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 a621df7d7a07ee..7866b48113e962 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 @@ -18,6 +18,7 @@ public UpgradeGradlePluginOperation(String pluginIdPattern, String newVersion) { @Override public Map single(BuildTool buildTool) { switch (buildTool) { + case GRADLE_KOTLIN_DSL: case GRADLE: return Map.of( "org.openrewrite.gradle.plugins.UpgradePluginVersion",