Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Java 21 #12

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Migrate to Java 21
ravinperera00 committed Oct 3, 2024
commit ee0538b412d4f9fce6f3a9bb04744edee936955b
2 changes: 1 addition & 1 deletion .github/workflows/build-timestamped-master.yml
Original file line number Diff line number Diff line change
@@ -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
@@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/central-publish.yml
Original file line number Diff line number Diff line change
@@ -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
@@ -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.yaml
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -87,7 +87,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/)
2 changes: 1 addition & 1 deletion ballerina/CompilerPlugin.toml
Original file line number Diff line number Diff line change
@@ -3,4 +3,4 @@ id = "constraint-compiler-plugin"
class = "io.ballerina.lib.data.yaml.compiler.YamlDataCompilerPlugin"

[[dependency]]
path = "../compiler-plugin/build/libs/data.yaml-compiler-plugin-0.1.0.jar"
path = "../compiler-plugin/build/libs/data.yaml-compiler-plugin-0.1.1-SNAPSHOT.jar"
4 changes: 2 additions & 2 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
@@ -11,14 +11,14 @@ distribution = "2201.10.0"
[platform.java17]
graalvmCompatible = true

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


[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "constraint-native"
version = "@constraint.version@"
7 changes: 5 additions & 2 deletions compiler-plugin-test/build.gradle
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions compiler-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 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.1.1-SNAPSHOT
ballerinaLangVersion=2201.10.0
ballerinaLangVersion=2201.10.0-20241002-115300-57eee14c

checkstyleToolVersion=10.12.0
puppycrawlCheckstyleVersion=10.12.0
testngVersion=7.6.1
slf4jVersion=2.0.7
githubSpotbugsVersion=5.0.14
githubSpotbugsVersion=6.0.18
githubJohnrengelmanShadowVersion=8.1.1
underCouchDownloadVersion=4.0.4
researchgateReleaseVersion=2.8.0
@@ -17,6 +17,6 @@ downloadPluginVersion=4.0.4
releasePluginVersion=2.8.0
ballerinaGradlePluginVersion=2.0.1

stdlibIoVersion=1.6.1
stdlibConstraintVersion=1.5.0
stdlibTimeVersion=2.4.0
stdlibIoVersion=1.6.2-20240928-084100-656404f
stdlibConstraintVersion=1.5.1-20240930-123400-5ecd396
stdlibTimeVersion=2.5.1-20240930-120200-e59222b
7 changes: 5 additions & 2 deletions native/build.gradle
Original file line number Diff line number Diff line change
@@ -51,9 +51,12 @@ tasks.withType(Checkstyle) {
}

spotbugsMain {
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")
enabled=false
effort "max"
reportLevel "low"
effort = SpotBugsEffort.MAX
reportLevel = SpotBugsConfidence.LOW
reportsDir = file("$project.buildDir/reports/spotbugs")
reports {
html.enabled true
23 changes: 16 additions & 7 deletions native/src/main/java/io/ballerina/lib/data/yaml/Native.java
Original file line number Diff line number Diff line change
@@ -19,13 +19,12 @@
package io.ballerina.lib.data.yaml;

import io.ballerina.lib.data.yaml.emitter.Emitter;
import io.ballerina.lib.data.yaml.io.DataReaderTask;
import io.ballerina.lib.data.yaml.io.DataReaderThreadPool;
import io.ballerina.lib.data.yaml.io.BallerinaByteBlockInputStream;
import io.ballerina.lib.data.yaml.parser.YamlParser;
import io.ballerina.lib.data.yaml.serializer.Serializer;
import io.ballerina.lib.data.yaml.utils.DiagnosticLog;
import io.ballerina.lib.data.yaml.utils.OptionsUtils;
import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.Future;
import io.ballerina.runtime.api.creators.ValueCreator;
import io.ballerina.runtime.api.values.BArray;
import io.ballerina.runtime.api.values.BError;
@@ -40,6 +39,9 @@
import java.io.StringReader;
import java.util.List;

import static io.ballerina.lib.data.yaml.utils.DataReader.resolveCloseMethod;
import static io.ballerina.lib.data.yaml.utils.DataReader.resolveNextMethod;

/**
* This class is used to convert json inform of string, byte[], byte-stream to record or json type.
*
@@ -69,10 +71,17 @@ public static Object parseBytes(BArray yaml, BMap<BString, Object> options, BTyp

public static Object parseStream(Environment env, BStream yaml, BMap<BString, Object> options, BTypedesc typed) {
final BObject iteratorObj = yaml.getIteratorObj();
final Future future = env.markAsync();
DataReaderTask task = new DataReaderTask(env, iteratorObj, future, typed, options);
DataReaderThreadPool.EXECUTOR_SERVICE.submit(task);
return null;
try {
BallerinaByteBlockInputStream byteBlockSteam = new BallerinaByteBlockInputStream(env,
iteratorObj, resolveNextMethod(iteratorObj), resolveCloseMethod(iteratorObj));
Object result = YamlParser.compose(new InputStreamReader(byteBlockSteam), options, typed);
if (byteBlockSteam.getError() != null) {
return byteBlockSteam.getError();
}
return result;
} catch (Exception e) {
return DiagnosticLog.getYamlError("Error occurred while reading the stream: " + e.getMessage());
}
}

public static Object toYamlStringArray(Object yamlValue, BMap<BString, Object> config) {
Original file line number Diff line number Diff line change
@@ -20,10 +20,7 @@

import io.ballerina.lib.data.yaml.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;
@@ -33,38 +30,26 @@
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;

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 final MethodType closeMethod;
private final Consumer<Object> futureResultConsumer;
private BError error = null;

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

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
@@ -82,8 +67,7 @@ public int read() {
return read();
}
} catch (InterruptedException e) {
BError error = DiagnosticLog.getYamlError("Cannot read the stream, interrupted error");
futureResultConsumer.accept(error);
this.error = DiagnosticLog.getYamlError("Cannot read the stream, interrupted error");
return -1;
}
return -1;
@@ -92,25 +76,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());
}
}

@@ -119,44 +86,32 @@ 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
try {
Object result = env.getRuntime().call(iterator, nextMethodName);
if (result == null) {
done.set(true);
futureResultConsumer.accept(bError);
currentChunk = new byte[0];
semaphore.release();
// TODO : Should we panic here?
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 {
// Case where Completes with an error
done.set(true);
ravinperera00 marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (BError bError) {
// Panic with an error
done.set(true);
currentChunk = new byte[0];
// TODO : Should we panic here?
}

};
env.getRuntime().invokeMethodAsyncSequentially(iterator, nextMethodName, strandName, metadata, callback,
properties, returnType);
semaphore.acquire();
return !done.get();
}

public BError getError() {
return this.error;
}
}
Loading
Loading