Use own allow list for each repository
This commit is contained in:
@@ -11,6 +11,7 @@ import junit.framework.TestCase
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
import kotlin.collections.HashSet
|
||||||
|
|
||||||
class CodeConformanceTest : TestCase() {
|
class CodeConformanceTest : TestCase() {
|
||||||
companion object {
|
companion object {
|
||||||
@@ -21,6 +22,7 @@ class CodeConformanceTest : TestCase() {
|
|||||||
private val EXCLUDED_FILES_AND_DIRS = listOf(
|
private val EXCLUDED_FILES_AND_DIRS = listOf(
|
||||||
"build/js",
|
"build/js",
|
||||||
"buildSrc",
|
"buildSrc",
|
||||||
|
"compiler/build",
|
||||||
"compiler/fir/lightTree/testData",
|
"compiler/fir/lightTree/testData",
|
||||||
"compiler/testData/psi/kdoc",
|
"compiler/testData/psi/kdoc",
|
||||||
"compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt",
|
"compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt",
|
||||||
@@ -245,13 +247,33 @@ class CodeConformanceTest : TestCase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testTemporaryRepositoriesAbuse() {
|
private class FileMatcher(val root: File, files: Collection<File>) {
|
||||||
val extensions = setOf("java", "kt", "gradle", "kts")
|
private val names = files.mapTo(HashSet()) { it.name }
|
||||||
val repositories = setOf(
|
private val paths = files.mapTo(HashSet()) { it.systemIndependentPath }
|
||||||
"https://dl.bintray.com/kotlin/kotlin-dev",
|
private val relativePaths = files.filter { it.isDirectory }.mapTo(HashSet()) { it.systemIndependentPath + "/" }
|
||||||
"https://dl.bintray.com/kotlin/kotlin-eap"
|
|
||||||
)
|
fun matchExact(file: File): Boolean {
|
||||||
val allowList = setOf(
|
return (file.name in names) && file.relativeTo(root).systemIndependentPath in paths
|
||||||
|
}
|
||||||
|
|
||||||
|
fun matchWithContains(file: File): Boolean {
|
||||||
|
if (matchExact(file)) return true
|
||||||
|
val relativePath = file.relativeTo(root).systemIndependentPath
|
||||||
|
return relativePaths.any { relativePath.startsWith(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testRepositoriesAbuse() {
|
||||||
|
class RepoAllowList(val repo: String, root: File, allowList: Set<String>) {
|
||||||
|
val allowFiles = allowList.map(::File)
|
||||||
|
val matcher = FileMatcher(root, allowFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
val root = File(".")
|
||||||
|
|
||||||
|
val repoCheckers = listOf(
|
||||||
|
RepoAllowList(
|
||||||
|
"https://dl.bintray.com/kotlin/kotlin-dev", root, setOf(
|
||||||
"libraries/tools/new-project-wizard/new-project-wizard-cli/testData",
|
"libraries/tools/new-project-wizard/new-project-wizard-cli/testData",
|
||||||
"gradle/cacheRedirector.gradle.kts",
|
"gradle/cacheRedirector.gradle.kts",
|
||||||
"kotlin-ultimate/prepare/mobile-plugin/build.gradle.kts",
|
"kotlin-ultimate/prepare/mobile-plugin/build.gradle.kts",
|
||||||
@@ -269,7 +291,11 @@ class CodeConformanceTest : TestCase() {
|
|||||||
"idea/testData/gradle/packagePrefixImport/packagePrefixNonMPP/build.gradle",
|
"idea/testData/gradle/packagePrefixImport/packagePrefixNonMPP/build.gradle",
|
||||||
"idea/testData/gradle/gradleFacetImportTest/jvmImportWithCustomSourceSets_1_1_2/build.gradle",
|
"idea/testData/gradle/gradleFacetImportTest/jvmImportWithCustomSourceSets_1_1_2/build.gradle",
|
||||||
"idea/testData/gradle/gradleFacetImportTest/jvmImport_1_1_2/build.gradle",
|
"idea/testData/gradle/gradleFacetImportTest/jvmImport_1_1_2/build.gradle",
|
||||||
"idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/MultiplePluginVersionGradleImportingTestCase.kt",
|
"idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/MultiplePluginVersionGradleImportingTestCase.kt"
|
||||||
|
)
|
||||||
|
),
|
||||||
|
RepoAllowList(
|
||||||
|
"https://dl.bintray.com/kotlin/kotlin-eap", root, setOf(
|
||||||
"kotlin-ultimate/ide/android-studio-native/testData/wizard/expected/app/build.gradle.kts",
|
"kotlin-ultimate/ide/android-studio-native/testData/wizard/expected/app/build.gradle.kts",
|
||||||
"kotlin-ultimate/ide/android-studio-native/testData/wizard/expected/shared/build.gradle.kts",
|
"kotlin-ultimate/ide/android-studio-native/testData/wizard/expected/shared/build.gradle.kts",
|
||||||
"kotlin-ultimate/ide/android-studio-native/testData/wizard/expected/build.gradle.kts",
|
"kotlin-ultimate/ide/android-studio-native/testData/wizard/expected/build.gradle.kts",
|
||||||
@@ -281,35 +307,72 @@ class CodeConformanceTest : TestCase() {
|
|||||||
"idea/testData/configuration/gradle/m04Version/build_after.gradle",
|
"idea/testData/configuration/gradle/m04Version/build_after.gradle",
|
||||||
"idea/testData/configuration/gsk/eapVersion/build_after.gradle.kts",
|
"idea/testData/configuration/gsk/eapVersion/build_after.gradle.kts",
|
||||||
"idea/testData/configuration/gsk/eap11Version/build_after.gradle.kts",
|
"idea/testData/configuration/gsk/eap11Version/build_after.gradle.kts",
|
||||||
"idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt"
|
"idea/idea-jvm/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt",
|
||||||
).map(::File)
|
"gradle/cacheRedirector.gradle.kts",
|
||||||
val fullIgnoreList = EXCLUDED_FILES_AND_DIRS + allowList
|
"idea/idea-maven/testData/configurator/jvm/simpleProjectEAP/pom_after.xml",
|
||||||
val excludeFileNames = fullIgnoreList.filter { it.isFile }.map { it.name }.toSet()
|
"idea/idea-maven/testData/configurator/jvm/simpleProjectRc/pom_after.xml",
|
||||||
val excludedDirNames = fullIgnoreList.filter { it.isDirectory }.map { it.name }.toSet()
|
"idea/idea-maven/testData/maven-inspections/deprecatedJre.fixed.1.xml",
|
||||||
val excludedPaths = fullIgnoreList.map { it.systemIndependentPath }.toSet()
|
"idea/idea-maven/testData/maven-inspections/deprecatedJre.xml",
|
||||||
val root = File(".")
|
"idea/idea-maven/testData/maven-inspections/deprecatedKotlinxCoroutines.fixed.1.xml",
|
||||||
val filesWithRepositories = root.walkTopDown()
|
"idea/idea-maven/testData/maven-inspections/deprecatedKotlinxCoroutines.xml",
|
||||||
.onEnter { dir ->
|
"idea/idea-maven/testData/maven-inspections/deprecatedKotlinxCoroutinesNoError.xml",
|
||||||
!(dir.name in excludedDirNames && dir.relativeTo(root).systemIndependentPath in excludedPaths)
|
"idea/testData/gradle/configurator/configureJsEAPWithBuildGradle/build.gradle.after",
|
||||||
}
|
"idea/testData/gradle/configurator/configureJsEAPWithBuildGradleKts/build.gradle.kts.after",
|
||||||
.filter { file -> file.extension in extensions && file.isFile }
|
"idea/testData/gradle/configurator/configureJvmEAPWithBuildGradle/build.gradle.after",
|
||||||
.filter { file -> !(file.name in excludeFileNames && file.isFile && file.relativeTo(root).systemIndependentPath in excludedPaths) }
|
"idea/testData/gradle/configurator/configureJvmEAPWithBuildGradleKts/build.gradle.kts.after",
|
||||||
.filter { file ->
|
"idea/testData/perfTest/native/_common/settings.gradle.kts",
|
||||||
file.useLines { lines ->
|
"kotlin-ultimate/gradle/cidrPluginTools.gradle.kts",
|
||||||
lines.any { line ->
|
"libraries/tools/new-project-wizard/src/org/jetbrains/kotlin/tools/projectWizard/core/service/KotlinVersionProviderService.kt"
|
||||||
repositories.any { repository -> line.contains(repository) }
|
)
|
||||||
}
|
)
|
||||||
}
|
)
|
||||||
}
|
|
||||||
.toList()
|
|
||||||
|
|
||||||
if (filesWithRepositories.isNotEmpty()) {
|
data class RepoOccurance(val repo: String, val file: File)
|
||||||
|
data class RepoOccurrences(val repo: String, val files: Collection<File>)
|
||||||
|
|
||||||
|
val extensions = hashSetOf("java", "kt", "gradle", "kts", "xml", "after")
|
||||||
|
val nonSourceMatcher = FileMatcher(root, EXCLUDED_FILES_AND_DIRS)
|
||||||
|
val repoOccurrences: List<RepoOccurrences> = root.walkTopDown()
|
||||||
|
.onEnter { dir -> !nonSourceMatcher.matchExact(dir) } // don't visit dirs
|
||||||
|
.filter { file -> file.extension in extensions && file.isFile }
|
||||||
|
.filter { file -> !nonSourceMatcher.matchExact(file) } // filter ignored files
|
||||||
|
.flatMap { file ->
|
||||||
|
val checkers = repoCheckers.filter { checker ->
|
||||||
|
!checker.matcher.matchWithContains(file)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkers.isNotEmpty()) {
|
||||||
|
val occurrences = ArrayList<RepoOccurance>()
|
||||||
|
file.useLines { lines ->
|
||||||
|
for (line in lines) {
|
||||||
|
for (checker in checkers) {
|
||||||
|
if (line.contains(checker.repo)) {
|
||||||
|
occurrences.add(RepoOccurance(checker.repo, file))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
occurrences
|
||||||
|
} else {
|
||||||
|
listOf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.groupBy { it.repo }
|
||||||
|
.map { (repo, occurrences) -> RepoOccurrences(repo, occurrences.mapTo(HashSet()) { it.file }) }
|
||||||
|
|
||||||
|
if (repoOccurrences.isNotEmpty()) {
|
||||||
|
val repoOccurrencesStableOrder = repoOccurrences
|
||||||
|
.map { RepoOccurrences(it.repo, it.files.sortedBy { it.path }) }
|
||||||
|
.sortedBy { it.repo }
|
||||||
fail(
|
fail(
|
||||||
buildString {
|
buildString {
|
||||||
appendLine("The following files use temporal repositories and not listed in the allowed list:")
|
appendLine("The following files use repositories and not listed in the correspondent allow lists")
|
||||||
filesWithRepositories.forEach { appendLine(" ${it.relativeTo(root).systemIndependentPath}") }
|
for ((repo, files) in repoOccurrencesStableOrder) {
|
||||||
appendLine("List of monitored repositories:")
|
appendLine(repo)
|
||||||
repositories.forEach { appendLine(" $it") }
|
for (file in files) {
|
||||||
|
appendLine(" ${file.relativeTo(root).systemIndependentPath}")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user