Skip to content

Commit

Permalink
Merge pull request #44 from HindujaB/java21
Browse files Browse the repository at this point in the history
Migrate to Java 21
  • Loading branch information
warunalakshitha authored Oct 11, 2024
2 parents 27e3d94 + 80ab14a commit 07653f7
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 230 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-timestamped-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
call_workflow:
name: Run Build Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@java21
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/build-with-bal-test-graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
call_stdlib_workflow:
name: Run StdLib Workflow
if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@java21
with:
lang_tag: ${{ inputs.lang_tag }}
lang_version: ${{ inputs.lang_version }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/central-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
call_workflow:
name: Run Central Publish Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@java21
secrets: inherit
with:
environment: ${{ github.event.inputs.environment }}
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
call_workflow:
name: Run Release Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@java21
secrets: inherit
with:
package-name: data.jsondata
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ jobs:
call_workflow:
name: Run PR Build Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@java21
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
call_workflow:
name: Run Trivy Scan Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@java21
secrets: inherit
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ This repository only contains the source code for the package.

### Set up the prerequisites

1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations).
1. Download and install Java SE Development Kit (JDK) version 21 (from one of the following locations).
* [Oracle](https://www.oracle.com/java/technologies/downloads/)
* [OpenJDK](https://adoptium.net/)

Expand Down
16 changes: 8 additions & 8 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ license = ["Apache-2.0"]
distribution = "2201.10.0"
export = ["data.jsondata"]

[platform.java17]
[platform.java21]
graalvmCompatible = true

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.lib"
artifactId = "jsondata-native"
version = "0.3.0"
path = "../native/build/libs/data.jsondata-native-0.3.0-SNAPSHOT.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/json-path-2.9.0.jar"
groupId = "com.jayway.jsonpath"
artifactId = "json-path"
version = "2.9.0"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/json-smart-2.4.11.jar"
groupId = "net.minidev.json"
artifactId = "json-smart"
version = "2.4.11"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/accessors-smart-2.4.7.jar"
groupId = "net.minidev.json"
artifactId = "accessors-smart"
version = "2.4.7"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "constraint-native"
version = "1.5.0"
path = "./lib/constraint-native-1.5.0.jar"
version = "1.5.1"
path = "./lib/constraint-native-1.5.1-20240930-123400-5ecd396.jar"
12 changes: 6 additions & 6 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@ license = ["Apache-2.0"]
distribution = "2201.10.0"
export = ["data.jsondata"]

[platform.java17]
[platform.java21]
graalvmCompatible = true

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.lib"
artifactId = "jsondata-native"
version = "@toml.version@"
path = "../native/build/libs/[email protected]@.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/[email protected]@.jar"
groupId = "com.jayway.jsonpath"
artifactId = "json-path"
version = "@jsonpath.version@"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/[email protected]@.jar"
groupId = "net.minidev.json"
artifactId = "json-smart"
version = "@jsonsmart.version@"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/[email protected]@.jar"
groupId = "net.minidev.json"
artifactId = "accessors-smart"
version = "@accessors.version@"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "constraint-native"
version = "@constraint.version@"
Expand Down
7 changes: 5 additions & 2 deletions compiler-plugin-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ checkstyle {
checkstyleTest.dependsOn(":checkstyle:downloadCheckstyleRuleFiles")

spotbugsTest {
effort "max"
reportLevel "low"
def classLoader = plugins["com.github.spotbugs"].class.classLoader
def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence")
def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort")
effort = SpotBugsEffort.MAX
reportLevel = SpotBugsConfidence.LOW
reportsDir = file("$project.buildDir/reports/spotbugs")
reports {
html.enabled true
Expand Down
7 changes: 5 additions & 2 deletions compiler-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ checkstyle {
checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles")

spotbugsMain {
effort "max"
reportLevel "low"
def classLoader = plugins["com.github.spotbugs"].class.classLoader
def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence")
def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort")
effort = SpotBugsEffort.MAX
reportLevel = SpotBugsConfidence.LOW
reportsDir = file("$project.buildDir/reports/spotbugs")
reports {
html.enabled true
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
org.gradle.caching=true
group=io.ballerina.lib
version=0.3.0-SNAPSHOT
ballerinaLangVersion=2201.10.0
ballerinaLangVersion=2201.10.0-20241007-143200-6b69ca80

checkstyleToolVersion=10.12.0
puppycrawlCheckstyleVersion=10.12.0
testngVersion=7.6.1
slf4jVersion=2.0.7
spotbugsVersion=5.0.14
spotbugsVersion=6.0.18
shadowJarPluginVersion=8.1.1
downloadPluginVersion=4.0.4
releasePluginVersion=2.8.0
Expand All @@ -16,8 +16,8 @@ javaJsonPathVersion=2.9.0
javaJsonSmartVersion=2.4.11
javaAccessorsSmartVersion=2.4.7

stdlibFileVersion=1.10.0
stdlibIoVersion=1.6.1
stdlibOsVersion=1.8.0
stdlibTimeVersion=2.4.0
stdlibConstraintVersion=1.5.0
stdlibFileVersion=1.10.1-20241007-160900-03f7b64
stdlibIoVersion=1.6.2-20240928-084100-656404f
stdlibOsVersion=1.8.1-20241001-120600-dd1626e
stdlibTimeVersion=2.5.1-20240930-120200-e59222b
stdlibConstraintVersion=1.5.1-20240930-123400-5ecd396
7 changes: 5 additions & 2 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ tasks.withType(Checkstyle) {

spotbugsMain {
enabled=false
effort "max"
reportLevel "low"
def classLoader = plugins["com.github.spotbugs"].class.classLoader
def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence")
def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort")
effort = SpotBugsEffort.MAX
reportLevel = SpotBugsConfidence.LOW
reportsDir = file("$project.buildDir/reports/spotbugs")
reports {
html.enabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@

package io.ballerina.lib.data.jsondata.io;

import io.ballerina.lib.data.jsondata.utils.DiagnosticErrorCode;
import io.ballerina.lib.data.jsondata.utils.DiagnosticLog;
import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.async.Callback;
import io.ballerina.runtime.api.async.StrandMetadata;
import io.ballerina.runtime.api.types.MethodType;
import io.ballerina.runtime.api.types.Type;
import io.ballerina.runtime.api.values.BArray;
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.api.values.BMap;
Expand All @@ -33,10 +31,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;

/**
* Java Input Stream based on Ballerina byte block stream. <code>stream<byte[], error?></code>
Expand All @@ -48,33 +42,24 @@ public class BallerinaByteBlockInputStream extends InputStream {
private final BObject iterator;
private final Environment env;
private final String nextMethodName;
private final Type returnType;
private final String strandName;
private final StrandMetadata metadata;
private final Map<String, Object> properties;
private final AtomicBoolean done = new AtomicBoolean(false);
private boolean done = false;
private final MethodType closeMethod;
private final Consumer<Object> futureResultConsumer;

private byte[] currentChunk = new byte[0];
private int nextChunkIndex = 0;
private BError error;

public BallerinaByteBlockInputStream(Environment env, BObject iterator, MethodType nextMethod,
MethodType closeMethod, Consumer<Object> futureResultConsumer) {
MethodType closeMethod) {
this.env = env;
this.iterator = iterator;
this.nextMethodName = nextMethod.getName();
this.returnType = nextMethod.getReturnType();
this.closeMethod = closeMethod;
this.strandName = env.getStrandName().orElse("");
this.metadata = env.getStrandMetadata();
this.properties = Map.of();
this.futureResultConsumer = futureResultConsumer;
}

@Override
public int read() {
if (done.get()) {
if (done) {
return -1;
}
if (hasBytesInCurrentChunk()) {
Expand All @@ -87,8 +72,7 @@ public int read() {
return read();
}
} catch (InterruptedException e) {
BError error = DiagnosticLog.createJsonError("Cannot read the stream, interrupted error");
futureResultConsumer.accept(error);
this.error = DiagnosticLog.error(DiagnosticErrorCode.CAN_NOT_READ_STREAM);
return -1;
}
return -1;
Expand All @@ -97,25 +81,8 @@ public int read() {
@Override
public void close() throws IOException {
super.close();
Semaphore semaphore = new Semaphore(0);
if (closeMethod != null) {
env.getRuntime().invokeMethodAsyncSequentially(iterator, closeMethod.getName(), strandName, metadata,
new Callback() {
@Override
public void notifyFailure(BError bError) {
semaphore.release();
}

@Override
public void notifySuccess(Object result) {
semaphore.release();
}
}, properties, returnType);
}
try {
semaphore.acquire();
} catch (InterruptedException e) {
throw new IOException("Error while closing the stream", e);
env.getRuntime().call(iterator, closeMethod.getName());
}
}

Expand All @@ -124,44 +91,28 @@ private boolean hasBytesInCurrentChunk() {
}

private boolean readNextChunk() throws InterruptedException {
Semaphore semaphore = new Semaphore(0);
Callback callback = new Callback() {

@Override
public void notifyFailure(BError bError) {
// Panic with an error
done.set(true);
futureResultConsumer.accept(bError);
currentChunk = new byte[0];
semaphore.release();
// TODO : Should we panic here?
try {
Object result = env.getRuntime().call(iterator, nextMethodName);
if (result == null) {
done = true;
return true;
}

@Override
public void notifySuccess(Object result) {
if (result == null) {
done.set(true);
currentChunk = new byte[0];
semaphore.release();
return;
}
if (result instanceof BMap<?, ?>) {
BMap<BString, Object> valueRecord = (BMap<BString, Object>) result;
final BString value = Arrays.stream(valueRecord.getKeys()).findFirst().get();
final BArray arrayValue = valueRecord.getArrayValue(value);
currentChunk = arrayValue.getByteArray();
semaphore.release();
} else {
// Case where Completes with an error
done.set(true);
semaphore.release();
}
if (result instanceof BMap<?, ?>) {
BMap<BString, Object> valueRecord = (BMap<BString, Object>) result;
final BString value = Arrays.stream(valueRecord.getKeys()).findFirst().get();
final BArray arrayValue = valueRecord.getArrayValue(value);
currentChunk = arrayValue.getByteArray();
} else {
done = true;
}
} catch (BError bError) {
done = true;
currentChunk = new byte[0];
}
return !done;
}

};
env.getRuntime().invokeMethodAsyncSequentially(iterator, nextMethodName, strandName, metadata, callback,
properties, returnType);
semaphore.acquire();
return !done.get();
public BError getError() {
return this.error;
}
}
Loading

0 comments on commit 07653f7

Please sign in to comment.