From 8639153b4b497f9f89ac6c88c8138aaec2bc2a9d Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Fri, 1 Sep 2023 17:18:10 +0200 Subject: [PATCH] Simplify extensions update info for easier consumption --- .../cli/MavenProjectInfoAndUpdateTest.java | 15 ++-- .../handlers/ProjectInfoCommandHandler.java | 2 +- .../handlers/UpdateProjectCommandHandler.java | 76 +++++++++---------- .../project/update/ExtensionUpdateInfo.java | 63 +++++++++++++++ .../update/ProjectExtensionsUpdateInfo.java | 62 +++++---------- .../project/update/ProjectUpdateInfos.java | 42 +--------- .../update/rewrite/QuarkusUpdateCommand.java | 74 ++++++++++++++---- .../update/rewrite/QuarkusUpdates.java | 27 +++---- .../UpdateDependencyVersionOperation.java | 1 + .../UpdateJavaVersionOperation.java | 1 + .../operations/UpdatePropertyOperation.java | 1 + .../UpgradeGradlePluginOperation.java | 1 + 12 files changed, 205 insertions(+), 160 deletions(-) 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 53b96e8b33db0..a3c38df41be66 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 e05ade2a0acc4..cdd44b0d0569f 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/commands/handlers/UpdateProjectCommandHandler.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/commands/handlers/UpdateProjectCommandHandler.java index 3a0895b31e170..097c899239694 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 @@ -8,7 +8,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Collections; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -40,6 +39,7 @@ public class UpdateProjectCommandHandler implements QuarkusCommandHandler { public static final String ADD = "Add:"; public static final String REMOVE = "Remove:"; public static final String UPDATE = "Update:"; + public static final String ITEM_FORMAT = "%-7s %s"; @Override @@ -179,7 +179,7 @@ private static void logUpdates(QuarkusProject project, ProjectState currentState log.info(""); } - if (extensionsUpdateInfo.isUpToDate() && !platformUpdateInfo.isPlatformUpdatesAvailable()) { + if (extensionsUpdateInfo.shouldUpdateExtensions() && !platformUpdateInfo.isPlatformUpdatesAvailable()) { log.info("The project is up-to-date"); return; } @@ -194,54 +194,46 @@ private static void logUpdates(QuarkusProject project, ProjectState currentState for (PlatformInfo platform : platformUpdateInfo.getPlatformImports().values()) { final String provider = platform.getRecommendedProviderKey(); - if (!extensionsUpdateInfo.getVersionedManagedExtensions().containsKey(provider) - && !extensionsUpdateInfo.getRemovedExtensions().containsKey(provider) - && !extensionsUpdateInfo.getAddedExtensions().containsKey(provider)) { + if (!extensionsUpdateInfo.containsProvider(provider)) { continue; } log.info("Extensions from " + platform.getRecommendedProviderKey() + ":"); - for (ExtensionUpdateInfo e : extensionsUpdateInfo.getVersionedManagedExtensions().getOrDefault(provider, - Collections.emptyList())) { - final StringBuilder sb = new StringBuilder(); - sb.append(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, - UpdateProjectCommandHandler.UPDATE, e.getCurrentDep().getArtifact().toCompactCoords())); - sb.append(" -> remove version (managed)"); - log.info(sb.toString()); - } - for (ExtensionUpdateInfo i : extensionsUpdateInfo.getAddedExtensions().getOrDefault(provider, - Collections.emptyList())) { - log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, UpdateProjectCommandHandler.ADD, - i.getRecommendedDependency().getKey().toGacString())); - } - for (ExtensionUpdateInfo i : extensionsUpdateInfo.getRemovedExtensions().getOrDefault(provider, + + for (ExtensionUpdateInfo e : extensionsUpdateInfo.extensionsByProvider().getOrDefault(provider, Collections.emptyList())) { - log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, UpdateProjectCommandHandler.REMOVE, - i.getCurrentDep().getKey().toGacString())); - } - log.info(""); - } - if (!extensionsUpdateInfo.getNonPlatformExtensions().isEmpty()) { - for (Map.Entry> provider : extensionsUpdateInfo.getNonPlatformExtensions() - .entrySet()) { - log.info("Extensions from " + provider.getKey() + ":"); - for (ExtensionUpdateInfo info : provider.getValue()) { - if (info.getCurrentDep().isPlatformExtension()) { - log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, - UpdateProjectCommandHandler.ADD, - info.getRecommendedDependency().getArtifact().toCompactCoords())); - } else if (info.getRecommendedDependency().isPlatformExtension()) { - log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, - UpdateProjectCommandHandler.REMOVE, info.getCurrentDep().getArtifact().toCompactCoords())); - } else { - log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, - UpdateProjectCommandHandler.UPDATE, - info.getCurrentDep().getArtifact().toCompactCoords() + " -> " - + info.getRecommendedDependency().getVersion())); + final ExtensionUpdateInfo.VersionUpdateType versionUpdateType = e.getVersionUpdateType(); + + if (e.hasKeyChanged()) { + log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, + UpdateProjectCommandHandler.UPDATE, + e.getCurrentDep().getArtifact().toCompactCoords() + " -> " + + e.getRecommendedDependency().getArtifact().toCompactCoords())); + } else { + switch (versionUpdateType) { + case PLATFORM_MANAGED: + // The extension update is done when updating the platform + break; + case RECOMMEND_PLATFORM_MANAGED: + log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, + UpdateProjectCommandHandler.UPDATE, e.getCurrentDep().getArtifact().toCompactCoords() + + " -> drop version (managed by platform)")); + break; + case ADD_VERSION: + log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, UpdateProjectCommandHandler.UPDATE, + e.getRecommendedDependency().getArtifact().toCompactCoords() + + " -> add version (managed by platform)")); + break; + case UPDATE_VERSION: + log.info(String.format(UpdateProjectCommandHandler.ITEM_FORMAT, + UpdateProjectCommandHandler.UPDATE, + e.getCurrentDep().getArtifact().toCompactCoords() + " -> " + + e.getRecommendedDependency().getVersion())); + break; } } - log.info(""); } + log.info(""); } } 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 5d2b530460937..82ae78192edf3 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 @@ -1,5 +1,8 @@ package io.quarkus.devtools.project.update; +import static io.quarkus.devtools.project.update.ExtensionUpdateInfo.VersionUpdateType.PLATFORM_MANAGED; +import static io.quarkus.devtools.project.update.ExtensionUpdateInfo.VersionUpdateType.computeVersionUpdateType; + import io.quarkus.devtools.project.state.TopExtensionDependency; import io.quarkus.registry.catalog.Extension; @@ -7,12 +10,59 @@ public final class ExtensionUpdateInfo { private final TopExtensionDependency currentDep; private final Extension recommendedMetadata; private final TopExtensionDependency recommendedDep; + private final VersionUpdateType versionUpdateType; + + public enum VersionUpdateType { + + /** + * This extension will be updated as part of the platform update. + */ + PLATFORM_MANAGED, + + /** + * This extension version is set, it is recommended to let the version be managed by the platform by dropping the + * .... + */ + RECOMMEND_PLATFORM_MANAGED, + + /** + * This extension is not part of the platform anymore and the ... should be added. + */ + ADD_VERSION, + + /** + * There is a more recent version of this non platform extension. + */ + UPDATE_VERSION; + + 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()) { + return VersionUpdateType.ADD_VERSION; + } + if (recommendedDep.isPlatformExtension()) { + return VersionUpdateType.RECOMMEND_PLATFORM_MANAGED; + } + return VersionUpdateType.UPDATE_VERSION; + } + } public ExtensionUpdateInfo(TopExtensionDependency currentDep, Extension recommendedMetadata, TopExtensionDependency recommendedDep) { this.currentDep = currentDep; this.recommendedMetadata = recommendedMetadata; this.recommendedDep = recommendedDep; + this.versionUpdateType = computeVersionUpdateType(currentDep, recommendedDep); + } + + public VersionUpdateType getVersionUpdateType() { + return versionUpdateType; } public TopExtensionDependency getCurrentDep() { @@ -30,4 +80,17 @@ public TopExtensionDependency getRecommendedDependency() { public boolean isUpdateRecommended() { return recommendedDep != currentDep; } + + public boolean shouldUpdateExtension() { + return hasKeyChanged() || !PLATFORM_MANAGED.equals(versionUpdateType); + } + + public boolean hasKeyChanged() { + return !currentDep.getKey().equals(recommendedDep.getKey()); + } + + public boolean isSimpleVersionUpdate() { + 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/ProjectExtensionsUpdateInfo.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/ProjectExtensionsUpdateInfo.java index b25631f6642d9..77ab4634aaaf3 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 @@ -5,66 +5,44 @@ import java.util.Map; import java.util.Optional; import java.util.OptionalInt; +import java.util.stream.Collectors; import java.util.stream.Stream; 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> nonPlatformExtensions; + private final Map> extensionsByProvider; - 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 ProjectExtensionsUpdateInfo(Map> extensionsByProvider) { + this.extensionsByProvider = extensionsByProvider; } - public Map> getManagedExtensions() { - return managedExtensions; + public Map> extensionsByProvider() { + return extensionsByProvider; } - public Map> getVersionedManagedExtensions() { - return versionedManagedExtensions; - } - - public Map> getRemovedExtensions() { - return removedExtensions; - } - - public Map> getAddedExtensions() { - return addedExtensions; - } - - public Map> getNonPlatformExtensions() { - return nonPlatformExtensions; + public boolean containsProvider(String provider) { + return extensionsByProvider.containsKey(provider); } public OptionalInt getMinJavaVersion() { - return Stream.of(getManagedExtensions().values(), - getVersionedManagedExtensions().values(), - getNonPlatformExtensions().values(), - getAddedExtensions().values()) - .flatMap(Collection::stream) - .flatMap(Collection::stream) + return streamExtensions() .mapToInt(e -> Optional.ofNullable(ExtensionProcessor.getMinimumJavaVersion(e.getRecommendedMetadata())) .orElse(JavaVersion.DEFAULT_JAVA_VERSION)) .max(); } - public boolean isUpToDate() { - return versionedManagedExtensions.isEmpty() - && removedExtensions.isEmpty() - && addedExtensions.isEmpty() - && nonPlatformExtensions.isEmpty(); + private Stream streamExtensions() { + return extensionsByProvider.values().stream() + .flatMap(Collection::stream); + } + + public List getSimpleVersionUpdates() { + return streamExtensions().filter(ExtensionUpdateInfo::isSimpleVersionUpdate).collect(Collectors.toList()); + } + + public boolean shouldUpdateExtensions() { + return streamExtensions().anyMatch(ExtensionUpdateInfo::shouldUpdateExtension); } } 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 bb3d978504fdf..02406cc8e084e 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,50 +43,16 @@ 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> nonPlatformExtensionUpdates = new LinkedHashMap<>(); + final Map> extensions = new LinkedHashMap<>(0); for (ExtensionUpdateInfoBuilder infoBuilder : extensionInfo.values()) { final ExtensionUpdateInfo info = infoBuilder.build(); if (!info.isUpdateRecommended()) { continue; } - if (!info.getCurrentDep().getKey().equals(info.getRecommendedDependency().getKey())) { - if (info.getCurrentDep().isPlatformExtension()) { - removedExtensions.computeIfAbsent(info.getCurrentDep().getProviderKey(), k -> new ArrayList<>()) - .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(new ExtensionUpdateInfo(null, info.getRecommendedMetadata(), info.getRecommendedDependency())); - } else { - nonPlatformExtensionUpdates - .computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()) - .add(info); - } - } else if (info.getRecommendedDependency().isPlatformExtension()) { - if (info.getCurrentDep().isNonRecommendedVersion()) { - 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); - } + extensions.computeIfAbsent(info.getRecommendedDependency().getProviderKey(), k -> new ArrayList<>()) + .add(info); } - return new ProjectExtensionsUpdateInfo(managedExtensions, versionedManagedExtensions, removedExtensions, - addedExtensions, - nonPlatformExtensionUpdates); + return new ProjectExtensionsUpdateInfo(extensions); } public static ProjectPlatformUpdateInfo resolvePlatformUpdateInfo(ProjectState currentState, 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 f8d252621bb8f..b7ea74069b464 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 14d3df0caaf65..770bf8bb92c68 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,7 +2,6 @@ import java.io.IOException; import java.nio.file.Path; -import java.util.List; import java.util.Optional; import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver; @@ -53,22 +52,18 @@ public static FetchResult createRecipe(MessageWriter log, Path target, MavenArti break; } - for (List nonPlatformExtensionsUpdates : request.projectExtensionsUpdateInfo - .getNonPlatformExtensions().values()) { - for (ExtensionUpdateInfo nonPlatformExtensionsUpdate : nonPlatformExtensionsUpdates) { - if (nonPlatformExtensionsUpdate.getCurrentDep().isPlatformExtension()) { - // add, my understanding is that we should define the version? As a dependency, as a managed one? - // not completely sure how to make it work for a multi-module project? - } else if (nonPlatformExtensionsUpdate.getRecommendedDependency().isPlatformExtension()) { - // remove, decide what to do here, should we remove the version given it is now managed? Will OpenRewrite support that? - // not completely sure how to make it work for a multi-module project? - } else { - recipe.addOperation(new UpdateDependencyVersionOperation( - nonPlatformExtensionsUpdate.getCurrentDep().getArtifact().getGroupId(), - nonPlatformExtensionsUpdate.getCurrentDep().getArtifact().getArtifactId(), - nonPlatformExtensionsUpdate.getRecommendedDependency().getVersion())); - } + for (ExtensionUpdateInfo versionUpdates : request.projectExtensionsUpdateInfo + .getSimpleVersionUpdates()) { + 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 3a8fabb65fd20..5eb197aaadf5f 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 ffdd9e194d3a2..ff862087923ce 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 4a8cc0f65c2d3..0c9724809aab1 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 a621df7d7a07e..7866b48113e96 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",