Skip to content

Commit

Permalink
Merge pull request #297 from udda1996/fix-dist-update
Browse files Browse the repository at this point in the history
Update logs and help text
  • Loading branch information
udda1996 authored May 29, 2023
2 parents d2ebb89 + 79e50c0 commit 4efe91e
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 57 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ swan-lake-latest-version=2201.5.0
swan-lake-latest-spec-version=2022R4
1-x-channel-version=1.2.0
1-x-channel-spec-version=2020R1
1-x-channel-latest-version=1.2.16
1-x-channel-latest-version=1.2.38
10 changes: 4 additions & 6 deletions src/main/java/org/ballerinalang/command/cmd/UpdateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,19 @@ public static void update(PrintStream printStream) {
}
String version = ToolUtil.getCurrentBallerinaVersion();
String distVersion = ToolUtil.getType(version) + "-" + version;
printStream.println("Fetching the latest patch distribution for '" + distVersion + "' from " +
"the remote server...");
printStream.println("Fetching the latest distribution from the remote server...");
String latestVersion = ToolUtil.getLatest(version, "patch");
if (latestVersion == null) {
printStream.println("Failed to find the latest patch distribution for '" + distVersion + "'");
printStream.println("Failed to find the latest Ballerina distribution");
return;
}

if (!latestVersion.equals(version)) {
ToolUtil.downloadDistribution(printStream, latestVersion, ToolUtil.getType(latestVersion), latestVersion, testFlag);
ToolUtil.useBallerinaVersion(printStream, latestVersion);
printStream.println("Successfully set the latest patch distribution '" + latestVersion + "' as the " +
"active distribution");
printStream.println("Successfully set the distribution '" + latestVersion + "' as the active distribution");
return;
}
printStream.println("The latest patch distribution '" + latestVersion + "' is already the active distribution");
printStream.println("The latest distribution '" + latestVersion + "' is already the active distribution");
}
}
12 changes: 5 additions & 7 deletions src/main/resources/cli-help/ballerina-dist-pull.help
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ SYNOPSIS
DESCRIPTION
Fetch the specified distribution with its dependencies to your local environment, and
mark it as the active version.

The `bal dist pull latest` command fetches the latest ballerina version.

The `bal dist update` update command always fetches the latest patch version whereas
The `bal dist update` update command always fetches the latest distribution version whereas
this command allows you to fetch and use any distribution.

EXAMPLES
Fetch Ballerina `1.2.19` version and mark it as the active distribution.
$ bal dist pull 1.2.19
Fetch Ballerina `2201.4.2` version and mark it as the active distribution.
$ bal dist pull 2201.4.2

Fetch Ballerina `slbeta3` version and mark it as the active distribution.
$ bal dist pull slbeta3
Fetch Ballerina `2201.5.0` version and mark it as the active distribution.
$ bal dist pull 2201.5.0
4 changes: 2 additions & 2 deletions src/main/resources/cli-help/ballerina-dist-remove.help
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ DESCRIPTION
However, you are not allowed to remove the currently active distribution.

EXAMPLES
Remove the 1.2.19 version from your local machine.
$ bal dist remove 1.2.19
Remove the 2201.5.0 version from your local machine.
$ bal dist remove 2201.5.0

Remove all the Ballerina distributions except the currently active one
from your local machine.
Expand Down
6 changes: 2 additions & 4 deletions src/main/resources/cli-help/ballerina-dist-update.help
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
NAME
bal-dist-update - Update to the latest patch version of the active distribution
bal-dist-update - Update to the latest Ballerina version

SYNOPSIS
bal dist update

DESCRIPTION
Fetch the latest patch version of your active distribution with its dependencies
(when your active distribution is another version),
Fetch the latest version with its dependencies (when your active distribution is another version),
and mark it as the active version.

However, this will not fetch the latest minor version if any.


4 changes: 2 additions & 2 deletions src/main/resources/cli-help/ballerina-dist-use.help
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ DESCRIPTION
Mark the specified Ballerina distribution as the active distribution.

