Add infrastructure and helpers for using intellij plugin, convert first project
This commit is contained in:
committed by
Vyacheslav Gerasimov
parent
a0d0bc074b
commit
743f599262
@@ -104,6 +104,7 @@ extra["JDK_17"] = jdkPath("1.7")
|
||||
extra["JDK_18"] = jdkPath("1.8")
|
||||
extra["JDK_9"] = jdkPathIfFound("9")
|
||||
|
||||
extra["versions.intellij"] = "IC-172.4343.14"
|
||||
extra["versions.protobuf-java"] = "2.6.1"
|
||||
extra["versions.javax.inject"] = "1"
|
||||
extra["versions.jsr305"] = "1.3.9"
|
||||
@@ -117,6 +118,21 @@ extra["versions.android"] = "2.3.1"
|
||||
extra["ideaCoreSdkJars"] = arrayOf("annotations", "asm-all", "guava", "intellij-core", "jdom", "jna", "log4j", "picocontainer",
|
||||
"snappy-in-java", "streamex", "trove4j", "xpp3-1.1.4-min", "xstream")
|
||||
|
||||
// the former "ideaSdk/core" dir contents without intellij-core.jar
|
||||
extra["ideaSdkIntellijCoreDependencies"] =
|
||||
listOf("annotations.jar",
|
||||
"asm-all.jar",
|
||||
"guava-*.jar",
|
||||
"jdom.jar",
|
||||
"jna.jar",
|
||||
"log4j.jar",
|
||||
"picocontainer.jar",
|
||||
"snappy-in-java-*.jar",
|
||||
"streamex-*.jar",
|
||||
"trove4j.jar",
|
||||
"xpp3-1.1.4-min.jar",
|
||||
"xstream-*.jar")
|
||||
|
||||
extra["compilerModules"] = arrayOf(
|
||||
":compiler:util",
|
||||
":compiler:container",
|
||||
|
||||
@@ -3,6 +3,7 @@ buildscript {
|
||||
val buildSrcKotlinVersion: String by extra(findProperty("buildSrc.kotlin.version")?.toString() ?: embeddedKotlinVersion)
|
||||
val buildSrcKotlinRepo: String? by extra(findProperty("buildSrc.kotlin.repo") as String?)
|
||||
extra["versions.shadow"] = "2.0.1"
|
||||
extra["versions.intellij-plugin"] = "0.3.0-SNAPSHOT"
|
||||
|
||||
repositories {
|
||||
buildSrcKotlinRepo?.let {
|
||||
@@ -34,7 +35,8 @@ repositories {
|
||||
maven(url = it)
|
||||
}
|
||||
maven(url = "https://dl.bintray.com/kotlin/kotlin-dev") // for dex-method-list
|
||||
// maven { setUrl("https://repo.gradle.org/gradle/libs-releases-local") }
|
||||
maven(url = "https://oss.sonatype.org/content/repositories/snapshots/") // for intellij plugin
|
||||
maven(url = "http://dl.bintray.com/jetbrains/intellij-plugin-service") // for intellij plugin
|
||||
jcenter()
|
||||
}
|
||||
|
||||
@@ -46,6 +48,7 @@ dependencies {
|
||||
// compile("org.jetbrains.kotlin:kotlin-gradle-plugin:${rootProject.extra["bootstrap_kotlin_version"]}")
|
||||
compile("com.github.jengelman.gradle.plugins:shadow:${property("versions.shadow")}")
|
||||
compile("org.ow2.asm:asm-all:6.0_BETA")
|
||||
compile("org.jetbrains.intellij.plugins:gradle-intellij-plugin:${property("versions.intellij-plugin")}")
|
||||
}
|
||||
|
||||
samWithReceiver {
|
||||
|
||||
@@ -80,7 +80,7 @@ fun DependencyHandler.protobufFull(): ProjectDependency =
|
||||
project(protobufLiteProject, configuration = "relocated").apply { isTransitive = false }
|
||||
val protobufFullTask = "$protobufLiteProject:prepare-relocated-protobuf"
|
||||
|
||||
private fun File.matchMaybeVersionedArtifact(baseName: String) = name.matches(baseName.toMaybeVersionedJarRegex())
|
||||
fun File.matchMaybeVersionedArtifact(baseName: String) = name.matches(baseName.toMaybeVersionedJarRegex())
|
||||
|
||||
private val wildcardsRe = """[^*?]+|(\*)|(\?)""".toRegex()
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
@file:Suppress("unused") // usages in build scripts are not tracked properly
|
||||
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.file.ConfigurableFileCollection
|
||||
import org.gradle.api.file.FileTree
|
||||
import org.gradle.api.tasks.util.PatternFilterable
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.extra
|
||||
import org.gradle.kotlin.dsl.the
|
||||
import org.jetbrains.intellij.IntelliJPluginExtension
|
||||
import org.jetbrains.intellij.dependency.PluginDependency
|
||||
|
||||
fun Project.configureIntellijPlugin(body: (IntelliJPluginExtension.() -> Unit) = {}) {
|
||||
|
||||
plugins.apply("org.jetbrains.intellij")
|
||||
|
||||
configure<IntelliJPluginExtension> {
|
||||
version = rootProject.extra["versions.intellij"] as String
|
||||
instrumentCode = false
|
||||
configureDefaultDependencies = false
|
||||
body()
|
||||
}
|
||||
|
||||
val intellijTasks = listOf("patchPluginXml", "prepareSandbox", "prepareTestingSandbox",
|
||||
"verifyPlugin", "runIde", "buildPlugin", "publishPlugin")
|
||||
intellijTasks.forEach {
|
||||
tasks.findByName(it)?.also { it.onlyIf { false }; tasks.remove(it) }
|
||||
?: logger.warn("intellij task $it not found")
|
||||
}
|
||||
configurations.findByName("archives")?.artifacts?.clear()
|
||||
}
|
||||
|
||||
// reimplementation of helpers from intellij plugin, since it is not convenient to use gradle closures from kotlin build scripts
|
||||
|
||||
fun Project.intellij(filter: (PatternFilterable.() -> Unit) = {}): FileTree {
|
||||
val jars = the<IntelliJPluginExtension>().ideaDependency?.jarFiles?.takeIf { it.isNotEmpty() }
|
||||
?: throw GradleException("intellij is not (yet) configured. Please note that you should configure intellij dependencies in the afterEvaluate block")
|
||||
return files(jars).asFileTree.matching {
|
||||
exclude("**/kotlin-*.jar")
|
||||
}.matching(filter)
|
||||
}
|
||||
|
||||
fun Project.intellijPlugins(vararg pluginNames: String): ConfigurableFileCollection {
|
||||
val selectedPlugins = arrayListOf<PluginDependency>()
|
||||
val invalidPlugins = arrayListOf<String>()
|
||||
for (pluginName in pluginNames) {
|
||||
val plugin = the<IntelliJPluginExtension>().pluginDependencies.find { it.id == pluginName }
|
||||
if (plugin == null || plugin.jarFiles.isEmpty()) {
|
||||
invalidPlugins.add(pluginName)
|
||||
}
|
||||
else {
|
||||
selectedPlugins.add(plugin)
|
||||
}
|
||||
}
|
||||
if (invalidPlugins.isNotEmpty()) {
|
||||
throw GradleException("intellij plugins $invalidPlugins are not (yet) configured or not found. Please note that you should specify plugins in the intellij.plugins property and configure dependencies to them in the afterEvaluate block")
|
||||
}
|
||||
return project.files(selectedPlugins.map { it.jarFiles })
|
||||
}
|
||||
|
||||
fun Project.intellijPlugin(pluginName: String, filter: (PatternFilterable.() -> Unit) = {}): FileTree {
|
||||
val pluginDep = the<IntelliJPluginExtension>().pluginDependencies.find { it.id == pluginName }?.takeIf { it.jarFiles.isNotEmpty() }
|
||||
?: throw GradleException("intellij plugin '$pluginName' is not (yet) configured or not found. Please note that you should specify plugins in the intellij.plugins property and configure dependencies to them in the afterEvaluate block")
|
||||
return project.files(pluginDep.jarFiles).asFileTree.matching(filter)
|
||||
}
|
||||
|
||||
fun Project.intellijExtra(extraName: String, filter: (PatternFilterable.() -> Unit) = {}): FileTree {
|
||||
val extraDep = the<IntelliJPluginExtension>().ideaDependency?.extraDependencies?.find { it.name == extraName }?.takeIf { it.jarFiles.isNotEmpty() }
|
||||
?: throw GradleException("intellij extra artifact '$extraName' is not (yet) configured or not found. Please note that you should specify extra dependencies in the intellij.extraDependencies property and configure dependencies to them in the afterEvaluate block")
|
||||
return project.files(extraDep.jarFiles).asFileTree.matching(filter)
|
||||
}
|
||||
|
||||
// frequent combinations
|
||||
|
||||
fun Project.intellijCoreJar() = intellijExtra("intellij-core") { include("intellij-core.jar") }
|
||||
fun Project.intellijCoreJarDependencies(filter: (PatternFilterable.() -> Unit) = {}): FileTree =
|
||||
intellij {
|
||||
include(rootProject.extra["IntellijCoreDependencies"] as List<String>)
|
||||
}
|
||||
.matching(filter)
|
||||
@@ -3,10 +3,21 @@ apply { plugin("kotlin") }
|
||||
|
||||
jvmTarget = "1.6"
|
||||
|
||||
configureIntellijPlugin {
|
||||
setExtraDependencies("intellij-core", "jps-standalone")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile(projectDist(":kotlin-stdlib"))
|
||||
compile(project(":core:deserialization"))
|
||||
compile(ideaSdkCoreDeps(*(rootProject.extra["ideaCoreSdkJars"] as Array<String>)))
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
dependencies {
|
||||
compile(intellijCoreJar())
|
||||
compile(intellijCoreJarDependencies())
|
||||
compile(intellijExtra("jps-standalone") { include("jps-model.jar") })
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
@@ -3002,6 +3002,8 @@
|
||||
"compileClasspath",
|
||||
"compileOnly",
|
||||
"default",
|
||||
"idea",
|
||||
"ideaPlugins",
|
||||
"implementation",
|
||||
"kapt",
|
||||
"kaptTest",
|
||||
@@ -3022,7 +3024,8 @@
|
||||
"kotlin": "org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension",
|
||||
"kapt": "org.jetbrains.kotlin.gradle.plugin.KaptExtension",
|
||||
"defaultArtifacts": "org.gradle.api.internal.plugins.DefaultArtifactPublicationSet",
|
||||
"reporting": "org.gradle.api.reporting.ReportingExtension"
|
||||
"reporting": "org.gradle.api.reporting.ReportingExtension",
|
||||
"intellij": "org.jetbrains.intellij.IntelliJPluginExtension"
|
||||
}
|
||||
},
|
||||
":core:builtins": {
|
||||
|
||||
Reference in New Issue
Block a user