Skip to content

Commit

Permalink
Migrate to Java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
ravinperera00 committed Oct 14, 2024
1 parent 2ebdfde commit e061407
Show file tree
Hide file tree
Showing 18 changed files with 182 additions and 159 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: java.jms
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,7 +10,7 @@ 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
with:
additional-windows-test-flags: "-x test"
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/trigger-load-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
call_stdlib_trigger_load_test_workflow:
name: Run StdLib Load Test Workflow
if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }}
uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@java21
with:
repo_name: 'module-ballerina-java.jms'
runtime_artifacts_url: 'https://api.github.com/repos/ballerina-platform/module-ballerina-java.jms/actions/artifacts'
Expand Down
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 @@ -118,7 +118,7 @@ This repository only contains the source code for the library.

### 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
10 changes: 5 additions & 5 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ keywords = ["jms"]
repository = "https://github.com/ballerina-platform/module-ballerina-java.jms"
icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.8.0"
distribution = "2201.10.0-20241011-161100-51978649"

[build-options]
observabilityIncluded = true

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

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "java.jms-native"
version = "1.0.2"
path = "../native/build/libs/java.jms-native-1.0.2-SNAPSHOT.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "org.slf4j"
artifactId = "slf4j-api"
version = "2.0.7"
path = "./lib/slf4j-api-2.0.7.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "javax.jms"
artifactId = "javax.jms-api"
version = "2.0.1"
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.8.0"
distribution-version = "2201.10.0-20241011-161100-51978649"

[[package]]
org = "ballerina"
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 @@ -7,27 +7,27 @@ keywords = ["jms"]
repository = "https://github.com/ballerina-platform/module-ballerina-java.jms"
icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.8.0"
distribution = "2201.10.0-20241011-161100-51978649"

[build-options]
observabilityIncluded = true

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

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

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "org.slf4j"
artifactId = "slf4j-api"
version = "@slf4j.version@"
path = "./lib/slf4j-api-@slf4j.version@.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "javax.jms"
artifactId = "javax.jms-api"
version = "@javax.jms.version@"
Expand Down
18 changes: 9 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
org.gradle.caching=true
group=io.ballerina.stdlib
version=1.0.2-SNAPSHOT
ballerinaLangVersion=2201.8.0
ballerinaLangVersion=2201.10.0-20241011-161100-51978649

checkstylePluginVersion=10.12.1
spotbugsPluginVersion=5.0.14
spotbugsPluginVersion=6.0.18
shadowJarPluginVersion=8.1.1
downloadPluginVersion=5.4.0
releasePluginVersion=2.8.0
Expand All @@ -20,15 +20,15 @@ activeMQDriverVersion=1.0.1
#stdlib dependencies

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

# Level 02
stdlibLogVersion=2.9.0
stdlibCryptoVersion=2.5.0
stdlibLogVersion=2.10.1-20240930-154200-5ab2aa4
stdlibCryptoVersion=2.7.3-20240930-132000-5ecc9ab

# Level 03
stdlibUuidVersion=1.7.0
stdlibUuidVersion=1.8.1-20241009-134600-a05012b

observeVersion=1.2.0
observeInternalVersion=1.2.0
observeVersion=1.3.1-20241007-161000-645452d
observeInternalVersion=1.3.1-20241007-182700-a5f77a1
7 changes: 5 additions & 2 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,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
52 changes: 52 additions & 0 deletions native/src/main/java/io/ballerina/stdlib/java.jms/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2024 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. 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.stdlib.java.jms;

import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.values.BError;

import java.util.concurrent.CompletableFuture;

