Skip to content

Commit

Permalink
Merge pull request #1328 from ravinperera00/java21_sync
Browse files Browse the repository at this point in the history
Migrate to Java 21
  • Loading branch information
warunalakshitha authored Nov 18, 2024
2 parents 662f258 + 8705de3 commit 8574240
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 48 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This repository only contains the source code for the module.

### 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
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ keywords = ["security", "authorization", "introspection"]
repository = "https://github.com/ballerina-platform/module-ballerina-oauth2"
icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.10.0"
distribution = "2201.10.0-20241007-143200-6b69ca80"

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

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "oauth2-native"
version = "2.12.1"
Expand Down
20 changes: 10 additions & 10 deletions ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "cache"
version = "3.8.0"
version = "3.8.1"
dependencies = [
{org = "ballerina", name = "constraint"},
{org = "ballerina", name = "jballerina.java"},
Expand All @@ -24,15 +24,15 @@ modules = [
[[package]]
org = "ballerina"
name = "constraint"
version = "1.5.0"
version = "1.6.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "crypto"
version = "2.7.2"
version = "2.7.3"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand All @@ -44,7 +44,7 @@ modules = [
[[package]]
org = "ballerina"
name = "io"
version = "1.6.0"
version = "1.6.2"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "lang.value"}
Expand Down Expand Up @@ -116,7 +116,7 @@ dependencies = [
[[package]]
org = "ballerina"
name = "log"
version = "2.10.0"
version = "2.10.1"
dependencies = [
{org = "ballerina", name = "io"},
{org = "ballerina", name = "jballerina.java"},
Expand Down Expand Up @@ -148,15 +148,15 @@ modules = [
[[package]]
org = "ballerina"
name = "observe"
version = "1.3.0"
version = "1.4.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]

[[package]]
org = "ballerina"
name = "task"
version = "2.5.0"
version = "2.5.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"},
{org = "ballerina", name = "time"}
Expand All @@ -179,7 +179,7 @@ modules = [
[[package]]
org = "ballerina"
name = "time"
version = "2.4.0"
version = "2.6.0"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand All @@ -190,7 +190,7 @@ modules = [
[[package]]
org = "ballerina"
name = "url"
version = "2.4.0"
version = "2.4.1"
dependencies = [
{org = "ballerina", name = "jballerina.java"}
]
Expand Down
6 changes: 3 additions & 3 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ keywords = ["security", "authorization", "introspection"]
repository = "https://github.com/ballerina-platform/module-ballerina-oauth2"
icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.10.0"
distribution = "2201.10.0-20241007-143200-6b69ca80"

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

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "oauth2-native"
version = "@toml.version@"
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,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}"
}

allprojects {
Expand Down
26 changes: 15 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ group=io.ballerina.stdlib
version=2.12.1-SNAPSHOT
puppycrawlCheckstyleVersion=10.12.0
ballerinaGradlePluginVersion=2.0.1
ballerinaLangVersion=2201.10.0
ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87
githubJohnrengelmanShadowVersion=8.1.1
underCouchDownloadVersion=5.4.0
researchgateReleaseVersion=2.8.0
githubSpotbugsVersion=6.0.18

# Dependencies
stdlibCacheVersion=3.8.0
stdlibCryptoVersion=2.7.2
stdlibLogVersion=2.10.0
stdlibTimeVersion=2.4.0
stdlibUrlVersion=2.4.0
stdlibCacheVersion=3.8.1-20241113-125700-b75a1bf
stdlibCryptoVersion=2.7.3-20241113-081400-d015a39
stdlibLogVersion=2.10.1-20241113-120000-4577868
stdlibTimeVersion=2.6.0-20241113-073800-201b904
stdlibUrlVersion=2.4.1-20241113-073900-335ff51

# Transitive dependencies
stdlibTaskVersion=2.5.0
stdlibConstraintVersion=1.5.0
stdlibIoVersion=1.6.0
observeVersion=1.3.0
observeInternalVersion=1.3.0
stdlibTaskVersion=2.5.1-20241113-123500-f905281
stdlibConstraintVersion=1.6.0-20241113-090900-d276ad5
stdlibIoVersion=1.6.2-20241112-233100-995cf5f
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 @@ -40,8 +40,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
31 changes: 17 additions & 14 deletions native/src/main/java/io/ballerina/stdlib/oauth2/OAuth2Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package io.ballerina.stdlib.oauth2;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.values.BError;
Expand Down Expand Up @@ -56,8 +57,8 @@ public class OAuth2Client {

private OAuth2Client() {}

public static Object doHttpRequest(BString url, BMap<BString, Object> clientConfig, BMap<BString, BString> headers,
BString payload) {
public static Object doHttpRequest(Environment env, BString url, BMap<BString, Object> clientConfig,
BMap<BString, BString> headers, BString payload) {
BString customPayload = getBStringValueIfPresent(clientConfig, OAuth2Constants.CUSTOM_PAYLOAD);
String textPayload = payload.getValue();
if (customPayload != null) {
Expand Down Expand Up @@ -100,13 +101,13 @@ public static Object doHttpRequest(BString url, BMap<BString, Object> clientConf
try {
SSLContext sslContext = getSslContext(secureSocket);
HttpClient client = buildHttpClient(httpVersion, sslContext);
return callEndpoint(client, request);
return callEndpoint(env, client, request);
} catch (Exception e) {
return createError("Failed to init SSL context. " + e.getMessage());
}
}
HttpClient client = buildHttpClient(httpVersion);
return callEndpoint(client, request);
return callEndpoint(env, client, request);
}

private static URI buildUri(String url, BMap<BString, ?> secureSocket) throws IllegalArgumentException {
Expand Down Expand Up @@ -300,17 +301,19 @@ private static HttpRequest buildHttpRequest(URI uri, String[] headers, String pa
.build();
}

private static Object callEndpoint(HttpClient client, HttpRequest request) {
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 200 && response.statusCode() < 300) {
return StringUtils.fromString(response.body());
private static Object callEndpoint(Environment env, HttpClient client, HttpRequest request) {
return env.yieldAndRun(() -> {
try {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 200 && response.statusCode() < 300) {
return StringUtils.fromString(response.body());
}
return createError("Failed to get a success response from the endpoint. Response code: '" +
response.statusCode() + "'. Response body: '" + response.body() + "'");
} catch (IOException | InterruptedException e) {
return createError("Failed to send the request to the endpoint. " + e.getMessage());
}
return createError("Failed to get a success response from the endpoint. Response code: '" +
response.statusCode() + "'. Response body: '" + response.body() + "'");
} catch (IOException | InterruptedException e) {
return createError("Failed to send the request to the endpoint. " + e.getMessage());
}
});
}

private static BMap<BString, ?> getBMapValueIfPresent(BMap<BString, ?> config, BString key) {
Expand Down

0 comments on commit 8574240

Please sign in to comment.