From 4c671d124824b36dae5d182d96ce00ce8af04914 Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Thu, 3 Oct 2024 15:51:13 +0530 Subject: [PATCH 1/7] Migrate to Java 21 --- .../workflows/build-timestamped-master.yml | 2 +- .../workflows/build-with-bal-test-graalvm.yml | 2 +- .github/workflows/central-publish.yml | 2 +- .github/workflows/publish-release.yml | 2 +- .github/workflows/pull-request.yml | 2 +- .github/workflows/trivy-scan.yml | 2 +- README.md | 2 +- build-config/resources/Ballerina.toml | 4 +- compiler-plugin-test/build.gradle | 7 +- compiler-plugin/build.gradle | 7 +- gradle.properties | 10 +- native/build.gradle | 9 +- .../io/BallerinaByteBlockInputStream.java | 76 +++--------- .../lib/data/xmldata/io/DataReaderTask.java | 111 ------------------ .../lib/data/xmldata/utils/DataReader.java | 59 ++++++++++ .../lib/data/xmldata/xml/Native.java | 14 +-- 16 files changed, 114 insertions(+), 197 deletions(-) delete mode 100644 native/src/main/java/io/ballerina/lib/data/xmldata/io/DataReaderTask.java create mode 100644 native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataReader.java diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 72d594a..6411caf 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -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 diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 291054d..a66ffb5 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -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 }} diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 11922b5..ebe213e 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -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 }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index c6044e4..73dfb78 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -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.xmldata diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 06f4f56..f45c742 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -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 diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index c02c8ff..41e8f6a 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -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 diff --git a/README.md b/README.md index 817dc92..98b2c5c 100644 --- a/README.md +++ b/README.md @@ -464,7 +464,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/) diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index e881ae9..6f8db8a 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -9,13 +9,13 @@ license = ["Apache-2.0"] distribution = "2201.10.0" export = ["data.xmldata"] -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.lib" artifactId = "data-native" version = "@toml.version@" path = "../native/build/libs/data.xmldata-native-@project.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "constraint-native" version = "@constraint.version@" diff --git a/compiler-plugin-test/build.gradle b/compiler-plugin-test/build.gradle index 6a96468..ec3b0a1 100644 --- a/compiler-plugin-test/build.gradle +++ b/compiler-plugin-test/build.gradle @@ -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 diff --git a/compiler-plugin/build.gradle b/compiler-plugin/build.gradle index 78ae721..7192800 100644 --- a/compiler-plugin/build.gradle +++ b/compiler-plugin/build.gradle @@ -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 diff --git a/gradle.properties b/gradle.properties index f92a9e9..241b56c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,18 +1,18 @@ org.gradle.caching=true group=io.ballerina.lib version=1.0.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 ballerinaGradlePluginVersion=2.0.1 -stdlibIoVersion=1.6.1 -stdlibTimeVersion=2.4.0 -stdlibConstraintVersion=1.5.0 +stdlibIoVersion=1.6.2-20240928-084100-656404f +stdlibTimeVersion=2.5.1-20240930-120200-e59222b +stdlibConstraintVersion=1.5.1-20240930-123400-5ecd396 diff --git a/native/build.gradle b/native/build.gradle index ceb83f2..8398a3a 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -51,9 +51,12 @@ 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") + enabled = false + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW reportsDir = file("$project.buildDir/reports/spotbugs") reports { html.enabled true diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java b/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java index 4811f56..316fddb 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java @@ -21,7 +21,6 @@ import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.xmldata.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; @@ -37,7 +36,6 @@ 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. stream @@ -55,13 +53,12 @@ public class BallerinaByteBlockInputStream extends InputStream { private final Map properties; private final AtomicBoolean done = new AtomicBoolean(false); private final MethodType closeMethod; - private final Consumer futureResultConsumer; private byte[] currentChunk = new byte[0]; private int nextChunkIndex = 0; public BallerinaByteBlockInputStream(Environment env, BObject iterator, MethodType nextMethod, - MethodType closeMethod, Consumer futureResultConsumer) { + MethodType closeMethod) { this.env = env; this.iterator = iterator; this.nextMethodName = nextMethod.getName(); @@ -70,7 +67,6 @@ public BallerinaByteBlockInputStream(Environment env, BObject iterator, MethodTy this.strandName = env.getStrandName().orElse(""); this.metadata = env.getStrandMetadata(); this.properties = Map.of(); - this.futureResultConsumer = futureResultConsumer; } @Override @@ -89,7 +85,6 @@ public int read() { } } catch (InterruptedException e) { BError error = DiagnosticLog.error(DiagnosticErrorCode.CAN_NOT_READ_STREAM); - futureResultConsumer.accept(error); return -1; } return -1; @@ -100,23 +95,7 @@ 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()); } } @@ -125,44 +104,25 @@ 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 valueRecord = (BMap) 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 valueRecord = (BMap) result; + final BString value = Arrays.stream(valueRecord.getKeys()).findFirst().get(); + final BArray arrayValue = valueRecord.getArrayValue(value); + currentChunk = arrayValue.getByteArray(); + } else { + done.set(true); + return true; } - - }; - env.getRuntime().invokeMethodAsyncSequentially(iterator, nextMethodName, strandName, metadata, callback, - properties, returnType); - semaphore.acquire(); + } catch (BError bError) { + done.set(true); + return true; + } return !done.get(); } } diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/io/DataReaderTask.java b/native/src/main/java/io/ballerina/lib/data/xmldata/io/DataReaderTask.java deleted file mode 100644 index 126d8ad..0000000 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/io/DataReaderTask.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package io.ballerina.lib.data.xmldata.io; - -import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; -import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; -import io.ballerina.lib.data.xmldata.xml.XmlParser; -import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; -import io.ballerina.runtime.api.types.MethodType; -import io.ballerina.runtime.api.types.ObjectType; -import io.ballerina.runtime.api.utils.TypeUtils; -import io.ballerina.runtime.api.values.BMap; -import io.ballerina.runtime.api.values.BObject; -import io.ballerina.runtime.api.values.BString; -import io.ballerina.runtime.api.values.BTypedesc; - -import java.io.InputStreamReader; -import java.util.function.Consumer; - -/** - * This class will read data from a Ballerina Stream of byte blocks, in non-blocking manner. - * - * @since 0.1.0 - */ -public class DataReaderTask implements Runnable { - - private static final String METHOD_NAME_NEXT = "next"; - private static final String METHOD_NAME_CLOSE = "close"; - - private final Environment env; - private final BObject iteratorObj; - private final Future future; - private final BTypedesc typed; - private final BMap options; - - public DataReaderTask(Environment env, BObject iteratorObj, Future future, BTypedesc typed, - BMap options) { - this.env = env; - this.iteratorObj = iteratorObj; - this.future = future; - this.typed = typed; - this.options = options; - } - - static MethodType resolveNextMethod(BObject iterator) { - MethodType method = getMethodType(iterator, METHOD_NAME_NEXT); - if (method != null) { - return method; - } - throw new IllegalStateException("next method not found in the iterator object"); - } - - static MethodType resolveCloseMethod(BObject iterator) { - return getMethodType(iterator, METHOD_NAME_CLOSE); - } - - private static MethodType getMethodType(BObject iterator, String methodName) { - ObjectType objectType = (ObjectType) TypeUtils.getReferredType(iterator.getOriginalType()); - MethodType[] methods = objectType.getMethods(); - // Assumes compile-time validation of the iterator object - for (MethodType method : methods) { - if (method.getName().equals(methodName)) { - return method; - } - } - return null; - } - - @Override - public void run() { - DataReaderTask.ResultConsumer resultConsumer = new DataReaderTask.ResultConsumer<>(future); - try (var byteBlockSteam = new BallerinaByteBlockInputStream(env, iteratorObj, resolveNextMethod(iteratorObj), - resolveCloseMethod(iteratorObj), resultConsumer)) { - Object result = XmlParser.parse(new InputStreamReader(byteBlockSteam), options, typed); - future.complete(result); - } catch (Exception e) { - future.complete(DiagnosticLog.error(DiagnosticErrorCode.STREAM_BROKEN, e.getMessage())); - } - } - - /** - * This class will hold module related utility functions. - * - * @param The type of the result - * @param future The future to complete - * @since 0.1.0 - */ - public record ResultConsumer(Future future) implements Consumer { - - @Override - public void accept(T t) { - future.complete(t); - } - } -} diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataReader.java b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataReader.java new file mode 100644 index 0000000..02124ad --- /dev/null +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataReader.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.lib.data.xmldata.utils; + +import io.ballerina.runtime.api.types.MethodType; +import io.ballerina.runtime.api.types.ObjectType; +import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.runtime.api.values.BObject; + +/** + * A class that holds util methods needed for BallerinaByteBlockInputStream class. + * + * @since 11.0.0 + */ +public class DataReader { + + private static final String METHOD_NAME_NEXT = "next"; + private static final String METHOD_NAME_CLOSE = "close"; + + public static MethodType resolveNextMethod(BObject iterator) { + MethodType method = getMethodType(iterator, METHOD_NAME_NEXT); + if (method != null) { + return method; + } + throw new IllegalStateException("next method not found in the iterator object"); + } + + public static MethodType resolveCloseMethod(BObject iterator) { + return getMethodType(iterator, METHOD_NAME_CLOSE); + } + + public static MethodType getMethodType(BObject iterator, String methodName) { + ObjectType objectType = (ObjectType) TypeUtils.getReferredType(iterator.getOriginalType()); + MethodType[] methods = objectType.getMethods(); + // Assumes compile-time validation of the iterator object + for (MethodType method : methods) { + if (method.getName().equals(methodName)) { + return method; + } + } + return null; + } +} diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java index 22de127..8c986da 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java @@ -18,12 +18,10 @@ package io.ballerina.lib.data.xmldata.xml; -import io.ballerina.lib.data.xmldata.io.DataReaderTask; -import io.ballerina.lib.data.xmldata.io.DataReaderThreadPool; +import io.ballerina.lib.data.xmldata.io.BallerinaByteBlockInputStream; import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; @@ -36,6 +34,9 @@ import java.io.InputStreamReader; import java.io.StringReader; +import static io.ballerina.lib.data.xmldata.utils.DataReader.resolveCloseMethod; +import static io.ballerina.lib.data.xmldata.utils.DataReader.resolveNextMethod; + /** * Xml conversion. * @@ -69,10 +70,9 @@ public static Object parseBytes(BArray xml, BMap options, BType public static Object parseStream(Environment env, BStream xml, BMap options, BTypedesc typed) { try { final BObject iteratorObj = xml.getIteratorObj(); - final Future future = env.markAsync(); - DataReaderTask task = new DataReaderTask(env, iteratorObj, future, typed, options); - DataReaderThreadPool.EXECUTOR_SERVICE.submit(task); - return null; + BallerinaByteBlockInputStream byteBlockSteam = new BallerinaByteBlockInputStream(env, + iteratorObj, resolveNextMethod(iteratorObj), resolveCloseMethod(iteratorObj)); + return XmlParser.parse(new InputStreamReader(byteBlockSteam), options, typed); } catch (Exception e) { return DiagnosticLog.error(DiagnosticErrorCode.XML_PARSE_ERROR, e.getMessage()); } From 6fa0051200d248c7006159bace622d8180e4d193 Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Thu, 3 Oct 2024 15:59:50 +0530 Subject: [PATCH 2/7] Downgrade stdlibTime version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 241b56c..c85a97c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ researchgateReleaseVersion=2.8.0 ballerinaGradlePluginVersion=2.0.1 stdlibIoVersion=1.6.2-20240928-084100-656404f -stdlibTimeVersion=2.5.1-20240930-120200-e59222b +stdlibTimeVersion=2.4.0 stdlibConstraintVersion=1.5.1-20240930-123400-5ecd396 From 552f177f499f4844425cc19c663c086aa982c140 Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Thu, 3 Oct 2024 23:12:51 +0530 Subject: [PATCH 3/7] Refactor code --- .../io/BallerinaByteBlockInputStream.java | 21 +++++++------------ .../lib/data/xmldata/xml/Native.java | 6 +++++- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java b/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java index 316fddb..7d69090 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java @@ -21,9 +21,7 @@ import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; import io.ballerina.runtime.api.Environment; -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,7 +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; @@ -47,12 +44,9 @@ 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 properties; private final AtomicBoolean done = new AtomicBoolean(false); private final MethodType closeMethod; + private BError error = null; private byte[] currentChunk = new byte[0]; private int nextChunkIndex = 0; @@ -62,11 +56,7 @@ public BallerinaByteBlockInputStream(Environment env, BObject iterator, MethodTy 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(); } @Override @@ -84,7 +74,7 @@ public int read() { return read(); } } catch (InterruptedException e) { - BError error = DiagnosticLog.error(DiagnosticErrorCode.CAN_NOT_READ_STREAM); + this.error = DiagnosticLog.error(DiagnosticErrorCode.CAN_NOT_READ_STREAM); return -1; } return -1; @@ -117,12 +107,15 @@ private boolean readNextChunk() throws InterruptedException { currentChunk = arrayValue.getByteArray(); } else { done.set(true); - return true; } } catch (BError bError) { done.set(true); - return true; + currentChunk = new byte[0]; } return !done.get(); } + + public BError getError() { + return this.error; + } } diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java index 8c986da..8eda9f9 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/Native.java @@ -72,7 +72,11 @@ public static Object parseStream(Environment env, BStream xml, BMap Date: Fri, 4 Oct 2024 00:11:02 +0530 Subject: [PATCH 4/7] Update stdlibTime version --- ballerina/Dependencies.toml | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 81e9251..e567c69 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -116,7 +116,7 @@ modules = [ [[package]] org = "ballerina" name = "time" -version = "2.4.1" +version = "2.5.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} diff --git a/gradle.properties b/gradle.properties index c85a97c..d42624e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ researchgateReleaseVersion=2.8.0 ballerinaGradlePluginVersion=2.0.1 stdlibIoVersion=1.6.2-20240928-084100-656404f -stdlibTimeVersion=2.4.0 +stdlibTimeVersion=2.5.1-20241003-232800-e59222b stdlibConstraintVersion=1.5.1-20240930-123400-5ecd396 From 5a7cd95f623b3ece723f7229a3455b2f22722ea5 Mon Sep 17 00:00:00 2001 From: Ravin Perera <62183347+ravinperera00@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:53:40 +0530 Subject: [PATCH 5/7] Add suggestions from code review Co-authored-by: Waruna Lakshitha --- .../java/io/ballerina/lib/data/xmldata/utils/DataReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataReader.java b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataReader.java index 02124ad..5d289ba 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataReader.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataReader.java @@ -26,7 +26,7 @@ /** * A class that holds util methods needed for BallerinaByteBlockInputStream class. * - * @since 11.0.0 + * @since 2.5.0 */ public class DataReader { From 12fa2eecb9d3a9cff1eebaa4534ea92e3093ac39 Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Wed, 13 Nov 2024 11:33:23 +0530 Subject: [PATCH 6/7] Migrate to new Runtime APIs --- ballerina/Ballerina.toml | 14 +++++++------- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 8 ++++---- gradle.properties | 8 ++++---- .../io/ballerina/lib/data/xmldata/FromString.java | 4 ++-- .../xmldata/io/BallerinaByteBlockInputStream.java | 6 ++---- .../lib/data/xmldata/utils/Constants.java | 2 +- .../lib/data/xmldata/utils/DataUtils.java | 4 ++-- .../ballerina/lib/data/xmldata/xml/XmlParser.java | 4 ++-- .../lib/data/xmldata/xml/XmlTraversal.java | 4 ++-- 10 files changed, 27 insertions(+), 29 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 65c2357..143368a 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "data.xmldata" -version = "1.0.0" +version = "1.0.1" authors = ["Ballerina"] keywords = ["xml"] repository = "https://github.com/ballerina-platform/module-ballerina-data-xmldata" @@ -9,14 +9,14 @@ license = ["Apache-2.0"] distribution = "2201.10.0" export = ["data.xmldata"] -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.lib" artifactId = "data-native" -version = "1.0.0" -path = "../native/build/libs/data.xmldata-native-1.0.0.jar" +version = "1.0.1" +path = "../native/build/libs/data.xmldata-native-1.0.1-SNAPSHOT.jar" -[[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.6.0" +path = "./lib/constraint-native-1.6.0-20241113-090900-d276ad5.jar" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 1669a30..d69411d 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "constraint-compiler-plugin" class = "io.ballerina.lib.data.xmldata.compiler.XmldataCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/data.xmldata-compiler-plugin-1.0.0.jar" +path = "../compiler-plugin/build/libs/data.xmldata-compiler-plugin-1.0.1-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index e567c69..aed09f8 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,12 +5,12 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.10.0" +distribution-version = "2201.11.0-20241112-214900-6b80ab87" [[package]] org = "ballerina" name = "constraint" -version = "1.5.0" +version = "1.6.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} @@ -22,7 +22,7 @@ modules = [ [[package]] org = "ballerina" name = "data.xmldata" -version = "1.0.0" +version = "1.0.1" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "io"}, @@ -116,7 +116,7 @@ modules = [ [[package]] org = "ballerina" name = "time" -version = "2.5.1" +version = "2.6.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} diff --git a/gradle.properties b/gradle.properties index d42624e..91d43e8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.caching=true group=io.ballerina.lib version=1.0.1-SNAPSHOT -ballerinaLangVersion=2201.10.0-20241002-115300-57eee14c +ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87 checkstyleToolVersion=10.12.0 puppycrawlCheckstyleVersion=10.12.0 @@ -13,6 +13,6 @@ underCouchDownloadVersion=4.0.4 researchgateReleaseVersion=2.8.0 ballerinaGradlePluginVersion=2.0.1 -stdlibIoVersion=1.6.2-20240928-084100-656404f -stdlibTimeVersion=2.5.1-20241003-232800-e59222b -stdlibConstraintVersion=1.5.1-20240930-123400-5ecd396 +stdlibIoVersion=1.6.2-20241112-233100-995cf5f +stdlibTimeVersion=2.6.0-20241113-073800-201b904 +stdlibConstraintVersion=1.6.0-20241113-090900-d276ad5 diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/FromString.java b/native/src/main/java/io/ballerina/lib/data/xmldata/FromString.java index d48b942..57d3a2f 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/FromString.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/FromString.java @@ -20,12 +20,12 @@ import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.types.PredefinedTypes; import io.ballerina.runtime.api.types.ReferenceType; import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.types.UnionType; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BDecimal; diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java b/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java index 7d69090..9a076a0 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/io/BallerinaByteBlockInputStream.java @@ -31,7 +31,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.Arrays; -import java.util.concurrent.Semaphore; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -83,9 +82,8 @@ public int read() { @Override public void close() throws IOException { super.close(); - Semaphore semaphore = new Semaphore(0); if (closeMethod != null) { - env.getRuntime().call(iterator, closeMethod.getName()); + env.getRuntime().callMethod(iterator, closeMethod.getName(), null); } } @@ -95,7 +93,7 @@ private boolean hasBytesInCurrentChunk() { private boolean readNextChunk() throws InterruptedException { try { - Object result = env.getRuntime().call(iterator, nextMethodName); + Object result = env.getRuntime().callMethod(iterator, nextMethodName, null); if (result == null) { done.set(true); return true; diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/Constants.java b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/Constants.java index 791e568..146accc 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/Constants.java @@ -18,10 +18,10 @@ package io.ballerina.lib.data.xmldata.utils; -import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.PredefinedTypes; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BXmlItem; diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java index 0a8cd06..78021eb 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/utils/DataUtils.java @@ -24,18 +24,18 @@ import io.ballerina.lib.data.xmldata.xml.QualifiedNameMap; import io.ballerina.lib.data.xmldata.xml.QualifiedNameSemantic; import io.ballerina.runtime.api.Module; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.types.Field; import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.PredefinedTypes; import io.ballerina.runtime.api.types.RecordType; import io.ballerina.runtime.api.types.ReferenceType; import io.ballerina.runtime.api.types.TupleType; import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.types.UnionType; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java index 113f1b8..0ed318e 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlParser.java @@ -23,16 +23,16 @@ import io.ballerina.lib.data.xmldata.utils.DataUtils; import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.types.Field; import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.PredefinedTypes; import io.ballerina.runtime.api.types.RecordType; import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.utils.XmlUtils; diff --git a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlTraversal.java b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlTraversal.java index 0d1776f..273ee4a 100644 --- a/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlTraversal.java +++ b/native/src/main/java/io/ballerina/lib/data/xmldata/xml/XmlTraversal.java @@ -23,16 +23,16 @@ import io.ballerina.lib.data.xmldata.utils.DataUtils.XmlAnalyzerData; import io.ballerina.lib.data.xmldata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.xmldata.utils.DiagnosticLog; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.types.Field; import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.PredefinedTypes; import io.ballerina.runtime.api.types.RecordType; import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.types.UnionType; import io.ballerina.runtime.api.types.XmlNodeType; import io.ballerina.runtime.api.utils.StringUtils; From 16181045ed7b50261f39cbd25aafd5db768b0f0e Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Mon, 18 Nov 2024 10:19:39 +0530 Subject: [PATCH 7/7] Use main branch for github actions --- .github/workflows/build-timestamped-master.yml | 2 +- .github/workflows/build-with-bal-test-graalvm.yml | 2 +- .github/workflows/central-publish.yml | 2 +- .github/workflows/publish-release.yml | 2 +- .github/workflows/pull-request.yml | 2 +- .github/workflows/trivy-scan.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 6411caf..72d594a 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main secrets: inherit diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index a66ffb5..291054d 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main with: lang_tag: ${{ inputs.lang_tag }} lang_version: ${{ inputs.lang_version }} diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index ebe213e..11922b5 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main secrets: inherit with: environment: ${{ github.event.inputs.environment }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 73dfb78..c6044e4 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main secrets: inherit with: package-name: data.xmldata diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index f45c742..06f4f56 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main secrets: inherit diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 41e8f6a..c02c8ff 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main secrets: inherit