diff --git a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/UpdateCommand.java b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/UpdateCommand.java index d1cdc898e..281c4f942 100644 --- a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/UpdateCommand.java +++ b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/UpdateCommand.java @@ -23,12 +23,15 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.eclipse.aether.artifact.Artifact; import org.jboss.galleon.ProvisioningException; import org.jboss.galleon.diff.FsDiff; import org.jboss.galleon.diff.FsEntry; @@ -60,6 +63,7 @@ import org.wildfly.prospero.api.TemporaryFilesManager; import org.wildfly.prospero.galleon.FeaturePackLocationParser; import org.wildfly.prospero.galleon.GalleonUtils; +import org.wildfly.prospero.metadata.ManifestVersionRecord; import org.wildfly.prospero.metadata.ProsperoMetadataUtils; import org.wildfly.prospero.model.InstallationProfile; import org.wildfly.prospero.updates.UpdateSet; @@ -117,7 +121,6 @@ public Integer call() throws Exception { log.tracef("Perform full update"); console.println(CliMessages.MESSAGES.updateHeader(installationDir)); - try (UpdateAction updateAction = actionFactory.update(installationDir, mavenOptions, console, repositories)) { performUpdate(updateAction, yes, console, installationDir); } @@ -133,6 +136,11 @@ private boolean performUpdate(UpdateAction updateAction, boolean yes, CliConsole Path targetDir = null; try { targetDir = Files.createTempDirectory("update-candidate"); + InstallationMetadata installationMetadata = InstallationMetadata.loadInstallation(installDir); + List mavenManifests = installationMetadata.getManifestVersions().get().getMavenManifests(); + final List manifestUpdates = updateAction.findCurrentChannelSessionManifests(); + compareManifests(mavenManifests,manifestUpdates); + if (buildUpdate(updateAction, targetDir, yes, console, () -> console.confirmUpdates())) { console.println(""); console.buildUpdatesComplete(); @@ -422,17 +430,17 @@ private FeaturePackLocation getFpl(InstallationProfile knownFeaturePack, String public UpdateCommand(CliConsole console, ActionFactory actionFactory) { super(console, actionFactory, CliConstants.Commands.UPDATE, List.of( - new UpdateCommand.PrepareCommand(console, actionFactory), - new UpdateCommand.ApplyCommand(console, actionFactory), - new UpdateCommand.PerformCommand(console, actionFactory), - new UpdateCommand.ListCommand(console, actionFactory), + new PrepareCommand(console, actionFactory), + new ApplyCommand(console, actionFactory), + new PerformCommand(console, actionFactory), + new ListCommand(console, actionFactory), new SubscribeCommand(console, actionFactory)) ); + } private static boolean buildUpdate(UpdateAction updateAction, Path updateDirectory, boolean yes, CliConsole console, Supplier confirmation) throws OperationException, ProvisioningException { final UpdateSet updateSet = updateAction.findUpdates(); - console.updatesFound(updateSet.getArtifactUpdates()); if (updateSet.isEmpty()) { return false; @@ -471,4 +479,49 @@ public static Path detectProsperoInstallationPath() throws ArgumentParsingExcept return Paths.get(modulePath).toAbsolutePath().getParent(); } + + public static void compareManifests(List mavenManifests, List manifestUpdates ) { + + List intersectingManifests = new ArrayList<>(); + + // Find intersecting manifests (those that are present in both mavenManifests and manifestUpdates) + for (ManifestVersionRecord.MavenManifest installedManifest : mavenManifests) { + for (Artifact update : manifestUpdates) { + if (update.getGroupId().equals(installedManifest.getGroupId()) && + update.getArtifactId().equals(installedManifest.getArtifactId())) { + intersectingManifests.add(installedManifest); // Add to intersection list + break; + } + } + } + + // For each intersecting manifest, compare the version + for (ManifestVersionRecord.MavenManifest installedManifest : intersectingManifests) { + Artifact updateArtifact = null; + + // Find the corresponding update artifact for the installedManifest + for (Artifact manifestUpdate : manifestUpdates) { + if (manifestUpdate.getGroupId().equals(installedManifest.getGroupId()) && + manifestUpdate.getArtifactId().equals(installedManifest.getArtifactId())) { + updateArtifact = manifestUpdate; + break; + } + } + + if (updateArtifact != null) { + // Compare versions + DefaultArtifactVersion installedVersion = new DefaultArtifactVersion(installedManifest.getVersion()); + DefaultArtifactVersion availableVersion = new DefaultArtifactVersion(updateArtifact.getVersion()); + + if (installedVersion.compareTo(availableVersion) < 0) { + System.out.println("Upgrade available for " + installedManifest.getArtifactId() + ": " + installedVersion + " -> " + availableVersion); + } else if (installedVersion.compareTo(availableVersion) > 0) { + System.out.println("Downgrade detected for " + installedManifest.getArtifactId() + ": " + installedVersion + " -> " + availableVersion); + } else { + System.out.println(installedManifest.getArtifactId() + " is up to date."); + } + } + } + } + } diff --git a/prospero-common/src/main/java/org/wildfly/prospero/actions/UpdateAction.java b/prospero-common/src/main/java/org/wildfly/prospero/actions/UpdateAction.java index 7b1e5c4c1..e752c2201 100644 --- a/prospero-common/src/main/java/org/wildfly/prospero/actions/UpdateAction.java +++ b/prospero-common/src/main/java/org/wildfly/prospero/actions/UpdateAction.java @@ -20,10 +20,13 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.apache.commons.io.FileUtils; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; import org.jboss.galleon.util.PathsUtils; import org.wildfly.channel.Channel; import org.wildfly.channel.Repository; @@ -35,6 +38,7 @@ import org.wildfly.prospero.api.InstallationMetadata; import org.wildfly.prospero.api.exceptions.OperationException; import org.wildfly.prospero.galleon.GalleonEnvironment; +import org.wildfly.prospero.metadata.ManifestVersionRecord; import org.wildfly.prospero.model.ProsperoConfig; import org.wildfly.prospero.updates.UpdateFinder; import org.wildfly.prospero.updates.UpdateSet; @@ -171,4 +175,14 @@ private ProsperoConfig addTemporaryRepositories(List repositories) { return new ProsperoConfig(channels, prosperoConfig.getMavenOptions()); } + + public List findCurrentChannelSessionManifests() { + List manifestArtifacts = new ArrayList<>(); + List mavenManifests = metadata.getManifestVersions().get().getMavenManifests(); + for (ManifestVersionRecord.MavenManifest mavenManifest : mavenManifests) { + manifestArtifacts.add(new DefaultArtifact(mavenManifest.getGroupId(), "eap-8.0", "yaml", "1.0.1.GA-redhat-00003")); + } + return manifestArtifacts; + } + }