Skip to content

Commit

Permalink
channel list output is confusing wildfly-extras#755
Browse files Browse the repository at this point in the history
  • Loading branch information
parsharma committed Oct 23, 2024
1 parent 452e26b commit cbbaca1
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

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;

Expand All @@ -53,6 +56,9 @@ public static class ChannelListCommand extends AbstractCommand {
@CommandLine.Option(names = CliConstants.DIR)
Optional<Path> directory;

@CommandLine.Option(names = CliConstants.FULL)
boolean fullList;

public ChannelListCommand(CliConsole console, ActionFactory actionFactory) {
super(console, actionFactory);
}
Expand All @@ -68,12 +74,36 @@ 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(String.format("%s %s@%s",
channel.getName(),
channel.getNoStreamStrategy(),
String.join(",", channel.getRepositories().stream()
.map(Repository::getId)
.collect(Collectors.toList()))
));
}
}
}

return ReturnCodes.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private Commands() {
public static final String DIR = "--dir";
public static final String FEATURE_PACK_REFERENCE = "<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";
Expand Down
1 change: 1 addition & 0 deletions prospero-cli/src/main/resources/UsageMessages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit cbbaca1

Please sign in to comment.