Skip to content

Commit

Permalink
Merge pull request #546 from HindujaB/java21
Browse files Browse the repository at this point in the history
Migrate to Java 21
  • Loading branch information
warunalakshitha authored Nov 19, 2024
2 parents 6a03f24 + a3e676a commit e60e412
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 102 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-dependent-std-libs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ jobs:
matrix:
module: ${{ fromJson(inputs.ballerina_modules) }}
steps:
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17.0.7
java-version: 21

- name: Checkout module
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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/)

Expand Down
10 changes: 5 additions & 5 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.10.0"

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

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "mime-native"
version = "2.10.1"
path = "../native/build/libs/mime-native-2.10.1.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "../test-utils/build/libs/mime-test-utils-2.10.1.jar"
scope = "testOnly"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/mimepull-1.9.11.jar"
groupId = "org.jvnet.mimepull"
artifactId = "mimepull"
version = "1.9.11"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/jakarta.activation-api-2.0.1.jar"
groupId = "jakarta.activation"
artifactId = "jakarta.activation-api"
Expand Down
10 changes: 5 additions & 5 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.10.0"

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

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

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "../test-utils/build/libs/[email protected]@.jar"
scope = "testOnly"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/[email protected]@.jar"
groupId = "org.jvnet.mimepull"
artifactId = "mimepull"
version = "@mimepull.version@"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/[email protected]@.jar"
groupId = "jakarta.activation"
artifactId = "jakarta.activation-api"
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
*/

plugins {
id "com.github.spotbugs" version "5.0.14"
id "com.github.johnrengelman.shadow" version "8.1.1"
id "de.undercouch.download" version "5.4.0"
id "net.researchgate.release" version "2.8.0"
id "com.github.spotbugs" version "${githubSpotbugsVersion}"
id "com.github.johnrengelman.shadow" version "${githubJohnrengelmanShadowVersion}"
id "de.undercouch.download" version "${underCouchDownloadVersion}"
id "net.researchgate.release" version "${researchgateReleaseVersion}"
}

ext.ballerinaLangVersion = project.ballerinaLangVersion
Expand Down
15 changes: 10 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
org.gradle.caching=true
group=io.ballerina.stdlib
version=2.10.2-SNAPSHOT
ballerinaLangVersion=2201.10.0
ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87

mimepullVersion=1.9.11
puppycrawlCheckstyleVersion=10.12.0
githubJohnrengelmanShadowVersion=8.1.1
underCouchDownloadVersion=5.4.0
researchgateReleaseVersion=2.8.0
checkstyleToolVersion=10.12.0
githubSpotbugsVersion=6.0.18
jakartaActivationVersion=2.0.1
testngVersion=7.6.1
ballerinaGradlePluginVersion=2.2.4
mockitoVersion=5.3.1

stdlibIoVersion=1.6.0
stdlibLogVersion=2.10.0
observeVersion=1.3.0
observeInternalVersion=1.3.0
stdlibIoVersion=1.6.2-20241112-233100-995cf5f
stdlibLogVersion=2.10.1-20241113-120000-4577868
observeVersion=1.4.0-20241113-092000-b83ae74
observeInternalVersion=1.3.1-20241113-101700-265054d
7 changes: 5 additions & 2 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles")
checkstyleTest.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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package io.ballerina.stdlib.mime.util;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.async.Callback;
import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.creators.TypeCreator;
import io.ballerina.runtime.api.creators.ValueCreator;
Expand Down Expand Up @@ -48,8 +47,6 @@
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static io.ballerina.stdlib.mime.util.MimeConstants.BODY_PARTS;
import static io.ballerina.stdlib.mime.util.MimeConstants.BYTE_STREAM_NEXT_FUNC;
Expand Down Expand Up @@ -374,53 +371,44 @@ public static void writeByteStreamToOutputStream(Environment env, BObject entity
BStream byteStream = EntityBodyHandler.getByteStream(entity);
if (byteStream != null) {
BObject iteratorObj = byteStream.getIteratorObj();
CountDownLatch latch = new CountDownLatch(1);
writeContent(env, entity, outputStream, iteratorObj, latch);
try {
int timeout = 120;
boolean countDownReached = latch.await(timeout, TimeUnit.SECONDS);
if (!countDownReached) {
throw ErrorCreator.createError(StringUtils.fromString(
"Could not complete byte stream serialization within " + timeout + " seconds"));
}
} catch (InterruptedException e) {
log.warn("Interrupted before completing the content write");
}
writeContent(env, entity, outputStream, iteratorObj);
}
}

