diff --git a/.github/workflows/build-dev-release.yml b/.github/workflows/build-dev-release.yml new file mode 100644 index 0000000..b438d11 --- /dev/null +++ b/.github/workflows/build-dev-release.yml @@ -0,0 +1,15 @@ +name: Build and publish dev release Docker image to Github Container Registry ghcr.io + +on: workflow_dispatch + +jobs: + build: + uses: th2-net/.github/.github/workflows/compound-java.yml@main + with: + build-target: 'Docker' + devRelease: true + createTag: true + docker-username: ${{ github.actor }} + secrets: + docker-password: ${{ secrets.GITHUB_TOKEN }} + nvd-api-key: ${{ secrets.NVD_APIKEY }} \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/build-release.yml similarity index 53% rename from .github/workflows/docker-publish.yml rename to .github/workflows/build-release.yml index cec50a6..dcf70be 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/build-release.yml @@ -1,20 +1,15 @@ -name: Build and publish Docker distributions to Github Container Registry ghcr.io +name: Build and publish release Docker image to Github Container Registry ghcr.io -on: - push: - branches: - - master - - version-* - paths: - - gradle.properties -# - package_info.json +on: workflow_dispatch jobs: - build-job: + build: uses: th2-net/.github/.github/workflows/compound-java.yml@main with: build-target: 'Docker' + devRelease: false + createTag: true docker-username: ${{ github.actor }} secrets: docker-password: ${{ secrets.GITHUB_TOKEN }} - \ No newline at end of file + nvd-api-key: ${{ secrets.NVD_APIKEY }} \ No newline at end of file diff --git a/.github/workflows/dev-docker-publish.yml b/.github/workflows/build-sanpshot.yml similarity index 75% rename from .github/workflows/dev-docker-publish.yml rename to .github/workflows/build-sanpshot.yml index 6f77755..9366a44 100644 --- a/.github/workflows/dev-docker-publish.yml +++ b/.github/workflows/build-sanpshot.yml @@ -1,4 +1,4 @@ -name: Dev build and publish Docker distributions to Github Container Registry ghcr.io +name: Build and publish Docker image to Github Container Registry ghcr.io on: push: @@ -17,3 +17,4 @@ jobs: docker-username: ${{ github.actor }} secrets: docker-password: ${{ secrets.GITHUB_TOKEN }} + nvd-api-key: ${{ secrets.NVD_APIKEY }} \ No newline at end of file diff --git a/.github/workflows/ci-unwelcome-words.yml b/.github/workflows/ci-unwelcome-words.yml index cd7adcf..b23bb56 100644 --- a/.github/workflows/ci-unwelcome-words.yml +++ b/.github/workflows/ci-unwelcome-words.yml @@ -7,17 +7,17 @@ jobs: test: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.sha }} - - name: Checkout tool - uses: actions/checkout@v2 - with: - repository: exactpro-th2/ci-github-action - ref: master - token: ${{ secrets.PAT_CI_ACTION }} - path: ci-github-action - - name: Run CI action - uses: ./ci-github-action - with: - ref: ${{ github.sha }} + - uses: actions/checkout@v4 + with: + ref: ${{ github.sha }} + - name: Checkout tool + uses: actions/checkout@v4 + with: + repository: exactpro-th2/ci-github-action + ref: master + token: ${{ secrets.PAT_CI_ACTION }} + path: ci-github-action + - name: Run CI action + uses: ./ci-github-action + with: + ref: ${{ github.sha }} \ No newline at end of file diff --git a/.github/workflows/dev-release-java-publish-sonatype-and-docker.yml b/.github/workflows/dev-release-java-publish-sonatype-and-docker.yml deleted file mode 100644 index 9c3e5df..0000000 --- a/.github/workflows/dev-release-java-publish-sonatype-and-docker.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Build and release Java distributions to sonatype. - -on: - push: - tags: - - \d+.\d+.\d+-dev - -jobs: - build: - uses: th2-net/.github/.github/workflows/compound-java.yml@main - with: - build-target: 'Sonatype,Docker' - runsOn: ubuntu-latest - gradleVersion: '7' - docker-username: ${{ github.actor }} - devRelease: true - secrets: - sonatypeUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} - sonatypePassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} - sonatypeSigningKey: ${{ secrets.SONATYPE_GPG_ARMORED_KEY }} - sonatypeSigningPassword: ${{ secrets.SONATYPE_SIGNING_PASSWORD }} - docker-password: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3ee4f84..432f34f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM gradle:7.6-jdk11 AS build +FROM gradle:8.7-jdk11 AS build ARG release_version COPY ./ . RUN gradle --no-daemon clean build dockerPrepare -Prelease_version=${release_version} diff --git a/README.md b/README.md index 671390e..3b3b9e0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Codec Xml via Xsd (2.2.0) +# Codec Xml via Xsd (2.3.0) ![version](https://img.shields.io/badge/version-0.0.4-blue.svg) # How it works: @@ -142,6 +142,14 @@ spec: ## Changelog +### v2.3.0 + +* Migrated to th2 gradle plugin `0.1.1` (bom: `4.6.1`) +* Updated common: `5.14.0-dev` +* Updated common-utils `2.2.3-dev` +* Updated codec `5.5.0-dev` +* Updated workflows + ### v2.2.0 * Migrate to StAX parser diff --git a/build.gradle b/build.gradle index cdecc3a..7295f39 100755 --- a/build.gradle +++ b/build.gradle @@ -1,54 +1,14 @@ -/* - * Copyright 2021-2023 Exactpro (Exactpro Systems Limited) - * Licensed 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. - */ - -import com.github.jk1.license.filter.LicenseBundleNormalizer -import com.github.jk1.license.render.JsonReportRenderer -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - plugins { - id "com.palantir.docker" version "0.25.0" id "org.jetbrains.kotlin.jvm" version "$kotlin_version" id "org.jetbrains.kotlin.kapt" version "$kotlin_version" id "application" - id "org.owasp.dependencycheck" version "8.4.0" - id "com.gorylenko.gradle-git-properties" version "2.4.1" - id "com.github.jk1.dependency-license-report" version "2.5" - id "de.undercouch.download" version "5.5.0" -} - -ext { - sharedDir = file("${project.rootDir}/shared") + id "com.exactpro.th2.gradle.component" version "0.1.1" } group = 'com.exactpro.th2' version = release_version -sourceCompatibility = JavaVersion.VERSION_11 -targetCompatibility = JavaVersion.VERSION_11 - -ext { - junitVersion = '5.10.0' -} - repositories { - maven { - name 'MavenLocal' - url sharedDir - } - maven { name 'Sonatype_snapshots' url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' @@ -62,10 +22,12 @@ repositories { artifact() } } + maven { name 'Sonatype_releases' url 'https://s01.oss.sonatype.org/content/repositories/releases/' } + maven { name 'Sonatype_releases' url 'https://s01.oss.sonatype.org/content/repositories/releases/' @@ -74,6 +36,7 @@ repositories { artifact() } } + mavenCentral() mavenLocal() @@ -83,100 +46,27 @@ repositories { } } -jar { - manifest { - attributes( - 'Created-By': "${System.getProperty('java.version')} (${System.getProperty('java.vendor')})", - 'Specification-Title': '', - 'Specification-Vendor': 'Exactpro Systems LLC', - 'Implementation-Title': project.archivesBaseName, - 'Implementation-Vendor': 'Exactpro Systems LLC', - 'Implementation-Vendor-Id': 'com.exactpro', - 'Implementation-Version': project.version - ) - } -} - dependencies { - api platform("com.exactpro.th2:bom:4.5.0") - implementation "com.exactpro.th2:common:5.4.0-dev" - implementation "com.exactpro.th2:codec:5.3.0-dev" - implementation "com.exactpro.th2:common-utils:2.2.0-dev" + implementation "com.exactpro.th2:common:5.14.0-dev" + implementation "com.exactpro.th2:common-utils:2.2.3-dev" + implementation "com.exactpro.th2:codec:5.5.0-dev" implementation "org.slf4j:slf4j-api" - implementation "io.github.microutils:kotlin-logging:3.0.5" - - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - implementation "org.jetbrains.kotlin:kotlin-reflect" + implementation "io.github.oshai:kotlin-logging:5.1.4" implementation "com.fasterxml.jackson.core:jackson-core" - implementation "com.github.javadev:underscore:1.93" + implementation "com.github.javadev:underscore:1.104" implementation "commons-io:commons-io" - implementation group: 'org.apache.ws.xmlschema', name: 'xmlschema-core', version: '2.3.0' - - testImplementation "org.jetbrains.kotlin:kotlin-test-junit5:$kotlin_version" + implementation "org.apache.ws.xmlschema:xmlschema-core:2.3.1" compileOnly "com.google.auto.service:auto-service:1.1.1" annotationProcessor "com.google.auto.service:auto-service:1.1.1" kapt "com.google.auto.service:auto-service:1.1.1" -} - -application { - mainClassName 'com.exactpro.th2.codec.MainKt' -} - -applicationName = 'service' - -dockerPrepare { - dependsOn distTar -} - -docker { - copySpec.from(tarTree("$buildDir/distributions/${applicationName}.tar")) -} - -sourceSets { - main.kotlin.srcDirs += "src/main/kotlin" -} - -tasks.withType(KotlinCompile).configureEach { - compilerOptions.jvmTarget.set(JvmTarget.JVM_11) -} - -clean { - delete sharedDir -} - -dependencyCheck { - formats = ['SARIF', 'JSON', 'HTML'] - failBuildOnCVSS = 5 - suppressionFile = file('suppressions.xml') - analyzers { - assemblyEnabled = false - nugetconfEnabled = false - nodeEnabled = false - } -} - -licenseReport { - def licenseNormalizerBundlePath = "$buildDir/license-normalizer-bundle.json" - - if (!file(licenseNormalizerBundlePath).exists()) { - download.run { - src 'https://raw.githubusercontent.com/th2-net/.github/main/license-compliance/gradle-license-report/license-normalizer-bundle.json' - dest "$buildDir/license-normalizer-bundle.json" - overwrite false - } - } - filters = [new LicenseBundleNormalizer(licenseNormalizerBundlePath, false)] - renderers = [new JsonReportRenderer('licenses.json', false)] - excludeOwnGroup = false - allowedLicensesFile = new URL("https://raw.githubusercontent.com/th2-net/.github/main/license-compliance/gradle-license-report/allowed-licenses.json") + testImplementation "org.jetbrains.kotlin:kotlin-test-junit5" } -test { - useJUnitPlatform() - //exclude 'com/exactpro/th2/codec/xml' -} \ No newline at end of file +test.useJUnitPlatform() +application.mainClass = "com.exactpro.th2.codec.MainKt" +dependencyCheck.suppressionFile = file('suppressions.xml') \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index d0630c1..bd09e9b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ # limitations under the License. # -release_version=2.2.0 +release_version=2.3.0 kotlin_version=1.8.22 description = 'th2 codec xml via xsd' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 801a5b3..cbb73a6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ # -# Copyright 2021-2023 Exactpro (Exactpro Systems Limited) +# Copyright 2021-2024 Exactpro (Exactpro Systems Limited) # Licensed 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 @@ -13,7 +13,7 @@ # limitations under the License. # -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStorePath=wrapper/dists diff --git a/src/main/kotlin/com/exactpro/th2/codec/xml/XmlPipelineCodec.kt b/src/main/kotlin/com/exactpro/th2/codec/xml/XmlPipelineCodec.kt index 7f75ffe..2ca97fd 100755 --- a/src/main/kotlin/com/exactpro/th2/codec/xml/XmlPipelineCodec.kt +++ b/src/main/kotlin/com/exactpro/th2/codec/xml/XmlPipelineCodec.kt @@ -1,5 +1,5 @@ /* - * Copyright 2021-2023 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * Licensed 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 @@ -37,13 +37,12 @@ import com.exactpro.th2.common.utils.message.transport.getField import com.github.underscore.Xml import com.google.protobuf.UnsafeByteOperations import io.netty.buffer.Unpooled -import mu.KotlinLogging +import io.github.oshai.kotlinlogging.KotlinLogging import java.io.InputStream import java.nio.charset.Charset import java.util.Locale open class XmlPipelineCodec(settings: XmlPipelineCodecSettings, xsdMap: Map InputStream> = emptyMap()) : IPipelineCodec { - private val pointer: List = settings.typePointer ?.split("/")?.filter(String::isNotBlank) ?: listOf() @@ -214,6 +213,5 @@ open class XmlPipelineCodec(settings: XmlPipelineCodecSettings, xsdMap: Map = XmlPipelineCodecSettings::class.java override val protocols: Set - get() = setOf(PROTOCOL) + get() = PROTOCOLS private lateinit var context: IPipelineCodecContext private val lock = ReentrantLock() @Volatile @@ -62,5 +62,6 @@ class XmlPipelineCodecFactory : IPipelineCodecFactory { companion object { private val LOGGER = KotlinLogging.logger { } const val PROTOCOL = "XML" + private val PROTOCOLS = setOf(PROTOCOL) } } \ No newline at end of file diff --git a/src/main/kotlin/com/exactpro/th2/codec/xml/xsd/XsdErrorHandler.kt b/src/main/kotlin/com/exactpro/th2/codec/xml/xsd/XsdErrorHandler.kt index 70d9643..ea99c0a 100644 --- a/src/main/kotlin/com/exactpro/th2/codec/xml/xsd/XsdErrorHandler.kt +++ b/src/main/kotlin/com/exactpro/th2/codec/xml/xsd/XsdErrorHandler.kt @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * Licensed 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 @@ -15,8 +15,7 @@ package com.exactpro.th2.codec.xml.xsd -import mu.KotlinLogging -import org.slf4j.Logger +import io.github.oshai.kotlinlogging.KotlinLogging import org.xml.sax.ErrorHandler import org.xml.sax.SAXException import org.xml.sax.SAXParseException @@ -44,11 +43,11 @@ class XsdErrorHandler : ErrorHandler { val lineNumber: Int = exception.lineNumber val columnNumber: Int = exception.columnNumber val message: String? = exception.message - LOGGER.error("[$level] line nr: $lineNumber column nr: $columnNumber \nmessage: $message") + LOGGER.error { "[$level] line nr: $lineNumber column nr: $columnNumber \nmessage: $message" } throw SAXException("[$level] line nr: $lineNumber column nr: $columnNumber \nmessage: $message", exception) } companion object { - private val LOGGER: Logger = KotlinLogging.logger { } + private val LOGGER = KotlinLogging.logger { } } } \ No newline at end of file diff --git a/src/main/kotlin/com/exactpro/th2/codec/xml/xsd/XsdValidator.kt b/src/main/kotlin/com/exactpro/th2/codec/xml/xsd/XsdValidator.kt index a7181c8..1a3d3e0 100644 --- a/src/main/kotlin/com/exactpro/th2/codec/xml/xsd/XsdValidator.kt +++ b/src/main/kotlin/com/exactpro/th2/codec/xml/xsd/XsdValidator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * Licensed 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 @@ -16,8 +16,7 @@ package com.exactpro.th2.codec.xml.xsd import com.exactpro.th2.codec.CodecException -import mu.KotlinLogging -import org.slf4j.Logger +import io.github.oshai.kotlinlogging.KotlinLogging import org.w3c.dom.Document import org.w3c.dom.NamedNodeMap import org.w3c.dom.Node @@ -55,18 +54,17 @@ class XsdValidator(private val xsdMap: Map InputStream>, private v val item = documentXML.getElementsByTagNameNS(attribute.nodeValue, "*").item(0) validator.validate(DOMSource(item)) - LOGGER.debug("Validation of raw message with XSD: ${schema.value} finished") + LOGGER.debug { "Validation of raw message with XSD: ${schema.value} finished" } } } } } catch (e: Exception) { if (dirtyValidation) { - LOGGER.warn("VALIDATION ERROR: ", e) + LOGGER.warn(e) { "VALIDATION ERROR: " } } else { throw e } } - } private fun getSchemas(input: String): Map = mutableMapOf().apply { @@ -101,10 +99,9 @@ class XsdValidator(private val xsdMap: Map InputStream>, private v } } - companion object { private const val SCHEMA_NAME_PROPERTY = "schemaLocation" - private val LOGGER: Logger = KotlinLogging.logger { } + private val LOGGER = KotlinLogging.logger { } private val SCHEMA_FACTORY = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).apply { errorHandler = XsdErrorHandler() @@ -140,5 +137,4 @@ class XsdValidator(private val xsdMap: Map InputStream>, private v } } } - } \ No newline at end of file diff --git a/src/test/kotlin/com/exactpro/th2/codec/xml/utils/XmlTest.kt b/src/test/kotlin/com/exactpro/th2/codec/xml/utils/XmlTest.kt index 78c004a..ec0af41 100644 --- a/src/test/kotlin/com/exactpro/th2/codec/xml/utils/XmlTest.kt +++ b/src/test/kotlin/com/exactpro/th2/codec/xml/utils/XmlTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * Licensed 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 @@ -23,22 +23,21 @@ import com.exactpro.th2.common.grpc.AnyMessage import com.exactpro.th2.common.grpc.Message import com.exactpro.th2.common.grpc.MessageGroup import com.google.protobuf.TextFormat -import mu.KotlinLogging +import io.github.oshai.kotlinlogging.KotlinLogging import org.apache.commons.io.FileUtils -import org.slf4j.Logger import java.io.File import java.util.Base64 import kotlin.test.assertEquals abstract class XmlTest(pathToType: String? = null) { protected val reportingContext = ReportingContext() - protected val codec: IPipelineCodec + protected val codec: IPipelineCodec = XmlPipelineCodec(XmlPipelineCodecSettings(pathToType)) protected fun checkEncode(xml: String, message: Message.Builder) { val group = codec.encode(MessageGroup.newBuilder().addMessages(AnyMessage.newBuilder().setMessage(message)).build(), reportingContext) assertEquals(1, group.messagesCount) - LOGGER.info("ENCODE_RESULT: ${TextFormat.shortDebugString(group)}") + LOGGER.info { "ENCODE_RESULT: ${TextFormat.shortDebugString(group)}" } assertEquals( "\n$xml", @@ -50,21 +49,16 @@ abstract class XmlTest(pathToType: String? = null) { val group = codec.decode(createRawMessage(xml), reportingContext) assertEquals(1, group.messagesCount) - LOGGER.info("DECODE_RESULT: ${TextFormat.shortDebugString(group)}") + LOGGER.info { "DECODE_RESULT: ${TextFormat.shortDebugString(group)}" } assertEqualsMessages(message.build(), group.messagesList[0].message, true) } - init { - codec = XmlPipelineCodec(XmlPipelineCodecSettings(pathToType)) - } - protected fun encodeFileToBase64Binary(fileName: String): ByteArray { - val file = File(fileName) - return Base64.getEncoder().encode(FileUtils.readFileToByteArray(file)) + return Base64.getEncoder().encode(FileUtils.readFileToByteArray(File(fileName))) } companion object { - private val LOGGER: Logger = KotlinLogging.logger { } + private val LOGGER = KotlinLogging.logger { } } } \ No newline at end of file diff --git a/suppressions.xml b/suppressions.xml index a7dc9b5..0c032ab 100644 --- a/suppressions.xml +++ b/suppressions.xml @@ -1,9 +1,10 @@ + - - + + - ^pkg:maven/com\.exactpro\.th2/task-utils@.*$ - cpe:/a:utils_project:utils + ^pkg:maven/com\.exactpro\.th2/grpc-.*@.*$ + cpe:/a:grpc:grpc \ No newline at end of file