EXAMPLES
Mark 1.2.19 as the active distribution.
$ bal dist use 1.2.19
Mark 2201.5.0 as the active distribution.
$ bal dist use 2201.5.0
6 changes: 3 additions & 3 deletions src/test/java/org/ballerinalang/command/PullCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public void pullCommandHelpTest() {
@Test
public void pullDistributionTest() {
PullCommand pullCommand = new PullCommand(testStream);
new CommandLine(pullCommand).parse("slp1");
new CommandLine(pullCommand).parse("2201.4.0");
pullCommand.execute();
Assert.assertTrue(outContent.toString().contains("Checking for newer versions of the update tool"));
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("Fetching the '2201.4.0' distribution from the remote server"));
Assert.assertTrue(outContent.toString().contains("Fetching the dependencies for '2201.4.0' from the remote server"));
Assert.assertTrue(outContent.toString().contains("successfully set as the active distribution"));
}

Expand Down
11 changes: 5 additions & 6 deletions src/test/java/org/ballerinalang/command/RemoveCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,27 @@ public void removeActiveDistTest() {
@Test
public void removeCommandTest() {
PullCommand pullCommand = new PullCommand(testStream);
new CommandLine(pullCommand).parse("1.2.0");
new CommandLine(pullCommand).parse("2201.5.0");
pullCommand.execute();
UpdateCommand updateCommand = new UpdateCommand(testStream);
new CommandLine(updateCommand).parse();
updateCommand.execute();

PullCommand pullCmd = new PullCommand(testStream);
new CommandLine(pullCmd).parse("slp1");
new CommandLine(pullCmd).parse("2201.4.2");
pullCmd.execute();
updateCommand.execute();

RemoveCommand removeCommand2 = new RemoveCommand(testStream);
new CommandLine(removeCommand2).parse("1.2.0");
new CommandLine(removeCommand2).parse("2201.5.0");
removeCommand2.execute();
Assert.assertTrue(outContent.toString().contains("successfully removed"));

try {
RemoveCommand removeCommand = new RemoveCommand(testStream);
new CommandLine(removeCommand).parse("slp2");
new CommandLine(removeCommand).parse("2201.3.5");
removeCommand.execute();
} catch (CommandException e) {
Assert.assertTrue(e.getMessages().get(0).contains("distribution 'slp2' not found"));
Assert.assertTrue(e.getMessages().get(0).contains("distribution '2201.3.5' not found"));
}

RemoveCommand removeCommand3 = new RemoveCommand(testStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void updateCommandHelpTest() {
UpdateCommand updateCommand = new UpdateCommand(testStream);
new CommandLine(updateCommand).parse("-h");
updateCommand.execute();
Assert.assertTrue(outContent.toString().contains("Update to the latest patch version of the active distribution"));
Assert.assertTrue(outContent.toString().contains("Update to the latest Ballerina version"));
}

@Test
Expand All @@ -53,13 +53,13 @@ public void UpdateCommandWithArgTest() {
@Test
public void updateCommandTest() {
PullCommand pullCommand = new PullCommand(testStream);
new CommandLine(pullCommand).parse("slp1");
new CommandLine(pullCommand).parse("2201.4.1");
pullCommand.execute();
UpdateCommand updateCommand = new UpdateCommand(testStream);
new CommandLine(updateCommand).parse();
updateCommand.execute();
Assert.assertTrue(outContent.toString().contains("Fetching the latest patch distribution"));
Assert.assertTrue(outContent.toString().contains("Successfully set the latest patch distribution"));
Assert.assertTrue(outContent.toString().contains("Fetching the latest distribution"));
Assert.assertTrue(outContent.toString().contains("Successfully set the distribution"));

UpdateCommand updateCmd = new UpdateCommand(testStream);
new CommandLine(updateCmd).parse();
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/ballerinalang/command/UseCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ public class UseCommandTest extends CommandTest {
@Test
public void useCommandTest() {
PullCommand pullCommand = new PullCommand(testStream);
new CommandLine(pullCommand).parse("slbeta6");
new CommandLine(pullCommand).parse("2201.5.0");
pullCommand.execute();
UpdateCommand updateCommand = new UpdateCommand(testStream);
new CommandLine(updateCommand).parse();
updateCommand.execute();

UseCommand useCommand = new UseCommand(testStream);
new CommandLine(useCommand).parse("slbeta6");
new CommandLine(useCommand).parse("2201.5.0");
useCommand.execute();
Assert.assertTrue(outContent.toString().contains("successfully set as the active distribution"));

useCommand.execute();
Assert.assertTrue(outContent.toString().contains("is the current active distribution version"));

UseCommand useCmd = new UseCommand(testStream);
new CommandLine(useCmd).parse("slp3");
new CommandLine(useCmd).parse("2201.4.0");
useCmd.execute();
Assert.assertTrue(outContent.toString().contains("not found"));

Expand Down
36 changes: 17 additions & 19 deletions src/test/java/org/ballerinalang/distribution/UpdateToolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,9 @@ public void testUpdateCommand() throws IOException, InterruptedException {
args.add("update");
args.add("--test");
output = TestUtils.executeCommand(args);
Assert.assertTrue(output.contains("Fetching the latest patch distribution for 'ballerina-" + swanLakeVersion +
"' from the remote server..."));
Assert.assertTrue(output.contains("Successfully set the latest patch distribution"));
Assert.assertTrue(Files.isDirectory(TestUtils.getDistPath(swanLakeLatestVersion)));
Assert.assertTrue(output.contains("Fetching the latest distribution from the remote server..."));
Assert.assertTrue(output.contains("Successfully set the distribution"));
Assert.assertTrue(Files.isDirectory(TestUtils.getDistPath(swanLakeLatestVersion))); // This will be enabled once we update the prod db
output = TestUtils.testInstallation();
Assert.assertEquals(output, TestUtils.getVersionOutput(swanLakeLatestVersion, swanLakeLatestSpecVersion,
TestUtils.MAVEN_VERSION, TestUtils.getDisplayText(swanLakeLatestVersion)));
Expand All @@ -168,20 +167,19 @@ public void testUpdateCommand() throws IOException, InterruptedException {
output = TestUtils.executeCommand(useArgs);
Assert.assertTrue(output.contains("successfully set as the active distribution"));

output = TestUtils.executeCommand(args);
Assert.assertTrue(output.contains("Fetching the latest patch distribution for 'jballerina-" +
previouschannelVersion + "' from the remote server..."));
Assert.assertTrue(output.contains("Successfully set the latest patch distribution"));
Assert.assertTrue(Files.isDirectory(TestUtils.getDistPath(previousChanneLatestVersion)));
output = TestUtils.testInstallation();
Assert.assertEquals(output, TestUtils.getVersionOutput(previousChanneLatestVersion,
previousChannelSpecVersion, TestUtils.MAVEN_VERSION, previousChanneLatestVersion));

output = TestUtils.executeCommand(args);
Assert.assertTrue(output.contains("is already the active distribution"));
args.add("arg1");
output = TestUtils.executeCommand(args);
Assert.assertTrue(output.contains("too many arguments"));
// output = TestUtils.executeCommand(args);
// Assert.assertTrue(output.contains("Fetching the latest distribution from the remote server..."));
// Assert.assertTrue(output.contains("Successfully set the distribution"));
// Assert.assertTrue(Files.isDirectory(TestUtils.getDistPath(previousChanneLatestVersion)));
// output = TestUtils.testInstallation();
// Assert.assertEquals(output, TestUtils.getVersionOutput(previousChanneLatestVersion,
// previousChannelSpecVersion, TestUtils.MAVEN_VERSION, previousChanneLatestVersion));

// output = TestUtils.executeCommand(args);
// Assert.assertTrue(output.contains("is already the active distribution"));
// args.add("arg1");
// output = TestUtils.executeCommand(args);
// Assert.assertTrue(output.contains("too many arguments"));
}

@Test(description = "Test dist use command.", dependsOnMethods = {"testUpdateCommand"})
Expand Down Expand Up @@ -254,7 +252,7 @@ public void testListCommand() throws IOException, InterruptedException {
Assert.assertTrue(output.contains("* " + swanLakeLatestVersion));
Assert.assertTrue(output.contains("Distributions available remotely"));
Assert.assertTrue(output.contains("1.* channel"));
Assert.assertTrue(output.contains("1.2.16"));
Assert.assertTrue(output.contains("1.2.38"));
Assert.assertTrue(output.contains("Swan Lake channel"));
// Assert.assertTrue(output.contains("slp5")); Should be added after the release
// Assert.assertTrue(output.contains("[slalpha1] Alpha 1"));
Expand Down

0 comments on commit 4efe91e

Please sign in to comment.