forked from dkandalov/live-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
226 lines (206 loc) · 8.5 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
buildscript {
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "http://dl.bintray.com/jetbrains/intellij-plugin-service" }
}
dependencies {
classpath("org.jetbrains.intellij.plugins:gradle-intellij-plugin:0.5.0-SNAPSHOT")
}
}
plugins {
id "nebula.dependency-lock" version "5.0.2"
id "org.jetbrains.intellij" version "0.4.9"
id "org.jetbrains.kotlin.jvm" version "1.3.20"
}
apply plugin:"java"
apply plugin:"groovy"
apply plugin:"idea"
apply plugin:"org.jetbrains.intellij"
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
ivy {
layout "pattern"
artifactPattern "http://raw.githubusercontent.com/dkandalov/kotlin-compiler-wrapper/master/jars/[organisation]-[artifact]-[revision](-[classifier])(.[ext])"
}
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
apiVersion = "1.3"
languageVersion = "1.3"
}
}
ext.kotlinVersion = "1.3.20"
intellij {
// (to find available IDE versions see https://www.jetbrains.com/intellij-repository/releases)
def ideVersion = System.getenv().getOrDefault("LIVEPLUGIN_IDEA_VERSION",
"191.6183.87" // Because of "import kotlin.script.experimental.*" classes
// "LATEST-EAP-SNAPSHOT"
)
println("Using ide version: ${ideVersion}")
version ideVersion
// The artifact name is deliberately not "live-plugin" because plugins are stored in the "live-plugins" directory.
// The "LivePlugin" directory is deleted on each plugin update so it's good make it distinct from "live-plugins".
pluginName = "LivePlugin"
downloadSources = true
sameSinceUntilBuild = false
updateSinceUntilBuild = false
plugins = ["Groovy", "Kotlin", "git4idea", "github", "junit"]
}
dependencyLock {
lockFile = "../dependencyLock.json"
configurationNames = ["runtime"]
includeTransitives = true
}
dependencies {
// Bundle kotlin compiler and stdlib with LivePlugin because they are not bundled with IDEs
// and because kotlin jars in IDE are likely to be updated, potentially breaking liveplugins,
// so it should be more reliable to have a particular version of kotlin jars inside LivePlugin.
runtime group: "org.jetbrains.kotlin", name: "kotlin-compiler-embeddable", version: kotlinVersion
runtime group: "org.jetbrains.kotlin", name: "kotlin-stdlib", version: kotlinVersion
runtime group: "org.jetbrains.kotlin", name: "kotlin-reflect", version: kotlinVersion
runtime group: "live-plugin", name: "kotlin-compiler-wrapper", version: "0.1.2"
testCompile group: "junit", name: "junit", version: "4.12" // includes hamcrest-core
}
"Move kotlin compiler jars from plugin classpath into a separate folder so that there are no conflicts between kotlin and intellij classes"()
"Add source files to compiler output so that LivePlugin source code is available for navigation at runtime"()
'Move GDSL file into standardDsls folder'()
sourceSets {
// Keep groovy and kotlin util source code in separate source sets, otherwise
// compilation fails because of inter-dependencies between kotlin and groovy files which confuse compiler,
// even though overall dependencies are unidirectional:
// pluginUtilKotlin -> pluginUtilGroovy -> main
main {
java { srcDir "src/main" }
resources { srcDir "resources" }
resources { srcDir "plugin-examples" }
}
pluginUtilGroovy {
groovy { srcDir "src/plugin-util-groovy" }
compileClasspath = main.output + configurations.compileClasspath + configurations.pluginUtilGroovyCompileClasspath
}
pluginUtilKotlin {
kotlin { srcDir "src/plugin-util-kotlin" }
compileClasspath = main.output + pluginUtilGroovy.output + configurations.compileClasspath + configurations.pluginUtilKotlinCompileClasspath
}
test {
groovy { srcDir "src/test" }
compileClasspath = main.output + pluginUtilGroovy.output + configurations.testCompileClasspath + configurations.pluginUtilGroovyCompileClasspath
runtimeClasspath = test.output + main.output + pluginUtilGroovy.output +
configurations.testRuntimeClasspath + configurations.pluginUtilGroovyRuntimeClasspath
}
}
jar {
from sourceSets.pluginUtilGroovy.output, sourceSets.pluginUtilKotlin.output
}
task validateLivePluginZip() { doLast {
def pluginZip = zipTree("build/distributions/LivePlugin.zip")
def pluginZipFiles = pluginZip.files.collect { it.path.replaceFirst(".*/LivePlugin.zip.*?/", "") }
def kotlinCompilerAndItsTransitiveDependencies = [
"LivePlugin/kotlin-compiler/kotlin-compiler-wrapper.jar",
"LivePlugin/kotlin-compiler/kotlin-compiler-embeddable.jar",
"LivePlugin/kotlin-compiler/kotlin-reflect.jar",
"LivePlugin/kotlin-compiler/kotlin-stdlib.jar",
"LivePlugin/kotlin-compiler/kotlin-stdlib-common.jar",
"LivePlugin/kotlin-compiler/kotlin-script-runtime.jar",
"LivePlugin/kotlin-compiler/trove4j.jar",
]
def expectedLivePluginJars = [
"LivePlugin/lib/LivePlugin.jar",
"LivePlugin/lib/annotations-13.0.jar",
"LivePlugin/lib/searchableOptions.jar",
"LivePlugin/lib/standardDsls/livePluginCompletions.gdsl",
]
expectToBeEqual(pluginZipFiles.toSet(), (expectedLivePluginJars + kotlinCompilerAndItsTransitiveDependencies).toSet())
def livePluginJar = zipTree(pluginZip.files.find { it.name == "LivePlugin.jar" })
def livePluginJarFiles = livePluginJar.files.collect{ it.path.replaceFirst(".*/LivePlugin.jar.*?/", "") }.toSet()
expectToContain(livePluginJarFiles, [
"liveplugin/LivePluginAppComponent.class",
"liveplugin/PluginUtil.class",
"liveplugin/PluginUtil.groovy",
"liveplugin/Plugin_utilKt.class",
"liveplugin/plugin-util.kt",
"groovy/default-plugin.groovy",
"kotlin/default-plugin.kts",
"META-INF/plugin.xml",
].toSet())
} }
build.finalizedBy(saveLock)
build.finalizedBy(validateLivePluginZip)
def expectToContain(Set actual, Set expected) {
if (!actual.containsAll(expected)) {
throw new GradleException(
"Didn't contain expected:\n" +
(expected - actual).join("\n") + "\n"
)
}
}
def expectToBeEqual(Set actual, Set expected) {
if (actual != expected) {
throw new GradleException(
"Expected:\n" +
expected.join("\n") + "\n" +
"but was:\n" +
actual.join("\n")
)
}
}
task installLivePlugin() { doLast {
def version = new File("resources/META-INF/plugin.xml").readLines()
.find { it.contains("<version>") }
.replaceFirst(".*<version>", "")
.replaceFirst("</version>.*", "")
def localMavenPath = repositories.mavenLocal().url.path + "/liveplugin/live-plugin/"
def toFile = "${localMavenPath}/${version}/live-plugin-${version}.jar"
ant.copy(
file: "LivePlugin.jar",
toFile: toFile
)
println("Installed to local maven liveplugin version " + version)
println("Path: ${toFile}")
} }
task runIdeWithDifferentJvm(type: org.jetbrains.intellij.tasks.RunIdeTask) {
jbrVersion "jbrex8u152b1024.10"
}
def "Add source files to compiler output so that LivePlugin source code is available for navigation at runtime"() {
compileJava.doLast {
def classesFolder = project.tasks.findByName(JavaPlugin.COMPILE_JAVA_TASK_NAME).destinationDir
ant.copy(toDir: classesFolder.absolutePath, overwrite: true) {
ant.fileset(dir: "./src/plugin-util-groovy", includes: "**/*")
ant.fileset(dir: "./src/plugin-util-kotlin", includes: "**/*")
ant.fileset(dir: "./src/main", includes: "**/KotlinScriptTemplate.kt")
}
}
}
def "Move kotlin compiler jars from plugin classpath into a separate folder so that there are no conflicts between kotlin and intellij classes"() {
// Remove kotlin version from jars zipped with plugin so that when they are updated, 'LivePlugin' module dependencies are still correct.
def filesToMove = [
["kotlin-compiler-wrapper-0.1.2.jar", "kotlin-compiler-wrapper.jar"],
["kotlin-compiler-embeddable-${kotlinVersion}.jar", "kotlin-compiler-embeddable.jar"],
["kotlin-reflect-${kotlinVersion}.jar", "kotlin-reflect.jar"],
["kotlin-stdlib-${kotlinVersion}.jar", "kotlin-stdlib.jar"],
["kotlin-stdlib-common-${kotlinVersion}.jar", "kotlin-stdlib-common.jar"],
["kotlin-script-runtime-${kotlinVersion}.jar", "kotlin-script-runtime.jar"],
["trove4j-1.0.20181211.jar", "trove4j.jar"]
]
prepareSandbox.doLast {
filesToMove.each {
ant.move(
file: "build/idea-sandbox/plugins/LivePlugin/lib/${it[0]}",
tofile: "build/idea-sandbox/plugins/LivePlugin/kotlin-compiler/${it[1]}"
)
}
}
}
def 'Move GDSL file into standardDsls folder'() {
prepareSandbox.doLast {
def resourcesFolder = project.tasks.findByName(JavaPlugin.PROCESS_RESOURCES_TASK_NAME).destinationDir
ant.move(
file: resourcesFolder.absolutePath + "/liveplugin/livePluginCompletions.gdsl",
tofile: "build/idea-sandbox/plugins/LivePlugin/lib/standardDsls/livePluginCompletions.gdsl"
)
}
}