From 1f8fd34f0ef468e19499c94561af7cca9107c733 Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Fri, 2 Feb 2024 10:30:49 +0530 Subject: [PATCH] Address review suggestions --- gradle.properties | 2 +- .../org/ballerina/projectapi/BalToolTest.java | 139 ++++++++++-------- .../cmd-outputs/tool-execute-general-help.txt | 4 +- .../tool-list-with-multiple-tool-versions.txt | 8 +- 4 files changed, 84 insertions(+), 69 deletions(-) diff --git a/gradle.properties b/gradle.properties index 865cb58a00..43696fd166 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ group=org.ballerinalang version=2201.9.0-SNAPSHOT codeName=swan-lake -ballerinaLangVersion=2201.9.0-20240120-003700-f65e7994 +ballerinaLangVersion=2201.9.0-20240201-152800-3c3df044 ballerinaJreVersion=2.0.0 dependencyJREVersion=jdk-17.0.7+7-jre specVersion=2023R1 diff --git a/project-api-tests/src/test/java/org/ballerina/projectapi/BalToolTest.java b/project-api-tests/src/test/java/org/ballerina/projectapi/BalToolTest.java index ea8afa1330..d47d217217 100644 --- a/project-api-tests/src/test/java/org/ballerina/projectapi/BalToolTest.java +++ b/project-api-tests/src/test/java/org/ballerina/projectapi/BalToolTest.java @@ -64,6 +64,12 @@ public class BalToolTest { private static final String nonExistingVersion = "1.0.3"; private static final String incompatibleDistVersion = "1.0.4"; private static final String packageName = "disttest"; + private static final String PULL = "pull"; + private static final String REMOVE = "remove"; + private static final String UPDATE = "update"; + private static final String USE = "use"; + private static final String LIST = "list"; + private static final String SEARCH = "search"; private Map toolEnvironments; @BeforeClass() @@ -94,10 +100,10 @@ public void setupPullTests() { } } - @Test(description = "Pull tool without specifying a version", groups = {"pull"}) + @Test(description = "Pull a tool without specifying a version", groups = {"pull"}) public void testPullToolWithoutVersion() throws IOException, InterruptedException { Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", toolId)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); + new ArrayList<>(Arrays.asList(PULL, toolId)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { Assert.fail(OUTPUT_CONTAIN_ERRORS + cmdErrors); @@ -110,7 +116,7 @@ public void testPullToolWithoutVersion() throws IOException, InterruptedExceptio Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } - // Check for tool availability in local env + // Check for tool availability in bal-tools.toml BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.PULL).balToolsTomlPath); Optional toolOpt = BalToolsManifestBuilder.from(balToolsToml).build() .getActiveTool(toolId); @@ -123,6 +129,7 @@ public void testPullToolWithoutVersion() throws IOException, InterruptedExceptio Assert.assertEquals(tool.org(), orgName); Assert.assertEquals(tool.name(), packageName); + // Check for tool availability in local cache Path toolVersionCachePath = toolEnvironments.get(ToolSubCommand.PULL).centralCachePath .resolve(Path.of(tool.org(), tool.name(), tool.version())); if (!Files.exists(toolVersionCachePath)) { @@ -136,11 +143,11 @@ public void testPullToolWithoutVersion() throws IOException, InterruptedExceptio Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); } - @Test(description = "Pull tool again without specifying a version", + @Test(description = "Pull a tool again without specifying a version", dependsOnMethods = "testPullToolWithoutVersion", groups = {"pull"}) public void testPullToolAgainWithoutVersion() throws IOException, InterruptedException { Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", toolId)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); + new ArrayList<>(Arrays.asList(PULL, toolId)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { Assert.fail(OUTPUT_CONTAIN_ERRORS + cmdErrors); @@ -153,7 +160,7 @@ public void testPullToolAgainWithoutVersion() throws IOException, InterruptedExc Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } - // Check for tool availability in local env + // Check for tool availability in bal-tools.toml BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.PULL).balToolsTomlPath); Optional toolOpt = BalToolsManifestBuilder.from(balToolsToml).build() .getActiveTool(toolId); @@ -166,6 +173,7 @@ public void testPullToolAgainWithoutVersion() throws IOException, InterruptedExc Assert.assertEquals(tool.org(), orgName); Assert.assertEquals(tool.name(), packageName); + // Check for tool availability in local cache Path toolVersionCachePath = toolEnvironments.get(ToolSubCommand.PULL).centralCachePath .resolve(Path.of(tool.org(), tool.name(), tool.version())); if (!Files.exists(toolVersionCachePath)) { @@ -179,12 +187,12 @@ public void testPullToolAgainWithoutVersion() throws IOException, InterruptedExc Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); } - @Test(description = "Pull tool with a specific version", + @Test(description = "Pull a tool with a specific version", dependsOnMethods = {"testPullToolAgainWithoutVersion"}, groups = {"pull"}) public void testPullToolWithASpecificVersion() throws IOException, InterruptedException { String toolIdAndVersion = toolId + ":" + specificVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(PULL, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { @@ -198,7 +206,7 @@ public void testPullToolWithASpecificVersion() throws IOException, InterruptedEx Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } - // Check for tool availability in local env + // Check for tool availability in bal-tools.toml BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.PULL).balToolsTomlPath); Optional toolOpt = BalToolsManifestBuilder.from(balToolsToml).build() .getActiveTool(toolId); @@ -211,6 +219,7 @@ public void testPullToolWithASpecificVersion() throws IOException, InterruptedEx Assert.assertEquals(tool.org(), orgName); Assert.assertEquals(tool.name(), packageName); + // Check for tool availability in local cache Path toolVersionCachePath = toolEnvironments.get(ToolSubCommand.PULL).centralCachePath .resolve(Path.of(tool.org(), tool.name(), tool.version())); if (!Files.exists(toolVersionCachePath)) { @@ -224,12 +233,12 @@ public void testPullToolWithASpecificVersion() throws IOException, InterruptedEx Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); } - @Test(description = "Pull tool again with a specific version", + @Test(description = "Pull a tool again with a specific version", dependsOnMethods = "testPullToolWithASpecificVersion", groups = {"pull"}) public void testPullToolAgainWithASpecificVersion() throws IOException, InterruptedException { String toolIdAndVersion = toolId + ":" + specificVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(PULL, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { @@ -243,7 +252,7 @@ public void testPullToolAgainWithASpecificVersion() throws IOException, Interrup Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } - // Check for tool availability in local env + // Check for tool availability in bal-tools.toml BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.PULL).balToolsTomlPath); Optional toolOpt = BalToolsManifestBuilder.from(balToolsToml).build() .getActiveTool(toolId); @@ -256,6 +265,7 @@ public void testPullToolAgainWithASpecificVersion() throws IOException, Interrup Assert.assertEquals(tool.org(), orgName); Assert.assertEquals(tool.name(), packageName); + // Check for tool availability in local cache Path toolVersionCachePath = toolEnvironments.get(ToolSubCommand.PULL).centralCachePath .resolve(Path.of(tool.org(), tool.name(), tool.version())); if (!Files.exists(toolVersionCachePath)) { @@ -269,12 +279,12 @@ public void testPullToolAgainWithASpecificVersion() throws IOException, Interrup Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); } - @Test(description = "Pull tool with a non existing version", + @Test(description = "Pull a tool with a non existing version", dependsOnMethods = "testPullToolWithASpecificVersion", groups = {"pull"}) public void testPullToolWithANonExistingVersion() throws IOException, InterruptedException { String toolIdAndVersion = toolId + ":" + nonExistingVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(PULL, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); String expectedOutput = readExpectedCmdOutsAsString("tool-pull-with-non-existing-version.txt"); @@ -282,14 +292,15 @@ public void testPullToolWithANonExistingVersion() throws IOException, Interrupte Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdErrors); } - // Check for tool availability in local env + // Check for tool availability in bal-tools.toml BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.PULL).balToolsTomlPath); Optional toolOpt = BalToolsManifestBuilder.from(balToolsToml).build() - .getTool(toolId, nonExistingVersion); + .getTool(toolId, nonExistingVersion, null); if (toolOpt.isPresent()) { Assert.fail("Tool " + toolIdAndVersion + " should not be in bal-tools.toml"); } + // Check for tool availability in local cache Path toolVersionCachePath = toolEnvironments.get(ToolSubCommand.PULL).centralCachePath .resolve(Path.of(orgName, toolId, nonExistingVersion)); if (Files.exists(toolVersionCachePath)) { @@ -308,7 +319,7 @@ public void testPullToolWithANonExistingVersion() throws IOException, Interrupte public void testPullAToolVersionWithIncompatibleDistribution() throws IOException, InterruptedException { String toolIdAndVersion = toolId + ":" + incompatibleDistVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(PULL, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); String expectedOutput = readExpectedCmdOutsAsString("tool-pull-with-incompatible-dist.txt"); @@ -328,33 +339,35 @@ public void setupRemoveTests() throws IOException, InterruptedException { // Pull a specific version of a tool String specificToolVersion = toolId + ":" + specificVersion; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", specificToolVersion)), + new ArrayList<>(Arrays.asList(PULL, specificToolVersion)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); // Pull the latest tool version executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", toolId)), + new ArrayList<>(Arrays.asList(PULL, toolId)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); // Pull tool version with incompatible distribution String incompToolVersion = toolId + ":" + incompatibleDistVersion; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", incompToolVersion)), + new ArrayList<>(Arrays.asList(PULL, incompToolVersion)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); // Add the dist incompatible version to the toml file BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.REMOVE).balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); - balToolsManifest.addTool(toolId, orgName, packageName, incompatibleDistVersion, false); + balToolsManifest.addTool(toolId, orgName, packageName, incompatibleDistVersion, false, null); balToolsToml.modify(balToolsManifest); + System.out.println(balToolsManifest); } @Test(description = "Remove a non existing tool", groups = {"remove"}) public void testRemoveANonExistingTool() throws IOException, InterruptedException { Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("remove", nonExistingTool)), + new ArrayList<>(Arrays.asList(REMOVE, nonExistingTool)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); + // Validate the command output String cmdErrors = getString(cmdExec.getErrorStream()); String expectedOutput = readExpectedCmdOutsAsString("tool-remove-non-existing-tool.txt"); if (!cmdErrors.contains(expectedOutput)) { @@ -373,9 +386,10 @@ public void testRemoveANonExistingTool() throws IOException, InterruptedExceptio public void testRemoveANonExistingVersionOfATool() throws IOException, InterruptedException { String toolIdAndVersion = toolId + ":" + nonExistingVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("remove", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(REMOVE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); + // Validate the command output String cmdErrors = getString(cmdExec.getErrorStream()); String expectedOutput = readExpectedCmdOutsAsString("tool-remove-non-existing-version.txt"); if (!cmdErrors.contains(expectedOutput)) { @@ -393,7 +407,7 @@ public void testRemoveANonExistingVersionOfATool() throws IOException, Interrupt public void testRemoveToolVersionWithIncompatibleDistribution() throws IOException, InterruptedException { String toolIdAndVersion = toolId + ":" + incompatibleDistVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("remove", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(REMOVE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); String expectedOutput = readExpectedCmdOutsAsString("tool-remove-with-incompatible-dist.txt"); @@ -413,12 +427,13 @@ public void testRemoveToolActiveVersion() throws IOException, InterruptedExcepti // Make the latest version active BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.REMOVE).balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); - balToolsManifest.setActiveToolVersion(toolId, latestVersion); + balToolsManifest.setActiveToolVersion(toolId, latestVersion, null); balToolsToml.modify(balToolsManifest); + // Remove the active version String toolIdAndVersion = toolId + ":" + latestVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("remove", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(REMOVE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); String expectedOutput = readExpectedCmdOutsAsString("tool-remove-active-version.txt"); @@ -441,19 +456,19 @@ public void testRemoveASpecificToolVersion() throws IOException, InterruptedExce // Make the latest version active BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.REMOVE).balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); - balToolsManifest.setActiveToolVersion(toolId, latestVersion); + balToolsManifest.setActiveToolVersion(toolId, latestVersion, null); balToolsToml.modify(balToolsManifest); String toolIdAndVersion = toolId + ":" + specificVersion; - // Check for tool availability in local env - Optional toolOpt = balToolsManifest.getTool(toolId, specificVersion); + // Check for tool availability in bal-tools.toml + Optional toolOpt = balToolsManifest.getTool(toolId, specificVersion, null); if (toolOpt.isEmpty()) { Assert.fail("Tool '" + toolIdAndVersion + "' is not available to be removed"); } Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("remove", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(REMOVE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { @@ -467,13 +482,14 @@ public void testRemoveASpecificToolVersion() throws IOException, InterruptedExce Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } - // Check for tool availability in local env + // Check for tool availability in bal-tools.toml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.REMOVE).balToolsTomlPath); - toolOpt = BalToolsManifestBuilder.from(balToolsToml).build().getTool(toolId, specificVersion); + toolOpt = BalToolsManifestBuilder.from(balToolsToml).build().getTool(toolId, specificVersion, null); if (toolOpt.isPresent()) { Assert.fail("Tool '" + toolIdAndVersion + "' is available in bal-tools.toml"); } + // Check for tool availability in local cache Path toolVersionCachePath = toolEnvironments.get(ToolSubCommand.REMOVE).centralCachePath .resolve(Path.of(orgName, packageName, specificVersion)); if (Files.exists(toolVersionCachePath)) { @@ -490,7 +506,7 @@ public void testRemoveASpecificToolVersion() throws IOException, InterruptedExce @Test(description = "Remove all tool versions", dependsOnMethods = {"testRemoveASpecificToolVersion"}, groups = {"remove"}) public void testRemoveAllToolVersions() throws IOException, InterruptedException { - // Check for tool availability in local env + // Check for tool availability in bal-tools.toml BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.REMOVE).balToolsTomlPath); Optional toolOpt = BalToolsManifestBuilder.from(balToolsToml).build() .getActiveTool(toolId); @@ -498,8 +514,9 @@ public void testRemoveAllToolVersions() throws IOException, InterruptedException Assert.fail("Tool '" + toolId + "' is not available to be removed"); } + // Remove all versions of the tool Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("remove", toolId)), + new ArrayList<>(Arrays.asList(REMOVE, toolId)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { @@ -513,13 +530,14 @@ public void testRemoveAllToolVersions() throws IOException, InterruptedException Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } - // Check for tool availability in local env + // Check for tool availability in bal-tools.toml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.REMOVE).balToolsTomlPath); toolOpt = BalToolsManifestBuilder.from(balToolsToml).build().getActiveTool(toolId); if (toolOpt.isPresent()) { Assert.fail("Tool " + toolId + " is available in bal-tools.toml"); } + // Check for tool availability in local cache Path toolVersionCachePath = toolEnvironments.get(ToolSubCommand.REMOVE).centralCachePath .resolve(Path.of(orgName, packageName)); if (Files.exists(toolVersionCachePath)) { @@ -537,21 +555,21 @@ public void testRemoveAllToolVersions() throws IOException, InterruptedException public void setupUpdateTests() throws IOException, InterruptedException { // Remove all versions of the tool Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("remove", toolId)), + new ArrayList<>(Arrays.asList(REMOVE, toolId)), toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); getString(cmdExec.getErrorStream()); // Pull an older version of the tool String toolIdAndVersion = toolId + ":" + specificVersion; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(PULL, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); } @Test(description = "Update a non-existing tool", groups = {"update"}) public void testUpdateNonExistingTool() throws IOException, InterruptedException { Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("update", nonExistingTool)), + new ArrayList<>(Arrays.asList(UPDATE, nonExistingTool)), toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); String expectedOutput = readExpectedCmdOutsAsString("tool-update-non-existing.txt"); @@ -587,8 +605,9 @@ public void testUpdateToolWithNewPatchAndMinor() throws IOException, Interrupted "' should be the current version in bal-tools.toml before update command"); } + // Update the tool Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("update", toolId)), + new ArrayList<>(Arrays.asList(UPDATE, toolId)), toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); @@ -611,7 +630,7 @@ public void testUpdateToolWithNewPatchAndMinor() throws IOException, Interrupted Assert.fail("Tool '" + toolIdAndVersion + "' is not available in bal-tools.toml"); } - // Check for tool availability in local env + // Check for tool availability in local cache Path toolVersionCachePath = toolEnvironments.get(ToolSubCommand.UPDATE).centralCachePath .resolve(Path.of(orgName, packageName, latestVersion)); if (!Files.exists(toolVersionCachePath)) { @@ -637,8 +656,9 @@ public void testUpdateToolWithNoNewVersions() throws IOException, InterruptedExc Assert.fail("Tool '" + toolIdAndVersion + "' should be the current version in bal-tools.toml"); } + // Update the tool Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("update", toolId)), + new ArrayList<>(Arrays.asList(UPDATE, toolId)), toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); @@ -672,24 +692,24 @@ public void testUpdateToolWithNoNewVersions() throws IOException, InterruptedExc public void setupUseTests() throws IOException, InterruptedException { // Pull the latest tool version executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", toolId)), toolEnvironments.get(ToolSubCommand.USE).envVariables); + new ArrayList<>(Arrays.asList(PULL, toolId)), toolEnvironments.get(ToolSubCommand.USE).envVariables); // Pull a specific version of a tool String specificToolVersion = toolId + ":" + specificVersion; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", specificToolVersion)), + new ArrayList<>(Arrays.asList(PULL, specificToolVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); // Pull tool version with incompatible distribution String incompToolVersion = toolId + ":" + incompatibleDistVersion; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", incompToolVersion)), + new ArrayList<>(Arrays.asList(PULL, incompToolVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); // Add the dist incompatible version to the toml file BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.USE).balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); - balToolsManifest.addTool(toolId, orgName, packageName, incompatibleDistVersion, false); + balToolsManifest.addTool(toolId, orgName, packageName, incompatibleDistVersion, false, null); balToolsToml.modify(balToolsManifest); } @@ -697,7 +717,7 @@ public void setupUseTests() throws IOException, InterruptedException { public void testUseNewToolVersion() throws IOException, InterruptedException { String toolIdAndVersion = toolId + ":" + latestVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("use", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(USE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { @@ -722,7 +742,7 @@ public void testUseNewToolVersion() throws IOException, InterruptedException { public void testUseOldToolVersion() throws IOException, InterruptedException { String toolIdAndVersion = toolId + ":" + specificVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("use", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(USE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { @@ -748,10 +768,9 @@ public void testUseOldToolVersion() throws IOException, InterruptedException { public void testUseCurrentlyActiveToolVersion() throws IOException, InterruptedException { String toolIdAndVersion = toolId + ":" + specificVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("use", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(USE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); - if (!cmdErrors.isEmpty()) { Assert.fail(OUTPUT_CONTAIN_ERRORS + cmdErrors); } @@ -775,10 +794,9 @@ public void testUseCurrentlyActiveToolVersion() throws IOException, InterruptedE public void testUseNonExistentToolVersion() throws IOException, InterruptedException { String toolIdAndVersion = toolId + ":" + nonExistingVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("use", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(USE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); - String expectedOutput = readExpectedCmdOutsAsString("tool-use-non-existent-version.txt"); if (!cmdErrors.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdErrors); @@ -796,10 +814,9 @@ public void testUseNonExistentToolVersion() throws IOException, InterruptedExcep public void testUseToolVersionWithIncompatibleDistribution() throws IOException, InterruptedException { String toolIdAndVersion = toolId + ":" + incompatibleDistVersion; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("use", toolIdAndVersion)), + new ArrayList<>(Arrays.asList(USE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); - String expectedOutput = readExpectedCmdOutsAsString("tool-use-with-incompatible-dist.txt"); if (!cmdErrors.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdErrors); @@ -816,12 +833,12 @@ public void testUseToolVersionWithIncompatibleDistribution() throws IOException, public void testListToolsWhenNoToolsInstalled() throws IOException, InterruptedException { // Remove the tool entirely executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("remove", toolId)), + new ArrayList<>(Arrays.asList(REMOVE, toolId)), toolEnvironments.get(ToolSubCommand.LIST).envVariables); // List all tools Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(List.of("list")), toolEnvironments.get(ToolSubCommand.LIST).envVariables); + new ArrayList<>(List.of(LIST)), toolEnvironments.get(ToolSubCommand.LIST).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { Assert.fail(OUTPUT_CONTAIN_ERRORS + cmdErrors); @@ -839,17 +856,17 @@ public void testListToolsWhenNoToolsInstalled() throws IOException, InterruptedE public void testListToolsWithMultipleToolVersions() throws IOException, InterruptedException { // Pull the latest tool version executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", toolId)), toolEnvironments.get(ToolSubCommand.LIST).envVariables); + new ArrayList<>(Arrays.asList(PULL, toolId)), toolEnvironments.get(ToolSubCommand.LIST).envVariables); // Pull a specific version of a tool String specificToolVersion = toolId + ":" + specificVersion; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", specificToolVersion)), + new ArrayList<>(Arrays.asList(PULL, specificToolVersion)), toolEnvironments.get(ToolSubCommand.LIST).envVariables); // List all tools Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(List.of("list")), toolEnvironments.get(ToolSubCommand.LIST).envVariables); + new ArrayList<>(List.of(LIST)), toolEnvironments.get(ToolSubCommand.LIST).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { Assert.fail(OUTPUT_CONTAIN_ERRORS + cmdErrors); @@ -866,7 +883,7 @@ public void testListToolsWithMultipleToolVersions() throws IOException, Interrup @Test(description = "Search a tool with tool id", groups = {"list"}) public void testSearchAToolWithId() throws IOException, InterruptedException { Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("search", toolId)), + new ArrayList<>(Arrays.asList(SEARCH, toolId)), toolEnvironments.get(ToolSubCommand.SEARCH).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { @@ -886,12 +903,12 @@ public void setupExecuteToolTests() throws IOException, InterruptedException { // Pull a specific version of a tool String specificToolVersion = toolId + ":" + specificVersion; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", specificToolVersion)), + new ArrayList<>(Arrays.asList(PULL, specificToolVersion)), toolEnvironments.get(ToolSubCommand.EXECUTE).envVariables); // Pull the latest tool version executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList("pull", toolId)), + new ArrayList<>(Arrays.asList(PULL, toolId)), toolEnvironments.get(ToolSubCommand.EXECUTE).envVariables); } diff --git a/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-execute-general-help.txt b/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-execute-general-help.txt index 51ae0fddbd..ad664ebad1 100644 --- a/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-execute-general-help.txt +++ b/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-execute-general-help.txt @@ -40,9 +40,7 @@ COMMANDS format Format Ballerina source files grpc Generate the Ballerina sources for a given Protocol Buffer definition - graphql Generate the Ballerina client sources for a GraphQL config file, - generate the GraphQL schema for a Ballerina GraphQL service, and - generate the Ballerina GraphQL service for a GraphQL schema + graphql Generate the Ballerina client sources for a GraphQL config file, the GraphQL schema for a GraphQL service, and Ballerina service sources for a GraphQL schema openapi Generate the Ballerina sources for a given OpenAPI definition and vice versa asyncapi Generate the Ballerina sources for a given AsyncAPI definition diff --git a/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-list-with-multiple-tool-versions.txt b/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-list-with-multiple-tool-versions.txt index 4bdfe71cd7..e3029ffb79 100644 --- a/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-list-with-multiple-tool-versions.txt +++ b/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-list-with-multiple-tool-versions.txt @@ -1,4 +1,4 @@ -|TOOL ID |VERSION | -|----------------------|----------------| -|disttest | 1.1.0 | -|disttest |* 1.0.0 | \ No newline at end of file +|TOOL ID |VERSION |REPO | +|----------------------|----------------|-----------| +|disttest | 1.1.0 |central | +|disttest |* 1.0.0 |central | \ No newline at end of file