forked from HaxeFoundation/intellij-haxe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
490 lines (398 loc) · 17.8 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
/*
* Copyright 2018-2018 m0rkeulv
* Copyright 2019-2020 Eric Bishton
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id 'de.undercouch.download' version '3.3.0'
id 'org.jetbrains.intellij' version '0.4.9'
}
if (!project.hasProperty('targetVersion')) {
ext.ideaVersion = "${defaultIdeaVersion}"
println '-------------------------------------------------------'
println "No target version selected, using default ($ext.ideaVersion)"
println 'to specify build target use -PtargetVersion=<version>'
println 'Ex:'
println 'gradlew buildPlugin -PtargetVersion=2017.2.2'
println 'If you\'re running "gradle clean," just ignore this warning.'
println '-------------------------------------------------------'
} else {
ext.ideaVersion = project.property('targetVersion')
}
println "Target set to IDEA ${ideaVersion}"
String[] versionInfo = "${ideaVersion}".split("\\.")
boolean requiresJavaPlugin = versionInfo.size() >= 2 && (versionInfo[0].toInteger() > 2019 || (versionInfo[0].toInteger() == 2019 && versionInfo[1].toInteger() >= 2))
boolean requiresFlexPlugin = versionInfo.size() >= 2 && (versionInfo[0].toInteger() > 2020 || (versionInfo[0].toInteger() == 2020 && versionInfo[1].toInteger() >=2 ))
allprojects {
repositories { mavenCentral() }
ext {
// modules
haxeCommonDir = "${rootDir}/common"
haxePluginDir = "${rootDir}"
// generated sources
generatedSrcDir = "${haxePluginDir}/gen/"
// dependencies
dependenciesDir = "${rootDir}/dependencies"
downloadsDir = "${dependenciesDir}/downloads"
toolDir = "${dependenciesDir}/tools"
ideaBaseDir = "${rootDir}/idea-IU"
ideaTargetDir = "${ideaBaseDir}/ideaIU-${ideaVersion}"
//Note: path is system directory separator sensitive, file.absolutePath solves this for us
grammarHaxe = file("${haxePluginDir}/grammar/haxe.bnf").absolutePath
grammarHxml = file("${haxePluginDir}/grammar/hxml.bnf").absolutePath
grammarMetadata = file("${haxePluginDir}/grammar/metadata.bnf").absolutePath
flexDownloadFile = "idea-flex-${ideaVersion}.skeleton"
flexTargetFile = "idea-flex.skeleton"
grammarKitDownloadFile = "GrammarKit-${grammarKitVersion}.zip"
grammarKitTargetFile = "grammar-kit.jar"
psiDownloadFile = "light-psi-all-${grammarKitVersion}.jar"
psiTargetFile = "light-psi-all.jar"
}
apply plugin: 'idea'
apply plugin: 'org.jetbrains.intellij'
apply from: "${haxePluginDir}/template.gradle"
apply from: "${haxePluginDir}/testSettings.gradle"
intellij {
type = 'IU'
version = "IU-${ideaVersion}"
pluginName = "intellij-haxe-${ideaVersion}"
ideaDependencyCachePath "${ideaBaseDir}"
// Specify the sandbox so that Gradle doesn't try to make it relative to each sub-project.
sandboxDirectory "${project.rootDir}/build/idea-sandbox"
// Don't let gradle fill in since/until, we fill them via patchCustomTags using the properties file.
updateSinceUntilBuild false
// Include the "java" built-in plugin for 2019.2 and later builds.
if (requiresJavaPlugin) {
System.println("Including java plugin for version >= 2019.2")
plugins += 'java' // 2019.2 + only. Causes build errors on earlier versions.
}
// Flex support was unbundled for version 2020.2.
if (requiresFlexPlugin) {
System.println("Including Flex plugin for version >= 2020.2")
plugins += 'com.intellij.flex:202.6397.59'
}
}
}
//Download build tools
apply from: 'dependencies/tools.gradle'
build.dependsOn('setupTools')
test.dependsOn('setupTools')
if (!file("$generatedSrcDir").exists()) file("$generatedSrcDir").mkdirs()
// Sources that contain templates to be generated.
sourceSets {
templates {
}
}
sourceSets.templates.resources.srcDir 'src/common'
sourceSets.main.java.srcDirs = ['src/common', 'src/icons', 'gen']
sourceSets.main.resources.srcDir 'resources'
sourceSets.test.java.srcDir 'testSrc'
sourceSets.test.resources.srcDir 'testData'
idea.module { generatedSourceDirs += file('gen') }
dependencies {
compile files('gen') {
builtBy 'generateSources'
}
compile project(':common')
compile project(':jps-plugin')
compile project(':hxcpp-debugger-protocol')
String flexPluginDir = "${ideaTargetDir}"
if (requiresFlexPlugin) {
flexPluginDir += "/config"
}
String flexShared = flexPluginDir + "/plugins/flex/lib/flex-shared.jar"
String flexSupport = flexPluginDir + "/plugins/flex/lib/FlexSupport.jar"
compileOnly files(flexShared)
compileOnly files(flexSupport)
compileOnly files("${ideaTargetDir}/lib/openapi.jar")
compileOnly files("${ideaTargetDir}/lib/util.jar")
testCompileOnly project(':jps-plugin')
testCompileOnly project(':common')
testCompileOnly project(':hxcpp-debugger-protocol')
testCompileOnly files(flexShared)
testCompileOnly files(flexSupport)
testCompileOnly files("${ideaTargetDir}/lib/ openapi.jar")
testCompileOnly files("${ideaTargetDir}/lib/util.jar")
}
afterEvaluate {
dependencies {
if (requiresJavaPlugin) {
compile intellijPlugin('java') { include("${ideaTargetDir}/plugins/java/lib/jps-builders.jar") }
}
}
}
runIde {
jbrVersion '8u152b1343.26'
/* Propagate VM options from gradle command line through to the plugin. */
systemProperties = System.getProperties()
}
compileJava {
dependsOn 'generateSources'
}
processResources {
from('src/common') {
includeEmptyDirs = false
include '**/*.properties'
// include 'META-INF/*.xml'
}
}
processResources {
from('src') {
include 'META-INF/pluginIcon.svg'
include 'META-INF/pluginIcon_dark.svg'
}
}
patchPluginXml {
pluginXmlFiles = [
'src/META-INF/plugin.xml',
'src/META-INF/debugger-support.xml',
'src/META-INF/flex-debugger-support.xml'
]
}
patchPluginXml.finalizedBy('patchCustomTags')
task patchCustomTags() {
doFirst {
file(patchPluginXml.destinationDir.toString() + '/plugin.xml')
.renameTo(patchPluginXml.destinationDir.toString() + '/plugin.xml.partial')
}
doLast {
copy {
def props = findSdkValuesAndProperties(file("${ideaTargetDir}/build.txt"))
from(patchPluginXml.destinationDir.toString() + '/plugin.xml.partial')
filter(ReplaceTokens, tokens: props)
into patchPluginXml.destinationDir.toString()
rename('plugin.xml.partial', 'plugin.xml')
}
}
doLast {
delete file(patchPluginXml.destinationDir.toString() + '/plugin.xml.partial')
}
}
jar {
baseName = "intellij-haxe"
include('**/*').includeEmptyDirs(false)
// include submodules
from(project(':jps-plugin').sourceSets.main.output).include('**/*').includeEmptyDirs(false)
from(project(':common').sourceSets.main.output).include('**/*').includeEmptyDirs(false)
from(project(':hxcpp-debugger-protocol').sourceSets.main.output).include('**/*').includeEmptyDirs(false)
from(zipTree("${ideaTargetDir}/lib/forms_rt.jar")).include('com/intellij/uiDesigner/core/*.class')
}
jar.finalizedBy('copyJar')
task copyJar() {
doLast {
def props = findSdkValuesAndProperties(file("${ideaTargetDir}/build.txt"))
def jarName = "intellij-haxe-" + props.getProperty("idea.version") + ".jar"
copy {
from("${haxePluginDir}/build/libs/").include(jar.archiveName)
into("${rootDir}/")
rename({jarName})
}
}
}
test {
useJUnit()
allJvmArgs = [
"-Didea.home.path=${ideaTargetDir}",
"-Xbootclasspath/a:${ideaTargetDir}/lib/boot.jar",
"-Dfile.encoding=UTF-8",
"-ea",
"-Didea.launcher.bin.path=${ideaTargetDir}/bin"
]
if (ideaVersion.matches(~/2017\.(1|2).*/)) {
// Project leak detection is not right in 2017.1&2.x
allJvmArgs += ["-Didea.log.leaked.projects.in.tests=false"]
}
}
clean.dependsOn('cleanGenerated')
task cleanGenerated(type: Delete, group: 'generate') {
outputs.upToDateWhen { !file("$generatedSrcDir").exists() }
delete "$generatedSrcDir"
}
task generateHaxeParser(dependsOn: ':setupTools', type: JavaExec, group: 'generate') {
workingDir = "${toolDir}"
main '-jar'
args = ['grammar-kit.jar', "${generatedSrcDir}", "${grammarHaxe}"]
inputs.file "${grammarHaxe}"
outputs.upToDateWhen { file("${generatedSrcDir}/com/intellij/plugins/haxe/lang").exists() }
}
task generateHxmlParser(dependsOn: ':setupTools', type: JavaExec, group: 'generate') {
workingDir = "${toolDir}"
main '-jar'
args = ['grammar-kit.jar', "${generatedSrcDir}", "${grammarHxml}"]
inputs.file "${grammarHxml}"
outputs.upToDateWhen { file("${generatedSrcDir}/com/intellij/plugins/haxe/hxml").exists() }
}
task generateMetadataParser(dependsOn: ':setupTools', type: JavaExec, group: 'generate') {
workingDir = "${toolDir}"
main '-jar'
args = ['grammar-kit.jar', "${generatedSrcDir}", "${grammarMetadata}"]
inputs.file "${grammarMetadata}"
outputs.upToDateWhen { file("${generatedSrcDir}/com/intellij/plugins/haxe/metadata").exists() }
}
import groovy.xml.MarkupBuilder
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
task generateIdeaSdkIdentifer(group: 'generate') {
doFirst {
copy {
file("${generatedSrcDir}/com/intellij/plugins/haxe/build/").mkdirs()
Properties properties = findSdkValuesAndProperties(file("${ideaTargetDir}/build.txt"))
from("${haxePluginDir}/src/common/com/intellij/plugins/haxe/build/IdeaSDKIdentifier.java.template") {
filter(ReplaceTokens, tokens: properties)
}
into "${generatedSrcDir}/com/intellij/plugins/haxe/build/"
rename('IdeaSDKIdentifier.java.template', 'IdeaSDKIdentifier.java')
}
}
}
task generateSources(group: 'generate') {
dependsOn 'generateIdeaSdkIdentifer'
// See template.gradle for generateVersionSpecificSources task.
dependsOn 'generateVersionSpecificSources'
dependsOn 'generateHaxeParser'
dependsOn 'generateHxmlParser'
dependsOn 'generateMetadataParser'
}
Properties findSdkValuesAndProperties(File buildFile) {
def buildId = buildFile.getText()
def typeSep = buildId.indexOf("-")
def clSep = buildId.indexOf(".", typeSep + 1)
def bldSep = buildId.indexOf(".", clSep + 1)
String buildType = buildId.substring(0, typeSep)
String codeLine = buildId.substring(typeSep + 1, clSep)
String buildNumber = (bldSep >= 0 ? buildId.substring(clSep + 1, bldSep) : buildId.substring(clSep + 1))
String patchNumber = (bldSep >= 0 ? buildId.substring(bldSep + 1) : 0)
ext.ideaSdkType = buildType
ext.ideaSdkCodeline = codeLine
ext.ideaSdkBuildNumber = buildNumber
ext.ideaSdkPatchNumber = patchNumber
// Lookup table for properties files. Add new versions here.
def propertiesFile = ""
switch (Integer.valueOf(codeLine, 10)) {
case 202: propertiesFile = "idea_v20.properties"; break
case 201: propertiesFile = "idea_v20.properties"; break
case 193: propertiesFile = "idea_v19.properties"; break
case 192: propertiesFile = "idea_v19.properties"; break
case 191: propertiesFile = "idea_v19.properties"; break
case 183: propertiesFile = "idea_v18.properties"; break
case 182: propertiesFile = "idea_v18.properties"; break
case 181: propertiesFile = "idea_v18.properties"; break
case 173: propertiesFile = "idea_v17.3.properties"; break
case 172: propertiesFile = "idea_v17.properties"; break
case 171: propertiesFile = "idea_v17.properties"; break
case 163: propertiesFile = "idea_v16.properties"; break
case 162: propertiesFile = "idea_v16.properties"; break
case 161: propertiesFile = "idea_v16.properties"; break
case 145: propertiesFile = "idea_v16.properties"; break
default:
throw new GradleException("Could not determine correct properties file for code line " + codeLine + ".")
}
def properties = new Properties()
if (0 != propertiesFile.size()) {
file("${rootDir}/properties/" + propertiesFile).withInputStream { properties.load(it) }
} else {
println "WARNING!: No Properties file found"
}
properties.setProperty('idea.sdk.version', "$ideaVersion")
properties.setProperty('idea.sdk.type', buildType)
properties.setProperty('idea.sdk.codeline', codeLine)
properties.setProperty('idea.sdk.build.number', buildNumber)
properties.setProperty('idea.sdk.patch.number', patchNumber)
properties.setProperty('replace.with.plugin.autogen.warning', "${pluginAutogenWarning}")
properties.setProperty('plugin.dev.version', project.hasProperty('devBuild') ? "${project.devBuild}" : '')
return properties
}
tasks.withType(Test) {
// force all tests to run every time
dependsOn "cleanTest"
// output summary and any failed or skipped tests
// from https://stackoverflow.com/questions/3963708/gradle-how-to-display-test-results-in-the-console-in-real-time
testLogging {
events TestLogEvent.FAILED,
TestLogEvent.SKIPPED
exceptionFormat TestExceptionFormat.FULL
showExceptions true
showCauses true
showStackTraces true
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
}
}
}
task checkForMissingRunConfigurations() {
def runConfigurationsDir = new File(".idea/runConfigurations")
if (!runConfigurationsDir.exists()) {
generateRunConfigurations()
}
}
task regenerateRunConfigurations() {
doLast {
generateRunConfigurations()
}
}
private void generateRunConfigurations() {
createGradleRunConfiguration('Run IDE (default)', 'runIde', '', '-Didea.is.internal=true')
createGradleRunConfiguration('Run IDE (default) - Suppress ProcessCanceledExceptions', 'runIde', '', '-Didea.is.internal=true -Didea.ProcessCanceledException=disabled')
createGradleRunConfiguration('Run Tests (default)', 'test', '', '')
createGradleRunConfiguration('Run Single Test (default)', 'test', '', '--tests "{replace this with FQDN of test suite or single test}"')
createGradleRunConfiguration('Generate Parsers', 'cleanGenerated generateHaxeParser generateHxmlParser', '', '')
createGradleRunConfiguration('Run Tests 2018', 'test', "-PtargetVersion=$latest2018Version", '')
createGradleRunConfiguration('Run Tests 2017', 'test', "-PtargetVersion=$latest2017Version", '')
createGradleRunConfiguration('Run Tests 2016', 'test', "-PtargetVersion=$latest2016Version", '')
createGradleRunConfiguration('Run IDE 2018',
'runIde',
"-PtargetVersion=$latest2018Version",
' -DHAXELIB_LIST_PATH_SUPPORTED=1 -Didea.is.internal=true')
createGradleRunConfiguration('Run IDE 2017',
'runIde',
"-PtargetVersion=$latest2017Version",
'-DHAXELIB_LIST_PATH_SUPPORTED=1 -Didea.is.internal=true')
createGradleRunConfiguration('Run IDE 2016',
'runIde',
"-PtargetVersion=$latest2016Version",
'-Xmx1024m -Xms512m -XX:MaxPermSize=256m -ea -DHAXELIB_LIST_PATH_SUPPORTED=1 -Didea.is.internal=true')
}
// create IDEA run configurations from Gradle JavaExec tasks
private void createGradleRunConfiguration(String configName, String taskList,String scriptParams, String vmOptions) {
def runConfigurationsDir = new File(".idea/runConfigurations")
runConfigurationsDir.mkdirs()
def writer = new FileWriter(new File(runConfigurationsDir, "${configName.replaceAll("\\s", "_")}.xml"))
def xml = new MarkupBuilder(writer)
xml.component(name: "ProjectRunConfigurationManager") {
configuration(default: 'false', name: configName, type: "GradleRunConfiguration", factoryName: "Gradle") {
ExternalSystemSettings() {
option(name: 'executionName')
option(name: 'externalProjectPath', value: '$PROJECT_DIR$')
option(name: 'externalSystemIdString', value: "GRADLE")
option(name: 'scriptParameters', value: scriptParams)
option(name: 'taskNames') {
list() {
for (String task : taskList.split('\\s')) {
option(value: task)
}
}
}
option(name: 'vmOptions', value: vmOptions)
}
}
}
}