Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ matrix:
env: COMPILE_TEST_SNIPPETS=false
install: true
script:
- ./gradlew build shadowJar --build-cache --parallel -PwarningsAsErrors=true -Pcompile-test-snippets=$COMPILE_TEST_SNIPPETS --scan
- ./gradlew build shadowJar --build-cache -PwarningsAsErrors=true -Pcompile-test-snippets=$COMPILE_TEST_SNIPPETS --scan
- java -jar ./detekt-cli/build/libs/detekt-cli-*-all.jar --help
- java -jar ./detekt-cli/build/libs/detekt-cli-*-all.jar -i . --baseline ./config/detekt/baseline.xml -ex "**/resources/**,**/detekt*/build/**" -c ./detekt-cli/src/main/resources/default-detekt-config.yml,./config/detekt/detekt.yml
- ./gradlew verifyGeneratorOutput
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![gradle plugin](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/io/gitlab/arturbosch/detekt/io.gitlab.arturbosch.detekt.gradle.plugin/maven-metadata.xml.svg?label=Gradle&style=flat-square)](https://plugins.gradle.org/plugin/io.gitlab.arturbosch.detekt)

[![build status](https://travis-ci.org/arturbosch/detekt.svg?branch=master)](https://travis-ci.org/arturbosch/detekt)
[![build status windows](https://ci.appveyor.com/api/projects/status/3q9g98vveiul7yut/branch/master?svg=true)](https://ci.appveyor.com/project/arturbosch/detekt)
[![build status windows](https://ci.appveyor.com/api/projects/status/3q9g98vveiul7yut?svg=true)](https://ci.appveyor.com/project/arturbosch/detekt)
[![codecov](https://codecov.io/gh/arturbosch/detekt/branch/master/graph/badge.svg)](https://codecov.io/gh/arturbosch/detekt)
[![CodeFactor](https://www.codefactor.io/repository/github/arturbosch/detekt/badge)](https://www.codefactor.io/repository/github/arturbosch/detekt)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Farturbosch%2Fdetekt-intellij-plugin.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Farturbosch%2Fdetekt?ref=badge_shield)
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ install:
- gradlew.bat --version

build_script:
- gradlew build installShadowDist --build-cache --parallel -PwarningsAsErrors=true -Pcompile-test-snippets=%COMPILE_TEST_SNIPPETS%
- gradlew build installShadowDist --build-cache -PwarningsAsErrors=true -Pcompile-test-snippets=%COMPILE_TEST_SNIPPETS%
- detekt-cli\build\install\detekt-cli-shadow\bin\detekt-cli --help

test_script:
Expand Down
118 changes: 51 additions & 67 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,41 @@ import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig
import java.util.Date

plugins {
id("io.gitlab.arturbosch.detekt")
kotlin("jvm")
jacoco
`maven-publish`
// Plugin versions for these plugins are defined in gradle.properties and applied in settings.gradle.kts
id("com.jfrog.artifactory") apply false
id("com.github.ben-manes.versions")
id("io.gitlab.arturbosch.detekt")
id("org.sonarqube")
id("com.jfrog.bintray")
id("com.jfrog.artifactory") apply false
id("org.jetbrains.dokka") apply false
id("com.github.ben-manes.versions")
kotlin("jvm")
id("com.github.johnrengelman.shadow") apply false
id("org.sonarqube")
}

buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}

tasks.wrapper {
val gradleVersion: String by project
this.gradleVersion = gradleVersion
distributionType = Wrapper.DistributionType.ALL
doLast {
/*
* Copy the properties file into the detekt-gradle-plugin project.
* This allows IDEs like IntelliJ to import the detekt-gradle-plugin as a standalone project.
*/
copy {
from(propertiesFile)
into(file("${gradle.includedBuild("detekt-gradle-plugin").projectDir}/gradle/wrapper"))
}
}
}

tasks.check {
dependsOn(gradle.includedBuild("detekt-gradle-plugin").task(":check"))
}

tasks.withType<Detekt>().configureEach {
dependsOn(gradle.includedBuild("detekt-gradle-plugin").task(":detekt"))
}

val detektVersion: String by project
val jacocoVersion: String by project
jacoco.toolVersion = jacocoVersion

tasks {
jacocoTestReport {
executionData.setFrom(fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec"))

subprojects
.filterNot { it.name in listOf("detekt-test", "detekt-sample-extensions") }
.forEach {
[email protected](it.sourceSets.main.get())
[email protected](it.tasks.test)
}

reports {
xml.isEnabled = true
xml.destination = file("$buildDir/reports/jacoco/report.xml")
}
val assertjVersion: String by project
val spekVersion: String by project
val reflectionsVersion: String by project
val mockkVersion: String by project
val junitPlatformVersion: String by project

fun versionOrSnapshot(): String {
if (System.getProperty("snapshot")?.toBoolean() == true) {
return "$detektVersion-SNAPSHOT"
}
return detektVersion
}

val detektVersion: String by project

allprojects {
group = "io.gitlab.arturbosch.detekt"
version = detektVersion + if (System.getProperty("snapshot")?.toBoolean() == true) "-SNAPSHOT" else ""
version = versionOrSnapshot()

repositories {
jcenter()
Expand All @@ -97,6 +64,20 @@ subprojects {
plugin("io.gitlab.arturbosch.detekt")
}

dependencies {
implementation(kotlin("stdlib"))

detekt(project(":detekt-cli"))
detektPlugins(project(":detekt-formatting"))

testImplementation("org.assertj:assertj-core:$assertjVersion")
testImplementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion")
testImplementation("org.reflections:reflections:$reflectionsVersion")
testImplementation("io.mockk:mockk:$mockkVersion")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:$junitPlatformVersion")
testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spekVersion")
}

if (project.name !in listOf("detekt-test", "detekt-sample-extensions")) {
apply {
plugin("jacoco")
Expand Down Expand Up @@ -142,7 +123,7 @@ subprojects {
}
}

tasks.withType<Test>().configureEach {
tasks.withType<Test>() {
useJUnitPlatform()
systemProperty("SPEK_TIMEOUT", 0) // disable test timeout
val compileSnippetText: Boolean = if (project.hasProperty("compile-test-snippets")) {
Expand All @@ -166,7 +147,7 @@ subprojects {
}
}

tasks.withType<KotlinCompile>().configureEach {
tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = projectJvmTarget
// https://youtrack.jetbrains.com/issue/KT-24946
kotlinOptions.freeCompilerArgs = listOf(
Expand Down Expand Up @@ -232,7 +213,7 @@ subprojects {
}

publishing {
publications.create<MavenPublication>(detektPublication) {
publications.register<MavenPublication>(detektPublication) {
from(components["java"])
artifact(sourcesJar)
artifact(javadocJar)
Expand Down Expand Up @@ -283,30 +264,33 @@ subprojects {
})
})
}
}

val assertjVersion: String by project
val spekVersion: String by project
val kotlinTest by configurations.creating
jacoco.toolVersion = jacocoVersion

dependencies {
implementation(kotlin("stdlib"))
tasks {
jacocoTestReport {
executionData.setFrom(fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec"))

detekt(project(":detekt-cli"))
detektPlugins(project(":detekt-formatting"))
subprojects
.filterNot { it.name in listOf("detekt-test", "detekt-sample-extensions") }
.forEach {
[email protected](it.sourceSets.main.get())
[email protected](it.tasks.test)
}

kotlinTest("org.assertj:assertj-core:$assertjVersion")
kotlinTest("org.spekframework.spek2:spek-dsl-jvm:$spekVersion")
reports {
xml.isEnabled = true
xml.destination = file("$buildDir/reports/jacoco/report.xml")
}
}

sourceSets.main.get().java.srcDirs("src/main/kotlin")
}

/**
* Usage: <code>./gradlew build -PwarningsAsErrors=true</code>.
*/
fun shouldTreatCompilerWarningsAsErrors(): Boolean {
return project.findProperty("warningsAsErrors") == "true"
}
fun shouldTreatCompilerWarningsAsErrors(): Boolean =
project.findProperty("warningsAsErrors") == "true"

dependencies {
detekt(project(":detekt-cli"))
Expand Down
6 changes: 0 additions & 6 deletions detekt-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ plugins {
id("org.jetbrains.dokka")
}

configurations.testImplementation.get().extendsFrom(configurations.kotlinTest.get())

val yamlVersion: String by project
val junitPlatformVersion: String by project
val spekVersion: String by project
Expand All @@ -14,11 +12,7 @@ dependencies {
implementation("org.yaml:snakeyaml:$yamlVersion")
api(kotlin("compiler-embeddable"))
implementation(kotlin("reflect"))

testImplementation(project(":detekt-test"))

testRuntimeOnly("org.junit.platform:junit-platform-launcher:$junitPlatformVersion")
testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spekVersion")
}

tasks.withType<DokkaTask>().configureEach {
Expand Down
7 changes: 0 additions & 7 deletions detekt-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ val detektVersion: String by project
val reflectionsVersion: String by project
val mockkVersion: String by project

// implementation.extendsFrom kotlin is not enough for using cli in a gradle task - #58
configurations.testImplementation.get().extendsFrom(configurations.kotlinTest.get())

dependencies {
implementation(project(":detekt-core"))
runtimeOnly(project(":detekt-rules"))
Expand All @@ -20,10 +17,6 @@ dependencies {

testImplementation(project(":detekt-test"))
testImplementation(project(":detekt-rules"))
testImplementation("org.reflections:reflections:$reflectionsVersion")
testImplementation("io.mockk:mockk:$mockkVersion")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:$junitPlatformVersion")
testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spekVersion")
}

// bundle detekt's version for debug logging on rule exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,6 @@ class CliArgs : Args {
* Creates an instance of [CliArgs]. Verification if the settings are sound
* must be made by the caller.
*/
fun parse(args: Array<String>): CliArgs = parseArguments<CliArgs>(args).first
fun parse(args: Array<String>): CliArgs = parseArguments(args)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.gitlab.arturbosch.detekt.cli

class HelpRequest : RuntimeException()
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ package io.gitlab.arturbosch.detekt.cli

import com.beust.jcommander.JCommander
import com.beust.jcommander.ParameterException
import kotlin.system.exitProcess

inline fun <reified T : Args> parseArguments(args: Array<String>): Pair<T, JCommander> {
val cli = T::class.java.declaredConstructors.firstOrNull()?.newInstance() as? T
import java.io.PrintStream

@Suppress("detekt.SpreadOperator", "detekt.ThrowsCount")
inline fun <reified T : Args> parseArguments(
args: Array<String>,
outPrinter: PrintStream = System.out,
errorPrinter: PrintStream = System.err,
validateCli: T.(MessageCollector) -> Unit = {}
): T {
val cli = T::class.java.declaredConstructors
.firstOrNull()
?.newInstance() as? T
?: throw IllegalStateException("Could not create Args object for class ${T::class.java}")

val jCommander = JCommander()
Expand All @@ -14,30 +22,36 @@ inline fun <reified T : Args> parseArguments(args: Array<String>): Pair<T, JComm
jCommander.programName = "detekt"

try {
@Suppress("SpreadOperator")
jCommander.parse(*args)
} catch (ex: ParameterException) {
val message = ex.message
jCommander.failWithErrorMessages(message)
errorPrinter.println("${ex.message}\n")
jCommander.usage(outPrinter)
throw IllegalArgumentException("Unexpected argument parsing error.")
}

if (cli.help) {
jCommander.usage()
exitProcess(0)
jCommander.usage(outPrinter)
throw HelpRequest()
}

return cli to jCommander
}
val violations = mutableListOf<String>()
validateCli(cli, object : MessageCollector {
override fun plusAssign(msg: String) {
violations += msg
}
})
if (violations.isNotEmpty()) {
violations.forEach(errorPrinter::println)
errorPrinter.println()
jCommander.usage(outPrinter)
throw IllegalStateException("Unexpected argument violation.")
}

fun JCommander.failWithErrorMessages(vararg messages: String?) {
failWithErrorMessages(messages.asIterable())
return cli
}

fun JCommander.failWithErrorMessages(messages: Iterable<String?>) {
messages.forEach {
println(it)
}
println()
this.usage()
exitProcess(1)
fun JCommander.usage(outPrinter: PrintStream) {
val usage = StringBuilder()
this.usageFormatter.usage(usage)
outPrinter.println(usage.toString())
}
Loading