Build: Exclude plugin.xml from runtime classpath normalization
Version is written to the plugin.xml in every build so we exclude it to improve caching. Add test for kotlin plugin version to checkArtifacts.gradle.kts
This commit is contained in:
@@ -396,6 +396,7 @@ allprojects {
|
|||||||
runtimeClasspath {
|
runtimeClasspath {
|
||||||
ignore("META-INF/MANIFEST.MF")
|
ignore("META-INF/MANIFEST.MF")
|
||||||
ignore("META-INF/compiler.version")
|
ignore("META-INF/compiler.version")
|
||||||
|
ignore("META-INF/plugin.xml")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,19 +10,20 @@ val kotlinVersion: String by rootProject.extra
|
|||||||
|
|
||||||
val checkMavenArtifacts = tasks.register("checkMavenArtifacts") {
|
val checkMavenArtifacts = tasks.register("checkMavenArtifacts") {
|
||||||
doLast {
|
doLast {
|
||||||
fileTree(repoDir).checkArtifacts { zip, artifactName ->
|
fileTree(repoDir).checkArtifacts { zip ->
|
||||||
if (!artifactName.endsWith("-sources.jar"))
|
if (!zip.name.endsWith("-sources.jar"))
|
||||||
zip.checkCompilerVersion(kotlinVersion)?.let { reportProblem(artifactName, it) }
|
zip.checkCompilerVersion(kotlinVersion)
|
||||||
|
|
||||||
zip.checkManifest(kotlinVersion)?.let { reportProblem(artifactName, it) }
|
zip.checkManifest(kotlinVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val checkDist = tasks.register("checkDistArtifacts") {
|
val checkDist = tasks.register("checkDistArtifacts") {
|
||||||
doLast {
|
doLast {
|
||||||
fileTree(distDir).checkArtifacts { zip, artifactName ->
|
fileTree(distDir).checkArtifacts { zip ->
|
||||||
zip.checkCompilerVersion(kotlinVersion)?.let { reportProblem(artifactName, it) }
|
zip.checkCompilerVersion(kotlinVersion)
|
||||||
|
zip.checkPluginXmlVersion(kotlinVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,18 +33,17 @@ tasks.register("checkArtifacts") {
|
|||||||
dependsOn(checkMavenArtifacts)
|
dependsOn(checkMavenArtifacts)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FileTree.checkArtifacts(action: (zip: ZipFile, artifactName: String) -> Unit) {
|
fun FileTree.checkArtifacts(action: (zip: ZipFile) -> Unit) {
|
||||||
filter { it.extension == "jar" }.forEach { jar ->
|
filter { it.extension == "jar" }.forEach { jar ->
|
||||||
val zip = ZipFile(jar)
|
val zip = ZipFile(jar)
|
||||||
val artifactName = jar.relativeTo(file(rootDir)).invariantSeparatorsPath
|
|
||||||
|
|
||||||
if (isTeamcityBuild)
|
if (isTeamcityBuild)
|
||||||
testStarted(artifactName)
|
testStarted(zip.testName())
|
||||||
|
|
||||||
action(zip, artifactName)
|
action(zip)
|
||||||
|
|
||||||
if (isTeamcityBuild)
|
if (isTeamcityBuild)
|
||||||
testFinished(artifactName)
|
testFinished(zip.testName())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,8 +60,25 @@ fun ZipFile.checkCompilerVersion(version: String) = checkZipEntry("META-INF/comp
|
|||||||
.takeIf { artifactVersion != version }
|
.takeIf { artifactVersion != version }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ZipFile.checkZipEntry(entryName: String, action: (entryStream: InputStream) -> String?): String? =
|
fun ZipFile.checkPluginXmlVersion(version: String) = checkZipEntry("META-INF/plugin.xml") { inputStream ->
|
||||||
getEntry(entryName)?.let { entry -> getInputStream(entry).use(action) }
|
val pluginVersion = inputStream.bufferedReader()
|
||||||
|
.lineSequence()
|
||||||
|
.mapNotNull { Regex("""<version>([^<]+)</version>""").find(it) }
|
||||||
|
.firstOrNull()
|
||||||
|
?.groupValues
|
||||||
|
?.get(1) ?: return@checkZipEntry "Plugin version not found in plugin.xml"
|
||||||
|
|
||||||
|
"Invalid plugin version, expected version starting with '$version', actual: '$pluginVersion'"
|
||||||
|
.takeIf { !pluginVersion.startsWith(version) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ZipFile.checkZipEntry(entryName: String, action: (entryStream: InputStream) -> String?) {
|
||||||
|
getEntry(entryName)
|
||||||
|
?.let { entry -> getInputStream(entry).use(action) }
|
||||||
|
?.let { reportProblem(testName(), it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ZipFile.testName() = file(name).relativeTo(file(rootDir)).invariantSeparatorsPath
|
||||||
|
|
||||||
fun reportProblem(artifact: String, message: String) {
|
fun reportProblem(artifact: String, message: String) {
|
||||||
if (isTeamcityBuild)
|
if (isTeamcityBuild)
|
||||||
|
|||||||
Reference in New Issue
Block a user