From dda9fdf131d274bb8f816ee8295b8e31b54f69ae Mon Sep 17 00:00:00 2001 From: Charuka Tharindu Date: Wed, 17 May 2023 10:19:08 +0530 Subject: [PATCH 1/2] Sort the distributions list in pull command --- src/main/java/org/ballerinalang/command/cmd/PullCommand.java | 4 ++++ 1 file changed, 4 insertions(+) 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"); } From c32ef68e913387a1c33a1b8ae5d278076d437af6 Mon Sep 17 00:00:00 2001 From: Charuka Tharindu Date: Wed, 17 May 2023 10:20:22 +0530 Subject: [PATCH 2/2] Add test cases for command --- .../org/ballerinalang/command/PullCommandTest.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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")); } }