From 9d356f19abf26e8a91d69f73eeb68034a741a69e Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Mon, 30 Sep 2024 12:46:14 +0530 Subject: [PATCH] Migrate to Java 21 --- .../workflows/build-timestamped-master.yml | 2 +- .../workflows/build-with-bal-test-graalvm.yml | 2 +- .github/workflows/central-publish.yml | 2 +- .github/workflows/publish-release.yml | 2 +- .github/workflows/pull-request.yml | 2 +- .github/workflows/trivy-scan.yml | 2 +- README.md | 2 +- ballerina/Ballerina.toml | 6 +- build-config/resources/Ballerina.toml | 6 +- gradle.properties | 6 +- native/build.gradle | 8 +- .../stdlib/task/utils/TaskCallBack.java | 74 ------------------- .../ballerina/stdlib/task/utils/TaskJob.java | 15 +++- .../io/ballerina/stdlib/task/utils/Utils.java | 31 ++++++++ native/src/main/java/module-info.java | 1 + 15 files changed, 66 insertions(+), 95 deletions(-) delete mode 100644 native/src/main/java/io/ballerina/stdlib/task/utils/TaskCallBack.java diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 4337022b..6ef21eb5 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -12,5 +12,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 diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 48b59d62..72433a6f 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 11922b55..ebe213e7 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 68a586ef..95a6dabe 100755 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -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: task diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 31e0976d..db98c8e1 100755 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -10,5 +10,5 @@ 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 secrets: inherit diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index c02c8ff4..41e8f6ad 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 85b0b989..20e520e7 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ This repository only contains the source code for the package. ## Build from the source ### 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 6d70d8f4..f2325cd1 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -9,14 +9,14 @@ icon = "icon.png" license = ["Apache-2.0"] distribution = "2201.8.0" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "task-native" version = "2.5.1" path = "../native/build/libs/task-native-2.5.1-SNAPSHOT.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] path = "./lib/quartz-2.3.2.jar" diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index 8bb61713..af376d58 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -9,14 +9,14 @@ icon = "icon.png" license = ["Apache-2.0"] distribution = "2201.8.0" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "task-native" version = "@toml.version@" path = "../native/build/libs/task-native-@project.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] path = "./lib/quartz-@quartz.version@.jar" diff --git a/gradle.properties b/gradle.properties index f5c7ec5b..d062413d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,11 +2,11 @@ org.gradle.caching=true group=io.ballerina.stdlib version=2.5.1-SNAPSHOT -ballerinaLangVersion=2201.8.0 +ballerinaLangVersion=2201.10.0-20241002-115300-57eee14c axiomVersion=1.2.22 puppycrawlCheckstyleVersion=10.12.0 ballerinaGradlePluginVersion=2.0.1 -githubSpotbugsVersion=5.0.14 +githubSpotbugsVersion=6.0.18 githubJohnrengelmanShadowVersion=7.1.2 underCouchDownloadVersion=5.4.0 researchgateReleaseVersion=2.8.0 @@ -14,4 +14,4 @@ researchgateReleaseVersion=2.8.0 quartzVersion=2.3.2 #stdlib dependencies -stdlibTimeVersion=2.4.0 +stdlibTimeVersion=2.5.1-20240930-120200-e59222b diff --git a/native/build.gradle b/native/build.gradle index 0b0ce11d..3cac75b3 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -46,8 +46,12 @@ tasks.withType(Checkstyle) { } spotbugsMain { - effort "max" - reportLevel "low" + ignoreFailures = true + 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 diff --git a/native/src/main/java/io/ballerina/stdlib/task/utils/TaskCallBack.java b/native/src/main/java/io/ballerina/stdlib/task/utils/TaskCallBack.java deleted file mode 100644 index 0946edc4..00000000 --- a/native/src/main/java/io/ballerina/stdlib/task/utils/TaskCallBack.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2021 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.task.utils; - -import io.ballerina.runtime.api.async.Callback; -import io.ballerina.runtime.api.values.BError; -import org.quartz.JobExecutionContext; -import org.quartz.Scheduler; -import org.quartz.SchedulerException; - -import java.io.PrintStream; - -/** - * The class handles the output of job execution by the trigger. - * - * @since 2.0.0 - */ -public class TaskCallBack implements Callback { - - JobExecutionContext jobExecutionContext; - private static PrintStream console = System.out; - - public TaskCallBack(JobExecutionContext jobExecutionContext) { - this.jobExecutionContext = jobExecutionContext; - } - - @Override - public void notifySuccess(Object o) { - } - - @Override - public void notifyFailure(BError bError) { - Scheduler scheduler = jobExecutionContext.getScheduler(); - String errorPolicy = (String) jobExecutionContext.getMergedJobDataMap().get(TaskConstants.ERROR_POLICY); - String jobId = (String) jobExecutionContext.getMergedJobDataMap().get(TaskConstants.JOB_ID); - if (isLogged(errorPolicy)) { - Utils.printMessage("Unable to execute the job[" + jobId + "]. " + bError.getMessage(), console); - } - if (isTerminated(errorPolicy)) { - try { - scheduler.unscheduleJob(this.jobExecutionContext.getTrigger().getKey()); - } catch (SchedulerException e) { - if (errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_TERMINATE)) { - Utils.printMessage(e.toString(), console); - } - } - } - } - - private boolean isLogged(String errorPolicy) { - return errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_TERMINATE) || - errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_CONTINUE); - } - - private boolean isTerminated(String errorPolicy) { - return errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_TERMINATE) || - errorPolicy.equalsIgnoreCase(TaskConstants.TERMINATE); - } -} diff --git a/native/src/main/java/io/ballerina/stdlib/task/utils/TaskJob.java b/native/src/main/java/io/ballerina/stdlib/task/utils/TaskJob.java index 023add4c..d9a830e0 100644 --- a/native/src/main/java/io/ballerina/stdlib/task/utils/TaskJob.java +++ b/native/src/main/java/io/ballerina/stdlib/task/utils/TaskJob.java @@ -18,7 +18,8 @@ package io.ballerina.stdlib.task.utils; import io.ballerina.runtime.api.Runtime; -import io.ballerina.runtime.api.async.Callback; +import io.ballerina.runtime.api.creators.ErrorCreator; +import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BObject; import io.ballerina.stdlib.task.objects.TaskManager; import org.quartz.Job; @@ -39,7 +40,15 @@ public TaskJob() { public void execute(JobExecutionContext jobExecutionContext) { Runtime runtime = TaskManager.getInstance().getRuntime(); BObject job = (BObject) jobExecutionContext.getMergedJobDataMap().get(TaskConstants.JOB); - Callback callback = new TaskCallBack(jobExecutionContext); - runtime.invokeMethodAsync(job, TaskConstants.EXECUTE, null, null, callback); + try { + Object result = runtime.call(job, TaskConstants.EXECUTE); + if (result instanceof BError error) { + Utils.notifyFailure(jobExecutionContext, error); + } + } catch (BError error) { + Utils.notifyFailure(jobExecutionContext, error); + } catch (Throwable t) { + Utils.notifyFailure(jobExecutionContext, ErrorCreator.createError(t)); + } } } diff --git a/native/src/main/java/io/ballerina/stdlib/task/utils/Utils.java b/native/src/main/java/io/ballerina/stdlib/task/utils/Utils.java index 75559961..51876855 100644 --- a/native/src/main/java/io/ballerina/stdlib/task/utils/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/task/utils/Utils.java @@ -26,6 +26,7 @@ import org.quartz.JobBuilder; import org.quartz.JobDataMap; import org.quartz.JobDetail; +import org.quartz.JobExecutionContext; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.SimpleScheduleBuilder; @@ -58,6 +59,8 @@ private Utils() {} private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"); + private static final PrintStream console = System.out; + public static BError createTaskError(String message) { return ErrorCreator.createDistinctError(TaskConstants.ERROR, ModuleUtils.getModule(), StringUtils.fromString(message)); @@ -164,4 +167,32 @@ public static void disableQuartzLogs() { public static boolean isInt(Object time) { return TypeUtils.getType(time).getTag() == TypeTags.INT_TAG; } + + public static void notifyFailure(JobExecutionContext jobExecutionContext, BError bError) { + Scheduler scheduler = jobExecutionContext.getScheduler(); + String errorPolicy = (String) jobExecutionContext.getMergedJobDataMap().get(TaskConstants.ERROR_POLICY); + String jobId = (String) jobExecutionContext.getMergedJobDataMap().get(TaskConstants.JOB_ID); + if (isLogged(errorPolicy)) { + Utils.printMessage("Unable to execute the job[" + jobId + "]. " + bError.getMessage(), console); + } + if (isTerminated(errorPolicy)) { + try { + scheduler.unscheduleJob(jobExecutionContext.getTrigger().getKey()); + } catch (SchedulerException e) { + if (errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_TERMINATE)) { + Utils.printMessage(e.toString(), console); + } + } + } + } + + private static boolean isLogged(String errorPolicy) { + return errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_TERMINATE) || + errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_CONTINUE); + } + + private static boolean isTerminated(String errorPolicy) { + return errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_TERMINATE) || + errorPolicy.equalsIgnoreCase(TaskConstants.TERMINATE); + } } diff --git a/native/src/main/java/module-info.java b/native/src/main/java/module-info.java index ef8f5a87..5c33de65 100644 --- a/native/src/main/java/module-info.java +++ b/native/src/main/java/module-info.java @@ -20,6 +20,7 @@ requires io.ballerina.runtime; requires quartz; requires java.logging; + requires io.ballerina.lang; exports io.ballerina.stdlib.task.actions; exports io.ballerina.stdlib.task.exceptions; exports io.ballerina.stdlib.task.objects;