Fix CodeConformanceTest after merging android-dx to prepare-deps

This commit is contained in:
Vyacheslav Gerasimov
2019-03-21 18:09:31 +03:00
parent a5f96d6470
commit e3a012cd19
@@ -27,30 +27,30 @@ class CodeConformanceTest : TestCase() {
private val JAVA_FILE_PATTERN = Pattern.compile(".+\\.java")
private val SOURCES_FILE_PATTERN = Pattern.compile("(.+\\.java|.+\\.kt|.+\\.js)")
private val EXCLUDED_FILES_AND_DIRS = listOf(
"android.tests.dependencies",
"buildSrc",
"core/reflection.jvm/src/kotlin/reflect/jvm/internal/pcollections",
"js/js.tests/.gradle",
"js/js.translator/testData/node_modules",
"libraries/kotlin.test/js/it/.gradle",
"libraries/kotlin.test/js/it/node_modules",
"libraries/stdlib/js/.gradle",
"libraries/stdlib/js/build",
"libraries/reflect/build",
"libraries/reflect/api/src/java9/java/kotlin/reflect/jvm/internal/impl",
"libraries/tools/binary-compatibility-validator/src/main/kotlin/org.jetbrains.kotlin.tools",
"dependencies",
"js/js.translator/qunit/qunit.js",
"libraries/tools/kotlin-js-tests/src/test/web/qunit.js",
"out",
"dist",
"libraries/tools/kotlin-gradle-plugin-core/gradle_api_jar/build/tmp",
"libraries/tools/kotlin-maven-plugin/target",
"libraries/tools/kotlinp/src",
"compiler/testData/psi/kdoc",
"compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt",
"compiler/util/src/org/jetbrains/kotlin/config/MavenComparableVersion.java",
"dependencies/protobuf/protobuf-relocated/build"
"android.tests.dependencies",
"buildSrc",
"core/reflection.jvm/src/kotlin/reflect/jvm/internal/pcollections",
"js/js.tests/.gradle",
"js/js.translator/testData/node_modules",
"libraries/kotlin.test/js/it/.gradle",
"libraries/kotlin.test/js/it/node_modules",
"libraries/stdlib/js/.gradle",
"libraries/stdlib/js/build",
"libraries/reflect/build",
"libraries/reflect/api/src/java9/java/kotlin/reflect/jvm/internal/impl",
"libraries/tools/binary-compatibility-validator/src/main/kotlin/org.jetbrains.kotlin.tools",
"dependencies",
"js/js.translator/qunit/qunit.js",
"libraries/tools/kotlin-js-tests/src/test/web/qunit.js",
"out",
"dist",
"libraries/tools/kotlin-gradle-plugin-core/gradle_api_jar/build/tmp",
"libraries/tools/kotlin-maven-plugin/target",
"libraries/tools/kotlinp/src",
"compiler/testData/psi/kdoc",
"compiler/tests/org/jetbrains/kotlin/code/CodeConformanceTest.kt",
"compiler/util/src/org/jetbrains/kotlin/config/MavenComparableVersion.java",
"dependencies/protobuf/protobuf-relocated/build"
).map(::File)
private val COPYRIGHT_EXCLUDED_FILES_AND_DIRS = listOf(
@@ -72,8 +72,7 @@ class CodeConformanceTest : TestCase() {
"libraries/stdlib/js/node_modules",
"libraries/tools/kotlin-maven-plugin-test/target",
"libraries/tools/kotlin-gradle-plugin-integration-tests/build",
"buildSrc/prepare-deps/android-dx/build",
"buildSrc/prepare-deps/intellij-sdk/build"
"buildSrc/prepare-deps/build"
)
}
@@ -96,49 +95,49 @@ class CodeConformanceTest : TestCase() {
val atAuthorPattern = Pattern.compile("/\\*.+@author.+\\*/", Pattern.DOTALL)
val tests = listOf(
TestData(
"%d source files contain @author javadoc tag.\nPlease remove them or exclude in this test:\n%s",
{ source ->
// substring check is an optimization
"@author" in source && atAuthorPattern.matcher(source).find() &&
"ASM: a very small and fast Java bytecode manipulation framework" !in source
}
),
TestData(
"%d source files use something from com.beust.jcommander.internal package.\n" +
TestData(
"%d source files contain @author javadoc tag.\nPlease remove them or exclude in this test:\n%s",
{ source ->
// substring check is an optimization
"@author" in source && atAuthorPattern.matcher(source).find() &&
"ASM: a very small and fast Java bytecode manipulation framework" !in source
}
),
TestData(
"%d source files use something from com.beust.jcommander.internal package.\n" +
"This code won't work when there's no TestNG in the classpath of our IDEA plugin, " +
"because there's only an optional dependency on testng.jar.\n" +
"Most probably you meant to use Guava's Lists, Maps or Sets instead. " +
"Please change references in these files to com.google.common.collect:\n%s",
{ source ->
"com.beust.jcommander.internal" in source
}
),
TestData(
"%d source files contain references to package org.jetbrains.jet.\n" +
{ source ->
"com.beust.jcommander.internal" in source
}
),
TestData(
"%d source files contain references to package org.jetbrains.jet.\n" +
"Package org.jetbrains.jet is deprecated now in favor of org.jetbrains.kotlin. " +
"Please consider changing the package in these files:\n%s",
{ source ->
"org.jetbrains.jet" in source
}
),
TestData(
"%d source files contain references to package kotlin.reflect.jvm.internal.impl.\n" +
{ source ->
"org.jetbrains.jet" in source
}
),
TestData(
"%d source files contain references to package kotlin.reflect.jvm.internal.impl.\n" +
"This package contains internal reflection implementation and is a result of a " +
"post-processing of kotlin-reflect.jar by jarjar.\n" +
"Most probably you meant to use classes from org.jetbrains.kotlin.**.\n" +
"Please change references in these files or exclude them in this test:\n%s",
{ source ->
"kotlin.reflect.jvm.internal.impl" in source
}
),
TestData(
"%d source files contain references to package org.objectweb.asm.\n" +
{ source ->
"kotlin.reflect.jvm.internal.impl" in source
}
),
TestData(
"%d source files contain references to package org.objectweb.asm.\n" +
"Package org.jetbrains.org.objectweb.asm should be used instead to avoid troubles with different asm versions in classpath. " +
"Please consider changing the package in these files:\n%s",
{ source ->
" org.objectweb.asm" in source
})
{ source ->
" org.objectweb.asm" in source
})
)
for (sourceFile in FileUtil.findFilesByMask(SOURCES_FILE_PATTERN, File("."))) {
@@ -171,7 +170,7 @@ class CodeConformanceTest : TestCase() {
for (sourceFile in FileUtil.findFilesByMask(SOURCES_FILE_PATTERN, root)) {
val relativePath = FileUtil.toSystemIndependentName(sourceFile.toRelativeString(root))
if (COPYRIGHT_EXCLUDED_FILES_AND_DIRS.any { relativePath.startsWith(it) } ||
knownThirdPartyCode.any { relativePath.startsWith(it)}) continue
knownThirdPartyCode.any { relativePath.startsWith(it) }) continue
sourceFile.useLines { lineSequence ->
for (line in lineSequence) {
@@ -182,21 +181,23 @@ class CodeConformanceTest : TestCase() {
}
}
if (filesWithUnlistedCopyrights.isNotEmpty()) {
fail("The following files contain third-party copyrights and no license information. " +
"Please update license/README.md accordingly:\n${filesWithUnlistedCopyrights.joinToString("\n")}")
fail(
"The following files contain third-party copyrights and no license information. " +
"Please update license/README.md accordingly:\n${filesWithUnlistedCopyrights.joinToString("\n")}"
)
}
}
private fun loadKnownThirdPartyCodeList(): List<String> {
File("license/README.md").useLines { lineSequence ->
return lineSequence
.filter { it.startsWith(" - Path: ") }
.map { it.removePrefix(" - Path: ").trim().ensureFileOrEndsWithSlash() }
.toList()
.filter { it.startsWith(" - Path: ") }
.map { it.removePrefix(" - Path: ").trim().ensureFileOrEndsWithSlash() }
.toList()
}
}
}
private fun String.ensureFileOrEndsWithSlash() =
if (endsWith("/") || "." in substringAfterLast('/')) this else this + "/"
if (endsWith("/") || "." in substringAfterLast('/')) this else this + "/"