private static void writeContent(Environment env, BObject entity, OutputStream outputStream,
BObject iteratorObj, CountDownLatch latch) {
env.getRuntime().invokeMethodAsyncConcurrently(iteratorObj, BYTE_STREAM_NEXT_FUNC, null, null, new Callback() {
@Override
public void notifySuccess(Object result) {
if (result == null) {
entity.addNativeData(ENTITY_BYTE_STREAM, null);
latch.countDown();
return;
}
if (result instanceof BError error) {
entity.addNativeData(ENTITY_BYTE_STREAM, null);
this.notifyFailure(error);
}
try {
writeContentPart((BMap) result, outputStream);
} catch (Exception e) {
latch.countDown();
throw ErrorCreator.createError(StringUtils.fromString(
"Error occurred while writing the stream content: "
+ MimeUtil.removeJavaExceptionPrefix(e.getMessage())));
}
writeContent(env, entity, outputStream, iteratorObj, latch);
}
BObject iteratorObj) {
try {
Object result = env.getRuntime().callMethod(iteratorObj, BYTE_STREAM_NEXT_FUNC, null);
handleContentResult(env, entity, outputStream, result, iteratorObj);
} catch (BError error) {
handleContentPanic(error);
} catch (Throwable throwable) {
handleContentPanic(ErrorCreator.createError(throwable));
}
}

@Override
public void notifyFailure(BError bError) {
latch.countDown();
throw ErrorCreator.createError(StringUtils.fromString(
"Error occurred while streaming content: " + bError.getMessage()));
}
}, null, null, new Object[]{});
public static void handleContentResult(Environment env, BObject entity, OutputStream outputStream, Object result,
BObject iteratorObj) {
if (result == null) {
entity.addNativeData(ENTITY_BYTE_STREAM, null);
return;
}
if (result instanceof BError error) {
entity.addNativeData(ENTITY_BYTE_STREAM, null);
handleContentPanic(error);
}
try {
writeContentPart((BMap) result, outputStream);
} catch (Exception e) {
throw ErrorCreator.createError(StringUtils.fromString("Error occurred while writing the stream content: " +
MimeUtil.removeJavaExceptionPrefix(e.getMessage())));
}
writeContent(env, entity, outputStream, iteratorObj);
}

public static void handleContentPanic(BError bError) {
throw ErrorCreator.createError(StringUtils.fromString("Error occurred while streaming content: " +
bError.getMessage()));
}

