From e72404dacf39eefdb150129b28476d180161bc78 Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Tue, 19 Nov 2024 19:55:41 +0530 Subject: [PATCH 1/2] Migrate to Java 21 and new Runtime APIs --- .../workflows/build-ballerina-to-openapi.yml | 6 +- .../workflows/build-timestamped-master.yml | 6 +- .github/workflows/central-publish.yml | 6 +- .../publish-ballerina-to-openapi.yml | 6 +- .github/workflows/publish-release.yml | 6 +- .github/workflows/pull-request.yml | 12 ++-- README.md | 2 +- build.gradle | 12 ++-- gradle.properties | 57 ++++++++------- gradle/javaProject.gradle | 9 ++- module-ballerina-openapi/Ballerina.toml | 2 +- module-ballerina-openapi/CompilerPlugin.toml | 4 +- module-ballerina-openapi/build.gradle | 2 +- .../bal/tool/OpenAPICodeGeneratorTool.java | 6 +- .../io/ballerina/openapi/cmd/OpenApiCmd.java | 6 +- .../expected_gen/post_method.yaml | 6 +- .../response/cache_config_02.yaml | 6 +- .../response/cache_config_03.yaml | 6 +- .../response/cache_config_04.yaml | 6 +- .../response/cache_config_05.yaml | 12 ++-- .../response/cache_config_06.yaml | 18 ++--- .../response/configuration_rs01.yaml | 12 ++-- .../expected_gen/snowpeak.yaml | 12 ++-- .../expected_gen/snowpeak_cache.yaml | 6 +- .../snowpeak_request_body_ref.yaml | 12 ++-- .../ballerina-tests/tests/test.bal | 2 +- .../build-configs/resources/Ballerina.toml | 4 +- openapi-client-native/build.gradle | 7 +- .../openapi/client/GeneratedClient.java | 69 ++++--------------- .../core/generators/common/TypeHandler.java | 2 +- .../project_openapi_bal_ext/result_1.yaml | 10 +-- spotbugs-exclude.xml | 8 +++ 32 files changed, 157 insertions(+), 183 deletions(-) diff --git a/.github/workflows/build-ballerina-to-openapi.yml b/.github/workflows/build-ballerina-to-openapi.yml index c313164ba..09c08414b 100644 --- a/.github/workflows/build-ballerina-to-openapi.yml +++ b/.github/workflows/build-ballerina-to-openapi.yml @@ -8,11 +8,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: 'adopt' - java-version: 17.0.7 + distribution: 'temurin' + java-version: 21.0.3 - name: Change to Timestamped Version run: | startTime=$(TZ="Asia/Kolkata" date +'%Y%m%d-%H%M00') diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 32e2d1d75..23d20cd67 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.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: 'adopt' - java-version: 17.0.7 + distribution: 'temurin' + java-version: 21.0.3 - name: Change to Timestamped Version run: | startTime=$(TZ="Asia/Kolkata" date +'%Y%m%d-%H%M00') diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 2ce7e868b..342712eac 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -17,11 +17,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: 'adopt' - java-version: 17.0.7 + distribution: 'temurin' + java-version: 21.0.3 - name: Grant execute permission for gradlew run: chmod +x gradlew diff --git a/.github/workflows/publish-ballerina-to-openapi.yml b/.github/workflows/publish-ballerina-to-openapi.yml index b7d763436..3a0a3aca0 100644 --- a/.github/workflows/publish-ballerina-to-openapi.yml +++ b/.github/workflows/publish-ballerina-to-openapi.yml @@ -11,11 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: - distribution: 'adopt' - java-version: 17.0.7 + distribution: 'temurin' + java-version: 21.0.3 - name: Set version env variable run: echo "VERSION=$((grep -w "ballerinaToOpenAPIVersion" | cut -d= -f2) < gradle.properties | rev | cut --complement -d- -f1 | rev)" >> $GITHUB_ENV - name: Pre release dependency version update diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index b34e76051..d0d94032c 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -11,11 +11,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: - distribution: 'adopt' - java-version: 17.0.7 + distribution: 'temurin' + java-version: 21.0.3 - name: Check for Ballerina to OpenAPI release run: | BAL_TO_OPENAPI_VERSION=$(grep -w "ballerinaToOpenAPIVersion" gradle.properties | cut -d= -f2) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index d912a4fcb..ce6bb41a8 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -10,11 +10,11 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: - distribution: 'adopt' - java-version: 17.0.7 + distribution: 'temurin' + java-version: 21.0.3 - name: Build with Gradle env: packageUser: ${{ github.actor }} @@ -32,11 +32,11 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v2 with: - distribution: 'adopt' - java-version: 17.0.7 + distribution: 'temurin' + java-version: 21.0.3 - name: Build with Gradle env: packageUser: ${{ github.actor }} diff --git a/README.md b/README.md index 92b773265..06eeefcec 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ For more information on the supported operations, go to [Using the OpenAPI Tools ### Setting Up the Prerequisites -1. OpenJDK 11 ([Adopt OpenJDK](https://adoptopenjdk.net/) or any other OpenJDK distribution) +1. OpenJDK 21 ([Adopt OpenJDK](https://adoptopenjdk.net/) or any other OpenJDK distribution) >**Info:** You can also use [Oracle JDK](https://www.oracle.com/java/technologies/javase-downloads.html). Set the JAVA_HOME environment variable to the pathname of the directory into which you installed JDK. diff --git a/build.gradle b/build.gradle index d1645abd0..3137bf9a7 100644 --- a/build.gradle +++ b/build.gradle @@ -17,10 +17,10 @@ plugins { id "base" id 'maven-publish' - 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 "${spotbugsPluginVersion}" + id "com.github.johnrengelman.shadow" version "${shadowJarPluginVersion}" + id "de.undercouch.download" version "${downloadPluginVersion}" + id "net.researchgate.release" version "${releasePluginVersion}" id 'org.javamodularity.moduleplugin' version '1.7.0' apply false id "org.sonarqube" version "4.0.0.2929" } @@ -54,7 +54,7 @@ ext.stdlibTaskVersion = project.stdlibTaskVersion ext.stdlibFileVersion = project.stdlibFileVersion ext.stdlibHttpVersion = project.stdlibHttpVersion ext.stdlibUrlVersion = project.stdlibUrlVersion -ext.stdlibXmldataVersion = project.stdlibXmldataVersion +ext.stdlibDataXmldataVersion = project.stdlibDataXmldataVersion ext.stdlibGraphqlVersion = project.stdlibGraphqlVersion ext.stdlibGrpcVersion = project.stdlibGrpcVersion ext.stdlibWebsubVersion = project.stdlibWebsubVersion @@ -129,7 +129,7 @@ subprojects { ballerinaStdLibs "io.ballerina.stdlib:oauth2-ballerina:${stdlibOAuth2Version}" ballerinaStdLibs "io.ballerina.stdlib:uuid-ballerina:${stdlibUuidVersion}" ballerinaStdLibs "io.ballerina.stdlib:url-ballerina:${stdlibUrlVersion}" - ballerinaStdLibs "io.ballerina.lib:data.xmldata-ballerina:${stdlibXmldataVersion}" + ballerinaStdLibs "io.ballerina.lib:data.xmldata-ballerina:${stdlibDataXmldataVersion}" ballerinaStdLibs "io.ballerina.stdlib:observe-ballerina:${observeVersion}" ballerinaStdLibs "io.ballerina:observe-ballerina:${observeInternalVersion}" ballerinaStdLibs "io.ballerina.stdlib:graphql-ballerina:${stdlibGraphqlVersion}" diff --git a/gradle.properties b/gradle.properties index 70492de42..087560724 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,13 +4,18 @@ version=2.1.1-SNAPSHOT ballerinaToOpenAPIVersion=2.1.1-SNAPSHOT +spotbugsPluginVersion=6.0.18 +shadowJarPluginVersion=8.1.1 +downloadPluginVersion=5.4.0 +releasePluginVersion=2.8.0 + # Client Native Version clientNativeVersion=1.0.1-SNAPSHOT # Mark this as false to skip publishing the client native artifacts clientNativePublish=false #dependency -ballerinaLangVersion=2201.11.0-20241008-112400-81975006 +ballerinaLangVersion=2201.11.0-20241117-133400-a3054b77 testngVersion=7.6.1 slf4jVersion=1.7.30 org.gradle.jvmargs=-Xmx4096M -Dfile.encoding=UTF-8 @@ -24,45 +29,45 @@ puppycrawlCheckstyleVersion = 10.12.1 commonsCodecVersion=1.16.0 # Stdlib Level 01 -stdlibIoVersion=1.6.1 -stdlibRegexVersion=1.4.3 -stdlibTimeVersion=2.4.0 -stdlibUrlVersion=2.4.0 -stdlibXmldataVersion=1.0.0 +stdlibIoVersion=1.6.2-20241112-233100-995cf5f +stdlibRegexVersion=1.4.4-20241108-130200-fcd3fce +stdlibTimeVersion=2.6.0-20241113-073800-201b904 +stdlibUrlVersion=2.4.1-20241113-073900-335ff51 +stdlibDataXmldataVersion=1.0.1-20241113-122800-f4e815c # Stdlib Level 02 -stdlibConstraintVersion=1.5.0 -stdlibCryptoVersion=2.7.2 -stdlibLogVersion=2.10.0 -stdlibOsVersion=1.8.0 -stdlibTaskVersion=2.5.0 +stdlibConstraintVersion=1.6.0-20241113-090900-d276ad5 +stdlibCryptoVersion=2.7.3-20241113-081400-d015a39 +stdlibLogVersion=2.10.1-20241113-120000-4577868 +stdlibOsVersion=1.8.1-20241113-122000-cca973b +stdlibTaskVersion=2.5.1-20241113-123500-f905281 # Stdlib Level 03 -stdlibCacheVersion=3.8.0 -stdlibFileVersion=1.10.0 -stdlibMimeVersion=2.10.0 -stdlibUuidVersion=1.8.0 +stdlibCacheVersion=3.8.1-20241113-125700-b75a1bf +stdlibFileVersion=1.10.1-20241113-151700-e1a2e38 +stdlibMimeVersion=2.10.2-20241113-154200-d953747 +stdlibUuidVersion=1.8.1-20241113-154400-443c67b # Stdlib Level 04 -stdlibAuthVersion=2.12.0 -stdlibDataJsonDataVersion=0.3.0-20241105-101100-661d11f -stdlibJwtVersion=2.13.0 -stdlibOAuth2Version=2.12.0 +stdlibAuthVersion=2.12.1-20241113-162300-ded40eb +stdlibDataJsonDataVersion=0.3.0-20241114-143900-285d739 +stdlibJwtVersion=2.13.1-20241113-162400-b59ccfa +stdlibOAuth2Version=2.12.1-20241113-162400-4c6ddfe # Stdlib Level 05 -stdlibHttpVersion=2.13.0-20241106-120000-d375c3b +stdlibHttpVersion=2.13.0-20241114-182900-7e9f66a # Stdlib Level 06 -stdlibGrpcVersion=1.12.0 -stdlibWebsocketVersion=2.12.0 -stdlibWebsubVersion=2.12.0 +stdlibGrpcVersion=1.13.0-20241114-195700-5188f60 +stdlibWebsocketVersion=2.13.0-20241116-202000-ddd958d +stdlibWebsubVersion=2.13.0-20241114-233100-73205d6 # Stdlib Level 07 -stdlibGraphqlVersion=1.14.0 +stdlibGraphqlVersion=1.15.0-20241117-164000-4d95b39 # 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/gradle/javaProject.gradle b/gradle/javaProject.gradle index 7d89a86b1..5fd57b0cc 100644 --- a/gradle/javaProject.gradle +++ b/gradle/javaProject.gradle @@ -69,7 +69,7 @@ dependencies { checkstyle "com.puppycrawl.tools:checkstyle:${project.puppycrawlCheckstyleVersion}" } -sourceCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 def excludePattern = '**/module-info.java' tasks.withType(Checkstyle) { @@ -140,9 +140,12 @@ checkstyle { } spotbugsMain { + 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 ignoreFailures = true - effort = "max" - reportLevel = "low" reportsDir = file("$project.buildDir/reports/spotbugs") def excludeFile = file("${rootDir}/spotbugs-exclude.xml") if (excludeFile.exists()) { diff --git a/module-ballerina-openapi/Ballerina.toml b/module-ballerina-openapi/Ballerina.toml index 54423c2fc..1c3e53d73 100644 --- a/module-ballerina-openapi/Ballerina.toml +++ b/module-ballerina-openapi/Ballerina.toml @@ -1,4 +1,4 @@ [package] org= "ballerina" name= "openapi" -version= "@toml.version@" +version= "2.1.1" diff --git a/module-ballerina-openapi/CompilerPlugin.toml b/module-ballerina-openapi/CompilerPlugin.toml index c4c4205c0..57d0fee57 100644 --- a/module-ballerina-openapi/CompilerPlugin.toml +++ b/module-ballerina-openapi/CompilerPlugin.toml @@ -3,7 +3,7 @@ id = "openapi-tools" class = "io.ballerina.openapi.validator.OpenAPIValidatorPlugin" [[dependency]] -path = "../openapi-validator/build/libs/openapi-validator-@project.version@.jar" +path = "../openapi-validator/build/libs/openapi-validator-2.1.1-SNAPSHOT.jar" groupId = "ballerina" artifactId = "openapi" -version = "@project.version@." +version = "2.1.1-SNAPSHOT" diff --git a/module-ballerina-openapi/build.gradle b/module-ballerina-openapi/build.gradle index c7d5fc188..631452dd2 100644 --- a/module-ballerina-openapi/build.gradle +++ b/module-ballerina-openapi/build.gradle @@ -47,7 +47,7 @@ jar { def packageName = "openapi" def packageOrg = "ballerina" -def platform = "java17" +def platform = "java21" def tomlVersion = stripBallerinaExtensionVersion("${project.version}") def ballerinaConfigFilePlaceHolder = new File("${project.rootDir}/config/resources/Ballerina.toml") def ballerinaCompileConfigFilePlaceHolder = new File("${project.rootDir}/config/resources/CompilerPlugin.toml") diff --git a/openapi-bal-task-plugin/src/main/java/io/ballerina/openapi/bal/tool/OpenAPICodeGeneratorTool.java b/openapi-bal-task-plugin/src/main/java/io/ballerina/openapi/bal/tool/OpenAPICodeGeneratorTool.java index 48513d3a2..e457ddd6f 100644 --- a/openapi-bal-task-plugin/src/main/java/io/ballerina/openapi/bal/tool/OpenAPICodeGeneratorTool.java +++ b/openapi-bal-task-plugin/src/main/java/io/ballerina/openapi/bal/tool/OpenAPICodeGeneratorTool.java @@ -413,8 +413,8 @@ private boolean clientNativeDependencyAlreadyExist(String version, ToolContext t project = BuildProject.load(path); Map platforms = project.currentPackage().manifest().platforms(); - if (Objects.nonNull(platforms) && platforms.containsKey("java17")) { - Optional> nativeDependency = platforms.get("java17").dependencies().stream().filter( + if (Objects.nonNull(platforms) && platforms.containsKey("java21")) { + Optional> nativeDependency = platforms.get("java21").dependencies().stream().filter( dependency -> dependency.containsKey("groupId") && dependency.get("groupId").equals("io.ballerina.openapi") && dependency.containsKey("artifactId") && @@ -439,7 +439,7 @@ private boolean clientNativeDependencyAlreadyExist(String version, ToolContext t private NodeList populateClientNativeDependency( NodeList tomlMembers, String version) { String desc = "This dependency is added automatically by the OpenAPI tool. DO NOT REMOVE UNLESS REQUIRED"; - tomlMembers = tomlMembers.add(SampleNodeGenerator.createTableArray("platform.java17.dependency", desc)); + tomlMembers = tomlMembers.add(SampleNodeGenerator.createTableArray("platform.java21.dependency", desc)); tomlMembers = tomlMembers.add(SampleNodeGenerator.createStringKV("groupId", "io.ballerina.openapi", null)); tomlMembers = tomlMembers.add(SampleNodeGenerator.createStringKV("artifactId", "client-native", null)); tomlMembers = tomlMembers.add(SampleNodeGenerator.createStringKV("version", version, null)); diff --git a/openapi-cli/src/main/java/io/ballerina/openapi/cmd/OpenApiCmd.java b/openapi-cli/src/main/java/io/ballerina/openapi/cmd/OpenApiCmd.java index 28af20e0c..62ae58d28 100644 --- a/openapi-cli/src/main/java/io/ballerina/openapi/cmd/OpenApiCmd.java +++ b/openapi-cli/src/main/java/io/ballerina/openapi/cmd/OpenApiCmd.java @@ -536,8 +536,8 @@ private void updateBallerinaTomlWithClientNativeDependency() { private boolean clientNativeDependencyAlreadyExist(String version) { Project project = ProjectLoader.loadProject(executionPath); Map platforms = project.currentPackage().manifest().platforms(); - if (Objects.nonNull(platforms) && platforms.containsKey("java17")) { - Optional> nativeDependency = platforms.get("java17").dependencies().stream().filter( + if (Objects.nonNull(platforms) && platforms.containsKey("java21")) { + Optional> nativeDependency = platforms.get("java21").dependencies().stream().filter( dependency -> dependency.containsKey("groupId") && dependency.get("groupId").equals("io.ballerina.openapi") && dependency.containsKey("artifactId") && @@ -565,7 +565,7 @@ private boolean clientNativeDependencyAlreadyExist(String version) { private NodeList populateClientNativeDependency( NodeList tomlMembers, String version) { String desc = "This dependency is added automatically by the OpenAPI tool. DO NOT REMOVE UNLESS REQUIRED"; - tomlMembers = tomlMembers.add(SampleNodeGenerator.createTableArray("platform.java17.dependency", desc)); + tomlMembers = tomlMembers.add(SampleNodeGenerator.createTableArray("platform.java21.dependency", desc)); tomlMembers = tomlMembers.add(SampleNodeGenerator.createStringKV("groupId", "io.ballerina.openapi", null)); tomlMembers = tomlMembers.add(SampleNodeGenerator.createStringKV("artifactId", "client-native", null)); tomlMembers = tomlMembers.add(SampleNodeGenerator.createStringKV("version", version, null)); diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/post_method.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/post_method.yaml index 0312dbb74..bed834dcf 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/post_method.yaml +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/post_method.yaml @@ -37,9 +37,6 @@ paths: "201": description: Created headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -47,6 +44,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: text/plain: schema: diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_02.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_02.yaml index 57f8a75c9..ec35aaa18 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_02.yaml +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_02.yaml @@ -57,9 +57,6 @@ paths: "200": description: Ok headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -67,6 +64,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: text/plain: schema: diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_03.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_03.yaml index c2d7fb5d2..a07a7d1a5 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_03.yaml +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_03.yaml @@ -17,9 +17,6 @@ paths: "200": description: Ok headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -28,6 +25,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: text/plain: schema: diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_04.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_04.yaml index 29951190d..5853c6d95 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_04.yaml +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_04.yaml @@ -6,9 +6,6 @@ paths: "200": description: Ok headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -16,6 +13,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: text/plain: schema: diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_05.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_05.yaml index 4b0c7d055..4d36136b5 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_05.yaml +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_05.yaml @@ -6,9 +6,6 @@ paths: "200": description: Ok headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -16,6 +13,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: text/plain: schema: @@ -27,9 +27,6 @@ paths: "200": description: Ok headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -37,6 +34,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: text/plain: schema: diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_06.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_06.yaml index b9188c400..8ae4c8c73 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_06.yaml +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/cache_config_06.yaml @@ -17,9 +17,6 @@ paths: "200": description: Ok headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -27,6 +24,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: text/plain: schema: @@ -44,9 +44,6 @@ paths: "200": description: Ok headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -54,6 +51,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: text/plain: schema: @@ -61,9 +61,6 @@ paths: "202": description: Accepted headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -71,6 +68,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string "500": description: InternalServerError content: diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/configuration_rs01.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/configuration_rs01.yaml index a573a557d..45e53c3fc 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/configuration_rs01.yaml +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/response/configuration_rs01.yaml @@ -17,9 +17,6 @@ paths: "200": description: Ok headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -27,6 +24,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: text/plain: schema: @@ -38,9 +38,6 @@ paths: "200": description: Ok headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -48,6 +45,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: text/plain: schema: diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak.yaml index e95541fab..6412d43b0 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak.yaml +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak.yaml @@ -18,9 +18,6 @@ paths: "200": description: Ok headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -28,6 +25,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: application/json: schema: @@ -112,9 +112,6 @@ paths: "201": description: Created headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -122,6 +119,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: application/json: schema: diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_cache.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_cache.yaml index 5315a6f8a..f5e218d14 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_cache.yaml +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_cache.yaml @@ -18,9 +18,6 @@ paths: "200": description: Ok headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -28,6 +25,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: application/json: schema: diff --git a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_request_body_ref.yaml b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_request_body_ref.yaml index e72cacc4c..2fba99fe1 100644 --- a/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_request_body_ref.yaml +++ b/openapi-cli/src/test/resources/ballerina-to-openapi/expected_gen/snowpeak_request_body_ref.yaml @@ -25,9 +25,6 @@ paths: "201": description: Created headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -35,6 +32,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string content: application/json: schema: @@ -68,9 +68,6 @@ paths: "201": description: Created headers: - Last-Modified: - schema: - type: string Cache-Control: schema: type: string @@ -78,6 +75,9 @@ paths: ETag: schema: type: string + Last-Modified: + schema: + type: string "409": description: Conflict content: diff --git a/openapi-client-native/ballerina-tests/tests/test.bal b/openapi-client-native/ballerina-tests/tests/test.bal index 7ed27a4ed..5af604960 100644 --- a/openapi-client-native/ballerina-tests/tests/test.bal +++ b/openapi-client-native/ballerina-tests/tests/test.bal @@ -512,7 +512,7 @@ function testInvalidImplFunctionSignature() { OkAlbumArray|NotFoundErrorMessage|error res = albumClient->getAlbums3(genre = "Hard Rock"); if res is error { test:assertTrue(res is ClientMethodInvocationError); - test:assertTrue(res.message().includes("client method invocation failed: java.lang.ClassCastException: " + + test:assertTrue(res.message().includes("error in invoking client remote method: " + "class io.ballerina.runtime.internal.values.TypedescValueImpl cannot be cast to class io.ballerina.runtime.internal.values.MapValueImpl")); } else { test:assertFail("invalid response type"); diff --git a/openapi-client-native/build-configs/resources/Ballerina.toml b/openapi-client-native/build-configs/resources/Ballerina.toml index 76ed1fb53..0c54a276e 100644 --- a/openapi-client-native/build-configs/resources/Ballerina.toml +++ b/openapi-client-native/build-configs/resources/Ballerina.toml @@ -2,9 +2,9 @@ org = "ballerina" name = "client_native_test" version = "0.1.0" -distribution = "2201.8.6" +distribution = "2201.11.0-20241117-133400-a3054b77" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.openapi" artifactId = "client-native" version = "@client.native.version@" diff --git a/openapi-client-native/build.gradle b/openapi-client-native/build.gradle index b9f83783f..cff460571 100644 --- a/openapi-client-native/build.gradle +++ b/openapi-client-native/build.gradle @@ -51,9 +51,12 @@ checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") checkstyleTest.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") spotbugsMain { + 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 ignoreFailures = true - effort = "max" - reportLevel = "low" reportsDir = file("$project.buildDir/reports/spotbugs") def excludeFile = file("${rootDir}/spotbugs-exclude.xml") if (excludeFile.exists()) { diff --git a/openapi-client-native/src/main/java/io/ballerina/openapi/client/GeneratedClient.java b/openapi-client-native/src/main/java/io/ballerina/openapi/client/GeneratedClient.java index 16ad1c76f..c3564edb5 100644 --- a/openapi-client-native/src/main/java/io/ballerina/openapi/client/GeneratedClient.java +++ b/openapi-client-native/src/main/java/io/ballerina/openapi/client/GeneratedClient.java @@ -18,20 +18,10 @@ package io.ballerina.openapi.client; 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.values.BArray; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BObject; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -import static io.ballerina.runtime.api.constants.RuntimeConstants.CURRENT_TRANSACTION_CONTEXT_PROPERTY; -import static io.ballerina.runtime.observability.ObservabilityConstants.KEY_OBSERVER_CONTEXT; - /** * This class contains the generated client's native code. * @@ -39,12 +29,6 @@ */ public class GeneratedClient { - static final String MAIN_STRAND = "MAIN_STRAND"; - static final String SRC_HANDLER = "SRC_HANDLER"; - static final String REMOTE_ADDRESS = "REMOTE_ADDRESS"; - static final String ORIGIN_HOST = "ORIGIN_HOST"; - static final String POOLED_BYTE_BUFFER_FACTORY = "POOLED_BYTE_BUFFER_FACTORY"; - public static Object invokeResource(Environment env, BObject client, BArray pathParams, BArray params) { String functionName = env.getFunctionName(); try { @@ -80,14 +64,12 @@ private static Object invokeClientMethod(Environment env, BObject client, BArray int pathLength = (int) path.getLength(); int paramLength = (int) params.getLength(); - Object[] paramFeed = new Object[(pathLength + paramLength) * 2]; + Object[] paramFeed = new Object[pathLength + paramLength]; for (int i = 0; i < pathLength; i++) { - paramFeed[i * 2] = path.get(i); - paramFeed[i * 2 + 1] = true; + paramFeed[i] = path.get(i); } for (int i = 0; i < paramLength; i++) { - paramFeed[(pathLength + i) * 2] = params.get(i); - paramFeed[(pathLength + i) * 2 + 1] = true; + paramFeed[pathLength + i] = params.get(i); } return invokeClientMethod(env, client, methodName, paramFeed); @@ -97,49 +79,22 @@ private static Object invokeClientMethod(Environment env, BObject client, BArray String methodName) { int paramLength = (int) params.getLength(); - Object[] paramFeed = new Object[paramLength * 2]; + Object[] paramFeed = new Object[paramLength]; for (int i = 0; i < paramLength; i++) { - paramFeed[i * 2] = params.get(i); - paramFeed[i * 2 + 1] = true; + paramFeed[i] = params.get(i); } return invokeClientMethod(env, client, methodName, paramFeed); } private static Object invokeClientMethod(Environment env, BObject client, String methodName, Object[] paramFeed) { - Future balFuture = env.markAsync(); - Map propertyMap = getPropertiesToPropagate(env); - env.getRuntime().invokeMethodAsyncSequentially(client, methodName, null, null, new Callback() { - @Override - public void notifySuccess(Object result) { - balFuture.complete(result); - } - - @Override - public void notifyFailure(BError bError) { - BError invocationError = ClientUtil.createHttpError("client method invocation failed: " + - bError.getErrorMessage(), bError); - balFuture.complete(invocationError); + return env.yieldAndRun(() -> { + try { + return env.getRuntime().callMethod(client, methodName, null, paramFeed); + } catch (BError bError) { + return ClientUtil.createHttpError("client method invocation failed: " + + bError.getErrorMessage(), bError); } - }, propertyMap, PredefinedTypes.TYPE_NULL, paramFeed); - return null; - } - - private static Map getPropertiesToPropagate(Environment env) { - String[] keys = {CURRENT_TRANSACTION_CONTEXT_PROPERTY, KEY_OBSERVER_CONTEXT, SRC_HANDLER, MAIN_STRAND, - POOLED_BYTE_BUFFER_FACTORY, REMOTE_ADDRESS, ORIGIN_HOST}; - Map subMap = new HashMap<>(); - for (String key : keys) { - Object value = env.getStrandLocal(key); - if (value != null) { - subMap.put(key, value); - } - } - String strandParentFunctionName = Objects.isNull(env.getStrandMetadata()) ? null : - env.getStrandMetadata().getParentFunctionName(); - if (Objects.nonNull(strandParentFunctionName) && strandParentFunctionName.equals("onMessage")) { - subMap.put(MAIN_STRAND, true); - } - return subMap; + }); } } diff --git a/openapi-core/src/main/java/io/ballerina/openapi/core/generators/common/TypeHandler.java b/openapi-core/src/main/java/io/ballerina/openapi/core/generators/common/TypeHandler.java index 628d2255e..305194bcb 100644 --- a/openapi-core/src/main/java/io/ballerina/openapi/core/generators/common/TypeHandler.java +++ b/openapi-core/src/main/java/io/ballerina/openapi/core/generators/common/TypeHandler.java @@ -81,7 +81,7 @@ public class TypeHandler { private static TypeHandler typeHandlerInstance; private static BallerinaTypesGenerator ballerinaTypesGenerator; - public HashMap typeDefinitionNodes = new HashMap<>(); + private HashMap typeDefinitionNodes = new HashMap<>(); private final Set imports = new LinkedHashSet<>(); private static List constraintDiagnostics; diff --git a/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_bal_ext/result_1.yaml b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_bal_ext/result_1.yaml index 996094380..f7a6c36c2 100644 --- a/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_bal_ext/result_1.yaml +++ b/openapi-integration-tests/src/test/resources/ballerina_sources/project_openapi_bal_ext/result_1.yaml @@ -57,7 +57,7 @@ components: orgName: ballerina pkgName: time moduleName: time - version: 2.5.0 + version: 2.6.0 modulePrefix: time name: Date DateFields: @@ -81,7 +81,7 @@ components: orgName: ballerina pkgName: time moduleName: time - version: 2.5.0 + version: 2.6.0 modulePrefix: time name: DateFields OptionalTimeOfDayFields: @@ -100,7 +100,7 @@ components: orgName: ballerina pkgName: time moduleName: time - version: 2.5.0 + version: 2.6.0 modulePrefix: time name: OptionalTimeOfDayFields Seconds: @@ -111,7 +111,7 @@ components: orgName: ballerina pkgName: time moduleName: time - version: 2.5.0 + version: 2.6.0 modulePrefix: time name: Seconds Student: @@ -165,6 +165,6 @@ components: orgName: ballerina pkgName: time moduleName: time - version: 2.5.0 + version: 2.6.0 modulePrefix: time name: ZoneOffset diff --git a/spotbugs-exclude.xml b/spotbugs-exclude.xml index 9c24bf709..363627fb4 100644 --- a/spotbugs-exclude.xml +++ b/spotbugs-exclude.xml @@ -34,4 +34,12 @@ + + + + + + + + From b46a62be28792eecf50524d03e0f6c26ff1be5f5 Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Thu, 21 Nov 2024 23:41:06 +0530 Subject: [PATCH 2/2] Add project.version and toml.version --- module-ballerina-openapi/Ballerina.toml | 2 +- module-ballerina-openapi/CompilerPlugin.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/module-ballerina-openapi/Ballerina.toml b/module-ballerina-openapi/Ballerina.toml index 1c3e53d73..54423c2fc 100644 --- a/module-ballerina-openapi/Ballerina.toml +++ b/module-ballerina-openapi/Ballerina.toml @@ -1,4 +1,4 @@ [package] org= "ballerina" name= "openapi" -version= "2.1.1" +version= "@toml.version@" diff --git a/module-ballerina-openapi/CompilerPlugin.toml b/module-ballerina-openapi/CompilerPlugin.toml index 57d0fee57..c4c4205c0 100644 --- a/module-ballerina-openapi/CompilerPlugin.toml +++ b/module-ballerina-openapi/CompilerPlugin.toml @@ -3,7 +3,7 @@ id = "openapi-tools" class = "io.ballerina.openapi.validator.OpenAPIValidatorPlugin" [[dependency]] -path = "../openapi-validator/build/libs/openapi-validator-2.1.1-SNAPSHOT.jar" +path = "../openapi-validator/build/libs/openapi-validator-@project.version@.jar" groupId = "ballerina" artifactId = "openapi" -version = "2.1.1-SNAPSHOT" +version = "@project.version@."