From 07d46c62ea567de985a30defa7f2eeedd15b14fa Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Sun, 17 Nov 2024 10:37:21 +0530 Subject: [PATCH 1/6] Migrate to Java 21 --- .../workflows/build-timestamped-master.yml | 9 +- .../workflows/build-with-bal-test-graalvm.yml | 2 +- .github/workflows/central-publish.yml | 4 +- .github/workflows/publish-release.yml | 4 +- .github/workflows/publish-snapshot-nexus.yml | 4 +- .github/workflows/pull-request.yml | 9 +- .github/workflows/trivy-scan.yml | 4 +- README.md | 2 +- ballerina/Ballerina.toml | 6 +- build-config/resources/Ballerina.toml | 6 +- build.gradle | 1 + gradle.properties | 46 ++--- native/build.gradle | 9 +- .../stdlib/persist/googlesheets/Utils.java | 2 +- .../datastore/GoogleSheetsProcessor.java | 171 ++++++------------ 15 files changed, 117 insertions(+), 162 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index ce4b7c9..3912ee5 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@v3 - - 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.0.3 - name: Change to Timestamped Version run: | initialVersion=$((grep -w 'version' | cut -d= -f2) < gradle.properties ) @@ -42,11 +43,11 @@ jobs: CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} run: | - ./gradlew clean build publishAllPublicationsToGitHubPackagesRepository --scan --no-daemon + ./gradlew clean build publishAllPublicationsToGitHubPackagesRepository --scan --no-daemon -x test - name: Generate CodeCov Report uses: codecov/codecov-action@v2 - name: Upload Artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ballerina-runtime path: target/ballerina-runtime/ diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 567565d..a81b820 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 1310269..4fa045a 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -18,11 +18,11 @@ jobs: if: github.repository_owner == 'ballerina-platform' steps: - uses: actions/checkout@v3 - - 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.0.3 - name: Build with Gradle env: packageUser: ${{ github.actor }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index f9dc72a..4ba91f5 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@v3 - - 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.0.3 - name: Build with Gradle env: packageUser: ${{ github.actor }} diff --git a/.github/workflows/publish-snapshot-nexus.yml b/.github/workflows/publish-snapshot-nexus.yml index 73c3df8..1762fb2 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@v3 - - 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.0.3 - name: Build with Gradle env: packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index a84f922..0cec882 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,6 +5,7 @@ on: branches: - main - 2201.[0-9]+.x + - java21 jobs: ubuntu-build: @@ -12,11 +13,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - 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.0.3 - name: Build with Gradle env: packageUser: ${{ github.actor }} @@ -35,11 +36,11 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v3 - - 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.0.3 - name: Build with Gradle env: packageUser: ${{ github.actor }} diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index a79a315..1ea5cc0 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -11,11 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - 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.0.3 - name: Build with Gradle env: packageUser: ${{ github.actor }} diff --git a/README.md b/README.md index dd75c97..fd5c6ef 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,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 d1f7448..3e3fb93 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -9,16 +9,16 @@ 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 = "persist.googlesheets-native" version = "1.4.0" path = "../native/build/libs/persist.googlesheets-native-1.4.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 8c26a0e..85d0911 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -9,16 +9,16 @@ 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 = "persist.googlesheets-native" version = "@toml.version@" path = "../native/build/libs/persist.googlesheets-native-@project.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "persist-native" version = "@persist.version@" diff --git a/build.gradle b/build.gradle index ecdb7c1..aa5ce82 100644 --- a/build.gradle +++ b/build.gradle @@ -86,6 +86,7 @@ subprojects { ballerinaStdLibs "io.ballerina.stdlib:uuid-ballerina:${stdlibUuidVersion}" ballerinaStdLibs "io.ballerina.stdlib:cache-ballerina:${stdlibCacheVersion}" ballerinaStdLibs "io.ballerina.stdlib:oauth2-ballerina:${stdlibOAuth2Version}" + ballerinaStdLibs "io.ballerina.lib:data.jsondata-ballerina:${stdlibDataJsonDataVersion}" ballerinaStdLibs "io.ballerina.stdlib:auth-ballerina:${stdlibAuthVersion}" ballerinaStdLibs "io.ballerina.stdlib:jwt-ballerina:${stdlibJwtVersion}" ballerinaStdLibs "io.ballerina.stdlib:http-ballerina:${stdlibHttpVersion}" diff --git a/gradle.properties b/gradle.properties index 624e2b8..1306e16 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ version=1.4.1-SNAPSHOT puppycrawlCheckstyleVersion=10.12.1 checkstyleToolVersion=10.12.1 -githubSpotbugsVersion=5.0.14 +githubSpotbugsVersion=6.0.18 githubJohnrengelmanShadowVersion=8.1.1 underCouchDownloadVersion=5.4.0 researchgateReleaseVersion=2.8.0 @@ -11,52 +11,52 @@ 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 -stdlibLogVersion=2.10.0 -stdlibOsVersion=1.8.0 +stdlibLogVersion=2.10.1-20241113-120000-4577868 +stdlibOsVersion=1.8.1-20241113-122000-cca973b # Level 03 -stdlibFileVersion=1.10.0 +stdlibFileVersion=1.10.1-20241113-151700-e1a2e38 # Level 05 -stdlibHttpVersion=2.12.0 +stdlibHttpVersion=2.13.0-20241114-182900-7e9f66a # Level 08 -stdlibPersistVersion=1.4.0 +stdlibPersistVersion=1.4.1-20241113-122000-306cc63 # Ballerinax Observer -observeVersion=1.3.0 -observeInternalVersion=1.3.0 +observeVersion=1.4.0-20241113-092000-b83ae74 +observeInternalVersion=1.3.1-20241113-101700-265054d # Transitive Dependencies # Level 01 -stdlibConstraintVersion=1.5.0 +stdlibConstraintVersion=1.6.0-20241113-090900-d276ad5 #Level 02 -stdlibCryptoVersion=2.7.2 -stdlibTaskVersion=2.5.0 +stdlibCryptoVersion=2.7.3-20241113-081400-d015a39 +stdlibTaskVersion=2.5.1-20241113-123500-f905281 # Level 03 -stdlibCacheVersion=3.8.0 -stdlibMimeVersion=2.10.0 -stdlibUuidVersion=1.8.0 +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 +stdlibDataJsonDataVersion=0.3.0-20241114-143900-285d739 # Level 06 -stdlibTransactionVersion=1.10.0 +stdlibTransactionVersion=1.10.1-20241116-112500-189a4e5 # Connectors googleSheetsConnector=3.5.0 diff --git a/native/build.gradle b/native/build.gradle index 51af4ae..d560a1b 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -43,7 +43,7 @@ tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } -sourceCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 jacoco { toolVersion = "0.8.6" @@ -77,8 +77,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/googlesheets/Utils.java b/native/src/main/java/io/ballerina/stdlib/persist/googlesheets/Utils.java index 41cd176..174dd2a 100644 --- a/native/src/main/java/io/ballerina/stdlib/persist/googlesheets/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/persist/googlesheets/Utils.java @@ -19,11 +19,11 @@ package io.ballerina.stdlib.persist.googlesheets; 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/googlesheets/datastore/GoogleSheetsProcessor.java b/native/src/main/java/io/ballerina/stdlib/persist/googlesheets/datastore/GoogleSheetsProcessor.java index a8eee20..70db6b7 100644 --- a/native/src/main/java/io/ballerina/stdlib/persist/googlesheets/datastore/GoogleSheetsProcessor.java +++ b/native/src/main/java/io/ballerina/stdlib/persist/googlesheets/datastore/GoogleSheetsProcessor.java @@ -19,15 +19,9 @@ package io.ballerina.stdlib.persist.googlesheets.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; @@ -35,15 +29,11 @@ import io.ballerina.runtime.api.values.BStream; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; -import io.ballerina.stdlib.persist.ModuleUtils; -import io.ballerina.stdlib.persist.googlesheets.Constants; import io.ballerina.stdlib.persist.googlesheets.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.Constants.RUN_READ_QUERY_METHOD; import static io.ballerina.stdlib.persist.ErrorGenerator.wrapError; import static io.ballerina.stdlib.persist.Utils.getEntity; @@ -52,6 +42,7 @@ import static io.ballerina.stdlib.persist.Utils.getPersistClient; import static io.ballerina.stdlib.persist.Utils.getRecordTypeWithKeyFields; import static io.ballerina.stdlib.persist.Utils.getTransactionContextProperties; +import static io.ballerina.stdlib.persist.googlesheets.Constants.RUN_READ_TABLE_AS_STREAM_METHOD; import static io.ballerina.stdlib.persist.googlesheets.Utils.getEntityFromStreamMethod; import static io.ballerina.stdlib.persist.googlesheets.Utils.getFieldTypes; @@ -77,8 +68,6 @@ 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); BArray[] metadata = getMetadata(recordType); BArray fields = metadata[0]; @@ -87,39 +76,28 @@ public static BStream query(Environment env, BObject client, BTypedesc targetTyp BMap typeMap = getFieldTypes(recordType); Map trxContextProperties = getTransactionContextProperties(); - String strandName = env.getStrandName().isPresent() ? env.getStrandName().get() : null; - - Future balFuture = env.markAsync(); - env.getRuntime().invokeMethodAsyncSequentially( - // Call `GoogleSheetsClient.runReadQuery( - // typedesc rowType, map typeMap, string[] fields = [], string[] include = [] - // ` which returns `stream|persist:Error` - - persistClient, RUN_READ_QUERY_METHOD, strandName, env.getStrandMetadata(), new Callback() { - @Override - public void notifySuccess(Object o) { - if (o instanceof BStream) { // stream - BStream gSheetStream = (BStream) o; - balFuture.complete(Utils.createPersistGSheetsStreamValue(gSheetStream, targetType, fields, - includes, typeDescriptions, persistClient, null)); - } else { // persist:Error - BError persistError = (BError) o; - balFuture.complete(Utils.createPersistGSheetsStreamValue(null, targetType, fields, includes, - typeDescriptions, persistClient, persistError)); - } - } - - @Override - public void notifyFailure(BError bError) { - BError persistError = wrapError(bError); - balFuture.complete(Utils.createPersistGSheetsStreamValue(null, targetType, fields, includes, - typeDescriptions, persistClient, persistError)); - } - }, 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, RUN_READ_QUERY_METHOD, new StrandMetadata(false, trxContextProperties), + targetTypeWithIdFields, typeMap, fields, includes); + if (result instanceof BStream bStream) { // stream + return Utils.createPersistGSheetsStreamValue(bStream, targetType, fields, includes, + typeDescriptions, persistClient, null); + } + // persist:Error + return Utils.createPersistGSheetsStreamValue(null, targetType, fields, includes, typeDescriptions, + persistClient, (BError) result); + } catch (BError bError) { + return Utils.createPersistGSheetsStreamValue(null, targetType, fields, includes, typeDescriptions, + persistClient, bError); + } + }); } public static BStream queryStream(Environment env, BObject client, BTypedesc targetType) { @@ -132,8 +110,6 @@ public static BStream queryStream(Environment env, BObject client, BTypedesc tar RecordType recordTypeWithIdFields = getRecordTypeWithKeyFields(keyFields, recordType); BTypedesc targetTypeWithIdFields = ValueCreator.createTypedescValue(recordTypeWithIdFields); - StreamType streamTypeWithIdFields = TypeCreator.createStreamType(recordTypeWithIdFields, - PredefinedTypes.TYPE_NULL); BArray[] metadata = getMetadata(recordType); BArray fields = metadata[0]; @@ -142,39 +118,28 @@ public static BStream queryStream(Environment env, BObject client, BTypedesc tar BMap typeMap = getFieldTypes(recordType); Map trxContextProperties = getTransactionContextProperties(); - String strandName = env.getStrandName().isPresent() ? env.getStrandName().get() : null; - - Future balFuture = env.markAsync(); - env.getRuntime().invokeMethodAsyncSequentially( - // Call `GoogleSheetsClient.readTableAsStream( - // typedesc rowType, map typeMap, string[] fields = [], string[] include = [] - // )' which returns `stream|persist:Error` - - persistClient, Constants.RUN_READ_TABLE_AS_STREAM_METHOD, strandName, env.getStrandMetadata(), - new Callback() { - @Override - public void notifySuccess(Object o) { - if (o instanceof BStream) { // stream - BStream gSheetStream = (BStream) o; - balFuture.complete(Utils.createPersistGSheetsStreamValue(gSheetStream, targetType, fields, - includes, typeDescriptions, persistClient, null)); - } else { // persist:Error - BError persistError = (BError) o; - balFuture.complete(Utils.createPersistGSheetsStreamValue(null, targetType, fields, includes, - typeDescriptions, persistClient, persistError)); - } - } - - @Override - public void notifyFailure(BError bError) { - BError persistError = wrapError(bError); - balFuture.complete(Utils.createPersistGSheetsStreamValue(null, targetType, fields, includes, - typeDescriptions, persistClient, persistError)); - } - }, 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, RUN_READ_TABLE_AS_STREAM_METHOD, new StrandMetadata(false, trxContextProperties), + targetTypeWithIdFields, typeMap, fields, includes); + if (result instanceof BStream bStream) { // stream + return Utils.createPersistGSheetsStreamValue(bStream, targetType, fields, includes, + typeDescriptions, persistClient, null); + } + // persist:Error + return Utils.createPersistGSheetsStreamValue(null, targetType, fields, includes, + typeDescriptions, persistClient, (BError) result); + } catch (BError bError) { + return Utils.createPersistGSheetsStreamValue(null, targetType, fields, includes, typeDescriptions, + persistClient, bError); + } + }); } public static Object queryOne(Environment env, BObject client, BArray path, BTypedesc targetType) { @@ -187,8 +152,6 @@ public static Object queryOne(Environment env, BObject client, BArray path, BTyp RecordType recordTypeWithIdFields = getRecordTypeWithKeyFields(keyFields, recordType); BTypedesc targetTypeWithIdFields = ValueCreator.createTypedescValue(recordTypeWithIdFields); - ErrorType persistErrorType = TypeCreator.createErrorType(ERROR, ModuleUtils.getModule()); - Type unionType = TypeCreator.createUnionType(recordTypeWithIdFields, persistErrorType); BArray[] metadata = getMetadata(recordType); BArray fields = metadata[0]; @@ -198,33 +161,19 @@ public static Object queryOne(Environment env, BObject client, BArray path, BTyp 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 `GoogleSheetsClient.runReadByKeyQuery( - // typedesc rowType, typedesc rowTypeWithIdFields, map typeMap, - // anydata key, string[] fields = [], string[] include = [], - // typedesc[] typeDescriptions = [] - // ) returns record {}|persist:Error - - getPersistClient(client, entity), 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) { - BError persistError = wrapError(bError); - balFuture.complete(persistError); - } - }, trxContextProperties, unionType, - targetType, true, targetTypeWithIdFields, 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_TABLE_AS_STREAM_METHOD, new StrandMetadata(false, trxContextProperties), + targetType, targetTypeWithIdFields, typeMap, key, fields, includes, typeDescriptions); + } catch (BError bError) { + return wrapError(bError); + } + }); } } From ae6eb0021a4de3a4d2bd4adde01182ee988bb867 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Tue, 19 Nov 2024 01:05:52 +0530 Subject: [PATCH 2/6] Use main branch for github actions --- .github/workflows/build-timestamped-master.yml | 1 - .github/workflows/build-with-bal-test-graalvm.yml | 2 +- .github/workflows/pull-request.yml | 1 - gradle.properties | 2 +- 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 3912ee5..e924c08 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -6,7 +6,6 @@ on: branches: - main - 2201.[0-9]+.x - - java21 paths-ignore: - 'load-tests/**' - '*.md' diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index a81b820..567565d 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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main with: lang_tag: ${{ inputs.lang_tag }} lang_version: ${{ inputs.lang_version }} diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 0cec882..ea4fc68 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -5,7 +5,6 @@ on: branches: - main - 2201.[0-9]+.x - - java21 jobs: ubuntu-build: diff --git a/gradle.properties b/gradle.properties index 1306e16..a84cca9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ testngVersion=7.6.1 gsonVersion=2.10 ballerinaGradlePluginVersion=2.0.1 -ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87 +ballerinaLangVersion=2201.11.0-20241117-133400-a3054b77 # Direct Dependencies From 5fbc866f37ebf1f884b395aaca2b4e7e9636b4aa Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Thu, 21 Nov 2024 13:50:18 +0530 Subject: [PATCH 3/6] update github workflows --- .../workflows/build-timestamped-master.yml | 23 +++++++-- .github/workflows/central-publish.yml | 34 +++++++++---- .github/workflows/publish-release.yml | 34 +++++++++---- .github/workflows/publish-snapshot-nexus.yml | 13 +++-- .github/workflows/pull-request.yml | 51 +++++++++++++------ .github/workflows/trivy-scan.yml | 32 +++--------- 6 files changed, 118 insertions(+), 69 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index ce4b7c9..73f4be6 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -16,12 +16,15 @@ jobs: runs-on: ubuntu-latest if: github.repository_owner == 'ballerina-platform' steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up JDK 21 uses: actions/setup-java@v3 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 ) @@ -32,6 +35,14 @@ jobs: updatedVersion=$VERSION-$startTime-$latestCommit echo $updatedVersion sed -i "s/version=\(.*\)/version=$updatedVersion/g" gradle.properties + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Set ENV Variables + run: | + echo -e '${{ toJson(secrets) }}' | jq -r 'to_entries[] | .key + "=" + .value' >> $GITHUB_ENV + - name: Build with Gradle env: packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} @@ -43,13 +54,15 @@ jobs: REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} run: | ./gradlew clean build publishAllPublicationsToGitHubPackagesRepository --scan --no-daemon + - name: Generate CodeCov Report - uses: codecov/codecov-action@v2 + uses: codecov/codecov-action@v3 - name: Upload Artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ballerina-runtime path: target/ballerina-runtime/ + - name: Revert to SNAPSHOT Version run: | echo "version=${{ env.Initial_Version }}" diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 1310269..2cad53c 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -17,27 +17,41 @@ jobs: runs-on: ubuntu-latest if: github.repository_owner == 'ballerina-platform' steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up JDK 21 uses: actions/setup-java@v3 with: - distribution: 'temurin' - java-version: 17.0.7 + distribution: "temurin" + java-version: 21.0.3 + + - name: Set ENV Variables + run: | + echo -e '${{ toJson(secrets) }}' | jq -r 'to_entries[] | .key + "=" + .value' >> $GITHUB_ENV + - name: Build with Gradle env: packageUser: ${{ github.actor }} packagePAT: ${{ secrets.GITHUB_TOKEN }} run: ./gradlew build -x check -x test + - name: Create lib directory if not exists run: mkdir -p ballerina/lib + - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@master + env: + TRIVY_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-db,public.ecr.aws/aquasecurity/trivy-db + TRIVY_JAVA_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-java-db,public.ecr.aws/aquasecurity/trivy-java-db with: - scan-type: 'rootfs' - scan-ref: '/github/workspace/ballerina/lib' - format: 'table' - timeout: '10m0s' - exit-code: '1' + scan-type: "rootfs" + scan-ref: "${{ github.workspace }}/ballerina/lib" + format: "table" + timeout: "10m0s" + exit-code: "1" + scanners: "vuln" + cache-dir: "/tmp/trivy-cache" - name: Ballerina Central Push if: ${{ github.event.inputs.environment == 'CENTRAL' }} @@ -84,4 +98,4 @@ jobs: REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} run: | sed -i 's/version=\(.*\)-SNAPSHOT/version=\1/g' gradle.properties - ./gradlew clean build -PpublishToCentral=true \ No newline at end of file + ./gradlew clean build -PpublishToCentral=true diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index f9dc72a..e2b640a 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -10,12 +10,19 @@ jobs: runs-on: ubuntu-latest if: github.repository_owner == 'ballerina-platform' steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up JDK 21 uses: actions/setup-java@v3 with: - distribution: 'temurin' - java-version: 17.0.7 + distribution: "temurin" + java-version: 21.0.3 + + - name: Set ENV Variables + run: | + echo -e '${{ toJson(secrets) }}' | jq -r 'to_entries[] | .key + "=" + .value' >> $GITHUB_ENV + - name: Build with Gradle env: packageUser: ${{ github.actor }} @@ -24,16 +31,24 @@ jobs: git config --global user.name ${{ secrets.BALLERINA_BOT_USERNAME }} git config --global user.email ${{ secrets.BALLERINA_BOT_EMAIL }} ./gradlew build -x check -x test + - name: Create lib directory if not exists run: mkdir -p ballerina/lib + - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@master + env: + TRIVY_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-db,public.ecr.aws/aquasecurity/trivy-db + TRIVY_JAVA_DB_REPOSITORY: ghcr.io/aquasecurity/trivy-java-db,public.ecr.aws/aquasecurity/trivy-java-db with: - scan-type: 'rootfs' - scan-ref: '/github/workspace/ballerina/lib' - format: 'table' - timeout: '10m0s' - exit-code: '1' + scan-type: "rootfs" + scan-ref: "${{ github.workspace }}/ballerina/lib" + format: "table" + timeout: "10m0s" + exit-code: "1" + scanners: "vuln" + cache-dir: "/tmp/trivy-cache" + - name: Set version env variable run: echo "VERSION=$((grep -w 'version' | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev)" >> $GITHUB_ENV - name: Pre release dependency version update @@ -52,6 +67,7 @@ jobs: git commit -m "Move dependencies to stable version" || echo "No changes to commit" - name: Grant execute permission for gradlew run: chmod +x gradlew + - name: Publish artifact env: BALLERINA_CENTRAL_ACCESS_TOKEN: ${{ secrets.BALLERINA_CENTRAL_ACCESS_TOKEN }} diff --git a/.github/workflows/publish-snapshot-nexus.yml b/.github/workflows/publish-snapshot-nexus.yml index 73c3df8..f0dc4ca 100644 --- a/.github/workflows/publish-snapshot-nexus.yml +++ b/.github/workflows/publish-snapshot-nexus.yml @@ -8,12 +8,15 @@ jobs: runs-on: ubuntu-latest if: github.repository_owner == 'ballerina-platform' steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up JDK 21 uses: actions/setup-java@v3 with: - distribution: 'temurin' - java-version: 17.0.7 + distribution: "temurin" + java-version: 21.0.3 + - name: Build with Gradle env: packageUser: ${{ secrets.BALLERINA_BOT_USERNAME }} @@ -24,4 +27,6 @@ jobs: CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} run: | + git config --global user.name ${{ secrets.BALLERINA_BOT_USERNAME }} + git config --global user.email ${{ secrets.BALLERINA_BOT_EMAIL }} ./gradlew build publishMavenJavaPublicationToWSO2NexusRepository --scan --no-daemon diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index a84f922..39ec41a 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -11,12 +11,19 @@ jobs: name: Build on Ubuntu runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17.0.7 + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: 21.0.3 + + - name: Set ENV Variables + run: | + echo -e '${{ toJson(secrets) }}' | jq -r 'to_entries[] | .key + "=" + .value' >> $GITHUB_ENV + - name: Build with Gradle env: packageUser: ${{ github.actor }} @@ -24,25 +31,39 @@ jobs: CLIENT_ID: ${{ secrets.CLIENT_ID }} CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} - run: ./gradlew build - - name: Generate Codecov Report - uses: codecov/codecov-action@v2 - with: - token: ${{ secrets.CODECOV_TOKEN }} + run: | + ./gradlew build -x test + ./gradlew test + + - name: Generate Codecov Report + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} windows-build: name: Build on Windows runs-on: windows-latest + concurrency: + group: ${{ github.head_ref }}-windows-build + cancel-in-progress: true steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up JDK 21 uses: actions/setup-java@v3 with: - distribution: 'temurin' - java-version: 17.0.7 + distribution: 'temurin' + java-version: 21.0.3 + + - name: Set ENV Variables + run: | + echo '${{ toJson(secrets) }}' | jq -r 'to_entries[] | .key + "=" + .value' | Out-File -FilePath $env:GITHUB_ENV -Append + - name: Build with Gradle env: packageUser: ${{ github.actor }} packagePAT: ${{ secrets.GITHUB_TOKEN }} + JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 run: ./gradlew.bat build -x test # Disabling tests because no docker in git-action windows \ No newline at end of file diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index a79a315..df072db 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -3,32 +3,12 @@ name: Trivy on: workflow_dispatch: schedule: - - cron: '30 20 * * *' + - cron: "30 20 * * *" jobs: - ubuntu-build: - name: Build on Ubuntu - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: 17.0.7 - - name: Build with Gradle - env: - packageUser: ${{ github.actor }} - packagePAT: ${{ secrets.GITHUB_TOKEN }} - run: ./gradlew build -x check -x test - - name: Create lib directory if not exists - run: mkdir -p ballerina/lib - - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master - with: - scan-type: 'rootfs' - scan-ref: '/github/workspace/ballerina/lib' - format: 'table' - timeout: '10m0s' - exit-code: '1' + 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 + secrets: inherit \ No newline at end of file From d8ad8c66e382bb3d9f9ba455639e8cd3e9ef019d Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Thu, 21 Nov 2024 14:21:03 +0530 Subject: [PATCH 4/6] enable test with github build --- .github/workflows/pull-request.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 39ec41a..89aa626 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -31,9 +31,10 @@ jobs: CLIENT_ID: ${{ secrets.CLIENT_ID }} CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} - run: | - ./gradlew build -x test - ./gradlew test + run: | + git config --global user.name ${{ secrets.BALLERINA_BOT_USERNAME }} + git config --global user.email ${{ secrets.BALLERINA_BOT_EMAIL }} + ./gradlew build - name: Generate Codecov Report uses: codecov/codecov-action@v3 From 385439fcd825f81069f3ba195076c9315cf7d9cc Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Thu, 21 Nov 2024 15:55:28 +0530 Subject: [PATCH 5/6] add new lines --- .github/workflows/build-timestamped-master.yml | 1 - .github/workflows/build-with-bal-test-graalvm.yml | 1 - .github/workflows/pull-request.yml | 2 +- .github/workflows/trivy-scan.yml | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 73f4be6..948fb35 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -75,4 +75,3 @@ jobs: nexusPassword: ${{ secrets.NEXUS_PASSWORD }} run: | ./gradlew clean publishMavenJavaPublicationToWSO2NexusRepository -x test --scan --no-daemon - \ No newline at end of file diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 567565d..92735c3 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -37,4 +37,3 @@ jobs: native_image_options: '-J-Xmx7G ${{ inputs.native_image_options }}' additional_windows_build_flags: '-x test' secrets: inherit - \ No newline at end of file diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 89aa626..8b4c330 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -67,4 +67,4 @@ jobs: packagePAT: ${{ secrets.GITHUB_TOKEN }} JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 run: ./gradlew.bat build -x test - # Disabling tests because no docker in git-action windows \ No newline at end of file + # Disabling tests because no docker in git-action windows diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index df072db..c02c8ff 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -11,4 +11,3 @@ jobs: if: ${{ github.repository_owner == 'ballerina-platform' }} uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main secrets: inherit - \ No newline at end of file From b148bc6eda369277b75376d07e4e57d9e16b791c Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Thu, 21 Nov 2024 15:57:30 +0530 Subject: [PATCH 6/6] Apply suggestions from code review --- .github/workflows/build-timestamped-master.yml | 1 + .github/workflows/build-with-bal-test-graalvm.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 948fb35..c7891b9 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -75,3 +75,4 @@ jobs: nexusPassword: ${{ secrets.NEXUS_PASSWORD }} run: | ./gradlew clean publishMavenJavaPublicationToWSO2NexusRepository -x test --scan --no-daemon + diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 92735c3..29e6c66 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -37,3 +37,4 @@ jobs: native_image_options: '-J-Xmx7G ${{ inputs.native_image_options }}' additional_windows_build_flags: '-x test' secrets: inherit +