Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic to load yaml recipes based on the extension #35910

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +31,7 @@
import io.quarkus.devtools.project.update.rewrite.QuarkusUpdateCommand;
import io.quarkus.devtools.project.update.rewrite.QuarkusUpdates;
import io.quarkus.devtools.project.update.rewrite.QuarkusUpdatesRepository;
import io.quarkus.devtools.project.update.rewrite.QuarkusUpdatesRepository.FetchResult;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.platform.tools.ToolsConstants;
import io.quarkus.registry.catalog.ExtensionCatalog;
Expand All @@ -40,6 +40,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
Expand All @@ -62,14 +63,16 @@ 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();
final ProjectState recommendedState = resolveRecommendedState(currentState, targetCatalog, invocation.log());
final ProjectState recommendedState = resolveRecommendedState(currentState, targetCatalog,
invocation.log());
final ProjectPlatformUpdateInfo platformUpdateInfo = resolvePlatformUpdateInfo(currentState,
recommendedState);
final ProjectExtensionsUpdateInfo extensionsUpdateInfo = ProjectUpdateInfos.resolveExtensionsUpdateInfo(
currentState,
recommendedState);

logUpdates(invocation.getQuarkusProject(), currentState, recommendedState, platformUpdateInfo, extensionsUpdateInfo,
logUpdates(invocation.getQuarkusProject(), currentState, recommendedState, platformUpdateInfo,
extensionsUpdateInfo,
false, perModule,
quarkusProject.log());
final boolean noRewrite = invocation.getValue(UpdateProject.NO_REWRITE, false);
Expand All @@ -95,17 +98,17 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
Path recipe = null;
try {
recipe = Files.createTempFile("quarkus-project-recipe-", ".yaml");
final String updateRecipesVersion = invocation.getValue(UpdateProject.REWRITE_UPDATE_RECIPES_VERSION,
final String updateRecipesVersion = invocation.getValue(
UpdateProject.REWRITE_UPDATE_RECIPES_VERSION,
QuarkusUpdatesRepository.DEFAULT_UPDATE_RECIPES_VERSION);
final QuarkusUpdatesRepository.FetchResult fetchResult = QuarkusUpdates.createRecipe(invocation.log(),
final 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,

String rewritePluginVersion = invocation.getValue(UpdateProject.REWRITE_PLUGIN_VERSION,
fetchResult.getRewritePluginVersion());
final boolean rewriteDryRun = invocation.getValue(UpdateProject.REWRITE_DRY_RUN, false);
invocation.log().warn(
"The update feature does not yet handle updates of the extension versions. If needed, update your extensions manually.");
boolean rewriteDryRun = invocation.getValue(UpdateProject.REWRITE_DRY_RUN, false);
QuarkusUpdateCommand.handle(
invocation.log(),
buildTool,
Expand All @@ -114,6 +117,7 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
fetchResult.getRecipesGAV(),
recipe,
rewriteDryRun);

} catch (IOException e) {
throw new QuarkusCommandException("Error while generating the project update script", e);
}
Expand Down Expand Up @@ -179,7 +183,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;
}
Expand All @@ -194,54 +198,48 @@ 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<String, List<ExtensionUpdateInfo>> 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("");
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,68 @@
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;

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
* <version>...</version>.
*/
RECOMMEND_PLATFORM_MANAGED,

/**
* This extension is not part of the platform anymore and the <version>...</version> 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() {
Expand All @@ -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());
}
}
Loading
Loading