/**
* Util methods for java.jms operations.
*/
public class Util {
private Util() {
//private constructor
}

public static Object getResult(CompletableFuture<Object> balFuture) {
try {
return balFuture.get();
} catch (Throwable throwable) {
throw ErrorCreator.createError(throwable);
}
}

public static void notifySuccess(Object o) {
if (o instanceof BError) {
((BError) o).printStackTrace();
}
}

public static void notifyFailure(BError bError) {
bError.printStackTrace();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
package io.ballerina.stdlib.java.jms.consumer;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.Future;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.api.values.BMap;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BString;
import io.ballerina.stdlib.java.jms.BallerinaJmsException;
import io.ballerina.stdlib.java.jms.Util;

import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand Down Expand Up @@ -128,31 +129,33 @@ private static MessageConsumer createConsumer(Session session, BMap<BString, Obj
*/
public static Object receive(Environment env, BObject consumer, long timeout) {
MessageConsumer nativeConsumer = (MessageConsumer) consumer.getNativeData(NATIVE_CONSUMER);
Future balFuture = env.markAsync();
executorService.execute(() -> {
try {
Message message = nativeConsumer.receive(timeout);
if (Objects.isNull(message)) {
balFuture.complete(null);
} else {
BMap<BString, Object> ballerinaMsg = getBallerinaMessage(message);
balFuture.complete(ballerinaMsg);
return env.yieldAndRun(() -> {
CompletableFuture<Object> balFuture = new CompletableFuture<>();
executorService.execute(() -> {
try {
Message message = nativeConsumer.receive(timeout);
if (Objects.isNull(message)) {
balFuture.complete(null);
} else {
BMap<BString, Object> ballerinaMsg = getBallerinaMessage(message);
balFuture.complete(ballerinaMsg);
}
} catch (JMSException exception) {
BError bError = createError(JMS_ERROR,
String.format("Error occurred while receiving messages: %s", exception.getMessage()),
exception);
balFuture.complete(bError);
} catch (BallerinaJmsException exception) {
balFuture.complete(createError(JMS_ERROR, exception.getMessage(), exception));
} catch (Exception exception) {
BError bError = createError(JMS_ERROR,
String.format("Unknown error occurred while processing the received messages: %s",
exception.getMessage()), exception);
balFuture.complete(bError);
}
} catch (JMSException exception) {
BError bError = createError(JMS_ERROR,
String.format("Error occurred while receiving messages: %s", exception.getMessage()),
exception);
balFuture.complete(bError);
} catch (BallerinaJmsException exception) {
balFuture.complete(createError(JMS_ERROR, exception.getMessage(), exception));
} catch (Exception exception) {
BError bError = createError(JMS_ERROR,
String.format("Unknown error occurred while processing the received messages: %s",
exception.getMessage()), exception);
balFuture.complete(bError);
}
});
return Util.getResult(balFuture);
});
return null;
}

/**
Expand All @@ -165,31 +168,33 @@ public static Object receive(Environment env, BObject consumer, long timeout) {
*/
public static Object receiveNoWait(Environment env, BObject consumer) {
MessageConsumer nativeConsumer = (MessageConsumer) consumer.getNativeData(NATIVE_CONSUMER);
Future balFuture = env.markAsync();
executorService.execute(() -> {
try {
Message message = nativeConsumer.receiveNoWait();
if (Objects.isNull(message)) {
balFuture.complete(null);
} else {
BMap<BString, Object> ballerinaMsg = getBallerinaMessage(message);
balFuture.complete(ballerinaMsg);
return env.yieldAndRun(() -> {
CompletableFuture<Object> balFuture = new CompletableFuture<>();
executorService.execute(() -> {
try {
Message message = nativeConsumer.receiveNoWait();
if (Objects.isNull(message)) {
balFuture.complete(null);
} else {
BMap<BString, Object> ballerinaMsg = getBallerinaMessage(message);
balFuture.complete(ballerinaMsg);
}
} catch (JMSException exception) {
BError bError = createError(JMS_ERROR,
String.format("Error occurred while receiving messages: %s", exception.getMessage()),
exception);
balFuture.complete(bError);
} catch (BallerinaJmsException exception) {
balFuture.complete(createError(JMS_ERROR, exception.getMessage(), exception));
} catch (Exception exception) {
BError bError = createError(JMS_ERROR,
String.format("Unknown error occurred while processing the received messages: %s",
exception.getMessage()), exception);
balFuture.complete(bError);
}
} catch (JMSException exception) {
BError bError = createError(JMS_ERROR,
String.format("Error occurred while receiving messages: %s", exception.getMessage()),
exception);
balFuture.complete(bError);
} catch (BallerinaJmsException exception) {
balFuture.complete(createError(JMS_ERROR, exception.getMessage(), exception));
} catch (Exception exception) {
BError bError = createError(JMS_ERROR,
String.format("Unknown error occurred while processing the received messages: %s",
exception.getMessage()), exception);
balFuture.complete(bError);
}
});
return Util.getResult(balFuture);
});
return null;
}

/**
Expand Down
Loading

0 comments on commit e061407

Please sign in to comment.