/**
Expand All @@ -442,31 +430,35 @@ public static void writeEventStreamToOutputStream(Environment env, BObject entit
}

private static void writeEvent(Environment env, BObject eventStreamWriter) {
env.getRuntime().invokeMethodAsyncConcurrently(eventStreamWriter, WRITE_EVENT_STREAM_METHOD, null, null,
new Callback() {
@Override
public void notifySuccess(Object result) {
BObject entity = (BObject) eventStreamWriter.getNativeData(ENTITY);
OutputStream outputStream = (OutputStream) eventStreamWriter.getNativeData(OUTPUT_STREAM);
if (result == null) {
entity.addNativeData(ENTITY_BYTE_STREAM, null);
EntityBodyHandler.closeMessageOutputStream(outputStream);
return;
}
if (result instanceof BError error) {
entity.addNativeData(ENTITY_BYTE_STREAM, null);
throw error;
}
}

@Override
public void notifyFailure(BError bError) {
OutputStream outputStream = (OutputStream) eventStreamWriter.getNativeData(OUTPUT_STREAM);
EntityBodyHandler.closeMessageOutputStream(outputStream);
throw ErrorCreator.createError(StringUtils.fromString(
"Error occurred while streaming content: " + bError.getMessage()));
}
}, null, null);
try {
handleEventResult(eventStreamWriter, env.getRuntime().callMethod(eventStreamWriter,
WRITE_EVENT_STREAM_METHOD, null));
} catch (BError error) {
handleEventPanic(eventStreamWriter, error);
} catch (Throwable throwable) {
handleEventPanic(eventStreamWriter, ErrorCreator.createError(throwable));
}
}

public static void handleEventResult(BObject eventStreamWriter, Object result) {
BObject entity = (BObject) eventStreamWriter.getNativeData(ENTITY);
OutputStream outputStream = (OutputStream) eventStreamWriter.getNativeData(OUTPUT_STREAM);
if (result == null) {
entity.addNativeData(ENTITY_BYTE_STREAM, null);
EntityBodyHandler.closeMessageOutputStream(outputStream);
return;
}
if (result instanceof BError error) {
entity.addNativeData(ENTITY_BYTE_STREAM, null);
throw error;
}
}

private static void handleEventPanic(BObject eventStreamWriter, BError bError) {
OutputStream outputStream = (OutputStream) eventStreamWriter.getNativeData(OUTPUT_STREAM);
EntityBodyHandler.closeMessageOutputStream(outputStream);
throw ErrorCreator.createError(StringUtils.fromString("Error occurred while streaming content: " +
bError.getMessage()));
}

private static void closeMessageOutputStream(OutputStream messageOutputStream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

package io.ballerina.stdlib.mime.util;

import io.ballerina.runtime.api.PredefinedTypes;
import io.ballerina.runtime.api.creators.TypeCreator;
import io.ballerina.runtime.api.creators.ValueCreator;
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.BArray;
import io.ballerina.runtime.api.values.BMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

package io.ballerina.stdlib.mime.util;

import io.ballerina.runtime.api.PredefinedTypes;
import io.ballerina.runtime.api.creators.TypeCreator;
import io.ballerina.runtime.api.creators.ValueCreator;
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.BMap;
import io.ballerina.runtime.api.values.BObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
package io.ballerina.stdlib.mime.util;

import io.ballerina.runtime.api.Module;
import io.ballerina.runtime.api.PredefinedTypes;
import io.ballerina.runtime.api.TypeTags;
import io.ballerina.runtime.api.creators.ErrorCreator;
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.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.values.BArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
package io.ballerina.stdlib.mime.util;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.PredefinedTypes;
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.utils.StringUtils;
import io.ballerina.runtime.api.values.BArray;
import io.ballerina.runtime.api.values.BLink;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

package io.ballerina.stdlib.mime.util;

import io.ballerina.runtime.api.PredefinedTypes;
import io.ballerina.runtime.api.creators.TypeCreator;
import io.ballerina.runtime.api.creators.ValueCreator;
import io.ballerina.runtime.api.types.MapType;
import io.ballerina.runtime.api.types.PredefinedTypes;
import io.ballerina.runtime.api.values.BMap;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

package io.ballerina.stdlib.mime.util;

import io.ballerina.runtime.api.PredefinedTypes;
import io.ballerina.runtime.api.TypeTags;
import io.ballerina.runtime.api.creators.TypeCreator;
import io.ballerina.runtime.api.types.ArrayType;
import io.ballerina.runtime.api.types.PredefinedTypes;
import io.ballerina.runtime.api.types.Type;
import io.ballerina.runtime.api.types.TypeTags;
import io.ballerina.runtime.api.values.BMap;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BStreamingJson;
Expand Down

0 comments on commit e60e412

Please sign in to comment.