Skip to content

Commit

Permalink
deps: Replace gson and simple-xml with Jackson
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed May 31, 2024
1 parent b7b6767 commit 7d0fedc
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 62 deletions.
9 changes: 5 additions & 4 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ object Versions {
const val mockito = "5.12.0"
const val mockito_kotlin = "5.3.1"
const val flr = "1.4.0-SNAPSHOT"
const val gson = "2.10.1"
const val jackson = "2.17.1"
const val jsoup = "1.17.2"
const val min_sonarqube = "9.9.0.65466"
const val min_sonarqube_api = "9.14.0.375"
const val sonarqube_orchestrator = "4.9.0.1920"
const val simple_xml = "2.7.1"
const val woodstox = "6.6.2"

const val plugin_shadow = "8.1.7"
}
Expand All @@ -22,6 +22,7 @@ object Libs {
const val flr_xpath = "com.felipebz.flr:flr-xpath:${Versions.flr}"
const val flr_toolkit = "com.felipebz.flr:flr-toolkit:${Versions.flr}"
const val flr_testing_harness = "com.felipebz.flr:flr-testing-harness:${Versions.flr}"
const val gson = "com.google.code.gson:gson:${Versions.gson}"
const val simple_xml = "org.simpleframework:simple-xml:${Versions.simple_xml}"
const val jackson = "com.fasterxml.jackson.core:jackson-databind:${Versions.jackson}"
const val jackson_xml = "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${Versions.jackson}"
const val woodstox = "com.fasterxml.woodstox:woodstox-core:${Versions.woodstox}"
}
3 changes: 2 additions & 1 deletion sonar-zpa-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ plugins {

dependencies {
implementation(Libs.flr_core)
implementation(Libs.simple_xml)
implementation(Libs.jackson_xml)
implementation(Libs.woodstox)
implementation(project(":zpa-core"))
implementation(project(":zpa-checks"))
implementation(project(":zpa-checks-testkit"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,41 @@
*/
package org.sonar.plsqlopen.utplsql

import org.simpleframework.xml.Attribute
import org.simpleframework.xml.ElementList
import org.simpleframework.xml.Root
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement

@Root(name = "coverage")
@JacksonXmlRootElement(localName = "coverage")
data class Coverage @JvmOverloads constructor(
@field:Attribute(name = "version")
@field:JacksonXmlProperty(isAttribute = true, localName = "version")
var version: Int = 0,

@field:ElementList(name = "file", inline = true, required = false)
@field:JacksonXmlElementWrapper(useWrapping = false)
@field:JacksonXmlProperty(localName = "file")
var files: List<CoveredFile>? = null
)

@Root(name = "file")
@JacksonXmlRootElement(localName = "file")
data class CoveredFile @JvmOverloads constructor(
@field:Attribute(name = "path")
@field:JacksonXmlProperty(isAttribute = true, localName = "path")
var path: String = "",

@field:ElementList(name = "lineToCover", inline = true, required = false)
@field:JacksonXmlElementWrapper(useWrapping = false)
@field:JacksonXmlProperty(localName = "lineToCover")
var linesToCover: List<LineToCover>? = null
)

@Root(name = "lineToCover")
@JacksonXmlRootElement(localName = "lineToCover")
data class LineToCover @JvmOverloads constructor(
@field:Attribute(name = "lineNumber")
@field:JacksonXmlProperty(isAttribute = true, localName = "lineNumber")
var lineNumber: Int = 0,

@field:Attribute(name = "covered")
@field:JacksonXmlProperty(isAttribute = true, localName = "covered")
var covered: Boolean = false,

@field:Attribute(name = "branchesToCover", required = false)
@field:JacksonXmlProperty(isAttribute = true, localName = "branchesToCover")
var branchesToCover: Int? = null,

@field:Attribute(name = "coveredBranches", required = false)
@field:JacksonXmlProperty(isAttribute = true, localName = "coveredBranches")
var coveredBranches: Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package org.sonar.plsqlopen.utplsql

import org.simpleframework.xml.core.Persister
import com.fasterxml.jackson.dataformat.xml.XmlMapper
import org.sonar.api.batch.fs.InputFile
import org.sonar.api.batch.sensor.SensorContext
import org.sonar.api.notifications.AnalysisWarnings
Expand All @@ -28,7 +28,6 @@ import org.sonar.plsqlopen.utils.log.Loggers
import org.sonar.plugins.plsqlopen.api.PlSqlGrammar
import java.io.File


class CoverageResultImporter(private val objectLocator: ObjectLocator,
analysisWarnings: AnalysisWarnings) : AbstractReportImporter(analysisWarnings) {

Expand All @@ -37,8 +36,8 @@ class CoverageResultImporter(private val objectLocator: ObjectLocator,
override val reportKey = UtPlSqlSensor.COVERAGE_REPORT_PATH_KEY

override fun processReport(context: SensorContext, report: File) {
val serializer = Persister()
val coverage = serializer.read(Coverage::class.java, report)
val serializer = XmlMapper()
val coverage = serializer.readValue(report, Coverage::class.java)

coverage.files?.forEach { file ->
val filePath = file.path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,46 @@
*/
package org.sonar.plsqlopen.utplsql

import org.simpleframework.xml.Attribute
import org.simpleframework.xml.Element
import org.simpleframework.xml.ElementList
import org.simpleframework.xml.Root
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement

@Root(name = "testExecutions")
@JacksonXmlRootElement(localName = "testExecutions")
data class TestExecutions @JvmOverloads constructor(
@field:Attribute(name = "version")
@field:JacksonXmlProperty(isAttribute = true, localName = "version")
var version: Int = 0,

@field:ElementList(name = "file", inline = true, required = false)
@field:JacksonXmlElementWrapper(useWrapping = false)
@field:JacksonXmlProperty(localName = "file")
var files: List<TestFile>? = null
)

@Root(name = "file")
@JacksonXmlRootElement(localName = "file")
data class TestFile @JvmOverloads constructor(
@field:Attribute(name = "path")
@field:JacksonXmlProperty(isAttribute = true, localName = "path")
var path: String = "",

@field:ElementList(name = "testCase", inline = true, required = false)
@field:JacksonXmlElementWrapper(useWrapping = false)
@field:JacksonXmlProperty(localName = "testCase")
var testCases: List<TestCase>? = null
)

@Root(name = "testCase")
@JacksonXmlRootElement(localName = "testCase")
data class TestCase @JvmOverloads constructor(
@field:Attribute(name = "name")
@field:JacksonXmlProperty(isAttribute = true, localName = "name")
var name: String = "",

@field:Attribute(name = "duration")
@field:JacksonXmlProperty(isAttribute = true, localName = "duration")
var duration: Long = 0,

@field:Element(name = "skipped", required = false)
@field:JacksonXmlProperty(localName = "skipped")
var skipped: Skipped? = null,

@field:Element(name = "failure", required = false)
@field:JacksonXmlProperty(localName = "failure")
var failure: Failure? = null,

@field:Element(name = "error", required = false)
@field:JacksonXmlProperty(localName = "error")
var error: Error? = null
) {
val status: TestCaseStatus
Expand All @@ -70,13 +72,16 @@ data class TestCase @JvmOverloads constructor(
}
}

@Root(name = "skipped", strict = false)
@JacksonXmlRootElement(localName = "skipped")
@JsonIgnoreProperties(ignoreUnknown = true)
class Skipped

@Root(name = "failure", strict = false)
@JacksonXmlRootElement(localName = "failure")
@JsonIgnoreProperties(ignoreUnknown = true)
class Failure

@Root(name = "error", strict = false)
@JacksonXmlRootElement(localName = "error")
@JsonIgnoreProperties(ignoreUnknown = true)
class Error

enum class TestCaseStatus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
package org.sonar.plsqlopen.utplsql

import org.simpleframework.xml.core.Persister
import com.fasterxml.jackson.dataformat.xml.XmlMapper
import org.sonar.api.batch.fs.InputFile
import org.sonar.api.batch.measure.Metric
import org.sonar.api.batch.sensor.SensorContext
Expand All @@ -39,8 +39,8 @@ class TestResultImporter(private val objectLocator: ObjectLocator,
override val reportKey = UtPlSqlSensor.TEST_REPORT_PATH_KEY

override fun processReport(context: SensorContext, report: File) {
val serializer = Persister()
val testExecutions = serializer.read(TestExecutions::class.java, report)
val serializer = XmlMapper()
val testExecutions = serializer.readValue(report, TestExecutions::class.java)

testExecutions.files?.forEach { file ->
val packageName = file.path.substringAfterLast('.')
Expand Down
1 change: 0 additions & 1 deletion zpa-checks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ testing {
dependencies {
implementation(project())
implementation(project(":zpa-core"))
implementation(Libs.gson)
implementation("org.jsoup:jsoup:${Versions.jsoup}")
}
}
Expand Down
2 changes: 1 addition & 1 deletion zpa-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies {
api(Libs.flr_core)
implementation(Libs.gson)
implementation(Libs.jackson)
testImplementation(Libs.flr_testing_harness)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
*/
package org.sonar.plsqlopen.metadata

import com.google.gson.Gson
import com.google.gson.stream.JsonReader
import com.fasterxml.jackson.databind.ObjectMapper
import org.sonar.plsqlopen.utils.log.Loggers
import java.io.File
import java.io.FileNotFoundException
import java.io.FileReader
import java.io.IOException

class Block(val name: String, val items: Array<String>)
class Block @JvmOverloads constructor(val name: String = "", val items: Array<String> = emptyArray())

class FormsMetadata {

Expand All @@ -40,11 +39,10 @@ class FormsMetadata {
fun loadFromFile(path: String?): FormsMetadata? {
if (!path.isNullOrEmpty()) {
try {
JsonReader(FileReader(path)).use { reader ->
val formsMetadata = Gson().fromJson<FormsMetadata>(reader, FormsMetadata::class.java)
LOG.info("Loaded Oracle Forms metadata from {}.", path)
return formsMetadata
}
val mapper = ObjectMapper()
val formsMetadata: FormsMetadata = mapper.readValue(File(path), FormsMetadata::class.java)
LOG.info("Loaded Oracle Forms metadata from {}.", path)
return formsMetadata
} catch (e: FileNotFoundException) {
LOG.warn("The metadata file {} was not found.", path, e)
} catch (e: IOException) {
Expand Down
12 changes: 6 additions & 6 deletions zpa-core/src/test/resources/metadata/metadata.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
alerts: ["foo", "bar"],
blocks: [
{ name: "foo", items: ["item1", "item2"] },
{ name: "bar", items: ["item1", "item2"] }
"alerts": ["foo", "bar"],
"blocks": [
{ "name": "foo", "items": ["item1", "item2"] },
{ "name": "bar", "items": ["item1", "item2"] }
],
lovs: ["foo", "bar"]
}
"lovs": ["foo", "bar"]
}

0 comments on commit 7d0fedc

Please sign in to comment.