mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
Replace get_analysis_projects.groovy with kotlin script (#4033)
* replace get_analysis_projects.groovy with kotlin script * fix violations Co-authored-by: Markus Schwarz <post@markus-schwarz.net>
This commit is contained in:
6
.github/CONTRIBUTING.md
vendored
6
.github/CONTRIBUTING.md
vendored
@@ -15,9 +15,9 @@
|
||||
- ... do not forget to add the new rule to a `RuleSetProvider` (e.g. StyleGuideProvider)
|
||||
- ... do not forget to write a description for the issue of the new rule.
|
||||
- ... add the [correct KDoc](#contents-and-structure-of-a-rules-kdoc) and [annotations](#rule-annotations) to your `Rule` class. This is used to generate documentation pages and the `default-detekt-config.yml` automatically.
|
||||
- ... do not forget to test the new rule and/or add tests for any changes made to a rule.
|
||||
Run detekt on itself and other kotlin projects with the `--run-rule RuleSet:RuleId` option to test your rule in isolation.
|
||||
Make use of the `scripts/get_analysis_projects.groovy` script to automatically establish a set of analysis projects.
|
||||
- ... do not forget to test the new rule and/or add tests for any changes made to a rule. Run detekt on itself and other
|
||||
kotlin projects with the `--run-rule RuleSet:RuleId` option to test your rule in isolation. Make use of
|
||||
the `scripts/get_analysis_projects.kts` script to automatically establish a set of analysis projects.
|
||||
- ... run `./gradlew generateDocumentation` to add your rule and its config options to the `default-detekt-config.yml`.
|
||||
- ... do not forget to run `./gradlew build`. This will execute tests locally.
|
||||
- To print the AST of sources you can pass the `--print-ast` flag to the CLI which will print each
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
@GrabResolver(name='detekt', root='https://dl.bintray.com/arturbosch/code-analysis/', m2Compatible='true')
|
||||
@Grab('org.vcsreader:vcsreader:1.1.1')
|
||||
import org.vcsreader.VcsProject
|
||||
import org.vcsreader.vcs.VcsError
|
||||
import org.vcsreader.vcs.git.GitVcsRoot
|
||||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
|
||||
HELP_MESSAGE = """
|
||||
Usage: groovy get_analysis_projects.groovy [/path/to/storing/folder]
|
||||
"""
|
||||
|
||||
def projects = [
|
||||
"git@github.com:arrow-kt/arrow.git",
|
||||
"git@github.com:shyiko/ktlint.git",
|
||||
"git@github.com:vanniktech/gradle-dependency-graph-generator-plugin.git",
|
||||
"git@github.com:vanniktech/lint-rules.git",
|
||||
"git@github.com:vanniktech/junit-rules.git",
|
||||
"git@github.com:spekframework/spek.git",
|
||||
"git@github.com:Kotlin/kotlinx.coroutines.git",
|
||||
"git@github.com:kotlintest/kotlintest.git",
|
||||
"git@github.com:tipsy/javalin.git",
|
||||
"git@github.com:arturbosch/ksh.git",
|
||||
"git@github.com:arturbosch/kutils.git",
|
||||
"git@github.com:arturbosch/deps.git",
|
||||
"git@github.com:detekt/detekt.git",
|
||||
"git@github.com:detekt/sonar-kotlin.git"
|
||||
]
|
||||
|
||||
if (args.size() == 0) {
|
||||
println(HELP_MESSAGE)
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
def storingFolder = Paths.get(args[0])
|
||||
|
||||
if (Files.notExists(storingFolder)) {
|
||||
Files.createDirectories(storingFolder)
|
||||
}
|
||||
|
||||
def gits = projects.collect { asGitRepo(storingFolder, it) }
|
||||
new VcsProject(gits) // sets observers, prevents NPE
|
||||
gits.parallelStream().forEach { handleProject(it) }
|
||||
|
||||
static asGitRepo(root, gitUrl) {
|
||||
def index = gitUrl.indexOf("/") + 1
|
||||
def name = gitUrl.substring(index)
|
||||
index = name.indexOf(".")
|
||||
name = name.substring(0, index)
|
||||
new GitVcsRoot(root.resolve(name).toString(), gitUrl)
|
||||
}
|
||||
|
||||
static handleProject(git) {
|
||||
def filePath = Paths.get(git.repoFolder())
|
||||
def fileName = filePath.fileName.toString()
|
||||
|
||||
try {
|
||||
if (Files.exists(filePath)) {
|
||||
def result = git.update()
|
||||
if (!result.isSuccessful()) {
|
||||
throw new IllegalStateException(extractVcsErrors(result.exceptions()))
|
||||
}
|
||||
println("Updated existing repo $fileName")
|
||||
} else {
|
||||
def cloneResult = git.cloneIt()
|
||||
if (!cloneResult.isSuccessful()) {
|
||||
throw new IllegalStateException(extractVcsErrors(cloneResult.exceptions()))
|
||||
}
|
||||
println("Finished cloning $fileName")
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
println("Error while handling $fileName: \n$ex.message")
|
||||
}
|
||||
}
|
||||
|
||||
static String extractVcsErrors(exceptions) {
|
||||
exceptions.stream()
|
||||
.filter { VcsError.isInstance(it) }
|
||||
.collect { it.message }
|
||||
.join("\n")
|
||||
}
|
||||
65
scripts/get_analysis_projects.kts
Executable file
65
scripts/get_analysis_projects.kts
Executable file
@@ -0,0 +1,65 @@
|
||||
#!kotlinc -script
|
||||
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.util.concurrent.TimeUnit.MINUTES
|
||||
|
||||
val githubProjects = listOf(
|
||||
"arrow-kt/arrow",
|
||||
"pintrest/ktlint",
|
||||
"vanniktech/gradle-dependency-graph-generator-plugin",
|
||||
"vanniktech/lint-rules",
|
||||
"vanniktech/junit-rules",
|
||||
"spekframework/spek",
|
||||
"Kotlin/kotlinx.coroutines",
|
||||
"Kotlin/kotlinx.serialization",
|
||||
"Kotlin/kotlinx-datetime",
|
||||
"Kotlin/dokka",
|
||||
"kotest/kotest",
|
||||
"tipsy/javalin",
|
||||
)
|
||||
|
||||
class Downloader(private val basePath: Path, private val project: String) {
|
||||
|
||||
fun download() {
|
||||
if (Files.exists(basePath.resolve(project.substringAfter('/')))) {
|
||||
println("Skipping $project as it already exists.")
|
||||
return
|
||||
}
|
||||
println("Downloading $project")
|
||||
cloneRepo("https://github.com/$project.git")
|
||||
}
|
||||
|
||||
private fun cloneRepo(repo: String) {
|
||||
ProcessBuilder("git", "clone", repo)
|
||||
.directory(basePath.toFile())
|
||||
.inheritIO()
|
||||
.start()
|
||||
.waitFor(MAX_CLONE_WAIT_MINUTES, MINUTES)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val MAX_CLONE_WAIT_MINUTES: Long = 5
|
||||
}
|
||||
}
|
||||
|
||||
fun downloadAnalysisProjects(basePath: Path) {
|
||||
println("Downloading analysis projects to ${basePath.toAbsolutePath()}")
|
||||
Files.createDirectories(basePath)
|
||||
|
||||
githubProjects.forEach { project ->
|
||||
Downloader(basePath, project).download()
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size != 1) {
|
||||
println(
|
||||
"""
|
||||
Usage: ./get_analysis_projects.kts [/path/to/storing/folder]
|
||||
or kotlinc -script get_analysis_projects.kts [/path/to/storing/folder]
|
||||
""".trimIndent()
|
||||
)
|
||||
System.exit(1)
|
||||
}
|
||||
|
||||
downloadAnalysisProjects(Path.of(args.first()))
|
||||
Reference in New Issue
Block a user