Skip to content

Commit

Permalink
feat: Remove the (unfinished) integration with SonarQube
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebz committed Sep 27, 2023
1 parent f13d50c commit 18aa33e
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 279 deletions.
6 changes: 1 addition & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ repositories {
}

dependencies {
implementation("org.sonarsource.api.plugin:sonar-plugin-api:9.14.0.375")
implementation("com.github.ajalt.clikt:clikt:3.5.0")
implementation("com.felipebz.zpa:sonar-zpa-plugin:3.3.0-SNAPSHOT")
implementation("org.sonarsource.sonarqube:sonar-scanner-protocol:7.9")
implementation("org.sonarsource.sonarqube:sonar-ws:7.9")
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.14.0")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.0")
implementation("org.pf4j:pf4j:3.9.0")
implementation("org.slf4j:slf4j-jdk14:2.0.7")
testImplementation(kotlin("test"))
Expand Down
11 changes: 0 additions & 11 deletions src/main/kotlin/br/com/felipezorzo/zpa/cli/InputFile.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package br.com.felipezorzo.zpa.cli

import org.apache.commons.codec.digest.DigestUtils
import org.sonar.plugins.plsqlopen.api.PlSqlFile
import java.io.File
import java.nio.charset.Charset
Expand All @@ -24,16 +23,6 @@ class InputFile(private val type: PlSqlFile.Type,

override fun path(): Path = file.toPath()

private val lineHashes: Array<String> by lazy {
contents().lineSequence().map {
DigestUtils.md5Hex(it.replace("\\s".toRegex(), ""))
}.toList().toTypedArray()
}

fun getLineHash(line: Int): String {
return lineHashes[line - 1]
}

val pathRelativeToBase: String = baseDirPath.relativize(Paths.get(file.absolutePath)).invariantSeparatorsPathString

override fun hashCode(): Int {
Expand Down
33 changes: 3 additions & 30 deletions src/main/kotlin/br/com/felipezorzo/zpa/cli/Main.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package br.com.felipezorzo.zpa.cli

import br.com.felipezorzo.zpa.cli.plugin.PluginManager
import br.com.felipezorzo.zpa.cli.sonarqube.SonarQubeLoader
import br.com.felipezorzo.zpa.cli.sqissue.GenericIssueData
import br.com.felipezorzo.zpa.cli.sqissue.PrimaryLocation
import br.com.felipezorzo.zpa.cli.sqissue.SecondaryLocation
import br.com.felipezorzo.zpa.cli.sqissue.TextRange
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.groups.OptionGroup
import com.github.ajalt.clikt.parameters.groups.cooccurring
import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
Expand Down Expand Up @@ -38,21 +35,13 @@ import br.com.felipezorzo.zpa.cli.sqissue.Issue as GenericIssue

const val CONSOLE = "console"
const val GENERIC_ISSUE_FORMAT = "sq-generic-issue-import"
const val SONAR_REPORT_FORMAT = "sq-issue-report"

class SonarQubeOptions : OptionGroup() {
val sonarqubeUrl by option(help = "SonarQube server URL").required()
val sonarqubeToken by option(help = "The authentication token of a SonarQube user with Execute Analysis permission on the project.").default("")
val sonarqubeKey by option(help = "The project's unique key on the SonarQube Server.").default("")
}

class Main : CliktCommand(name = "zpa-cli") {
private val sources by option(help = "Folder with files").required()
private val formsMetadata by option(help = "Oracle Forms metadata file").default("")
private val extensions by option(help = "Extensions to analyze").default("sql,pkg,pks,pkb,fun,pcd,tgg,prc,tpb,trg,typ,tab,tps")
private val outputFormat by option(help = "Format of the output file").choice(CONSOLE, GENERIC_ISSUE_FORMAT, SONAR_REPORT_FORMAT).default(CONSOLE)
private val outputFormat by option(help = "Format of the output file").choice(CONSOLE, GENERIC_ISSUE_FORMAT).default(CONSOLE)
private val outputFile by option(help = "Output filename").default("")
private val sonarqubeOptions by SonarQubeOptions().cooccurring()

override fun run() {
javaClass.getResourceAsStream("/logging.properties").use {
Expand All @@ -75,15 +64,8 @@ class Main : CliktCommand(name = "zpa-cli") {
val baseDir = File(sources).absoluteFile
val baseDirPath = baseDir.toPath()

var sonarqubeLoader: SonarQubeLoader? = null
sonarqubeOptions?.let {
if (it.sonarqubeUrl.isNotEmpty()) {
sonarqubeLoader = SonarQubeLoader(it)
}
}

val activeRulesOnSonarQube = sonarqubeLoader?.downloadQualityProfile() ?: emptyList()
val activeRules = ActiveRules().configureRules(activeRulesOnSonarQube)
val activeRules = ActiveRules()
// TODO: read the configuration from a file and call activeRules.configureRules with the list of rules

val ruleMetadataLoader = RuleMetadataLoader()

Expand Down Expand Up @@ -138,15 +120,6 @@ class Main : CliktCommand(name = "zpa-cli") {
GENERIC_ISSUE_FORMAT -> {
exportToGenericIssueFormat(issues)
}

SONAR_REPORT_FORMAT -> {
sonarqubeLoader?.let {
val issuesToExport = it.updateIssues(activeRules, issues)
val gson = Gson()
gson.toJson(issuesToExport)
}.orEmpty()
}

else -> {
""
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 18aa33e

Please sign in to comment.