Skip to content

Commit

Permalink
Merge pull request #294 from udda1996/fix-latest
Browse files Browse the repository at this point in the history
Sort the distribution list based on version in pull latest command
  • Loading branch information
udda1996 authored May 17, 2023
2 parents ae2e017 + c32ef68 commit e6fd13e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/main/java/org/ballerinalang/command/cmd/PullCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import picocli.CommandLine;

import java.io.PrintStream;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
Expand Down Expand Up @@ -76,6 +78,8 @@ public void execute() {
// Assume channels are sorted descending
Channel latestChanel = channels.get(0);
List<Distribution> distributions = latestChanel.getDistributions();
distributions.sort(Comparator.comparing(Distribution::getVersion));
Collections.reverse(distributions);
distribution = ToolUtil.getLatest(distributions.get(0).getVersion(), "patch");
}

Expand Down
13 changes: 9 additions & 4 deletions src/test/java/org/ballerinalang/command/PullCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"));
}
}

0 comments on commit e6fd13e

Please sign in to comment.