Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'detekt/main' into chao/kt47
- Loading branch information
Showing
34 changed files
with
870 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ | |
"main": "index.js", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"danger": "11.1.2" | ||
"danger": "11.1.4" | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 32 additions & 31 deletions
63
detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/internal/DetektJvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,53 @@ | ||
@file:Suppress("DEPRECATION") | ||
|
||
package io.gitlab.arturbosch.detekt.internal | ||
|
||
import io.gitlab.arturbosch.detekt.DetektPlugin | ||
import io.gitlab.arturbosch.detekt.extensions.DetektExtension | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.Project | ||
import org.gradle.api.file.FileCollection | ||
import org.gradle.api.internal.HasConvention | ||
import org.gradle.api.plugins.JavaPluginConvention | ||
import org.gradle.api.tasks.SourceSet | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation | ||
|
||
internal class DetektJvm(private val project: Project) { | ||
fun registerTasks(extension: DetektExtension) { | ||
project.convention.getPlugin(JavaPluginConvention::class.java).sourceSets.all { sourceSet -> | ||
project.registerJvmDetektTask(extension, sourceSet) | ||
project.registerJvmCreateBaselineTask(extension, sourceSet) | ||
project.extensions.getByType(KotlinJvmProjectExtension::class.java).target.compilations.all { compilation -> | ||
val inputSource = compilation.kotlinSourceSets | ||
.map { it.kotlin.sourceDirectories } | ||
.fold(project.files() as FileCollection) { collection, next -> collection.plus(next) } | ||
project.registerJvmDetektTask(compilation, extension, inputSource) | ||
project.registerJvmCreateBaselineTask(compilation, extension, inputSource) | ||
} | ||
} | ||
|
||
private fun Project.registerJvmDetektTask(extension: DetektExtension, sourceSet: SourceSet) { | ||
val kotlinSourceSet = (sourceSet as HasConvention).convention.plugins["kotlin"] as? KotlinSourceSet | ||
?: throw GradleException("Kotlin source set not found. Please report on detekt's issue tracker") | ||
registerDetektTask(DetektPlugin.DETEKT_TASK_NAME + sourceSet.name.capitalize(), extension) { | ||
source = kotlinSourceSet.kotlin | ||
classpath.setFrom(sourceSet.compileClasspath.existingFiles(), sourceSet.output.classesDirs.existingFiles()) | ||
private fun Project.registerJvmDetektTask( | ||
compilation: KotlinCompilation<KotlinCommonOptions>, | ||
extension: DetektExtension, | ||
inputSource: FileCollection | ||
) { | ||
registerDetektTask(DetektPlugin.DETEKT_TASK_NAME + compilation.name.capitalize(), extension) { | ||
setSource(inputSource) | ||
classpath.setFrom(inputSource, compilation.compileDependencyFiles) | ||
// If a baseline file is configured as input file, it must exist to be configured, otherwise the task fails. | ||
// We try to find the configured baseline or alternatively a specific variant matching this task. | ||
extension.baseline?.existingVariantOrBaseFile(sourceSet.name)?.let { baselineFile -> | ||
baseline.convention(layout.file(project.provider { baselineFile })) | ||
extension.baseline?.existingVariantOrBaseFile(compilation.name)?.let { baselineFile -> | ||
baseline.convention(layout.file(provider { baselineFile })) | ||
} | ||
setReportOutputConventions(reports, extension, sourceSet.name) | ||
description = "EXPERIMENTAL: Run detekt analysis for ${sourceSet.name} classes with type resolution" | ||
setReportOutputConventions(reports, extension, compilation.name) | ||
description = "EXPERIMENTAL: Run detekt analysis for ${compilation.name} classes with type resolution" | ||
} | ||
} | ||
|
||
private fun Project.registerJvmCreateBaselineTask(extension: DetektExtension, sourceSet: SourceSet) { | ||
val kotlinSourceSet = (sourceSet as HasConvention).convention.plugins["kotlin"] as? KotlinSourceSet | ||
?: throw GradleException("Kotlin source set not found. Please report on detekt's issue tracker") | ||
registerCreateBaselineTask(DetektPlugin.BASELINE_TASK_NAME + sourceSet.name.capitalize(), extension) { | ||
source = kotlinSourceSet.kotlin | ||
classpath.setFrom(sourceSet.compileClasspath.existingFiles(), sourceSet.output.classesDirs.existingFiles()) | ||
val variantBaselineFile = extension.baseline?.addVariantName(sourceSet.name) | ||
baseline.convention(project.layout.file(project.provider { variantBaselineFile })) | ||
description = "EXPERIMENTAL: Creates detekt baseline for ${sourceSet.name} classes with type resolution" | ||
private fun Project.registerJvmCreateBaselineTask( | ||
compilation: KotlinCompilation<KotlinCommonOptions>, | ||
extension: DetektExtension, | ||
inputSource: FileCollection | ||
) { | ||
registerCreateBaselineTask(DetektPlugin.BASELINE_TASK_NAME + compilation.name.capitalize(), extension) { | ||
setSource(inputSource) | ||
classpath.setFrom(inputSource, compilation.compileDependencyFiles) | ||
val variantBaselineFile = extension.baseline?.addVariantName(compilation.name) | ||
baseline.convention(layout.file(provider { variantBaselineFile })) | ||
description = "EXPERIMENTAL: Creates detekt baseline for ${compilation.name} classes with type resolution" | ||
} | ||
} | ||
|
||
private fun FileCollection.existingFiles() = filter { it.exists() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.