diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index b853e7e10f..4e7c6b6cc3 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -236,6 +236,7 @@ jobs: packageUser: ${{ github.actor }} packagePAT: ${{ secrets.GITHUB_TOKEN }} devCentralToken: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }} + prodCentralToken: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} githubAccessToken: ${{ secrets.GITHUB_TOKEN }} ballerinaBotWorkflow: $ {{ secrets.BALLERINA_BOT_WORKFLOW }} TEST_MODE_ACTIVE: true diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index c4f204b279..ebc58c4dce 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -73,6 +73,7 @@ jobs: packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} packagePAT: ${{ secrets.BALLERINA_BOT_TOKEN }} devCentralToken: ${{ secrets.BALLERINA_CENTRAL_DEV_ACCESS_TOKEN }} + prodCentralToken: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} githubAccessToken: ${{ secrets.GITHUB_TOKEN }} ballerinaBotWorkflow: $ {{ secrets.BALLERINA_BOT_WORKFLOW }} run: | diff --git a/devtools-integration-tests/src/test/java/org/ballerina/devtools/cmd/BuildNewCommandTest.java b/devtools-integration-tests/src/test/java/org/ballerina/devtools/cmd/BuildNewCommandTest.java deleted file mode 100644 index f5b3cf488b..0000000000 --- a/devtools-integration-tests/src/test/java/org/ballerina/devtools/cmd/BuildNewCommandTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.ballerina.devtools.cmd; - -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.LinkedList; -import java.util.List; - -import static org.ballerina.devtools.cmd.TestUtils.*; - -/** - * Tests related new command compiling. - */ -public class BuildNewCommandTest { - - public static final String DISTRIBUTION_FILE_NAME = "ballerina-" + MAVEN_VERSION + "-" + CODE_NAME; - public static final String WHITESPACE_PATTERN = "\\s+"; - - private Path tempHomeDirectory; - private Path tempWorkspaceDirectory; - private static Path sourceDirectory; - private ByteArrayOutputStream console; - protected PrintStream printStream; - - @BeforeClass() - public void setUp() throws IOException { - setupDistributions(); - TestUtils.createTempDirectories(); - tempWorkspaceDirectory = Files.createTempDirectory("bal-test-integration-packaging-workspace-"); - } - - @BeforeMethod - public void beforeMethod() { - this.console = new ByteArrayOutputStream(); - this.printStream = new PrintStream(this.console); - } - - @Test(description = "Build package created from new command with default template") - public void testCompilingNewCommandDefaultTempProject() throws IOException { - List args = new LinkedList<>(); - args.add("project_sample"); - Path newOutputPath = TestUtils.executeNew(distributionName, args); - Assert.assertTrue(Files.isDirectory(newOutputPath.resolve("project_sample"))); - Assert.assertTrue(Files.exists(newOutputPath.resolve("project_sample").resolve("Ballerina.toml"))); - - List buildArgs = new LinkedList<>(); - String buildOutput = TestUtils.executeBuild(distributionName, newOutputPath.resolve("project_sample"), buildArgs); - Assert.assertTrue(buildOutput.contains("Compiling source")); - Assert.assertTrue(buildOutput.contains("Generating executable")); - } - - @Test(description = "Build package created from new command with main template") - public void testCompilingNewCommandMainTempProject() throws IOException { - List args = new LinkedList<>(); - args.add("main_sample"); - args.add("-t"); - args.add("main"); - Path newOutputPath = TestUtils.executeNew(distributionName, args); - Assert.assertTrue(Files.isDirectory(newOutputPath.resolve("main_sample"))); - Assert.assertTrue(Files.exists(newOutputPath.resolve("main_sample").resolve("Ballerina.toml"))); - - List buildArgs = new LinkedList<>(); - String buildOutput = TestUtils.executeBuild(distributionName, newOutputPath.resolve("main_sample"), buildArgs); - Assert.assertTrue(buildOutput.contains("Compiling source")); - Assert.assertTrue(buildOutput.contains("Generating executable")); - } - - @Test(description = "Build package created from new command with service template") - public void testCompilingNewCommandServiceTempProject() throws IOException { - List args = new LinkedList<>(); - args.add("service_sample"); - args.add("-t"); - args.add("service"); - Path newOutputPath = TestUtils.executeNew(distributionName, args); - Assert.assertTrue(Files.isDirectory(newOutputPath.resolve("service_sample"))); - Assert.assertTrue(Files.exists(newOutputPath.resolve("service_sample").resolve("Ballerina.toml"))); - - List buildArgs = new LinkedList<>(); - String buildOutput = TestUtils.executeBuild(distributionName, newOutputPath.resolve("service_sample"), buildArgs); - Assert.assertTrue(buildOutput.contains("Compiling source")); - Assert.assertTrue(buildOutput.contains("Generating executable")); - } - - @Test(description = "Build package created from new command with lib template") - public void testCompilingNewCommandLibTempProject() throws IOException { - List args = new LinkedList<>(); - args.add("lib_sample"); - args.add("-t"); - args.add("lib"); - Path newOutputPath = TestUtils.executeNew(distributionName, args); - Assert.assertTrue(Files.isDirectory(newOutputPath.resolve("lib_sample"))); - Assert.assertTrue(Files.exists(newOutputPath.resolve("lib_sample").resolve("Ballerina.toml"))); - - List buildArgs = new LinkedList<>(); - String buildOutput = TestUtils.executeBuild(distributionName, newOutputPath.resolve("lib_sample"), buildArgs); - Assert.assertTrue(buildOutput.contains("Compiling source")); - Assert.assertTrue(buildOutput.contains("Generating executable")); - } - - @AfterClass - private void cleanup() throws IOException { - TestUtils.deleteFiles(); - } - - /** - * Clean and set up distributions. - */ - private void setupDistributions() throws IOException { - TestUtils.cleanDistribution(); - TestUtils.prepareDistribution(DISTRIBUTIONS_DIR.resolve(DISTRIBUTION_FILE_NAME + ".zip")); - } -} diff --git a/devtools-integration-tests/src/test/java/org/ballerina/devtools/cmd/TestUtils.java b/devtools-integration-tests/src/test/java/org/ballerina/devtools/cmd/TestUtils.java deleted file mode 100644 index 31070d31be..0000000000 --- a/devtools-integration-tests/src/test/java/org/ballerina/devtools/cmd/TestUtils.java +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.ballerina.devtools.cmd; - -import net.lingala.zip4j.ZipFile; -import net.lingala.zip4j.exception.ZipException; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.testng.Assert; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.PrintStream; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class TestUtils { - private TestUtils() { - } - - public static final Path DISTRIBUTIONS_DIR = Paths.get(System.getProperty("distributions.dir")); - public static final Path MAVEN_VERSION = Paths.get(System.getProperty("maven.version")); - public static final Path CODE_NAME = Paths.get(System.getProperty("code.name")); - - private static final String BALLERINA_HOME_DIR = "BALLERINA_HOME_DIR"; - private static final String BALLERINA_DEV_CENTRAL = "BALLERINA_DEV_CENTRAL"; - private static final PrintStream OUT = System.out; - private static final Path TARGET_DIR = Paths.get(System.getProperty("target.dir")); - private static final Path TEST_DISTRIBUTION_PATH = TARGET_DIR.resolve("test-distribution"); - - public static String distributionName = "ballerina-" + MAVEN_VERSION + "-" + CODE_NAME; - private static Path sourceDirectory; - private static Path tempHomeDirectory; - private static Map envProperties; - - public static String executeBuild(String distributionName, Path projectDir, List args) throws - IOException { - args.add(0, "build"); - args.add(0, TEST_DISTRIBUTION_PATH.resolve(distributionName).resolve("bin").resolve("bal").toString()); - OUT.println("Executing: " + StringUtils.join(args, ' ')); - ProcessBuilder pb = new ProcessBuilder(args); - pb.directory(projectDir.toFile()); - Process process = pb.start(); - InputStream inputStream = process.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - String line; - String output = ""; - while ((line = reader.readLine()) != null) { - output += line + "\n"; - } - if (output.isEmpty()) { - inputStream = process.getErrorStream(); - reader = new BufferedReader(new InputStreamReader(inputStream)); - while ((line = reader.readLine()) != null) { - output += line + "\n"; - } - } - return output; - } - - /** - * Execute ballerina build command. - * - * @param distributionName The name of the distribution. - * @param args The arguments to be passed to the build command. - * @return True if build is successful, else false. - * @throws IOException Error executing build command. - * @throws InterruptedException Interrupted error executing build command. - */ - public static Path executeNew(String distributionName, List args) throws - IOException { - args.add(0, "new"); - args.add(0, TEST_DISTRIBUTION_PATH.resolve(distributionName).resolve("bin").resolve("bal").toString()); - OUT.println("Executing: " + StringUtils.join(args, ' ')); - ProcessBuilder pb = new ProcessBuilder(args); - pb.directory(sourceDirectory.toFile()); - Process process = pb.start(); - InputStream inputStream = process.getInputStream(); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - String line; - String output = ""; - while ((line = reader.readLine()) != null) { - output += line + "\n"; - } - if (output.isEmpty()) { - inputStream = process.getErrorStream(); - reader = new BufferedReader(new InputStreamReader(inputStream)); - while ((line = reader.readLine()) != null) { - output += line + "\n"; - } - } - return sourceDirectory; - } - - /** - * Creates temporary directories. - * - * @throws ZipException Error occurred when extracting. - */ - public static void createTempDirectories() throws IOException { - sourceDirectory = Files.createTempDirectory("bal-test-integration-packaging-workspace-"); - envProperties = addEnvVariables(getEnvVariables()); - tempHomeDirectory = Files.createTempDirectory("bal-test-integration-packaging-home-"); - createSettingToml(tempHomeDirectory); - } - - /** - * Extracts a distribution to a temporary directory. - * - * @param distributionZipPath Path to the distribution. - * @throws ZipException Error occurred when extracting. - */ - public static void prepareDistribution(Path distributionZipPath) throws ZipException { - OUT.println("Extracting: " + distributionZipPath.normalize()); - ZipFile zipFile = new ZipFile(distributionZipPath.toFile()); - zipFile.extractAll(TEST_DISTRIBUTION_PATH.toAbsolutePath().toString()); - } - - /** - * Delete the temporary directory used to extract distributions. - * - * @throws IOException If temporary directory does not exists. - */ - public static void cleanDistribution() throws IOException { - FileUtils.deleteDirectory(TEST_DISTRIBUTION_PATH.toFile()); - } - - /** - * Create Settings.toml inside the home repository. - * - * @param dirPath Path to directory for creating settings.toml. - * @throws IOException i/o exception when writing to file. - */ - static void createSettingToml(Path dirPath) throws IOException { - String content = "[central]\n accesstoken = \"" + getToken() + "\""; - Files.write(dirPath.resolve("Settings.toml"), content.getBytes(), StandardOpenOption.CREATE, - StandardOpenOption.TRUNCATE_EXISTING); - } - - /** - * Get token of ballerina-central-bot required to push the module. - * - * @return token required to push the module. - */ - private static String getToken() { - // staging and dev both has the same access token - return System.getenv("devCentralToken"); - } - - /** - * Get environment variables and add ballerina_home as a env variable the tmp directory. - * - * @return env directory variable array - */ - static Map getEnvVariables() { - Map envVarMap = System.getenv(); - Map retMap = new HashMap<>(); - envVarMap.forEach(retMap::put); - return retMap; - } - - /** - * Delete files inside directories. - * - * @throws IOException throw an exception if an issue occurs - */ - static void deleteFiles() throws IOException { - if (sourceDirectory == null && tempHomeDirectory == null) { - return; - } - if (sourceDirectory != null) { - Files.walk(sourceDirectory).sorted(Comparator.reverseOrder()).forEach(path -> { - try { - Files.delete(path); - } catch (IOException e) { - Assert.fail(e.getMessage(), e); - } - }); - } - if (tempHomeDirectory != null) { - Files.walk(tempHomeDirectory).sorted(Comparator.reverseOrder()).forEach(path -> { - try { - Files.delete(path); - } catch (IOException e) { - Assert.fail(e.getMessage(), e); - } - }); - } - } - - /** - * Get environment variables and add ballerina_home as a env variable the tmp directory. - * - * @return env directory variable array - */ - public static Map addEnvVariables(Map envVariables) throws IOException { - Path tempHomeDirectory = Files.createTempDirectory("bal-test-integration-packaging-home-"); - envVariables.put(BALLERINA_HOME_DIR, tempHomeDirectory.toString()); - envVariables.put(BALLERINA_DEV_CENTRAL, "true"); - return envVariables; - } - - /** - * Get executable jar path. - * - * @param projectPath project path - * @param pkgName package name - * @return executable jar path - */ - static Path getExecutableJarPath(Path projectPath, String pkgName) { - return projectPath.resolve("target").resolve("bin").resolve(pkgName + ".jar"); - } -} diff --git a/devtools-integration-tests/src/test/resources/testng.xml b/devtools-integration-tests/src/test/resources/testng.xml index be5055e339..4e1d336aa5 100644 --- a/devtools-integration-tests/src/test/resources/testng.xml +++ b/devtools-integration-tests/src/test/resources/testng.xml @@ -22,8 +22,6 @@ - - diff --git a/gradle.properties b/gradle.properties index 7606046096..3d7ae6d6e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ group=org.ballerinalang version=2201.9.4-SNAPSHOT codeName=swan-lake -ballerinaLangVersion=2201.9.3 +ballerinaLangVersion=2201.9.4-20240816-221000-362fba7c ballerinaJreVersion=2.0.0 dependencyJREVersion=jdk-17.0.7+7-jre specVersion=2024R1 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 7d60a8c40b..62ac077431 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 @@ -18,8 +18,13 @@ package org.ballerina.projectapi; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import io.ballerina.projects.BalToolsManifest; import io.ballerina.projects.BalToolsToml; +import io.ballerina.projects.JvmTarget; import io.ballerina.projects.internal.BalToolsManifestBuilder; import io.ballerina.projects.util.ProjectUtils; import org.apache.commons.lang3.tuple.Pair; @@ -28,60 +33,73 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; +import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import java.util.zip.ZipOutputStream; import static io.ballerina.projects.util.ProjectConstants.BALA_DIR_NAME; import static io.ballerina.projects.util.ProjectConstants.CENTRAL_REPOSITORY_CACHE_NAME; import static io.ballerina.projects.util.ProjectConstants.REPOSITORIES_DIR; -import static org.ballerina.projectapi.CentralTestUtils.BALLERINA_DEV_CENTRAL; import static org.ballerina.projectapi.CentralTestUtils.OUTPUT_NOT_CONTAINS_EXP_MSG; +import static org.ballerina.projectapi.CentralTestUtils.createSettingToml; import static org.ballerina.projectapi.CentralTestUtils.getEnvVariables; import static org.ballerina.projectapi.CentralTestUtils.getString; -import static org.ballerina.projectapi.CentralTestUtils.isToolAvailableInCentral; import static org.ballerina.projectapi.TestUtils.DISTRIBUTION_FILE_NAME; import static org.ballerina.projectapi.TestUtils.OUTPUT_CONTAIN_ERRORS; import static org.ballerina.projectapi.TestUtils.executeCommand; import static org.ballerina.projectapi.TestUtils.executeHelpCommand; +import static org.ballerina.projectapi.TestUtils.executePackCommand; +import static org.ballerina.projectapi.TestUtils.executePushCommand; import static org.ballerina.projectapi.TestUtils.executeToolCommand; public class BalToolTest { private Path tempWorkspaceDirectory; - private final String orgName = "bctestorg"; - private static final String toolId = "disttest"; - private static final String nonExistingTool = "disttest2"; - private static final String latestVersion = "1.1.0"; - private static final String specificVersion = "1.0.0"; - 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; + static final String ORG_NAME = "bctestorg"; + static final String TOOL_ID = "disttest"; + static final String PACKAGE_NAME = "disttestpackage"; + static final String NON_EXISTING_TOOL = "disttest2"; + static final String LATEST_VERSION = "1.1.0"; + static final String SPECIFIC_VERSION = "1.0.0"; + static final String PATCH_VERSION = "1.0.1"; + static final String NON_EXISTING_VERSION = "1.0.3"; + static final String INCOMPATIBLE_DIST_VERSION = "1.0.4"; + static final String PULL = "pull"; + static final String REMOVE = "remove"; + static final String UPDATE = "update"; + static final String USE = "use"; + static final String LIST = "list"; + static final String SEARCH = "search"; + @BeforeClass() public void setUp() throws IOException, InterruptedException { TestUtils.setupDistributions(); - tempWorkspaceDirectory = Files.createTempDirectory("bal-test-integration-packaging-workspace-"); - setToolEnvironmentsForSubCommands(); - Map envVariables = getEnvVariables(); - envVariables.put(BALLERINA_DEV_CENTRAL, "true"); - if (!isToolAvailableInCentral(toolId, tempWorkspaceDirectory, envVariables)) { - Assert.fail("Tool " + toolId + " is not available in central"); - } + Path tempHomeDirectory = Files.createTempDirectory("bal-test-integration-packaging-home-"); + this.tempWorkspaceDirectory = Files.createTempDirectory("bal-test-integration-packaging-workspace-"); + createSettingToml(tempHomeDirectory); + this.toolEnvironments = setToolEnvironmentsForSubCommands(); + Map envVariables = TestUtils.addEnvVariables(getEnvVariables(), tempHomeDirectory); + copyTestResourcesToTempWorkspace(); + pushToolPackages(envVariables); } @BeforeGroups(value = "pull") @@ -89,12 +107,12 @@ public void setupPullTests() { // Remove the tool from bal-tools.toml if exists BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.PULL).balToolsTomlPath); BalToolsManifest balToolsManifest = BalToolsManifestBuilder.from(balToolsToml).build(); - balToolsManifest.removeTool(toolId); + balToolsManifest.removeTool(TOOL_ID); balToolsToml.modify(balToolsManifest); // Delete the tool from local cache if exists Path toolPath = toolEnvironments.get(ToolSubCommand.PULL).centralCachePath - .resolve(Path.of(orgName, packageName)); + .resolve(Path.of(ORG_NAME, PACKAGE_NAME)); if (Files.exists(toolPath)) { ProjectUtils.deleteDirectory(toolPath); } @@ -103,7 +121,7 @@ public void setupPullTests() { @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, TOOL_ID)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { Assert.fail(OUTPUT_CONTAIN_ERRORS + cmdErrors); @@ -119,35 +137,36 @@ public void testPullToolWithoutVersion() throws IOException, InterruptedExceptio // 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); + .getActiveTool(TOOL_ID); if (toolOpt.isEmpty()) { - Assert.fail("Tool " + toolId + " is not available in bal-tools.toml"); + Assert.fail("Tool " + TOOL_ID + " is not available in bal-tools.toml"); } BalToolsManifest.Tool tool = toolOpt.get(); - Assert.assertEquals(tool.id(), toolId); - Assert.assertEquals(tool.version(), latestVersion); - Assert.assertEquals(tool.org(), orgName); - Assert.assertEquals(tool.name(), packageName); + Assert.assertEquals(tool.id(), TOOL_ID); + Assert.assertEquals(tool.version(), LATEST_VERSION); + Assert.assertEquals(tool.org(), ORG_NAME); + Assert.assertEquals(tool.name(), PACKAGE_NAME); // 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)) { - Assert.fail("Tool " + toolId + ":" + latestVersion + " is not available in local cache"); + Assert.fail("Tool " + TOOL_ID + ":" + LATEST_VERSION + " is not available in local cache"); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.PULL).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.PULL).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); } @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, TOOL_ID)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { Assert.fail(OUTPUT_CONTAIN_ERRORS + cmdErrors); @@ -155,7 +174,8 @@ public void testPullToolAgainWithoutVersion() throws IOException, InterruptedExc // Validate the command output String cmdOutput = getString(cmdExec.getInputStream()); - String expectedOutput = readExpectedCmdOutsAsString("tool-pull-again-without-version.txt"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-pull-again-without-version.txt"); if (!cmdOutput.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } @@ -163,34 +183,35 @@ public void testPullToolAgainWithoutVersion() throws IOException, InterruptedExc // 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); + .getActiveTool(TOOL_ID); if (toolOpt.isEmpty()) { - Assert.fail("Tool " + toolId + " is not available in bal-tools.toml"); + Assert.fail("Tool " + TOOL_ID + " is not available in bal-tools.toml"); } BalToolsManifest.Tool tool = toolOpt.get(); - Assert.assertEquals(tool.id(), toolId); - Assert.assertEquals(tool.version(), latestVersion); - Assert.assertEquals(tool.org(), orgName); - Assert.assertEquals(tool.name(), packageName); + Assert.assertEquals(tool.id(), TOOL_ID); + Assert.assertEquals(tool.version(), LATEST_VERSION); + Assert.assertEquals(tool.org(), ORG_NAME); + Assert.assertEquals(tool.name(), PACKAGE_NAME); // 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)) { - Assert.fail("Tool " + toolId + ":" + latestVersion + " is not available in local cache"); + Assert.fail("Tool " + TOOL_ID + ":" + LATEST_VERSION + " is not available in local cache"); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.PULL).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.PULL).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); } @Test(description = "Pull a tool with a specific version", dependsOnMethods = {"testPullToolAgainWithoutVersion"}, groups = {"pull"}) public void testPullToolWithASpecificVersion() throws IOException, InterruptedException { - String toolIdAndVersion = toolId + ":" + specificVersion; + String toolIdAndVersion = TOOL_ID + ":" + SPECIFIC_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(Arrays.asList(PULL, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); @@ -201,7 +222,8 @@ public void testPullToolWithASpecificVersion() throws IOException, InterruptedEx // Validate the command output String cmdOutput = getString(cmdExec.getInputStream()); - String expectedOutput = readExpectedCmdOutsAsString("tool-pull-with-specific-version.txt"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-pull-with-specific-version.txt"); if (!cmdOutput.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } @@ -209,34 +231,35 @@ public void testPullToolWithASpecificVersion() throws IOException, InterruptedEx // 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); + .getActiveTool(TOOL_ID); if (toolOpt.isEmpty()) { - Assert.fail("Tool " + toolId + " is not available in bal-tools.toml"); + Assert.fail("Tool " + TOOL_ID + " is not available in bal-tools.toml"); } BalToolsManifest.Tool tool = toolOpt.get(); - Assert.assertEquals(tool.id(), toolId); - Assert.assertEquals(tool.version(), specificVersion); - Assert.assertEquals(tool.org(), orgName); - Assert.assertEquals(tool.name(), packageName); + Assert.assertEquals(tool.id(), TOOL_ID); + Assert.assertEquals(tool.version(), SPECIFIC_VERSION); + Assert.assertEquals(tool.org(), ORG_NAME); + Assert.assertEquals(tool.name(), PACKAGE_NAME); // 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)) { - Assert.fail("Tool " + toolId + ":" + specificVersion + " is not available in local cache"); + Assert.fail("Tool " + TOOL_ID + ":" + SPECIFIC_VERSION + " is not available in local cache"); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.PULL).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.PULL).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString( + "tool-execute-specific-help-1.0.0.txt")); } @Test(description = "Pull a tool again with a specific version", dependsOnMethods = "testPullToolWithASpecificVersion", groups = {"pull"}) public void testPullToolAgainWithASpecificVersion() throws IOException, InterruptedException { - String toolIdAndVersion = toolId + ":" + specificVersion; + String toolIdAndVersion = TOOL_ID + ":" + SPECIFIC_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(Arrays.asList(PULL, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.PULL).envVariables); @@ -247,7 +270,8 @@ public void testPullToolAgainWithASpecificVersion() throws IOException, Interrup // Validate the command output String cmdOutput = getString(cmdExec.getInputStream()); - String expectedOutput = readExpectedCmdOutsAsString("tool-pull-again-with-specific-version.txt"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-pull-again-with-specific-version.txt"); if (!cmdOutput.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } @@ -255,39 +279,41 @@ public void testPullToolAgainWithASpecificVersion() throws IOException, Interrup // 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); + .getActiveTool(TOOL_ID); if (toolOpt.isEmpty()) { - Assert.fail("Tool " + toolId + " is not available in bal-tools.toml"); + Assert.fail("Tool " + TOOL_ID + " is not available in bal-tools.toml"); } BalToolsManifest.Tool tool = toolOpt.get(); - Assert.assertEquals(tool.id(), toolId); - Assert.assertEquals(tool.version(), specificVersion); - Assert.assertEquals(tool.org(), orgName); - Assert.assertEquals(tool.name(), packageName); + Assert.assertEquals(tool.id(), TOOL_ID); + Assert.assertEquals(tool.version(), SPECIFIC_VERSION); + Assert.assertEquals(tool.org(), ORG_NAME); + Assert.assertEquals(tool.name(), PACKAGE_NAME); // 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)) { - Assert.fail("Tool " + toolId + ":" + specificVersion + " is not available in local cache"); + Assert.fail("Tool " + TOOL_ID + ":" + SPECIFIC_VERSION + " is not available in local cache"); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.PULL).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.PULL).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString( + "tool-execute-specific-help-1.0.0.txt")); } @Test(description = "Pull a tool with a non existing version", dependsOnMethods = "testPullToolWithASpecificVersion", groups = {"pull"}) public void testPullToolWithANonExistingVersion() throws IOException, InterruptedException { - String toolIdAndVersion = toolId + ":" + nonExistingVersion; + String toolIdAndVersion = TOOL_ID + ":" + NON_EXISTING_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, 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"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-pull-with-non-existing-version.txt"); if (!cmdErrors.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdErrors); } @@ -295,60 +321,63 @@ public void testPullToolWithANonExistingVersion() throws IOException, Interrupte // 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, null); + .getTool(TOOL_ID, NON_EXISTING_VERSION, 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)); + .resolve(Path.of(ORG_NAME, TOOL_ID, NON_EXISTING_VERSION)); if (Files.exists(toolVersionCachePath)) { - Assert.fail("Tool " + toolId + ":" + nonExistingVersion + " should not be available in local cache"); + Assert.fail("Tool " + TOOL_ID + ":" + NON_EXISTING_VERSION + " should not be available in local cache"); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.PULL).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.PULL).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString( + "tool-execute-specific-help-1.0.0.txt")); } @Test(description = "Pull a tool version with incompatible distribution", dependsOnMethods = "testPullToolWithASpecificVersion", groups = {"pull"}) public void testPullAToolVersionWithIncompatibleDistribution() throws IOException, InterruptedException { - String toolIdAndVersion = toolId + ":" + incompatibleDistVersion; + String toolIdAndVersion = TOOL_ID + ":" + INCOMPATIBLE_DIST_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, 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"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-pull-with-incompatible-dist.txt"); if (!cmdErrors.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdErrors); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.PULL).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.PULL).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString( + "tool-execute-specific-help-1.0.0.txt")); } @BeforeGroups(value = "remove") public void setupRemoveTests() throws IOException, InterruptedException { // Pull a specific version of a tool - String specificToolVersion = toolId + ":" + specificVersion; + String specificToolVersion = TOOL_ID + ":" + SPECIFIC_VERSION; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, 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, TOOL_ID)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); // Pull tool version with incompatible distribution - String incompToolVersion = toolId + ":" + incompatibleDistVersion; + String incompToolVersion = TOOL_ID + ":" + INCOMPATIBLE_DIST_VERSION; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(Arrays.asList(PULL, incompToolVersion)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); @@ -356,69 +385,75 @@ public void setupRemoveTests() throws IOException, InterruptedException { // 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, null); + balToolsManifest.addTool(TOOL_ID, ORG_NAME, PACKAGE_NAME, INCOMPATIBLE_DIST_VERSION, false, null); balToolsToml.modify(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, NON_EXISTING_TOOL)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); // Validate the command output String cmdErrors = getString(cmdExec.getErrorStream()); - String expectedOutput = readExpectedCmdOutsAsString("tool-remove-non-existing-tool.txt"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-remove-non-existing-tool.txt"); if (!cmdErrors.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdErrors); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - nonExistingTool, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); + NON_EXISTING_TOOL, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); Assert.assertEquals( - outputs.getLeft(), readExpectedCmdOutsAsString("tool-execute-unknown-cmd-non-existing.txt")); - Assert.assertEquals("", outputs.getRight()); + outputs.getLeft(), + readExpectedCmdOutsAsString("tool-execute-unknown-cmd-non-existing.txt")); + Assert.assertEquals(outputs.getRight(), ""); } @Test(description = "Remove a non existing version of a tool", groups = {"remove"}) public void testRemoveANonExistingVersionOfATool() throws IOException, InterruptedException { - String toolIdAndVersion = toolId + ":" + nonExistingVersion; + String toolIdAndVersion = TOOL_ID + ":" + NON_EXISTING_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, 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"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-remove-non-existing-version.txt"); if (!cmdErrors.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdErrors); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); } @Test(description = "Remove a tool version with incompatible distribution", groups = {"remove"}) public void testRemoveToolVersionWithIncompatibleDistribution() throws IOException, InterruptedException { - String toolIdAndVersion = toolId + ":" + incompatibleDistVersion; + String toolIdAndVersion = TOOL_ID + ":" + INCOMPATIBLE_DIST_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, 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"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-remove-with-incompatible-dist.txt"); if (!cmdErrors.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdErrors); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); } @Test(description = "Remove a tool version with incompatible distribution", groups = {"remove"}) @@ -426,11 +461,11 @@ 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, null); + balToolsManifest.setActiveToolVersion(TOOL_ID, LATEST_VERSION, null); balToolsToml.modify(balToolsManifest); // Remove the active version - String toolIdAndVersion = toolId + ":" + latestVersion; + String toolIdAndVersion = TOOL_ID + ":" + LATEST_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(Arrays.asList(REMOVE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); @@ -442,9 +477,10 @@ public void testRemoveToolActiveVersion() throws IOException, InterruptedExcepti // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); } @Test(description = "Remove a specific tool version", @@ -455,13 +491,13 @@ 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, null); + balToolsManifest.setActiveToolVersion(TOOL_ID, LATEST_VERSION, null); balToolsToml.modify(balToolsManifest); - String toolIdAndVersion = toolId + ":" + specificVersion; + String toolIdAndVersion = TOOL_ID + ":" + SPECIFIC_VERSION; // Check for tool availability in bal-tools.toml - Optional toolOpt = balToolsManifest.getTool(toolId, specificVersion, null); + Optional toolOpt = balToolsManifest.getTool(TOOL_ID, SPECIFIC_VERSION, null); if (toolOpt.isEmpty()) { Assert.fail("Tool '" + toolIdAndVersion + "' is not available to be removed"); } @@ -476,30 +512,32 @@ public void testRemoveASpecificToolVersion() throws IOException, InterruptedExce // Validate the command output String cmdOutput = getString(cmdExec.getInputStream()); - String expectedOutput = readExpectedCmdOutsAsString("tool-remove-specific-version.txt"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-remove-specific-version.txt"); if (!cmdOutput.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } // Check for tool availability in bal-tools.toml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.REMOVE).balToolsTomlPath); - toolOpt = BalToolsManifestBuilder.from(balToolsToml).build().getTool(toolId, specificVersion, null); + toolOpt = BalToolsManifestBuilder.from(balToolsToml).build().getTool(TOOL_ID, SPECIFIC_VERSION, 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)); + .resolve(Path.of(ORG_NAME, PACKAGE_NAME, SPECIFIC_VERSION)); if (Files.exists(toolVersionCachePath)) { Assert.fail("Tool '" + toolIdAndVersion + "' is available in local cache"); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); } @Test(description = "Remove all tool versions", dependsOnMethods = {"testRemoveASpecificToolVersion"}, @@ -508,14 +546,14 @@ public void testRemoveAllToolVersions() throws IOException, InterruptedException // 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); + .getActiveTool(TOOL_ID); if (toolOpt.isEmpty()) { - Assert.fail("Tool '" + toolId + "' is not available to be removed"); + Assert.fail("Tool '" + TOOL_ID + "' 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, TOOL_ID)), toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { @@ -531,35 +569,36 @@ public void testRemoveAllToolVersions() throws IOException, InterruptedException // Check for tool availability in bal-tools.toml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.REMOVE).balToolsTomlPath); - toolOpt = BalToolsManifestBuilder.from(balToolsToml).build().getActiveTool(toolId); + toolOpt = BalToolsManifestBuilder.from(balToolsToml).build().getActiveTool(TOOL_ID); if (toolOpt.isPresent()) { - Assert.fail("Tool " + toolId + " is available in bal-tools.toml"); + Assert.fail("Tool " + TOOL_ID + " 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)); + .resolve(Path.of(ORG_NAME, PACKAGE_NAME)); if (Files.exists(toolVersionCachePath)) { - Assert.fail("Tool '" + toolId + "' is available in local cache"); + Assert.fail("Tool '" + TOOL_ID + "' is available in local cache"); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); - Assert.assertEquals(outputs.getLeft(), readExpectedCmdOutsAsString("tool-execute-unknown-cmd.txt")); - Assert.assertEquals("", outputs.getRight()); + TOOL_ID, toolEnvironments.get(ToolSubCommand.REMOVE).envVariables); + Assert.assertEquals(outputs.getLeft(), + readExpectedCmdOutsAsString("tool-execute-unknown-cmd.txt")); + Assert.assertEquals(outputs.getRight(), ""); } @BeforeGroups(value = "update") 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, TOOL_ID)), toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); getString(cmdExec.getErrorStream()); // Pull an older version of the tool - String toolIdAndVersion = toolId + ":" + specificVersion; + String toolIdAndVersion = TOOL_ID + ":" + SPECIFIC_VERSION; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(Arrays.asList(PULL, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); @@ -568,7 +607,7 @@ public void setupUpdateTests() throws IOException, InterruptedException { @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, NON_EXISTING_TOOL)), toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); String expectedOutput = readExpectedCmdOutsAsString("tool-update-non-existing.txt"); @@ -579,17 +618,18 @@ public void testUpdateNonExistingTool() throws IOException, InterruptedException // Check for tool availability in bal-tools.toml BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.UPDATE).balToolsTomlPath); Optional toolOpt = BalToolsManifestBuilder.from(balToolsToml).build() - .getActiveTool(nonExistingTool); + .getActiveTool(NON_EXISTING_TOOL); if (toolOpt.isPresent()) { - Assert.fail("Tool " + nonExistingTool + " should not be available in bal-tools.toml"); + Assert.fail("Tool " + NON_EXISTING_TOOL + " should not be available in bal-tools.toml"); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - nonExistingTool, toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); + NON_EXISTING_TOOL, toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); Assert.assertEquals( - outputs.getLeft(), readExpectedCmdOutsAsString("tool-execute-unknown-cmd-non-existing.txt")); - Assert.assertEquals("", outputs.getRight()); + outputs.getLeft(), + readExpectedCmdOutsAsString("tool-execute-unknown-cmd-non-existing.txt")); + Assert.assertEquals(outputs.getRight(), ""); } @Test(description = "Update a tool with new patch and minor versions", groups = {"update"}) @@ -597,8 +637,8 @@ public void testUpdateToolWithNewPatchAndMinor() throws IOException, Interrupted // Check for tool availability in bal-tools.toml BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.UPDATE).balToolsTomlPath); Optional toolOpt = BalToolsManifestBuilder.from(balToolsToml).build() - .getActiveTool(toolId); - String toolIdAndVersion = toolId + ":" + specificVersion; + .getActiveTool(TOOL_ID); + String toolIdAndVersion = TOOL_ID + ":" + SPECIFIC_VERSION; if (toolOpt.isEmpty()) { Assert.fail("Tool '" + toolIdAndVersion + "' should be the current version in bal-tools.toml before update command"); @@ -606,7 +646,7 @@ public void testUpdateToolWithNewPatchAndMinor() throws IOException, Interrupted // Update the tool Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(Arrays.asList(UPDATE, toolId)), + new ArrayList<>(Arrays.asList(UPDATE, TOOL_ID)), toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); @@ -616,31 +656,33 @@ public void testUpdateToolWithNewPatchAndMinor() throws IOException, Interrupted // Validate the command output String cmdOutput = getString(cmdExec.getInputStream()); - String expectedOutput = readExpectedCmdOutsAsString("tool-update-with-new-patch-and-minor.txt"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-update-with-new-patch-and-minor.txt"); if (!cmdOutput.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } // Check for tool availability in bal-tools.toml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.UPDATE).balToolsTomlPath); - toolOpt = BalToolsManifestBuilder.from(balToolsToml).build().getActiveTool(toolId); - toolIdAndVersion = toolId + ":" + latestVersion; + toolOpt = BalToolsManifestBuilder.from(balToolsToml).build().getActiveTool(TOOL_ID); + toolIdAndVersion = TOOL_ID + ":" + LATEST_VERSION; if (toolOpt.isEmpty()) { Assert.fail("Tool '" + toolIdAndVersion + "' is not available in bal-tools.toml"); } // Check for tool availability in local cache Path toolVersionCachePath = toolEnvironments.get(ToolSubCommand.UPDATE).centralCachePath - .resolve(Path.of(orgName, packageName, latestVersion)); + .resolve(Path.of(ORG_NAME, PACKAGE_NAME, LATEST_VERSION)); if (!Files.exists(toolVersionCachePath)) { Assert.fail("Tool '" + toolIdAndVersion + "' is not available in local cache"); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); } @Test(description = "Update a tool with no new versions", @@ -649,15 +691,15 @@ public void testUpdateToolWithNoNewVersions() throws IOException, InterruptedExc // Check for tool availability in bal-tools.toml BalToolsToml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.UPDATE).balToolsTomlPath); Optional toolOpt = BalToolsManifestBuilder.from(balToolsToml).build() - .getActiveTool(toolId); - String toolIdAndVersion = toolId + ":" + latestVersion; + .getActiveTool(TOOL_ID); + String toolIdAndVersion = TOOL_ID + ":" + LATEST_VERSION; if (toolOpt.isEmpty()) { 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, TOOL_ID)), toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); @@ -667,40 +709,42 @@ public void testUpdateToolWithNoNewVersions() throws IOException, InterruptedExc // Validate the command output String cmdOutput = getString(cmdExec.getInputStream()); - String expectedOutput = readExpectedCmdOutsAsString("tool-update-with-no-new-version.txt"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-update-with-no-new-version.txt"); if (!cmdOutput.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } // Check for tool availability in bal-tools.toml balToolsToml = BalToolsToml.from(toolEnvironments.get(ToolSubCommand.UPDATE).balToolsTomlPath); - toolOpt = BalToolsManifestBuilder.from(balToolsToml).build().getActiveTool(toolId); - toolIdAndVersion = toolId + ":" + latestVersion; + toolOpt = BalToolsManifestBuilder.from(balToolsToml).build().getActiveTool(TOOL_ID); + toolIdAndVersion = TOOL_ID + ":" + LATEST_VERSION; if (toolOpt.isEmpty()) { Assert.fail("Tool '" + toolIdAndVersion + "' is not available in bal-tools.toml"); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.UPDATE).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); } @BeforeGroups(value = "use") 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, TOOL_ID)), toolEnvironments.get(ToolSubCommand.USE).envVariables); // Pull a specific version of a tool - String specificToolVersion = toolId + ":" + specificVersion; + String specificToolVersion = TOOL_ID + ":" + SPECIFIC_VERSION; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(Arrays.asList(PULL, specificToolVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); // Pull tool version with incompatible distribution - String incompToolVersion = toolId + ":" + incompatibleDistVersion; + String incompToolVersion = TOOL_ID + ":" + INCOMPATIBLE_DIST_VERSION; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(Arrays.asList(PULL, incompToolVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); @@ -708,13 +752,13 @@ public void setupUseTests() throws IOException, InterruptedException { // 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, null); + balToolsManifest.addTool(TOOL_ID, ORG_NAME, PACKAGE_NAME, INCOMPATIBLE_DIST_VERSION, false, null); balToolsToml.modify(balToolsManifest); } @Test(description = "Use a newer tool version", groups = {"use"}) public void testUseNewToolVersion() throws IOException, InterruptedException { - String toolIdAndVersion = toolId + ":" + latestVersion; + String toolIdAndVersion = TOOL_ID + ":" + LATEST_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(Arrays.asList(USE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); @@ -732,14 +776,15 @@ public void testUseNewToolVersion() throws IOException, InterruptedException { // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.USE).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.USE).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt")); } @Test(description = "Use a newer tool version", dependsOnMethods = {"testUseNewToolVersion"}, groups = {"use"}) public void testUseOldToolVersion() throws IOException, InterruptedException { - String toolIdAndVersion = toolId + ":" + specificVersion; + String toolIdAndVersion = TOOL_ID + ":" + SPECIFIC_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(Arrays.asList(USE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); @@ -757,15 +802,16 @@ public void testUseOldToolVersion() throws IOException, InterruptedException { // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.USE).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.USE).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); } @Test(description = "Use the currently active tool version", dependsOnMethods = {"testUseOldToolVersion"}, groups = {"use"}) public void testUseCurrentlyActiveToolVersion() throws IOException, InterruptedException { - String toolIdAndVersion = toolId + ":" + specificVersion; + String toolIdAndVersion = TOOL_ID + ":" + SPECIFIC_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(Arrays.asList(USE, toolIdAndVersion)), toolEnvironments.get(ToolSubCommand.USE).envVariables); @@ -783,56 +829,61 @@ public void testUseCurrentlyActiveToolVersion() throws IOException, InterruptedE // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.USE).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.USE).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); } @Test(description = "Use a non existent tool version", dependsOnMethods = {"testUseCurrentlyActiveToolVersion"}, groups = {"use"}) public void testUseNonExistentToolVersion() throws IOException, InterruptedException { - String toolIdAndVersion = toolId + ":" + nonExistingVersion; + String toolIdAndVersion = TOOL_ID + ":" + NON_EXISTING_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, 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"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-use-non-existent-version.txt"); if (!cmdErrors.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdErrors); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.USE).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.USE).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); } @Test(description = "Use a tool version built with incompatible distribution", dependsOnMethods = "testUseNonExistentToolVersion", groups = {"use"}) public void testUseToolVersionWithIncompatibleDistribution() throws IOException, InterruptedException { - String toolIdAndVersion = toolId + ":" + incompatibleDistVersion; + String toolIdAndVersion = TOOL_ID + ":" + INCOMPATIBLE_DIST_VERSION; Process cmdExec = executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, 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"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-use-with-incompatible-dist.txt"); if (!cmdErrors.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdErrors); } // Execute the tool Pair outputs = executeHelpFlagOfTool( - toolId, toolEnvironments.get(ToolSubCommand.USE).envVariables); - Assert.assertEquals("", outputs.getLeft()); - Assert.assertEquals(outputs.getRight(), readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); + TOOL_ID, toolEnvironments.get(ToolSubCommand.USE).envVariables); + Assert.assertEquals(outputs.getLeft(), ""); + Assert.assertEquals(outputs.getRight(), + readExpectedCmdOutsAsString("tool-execute-specific-help-1.0.0.txt")); } @Test(description = "List all tools when there are no tools", groups = {"list"}) 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, TOOL_ID)), toolEnvironments.get(ToolSubCommand.LIST).envVariables); // List all tools @@ -855,10 +906,10 @@ 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, TOOL_ID)), toolEnvironments.get(ToolSubCommand.LIST).envVariables); // Pull a specific version of a tool - String specificToolVersion = toolId + ":" + specificVersion; + String specificToolVersion = TOOL_ID + ":" + SPECIFIC_VERSION; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(Arrays.asList(PULL, specificToolVersion)), toolEnvironments.get(ToolSubCommand.LIST).envVariables); @@ -873,7 +924,8 @@ public void testListToolsWithMultipleToolVersions() throws IOException, Interrup // Validate the command output String cmdOutput = getString(cmdExec.getInputStream()); - String expectedOutput = readExpectedCmdOutsAsString("tool-list-with-multiple-tool-versions.txt"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-list-with-multiple-tool-versions.txt"); if (!cmdOutput.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } @@ -882,7 +934,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, TOOL_ID)), toolEnvironments.get(ToolSubCommand.SEARCH).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { @@ -900,14 +952,14 @@ public void testSearchAToolWithId() throws IOException, InterruptedException { @BeforeGroups(value = "execute_tool") public void setupExecuteToolTests() throws IOException, InterruptedException { // Pull a specific version of a tool - String specificToolVersion = toolId + ":" + specificVersion; + String specificToolVersion = TOOL_ID + ":" + SPECIFIC_VERSION; executeToolCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, 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, TOOL_ID)), toolEnvironments.get(ToolSubCommand.EXECUTE).envVariables); } @@ -931,7 +983,7 @@ public void testExecuteGeneralHelpWithToolInstalled() throws IOException, Interr @Test(description = "Execute bal help disttest with the tool installed", groups = {"execute_tool"}) public void testExecuteToolSpecificHelpWithToolInstalled() throws IOException, InterruptedException { Process cmdExec = executeHelpCommand(DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, - new ArrayList<>(List.of(toolId)), toolEnvironments.get(ToolSubCommand.EXECUTE).envVariables); + new ArrayList<>(List.of(TOOL_ID)), toolEnvironments.get(ToolSubCommand.EXECUTE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { Assert.fail(OUTPUT_CONTAIN_ERRORS + cmdErrors); @@ -939,7 +991,8 @@ public void testExecuteToolSpecificHelpWithToolInstalled() throws IOException, I // Validate the command output String cmdOutput = getString(cmdExec.getInputStream()); - String expectedOutput = readExpectedCmdOutsAsString("tool-execute-specific-help-1.1.0.txt"); + String expectedOutput = readExpectedCmdOutsAsString( + "tool-execute-specific-help-1.1.0.txt"); if (!cmdOutput.contains(expectedOutput)) { Assert.fail(OUTPUT_NOT_CONTAINS_EXP_MSG + expectedOutput + "\nactual output:" + cmdOutput); } @@ -947,7 +1000,7 @@ public void testExecuteToolSpecificHelpWithToolInstalled() throws IOException, I @Test(description = "Execute disstest tool", groups = {"execute_tool"}) public void testExecuteTool() throws IOException, InterruptedException { - Process cmdExec = executeCommand(toolId, DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, + Process cmdExec = executeCommand(TOOL_ID, DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, new ArrayList<>(List.of("arg1")), toolEnvironments.get(ToolSubCommand.EXECUTE).envVariables); String cmdErrors = getString(cmdExec.getErrorStream()); if (!cmdErrors.isEmpty()) { @@ -962,18 +1015,8 @@ public void testExecuteTool() throws IOException, InterruptedException { } } - private static String readExpectedCmdOutsAsString(String outputFileName) { - try { - return Files.readString(Path.of(Objects.requireNonNull( - BalToolTest.class.getClassLoader().getResource( - Path.of("bal-tool/cmd-outputs/").resolve(outputFileName).toString())).toURI())); - } catch (IOException | URISyntaxException e) { - throw new RuntimeException("Error reading resource file"); - } - } - - private void setToolEnvironmentsForSubCommands() { - toolEnvironments = Arrays.stream(ToolSubCommand.values()).map( + private Map setToolEnvironmentsForSubCommands() { + return Arrays.stream(ToolSubCommand.values()).map( toolSubCommand -> { try { return getToolEnvironment(toolSubCommand); @@ -984,6 +1027,148 @@ private void setToolEnvironmentsForSubCommands() { toolEnvironment -> toolEnvironment.subCommand, toolEnvironment -> toolEnvironment)); } + private BalToolTest.ToolEnvironment getToolEnvironment(ToolSubCommand subCommand) throws IOException { + Path tempHomeDirectory = Files.createTempDirectory("bal-test-integration-packaging-home-"); + Map envVariables = TestUtils.addEnvVariables(getEnvVariables(), + tempHomeDirectory); + Path balToolsTomlPath = tempHomeDirectory.resolve(".config").resolve("bal-tools.toml"); + Path centralCachePath = tempHomeDirectory.resolve( + Path.of(REPOSITORIES_DIR, CENTRAL_REPOSITORY_CACHE_NAME, BALA_DIR_NAME)); + return new BalToolTest.ToolEnvironment(subCommand, envVariables, balToolsTomlPath, centralCachePath); + } + + private void copyTestResourcesToTempWorkspace() { + try { + URI testResourcesURI = Objects.requireNonNull(BalToolTest.class.getClassLoader().getResource("bal-tool")). + toURI(); + Path start = Paths.get(testResourcesURI); + Files.walkFileTree(start, new CentralTest.Copy(start, tempWorkspaceDirectory)); + } catch (URISyntaxException | IOException e) { + Assert.fail("error loading resources"); + } + } + + private void pushToolPackages(Map envVariables) throws IOException, InterruptedException { + for (String version : + Arrays.asList(SPECIFIC_VERSION, PATCH_VERSION, INCOMPATIBLE_DIST_VERSION, LATEST_VERSION)) { + Path packagePath = tempWorkspaceDirectory.resolve("v" + version).resolve(PACKAGE_NAME); + executePackCommand(DISTRIBUTION_FILE_NAME, packagePath, new LinkedList<>(), envVariables); + Optional balaPath = getBalaPath(packagePath, version); + if (balaPath.isEmpty()) { + Assert.fail("Bala file " + balaPath + " not found for " + TOOL_ID + ":" + version); + } + // This should make the tools incompatible with the current distribution for incompatible version tests, + // and compatible with the current distribution (>=U9) for other versions. + String balVersion = version.equals(INCOMPATIBLE_DIST_VERSION) ? "2201.99.0" : "2201.9.0"; + updateBallerinaVersionOfBala(balaPath.get(), balVersion); + Process build = executePushCommand(DISTRIBUTION_FILE_NAME, packagePath, new LinkedList<>(), envVariables); + String buildErrors = getString(build.getErrorStream()); + if (!buildErrors.isEmpty() && !buildErrors.contains("already exists")) { + Assert.fail(OUTPUT_CONTAIN_ERRORS + buildErrors); + } + } + } + + private Optional getBalaPath(Path packagePath, String version) { + Path balaRootPath = packagePath.resolve("target").resolve("bala"); + String balaNamePrefix = ORG_NAME + "-" + PACKAGE_NAME + "-"; + String balaNameSuffix = "-" + version + ".bala"; + for (JvmTarget jvmTarget : JvmTarget.values()) { + Path balaPath = balaRootPath.resolve(balaNamePrefix + jvmTarget.code() + balaNameSuffix); + if (Files.exists(balaPath)) { + return Optional.of(balaPath); + } + } + return Optional.empty(); + } + + private void updateBallerinaVersionOfBala(Path balaFilePath, String balVersion) throws IOException { + Path tempDir = Files.createTempDirectory(balaFilePath.getFileName().toString()); + try { + unzipBalaFile(balaFilePath, tempDir); + updatePackageJsonBallerinaVersion(tempDir, balVersion); + zipBalaFile(tempDir, balaFilePath); + } catch (IOException e) { + Assert.fail("Failed to update the ballerina version of the bala file", e); + } + } + + private void unzipBalaFile(Path balaFilePath, Path destDir) throws IOException { + File destDirFile = destDir.toFile(); + byte[] buffer = new byte[1024]; + try (ZipInputStream zis = new ZipInputStream(new FileInputStream(balaFilePath.toFile()))) { + ZipEntry zipEntry = zis.getNextEntry(); + while (zipEntry != null) { + File newFile = newFile(destDirFile, zipEntry); + if (zipEntry.isDirectory()) { + newFile.mkdirs(); + } else { + // Create all non-existing directories + new File(newFile.getParent()).mkdirs(); + try (FileOutputStream fos = new FileOutputStream(newFile)) { + int len; + while ((len = zis.read(buffer)) > 0) { + fos.write(buffer, 0, len); + } + } + } + zipEntry = zis.getNextEntry(); + } + zis.closeEntry(); + } + } + + private File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { + File destFile = new File(destinationDir, zipEntry.getName()); + String destDirPath = destinationDir.getCanonicalPath(); + String destFilePath = destFile.getCanonicalPath(); + if (!destFilePath.startsWith(destDirPath + File.separator)) { + throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); + } + return destFile; + } + + private void updatePackageJsonBallerinaVersion(Path packagePath, String balVersion) throws IOException { + Path packageJsonPath = packagePath.resolve("package.json"); + String content = Files.readString(packageJsonPath); + JsonObject jsonObject = JsonParser.parseString(content).getAsJsonObject(); + + // Update the value for the given key + jsonObject.addProperty("ballerina_version", balVersion); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String formattedJson = gson.toJson(jsonObject); + Files.writeString(packageJsonPath, formattedJson); + } + + private void zipBalaFile(Path sourceDirPath, Path zipFilePath) throws IOException { + Files.deleteIfExists(zipFilePath); + Path zipFile = Files.createFile(zipFilePath); + try (ZipOutputStream zs = new ZipOutputStream(Files.newOutputStream(zipFile)); + Stream walk = Files.walk(sourceDirPath)) { + walk.filter(path -> !Files.isDirectory(path)) + .forEach(path -> { + ZipEntry zipEntry = new ZipEntry(sourceDirPath.relativize(path).toString()); + try { + zs.putNextEntry(zipEntry); + Files.copy(path, zs); + zs.closeEntry(); + } catch (IOException e) { + throw new RuntimeException("\"Failed to re-zip bala with error: ", e); + } + }); + } + } + + private String readExpectedCmdOutsAsString(String outputFileName) { + try { + return Files.readString(Path.of(Objects.requireNonNull( + BalToolTest.class.getClassLoader().getResource( + Path.of("bal-tool/cmd-outputs/").resolve(outputFileName).toString())).toURI())); + } catch (IOException | URISyntaxException e) { + throw new RuntimeException("Error reading resource file"); + } + } + private Pair executeHelpFlagOfTool(String toolId, Map envVariables) throws IOException, InterruptedException { Process cmdExec = executeCommand(toolId, DISTRIBUTION_FILE_NAME, tempWorkspaceDirectory, @@ -993,16 +1178,6 @@ private Pair executeHelpFlagOfTool(String toolId, Map envVariables = TestUtils.addEnvVariables(getEnvVariables(), - tempHomeDirectory); - Path balToolsTomlPath = tempHomeDirectory.resolve(".config").resolve("bal-tools.toml"); - Path centralCachePath = tempHomeDirectory.resolve( - Path.of(REPOSITORIES_DIR, CENTRAL_REPOSITORY_CACHE_NAME, BALA_DIR_NAME)); - return new ToolEnvironment(subCommand, envVariables, balToolsTomlPath, centralCachePath); - } - static class ToolEnvironment { ToolSubCommand subCommand; Map envVariables; diff --git a/project-api-tests/src/test/java/org/ballerina/projectapi/BuildTimeTest.java b/project-api-tests/src/test/java/org/ballerina/projectapi/BuildTimeTest.java index 7f6c2a18c2..11326a88df 100644 --- a/project-api-tests/src/test/java/org/ballerina/projectapi/BuildTimeTest.java +++ b/project-api-tests/src/test/java/org/ballerina/projectapi/BuildTimeTest.java @@ -37,8 +37,8 @@ import java.util.Map; import java.util.Objects; -import static org.ballerina.projectapi.CentralTestUtils.BALLERINA_DEV_CENTRAL; import static org.ballerina.projectapi.CentralTestUtils.BALLERINA_HOME_DIR; +import static org.ballerina.projectapi.CentralTestUtils.TEST_MODE_ACTIVE; import static org.ballerina.projectapi.CentralTestUtils.createSettingToml; import static org.ballerina.projectapi.CentralTestUtils.deleteFiles; import static org.ballerina.projectapi.CentralTestUtils.getEnvVariables; @@ -107,7 +107,7 @@ public void testCodeGenOfflineResolution() throws IOException, InterruptedExcept */ private Map addEnvVariables(Map envVariables) { envVariables.put(BALLERINA_HOME_DIR, tempHome.toString()); - envVariables.put(BALLERINA_DEV_CENTRAL, "true"); + envVariables.put(TEST_MODE_ACTIVE, "true"); return envVariables; } diff --git a/project-api-tests/src/test/java/org/ballerina/projectapi/CentralTestUtils.java b/project-api-tests/src/test/java/org/ballerina/projectapi/CentralTestUtils.java index 658a9bd12e..434ac85be4 100644 --- a/project-api-tests/src/test/java/org/ballerina/projectapi/CentralTestUtils.java +++ b/project-api-tests/src/test/java/org/ballerina/projectapi/CentralTestUtils.java @@ -59,9 +59,11 @@ private CentralTestUtils() { static final String BALLERINA_HOME_DIR = "BALLERINA_HOME_DIR"; static final String BALLERINA_DEV_CENTRAL = "BALLERINA_DEV_CENTRAL"; + static final String TEST_MODE_ACTIVE = "TEST_MODE_ACTIVE"; static final String BALLERINA_CENTRAL_ACCESS_TOKEN = "BALLERINA_CENTRAL_ACCESS_TOKEN"; static final String BALLERINA_TOML = "Ballerina.toml"; static final String DEPENDENCIES_TOML = "Dependencies.toml"; + static final String BAL_TOOL_TOML = "BalTool.toml"; static final String MAIN_BAL = "main.bal"; static final String COMMON_VERSION = "1.0.0"; static final String TEST_PREFIX = "test_"; @@ -97,21 +99,30 @@ static String randomPackageName(int count) { * @throws IOException i/o exception when writing to file */ static void createSettingToml(Path dirPath) throws IOException { - String content = "[central]\n accesstoken = \"" + getToken() + "\""; + String content = "[central]\n accesstoken = \"" + getProdToken() + "\""; Files.write(dirPath.resolve("Settings.toml"), content.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } /** - * Get token of ballerina-central-bot required to push the module. + * Get token of ballerina-dev-central required to push the module. * * @return token required to push the module. */ - private static String getToken() { + private static String getDevToken() { // staging and dev both has the same access token return System.getenv("devCentralToken"); } + /** + * Get token of ballerina-central required to push the module. + * + * @return token required to push the module. + */ + private static String getProdToken() { + return System.getenv("prodCentralToken"); + } + /** * Get token of ballerina-bot required to dispatch GitHub workflows. * diff --git a/project-api-tests/src/test/java/org/ballerina/projectapi/TestUtils.java b/project-api-tests/src/test/java/org/ballerina/projectapi/TestUtils.java index 9ef83c35a5..67cc0ef516 100644 --- a/project-api-tests/src/test/java/org/ballerina/projectapi/TestUtils.java +++ b/project-api-tests/src/test/java/org/ballerina/projectapi/TestUtils.java @@ -30,8 +30,8 @@ import java.util.List; import java.util.Map; -import static org.ballerina.projectapi.CentralTestUtils.BALLERINA_DEV_CENTRAL; import static org.ballerina.projectapi.CentralTestUtils.BALLERINA_HOME_DIR; +import static org.ballerina.projectapi.CentralTestUtils.TEST_MODE_ACTIVE; /** * Utility class for tests. @@ -118,6 +118,12 @@ public static Process executeHelpCommand(String distributionName, Path sourceDir return executeCommand("help", distributionName, sourceDirectory, args, envProperties); } + public static Process executeNewCommand(String distributionName, Path sourceDirectory, + List args, Map envProperties) + throws IOException, InterruptedException { + return executeCommand("new", distributionName, sourceDirectory, args, envProperties); + } + /** * Clean and setup the distribution. * @@ -156,7 +162,7 @@ public static void cleanDistribution() throws IOException { */ static Map addEnvVariables(Map envVariables, Path tempHomeDirectory) { envVariables.put(BALLERINA_HOME_DIR, tempHomeDirectory.toString()); - envVariables.put(BALLERINA_DEV_CENTRAL, "true"); + envVariables.put(TEST_MODE_ACTIVE, "true"); return envVariables; } } diff --git a/project-api-tests/src/test/resources/bal-tool/DistTestCommand/build.gradle b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/build.gradle new file mode 100644 index 0000000000..bd3416acd8 --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/build.gradle @@ -0,0 +1,38 @@ +plugins { + id 'java' +} + +group 'org.example' +version '1.0.0' + +repositories { + mavenLocal() + maven { + url = 'https://maven.wso2.org/nexus/content/repositories/releases/' + } + + maven { + url = 'https://maven.wso2.org/nexus/content/groups/wso2-public/' + } + + maven { + url = 'https://repo.maven.apache.org/maven2' + } + maven { + url = 'https://maven.pkg.github.com/ballerina-platform/*' + credentials { + username System.getenv("packageUser") + password System.getenv("packagePAT") + } + } +} + +dependencies { + implementation 'org.ballerinalang:ballerina-cli:2201.8.0-SNAPSHOT' + implementation 'info.picocli:picocli:4.0.1' + implementation group: 'org.talend.sdk.component', name: 'sample', version: '10.57.0' +} + +test { + useJUnitPlatform() +} diff --git a/project-api-tests/src/test/resources/bal-tool/DistTestCommand/gradlew b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/gradlew new file mode 100644 index 0000000000..1b6c787337 --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/project-api-tests/src/test/resources/bal-tool/DistTestCommand/gradlew.bat b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/gradlew.bat new file mode 100644 index 0000000000..107acd32c4 --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/project-api-tests/src/test/resources/bal-tool/DistTestCommand/settings.gradle b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/settings.gradle new file mode 100644 index 0000000000..d110e4737b --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/settings.gradle @@ -0,0 +1,6 @@ +rootProject.name = 'DistTestCommand' +include 'src:main:main' +findProject(':src:main:main')?.name = 'main' +include 'untitled' +include 'main' + diff --git a/project-api-tests/src/test/resources/bal-tool/DistTestCommand/src/main/java/disttest/cli/DistTestCommand.java b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/src/main/java/disttest/cli/DistTestCommand.java new file mode 100644 index 0000000000..617bdc8a53 --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/src/main/java/disttest/cli/DistTestCommand.java @@ -0,0 +1,83 @@ +package disttest.cli; + +import io.ballerina.cli.BLauncherCmd; +import picocli.CommandLine; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.nio.charset.StandardCharsets; +import java.util.List; + +@CommandLine.Command(name = "disttest", description = "The tool implementation for ballerina distribution tool tests") +public class DistTestCommand implements BLauncherCmd { + private final PrintStream printStream; + + @CommandLine.Option(names = {"--help", "-h", "?"}, usageHelp = true) + private boolean helpFlag; + + @CommandLine.Parameters(description = "User name") + private List argList; + + public DistTestCommand() { + this.printStream = System.out; + } + + public DistTestCommand(PrintStream printStream) { + this.printStream = printStream; + } + + @Override + public void execute() { + if (helpFlag) { + StringBuilder out = new StringBuilder(); + appendHelpText(out); + printStream.println(out); + return; + } + if (argList == null || argList.size() < 1) { + printStream.println("dist test command 1.0.0 is executing with no args\n"); + return; + } + printStream.println("dist test command 1.0.0 is executing with args " + argList.get(0) + "\n"); + } + + @Override + public String getName() { + return "disttest"; + } + + @Override + public void printLongDesc(StringBuilder out) { + appendHelpText(out); + } + + @Override + public void printUsage(StringBuilder out) { + out.append("A sample tool built for testing bal tool functionality"); + } + + @Override + public void setParentCmdParser(CommandLine parentCmdParser) { + } + + private void appendHelpText(StringBuilder out) { + Class clazz = DistTestCommand.class; + ClassLoader classLoader = clazz.getClassLoader(); + InputStream inputStream = classLoader.getResourceAsStream("disttest.help"); + if (inputStream != null) { + try (InputStreamReader inputStreamREader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); + BufferedReader br = new BufferedReader(inputStreamREader)) { + String content = br.readLine(); + out.append(content); + while ((content = br.readLine()) != null) { + out.append('\n').append(content); + } + } catch (IOException e) { + out.append("Helper text is not available."); + } + } + } +} diff --git a/project-api-tests/src/test/resources/bal-tool/DistTestCommand/src/main/resources/META-INF/services/io.ballerina.cli.BLauncherCmd b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/src/main/resources/META-INF/services/io.ballerina.cli.BLauncherCmd new file mode 100644 index 0000000000..8bed272842 --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/src/main/resources/META-INF/services/io.ballerina.cli.BLauncherCmd @@ -0,0 +1 @@ +disttest.cli.DistTestCommand \ No newline at end of file diff --git a/project-api-tests/src/test/resources/bal-tool/DistTestCommand/src/main/resources/disttest.help b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/src/main/resources/disttest.help new file mode 100644 index 0000000000..4c762831c0 --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/DistTestCommand/src/main/resources/disttest.help @@ -0,0 +1,8 @@ +Sample tool used for testing the bal tools in ballerina distribution tests. +bal disttest + +--args-- + + The argument to be printed. + +version: 1.0.0 diff --git a/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-search-with-tool-id.txt b/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-search-with-tool-id.txt index 5c727eaa9d..dd802350f3 100644 --- a/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-search-with-tool-id.txt +++ b/project-api-tests/src/test/resources/bal-tool/cmd-outputs/tool-search-with-tool-id.txt @@ -3,4 +3,4 @@ Ballerina Central |ID |PACKAGE |DESCRIPTION |DATE |VERSION | |------------|-------------|-------------|----------------|-------------| -|disttest |bctestorg... |Sample to... |2023-09-12-Tue |1.1.0 | \ No newline at end of file +|disttest |bctestorg... |Sample to... | \ No newline at end of file diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/BalTool.toml b/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/BalTool.toml new file mode 100644 index 0000000000..35bbe95edd --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/BalTool.toml @@ -0,0 +1,5 @@ +[tool] +id="disttest" + +[[dependency]] +path="./resources/DistTestCommand-1.0.0.jar" diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/Ballerina.toml b/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/Ballerina.toml new file mode 100644 index 0000000000..b383ed560a --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "bctestorg" +name = "disttestpackage" +version = "1.0.0" diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/Package.md b/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/Package.md new file mode 100644 index 0000000000..f44ebdfb0e --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/Package.md @@ -0,0 +1,4 @@ +# disttest + +## Description +Sample tool used for testing the bal tools in ballerina distribution tests. diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/resources/DistTestCommand-1.0.0.jar b/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/resources/DistTestCommand-1.0.0.jar new file mode 100644 index 0000000000..d0e6c1f00d Binary files /dev/null and b/project-api-tests/src/test/resources/bal-tool/v1.0.0/disttestpackage/resources/DistTestCommand-1.0.0.jar differ diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/BalTool.toml b/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/BalTool.toml new file mode 100644 index 0000000000..3fc8f3bfb3 --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/BalTool.toml @@ -0,0 +1,5 @@ +[tool] +id="disttest" + +[[dependency]] +path="./resources/DistTestCommand-1.0.1.jar" \ No newline at end of file diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/Ballerina.toml b/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/Ballerina.toml new file mode 100644 index 0000000000..f5230f5b6b --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "bctestorg" +name = "disttestpackage" +version = "1.0.1" diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/Package.md b/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/Package.md new file mode 100644 index 0000000000..f44ebdfb0e --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/Package.md @@ -0,0 +1,4 @@ +# disttest + +## Description +Sample tool used for testing the bal tools in ballerina distribution tests. diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/resources/DistTestCommand-1.0.1.jar b/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/resources/DistTestCommand-1.0.1.jar new file mode 100644 index 0000000000..2df0f3cf7d Binary files /dev/null and b/project-api-tests/src/test/resources/bal-tool/v1.0.1/disttestpackage/resources/DistTestCommand-1.0.1.jar differ diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/BalTool.toml b/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/BalTool.toml new file mode 100644 index 0000000000..5b505a9c8c --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/BalTool.toml @@ -0,0 +1,5 @@ +[tool] +id="disttest" + +[[dependency]] +path="./resources/DistTestCommand-1.0.4.jar" diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/Ballerina.toml b/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/Ballerina.toml new file mode 100644 index 0000000000..e7fb04a437 --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "bctestorg" +name = "disttestpackage" +version = "1.0.4" diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/Package.md b/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/Package.md new file mode 100644 index 0000000000..f44ebdfb0e --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/Package.md @@ -0,0 +1,4 @@ +# disttest + +## Description +Sample tool used for testing the bal tools in ballerina distribution tests. diff --git a/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/resources/DistTestCommand-1.0.4.jar b/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/resources/DistTestCommand-1.0.4.jar new file mode 100644 index 0000000000..761390bcfe Binary files /dev/null and b/project-api-tests/src/test/resources/bal-tool/v1.0.4/disttestpackage/resources/DistTestCommand-1.0.4.jar differ diff --git a/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/BalTool.toml b/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/BalTool.toml new file mode 100644 index 0000000000..2cb820db09 --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/BalTool.toml @@ -0,0 +1,5 @@ +[tool] +id="disttest" + +[[dependency]] +path="./resources/DistTestCommand-1.1.0.jar" \ No newline at end of file diff --git a/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/Ballerina.toml b/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/Ballerina.toml new file mode 100644 index 0000000000..36b8931a27 --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "bctestorg" +name = "disttestpackage" +version = "1.1.0" diff --git a/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/Package.md b/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/Package.md new file mode 100644 index 0000000000..f44ebdfb0e --- /dev/null +++ b/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/Package.md @@ -0,0 +1,4 @@ +# disttest + +## Description +Sample tool used for testing the bal tools in ballerina distribution tests. diff --git a/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/resources/DistTestCommand-1.1.0.jar b/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/resources/DistTestCommand-1.1.0.jar new file mode 100644 index 0000000000..0287317e48 Binary files /dev/null and b/project-api-tests/src/test/resources/bal-tool/v1.1.0/disttestpackage/resources/DistTestCommand-1.1.0.jar differ