From c71b1bcabf269215262fa9636490ba4a5de2a2ee Mon Sep 17 00:00:00 2001 From: Gureumi Date: Sun, 14 Apr 2024 14:55:39 +0900 Subject: [PATCH] Fix sonarcloud --- .github/workflows/build.yml | 3 +++ build.gradle.kts | 9 +++++++++ sonar-project.properties | 6 ++++-- src/test/kotlin/FeatureTest.kt | 28 +++++++++++++++++----------- src/test/kotlin/PluginTest.kt | 6 +----- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ec7b561..03056505 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,6 +11,9 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + - name: test + uses: actions/checkout@v3 + run: ./gradlew jacocoTestReport - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master env: diff --git a/build.gradle.kts b/build.gradle.kts index 67b65f01..77affe03 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,6 +5,7 @@ plugins { id("com.github.johnrengelman.shadow") version "8.1.1" id("com.github.node-gradle.node") version "5.0.0" id("maven-publish") + id("jacoco") } java { @@ -185,4 +186,12 @@ publishing { from(components["java"]) } } +} + +tasks.jacocoTestReport { + dependsOn("test") + reports { + xml.required.set(true) + xml.outputLocation.set(file("build/reports/jacoco/test/jacoco.xml")) + } } \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties index 6bf12b09..e0e3ec7c 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -5,9 +5,11 @@ sonar.organization=kieaer #sonar.projectName=Essentials #sonar.projectVersion=1.0 - # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows. #sonar.sources=. # Encoding of the source code. Default is default system encoding -sonar.sourceEncoding=UTF-8 \ No newline at end of file +sonar.sourceEncoding=UTF-8 + +sonar.coverage.jacoco.xmlReportPaths = build/reports/jacoco/test/jacoco.xml +sonar.java.coveragePlugin = jacoco \ No newline at end of file diff --git a/src/test/kotlin/FeatureTest.kt b/src/test/kotlin/FeatureTest.kt index db9674e7..a4679e92 100644 --- a/src/test/kotlin/FeatureTest.kt +++ b/src/test/kotlin/FeatureTest.kt @@ -1,3 +1,4 @@ +import ClientCommandTest.Companion.playerData import PluginTest.Companion.clientCommand import PluginTest.Companion.loadGame import PluginTest.Companion.loadPlugin @@ -14,24 +15,29 @@ import org.junit.Test class FeatureTest { - private var done = false lateinit var playerData: DB.PlayerData - @BeforeClass - fun setup() { - if (!done) { - loadGame() - loadPlugin() + companion object { + var done = false - val p = newPlayer() - Vars.player = p.first.self() - player = p.first.self() - playerData = p.second + @BeforeClass + @JvmStatic fun setup() { + if (!done) { + loadGame() + loadPlugin() - done = true + val p = newPlayer() + Vars.player = p.first.self() + player = p.first.self() + playerData = p.second + + done = true + } } } + + @Test fun pvpBalanceTest() { // Require user or above permission diff --git a/src/test/kotlin/PluginTest.kt b/src/test/kotlin/PluginTest.kt index ff2b11ac..be4cfd7e 100644 --- a/src/test/kotlin/PluginTest.kt +++ b/src/test/kotlin/PluginTest.kt @@ -39,10 +39,6 @@ import java.lang.Thread.sleep import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths -import java.sql.Connection -import java.sql.DriverManager -import java.sql.ResultSet -import java.sql.Statement import java.text.MessageFormat import java.util.* import java.util.zip.ZipFile @@ -311,7 +307,7 @@ class PluginTest { // Copy Essentials 14.1 database val file = Paths.get("src", "test", "resources", "database-v0.db").toFile() - val desc = File(Config.database + ".mv.db") + val desc = File("database.mv.db") file.copyRecursively(desc, true) println(Config.database)