Skip to content

Commit

Permalink
Migrate to Java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
warunalakshitha committed Oct 2, 2024
1 parent 6f42b1c commit 9d356f1
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 95 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 @@ -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
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: task
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,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
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 @@ -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/)
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ 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

quartzVersion=2.3.2

#stdlib dependencies
stdlibTimeVersion=2.4.0
stdlibTimeVersion=2.5.1-20240930-120200-e59222b
8 changes: 6 additions & 2 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

15 changes: 12 additions & 3 deletions native/src/main/java/io/ballerina/stdlib/task/utils/TaskJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
}
}
31 changes: 31 additions & 0 deletions native/src/main/java/io/ballerina/stdlib/task/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions native/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9d356f1

Please sign in to comment.