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 #24

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions .github/workflows/build-timestamped-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- java21
paths-ignore:
- '*.md'
- 'docs/**'
Expand All @@ -19,11 +20,11 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '21'

- name: Change to Timestamped Version
run: |
Expand Down
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-standard-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main
uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-with-bal-test-graalvm-template.yml@java21
with:
lang_tag: ${{ inputs.lang_tag }}
lang_version: ${{ inputs.lang_version }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/central-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '21'

- name: Build with Gradle
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '21'

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v1

- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '21'

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -35,11 +35,11 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v1

- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '21'

- name: Build the Project
env:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: 11
distribution: 'temurin'
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ public function main() returns error? {

### Set up the prerequisites

1. Download and install Java SE Development Kit (JDK) version 11 (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/javase-jdk11-downloads.html)
- [Oracle](https://www.oracle.com/java/technologies/javase-jdk21-downloads.html)

- [OpenJDK](https://adoptopenjdk.net/)

Expand Down
4 changes: 2 additions & 2 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ authors = ["xlibb"]
keywords = ["pubsub"]
repository = "https://github.com/xlibb/module-pubsub"
license = ["Apache-2.0"]
distribution = "2201.4.0"
distribution = "2201.10.0-20241025-103700-5c9e6a27"
icon = "icon.png"

[[platform.java11.dependency]]
[[platform.java21.dependency]]
path = "../native/build/libs/pubsub-native-1.4.1-SNAPSHOT.jar"
42 changes: 40 additions & 2 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.10.0-20241025-103700-5c9e6a27"

[[package]]
org = "ballerina"
Expand All @@ -14,6 +15,41 @@ modules = [
{org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.__internal"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.object"}
]

[[package]]
org = "ballerina"
name = "lang.array"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.__internal"}
]

[[package]]
org = "ballerina"
name = "lang.error"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "lang.object"
version = "0.0.0"
scope = "testOnly"

[[package]]
org = "ballerina"
name = "lang.runtime"
Expand All @@ -31,7 +67,9 @@ name = "test"
version = "0.0.0"
scope = "testOnly"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.array"},
{org = "ballerina", name = "lang.error"}
]
modules = [
{org = "ballerina", packageName = "test", moduleName = "test"}
Expand All @@ -40,7 +78,7 @@ modules = [
[[package]]
org = "xlibb"
name = "pipe"
version = "1.4.1"
version = "1.5.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand Down
2 changes: 1 addition & 1 deletion ballerina/tests/errors_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function testClosingPubSubWithClosedStream() returns error? {
test:assertEquals(pubsubError.message(), expectedMessage);
error? cause = pubsubError.cause();
test:assertTrue(cause is error);
expectedMessage = "Closing of a closed pipe is not allowed";
expectedMessage = "Attempting to close an already closed pipe";
test:assertEquals((<error>cause).message(), expectedMessage);
}

Expand Down
12 changes: 6 additions & 6 deletions ballerina/tests/pubsub_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function testGracefulShutdown() returns error? {
stream<string, error?> subscribe = check pubsub.subscribe("topic");
check pubsub.gracefulShutdown();
record {|string value;|}|error? msg = subscribe.next();
if msg !is () {
test:assertFail(string `Expected "()", received ${(typeof msg).toString()}`);
test:assertTrue(msg is error);
if msg is error {
test:assertEquals(msg.message(), "Events must not be consumed from a closed pipe");
Nuvindu marked this conversation as resolved.
Show resolved Hide resolved
}

string expectedValue = "Users cannot subscribe to a closed PubSub";
stream<string, error?>|Error new_subscriber = pubsub.subscribe("topic");
test:assertTrue(new_subscriber is Error);
Expand All @@ -64,10 +64,10 @@ function testForceShutdown() returns error? {
stream<string, error?> subscribe = check pubsub.subscribe("topic");
check pubsub.forceShutdown();
record {|string value;|}|error? msg = subscribe.next();
if msg !is () {
test:assertFail(string `Expected "()", received ${(typeof msg).toString()}`);
test:assertTrue(msg is error);
if msg is error {
test:assertEquals(msg.message(), "Events must not be consumed from a closed pipe");
}

string expectedValue = "Users cannot subscribe to a closed PubSub";
stream<string, error?>|Error new_subscriber = pubsub.subscribe("topic");
test:assertTrue(new_subscriber is Error);
Expand Down
4 changes: 2 additions & 2 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ authors = ["xlibb"]
keywords = ["pubsub"]
repository = "https://github.com/xlibb/module-pubsub"
license = ["Apache-2.0"]
distribution = "2201.4.0"
distribution = "2201.10.0-20241025-103700-5c9e6a27"
icon = "icon.png"

[[platform.java11.dependency]]
[[platform.java21.dependency]]
path = "../native/build/libs/[email protected]@.jar"
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
org.gradle.caching=true
group=io.xlibb
version=1.4.1-SNAPSHOT
ballerinaLangVersion=2201.4.0
ballerinaLangVersion=2201.10.0-20241025-103700-5c9e6a27

checkstylePluginVersion=8.18
spotbugsPluginVersion=4.5.1
spotbugsPluginVersion=6.0.18
shadowJarPluginVersion=5.2.0
downloadPluginVersion=4.0.4
releasePluginVersion=2.6.0
Expand All @@ -13,14 +13,14 @@ ballerinaGradlePluginVersion=1.1.0
#stdlib dependencies

# Level 01
stdlibIoVersion=1.4.0
stdlibTimeVersion=2.2.3
stdlibIoVersion=1.6.2-20240928-084100-656404f
stdlibTimeVersion=2.5.1-20240930-120200-e59222b

# Level 02
stdlibLogVersion=2.6.0
stdlibLogVersion=2.10.1-20240930-154200-5ab2aa4

# Ballerinax Observer
observeVersion=1.0.6
observeInternalVersion=1.0.5
observeVersion=1.3.1-20241007-161000-645452d
observeInternalVersion=1.3.1-20241015-172900-cdc3cb3

pipeVersion=1.4.1
pipeVersion=1.5.0-20241104-194300-4c6aa2b
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 5 additions & 2 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,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
12 changes: 5 additions & 7 deletions native/src/main/java/io/xlibb/pubsub/MethodCallback.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
package io.xlibb.pubsub;

import io.ballerina.runtime.api.Future;
import io.ballerina.runtime.api.async.Callback;
import io.ballerina.runtime.api.values.BError;

import java.util.concurrent.CompletableFuture;

import static io.xlibb.pubsub.utils.Utils.createError;

/**
* Callback class for running Ballerina methods in PubSub Native code.
*/
public class MethodCallback implements Callback {
private final Future future;
public class MethodCallback {
private final CompletableFuture<Object> future;

protected MethodCallback(Future future) {
protected MethodCallback(CompletableFuture<Object> future) {
this.future = future;
}

@Override
public void notifySuccess(Object o) {
if (o instanceof BError) {
this.notifyFailure((BError) o);
Expand All @@ -25,7 +24,6 @@ public void notifySuccess(Object o) {
}
}

@Override
public void notifyFailure(BError bError) {
BError pubsubError = createError("Failed to subscribe to topic", bError);
this.future.complete(pubsubError);
Expand Down
27 changes: 15 additions & 12 deletions native/src/main/java/io/xlibb/pubsub/PubSub.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
package io.xlibb.pubsub;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.Future;
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.StreamType;
import io.ballerina.runtime.api.types.Type;
import io.ballerina.runtime.api.utils.TypeUtils;
import io.ballerina.runtime.api.values.BArray;
Expand All @@ -32,6 +29,8 @@
import io.ballerina.runtime.api.values.BString;
import io.ballerina.runtime.api.values.BTypedesc;

import java.util.concurrent.CompletableFuture;

import static io.xlibb.pubsub.utils.Utils.AUTO_CREATE_TOPICS;
import static io.xlibb.pubsub.utils.Utils.CONSUME_STREAM_METHOD;
import static io.xlibb.pubsub.utils.Utils.IS_CLOSED;
Expand All @@ -40,6 +39,7 @@
import static io.xlibb.pubsub.utils.Utils.TIMER_FIELD_NAME;
import static io.xlibb.pubsub.utils.Utils.TOPICS;
import static io.xlibb.pubsub.utils.Utils.createError;
import static io.xlibb.pubsub.utils.Utils.getResult;

/**
* Provides a message communication model with publish/subscribe APIs.
Expand All @@ -62,16 +62,19 @@ public static Object subscribe(Environment environment, BObject pubsub, BString
} catch (BError bError) {
return bError;
}
Object[] arguments = new Object[]{timeout, true, typeParam, true};
Future future = environment.markAsync();
StreamType streamType = TypeCreator.createStreamType(typeParam.getDescribingType(),
TypeCreator.createUnionType(PredefinedTypes.TYPE_ERROR,
PredefinedTypes.TYPE_NULL));
Object[] arguments = new Object[]{timeout, typeParam};
CompletableFuture<Object> future = new CompletableFuture<>();
MethodCallback callback = new MethodCallback(future);
environment.getRuntime()
.invokeMethodAsyncConcurrently(pipe, CONSUME_STREAM_METHOD, null, null, callback, null, streamType,
arguments);
return null;
return environment.yieldAndRun(() -> {
ravinperera00 marked this conversation as resolved.
Show resolved Hide resolved
try {
Object result = environment.getRuntime().startIsolatedWorker(pipe, CONSUME_STREAM_METHOD, null,
null, null, arguments).get();
callback.notifySuccess(result);
} catch (BError bError) {
callback.notifyFailure(bError);
}
return getResult(future);
});
}

@SuppressWarnings("unchecked")
Expand Down
Loading