From 60f36f2bd2d09c7b829096c8c96eb48def7bde20 Mon Sep 17 00:00:00 2001 From: kpavlov <{ID}+{username}@users.noreply.github.com> Date: Fri, 13 Sep 2024 12:45:16 +0300 Subject: [PATCH 1/2] Upgrade dependencies, gradle, jdk --- .github/workflows/detekt-analysis.yml | 103 ------------------ .github/workflows/gradle-publish.yml | 45 -------- .github/workflows/gradle.yml | 3 +- .java-version | 2 +- .travis.yml | 16 --- build.gradle.kts | 71 ++++++------ gradle/libs.versions.toml | 34 ++++++ gradle/wrapper/gradle-wrapper.jar | 4 +- gradle/wrapper/gradle-wrapper.properties | 4 +- gradlew | 44 +++++--- gradlew.bat | 37 ++++--- .../jreactive8583/ConnectorConfiguration.kt | 2 +- .../jreactive8583/ConnectorConfigurer.kt | 3 +- .../jreactive8583/iso/ISO8583Version.kt | 2 +- .../kpavlov/jreactive8583/iso/MessageClass.kt | 2 +- .../jreactive8583/iso/MessageFunction.kt | 2 +- .../jreactive8583/iso/MessageOrigin.kt | 2 +- .../pipeline/CompositeIsoMessageHandler.kt | 6 +- .../pipeline/Iso8583ChannelInitializer.kt | 2 + .../pipeline/IsoMessageLoggingHandler.kt | 4 +- .../netty/pipeline/ParseExceptionHandler.kt | 6 +- .../jreactive8583/server/Iso8583Server.kt | 3 + .../pipeline/ParseExceptionHandlerTest.java | 5 +- 23 files changed, 152 insertions(+), 250 deletions(-) delete mode 100644 .github/workflows/detekt-analysis.yml delete mode 100644 .github/workflows/gradle-publish.yml delete mode 100644 .travis.yml create mode 100644 gradle/libs.versions.toml diff --git a/.github/workflows/detekt-analysis.yml b/.github/workflows/detekt-analysis.yml deleted file mode 100644 index 6d31108..0000000 --- a/.github/workflows/detekt-analysis.yml +++ /dev/null @@ -1,103 +0,0 @@ -# This workflow performs a static analysis of your Kotlin source code using -# Detekt. -# -# Scans are triggered: -# 1. On every push to default and protected branches -# 2. On every Pull Request targeting the default branch -# 3. On a weekly schedule -# 4. Manually, on demand, via the "workflow_dispatch" event -# -# The workflow should work with no modifications, but you might like to use a -# later version of the Detekt CLI by modifing the $DETEKT_RELEASE_TAG -# environment variable. -name: Scan with Detekt - -on: - # Triggers the workflow on push or pull request events but only for default and protected branches - push: - branches: [ master ] - pull_request: - branches: [ master ] - schedule: - - cron: '22 0 * * 6' - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -env: - # Release tag associated with version of Detekt to be installed - # SARIF support (required for this workflow) was introduced in Detekt v1.15.0 - DETEKT_RELEASE_TAG: v1.15.0 - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "scan" - scan: - name: Scan - # The type of runner that the job will run on - runs-on: ubuntu-latest - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v3 - - # Gets the download URL associated with the $DETEKT_RELEASE_TAG - - name: Get Detekt download URL - id: detekt_info - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - DETEKT_DOWNLOAD_URL=$( gh api graphql --field tagName=$DETEKT_RELEASE_TAG --raw-field query=' - query getReleaseAssetDownloadUrl($tagName: String!) { - repository(name: "detekt", owner: "detekt") { - release(tagName: $tagName) { - releaseAssets(name: "detekt", first: 1) { - nodes { - downloadUrl - } - } - } - } - } - ' | \ - jq --raw-output '.data.repository.release.releaseAssets.nodes[0].downloadUrl' ) - echo "::set-output name=download_url::$DETEKT_DOWNLOAD_URL" - - # Sets up the detekt cli - - name: Setup Detekt - run: | - dest=$( mktemp -d ) - curl --request GET \ - --url ${{ steps.detekt_info.outputs.download_url }} \ - --silent \ - --location \ - --output $dest/detekt - chmod a+x $dest/detekt - echo $dest >> $GITHUB_PATH - - # Performs static analysis using Detekt - - name: Run Detekt - continue-on-error: true - run: | - detekt --input ${{ github.workspace }} --report sarif:${{ github.workspace }}/detekt.sarif.json - - # Modifies the SARIF output produced by Detekt so that absolute URIs are relative - # This is so we can easily map results onto their source files - # This can be removed once relative URI support lands in Detekt: https://git.io/JLBbA - - name: Make artifact location URIs relative - continue-on-error: true - run: | - echo "$( - jq \ - --arg github_workspace ${{ github.workspace }} \ - '. | ( .runs[].results[].locations[].physicalLocation.artifactLocation.uri |= if test($github_workspace) then .[($github_workspace | length | . + 1):] else . end )' \ - ${{ github.workspace }}/detekt.sarif.json - )" > ${{ github.workspace }}/detekt.sarif.json - - # Uploads results to GitHub repository using the upload-sarif action - - uses: github/codeql-action/upload-sarif@v2 - with: - # Path to SARIF file relative to the root of the repository - sarif_file: ${{ github.workspace }}/detekt.sarif.json - checkout_path: ${{ github.workspace }} diff --git a/.github/workflows/gradle-publish.yml b/.github/workflows/gradle-publish.yml deleted file mode 100644 index 3e2af91..0000000 --- a/.github/workflows/gradle-publish.yml +++ /dev/null @@ -1,45 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created -# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle - -name: Gradle Package - -on: - release: - types: [created] - -jobs: - build: - - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v4 - with: - java-version: '11' - distribution: 'zulu' - server-id: github # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Build with Gradle - uses: gradle/gradle-build-action@v2 - with: - arguments: build - - # The USERNAME and TOKEN need to correspond to the credentials environment variables used in - # the publishing section of your build.gradle - - name: Publish to GitHub Packages - uses: gradle/gradle-build-action@v2 - with: - arguments: publish - env: - USERNAME: ${{ github.actor }} - TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index eeb9482..b872dad 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -23,7 +23,8 @@ jobs: strategy: matrix: - java: [ '11', '17', '21' ] + java: [ '17', '21' ] + distribution: 'corretto' name: Build under JDK ${{ matrix.Java }} diff --git a/.java-version b/.java-version index 2dbc24b..98d9bcb 100644 --- a/.java-version +++ b/.java-version @@ -1 +1 @@ -11.0 +17 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 12f615d..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -language: java -jdk: - - openjdk11 - - openjdk15 - -cache: - directories: - - $HOME/.m2 - -script: - - mvn verify source:jar dokka:dokka -B - -after_success: - - echo "ossrh\${env.OSSRH_USER}\${env.OSSRH_PASS}" > ~/settings.xml - - mvn deploy --settings ~/settings.xml - - rm ~/settings.xml diff --git a/build.gradle.kts b/build.gradle.kts index e1b046a..23d9661 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,48 +1,42 @@ import org.gradle.api.tasks.testing.logging.TestLogEvent +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.platform.jvm.JvmPlatform plugins { `java-library` - kotlin("jvm") version "1.7.0" - id("org.jetbrains.dokka") version "1.7.0" - id("org.jlleitschuh.gradle.ktlint") version "10.3.0" + alias(libs.plugins.kotlinJvm) + alias(libs.plugins.dokka) + alias(libs.plugins.detekt) signing `maven-publish` // https://github.com/gradle-nexus/publish-plugin - id("io.github.gradle-nexus.publish-plugin") version "1.1.0" + alias(libs.plugins.nexusPublish) } repositories { - mavenLocal() mavenCentral() } dependencies { - val awitilityVersion = "4.2.0" - val junitJupiterVersion = "5.8.2" - val mockitoVersion = "4.3.1" - val nettyVersion = "4.1.78.Final" - val slf4jVersion = "1.7.36" - val springVersion = "5.3.21" - - api("com.google.code.findbugs:jsr305:3.0.2") - api("io.netty:netty-handler:$nettyVersion") - api("net.sf.j8583:j8583:1.17.0") - api("org.slf4j:slf4j-api:$slf4jVersion") + api(libs.findbugs) + api(libs.netty) + api(libs.j8583) + api(libs.slf4j.api) api(kotlin("stdlib-jdk8")) - implementation(platform("org.jetbrains.kotlin:kotlin-bom")) - testImplementation("net.jcip:jcip-annotations:1.0") - testImplementation("org.apache.commons:commons-lang3:3.12.0") - testImplementation("org.assertj:assertj-core:3.22.0") - testImplementation("org.awaitility:awaitility-kotlin:$awitilityVersion") - testImplementation("org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion") - testImplementation("org.mockito:mockito-junit-jupiter:$mockitoVersion") - testImplementation("org.slf4j:slf4j-simple:$slf4jVersion") - testImplementation("org.springframework:spring-context") - testImplementation("org.springframework:spring-test") + + testImplementation(libs.jcip) + testImplementation(libs.commons.lang3) + testImplementation(libs.assertj) + testImplementation(libs.awaitility) + testImplementation(libs.junit.jupiter.params) + testImplementation(libs.mockito) + testImplementation(libs.slf4j.simple) + testImplementation(platform(libs.spring.bom)) + testImplementation(libs.spring.context) + testImplementation(libs.spring.test) testImplementation(kotlin("test-junit5")) - testImplementation(platform("org.springframework:spring-framework-bom:$springVersion")) - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion") + testRuntimeOnly(libs.junit.jupiter.engine) } group = "com.github.kpavlov.jreactive8583" @@ -54,17 +48,20 @@ version = ( } ) description = "ISO8583 Connector for Netty" -java.sourceCompatibility = JavaVersion.VERSION_11 -java.targetCompatibility = JavaVersion.VERSION_11 - -tasks.withType().configureEach { - kotlinOptions { - jvmTarget = "11" - apiVersion = "1.7" - freeCompilerArgs = listOf( + +java { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +kotlin { + compilerOptions { + jvmTarget = JvmTarget.JVM_17 + progressiveMode = true + freeCompilerArgs.addAll( "-Xjvm-default=all", "-Xjsr305=strict", - "-Xexplicit-api=strict" + "-Xexplicit-api=strict", ) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..f91022e --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,34 @@ +[versions] +awaitility = "4.2.2" +detekt = "1.23.7" +dokka = "1.9.20" +junitJupiter = "5.11.0" +kotlin = "2.0.20" +mockito = "5.13.0" +netty = "4.1.113.Final" +slf4j = "2.0.16" +spring = "6.1.13" +findbugs = "3.0.2" + +[libraries] +findbugs = { group = "com.google.code.findbugs", name = "jsr305", version.ref = "findbugs" } +netty = { group = "io.netty", name = "netty-handler", version.ref = "netty" } +j8583 = { group = "net.sf.j8583", name = "j8583", version = "2.0.0" } +jcip = { group = "net.jcip", name = "jcip-annotations", version = "1.0" } +commons-lang3 = { group = "org.apache.commons", name = "commons-lang3", version = "3.17.0" } +assertj = { group = "org.assertj", name = "assertj-core", version = "3.26.3" } +awaitility = { group = "org.awaitility", name = "awaitility-kotlin", version.ref = "awaitility" } +junit-jupiter-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version.ref = "junitJupiter" } +mockito = { group = "org.mockito", name = "mockito-junit-jupiter", version.ref = "mockito" } +spring-bom = { group = "org.springframework", name = "spring-framework-bom", version.ref = "spring" } +spring-context = { group = "org.springframework", name = "spring-context" } +spring-test = { group = "org.springframework", name = "spring-test" } +junit-jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junitJupiter" } +slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" } +slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" } + +[plugins] +kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } +detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } +nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version = "2.0.0" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index c4868df..cdd1464 100644 --- a/gradle/wrapper/gradle-wrapper.jar +++ b/gradle/wrapper/gradle-wrapper.jar @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:33ad4583fd7ee156f533778736fa1b4940bd83b433934d1cc4e9f608e99a6a89 -size 59536 +oid sha256:2db75c40782f5e8ba1fc278a5574bab070adccb2d21ca5a6e5ed840888448046 +size 43583 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e1adfb4..0aaefbc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..f5feea6 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,12 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +134,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +201,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +217,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,10 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +27,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +43,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +78,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/ConnectorConfiguration.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/ConnectorConfiguration.kt index d039efc..6e4ae70 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/ConnectorConfiguration.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/ConnectorConfiguration.kt @@ -193,7 +193,7 @@ public abstract class ConnectorConfiguration protected constructor(b: Builder<*> this.workerThreadsCount = b.workerThreadsCount } - @Suppress("UNCHECKED_CAST") + @Suppress("UNCHECKED_CAST", "TooManyFunctions") public open class Builder> { internal var addLoggingHandler = false internal var addEchoMessageListener = false diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/ConnectorConfigurer.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/ConnectorConfigurer.kt index 49e72ef..a2f7e8d 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/ConnectorConfigurer.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/ConnectorConfigurer.kt @@ -5,6 +5,7 @@ package com.github.kpavlov.jreactive8583 import io.netty.bootstrap.AbstractBootstrap import io.netty.channel.ChannelPipeline +@JvmDefaultWithCompatibility public interface ConnectorConfigurer> { /** * Hook added before completion of the bootstrap configuration. @@ -19,7 +20,6 @@ public interface ConnectorConfigurer @JvmOverloads construc } catch (e: ClassCastException) { logger.debug( "IsoMessage subclass {} is not supported by {}. Doing nothing.", - msg.javaClass, javaClass + msg.javaClass, javaClass, + e ) return } @@ -55,6 +56,7 @@ internal class CompositeIsoMessageHandler @JvmOverloads construc } } + @Suppress("TooGenericExceptionCaught") private fun handleWithMessageListener( messageListener: IsoMessageListener, isoMessage: T, @@ -64,7 +66,7 @@ internal class CompositeIsoMessageHandler @JvmOverloads construc if (messageListener.applies(isoMessage)) { logger.debug( "Handling IsoMessage[@type=0x{}] with {}", - String.format("%04X", isoMessage.type), + "%04X".format(isoMessage.type), messageListener ) return messageListener.onMessage(ctx, isoMessage) diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/Iso8583ChannelInitializer.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/Iso8583ChannelInitializer.kt index 2e22560..4351969 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/Iso8583ChannelInitializer.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/Iso8583ChannelInitializer.kt @@ -42,6 +42,7 @@ internal constructor( vararg customChannelHandlers: ChannelHandler ) : ChannelInitializer() { + @Suppress("SpreadOperator") private val customChannelHandlers = arrayOf(*customChannelHandlers) private val isoMessageEncoder = createIso8583Encoder(configuration) private val loggingHandler = createLoggingHandler(configuration) @@ -69,6 +70,7 @@ internal constructor( ) pipeline.addLast(workerGroup, "idleEventHandler", IdleEventHandler(isoMessageFactory)) } + @Suppress("SpreadOperator") pipeline.addLast(workerGroup, *customChannelHandlers) configurer?.configurePipeline(pipeline, configuration) } diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandler.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandler.kt index 661d949..1bfad3b 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandler.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/IsoMessageLoggingHandler.kt @@ -93,7 +93,8 @@ internal class IsoMessageLoggingHandler( if (printSensitiveData) { sb.append("Message: ").append(m.debugString()).append("\n") } - sb.append("MTI: 0x").append(String.format("%04x", m.type)) + sb.append("MTI: 0x").append("%04x".format(m.type)) + @Suppress("MagicNumber") for (i in 2..127) { if (m.hasField(i)) { val field = m.getField(i) @@ -124,6 +125,7 @@ internal class IsoMessageLoggingHandler( private fun maskPAN(fullPan: String): CharArray { val maskedPan = fullPan.toCharArray() + @Suppress("MagicNumber") for (i in 6 until maskedPan.size - 4) { maskedPan[i] = MASK_CHAR } diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandler.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandler.kt index 6f22766..fd887e5 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandler.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandler.kt @@ -17,10 +17,11 @@ import java.text.ParseException * @see [StackOverflow: How to answer an invalid ISO8583 message](http://stackoverflow.com/questions/28275677/how-to-answer-an-invalid-iso8583-message) */ @Sharable -internal open class ParseExceptionHandler( +public open class ParseExceptionHandler( private val isoMessageFactory: MessageFactory, private val includeErrorDetails: Boolean ) : ChannelInboundHandlerAdapter() { + @Deprecated("Deprecated in Java") @Throws(Exception::class) override fun exceptionCaught( ctx: ChannelHandlerContext, @@ -33,6 +34,7 @@ internal open class ParseExceptionHandler( ctx.fireExceptionCaught(cause) } + @Suppress("MagicNumber") protected fun createErrorResponseMessage(cause: ParseException): IsoMessage { val message = isoMessageFactory.newMessage( MessageClass.ADMINISTRATIVE, MessageFunction.NOTIFICATION, MessageOrigin.OTHER @@ -42,7 +44,7 @@ internal open class ParseExceptionHandler( if (includeErrorDetails) { var details = cause.message if (details!!.length > 25) { - details = details.substring(0, 22) + "..." + details = details.take(22) + "..." } message.setValue(44, details, IsoType.LLVAR, 25) } diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/server/Iso8583Server.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/server/Iso8583Server.kt index a739af7..6fde5ed 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/server/Iso8583Server.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/server/Iso8583Server.kt @@ -36,6 +36,7 @@ public open class Iso8583Server( val bootstrap = ServerBootstrap() val tcpNoDelay = java.lang.Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.nodelay", "true")) + @Suppress("UNCHECKED_CAST") bootstrap.group(bossEventLoopGroup, workerEventLoopGroup) .channel(NioServerSocketChannel::class.java) .childOption(ChannelOption.TCP_NODELAY, tcpNoDelay) @@ -77,10 +78,12 @@ public open class Iso8583Server( } logger.info("Stopping the Server...") with(channel) { + @Suppress("TooGenericExceptionCaught") try { deregister() close().syncUninterruptibly() logger.info("Server was Stopped.") + } catch (e: Exception) { logger.error("Error while stopping the server", e) } diff --git a/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandlerTest.java b/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandlerTest.java index 644c8e4..0f5e529 100644 --- a/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandlerTest.java +++ b/src/test/java/com/github/kpavlov/jreactive8583/netty/pipeline/ParseExceptionHandlerTest.java @@ -67,8 +67,7 @@ void testExceptionCaught() throws Exception { assertThat(field44).as("field44").isInstanceOf(IsoValue.class); assertThat(field44.getType()).as("field44.type").isEqualTo(IsoType.LLVAR); assertThat(field44.getLength()).as("field44.length").isEqualTo(25); - assertThat(field44.getValue()).as("field44.value") - .isEqualToComparingFieldByField(errorMessage.substring(0, 22) + "..."); - + final var expectedValue = errorMessage.substring(0, 22) + "..."; + assertThat(field44.getValue()).as("field44.value").isEqualTo(expectedValue); } } From 41bb0e7a0c25d24d2db4cebc174d6e041ffb0489 Mon Sep 17 00:00:00 2001 From: kpavlov <{ID}+{username}@users.noreply.github.com> Date: Sat, 14 Sep 2024 12:13:43 +0300 Subject: [PATCH 2/2] Fix github actions --- .editorconfig | 6 +-- .github/workflows/gradle.yml | 45 +++++++++---------- .../client/ClientConfiguration.kt | 8 ++-- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0c8739e..cbc2e8c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -341,8 +341,6 @@ ij_kotlin_wrap_elvis_expressions = 1 ij_kotlin_wrap_expression_body_functions = 1 ij_kotlin_wrap_first_method_in_call_chain = false -[{*.json, *.yml}] +[*.{json,yml,yaml}] indent_size = 2 - -[pom.xml] -max_line_length = 120 +tab_width = 2 diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index b872dad..fd608de 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -24,31 +24,30 @@ jobs: strategy: matrix: java: [ '17', '21' ] - distribution: 'corretto' name: Build under JDK ${{ matrix.Java }} steps: - - name: Checkout github repo (+ download lfs dependencies) - uses: actions/checkout@v4 - with: - lfs: true - - name: Set up JDK - uses: actions/setup-java@v4 - with: - java-version: ${{ matrix.java }} - distribution: 'corretto' - cache: 'gradle' - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Build with Gradle - uses: gradle/gradle-build-action@v2 - with: - gradle-version: wrapper - arguments: check build --stacktrace - - name: Publish Test Report - uses: mikepenz/action-junit-report@v4 - if: success() || failure() - with: - report_paths: '**/TEST-*.xml' + - name: Checkout github repo (+ download lfs dependencies) + uses: actions/checkout@v4 + with: + lfs: true + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: ${{ matrix.java }} + distribution: 'corretto' + cache: 'gradle' + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + uses: gradle/gradle-build-action@v2 + with: + gradle-version: wrapper + arguments: check build --stacktrace + - name: Publish Test Report + uses: mikepenz/action-junit-report@v4 + if: success() || failure() + with: + report_paths: '**/TEST-*.xml' diff --git a/src/main/kotlin/com/github/kpavlov/jreactive8583/client/ClientConfiguration.kt b/src/main/kotlin/com/github/kpavlov/jreactive8583/client/ClientConfiguration.kt index 9d951ab..be629f4 100644 --- a/src/main/kotlin/com/github/kpavlov/jreactive8583/client/ClientConfiguration.kt +++ b/src/main/kotlin/com/github/kpavlov/jreactive8583/client/ClientConfiguration.kt @@ -15,19 +15,19 @@ public open class ClientConfiguration( */ internal val reconnectInterval: Int = builder.reconnectInterval - internal companion object { + public companion object { /** * Default client reconnect interval in milliseconds. */ - const val DEFAULT_RECONNECT_INTERVAL = 100 + public const val DEFAULT_RECONNECT_INTERVAL: Int = 100 @JvmStatic - fun newBuilder(): Builder = Builder() + public fun newBuilder(): Builder = Builder() @Suppress("unused") @JvmStatic - fun getDefault(): ClientConfiguration = newBuilder().build() + public fun getDefault(): ClientConfiguration = newBuilder().build() } @Suppress("unused")