From 8ed63d1c1853248a1e3fa02a0760c65040e093ce Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Wed, 24 Oct 2018 01:18:17 +0300 Subject: [PATCH] CLion: Patch some xml's of Java plugin to make it work more stable To get rid of exceptions while startup and indexing --- prepare/clion-plugin/build.gradle.kts | 40 ++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/prepare/clion-plugin/build.gradle.kts b/prepare/clion-plugin/build.gradle.kts index 8e86c42128c..0469e68818d 100644 --- a/prepare/clion-plugin/build.gradle.kts +++ b/prepare/clion-plugin/build.gradle.kts @@ -1,6 +1,6 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jk1.tcdeps.KotlinScriptDslAdapter.teamcityServer import com.github.jk1.tcdeps.KotlinScriptDslAdapter.tc +import java.util.regex.Pattern apply { plugin("kotlin") @@ -29,6 +29,9 @@ val cidrPlugin by configurations.creating val platformDepsZip by configurations.creating val pluginXmlPath = "META-INF/plugin.xml" +val javaPsiXmlPath = "META-INF/JavaPsiPlugin.xml" +val javaPluginXmlPath = "META-INF/JavaPlugin.xml" + val platformDepsJarName = "kotlinNative-platformDeps.jar" val pluginXmlLocation = File(buildDir, "pluginXml") @@ -93,11 +96,46 @@ val jar = runtimeJar { from(pluginXmlLocation) { include(pluginXmlPath) } } +fun Zip.includePatched(fileToMarkers: Map>) { + + val notDone = mutableSetOf>() + fileToMarkers.forEach { (path, markers) -> + for (marker in markers) { + notDone += path to marker + } + } + + eachFile { + val markers = fileToMarkers[this.sourcePath] ?: return@eachFile + this.filter { + var data = it + for (marker in markers) { + val newData = data.replace(("^(.*" + Pattern.quote(marker) + ".*)$").toRegex(), "") + data = newData + notDone -= path to marker + } + data + } + } + doLast { + check(notDone.size == 0) { + "Filtering failed for: " + + notDone.joinToString(separator = "\n") { (file, marker) -> "file=$file, marker=`$marker`" } + } + } +} + val platformDepsJar by task { archiveName = platformDepsJarName val platformDepsJar = zipTree(platformDepsZip.singleFile).matching { include("**/$platformDepsJarName") }.singleFile from(zipTree(platformDepsJar)) { exclude(pluginXmlPath) + includePatched( + mapOf( + javaPsiXmlPath to listOf("implementation=\"org.jetbrains.uast.java.JavaUastLanguagePlugin\""), + javaPluginXmlPath to listOf("implementation=\"com.intellij.spi.SPIFileTypeFactory\"") + ) + ) } }