Files
kotlin-fork/prepare/cidr-plugin/build.gradle.kts
T
2018-05-11 13:28:22 +02:00

70 lines
2.1 KiB
Kotlin

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(
"""<!-- CIDR-PLUGIN-PLACEHOLDER-START -->(.*)<!-- CIDR-PLUGIN-PLACEHOLDER-END -->""",
RegexOption.DOT_MATCHES_ALL)
val excludeRegex = Regex(
"""<!-- CIDR-PLUGIN-EXCLUDE-START -->(.*?)<!-- CIDR-PLUGIN-EXCLUDE-END -->""",
RegexOption.DOT_MATCHES_ALL)
val versionRegex = Regex("""<version>([^<]+)</version>""")
zipTree(inputs.files.singleFile)
.matching { include(pluginXmlPath) }
.singleFile
.readText()
.replace(placeholderRegex, "<depends>com.intellij.modules.cidr.lang</depends>")
.replace(excludeRegex, "")
.replace(versionRegex, "<version>$pluginFullVersionNumber</version>")
.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<Copy>("cidrPlugin") {
into(cidrPluginDir)
from(ideaPluginDir) { exclude("lib/kotlin-plugin.jar") }
from(jar) { into("lib") }
}