From d39f942190f60595b191b11cf76e8dc82abd6bf8 Mon Sep 17 00:00:00 2001 From: Parul Sharma Date: Wed, 16 Oct 2024 13:52:29 +0530 Subject: [PATCH] channel list output is confusing #755 --- .../prospero/cli/commands/ChannelCommand.java | 38 ++++++++++++++++--- .../prospero/cli/commands/CliConstants.java | 1 + .../main/resources/UsageMessages.properties | 1 + .../cli/commands/ChannelCommandTest.java | 25 +++++++++++- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/ChannelCommand.java b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/ChannelCommand.java index 6d2a00c11..53fead114 100644 --- a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/ChannelCommand.java +++ b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/ChannelCommand.java @@ -22,12 +22,14 @@ import java.util.Optional; import org.wildfly.channel.Channel; +import org.wildfly.channel.ChannelManifestCoordinate; +import org.wildfly.channel.ChannelMapper; +import org.wildfly.channel.Repository; import org.wildfly.prospero.actions.MetadataAction; import org.wildfly.prospero.cli.ActionFactory; import org.wildfly.prospero.cli.CliConsole; import org.wildfly.prospero.cli.CliMessages; import org.wildfly.prospero.cli.ReturnCodes; -import org.wildfly.prospero.cli.printers.ChannelPrinter; import org.wildfly.prospero.metadata.ManifestVersionRecord; import picocli.CommandLine; @@ -53,6 +55,9 @@ public static class ChannelListCommand extends AbstractCommand { @CommandLine.Option(names = CliConstants.DIR) Optional directory; + @CommandLine.Option(names = CliConstants.FULL) + boolean fullList; + public ChannelListCommand(CliConsole console, ActionFactory actionFactory) { super(console, actionFactory); } @@ -68,12 +73,33 @@ public Integer call() throws Exception { channels = metadataAction.getChannels(); } - final ChannelPrinter channelPrinter = new ChannelPrinter(console); - console.println("-------"); for (Channel channel : channels) { - channelPrinter.print(channel); - console.println("-------"); - } + if (fullList) { + console.println(ChannelMapper.toYaml(channels)); + } else { + ChannelManifestCoordinate coordinate = channel.getManifestCoordinate(); + if (coordinate != null) { + // Full Maven GAV + if (coordinate.getVersion() != null && !coordinate.getVersion().isEmpty()) { + console.println(channel.getName() + " " + coordinate.getGroupId() + ":" + coordinate.getArtifactId() + ":" + coordinate.getVersion() + "\n"); + } + // GA only (no version) + else if (coordinate.getGroupId() != null && coordinate.getArtifactId() != null) { + console.println(channel.getName() + " " + coordinate.getGroupId() + ":" + coordinate.getArtifactId() + "\n"); + } + // Manifest URL + else if (coordinate.getUrl() != null){ + console.println(channel.getName() + " " + coordinate.getUrl() + "\n"); + } + } else { + // No manifest coordinate, print no-stream-strategy and repository ids + console.println(channel.getName() + " no-stream-strategy: " + channel.getNoStreamStrategy()); + for (Repository repo : channel.getRepositories()) { + console.println("Repository ID: " + repo.getId()); + } + } + } + } return ReturnCodes.SUCCESS; } diff --git a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/CliConstants.java b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/CliConstants.java index 67baaaf89..a17d91f8a 100644 --- a/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/CliConstants.java +++ b/prospero-cli/src/main/java/org/wildfly/prospero/cli/commands/CliConstants.java @@ -75,6 +75,7 @@ private Commands() { public static final String DIR = "--dir"; public static final String FEATURE_PACK_REFERENCE = ""; public static final String FPL = "--fpl"; + public static final String FULL = "--full"; public static final String H = "-h"; public static final String HELP = "--help"; public static final String LAYERS = "--layers"; diff --git a/prospero-cli/src/main/resources/UsageMessages.properties b/prospero-cli/src/main/resources/UsageMessages.properties index 8e4cd917b..8ffda9df9 100644 --- a/prospero-cli/src/main/resources/UsageMessages.properties +++ b/prospero-cli/src/main/resources/UsageMessages.properties @@ -166,6 +166,7 @@ ${prospero.dist.name}.help = Displays the help information for the command. verbose = Prints additional information if the command fails. ${prospero.dist.name}.verbose = Prints additional information if the command fails. debug = Prints debug messages. +full = Display the detailed list of all available channels ${prospero.dist.name}.debug = Prints debug messages. local-cache = Path to the local Maven repository cache. It overrides the default Maven repository at ~/.m2/repository. no-resolve-local-cache = Perform the operation without resolving or installing artifacts in the local maven cache. diff --git a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/ChannelCommandTest.java b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/ChannelCommandTest.java index 2d7c32390..65af87768 100644 --- a/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/ChannelCommandTest.java +++ b/prospero-cli/src/test/java/org/wildfly/prospero/cli/commands/ChannelCommandTest.java @@ -18,6 +18,7 @@ package org.wildfly.prospero.cli.commands; import java.io.File; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Files; @@ -34,10 +35,11 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.wildfly.channel.Channel; -import org.wildfly.channel.ChannelManifest; import org.wildfly.channel.ChannelManifestCoordinate; import org.wildfly.channel.MavenCoordinate; import org.wildfly.channel.Repository; +import org.wildfly.channel.ChannelManifest; +import org.wildfly.channel.ChannelMapper; import org.wildfly.prospero.api.InstallationMetadata; import org.wildfly.prospero.api.exceptions.MetadataException; import org.wildfly.prospero.cli.AbstractConsoleTest; @@ -191,9 +193,28 @@ public void testList() { int exitCode = commandLine.execute(CliConstants.Commands.CHANNEL, CliConstants.Commands.LIST, CliConstants.DIR, dir.toString()); Assert.assertEquals(ReturnCodes.SUCCESS, exitCode); - Assert.assertEquals(3, getStandardOutput().lines().filter(l->l.contains("manifest")).count()); + assertThat(getStandardOutput().lines() + .filter(line -> line.matches(".*\\S+ \\S+:\\S+(?::\\S+)?"))) + .containsExactlyInAnyOrder( + "test1 g:a", + "test2 g:a:v", + "test3 file:/a:b" + ); + } + + @Test + public void testFullList() throws MetadataException, IOException { + // Execute the command + int exitCode = commandLine.execute(CliConstants.Commands.CHANNEL, CliConstants.Commands.LIST, CliConstants.FULL, + CliConstants.DIR, dir.toString()); + InstallationMetadata installationMetadata = InstallationMetadata.loadInstallation(dir); + + Assert.assertEquals(ReturnCodes.SUCCESS, exitCode); + assertThat(getStandardOutput()).contains(ChannelMapper.toYaml(installationMetadata.getProsperoConfig().getChannels())); + } + @Test public void testAddDuplicate() { int exitCode = commandLine.execute(CliConstants.Commands.CHANNEL, CliConstants.Commands.ADD,