diff --git a/src/main/java/org/ballerinalang/command/cmd/PullCommand.java b/src/main/java/org/ballerinalang/command/cmd/PullCommand.java index dff3e446..7f4bb3e6 100644 --- a/src/main/java/org/ballerinalang/command/cmd/PullCommand.java +++ b/src/main/java/org/ballerinalang/command/cmd/PullCommand.java @@ -24,6 +24,8 @@ import picocli.CommandLine; import java.io.PrintStream; +import java.util.Collections; +import java.util.Comparator; import java.util.List; /** @@ -76,6 +78,8 @@ public void execute() { // Assume channels are sorted descending Channel latestChanel = channels.get(0); List distributions = latestChanel.getDistributions(); + distributions.sort(Comparator.comparing(Distribution::getVersion)); + Collections.reverse(distributions); distribution = ToolUtil.getLatest(distributions.get(0).getVersion(), "patch"); } diff --git a/src/test/java/org/ballerinalang/command/PullCommandTest.java b/src/test/java/org/ballerinalang/command/PullCommandTest.java index 3c7c588d..7a1b686b 100644 --- a/src/test/java/org/ballerinalang/command/PullCommandTest.java +++ b/src/test/java/org/ballerinalang/command/PullCommandTest.java @@ -28,6 +28,7 @@ * @since 2.0.0 */ public class PullCommandTest extends CommandTest { + String swanLakeLatestVersion = System.getProperty("swan-lake-latest-version"); @Test public void pullCommandwithoutArgsTest() { @@ -79,14 +80,18 @@ public void pullDistributionTest() { Assert.assertTrue(outContent.toString().contains("Fetching the 'slp1' distribution from the remote server")); Assert.assertTrue(outContent.toString().contains("Fetching the dependencies for 'slp1' from the remote server")); Assert.assertTrue(outContent.toString().contains("successfully set as the active distribution")); + } - PullCommand pullCmd = new PullCommand(testStream); - new CommandLine(pullCmd).parse("latest"); - pullCmd.execute(); + @Test + public void pullLatestDistributionTest() { + PullCommand pullCommand = new PullCommand(testStream); + new CommandLine(pullCommand).parse("latest"); + pullCommand.execute(); Assert.assertTrue(outContent.toString().contains("Fetching the latest distribution from the remote server")); + Assert.assertTrue(outContent.toString().contains("Fetching the '" + swanLakeLatestVersion + "' distribution from the remote server")); Assert.assertTrue(outContent.toString().contains("successfully set as the active distribution")); pullCommand.execute(); - Assert.assertTrue(outContent.toString().contains("is already available locally")); + Assert.assertTrue(outContent.toString().contains("is already the active distribution")); } }