Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
Prepare 2.0.0 release / rebrand to sonar-detekt (#115)
Browse files Browse the repository at this point in the history
* Re-brand to sonar-detekt removing redundant features SonarKotlin should provide

* Update readme for a 2.0 release

* Remove redundant extension loading

* Apply suggestions from code review

Co-Authored-By: M Schalk <[email protected]>

* Update src/main/kotlin/io/gitlab/arturbosch/detekt/sonar/sensor/IssueReporter.kt

Co-Authored-By: M Schalk <[email protected]>

* Apply readme suggestions

Co-authored-by: M Schalk <[email protected]>
  • Loading branch information
arturbosch and schalkms authored Apr 11, 2020
1 parent cb313b3 commit 4467370
Show file tree
Hide file tree
Showing 39 changed files with 102 additions and 1,805 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Detekt - Changelog

#### 2.0.0

- Rename to sonar-detekt
- Based on detekt 1.7.4
- All redundant features to official SonarKotlin plugin got dropped
- Compatible with SonarKotlin, allows mixing rulesets

#### 1.5.0

- Updated to detekt 1.7.4
Expand Down
47 changes: 28 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sonar-kotlin
# sonar-detekt

[![Join the chat at https://kotlinlang.slack.com/messages/C88E12QH4/convo/C0BQ5GZ0S-1511956674.000289/](https://img.shields.io/badge/chat-on_slack-red.svg?style=flat-square)](https://kotlinlang.slack.com/messages/C88E12QH4/convo/C0BQ5GZ0S-1511956674.000289/)
![Pre Merge Checks](https://github.com/detekt/sonar-kotlin/workflows/Pre%20Merge%20Checks/badge.svg)
Expand All @@ -8,25 +8,34 @@

### Features

- Integrates [detekt](https://github.com/arturbosch/detekt) for code analysis
- Default quality profile `detekt active` (80 rules) and `detekt all` (164 rules)
- Syntax highlighting
- Supports SonarQube 6.7.7 and up
- Supports detekt's `yaml config` and `baseline.xml` (also `path filters`)
- Jacoco support
- Lines of code and complexity metrics
- Integrates [detekt](https://github.com/arturbosch/detekt) for static code analysis
- Default quality profiles `detekt active` (80+ rules) and `detekt all` (164+ rules)
- Supports SonarQube 7.9.3+
- Supports detekt's `yaml config`, `baseline.xml` and `excludes`
- Seamless integration with official SonarKotlin (no redundant features)

#### Non supported features as of 2.x.x

- code coverage
- test reports
- syntax highlighting
- metrics

The official SonarKotlin plugin now supports these features.

### Usage

This sonar-kotlin is not the official sonarqube plugin.
It was released before the official plugin and uses the same plugin key 'kotlin'.
That means you can't use this plugin together with the official one.
#### Sonar Update Center

- TODO

#### Building from source

- `git clone https://github.com/arturbosch/sonar-kotlin`
- `cd sonar-kotlin`
- `mvn package`
- `cp target/sonar-kotlin-[enter_version].jar $SONAR_HOME/extensions/plugins`
- `cd $SONAR_HOME/bin/[your_os]`
- `git clone https://github.com/detekt/sonar-detekt`
- `cd sonar-detekt`
- `mvn verify`
- `cp target/sonar-detekt-<version>.jar $SONAR_HOME/extensions/plugins`
- `cd $SONAR_HOME/bin/<OS>`
- `./sonar.sh restart`

### Configurations and Baselines (and Filters)
Expand All @@ -48,14 +57,14 @@ To make use of this features, you have to set up some properties:
![configs](img/config.png)


__Detekt path filters__ support multiple regex entries by adding a `,` for separating.
__Detekt yaml configuration path__ also supports multiple configuration files where the first entered override some
__detekt path filters__ support multiple regex entries by adding a `,` for separating.
__detekt yaml configuration path__ also supports multiple configuration files where the first entered override some
values of the later added config files.

##### Limitations

Sonar analyzes each module individually which makes it harder to search for your config files.
If you use relative paths, sonar-kotlin first tries to find the provided path inside this module and if it can't find
If you use relative paths, sonar-detekt first tries to find the provided path inside this module and if it can't find
it, we are searching for the file in the parent folder. This leads to the limitation that only projects with
sub-projects of depth 1 are supported. If you need more config files in your project hierarchies, provide them in
the sub-projects with the same relative path available.
Expand Down
18 changes: 7 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.gitlab.arturbosch</groupId>
<artifactId>sonar-kotlin</artifactId>
<version>1.5.0</version>
<groupId>io.github.detekt</groupId>
<artifactId>sonar-detekt</artifactId>
<version>2.0.0-RC1</version>

<packaging>sonar-plugin</packaging>

<properties>
<kotlin.version>1.3.71</kotlin.version>
<spek.version>2.0.10</spek.version>
<detekt.version>1.7.4</detekt.version>
<sonar.api.version>6.7.7</sonar.api.version>
<sonar.api.version>7.9.3</sonar.api.version>
<assertj.version>3.15.0</assertj.version>
<jcommander.version>1.78</jcommander.version>
<mockk.version>1.9.3</mockk.version>
Expand Down Expand Up @@ -74,11 +74,6 @@
<artifactId>detekt-formatting</artifactId>
<version>${detekt.version}</version>
</dependency>
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>java-jacoco</artifactId>
<version>5.7.0.15470</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-compiler-embeddable</artifactId>
Expand Down Expand Up @@ -140,8 +135,8 @@
<configuration>
<pluginClass>io.gitlab.arturbosch.detekt.sonar.DetektPlugin</pluginClass>
<pluginDescription>Sonarqube plugin for Kotlin based on detekt.</pluginDescription>
<pluginKey>kotlin</pluginKey>
<pluginName>Kotlin</pluginName>
<pluginKey>detekt</pluginKey>
<pluginName>detekt</pluginName>
<pluginSourcesUrl>https://github.com/detekt/sonar-kotlin</pluginSourcesUrl>
<pluginUrl>https://github.com/detekt/sonar-kotlin</pluginUrl>
</configuration>
Expand Down Expand Up @@ -237,6 +232,7 @@
</goals>
<configuration>
<baseline>${project.basedir}/reports/baseline.xml</baseline>
<excludes>**/resources/**</excludes>
</configuration>
</execution>
</executions>
Expand Down
21 changes: 3 additions & 18 deletions src/main/kotlin/io/gitlab/arturbosch/detekt/sonar/DetektPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
package io.gitlab.arturbosch.detekt.sonar

import io.gitlab.arturbosch.detekt.sonar.foundation.KotlinClasspath
import io.gitlab.arturbosch.detekt.sonar.foundation.KotlinLanguage
import io.gitlab.arturbosch.detekt.sonar.foundation.DetektProfile
import io.gitlab.arturbosch.detekt.sonar.foundation.propertyDefinitions
import io.gitlab.arturbosch.detekt.sonar.jacoco.KotlinJaCoCoSensor
import io.gitlab.arturbosch.detekt.sonar.profiles.KotlinProfile
import io.gitlab.arturbosch.detekt.sonar.rules.DetektRulesDefinition
import io.gitlab.arturbosch.detekt.sonar.sensor.DetektMetrics
import io.gitlab.arturbosch.detekt.sonar.sensor.DetektSensor
import io.gitlab.arturbosch.detekt.sonar.surefire.KotlinSurefireParser
import io.gitlab.arturbosch.detekt.sonar.surefire.KotlinSurefireSensor
import org.sonar.api.Plugin
import org.sonar.java.JavaTestClasspath

class DetektPlugin : Plugin {

override fun define(context: Plugin.Context) {
context.addExtensions(listOf(
KotlinLanguage::class.java,
KotlinProfile::class.java,
DetektProfile::class.java,
DetektSensor::class.java,
DetektRulesDefinition::class.java,
DetektMetrics::class.java,
KotlinClasspath::class.java,
JavaTestClasspath::class.java,
KotlinJaCoCoSensor::class.java,
// Tests
KotlinSurefireSensor::class.java,
KotlinSurefireParser::class.java
DetektRulesDefinition::class.java
))
context.addExtensions(propertyDefinitions)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package io.gitlab.arturbosch.detekt.sonar.profiles
package io.gitlab.arturbosch.detekt.sonar.foundation

import io.gitlab.arturbosch.detekt.sonar.foundation.DETEKT_FAIL_FAST
import io.gitlab.arturbosch.detekt.sonar.foundation.DETEKT_WAY
import io.gitlab.arturbosch.detekt.sonar.foundation.KEY
import io.gitlab.arturbosch.detekt.sonar.rules.DetektRuleKey
import io.gitlab.arturbosch.detekt.sonar.rules.ruleKeys
import io.gitlab.arturbosch.detekt.sonar.rules.severityTranslations
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition

typealias RuleContext = BuiltInQualityProfilesDefinition.Context

class KotlinProfile : BuiltInQualityProfilesDefinition {
class DetektProfile : BuiltInQualityProfilesDefinition {

override fun define(context: RuleContext) {
registerProfile(context, DETEKT_WAY, ruleKeys.filter { it.active }, isDefault = true)
Expand All @@ -23,7 +20,7 @@ class KotlinProfile : BuiltInQualityProfilesDefinition {
rules: List<DetektRuleKey>,
isDefault: Boolean
) {
val profile = context.createBuiltInQualityProfile(name, KEY)
val profile = context.createBuiltInQualityProfile(name, LANGUAGE_KEY)
profile.isDefault = isDefault

for (ruleKey in rules) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@ package io.gitlab.arturbosch.detekt.sonar.foundation
import io.gitlab.arturbosch.detekt.sonar.DetektPlugin
import org.sonar.api.utils.log.Logger
import org.sonar.api.utils.log.Loggers
import java.util.Optional

const val KEY = "kotlin"
const val NAME = "Kotlin"
const val FILE_SUFFIX = ".kt"
const val SCRIPT_SUFFIX = ".kts"
const val LANGUAGE_KEY = "kotlin"
const val REPOSITORY_KEY = "sonar-detekt"

const val DETEKT_WAY = "detekt active"
const val DETEKT_FAIL_FAST = "detekt all"
const val DETEKT_SENSOR = "DetektSensor"
const val DETEKT_REPOSITORY = "detekt-kotlin"
const val DETEKT_ANALYZER = "Detekt-based Kotlin Analyzer"

val logger: Logger = Loggers.get(DetektPlugin::class.java)

fun <T> Optional<T>.unwrap(): T? = orElse(null)

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4467370

Please sign in to comment.