Skip to content

Commit

Permalink
Simplify extensions update info for easier consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Sep 14, 2023
1 parent 3bfd85a commit 8639153
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 160 deletions.
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 Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, List<ExtensionUpdateInfo>> managedExtensions;
final Map<String, List<ExtensionUpdateInfo>> versionedManagedExtensions;
final Map<String, List<ExtensionUpdateInfo>> removedExtensions;
final Map<String, List<ExtensionUpdateInfo>> addedExtensions;
final Map<String, List<ExtensionUpdateInfo>> nonPlatformExtensions;
private final Map<String, List<ExtensionUpdateInfo>> extensionsByProvider;

public ProjectExtensionsUpdateInfo(Map<String, List<ExtensionUpdateInfo>> managedExtensions,
Map<String, List<ExtensionUpdateInfo>> versionedManagedExtensions,
Map<String, List<ExtensionUpdateInfo>> removedExtensions,
Map<String, List<ExtensionUpdateInfo>> addedExtensions,
Map<String, List<ExtensionUpdateInfo>> nonPlatformExtensionUpdate) {
this.managedExtensions = managedExtensions;
this.versionedManagedExtensions = versionedManagedExtensions;
this.removedExtensions = removedExtensions;
this.addedExtensions = addedExtensions;
this.nonPlatformExtensions = nonPlatformExtensionUpdate;
public ProjectExtensionsUpdateInfo(Map<String, List<ExtensionUpdateInfo>> extensionsByProvider) {
this.extensionsByProvider = extensionsByProvider;
}

public Map<String, List<ExtensionUpdateInfo>> getManagedExtensions() {
return managedExtensions;
public Map<String, List<ExtensionUpdateInfo>> extensionsByProvider() {
return extensionsByProvider;
}

public Map<String, List<ExtensionUpdateInfo>> getVersionedManagedExtensions() {
return versionedManagedExtensions;
}

public Map<String, List<ExtensionUpdateInfo>> getRemovedExtensions() {
return removedExtensions;
}

public Map<String, List<ExtensionUpdateInfo>> getAddedExtensions() {
return addedExtensions;
}

public Map<String, List<ExtensionUpdateInfo>> 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<ExtensionUpdateInfo> streamExtensions() {
return extensionsByProvider.values().stream()
.flatMap(Collection::stream);
}

public List<ExtensionUpdateInfo> getSimpleVersionUpdates() {
return streamExtensions().filter(ExtensionUpdateInfo::isSimpleVersionUpdate).collect(Collectors.toList());
}

public boolean shouldUpdateExtensions() {
return streamExtensions().anyMatch(ExtensionUpdateInfo::shouldUpdateExtension);
}
}
Loading

0 comments on commit 8639153

Please sign in to comment.