-
-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow plugins to contribute to the default configuration (#4315)
* Add missing tests * Remove deprecated code * Get Spec in DefaultConfigProvider * Remove DefaultConfig * Concat configurations * Apply suggestions from code review Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Chao Zhang <zhangchao6865@gmail.com> Co-authored-by: M Schalk <30376729+schalkms@users.noreply.github.com> Co-authored-by: Chao Zhang <zhangchao6865@gmail.com>
- Loading branch information
1 parent
d993ce6
commit a7184d1
Showing
21 changed files
with
203 additions
and
71 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
24 changes: 0 additions & 24 deletions
24
detekt-cli/src/main/kotlin/io/gitlab/arturbosch/detekt/cli/Configurations.kt
This file was deleted.
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
15 changes: 0 additions & 15 deletions
15
detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/config/DefaultConfig.kt
This file was deleted.
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
44 changes: 40 additions & 4 deletions
44
...kt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/tooling/DefaultConfigProvider.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,19 +1,55 @@ | ||
package io.gitlab.arturbosch.detekt.core.tooling | ||
|
||
import io.github.detekt.tooling.api.DefaultConfigurationProvider | ||
import io.github.detekt.tooling.api.spec.ProcessingSpec | ||
import io.github.detekt.utils.getSafeResourceAsStream | ||
import io.github.detekt.utils.openSafeStream | ||
import io.gitlab.arturbosch.detekt.api.Config | ||
import io.gitlab.arturbosch.detekt.core.config.DefaultConfig | ||
import io.gitlab.arturbosch.detekt.core.config.YamlConfig | ||
import io.gitlab.arturbosch.detekt.core.settings.ExtensionFacade | ||
import java.io.ByteArrayInputStream | ||
import java.io.ByteArrayOutputStream | ||
import java.io.InputStream | ||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.nio.file.StandardCopyOption | ||
|
||
class DefaultConfigProvider : DefaultConfigurationProvider { | ||
private lateinit var spec: ProcessingSpec | ||
|
||
override fun get(): Config = DefaultConfig.newInstance() | ||
override fun init(spec: ProcessingSpec) { | ||
this.spec = spec | ||
} | ||
|
||
override fun get(): Config = spec.getDefaultConfiguration() | ||
|
||
override fun copy(targetLocation: Path) { | ||
val configUrl = javaClass.getResource("/${DefaultConfig.RESOURCE_NAME}")!! | ||
Files.copy(configUrl.openSafeStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING) | ||
Files.copy(configInputStream(spec), targetLocation, StandardCopyOption.REPLACE_EXISTING) | ||
} | ||
} | ||
|
||
private fun configInputStream(spec: ProcessingSpec): InputStream { | ||
val outputStream = ByteArrayOutputStream() | ||
|
||
requireNotNull(spec.javaClass.getSafeResourceAsStream("/default-detekt-config.yml")) | ||
.use { it.copyTo(outputStream) } | ||
|
||
ExtensionFacade(spec.extensionsSpec).pluginLoader | ||
.getResourcesAsStream("config/config.yml") | ||
.forEach { inputStream -> | ||
outputStream.bufferedWriter().append('\n').flush() | ||
inputStream.use { it.copyTo(outputStream) } | ||
} | ||
|
||
return ByteArrayInputStream(outputStream.toByteArray()) | ||
} | ||
|
||
private fun ClassLoader.getResourcesAsStream(name: String): Sequence<InputStream> { | ||
return getResources(name) | ||
.asSequence() | ||
.map { it.openSafeStream() } | ||
} | ||
|
||
fun ProcessingSpec.getDefaultConfiguration(): Config { | ||
return YamlConfig.load(configInputStream(this).reader()) | ||
} |
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.