diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index d9dbd5b..be49d37 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -6,6 +6,7 @@ on: branches: - main - 2201.[0-9]+.x + - java21 paths-ignore: - 'load-tests/**' - '*.md' @@ -17,11 +18,11 @@ jobs: if: github.repository_owner == 'ballerina-platform' steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: distribution: 'temurin' - java-version: 17.0.7 + java-version: 21.0.3 - name: Change to Timestamped Version run: | initialVersion=$((grep -w 'version' | cut -d= -f2) < gradle.properties ) @@ -42,7 +43,7 @@ jobs: CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} run: | - ./gradlew clean build publishAllPublicationsToGitHubPackagesRepository --scan --no-daemon + ./gradlew clean build publishAllPublicationsToGitHubPackagesRepository -x test --scan --no-daemon - name: Generate CodeCov Report uses: codecov/codecov-action@v2 - name: Upload Artifact diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index aced9a4..1a9fd9c 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 cc206bb..1310c1c 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -11,11 +11,11 @@ jobs: if: github.repository_owner == 'ballerina-platform' steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: distribution: 'temurin' - java-version: 17.0.7 + java-version: 21.0.3 - name: Give execute permission to gradlew run: chmod +x ./gradlew - name: Build with Gradle diff --git a/.github/workflows/publish-snapshot-nexus.yml b/.github/workflows/publish-snapshot-nexus.yml index 4672737..cf05a12 100644 --- a/.github/workflows/publish-snapshot-nexus.yml +++ b/.github/workflows/publish-snapshot-nexus.yml @@ -9,11 +9,11 @@ jobs: if: github.repository_owner == 'ballerina-platform' steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: distribution: 'temurin' - java-version: 17.0.7 + java-version: 21.0.3 - name: Give execute permission to gradlew run: chmod +x ./gradlew - name: Build with Gradle diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 19a104e..785e13e 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -12,6 +12,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-ubuntu-test-flags: "-x test" additional-windows-test-flags: "-x test" diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 458aab5..d91a5f3 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 94db2f8..03c8ef1 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,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/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index bb0d906..8b930fe 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -8,16 +8,16 @@ repository = "https://github.com/ballerina-platform/module-ballerinax-persist.re license = ["Apache-2.0"] distribution = "2201.10.0" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.lib" artifactId = "persist.redis-native" version = "0.2.0" path = "../native/build/libs/persist.redis-native-0.2.0.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "persist-native" version = "1.4.0" diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index ddd1b8b..5624845 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -8,16 +8,16 @@ repository = "https://github.com/ballerina-platform/module-ballerinax-persist.re license = ["Apache-2.0"] distribution = "2201.10.0" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.lib" artifactId = "persist.redis-native" version = "@toml.version@" path = "../native/build/libs/persist.redis-native-@project.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "persist-native" version = "@persist.version@" diff --git a/gradle.properties b/gradle.properties index 83e4f14..cf7a37b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ version=0.2.1-SNAPSHOT puppycrawlCheckstyleVersion=10.12.0 checkstyleToolVersion=10.12.0 -githubSpotbugsVersion=5.0.14 +githubSpotbugsVersion=6.0.18 githubJohnrengelmanShadowVersion=8.1.1 underCouchDownloadVersion=5.4.0 researchgateReleaseVersion=2.8.0 @@ -11,42 +11,42 @@ testngVersion=7.6.1 gsonVersion=2.10 ballerinaGradlePluginVersion=2.0.1 -ballerinaLangVersion=2201.10.0 +ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87 # Direct Dependencies # Level 01 -stdlibIoVersion=1.6.1 -stdlibTimeVersion=2.4.0 -stdlibUrlVersion=2.4.0 +stdlibIoVersion=1.6.2-20241112-233100-995cf5f +stdlibTimeVersion=2.6.0-20241113-073800-201b904 +stdlibUrlVersion=2.4.1-20241113-073900-335ff51 # Level 02 -stdlibConstraintVersion=1.5.0 -stdlibLogVersion=2.10.0 -stdlibOsVersion=1.8.0 -stdlibCryptoVersion=2.7.2 -stdlibTaskVersion=2.5.0 -stdlibPersistVersion=1.4.0 +stdlibConstraintVersion=1.6.0-20241113-090900-d276ad5 +stdlibLogVersion=2.10.1-20241113-120000-4577868 +stdlibOsVersion=1.8.1-20241113-122000-cca973b +stdlibCryptoVersion=2.7.3-20241113-081400-d015a39 +stdlibTaskVersion=2.5.1-20241113-123500-f905281 +stdlibPersistVersion=1.4.1-20241113-122000-306cc63 # Level 03 -stdlibFileVersion=1.10.0 -stdlibCacheVersion=3.8.0 -stdlibMimeVersion=2.10.0 -stdlibUuidVersion=1.8.0 +stdlibFileVersion=1.10.1-20241113-151700-e1a2e38 +stdlibCacheVersion=3.8.1-20241113-125700-b75a1bf +stdlibMimeVersion=2.10.2-20241113-154200-d953747 +stdlibUuidVersion=1.8.1-20241113-154400-443c67b # Level 04 -stdlibAuthVersion=2.12.0 -stdlibJwtVersion=2.13.0 -stdlibOAuth2Version=2.12.0 +stdlibAuthVersion=2.12.1-20241113-162300-ded40eb +stdlibJwtVersion=2.13.1-20241113-162400-b59ccfa +stdlibOAuth2Version=2.12.1-20241113-162400-4c6ddfe # Level 05 -stdlibHttpVersion=2.12.0 +stdlibHttpVersion=2.13.0-20241114-182900-7e9f66a # Level 08 stdlibRedisVersion=3.0.1 # Ballerinax Observer -observeVersion=1.3.0 -observeInternalVersion=1.3.0 +observeVersion=1.4.0-20241113-092000-b83ae74 +observeInternalVersion=1.3.1-20241113-101700-265054d # Enabled publishing insecure checksums, due to fail to publish to maven central # Refer https://github.com/gradle/gradle/issues/11308 diff --git a/native/build.gradle b/native/build.gradle index 53519b5..897b818 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -44,7 +44,7 @@ tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } -sourceCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 jacoco { toolVersion = "0.8.8" @@ -78,8 +78,11 @@ jacocoTestReport { spotbugsMain { ignoreFailures = true - 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") def excludeFile = file("${rootDir}/build-config/spotbugs-exclude.xml") if (excludeFile.exists()) { diff --git a/native/src/main/java/io/ballerina/stdlib/persist/redis/Utils.java b/native/src/main/java/io/ballerina/stdlib/persist/redis/Utils.java index 61c3fa0..8528f36 100644 --- a/native/src/main/java/io/ballerina/stdlib/persist/redis/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/persist/redis/Utils.java @@ -19,11 +19,11 @@ package io.ballerina.stdlib.persist.redis; 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.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.utils.StringUtils; diff --git a/native/src/main/java/io/ballerina/stdlib/persist/redis/datastore/RedisProcessor.java b/native/src/main/java/io/ballerina/stdlib/persist/redis/datastore/RedisProcessor.java index 9c3e3ee..2b41de2 100644 --- a/native/src/main/java/io/ballerina/stdlib/persist/redis/datastore/RedisProcessor.java +++ b/native/src/main/java/io/ballerina/stdlib/persist/redis/datastore/RedisProcessor.java @@ -19,15 +19,9 @@ package io.ballerina.stdlib.persist.redis.datastore; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.async.Callback; -import io.ballerina.runtime.api.creators.TypeCreator; +import io.ballerina.runtime.api.concurrent.StrandMetadata; import io.ballerina.runtime.api.creators.ValueCreator; -import io.ballerina.runtime.api.types.ErrorType; import io.ballerina.runtime.api.types.RecordType; -import io.ballerina.runtime.api.types.StreamType; -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; @@ -36,12 +30,10 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.stdlib.persist.Constants; -import io.ballerina.stdlib.persist.ModuleUtils; import io.ballerina.stdlib.persist.redis.Utils; import java.util.Map; -import static io.ballerina.stdlib.persist.Constants.ERROR; import static io.ballerina.stdlib.persist.Constants.KEY_FIELDS; import static io.ballerina.stdlib.persist.Constants.RUN_READ_BY_KEY_QUERY_METHOD; import static io.ballerina.stdlib.persist.ErrorGenerator.wrapError; @@ -69,48 +61,35 @@ public static BStream query(Environment env, BObject client, BTypedesc targetTyp RecordType recordTypeWithIdFields = getRecordTypeWithKeyFields(keyFields, recordType); BTypedesc targetTypeWithIdFields = ValueCreator.createTypedescValue(recordTypeWithIdFields); - StreamType streamTypeWithIdFields = TypeCreator.createStreamType(recordTypeWithIdFields, - PredefinedTypes.TYPE_NULL); - Map trxContextProperties = getTransactionContextProperties(); - String strandName = env.getStrandName().isPresent() ? env.getStrandName().get() : null; - BArray[] metadata = getMetadata(recordType); BArray fields = metadata[0]; BArray includes = metadata[1]; BArray typeDescriptions = metadata[2]; BMap typeMap = getFieldTypes(recordType); - Future balFuture = env.markAsync(); - env.getRuntime().invokeMethodAsyncSequentially( - // Call `RedisClient.runReadQuery( - // typedesc rowType, map typeMap, string[] fields = [], - // string[] include = [] - // )` - // which returns `stream|persist:Error` - - persistClient, Constants.RUN_READ_QUERY_METHOD, strandName, env.getStrandMetadata(), new Callback() { - @Override - public void notifySuccess(Object o) { - if (o instanceof BStream) { // stream - BStream redisStream = (BStream) o; - balFuture.complete(Utils.createPersistRedisStreamValue(redisStream, targetType, fields, - includes, typeDescriptions, persistClient, null)); - } else { // persist:Error - balFuture.complete(Utils.createPersistRedisStreamValue(null, targetType, fields, includes, - typeDescriptions, persistClient, (BError) o)); - } - } - - @Override - public void notifyFailure(BError bError) { - balFuture.complete(Utils.createPersistRedisStreamValue(null, targetType, fields, includes, - typeDescriptions, persistClient, wrapError(bError))); - } - }, trxContextProperties, streamTypeWithIdFields, - targetTypeWithIdFields, true, typeMap, true, fields, true, includes, true); - - return null; + return env.yieldAndRun(() -> { + try { + Object result = env.getRuntime().callMethod( + // Call `RedisClient.runReadQuery( + // typedesc rowType, map typeMap, string[] fields = [], + // string[] include = [] + // )` + // which returns `stream|persist:Error` + persistClient, Constants.RUN_READ_QUERY_METHOD, new StrandMetadata(false, trxContextProperties), + targetTypeWithIdFields, typeMap, fields, includes); + if (result instanceof BStream bStream) { // stream + return Utils.createPersistRedisStreamValue(bStream, targetType, fields, includes, + typeDescriptions, persistClient, null); + } + // persist:Error + return Utils.createPersistRedisStreamValue(null, targetType, fields, includes, typeDescriptions, + persistClient, (BError) result); + } catch (BError bError) { + return Utils.createPersistRedisStreamValue(null, targetType, fields, includes, typeDescriptions, + persistClient, wrapError(bError)); + } + }); } public static Object queryOne(Environment env, BObject client, BArray path, BTypedesc targetType) { @@ -118,13 +97,7 @@ public static Object queryOne(Environment env, BObject client, BArray path, BTyp BString entity = getEntity(env); BObject persistClient = getPersistClient(client, entity); - BArray keyFields = (BArray) persistClient.get(KEY_FIELDS); RecordType recordType = (RecordType) targetType.getDescribingType(); - - RecordType recordTypeWithIdFields = getRecordTypeWithKeyFields(keyFields, recordType); - ErrorType persistErrorType = TypeCreator.createErrorType(ERROR, ModuleUtils.getModule()); - Type unionType = TypeCreator.createUnionType(recordTypeWithIdFields, persistErrorType); - BArray[] metadata = getMetadata(recordType); BArray fields = metadata[0]; BArray includes = metadata[1]; @@ -132,34 +105,20 @@ public static Object queryOne(Environment env, BObject client, BArray path, BTyp BMap typeMap = getFieldTypes(recordType); Object key = getKey(env, path); - Map trxContextProperties = getTransactionContextProperties(); - String strandName = env.getStrandName().isPresent() ? env.getStrandName().get() : null; - - Future balFuture = env.markAsync(); - env.getRuntime().invokeMethodAsyncSequentially( - // Call `RedisClient.runReadByKeyQuery( - // typedesc rowType, anydata key, string[] fields = [], string[] - // include = [], - // typedesc[] typeDescriptions = [] - // )` - // which returns `record {}|persist:Error` - - persistClient, RUN_READ_BY_KEY_QUERY_METHOD, strandName, env.getStrandMetadata(), - new Callback() { - @Override - public void notifySuccess(Object o) { - balFuture.complete(o); - } - - @Override - public void notifyFailure(BError bError) { - balFuture.complete(wrapError(bError)); - } - }, trxContextProperties, unionType, - targetType, true, typeMap, true, key, true, fields, true, includes, true, - typeDescriptions, true); - - return null; + return env.yieldAndRun(() -> { + try { + return env.getRuntime().callMethod( + // Call `RedisClient.runReadQuery( + // typedesc rowType, map typeMap, string[] fields = [], + // string[] include = [] + // )` + // which returns `stream|persist:Error` + persistClient, RUN_READ_BY_KEY_QUERY_METHOD, new StrandMetadata(false, trxContextProperties), + targetType, typeMap, key, fields, includes, typeDescriptions); + } catch (BError bError) { + return wrapError(bError); + } + }); } }