Skip to content

Commit

Permalink
Merge pull request #352 from udda1996/sort-1-2-x
Browse files Browse the repository at this point in the history
Include sort issue
  • Loading branch information
keizer619 authored Aug 22, 2024
2 parents dd5dd76 + 1323339 commit 10a0aca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/main/java/org/ballerinalang/command/cmd/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ private static void listDistributions(PrintStream outStream, boolean allFlag, bo
JSONObject channelJson = new JSONObject();
JSONArray releases = new JSONArray();
channelJson.put("name", channel.getName());
List<Distribution> channelDistListLocal = channel.getDistributions();
if (!channel.getName().contains(ToolUtil.PRE_RELEASE)) {
channelDistListLocal = getSortedDistList(channelDistListLocal);
}
if (listOfFiles != null) {
for (Distribution distribution : channel.getDistributions()) {
for (Distribution distribution : channelDistListLocal) {
Arrays.sort(listOfFiles);
for (File file : listOfFiles) {
if (file.isDirectory()) {
Expand Down Expand Up @@ -153,15 +157,14 @@ private static void listDistributions(PrintStream outStream, boolean allFlag, bo
writeLocalDistsIntoJson(distList);
outStream.println("\nDistributions available remotely:");
for (Channel channel : channels) {
if (channel.getName().contains("pre-release") && !prFlag) {
if (channel.getName().contains(ToolUtil.PRE_RELEASE) && !prFlag) {
continue;
}
else {
outStream.println("\n" + channel.getName() + "\n");
List<Distribution> channelDistList = channel.getDistributions();
if (channel.getName().equals("Swan Lake channel")) {
channelDistList.sort(Comparator.comparing(Distribution::getVersion));
Collections.reverse(channelDistList);
if (!channel.getName().contains(ToolUtil.PRE_RELEASE)) {
channelDistList = getSortedDistList(channelDistList);
}
if (!allFlag){
if (channelDistList.size() > maxListingDistributions) {
Expand Down Expand Up @@ -305,6 +308,21 @@ private static void listLocalDists(File[] listOfFiles, PrintStream outStream, St
}
}

/**
* Sorts the distributions under a channel according to their semver version.
*
* @param channelDistList The list of distributions under a channel
*/
private static List<Distribution> getSortedDistList(List<Distribution> channelDistList) {
Comparator<Distribution> semverComparator = Comparator
.comparingInt((Distribution distribution) -> Integer.parseInt(distribution.getVersion().split("\\.")[0]))
.thenComparingInt((Distribution distribution) -> Integer.parseInt(distribution.getVersion().split("\\.")[1]))
.thenComparingInt((Distribution distribution) -> Integer.parseInt(distribution.getVersion().split("\\.")[2]));
channelDistList.sort(semverComparator);
Collections.reverse(channelDistList);
return channelDistList;
}

private static boolean isUpdated(File[] listOfFiles) {
try {
if (!new File(OSUtils.getBallerinaDistListFilePath()).exists()) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ballerinalang/command/util/ToolUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class ToolUtil {
private static final String PRODUCTION_URL = "https://api.central.ballerina.io/2.0/update-tool";
private static final String STAGING_URL = "https://api.staging-central.ballerina.io/2.0/update-tool/";
private static final String DEV_URL = "https://api.dev-central.ballerina.io/2.0/update-tool/";
public static final String PRE_RELEASE = "pre-release";
public static final String CLI_HELP_FILE_PREFIX = "dist-";
private static final String BALLERINA_1_X_VERSIONS = "1.0.";
private static final String CONNECTION_ERROR_MESSAGE = "connection to the remote server failed";
Expand Down

0 comments on commit 10a0aca

Please sign in to comment.