From 65901ab8f12865dbaa2491a6165c734da6e8ed70 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 16 Aug 2023 12:15:27 +0530 Subject: [PATCH 1/5] Fix platform dependency issues related to java17 mingration --- .../projects/JBallerinaBalaWriter.java | 18 +++- .../projects/internal/ManifestBuilder.java | 95 +++++++++---------- .../main/resources/ballerina-toml-schema.json | 62 +++++++++++- 3 files changed, 118 insertions(+), 57 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java index 11afb8b6e683..59794c32ce56 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java @@ -236,10 +236,7 @@ private CompilerBackend.TargetPlatform getTargetPlatform(PackageResolution pkgRe // 2) Check package has defined any platform dependency PackageManifest manifest = this.packageContext.project().currentPackage().manifest(); - PackageManifest.Platform manifestPlatform = manifest.platform(this.backend.targetPlatform().code()); - if (manifestPlatform != null && - !manifestPlatform.dependencies().isEmpty() && - !isPlatformDependenciesTestOnly(manifestPlatform.dependencies())) { + if (hasPlatformDependencies(manifest.platforms())) { return this.backend.targetPlatform(); } @@ -247,10 +244,21 @@ private CompilerBackend.TargetPlatform getTargetPlatform(PackageResolution pkgRe if (this.balToolToml.isPresent() || this.compilerPluginToml.isPresent()) { return this.backend.targetPlatform(); } - return AnyTarget.ANY; } + private boolean hasPlatformDependencies(Map platforms) { + boolean platformsNotEmpty = !platforms.isEmpty(); + boolean hasDependencies = true; + for (PackageManifest.Platform value: platforms.values()){ + if (!value.dependencies().isEmpty()) { + boolean isTestOnly = isPlatformDependenciesTestOnly(value.dependencies()); + return platformsNotEmpty && hasDependencies && !isTestOnly; + } + } + return false; + } + private Optional readCompilerPluginToml() { Optional compilerPluginToml = backend.packageContext().project() .currentPackage().compilerPluginToml(); diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index 029688c885e3..989c3edf90e4 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -344,62 +344,59 @@ private Map getPlatforms(TopLevelNode platform if (platformNode.kind() == TomlType.TABLE) { TomlTableNode platformTable = (TomlTableNode) platformNode; Set platformCodes = platformTable.entries().keySet(); - if (platformCodes.size() != 1) { - return platforms; - } - - String platformCode = platformCodes.stream().findFirst().get(); - TopLevelNode platformCodeNode = platformTable.entries().get(platformCode); - - if (platformCodeNode.kind() == TomlType.TABLE) { - TomlTableNode platformCodeTable = (TomlTableNode) platformCodeNode; - // Get graalvmCompatible value - TopLevelNode graalvmCompatibleNode = platformCodeTable.entries().get(GRAALVM_COMPATIBLE); - if (graalvmCompatibleNode != null) { - if (graalvmCompatibleNode.kind() == TomlType.NONE) { - return platforms; - } - PackageManifest.Platform newPlatform = getGraalvmCompatibilityPlatform(graalvmCompatibleNode); - if (newPlatform != null) { - if (platforms.get(platformCode) != null) { - newPlatform = new PackageManifest.Platform(platforms.get(platformCode).dependencies(), - platforms.get(platformCode).repositories(), - newPlatform.graalvmCompatible()); + for (String platformCode : platformCodes) { + TopLevelNode platformCodeNode = platformTable.entries().get(platformCode); + + if (platformCodeNode.kind() == TomlType.TABLE) { + TomlTableNode platformCodeTable = (TomlTableNode) platformCodeNode; + // Get graalvmCompatible value + TopLevelNode graalvmCompatibleNode = platformCodeTable.entries().get(GRAALVM_COMPATIBLE); + if (graalvmCompatibleNode != null) { + if (graalvmCompatibleNode.kind() == TomlType.NONE) { + return platforms; + } + PackageManifest.Platform newPlatform = getGraalvmCompatibilityPlatform(graalvmCompatibleNode); + if (newPlatform != null) { + if (platforms.get(platformCode) != null) { + newPlatform = new PackageManifest.Platform(platforms.get(platformCode).dependencies(), + platforms.get(platformCode).repositories(), + newPlatform.graalvmCompatible()); + } + platforms.put(platformCode, newPlatform); } - platforms.put(platformCode, newPlatform); } - } - TopLevelNode topLevelNode = platformCodeTable.entries().get(DEPENDENCY); - if (topLevelNode != null) { - if (topLevelNode.kind() == TomlType.NONE) { - return platforms; - } - PackageManifest.Platform newPlatform = getDependencyPlatform(topLevelNode); - if (newPlatform != null) { - if (platforms.get(platformCode) != null) { - newPlatform = new PackageManifest.Platform(newPlatform.dependencies(), - platforms.get(platformCode).repositories(), - platforms.get(platformCode).graalvmCompatible()); + TopLevelNode topLevelNode = platformCodeTable.entries().get(DEPENDENCY); + if (topLevelNode != null) { + if (topLevelNode.kind() == TomlType.NONE) { + return platforms; + } + PackageManifest.Platform newPlatform = getDependencyPlatform(topLevelNode); + if (newPlatform != null) { + if (platforms.get(platformCode) != null) { + newPlatform = new PackageManifest.Platform(newPlatform.dependencies(), + platforms.get(platformCode).repositories(), + platforms.get(platformCode).graalvmCompatible()); + } + platforms.put(platformCode, newPlatform); } - platforms.put(platformCode, newPlatform); - } - } - topLevelNode = platformCodeTable.entries().get(REPOSITORY); - if (topLevelNode != null) { - if (topLevelNode.kind() == TomlType.NONE) { - return platforms; } - PackageManifest.Platform platform = getRepositoryPlatform(topLevelNode); - if (platform != null) { - if (platforms.get(platformCode) != null) { - platform = new PackageManifest.Platform(platforms.get(platformCode) - .dependencies(), platform.repositories(), - platforms.get(platformCode).graalvmCompatible()); + topLevelNode = platformCodeTable.entries().get(REPOSITORY); + if (topLevelNode != null) { + if (topLevelNode.kind() == TomlType.NONE) { + return platforms; + } + PackageManifest.Platform platform = getRepositoryPlatform(topLevelNode); + if (platform != null) { + if (platforms.get(platformCode) != null) { + platform = new PackageManifest.Platform(platforms.get(platformCode) + .dependencies(), platform.repositories(), + platforms.get(platformCode).graalvmCompatible()); + } + platforms.put(platformCode, platform); } - platforms.put(platformCode, platform); } - } + } } } } diff --git a/compiler/ballerina-lang/src/main/resources/ballerina-toml-schema.json b/compiler/ballerina-lang/src/main/resources/ballerina-toml-schema.json index 9a3d7d2f6463..e8163848ead9 100644 --- a/compiler/ballerina-lang/src/main/resources/ballerina-toml-schema.json +++ b/compiler/ballerina-lang/src/main/resources/ballerina-toml-schema.json @@ -153,6 +153,65 @@ "type": "object", "additionalProperties": false, "properties": { + "java11": { + "type": "object", + "additionalProperties": false, + "properties": { + "dependency": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": true, + "properties": { + "path": { + "type": "string" + }, + "artifactId": { + "type": "string" + }, + "groupId": { + "type": "string" + }, + "version": { + "type": "string" + }, + "scope": { + "type": "string" + } + } + } + }, + "repository": { + "type": "array", + "items": { + "type": "object", + "additionalProperties": true, + "properties": { + "id": { + "type": "string" + }, + "url": { + "type": "string" + }, + "username": { + "type": "string" + }, + "password": { + "type": "string" + } + } + } + }, + "graalvmCompatible": { + "type": "boolean" + } + }, + "required": [ + ], + "message": { + "required": "cannot find '${property}' under 'platform.java17'" + } + }, "java17": { "type": "object", "additionalProperties": false, @@ -213,9 +272,6 @@ } } }, - "required": [ - "java17" - ], "message": { "required": "cannot find '${property}' under 'platform'" } From 0b5f688fd8d7a4d8d3a49dc493f0501139d8a2d1 Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 16 Aug 2023 15:15:14 +0530 Subject: [PATCH 2/5] Add tests for java11 and java17 platform dependencies --- .../io/ballerina/cli/cmd/PackCommandTest.java | 44 ++++++++++++++++++ .../Ballerina.toml | 7 +++ .../libs/one-1.0.0.jar | Bin 0 -> 2567 bytes .../projectWithJava11PlatformLibs/main.bal | 3 ++ .../Ballerina.toml | 13 ++++++ .../libs/one-1.0.0.jar | Bin 0 -> 2567 bytes .../libs/two-2.0.0.jar | Bin 0 -> 2567 bytes .../main.bal | 3 ++ .../projects/JBallerinaBalaWriter.java | 2 +- .../projects/internal/ManifestBuilder.java | 6 ++- .../main/resources/ballerina-toml-schema.json | 2 +- 11 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/Ballerina.toml create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/libs/one-1.0.0.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/main.bal create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/Ballerina.toml create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/libs/one-1.0.0.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/libs/two-2.0.0.jar create mode 100644 cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/main.bal 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 c4ecacbd0b95..41e25ed5066d 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 @@ -168,6 +168,50 @@ public void testPackageWithPlatformLibs() throws IOException { .toFile().exists()); } + @Test(description = "Pack a package with java11 platform libs") + public void testPackageWithJava11PlatformLibs() throws IOException { + Path projectPath = this.testResources.resolve("projectWithJava11PlatformLibs"); + 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.assertEquals(buildLog.replaceAll("\r", ""), + getOutput("build-project-with-platform-libs.txt")); + Path balaDirPath = projectPath.resolve("target").resolve("bala"); + Assert.assertTrue(balaDirPath.resolve("sameera-myproject-java17-0.1.0.bala") + .toFile().exists()); + + Path balaDestPath = balaDirPath.resolve("extracted"); + ProjectUtils.extractBala(balaDirPath.resolve("sameera-myproject-java17-0.1.0.bala"), balaDestPath); + Assert.assertTrue(balaDestPath.resolve("platform").resolve("java17").resolve("one-1.0.0.jar") + .toFile().exists()); + } + + @Test(description = "Pack a package with java11 and java17 platform libs") + public void testPackageWithJava11andJava17PlatformLibs() throws IOException { + Path projectPath = this.testResources.resolve("projectWithJava11and17PlatformLibs"); + 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.assertEquals(buildLog.replaceAll("\r", ""), + getOutput("build-project-with-platform-libs.txt")); + Path balaDirPath = projectPath.resolve("target").resolve("bala"); + Assert.assertTrue(balaDirPath.resolve("sameera-myproject-java17-0.1.0.bala") + .toFile().exists()); + + Path balaDestPath = balaDirPath.resolve("extracted"); + ProjectUtils.extractBala(balaDirPath.resolve("sameera-myproject-java17-0.1.0.bala"), balaDestPath); + Assert.assertTrue(balaDestPath.resolve("platform").resolve("java17").resolve("one-1.0.0.jar") + .toFile().exists()); + Assert.assertTrue(balaDestPath.resolve("platform").resolve("java17").resolve("two-2.0.0.jar") + .toFile().exists()); + } + @Test(description = "Pack a package with testOnly platform libs") public void testPackageWithTestOnlyPlatformLibs() throws IOException { Path projectPath = this.testResources.resolve("projectWithTestOnlyPlatformLibs"); diff --git a/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/Ballerina.toml new file mode 100644 index 000000000000..d0427ae1539a --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/Ballerina.toml @@ -0,0 +1,7 @@ +[package] +org = "sameera" +name = "myproject" +version = "0.1.0" + +[[platform.java11.dependency]] +path = "./libs/one-1.0.0.jar" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/libs/one-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/libs/one-1.0.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..d22013058e3d09cc578084e43cd8bf421d7844c5 GIT binary patch literal 2567 zcmWIWW@h1H0D;ED>>w}$N^k;cU)K;vT~9wZ{Q#&k4u%GxvgK3nH01)Nn}JvaS(&e+ zpQoE^aEP9-+h^Z1r+vJ2^)B*y>uQ}lbAEG>!4=~NPm6TC&YjTl)^*}wf3hTOikS8R zm5QBnx`TwhgMv%uYONKK;TD=~93)yJd^+f}NY7WFuRcI|FXLjb1DjY~J9qxnoZ2a{ zQ6zT#l$-^o4%J_LDtA`wWPmvj(-*8j=ar-um%x31se}inq&P9RASV^Bk^>whi?@3C zo(8JmV`N~EL{k|I)?locoRe5woZGiC?~sFlOZvu*2MZY*e=t~0QVLg*7339~%F5dD zFUPOo#Epry=jsDpy$-T}2n@W|?)`1a&Dj^FGxO{Bhcn1auoQfFv-tU9{||Ph%g)Yu z;1gfQQaI(O`EwUV=e(_0EtLNZ-6&&RJ6lHPqU zy(M9Cxa*>6yV4G;)mxv;mptS;+o0-#GEbJ%5+m!5(wd;ogDkrHcFH|E9vap^cY|EU z{(lX6e=-lIf6aNZ;IPy^#uC9Bza}p|R1XVINC>!@_O_kD8v;hK5IC51$U(&Qy|Lj% zlhD9F4CULp`KG+n$zut36z}@&DN~}NraJS>{ut3+ADI8FxHR3+`~HF2V*TfbcK`hw z$5@jfaNywP{(1d&2Y+9gX;$21TzgaSj_bbgmbxXzTUVXisI|?=&r;H@Qt9$sosze+ zFPOT=3LTpmxKwbdP5n}@oHteT1)F^1L_4Ei&ElQ?=dH^AR1WdnLoXcr4OVbYJoQH5 z+DA`SHsLKlo>g_ohez6$9jaRJ_ZRc756fBSU){X0nJ>G7{eo-4YyW9n{~1w(;I?gZ z@F~1OU;+yQL?W2c;P8`SS4&g&3kQ>lD|9p*zN9~&B4cE>iT__WS7#IdgT(@`nYa{rvK>P3Bi;ni)5J{<>FjhyBm>N+n8jR~}6iU!A1;c*^9s zDe6XdPdJ7D6W#SJetOIK6Duxt1ikyVQb>FEF=3|-r}$kLJ=>LZINa{msl_}G7x}%| z|59+5sAAB}zn!UjLOTyKnC{yt1xo`f_|Gp8uFv`qX)A4&v7ybM!Ix#*y-guM@MI}| zU_ihNhTO!m)I4~W!OUFJn2JH!Q5P+*VQQ4euQ5LlIinT;3#Gbkg*jZnOlr);z@SE0 zb3uNtUPW$BYtYH8!v+F-e{1)=oAzc~dxFT*Fb$P07h2<5Z3;uyuzGI%`!jT@ip7M0 z`_FVgyYXK>yQZy(<@wT!*;gJ&O={vFFrrs8MTmCdqwFpb{CDsQNK;CS`wn2 zMC2Wl^LAP=n5|RKUvK@X<@JuG8t3CTZP`3s{I-d2MU_um`>wnb-}8RUnQO#(zGc47 zG_6cOdj5^If;LNx|M%*@*G#*gy1~mzCjCf|MCh{ShuY=`g}hIShNZ;5KXY+kiB1Fm z)aR%898OA}5qj5jr&v%ap(I7TSZoegx^JK4df}v-VvAU9c7JjB9NZEZ#`j=@xx2c8 zUPNHg>|NQscfJbbMfr!=HS4_hxO`v#Kpk3&XFT^#IUX2_$v~`2Txb>)0xEXtCjxa_Pm~k+TftKy)#-Nvo z2xBCeu^9s`9}&i2h9Ib1fdB!9|NkXfkm3MV%D_SdQ!}WXL1=cv)C}?&qSV1{5UAWi z7*vnnAV?_$GmL`)TR8+XZb{=F!iGUhB}6bmA`Lw^BFyAs!w4p1pMo3+G82(E1H4&* QS{N93fY25gRa?M303(_<9RL6T literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/main.bal new file mode 100644 index 000000000000..6d0ccb5ba65d --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/main.bal @@ -0,0 +1,3 @@ + +public function main() { +} diff --git a/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/Ballerina.toml new file mode 100644 index 000000000000..5cf8ae2461f3 --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/Ballerina.toml @@ -0,0 +1,13 @@ +[package] +org = "sameera" +name = "myproject" +version = "0.1.0" + +[platform.java17] +graalvmCompatible = true + +[[platform.java11.dependency]] +path = "./libs/one-1.0.0.jar" + +[[platform.java17.dependency]] +path = "./libs/two-2.0.0.jar" diff --git a/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/libs/one-1.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/libs/one-1.0.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..d22013058e3d09cc578084e43cd8bf421d7844c5 GIT binary patch literal 2567 zcmWIWW@h1H0D;ED>>w}$N^k;cU)K;vT~9wZ{Q#&k4u%GxvgK3nH01)Nn}JvaS(&e+ zpQoE^aEP9-+h^Z1r+vJ2^)B*y>uQ}lbAEG>!4=~NPm6TC&YjTl)^*}wf3hTOikS8R zm5QBnx`TwhgMv%uYONKK;TD=~93)yJd^+f}NY7WFuRcI|FXLjb1DjY~J9qxnoZ2a{ zQ6zT#l$-^o4%J_LDtA`wWPmvj(-*8j=ar-um%x31se}inq&P9RASV^Bk^>whi?@3C zo(8JmV`N~EL{k|I)?locoRe5woZGiC?~sFlOZvu*2MZY*e=t~0QVLg*7339~%F5dD zFUPOo#Epry=jsDpy$-T}2n@W|?)`1a&Dj^FGxO{Bhcn1auoQfFv-tU9{||Ph%g)Yu z;1gfQQaI(O`EwUV=e(_0EtLNZ-6&&RJ6lHPqU zy(M9Cxa*>6yV4G;)mxv;mptS;+o0-#GEbJ%5+m!5(wd;ogDkrHcFH|E9vap^cY|EU z{(lX6e=-lIf6aNZ;IPy^#uC9Bza}p|R1XVINC>!@_O_kD8v;hK5IC51$U(&Qy|L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}WXL1=cv)C}?&qSV1{5UAWi z7*vnnAV?_$GmL`)TR8+XZb{=F!iGUhB}6bmA`Lw^BFyAs!w4p1pMo3+G82(E1H4&* QS{N93fY25gRa?M303(_<9RL6T literal 0 HcmV?d00001 diff --git a/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/libs/two-2.0.0.jar b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/libs/two-2.0.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..d22013058e3d09cc578084e43cd8bf421d7844c5 GIT binary patch literal 2567 zcmWIWW@h1H0D;ED>>w}$N^k;cU)K;vT~9wZ{Q#&k4u%GxvgK3nH01)Nn}JvaS(&e+ zpQoE^aEP9-+h^Z1r+vJ2^)B*y>uQ}lbAEG>!4=~NPm6TC&YjTl)^*}wf3hTOikS8R zm5QBnx`TwhgMv%uYONKK;TD=~93)yJd^+f}NY7WFuRcI|FXLjb1DjY~J9qxnoZ2a{ zQ6zT#l$-^o4%J_LDtA`wWPmvj(-*8j=ar-um%x31se}inq&P9RASV^Bk^>whi?@3C zo(8JmV`N~EL{k|I)?locoRe5woZGiC?~sFlOZvu*2MZY*e=t~0QVLg*7339~%F5dD zFUPOo#Epry=jsDpy$-T}2n@W|?)`1a&Dj^FGxO{Bhcn1auoQfFv-tU9{||Ph%g)Yu z;1gfQQaI(O`EwUV=e(_0EtLNZ-6&&RJ6lHPqU zy(M9Cxa*>6yV4G;)mxv;mptS;+o0-#GEbJ%5+m!5(wd;ogDkrHcFH|E9vap^cY|EU z{(lX6e=-lIf6aNZ;IPy^#uC9Bza}p|R1XVINC>!@_O_kD8v;hK5IC51$U(&Qy|Lj% zlhD9F4CULp`KG+n$zut36z}@&DN~}NraJS>{ut3+ADI8FxHR3+`~HF2V*TfbcK`hw z$5@jfaNywP{(1d&2Y+9gX;$21TzgaSj_bbgmbxXzTUVXisI|?=&r;H@Qt9$sosze+ zFPOT=3LTpmxKwbdP5n}@oHteT1)F^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ithJava11and17PlatformLibs/main.bal b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/main.bal new file mode 100644 index 000000000000..6d0ccb5ba65d --- /dev/null +++ b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11and17PlatformLibs/main.bal @@ -0,0 +1,3 @@ + +public function main() { +} diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java index 59794c32ce56..638ed336da24 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java @@ -250,7 +250,7 @@ private CompilerBackend.TargetPlatform getTargetPlatform(PackageResolution pkgRe private boolean hasPlatformDependencies(Map platforms) { boolean platformsNotEmpty = !platforms.isEmpty(); boolean hasDependencies = true; - for (PackageManifest.Platform value: platforms.values()){ + for (PackageManifest.Platform value: platforms.values()) { if (!value.dependencies().isEmpty()) { boolean isTestOnly = isPlatformDependenciesTestOnly(value.dependencies()); return platformsNotEmpty && hasDependencies && !isTestOnly; diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index 989c3edf90e4..922bd17f05de 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -355,10 +355,12 @@ private Map getPlatforms(TopLevelNode platform if (graalvmCompatibleNode.kind() == TomlType.NONE) { return platforms; } - PackageManifest.Platform newPlatform = getGraalvmCompatibilityPlatform(graalvmCompatibleNode); + PackageManifest.Platform newPlatform = + getGraalvmCompatibilityPlatform(graalvmCompatibleNode); if (newPlatform != null) { if (platforms.get(platformCode) != null) { - newPlatform = new PackageManifest.Platform(platforms.get(platformCode).dependencies(), + newPlatform = new PackageManifest.Platform(platforms. + get(platformCode).dependencies(), platforms.get(platformCode).repositories(), newPlatform.graalvmCompatible()); } diff --git a/compiler/ballerina-lang/src/main/resources/ballerina-toml-schema.json b/compiler/ballerina-lang/src/main/resources/ballerina-toml-schema.json index e8163848ead9..799840b44b7e 100644 --- a/compiler/ballerina-lang/src/main/resources/ballerina-toml-schema.json +++ b/compiler/ballerina-lang/src/main/resources/ballerina-toml-schema.json @@ -209,7 +209,7 @@ "required": [ ], "message": { - "required": "cannot find '${property}' under 'platform.java17'" + "required": "cannot find '${property}' under 'platform.java11'" } }, "java17": { From c2d442e3a7f5fce21cb7724f4e5032460a3fa98e Mon Sep 17 00:00:00 2001 From: ShammiL Date: Wed, 16 Aug 2023 17:20:12 +0530 Subject: [PATCH 3/5] Fix ballerinatoml completion tests --- .../config/table_array_context/config1.json | 21 +++++++++++++++++++ .../config/table_context/config1.json | 21 +++++++++++++++++++ .../config/table_context/config2.json | 21 +++++++++++++++++++ 3 files changed, 63 insertions(+) diff --git a/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_array_context/config1.json b/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_array_context/config1.json index 465e2d357824..b7f3c1b473b2 100644 --- a/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_array_context/config1.json +++ b/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_array_context/config1.json @@ -33,6 +33,27 @@ "sortText": "C", "insertText": "[[platform.java17.repository]]" }, + { + "label": "platform.java11", + "kind": "Snippet", + "detail": "Table", + "sortText": "C", + "insertText": "[platform.java11]" + }, + { + "label": "platform.java11.dependency", + "kind": "Snippet", + "detail": "Table Array", + "sortText": "C", + "insertText": "[[platform.java11.dependency]]" + }, + { + "label": "platform.java11.repository", + "kind": "Snippet", + "detail": "Table Array", + "sortText": "C", + "insertText": "[[platform.java11.repository]]" + }, { "label": "groupId", "kind": "Snippet", diff --git a/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_context/config1.json b/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_context/config1.json index b3ec0fb16d10..3eae823649f8 100644 --- a/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_context/config1.json +++ b/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_context/config1.json @@ -26,6 +26,27 @@ "sortText": "C", "insertText": "[[platform.java17.repository]]" }, + { + "label": "platform.java11", + "kind": "Snippet", + "detail": "Table", + "sortText": "C", + "insertText": "[platform.java11]" + }, + { + "label": "platform.java11.dependency", + "kind": "Snippet", + "detail": "Table Array", + "sortText": "C", + "insertText": "[[platform.java11.dependency]]" + }, + { + "label": "platform.java11.repository", + "kind": "Snippet", + "detail": "Table Array", + "sortText": "C", + "insertText": "[[platform.java11.repository]]" + }, { "label": "license", "kind": "Snippet", diff --git a/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_context/config2.json b/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_context/config2.json index 638e90123bf4..1503e59c3beb 100644 --- a/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_context/config2.json +++ b/language-server/modules/langserver-core/src/test/resources/toml/ballerina_toml/completion/config/table_context/config2.json @@ -26,6 +26,27 @@ "sortText": "C", "insertText": "[[platform.java17.repository]]" }, + { + "label": "platform.java11", + "kind": "Snippet", + "detail": "Table", + "sortText": "C", + "insertText": "[platform.java11]" + }, + { + "label": "platform.java11.dependency", + "kind": "Snippet", + "detail": "Table Array", + "sortText": "C", + "insertText": "[[platform.java11.dependency]]" + }, + { + "label": "platform.java11.repository", + "kind": "Snippet", + "detail": "Table Array", + "sortText": "C", + "insertText": "[[platform.java11.repository]]" + }, { "label": "license", "kind": "Snippet", From 21ae82c064d85ce376d891f7903ede8abb971c0e Mon Sep 17 00:00:00 2001 From: ShammiL Date: Thu, 17 Aug 2023 19:54:10 +0530 Subject: [PATCH 4/5] Address review comments --- .../projectWithJava11PlatformLibs/Ballerina.toml | 3 +++ .../java/io/ballerina/projects/JBallerinaBalaWriter.java | 7 ++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/Ballerina.toml b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/Ballerina.toml index d0427ae1539a..40fe374f5b69 100644 --- a/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/Ballerina.toml +++ b/cli/ballerina-cli/src/test/resources/test-resources/projectWithJava11PlatformLibs/Ballerina.toml @@ -3,5 +3,8 @@ org = "sameera" name = "myproject" version = "0.1.0" +[platform.java11] +graalvmCompatible = true + [[platform.java11.dependency]] path = "./libs/one-1.0.0.jar" diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java index 638ed336da24..25971d214191 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/JBallerinaBalaWriter.java @@ -248,12 +248,9 @@ private CompilerBackend.TargetPlatform getTargetPlatform(PackageResolution pkgRe } private boolean hasPlatformDependencies(Map platforms) { - boolean platformsNotEmpty = !platforms.isEmpty(); - boolean hasDependencies = true; for (PackageManifest.Platform value: platforms.values()) { - if (!value.dependencies().isEmpty()) { - boolean isTestOnly = isPlatformDependenciesTestOnly(value.dependencies()); - return platformsNotEmpty && hasDependencies && !isTestOnly; + if (!value.dependencies().isEmpty() && !isPlatformDependenciesTestOnly(value.dependencies())) { + return true; } } return false; From 7adc53fd19592d0e6ba12b32fbc017207e27806f Mon Sep 17 00:00:00 2001 From: ShammiL Date: Fri, 18 Aug 2023 08:35:39 +0530 Subject: [PATCH 5/5] Fix bug in ManifestBuilder --- .../projects/internal/ManifestBuilder.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java index 922bd17f05de..265163cc8309 100644 --- a/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java +++ b/compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ManifestBuilder.java @@ -351,10 +351,7 @@ private Map getPlatforms(TopLevelNode platform TomlTableNode platformCodeTable = (TomlTableNode) platformCodeNode; // Get graalvmCompatible value TopLevelNode graalvmCompatibleNode = platformCodeTable.entries().get(GRAALVM_COMPATIBLE); - if (graalvmCompatibleNode != null) { - if (graalvmCompatibleNode.kind() == TomlType.NONE) { - return platforms; - } + if (graalvmCompatibleNode != null && graalvmCompatibleNode.kind() != TomlType.NONE) { PackageManifest.Platform newPlatform = getGraalvmCompatibilityPlatform(graalvmCompatibleNode); if (newPlatform != null) { @@ -369,10 +366,7 @@ private Map getPlatforms(TopLevelNode platform } TopLevelNode topLevelNode = platformCodeTable.entries().get(DEPENDENCY); - if (topLevelNode != null) { - if (topLevelNode.kind() == TomlType.NONE) { - return platforms; - } + if (topLevelNode != null && topLevelNode.kind() != TomlType.NONE) { PackageManifest.Platform newPlatform = getDependencyPlatform(topLevelNode); if (newPlatform != null) { if (platforms.get(platformCode) != null) { @@ -384,10 +378,7 @@ private Map getPlatforms(TopLevelNode platform } } topLevelNode = platformCodeTable.entries().get(REPOSITORY); - if (topLevelNode != null) { - if (topLevelNode.kind() == TomlType.NONE) { - return platforms; - } + if (topLevelNode != null && topLevelNode.kind() != TomlType.NONE) { PackageManifest.Platform platform = getRepositoryPlatform(topLevelNode); if (platform != null) { if (platforms.get(platformCode) != null) {