Skip to content

Commit

Permalink
Merge pull request #41215 from ShammiL/java17-mig-issues
Browse files Browse the repository at this point in the history
Fix platform dependency issues related to java17 migration
  • Loading branch information
Dilhasha authored Aug 18, 2023
2 parents c86770c + 7adc53f commit ab7e94f
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
org = "sameera"
name = "myproject"
version = "0.1.0"

[platform.java11]
graalvmCompatible = true

[[platform.java11.dependency]]
path = "./libs/one-1.0.0.jar"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

public function main() {
}
Original file line number Diff line number Diff line change
@@ -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"
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

public function main() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,26 @@ 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();
}

// 3) Check if the package has a BalTool.toml or a CompilerPlugin.toml
if (this.balToolToml.isPresent() || this.compilerPluginToml.isPresent()) {
return this.backend.targetPlatform();
}

return AnyTarget.ANY;
}

private boolean hasPlatformDependencies(Map<String, PackageManifest.Platform> platforms) {
for (PackageManifest.Platform value: platforms.values()) {
if (!value.dependencies().isEmpty() && !isPlatformDependenciesTestOnly(value.dependencies())) {
return true;
}
}
return false;
}

private Optional<CompilerPluginDescriptor> readCompilerPluginToml() {
Optional<io.ballerina.projects.CompilerPluginToml> compilerPluginToml = backend.packageContext().project()
.currentPackage().compilerPluginToml();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,62 +344,52 @@ private Map<String, PackageManifest.Platform> getPlatforms(TopLevelNode platform
if (platformNode.kind() == TomlType.TABLE) {
TomlTableNode platformTable = (TomlTableNode) platformNode;
Set<String> 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 && graalvmCompatibleNode.kind() != TomlType.NONE) {
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 && topLevelNode.kind() != TomlType.NONE) {
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 && topLevelNode.kind() != TomlType.NONE) {
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);
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.java11'"
}
},
"java17": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -213,9 +272,6 @@
}
}
},
"required": [
"java17"
],
"message": {
"required": "cannot find '${property}' under 'platform'"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ab7e94f

Please sign in to comment.