From d33b3cd4eeefe96166ca7d786237212511c15eb2 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gerasimov Date: Thu, 22 Mar 2018 23:37:24 +0300 Subject: [PATCH] Build: Add :prepare:cidr-plugin project --- .idea/dictionaries/4u7.xml | 1 + build.gradle.kts | 2 + buildSrc/src/main/kotlin/CommonUtil.kt | 7 ++- prepare/cidr-plugin/build.gradle.kts | 64 ++++++++++++++++++++++++++ settings.gradle | 1 + 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 prepare/cidr-plugin/build.gradle.kts diff --git a/.idea/dictionaries/4u7.xml b/.idea/dictionaries/4u7.xml index 57de8025848..90f35a2b9cb 100644 --- a/.idea/dictionaries/4u7.xml +++ b/.idea/dictionaries/4u7.xml @@ -1,6 +1,7 @@ + cidr foldable diff --git a/build.gradle.kts b/build.gradle.kts index d26b2b3df62..f18dfb25422 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -94,6 +94,7 @@ val ideaSandboxDir = "$commonLocalDataDir/ideaSandbox" val ideaUltimateSandboxDir = "$commonLocalDataDir/ideaUltimateSandbox" val ideaPluginDir = "$distDir/artifacts/ideaPlugin/Kotlin" val ideaUltimatePluginDir = "$distDir/artifacts/ideaUltimatePlugin/Kotlin" +val cidrPluginDir = "$distDir/artifacts/cidrPlugin/Kotlin" // TODO: use "by extra()" syntax where possible extra["distLibDir"] = project.file(distLibDir) @@ -103,6 +104,7 @@ extra["ideaSandboxDir"] = project.file(ideaSandboxDir) extra["ideaUltimateSandboxDir"] = project.file(ideaUltimateSandboxDir) extra["ideaPluginDir"] = project.file(ideaPluginDir) extra["ideaUltimatePluginDir"] = project.file(ideaUltimatePluginDir) +extra["cidrPluginDir"] = project.file(cidrPluginDir) extra["isSonatypeRelease"] = false Properties().apply { diff --git a/buildSrc/src/main/kotlin/CommonUtil.kt b/buildSrc/src/main/kotlin/CommonUtil.kt index 033a7dfa659..2ed392d7ced 100644 --- a/buildSrc/src/main/kotlin/CommonUtil.kt +++ b/buildSrc/src/main/kotlin/CommonUtil.kt @@ -3,8 +3,8 @@ import groovy.lang.Closure import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.file.CopySourceSpec import org.gradle.api.file.SourceDirectorySet -import org.gradle.api.internal.AbstractTask import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.tasks.JavaExec import org.gradle.api.tasks.SourceSetOutput @@ -13,6 +13,7 @@ import org.gradle.kotlin.dsl.extra import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.the import java.io.File +import java.util.concurrent.Callable inline fun Project.task(noinline configuration: T.() -> Unit) = tasks.creating(T::class, configuration) @@ -61,4 +62,6 @@ fun Project.getBooleanProperty(name: String): Boolean? = this.findProperty(name) val v = it.toString() if (v.isBlank()) true else v.toBoolean() -} \ No newline at end of file +} + +inline fun CopySourceSpec.from(crossinline filesProvider: () -> Any?): CopySourceSpec = from(Callable { filesProvider() }) diff --git a/prepare/cidr-plugin/build.gradle.kts b/prepare/cidr-plugin/build.gradle.kts new file mode 100644 index 00000000000..edb47e2bdde --- /dev/null +++ b/prepare/cidr-plugin/build.gradle.kts @@ -0,0 +1,64 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import groovy.lang.Closure +import java.io.FilterReader + +description = "Kotlin AppCode & CLion plugin" + +apply { + plugin("kotlin") +} + +val ideaPluginDir: File by rootProject.extra +val cidrPluginDir: File by rootProject.extra + +val kotlinPlugin by configurations.creating + +val pluginXmlPath = "META-INF/plugin.xml" + +dependencies { + kotlinPlugin(project(":prepare:idea-plugin", configuration = "runtimeJar")) +} + +val pluginXml by tasks.creating { + val kotlinVersion: String by rootProject.extra + val pluginFullVersionNumber = findProperty("pluginVersion") as? String + ?: "$kotlinVersion-CIDR" + + inputs.property("pluginFullVersionNumber", pluginFullVersionNumber) + inputs.files(kotlinPlugin) + outputs.files(File(buildDir, name, pluginXmlPath)) + + doFirst { + val placeholderRegex = Regex( + """(.*)""", + RegexOption.DOT_MATCHES_ALL) + val versionRegex = Regex("""([^<]+)""") + + zipTree(inputs.files.singleFile) + .matching { include(pluginXmlPath) } + .singleFile + .readText() + .replace(placeholderRegex, "") + .replace(versionRegex, "$pluginFullVersionNumber") + .also { pluginXmlText -> + outputs.files.singleFile.writeText(pluginXmlText) + } + } +} + +val jar = runtimeJar { + archiveName = "kotlin-plugin.jar" + dependsOn(kotlinPlugin) + from { + zipTree(kotlinPlugin.singleFile).matching { + exclude(pluginXmlPath) + } + } + from(pluginXml) { into("META-INF") } +} + +task("cidrPlugin") { + into(cidrPluginDir) + from(ideaPluginDir) { exclude("lib/kotlin-plugin.jar") } + from(jar) { into("lib") } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index e945140bb1f..18b575a9d86 100644 --- a/settings.gradle +++ b/settings.gradle @@ -118,6 +118,7 @@ include ":kotlin-build-common", ":prepare:formatter", ":prepare:ide-lazy-resolver", ":prepare:idea-plugin", + ":prepare:cidr-plugin", ":android-lint", ":kotlin-compiler", ":kotlin-compiler-embeddable",