From 561ef6a23abcb3a965f41b6a6c34195de043b8b0 Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Mon, 4 Dec 2023 14:13:17 +0530 Subject: [PATCH 1/2] Update PackCommandTest to fix failures --- .../io/ballerina/cli/cmd/PackCommandTest.java | 24 ++++++++++--------- ...ile-empty-project-with-compiler-plugin.txt | 2 +- .../unix/compile-empty-project-with-tool.txt | 2 +- ...ack-empty-package-with-compiler-plugin.txt | 2 +- .../unix/pack-project-with-platform-libs.txt | 16 +++++++++++++ ...ile-empty-project-with-compiler-plugin.txt | 2 +- .../compile-empty-project-with-tool.txt | 2 +- ...ack-empty-package-with-compiler-plugin.txt | 2 +- .../pack-project-with-platform-libs.txt | 16 +++++++++++++ .../Dependencies.toml | 1 + .../resources/expectedDependencies.toml | 17 +++++++++++++ .../resources/expectedDependencies.toml | 1 + 12 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-project-with-platform-libs.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-project-with-platform-libs.txt create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/validProjectWithDependenciesToml/resources/expectedDependencies.toml diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java index 41e25ed5066d..2878165cad56 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java @@ -8,6 +8,7 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; +import org.wso2.ballerinalang.util.RepoUtils; import picocli.CommandLine; import java.io.IOException; @@ -18,8 +19,9 @@ import java.nio.file.Paths; import java.util.Objects; +import static io.ballerina.cli.cmd.CommandOutputUtils.assertTomlFilesEquals; import static io.ballerina.cli.cmd.CommandOutputUtils.getOutput; -import static io.ballerina.cli.cmd.CommandOutputUtils.readFileAsString; +import static io.ballerina.cli.cmd.CommandOutputUtils.replaceDependenciesTomlContent; import static io.ballerina.projects.util.ProjectConstants.DEPENDENCIES_TOML; import static io.ballerina.projects.util.ProjectConstants.RESOURCE_DIR_NAME; @@ -258,10 +260,8 @@ public void testPackageWithEmptyDependenciesToml() throws IOException { // `Dependencies.toml` file should not get deleted Assert.assertTrue(projectPath.resolve(DEPENDENCIES_TOML).toFile().exists()); // `dependencies-toml-version` should exists in `Dependencies.toml` - String expected = "[ballerina]\n" - + "dependencies-toml-version = \"2\""; - String actual = Files.readString(projectPath.resolve(DEPENDENCIES_TOML)); - Assert.assertTrue(actual.contains(expected)); + assertTomlFilesEquals(projectPath.resolve(DEPENDENCIES_TOML), + projectPath.resolve("resources").resolve("expectedDependencies.toml")); } @Test(description = "Pack a package without root package in Dependencies.toml") @@ -278,8 +278,8 @@ public void testPackageWithoutRootPackageInDependenciesToml() throws IOException Assert.assertTrue(projectPath.resolve("target").resolve("bala").resolve("foo-winery-java17-0.1.0.bala") .toFile().exists()); - Assert.assertEquals(readFileAsString(projectPath.resolve(DEPENDENCIES_TOML)).trim(), readFileAsString( - projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDependencies.toml")).trim()); + assertTomlFilesEquals(projectPath.resolve(DEPENDENCIES_TOML), + projectPath.resolve(RESOURCE_DIR_NAME).resolve("expectedDependencies.toml")); } @Test(description = "Pack an empty package with compiler plugin") @@ -293,7 +293,7 @@ public void testPackEmptyProjectWithCompilerPlugin() throws IOException { String buildLog = readOutput(true); Assert.assertTrue(projectPath.resolve("target").resolve("bala") - .resolve("wso2-emptyProjWithCompilerPlugin-any-0.1.0.bala").toFile().exists()); + .resolve("wso2-emptyProjWithCompilerPlugin-java17-0.1.0.bala").toFile().exists()); Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("compile-empty-project-with-compiler-plugin.txt")); } @@ -309,7 +309,7 @@ public void testPackEmptyProjectWithTool() throws IOException { String buildLog = readOutput(true); Assert.assertTrue(projectPath.resolve("target").resolve("bala") - .resolve("wso2-emptyProjWithTool-any-0.1.0.bala").toFile().exists()); + .resolve("wso2-emptyProjWithTool-java17-0.1.0.bala").toFile().exists()); Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("compile-empty-project-with-tool.txt")); } @@ -427,6 +427,8 @@ public void testPackEmptyPackage() throws IOException { @Test(description = "Pack an empty package with compiler plugin") public void testPackEmptyPackageWithCompilerPlugin() throws IOException { Path projectPath = this.testResources.resolve("emptyPackageWithCompilerPlugin"); + replaceDependenciesTomlContent( + projectPath, "**INSERT_DISTRIBUTION_VERSION_HERE**", RepoUtils.getBallerinaShortVersion()); System.setProperty("user.dir", projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); @@ -497,14 +499,14 @@ public void testPackTemplatePackageWithACompilerPackageDependency() throws IOExc @Test(description = "Pack a library package with platform libraries") public void testPackProjectWithPlatformLibs() throws IOException { - Path projectPath = this.testResources.resolve("validProjectWithPlatformLibs"); + Path projectPath = this.testResources.resolve("validProjectWithPlatformLibs1"); System.setProperty("user.dir", projectPath.toString()); PackCommand packCommand = new PackCommand(projectPath, printStream, printStream, false, true); new CommandLine(packCommand).parseArgs(); packCommand.execute(); String buildLog = readOutput(true); - Assert.assertTrue(buildLog.contains("WARNING: Package is not verified with GraalVM.")); + Assert.assertEquals(buildLog.replaceAll("\r", ""), getOutput("pack-project-with-platform-libs.txt")); } @AfterClass diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/compile-empty-project-with-compiler-plugin.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/compile-empty-project-with-compiler-plugin.txt index 09fad681b8df..dafe43ecb682 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/compile-empty-project-with-compiler-plugin.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/compile-empty-project-with-compiler-plugin.txt @@ -2,4 +2,4 @@ Compiling source wso2/emptyProjWithCompilerPlugin:0.1.0 Creating bala - target/bala/wso2-emptyProjWithCompilerPlugin-any-0.1.0.bala + target/bala/wso2-emptyProjWithCompilerPlugin-java17-0.1.0.bala diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/compile-empty-project-with-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/compile-empty-project-with-tool.txt index 4ccf26d2e611..d31166101173 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/compile-empty-project-with-tool.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/compile-empty-project-with-tool.txt @@ -2,4 +2,4 @@ Compiling source wso2/emptyProjWithTool:0.1.0 Creating bala - target/bala/wso2-emptyProjWithTool-any-0.1.0.bala + target/bala/wso2-emptyProjWithTool-java17-0.1.0.bala diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-empty-package-with-compiler-plugin.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-empty-package-with-compiler-plugin.txt index f21b268f223b..13b4898adedf 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-empty-package-with-compiler-plugin.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-empty-package-with-compiler-plugin.txt @@ -2,4 +2,4 @@ Compiling source user/LibraryProject:0.1.0 Creating bala - target/bala/user-LibraryProject-any-0.1.0.bala + target/bala/user-LibraryProject-java17-0.1.0.bala diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-project-with-platform-libs.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-project-with-platform-libs.txt new file mode 100644 index 000000000000..0741522e0fb8 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/unix/pack-project-with-platform-libs.txt @@ -0,0 +1,16 @@ +Compiling source + sameera/myproject:0.1.0 + +Creating bala + +************************************************************ +* WARNING: Package is not verified with GraalVM. * +************************************************************ + +The GraalVM compatibility property has not been defined for the package 'myproject'. This could potentially lead to compatibility issues with GraalVM. + +To resolve this warning, please ensure that all Java dependencies of this package are compatible with GraalVM. Subsequently, update the Ballerina.toml file under the section '[platform.java17]' with the attribute 'graalvmCompatible = true'. + +************************************************************ + + target/bala/sameera-myproject-java17-0.1.0.bala diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/compile-empty-project-with-compiler-plugin.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/compile-empty-project-with-compiler-plugin.txt index 877235119fbb..8df7751db497 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/compile-empty-project-with-compiler-plugin.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/compile-empty-project-with-compiler-plugin.txt @@ -2,4 +2,4 @@ Compiling source wso2/emptyProjWithCompilerPlugin:0.1.0 Creating bala - target\bala\wso2-emptyProjWithCompilerPlugin-any-0.1.0.bala + target\bala\wso2-emptyProjWithCompilerPlugin-java17-0.1.0.bala diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/compile-empty-project-with-tool.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/compile-empty-project-with-tool.txt index 8cf4014a6668..7d6cd6058b04 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/compile-empty-project-with-tool.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/compile-empty-project-with-tool.txt @@ -2,4 +2,4 @@ Compiling source wso2/emptyProjWithTool:0.1.0 Creating bala - target\bala\wso2-emptyProjWithTool-any-0.1.0.bala + target\bala\wso2-emptyProjWithTool-java17-0.1.0.bala diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-empty-package-with-compiler-plugin.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-empty-package-with-compiler-plugin.txt index 4510e85aa844..63f2c61d599d 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-empty-package-with-compiler-plugin.txt +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-empty-package-with-compiler-plugin.txt @@ -2,4 +2,4 @@ Compiling source user/LibraryProject:0.1.0 Creating bala - target\bala\user-LibraryProject-any-0.1.0.bala + target\bala\user-LibraryProject-java17-0.1.0.bala diff --git a/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-project-with-platform-libs.txt b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-project-with-platform-libs.txt new file mode 100644 index 000000000000..ee964f99c893 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/command-outputs/windows/pack-project-with-platform-libs.txt @@ -0,0 +1,16 @@ +Compiling source + sameera/myproject:0.1.0 + +Creating bala + +************************************************************ +* WARNING: Package is not verified with GraalVM. * +************************************************************ + +The GraalVM compatibility property has not been defined for the package 'myproject'. This could potentially lead to compatibility issues with GraalVM. + +To resolve this warning, please ensure that all Java dependencies of this package are compatible with GraalVM. Subsequently, update the Ballerina.toml file under the section '[platform.java17]' with the attribute 'graalvmCompatible = true'. + +************************************************************ + + target\bala\sameera-myproject-java17-0.1.0.bala diff --git a/cli/ballerina-cli/src/test/resources/test-resources/emptyPackageWithCompilerPlugin/Dependencies.toml b/cli/ballerina-cli/src/test/resources/test-resources/emptyPackageWithCompilerPlugin/Dependencies.toml index f39c41747f16..8b8670ff1e45 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/emptyPackageWithCompilerPlugin/Dependencies.toml +++ b/cli/ballerina-cli/src/test/resources/test-resources/emptyPackageWithCompilerPlugin/Dependencies.toml @@ -5,6 +5,7 @@ [ballerina] dependencies-toml-version = "2" +distribution-version = "**INSERT_DISTRIBUTION_VERSION_HERE**" [[package]] org = "user" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/validProjectWithDependenciesToml/resources/expectedDependencies.toml b/cli/ballerina-cli/src/test/resources/test-resources/validProjectWithDependenciesToml/resources/expectedDependencies.toml new file mode 100644 index 000000000000..e8f99a4c9697 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/validProjectWithDependenciesToml/resources/expectedDependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "**INSERT_DISTRIBUTION_VERSION_HERE**" + +[[package]] +org = "foo" +name = "winery" +version = "0.1.0" +modules = [ + {org = "foo", packageName = "winery", moduleName = "winery"} +] + diff --git a/cli/ballerina-cli/src/test/resources/test-resources/validProjectWoRootPkgInDepsToml/resources/expectedDependencies.toml b/cli/ballerina-cli/src/test/resources/test-resources/validProjectWoRootPkgInDepsToml/resources/expectedDependencies.toml index 5ccf30181c95..6943fe21a360 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/validProjectWoRootPkgInDepsToml/resources/expectedDependencies.toml +++ b/cli/ballerina-cli/src/test/resources/test-resources/validProjectWoRootPkgInDepsToml/resources/expectedDependencies.toml @@ -5,6 +5,7 @@ [ballerina] dependencies-toml-version = "2" +distribution-version = "**INSERT_DISTRIBUTION_VERSION_HERE**" [[package]] org = "ballerina" From e0666656e3f42aee3ae861040bb61893b2bf5e6b Mon Sep 17 00:00:00 2001 From: Gayal Dassanayake Date: Tue, 5 Dec 2023 10:24:08 +0530 Subject: [PATCH 2/2] Fix and enable compiler plugin related tests --- cli/ballerina-cli/build.gradle | 2 ++ .../io/ballerina/cli/cmd/PackCommandTest.java | 15 +++++++++++---- .../CompilerPlugin.toml | 4 ++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cli/ballerina-cli/build.gradle b/cli/ballerina-cli/build.gradle index 3f2706761030..da48d237bd18 100644 --- a/cli/ballerina-cli/build.gradle +++ b/cli/ballerina-cli/build.gradle @@ -84,6 +84,8 @@ dependencies { compilerPluginJar project(':project-api-test-artifact:log-creator-pkg-provided-code-modifier') compilerPluginJar project(':project-api-test-artifact:log-creator-pkg-provided-code-generator') compilerPluginJar project(':project-api-test-artifact:log-creator-pkg-provided-code-analyzer') + compilerPluginJar project(':project-api-test-artifact:init-function-code-modify-compiler-plugin') + compilerPluginJar project(':project-api-test-artifact:diagnostic-utils-lib') } task createTestDistributionCache(type: Copy) { diff --git a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java index 2878165cad56..d25063551c48 100644 --- a/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java +++ b/cli/ballerina-cli/src/test/java/io/ballerina/cli/cmd/PackCommandTest.java @@ -45,8 +45,15 @@ public void setup() throws IOException { this.testResources = super.tmpDir.resolve("build-test-resources"); URI testResourcesURI = Objects.requireNonNull(getClass().getClassLoader().getResource("test-resources")) .toURI(); - Files.walkFileTree(Paths.get(testResourcesURI), - new BuildCommandTest.Copy(Paths.get(testResourcesURI), this.testResources)); + Path testResourcesPath = Paths.get(testResourcesURI); + Files.walkFileTree(testResourcesPath, + new BuildCommandTest.Copy(testResourcesPath, this.testResources)); + + // Copy the compiler plugin jars to the test resources directory + Path compilerPluginJarsPath = Paths.get("build", "compiler-plugin-jars"); + Files.walkFileTree(compilerPluginJarsPath, + new BuildCommandTest.Copy(compilerPluginJarsPath, + this.testResources.resolve("compiler-plugin-jars"))); } catch (URISyntaxException e) { Assert.fail("error loading resources"); } @@ -447,7 +454,7 @@ private void buildAndCacheCompilerPluginPackage() { BCompileUtil.compileAndCacheBala(compilerPluginPath.toString()); } - @Test(enabled = false, description = "Pack a non template package with a compiler plugin dependency", + @Test(description = "Pack a non template package with a compiler plugin dependency", groups = {"packWithCompilerPlugin"}) public void testPackNonTemplatePackageWithACompilerPackageDependency() throws IOException { @@ -472,7 +479,7 @@ public void testPackNonTemplatePackageWithACompilerPackageDependency() throws IO "returns error? {\n}")); } - @Test(enabled = false, description = "Pack a template package with a compiler plugin dependency", + @Test(description = "Pack a template package with a compiler plugin dependency", groups = {"packWithCompilerPlugin"}) public void testPackTemplatePackageWithACompilerPackageDependency() throws IOException { diff --git a/cli/ballerina-cli/src/test/resources/test-resources/compiler-plugins/package_comp_plugin_code_modify_add_function/CompilerPlugin.toml b/cli/ballerina-cli/src/test/resources/test-resources/compiler-plugins/package_comp_plugin_code_modify_add_function/CompilerPlugin.toml index d5bcb3f3aecf..3ac66eaa133b 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/compiler-plugins/package_comp_plugin_code_modify_add_function/CompilerPlugin.toml +++ b/cli/ballerina-cli/src/test/resources/test-resources/compiler-plugins/package_comp_plugin_code_modify_add_function/CompilerPlugin.toml @@ -2,7 +2,7 @@ class = "io.samjs.plugins.init.codemodify.CodeModifyFunctionPlugin" [[dependency]] -path = "../init-function-code-modify-compiler-plugin-1.0.0.jar" +path = "../../compiler-plugin-jars/init-function-code-modify-compiler-plugin-1.0.0.jar" [[dependency]] -path = "../diagnostic-utils-lib-1.0.0.jar" +path = "../../compiler-plugin-jars/diagnostic-utils-lib-1.0.0.jar"