forked from JetBrains/educational-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
970 lines (839 loc) · 28.3 KB
/
build.gradle.kts
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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
import de.undercouch.gradle.tasks.download.DownloadAction
import de.undercouch.gradle.tasks.download.DownloadSpec
import groovy.util.Node
import groovy.xml.XmlParser
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.JavaVersion.VERSION_11
import org.gradle.plugins.ide.idea.model.IdeaLanguageLevel
import org.jetbrains.intellij.tasks.IntelliJInstrumentCodeTask
import org.jetbrains.intellij.tasks.PatchPluginXmlTask
import org.jetbrains.intellij.tasks.PrepareSandboxTask
import org.jetbrains.intellij.tasks.RunIdeTask
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*
apply(from = "common.gradle.kts")
apply(from = "changes.gradle.kts")
val environmentName: String by project
val pluginVersion: String by project
val platformVersion: String = "20${StringBuilder(environmentName).insert(environmentName.length - 1, '.')}"
val baseIDE: String by project
val isJvmCenteredIDE = baseIDE in listOf("idea", "studio")
val ideaVersion: String by project
val clionVersion: String by project
val pycharmVersion: String by project
val studioVersion: String by project
val studioBuildVersion: String by project
val secretProperties: String by extra
val inJetBrainsNetwork: () -> Boolean by extra
val generateNotes: (String) -> String by extra
val isIdeaIDE = baseIDE == "idea"
val isClionIDE = baseIDE == "clion"
val isPycharmIDE = baseIDE == "pycharm"
val isStudioIDE = baseIDE == "studio"
val baseVersion = when {
isIdeaIDE -> ideaVersion
isClionIDE -> clionVersion
isPycharmIDE -> pycharmVersion
isStudioIDE -> studioVersion
else -> error("Unexpected IDE name = `$baseIDE`")
}
val studioPath: String
get() {
val androidStudioPath: String? by project
return androidStudioPath ?: downloadStudioIfNeededAndGetPath()
}
val jacksonVersion = "2.10.0"
val okhttpVersion = "3.14.0"
val ideaSandbox = "${project.buildDir.absolutePath}/idea-sandbox"
val pycharmSandbox = "${project.buildDir.absolutePath}/pycharm-sandbox"
val studioSandbox = "${project.buildDir.absolutePath}/studio-sandbox"
val webStormSandbox = "${project.buildDir.absolutePath}/webstorm-sandbox"
val clionSandbox = "${project.buildDir.absolutePath}/clion-sandbox"
val goLandSandbox = "${project.buildDir.absolutePath}/goland-sandbox"
val phpStormSandbox = "${project.buildDir.absolutePath}/phpstorm-sandbox"
// BACKCOMPAT: 2021.2
val isAtLeast213 = environmentName.toInt() >= 213
// BACKCOMPAT: 2021.3
val isAtLeast221 = environmentName.toInt() >= 221
val pythonProPlugin = "Pythonid:${prop("pythonProPluginVersion")}"
val pythonCommunityPlugin = "PythonCore:${prop("pythonCommunityPluginVersion")}"
val pythonPlugin = when {
isIdeaIDE -> pythonProPlugin
isClionIDE -> "python-ce"
isPycharmIDE -> "python-ce"
isStudioIDE -> pythonCommunityPlugin
else -> error("Unexpected IDE name = `$baseIDE`")
}
val scalaPlugin = "org.intellij.scala:${prop("scalaPluginVersion")}"
val rustPlugin = "org.rust.lang:${prop("rustPluginVersion")}"
// Since 2022.1 TOML plugin is bundled into IDEA and CLion
val tomlPlugin = if (isAtLeast221 && (isIdeaIDE || isClionIDE)) "org.toml.lang" else "org.toml.lang:${prop("tomlPluginVersion")}"
val goPlugin = "org.jetbrains.plugins.go:${prop("goPluginVersion")}"
val sqlPlugin = "com.intellij.database"
val markdownPlugin = if (isStudioIDE) "org.intellij.plugins.markdown:${prop("markdownPluginVersion")}" else "org.intellij.plugins.markdown"
val psiViewerPlugin = "PsiViewer:${prop("psiViewerPluginVersion")}"
val phpPlugin = "com.jetbrains.php:${prop("phpPluginVersion")}"
val jvmPlugins = listOf(
"java",
"junit",
"gradle-java"
)
val changesFile = "changes.html"
val isTeamCity: Boolean get() = System.getenv("TEAMCITY_VERSION") != null
plugins {
idea
kotlin("jvm") version "1.6.10"
id("org.jetbrains.intellij") version "1.4.0"
id("de.undercouch.download") version "4.0.4"
id("net.saliman.properties") version "1.5.1"
id("org.gradle.test-retry") version "1.3.1"
}
idea {
project {
jdkName = "11"
languageLevel = IdeaLanguageLevel("11")
vcs = "Git"
}
module {
// https://github.com/gradle/gradle/issues/8749
// `.add` can be used since Gradle 7.1
excludeDirs = excludeDirs + file("dependencies")
}
}
allprojects {
apply {
plugin("org.jetbrains.intellij")
plugin("java")
plugin("kotlin")
plugin("net.saliman.properties")
plugin("org.gradle.test-retry")
}
repositories {
mavenCentral()
maven("https://cache-redirector.jetbrains.com/intellij-dependencies")
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-js-wrappers")
}
configure<JavaPluginExtension> {
sourceCompatibility = VERSION_11
targetCompatibility = VERSION_11
}
sourceSets {
main {
if (project != rootProject) {
java.srcDirs("src", "branches/$environmentName/src")
}
resources.srcDirs("resources", "branches/$environmentName/resources")
}
test {
if (project != rootProject) {
java.srcDirs("testSrc", "branches/$environmentName/testSrc")
resources.srcDirs("testResources", "branches/$environmentName/testResources")
}
}
}
kotlin {
sourceSets {
if (project != rootProject) {
main {
kotlin.srcDirs("src", "branches/$environmentName/src")
}
test {
kotlin.srcDirs("testSrc", "branches/$environmentName/testSrc")
}
}
}
}
configurations {
all {
// Allows using project dependencies instead of IDE dependencies during compilation and test running
resolutionStrategy.sortArtifacts(ResolutionStrategy.SortOrder.DEPENDENCY_FIRST)
}
}
intellij {
if (isStudioIDE) {
localPath.set(studioPath)
} else {
version.set(baseVersion)
}
}
tasks {
withProp("customJbr") {
if (it.isNotBlank()) {
runIde {
jbrVersion.set(it)
}
}
}
if (isStudioIDE) {
withType<IntelliJInstrumentCodeTask> {
compilerVersion.set(studioBuildVersion)
}
}
withType<Test> {
withProp(secretProperties, "stepikTestClientSecret") { environment("STEPIK_TEST_CLIENT_SECRET", it) }
withProp(secretProperties, "stepikTestClientId") { environment("STEPIK_TEST_CLIENT_ID", it) }
withProp("excludeTests") { exclude(it) }
ignoreFailures = true
filter {
isFailOnNoMatchingTests = false
}
if (isTeamCity) {
retry {
maxRetries.set(3)
maxFailures.set(5)
}
}
}
withType<JavaCompile> { options.encoding = "UTF-8" }
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
languageVersion = "1.6"
apiVersion = "1.5"
freeCompilerArgs = listOf("-Xjvm-default=all")
}
}
val verifyClasses = task("verifyClasses") {
dependsOn(jar)
doLast {
verifyClasses(project)
}
}
// Fail plugin build if there are errors in module packages
rootProject.tasks.buildPlugin {
dependsOn(verifyClasses)
}
}
dependencies {
implementation(group = "org.twitter4j", name = "twitter4j-core", version = "4.0.1")
implementation("org.jsoup:jsoup:1.12.1")
implementation(group = "com.fasterxml.jackson.dataformat", name = "jackson-dataformat-yaml", version = jacksonVersion) {
exclude(module = "snakeyaml")
}
implementation(group = "com.fasterxml.jackson.datatype", name = "jackson-datatype-jsr310", version = jacksonVersion)
//transitive dependency is specified explicitly to avoid conflict with lib bundled since idea 181
implementation(group = "com.fasterxml.jackson.core", name = "jackson-core", version = jacksonVersion)
//transitive dependency is specified explicitly because of the issue https://github.com/FasterXML/jackson-dataformats-text/issues/81
//intellij platform uses affected snakeyaml version inside
implementation(group = "org.yaml", name = "snakeyaml", version = "1.21")
implementation(group = "com.fasterxml.jackson.module", name = "jackson-module-kotlin", version = jacksonVersion) {
excludeKotlinDeps()
}
implementation("com.squareup.retrofit2:retrofit:2.4.0")
implementation("com.squareup.retrofit2:converter-jackson:2.3.0")
implementation("com.squareup.okhttp3:logging-interceptor:$okhttpVersion")
implementation("org.jetbrains:kotlin-css-jvm:1.0.0-pre.58-kotlin-1.3.0") {
excludeKotlinDeps()
}
// The same as `testImplementation(kotlin("test"))` but with excluding kotlin stdlib dependencies
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:${getKotlinPluginVersion()}") {
excludeKotlinDeps()
}
testImplementation("com.squareup.okhttp3:mockwebserver:$okhttpVersion")
testImplementation("io.mockk:mockk:1.12.0") {
excludeKotlinDeps()
}
}
}
subprojects {
tasks {
runIde { enabled = false }
prepareSandbox { enabled = false }
buildSearchableOptions { enabled = false }
}
val testOutput = configurations.create("testOutput")
dependencies {
testOutput(sourceSets.test.get().output.classesDirs)
}
}
project(":") {
val buildNumber = System.getenv("BUILD_NUMBER") ?: "SNAPSHOT"
if (hasProp("setTCBuildNumber")) {
// Specify build number at building plugin running configuration on TC
// with heading plugin version: e.g. `3.8.BUILD_NUMBER` instead of `BUILD_NUMBER`
println("##teamcity[buildNumber '$pluginVersion.$buildNumber']")
}
version = "$pluginVersion-$platformVersion-$buildNumber"
intellij {
pluginName.set("EduTools")
updateSinceUntilBuild.set(true)
downloadSources.set(false)
tasks.withType<PatchPluginXmlTask> {
changeNotes.set(provider { file(changesFile).readText() })
pluginDescription.set(provider { file("description.html").readText() })
sinceBuild.set(prop("customSinceBuild"))
untilBuild.set(prop("customUntilBuild"))
}
val pluginsList = mutableListOf(
rustPlugin,
tomlPlugin,
"yaml",
markdownPlugin,
// PsiViewer plugin is not a runtime dependency
// but it helps a lot while developing features related to PSI
psiViewerPlugin
)
pluginsList += listOfNotNull(pythonPlugin)
if (isJvmCenteredIDE) {
pluginsList += listOf("java", "junit", "Kotlin", scalaPlugin)
}
if (isIdeaIDE) {
pluginsList += listOf("JavaScriptLanguage", "NodeJS", goPlugin, phpPlugin)
}
if (!(isStudioIDE || isPycharmIDE)) {
pluginsList += sqlPlugin
}
plugins.set(pluginsList)
}
dependencies {
compileOnly(project(":educational-core"))
compileOnly(project(":code-insight"))
compileOnly(project(":code-insight:html"))
compileOnly(project(":code-insight:markdown"))
compileOnly(project(":code-insight:yaml"))
compileOnly(project(":jvm-core"))
compileOnly(project(":Edu-Java"))
compileOnly(project(":Edu-Kotlin"))
compileOnly(project(":Edu-Python"))
compileOnly(project(":Edu-Python:Idea"))
compileOnly(project(":Edu-Python:PyCharm"))
compileOnly(project(":Edu-Scala"))
compileOnly(project(":Edu-Android"))
compileOnly(project(":Edu-JavaScript"))
compileOnly(project(":Edu-Rust"))
compileOnly(project(":Edu-Cpp"))
compileOnly(project(":Edu-Go"))
compileOnly(project(":Edu-Php"))
compileOnly(project(":Edu-Sql"))
}
val removeIncompatiblePlugins = task<Delete>("removeIncompatiblePlugins") {
fun deletePlugin(sandboxPath: String, pluginName: String) {
file("$sandboxPath/plugins/$pluginName").deleteRecursively()
}
doLast {
deletePlugin(pycharmSandbox, "python-ce")
deletePlugin(clionSandbox, "python-ce")
deletePlugin(pycharmSandbox, "Scala")
}
}
tasks {
jar {
from({
// Collect all `compileOnly` project dependencies and add their compilation output to jar.
// We need to put all plugin manifest files into single jar to make new plugin model work
val projectDependencies = project.configurations.compileOnly.get().allDependencies.withType<ProjectDependency>()
projectDependencies.map { it.dependencyProject.sourceSets.main.get().output }
})
}
withType<PrepareSandboxTask> {
from("$rootDir/twitter") {
into("${pluginName.get()}/twitter")
include("**/*.gif")
}
finalizedBy(removeIncompatiblePlugins)
}
withType<RunIdeTask> {
// Disable auto plugin reloading. See `com.intellij.ide.plugins.DynamicPluginVfsListener`
// To enable dynamic reloading, change value to `true` and disable `EduDynamicPluginListener`
jvmArgs("-Didea.auto.reload.plugins=false")
jvmArgs("-Xmx2g")
// Uncomment to show localized messages
// jvmArgs("-Didea.l10n=true")
// Uncomment to enable memory dump creation if plugin cannot be unloaded by the platform
// jvmArgs("-Dide.plugins.snapshot.on.unload.fail=true")
// Uncomment to enable FUS testing mode
// jvmArgs("-Dfus.internal.test.mode=true")
}
buildSearchableOptions {
enabled = findProperty("enableBuildSearchableOptions") != "false"
}
}
// Generates event scheme for EduTools plugin FUS events to `build/eventScheme.json`
task<RunIdeTask>("buildEventsScheme") {
dependsOn(tasks.prepareSandbox)
args("buildEventsScheme", "--outputFile=${buildDir.resolve("eventScheme.json").absolutePath}", "--pluginId=com.jetbrains.edu")
// Force headless mode to be able to run command on CI
systemProperty("java.awt.headless", "true")
// BACKCOMPAT: 2021.2
doFirst {
if (!isAtLeast213) {
throw GradleException("`buildEventsScheme` task is supported only for 213 platform or higher. Please, change `environmentName` property value")
}
}
}
task("configureIdea") {
doLast {
intellij.sandboxDir.set(ideaSandbox)
withProp("ideaPath") { path ->
tasks.runIde {
ideDir.set(file(path))
}
}
}
}
task("configurePyCharm") {
doLast {
intellij.sandboxDir.set(pycharmSandbox)
withProp("pycharmPath") { path ->
tasks.runIde {
ideDir.set(file(path))
}
}
}
}
task("configureWebStorm") {
doLast {
if (!hasProp("webStormPath")) {
throw InvalidUserDataException("Path to WebStorm installed locally is needed\nDefine \"webStormPath\" property")
}
intellij.sandboxDir.set(webStormSandbox)
tasks.runIde {
ideDir.set(file(prop("webStormPath")))
}
}
}
task("configureCLion") {
doLast {
intellij.sandboxDir.set(clionSandbox)
withProp("clionPath") { path ->
tasks.runIde {
ideDir.set(file(path))
}
}
}
}
task("configureAndroidStudio") {
doLast {
intellij.sandboxDir.set(studioSandbox)
withProp("androidStudioPath") { path ->
tasks.runIde {
ideDir.set(file(path))
}
}
}
}
task("configureGoLand") {
doLast {
if (!hasProp("goLandPath")) {
throw InvalidUserDataException("Path to GoLand installed locally is needed\nDefine \"goLandPath\" property")
}
intellij.sandboxDir.set(goLandSandbox)
tasks.runIde {
ideDir.set(file(prop("goLandPath")))
}
}
}
task("configurePhpStorm") {
doLast {
if (!hasProp("phpStormPath")) {
throw InvalidUserDataException("Path to PhpStorm installed locally is needed\nDefine \"phpStormPath\" property")
}
intellij.sandboxDir.set(phpStormSandbox)
tasks.runIde {
ideDir.set(file(prop("phpStormPath")))
}
}
}
}
project(":educational-core")
project(":code-insight") {
dependencies {
implementation(project(":educational-core"))
testImplementation(project(":educational-core", "testOutput"))
}
}
project(":code-insight:html") {
dependencies {
implementation(project(":educational-core"))
implementation(project(":code-insight"))
testImplementation(project(":educational-core", "testOutput"))
testImplementation(project(":code-insight", "testOutput"))
}
}
project(":code-insight:markdown") {
val pluginList = mutableListOf(markdownPlugin)
if (isStudioIDE) {
pluginList += "platform-images"
}
intellij {
plugins.set(pluginList)
}
tasks {
prepareTestingSandbox {
// Set custom plugin directory name for tests.
// Otherwise, `prepareTestingSandbox` merge directories of `markdown` plugin and `markdown` modules
// into single one
pluginName.set("edu-markdown")
}
}
dependencies {
implementation(project(":educational-core"))
implementation(project(":code-insight"))
testImplementation(project(":educational-core", "testOutput"))
testImplementation(project(":code-insight", "testOutput"))
}
}
project(":code-insight:yaml") {
intellij {
plugins.set(listOf("yaml"))
}
dependencies {
implementation(project(":educational-core"))
implementation(project(":code-insight"))
testImplementation(project(":educational-core", "testOutput"))
testImplementation(project(":code-insight", "testOutput"))
}
}
project(":jvm-core") {
intellij {
if (!isJvmCenteredIDE) {
localPath.set(null as String?)
version.set(ideaVersion)
}
plugins.set(jvmPlugins)
}
dependencies {
implementation(project(":educational-core"))
testImplementation(project(":educational-core", "testOutput"))
}
}
project(":Edu-Java") {
intellij {
localPath.set(null as String?)
version.set(ideaVersion)
plugins.set(jvmPlugins)
}
dependencies {
implementation(project(":educational-core"))
implementation(project(":jvm-core"))
testImplementation(project(":educational-core", "testOutput"))
testImplementation(project(":jvm-core", "testOutput"))
}
}
project(":Edu-Kotlin") {
intellij {
if (!isJvmCenteredIDE) {
localPath.set(null as String?)
version.set(ideaVersion)
}
val pluginList = jvmPlugins + "Kotlin"
plugins.set(pluginList)
}
dependencies {
implementation(project(":educational-core"))
implementation(project(":jvm-core"))
testImplementation(project(":educational-core", "testOutput"))
testImplementation(project(":jvm-core", "testOutput"))
}
}
project(":Edu-Scala") {
intellij {
localPath.set(null as String?)
version.set(ideaVersion)
val pluginsList = jvmPlugins + scalaPlugin
plugins.set(pluginsList)
}
dependencies {
implementation(project(":educational-core"))
implementation(project(":jvm-core"))
testImplementation(project(":educational-core", "testOutput"))
testImplementation(project(":jvm-core", "testOutput"))
}
}
project(":Edu-Android") {
intellij {
localPath.set(studioPath)
val pluginsList = jvmPlugins + "android"
plugins.set(pluginsList)
}
tasks {
withType<IntelliJInstrumentCodeTask> {
compilerVersion.set(studioBuildVersion)
}
}
dependencies {
implementation(project(":educational-core"))
implementation(project(":jvm-core"))
testImplementation(project(":educational-core", "testOutput"))
testImplementation(project(":jvm-core", "testOutput"))
}
// BACKCOMPAT: enable when 221 studio is available
tasks.withType<Test> {
enabled = environmentName.toInt() < 221
}
}
project(":Edu-Python") {
intellij {
val pluginList = listOfNotNull(
pythonPlugin,
if (isJvmCenteredIDE) "java" else null,
// needed only for tests, actually
if (isAtLeast213) "platform-images" else null
)
plugins.set(pluginList)
}
dependencies {
implementation(project(":educational-core"))
testImplementation(project(":educational-core", "testOutput"))
testImplementation(project(":Edu-Python:Idea"))
testImplementation(project(":Edu-Python:PyCharm"))
}
}
project(":Edu-Python:Idea") {
intellij {
if (!isJvmCenteredIDE || isStudioIDE) {
localPath.set(null as String?)
version.set(ideaVersion)
}
val pluginList = listOfNotNull(
if (!isJvmCenteredIDE) pythonProPlugin else pythonPlugin,
"java"
)
plugins.set(pluginList)
}
dependencies {
implementation(project(":educational-core"))
compileOnly(project(":Edu-Python"))
testImplementation(project(":educational-core", "testOutput"))
}
}
project(":Edu-Python:PyCharm") {
intellij {
if (isStudioIDE) {
localPath.set(null as String?)
version.set(ideaVersion)
}
plugins.set(listOf(pythonPlugin))
}
dependencies {
implementation(project(":educational-core"))
compileOnly(project(":Edu-Python"))
testImplementation(project(":educational-core", "testOutput"))
}
}
project(":Edu-JavaScript") {
intellij {
localPath.set(null as String?)
version.set(ideaVersion)
val pluginList = mutableListOf("NodeJS", "JavaScriptLanguage", "com.intellij.css")
plugins.set(pluginList)
}
dependencies {
implementation(project(":educational-core"))
testImplementation(project(":educational-core", "testOutput"))
}
}
project(":Edu-Rust") {
intellij {
plugins.set(listOf(rustPlugin, tomlPlugin))
}
dependencies {
implementation(project(":educational-core"))
testImplementation(project(":educational-core", "testOutput"))
}
}
project(":Edu-Cpp") {
intellij {
localPath.set(null as String?)
version.set(clionVersion)
plugins.set(listOf("clion-test-google", "clion-test-catch", "clion", "c-plugin"))
}
dependencies {
implementation(project(":educational-core"))
testImplementation(project(":educational-core", "testOutput"))
}
}
project(":Edu-Go") {
intellij {
localPath.set(null as String?)
version.set(ideaVersion)
plugins.set(listOf(goPlugin))
}
dependencies {
implementation(project(":educational-core"))
testImplementation(project(":educational-core", "testOutput"))
}
}
project(":Edu-Php") {
intellij {
localPath.set(null as String?)
version.set(ideaVersion)
plugins.set(listOf(phpPlugin))
}
dependencies {
implementation(project(":educational-core"))
testImplementation(project(":educational-core", "testOutput"))
}
}
project(":Edu-Sql") {
intellij {
if (isStudioIDE || isPycharmIDE) {
localPath.set(null as String?)
version.set(ideaVersion)
}
plugins.set(listOf(sqlPlugin))
}
dependencies {
implementation(project(":educational-core"))
testImplementation(project(":educational-core", "testOutput"))
}
}
fun downloadStudioIfNeededAndGetPath(): String {
if (!rootProject.hasProperty("studioVersion")) error("studioVersion is unspecified")
val osFamily = osFamily
val (archiveType, fileTreeMethod) = if (osFamily == "linux") "tar.gz" to this::tarTree else "zip" to this::zipTree
val studioArchive = file("${rootProject.projectDir}/dependencies/studio-$studioVersion-${osFamily}.$archiveType")
if (!studioArchive.exists()) {
download {
src(studioArtifactDownloadPath(archiveType))
retries(2)
readTimeout(3 * 60 * 1000) // 3 min
dest(studioArchive)
}
}
val studioFolder = file("${rootProject.projectDir}/dependencies/studio-$studioVersion")
if (!studioFolder.exists()) {
copy {
from(fileTreeMethod(studioArchive))
into(studioFolder)
}
}
return studioPath(studioFolder)
}
fun studioArtifactDownloadPath(archiveType: String): String {
return if (inJetBrainsNetwork()) {
println("Downloading studio from JB repo...")
"https://repo.labs.intellij.net/edu-tools/android-studio-${studioVersion}-${osFamily}.$archiveType"
} else {
"http://dl.google.com/dl/android/studio/ide-zips/${studioVersion}/android-studio-${studioVersion}-${osFamily}.$archiveType"
}
}
fun studioPath(studioFolder: File): String {
return if (osFamily == "mac") {
val candidates = studioFolder.listFiles()
.orEmpty()
.filter { it.isDirectory && it.name.matches(Regex("Android Studio.*\\.app")) }
when (candidates.size) {
0 -> error("Can't find any folder matching `Android Studio*.app` in `$studioFolder`")
1 -> return "${candidates[0]}/Contents"
else -> error("More than one folder matching `Android Studio*.app` found in `$studioFolder`")
}
} else {
"$studioFolder/android-studio"
}
}
val osFamily: String get() {
return when {
Os.isFamily(Os.FAMILY_WINDOWS) -> "windows"
Os.isFamily(Os.FAMILY_MAC) -> "mac"
Os.isFamily(Os.FAMILY_UNIX) && !Os.isFamily(Os.FAMILY_MAC) -> "linux"
else -> error("current os family is unsupported")
}
}
fun hasProp(name: String): Boolean = extra.has(name)
fun prop(name: String): String =
extra.properties[name] as? String ?: error("Property `$name` is not defined in gradle.properties")
fun withProp(name: String, action: (String) -> Unit) {
if (hasProp(name)) {
action(prop(name))
}
}
fun withProp(filePath: String, name: String, action: (String) -> Unit) {
if (!file(filePath).exists()) {
println("$filePath doesn't exist")
return
}
val properties = loadProperties(filePath)
val value = properties.getProperty(name) ?: return
action(value)
}
fun <T : ModuleDependency> T.excludeKotlinDeps() {
exclude(module = "kotlin-runtime")
exclude(module = "kotlin-reflect")
exclude(module = "kotlin-stdlib")
exclude(module = "kotlin-stdlib-common")
exclude(module = "kotlin-stdlib-jdk8")
}
// TODO: find way how to use existing functionality
fun download(configure: DownloadSpec.() -> Unit) {
with(DownloadAction(project)) {
configure()
execute()
println("Download completed")
}
}
fun loadProperties(path: String): Properties {
val properties = Properties()
file(path).bufferedReader().use { properties.load(it) }
return properties
}
/*
Workflow is the following:
1. Launch the task.
2. Review changes in changes.html and edit if needed.
3. Push.
*/
task("generate-release-notes") {
doLast {
val notes = generateNotes(pluginVersion)
val changesFile = file(changesFile)
val oldChangeNotes = changesFile.readText()
changesFile.writeText("$notes\n$oldChangeNotes")
}
}
fun parseManifest(file: File): Node {
val node = XmlParser().parse(file)
check(node.name() == "idea-plugin") {
"Manifest file `$file` doesn't contain top-level `idea-plugin` attribute"
}
return node
}
fun manifestFile(project: Project, filePath: String? = null): File {
val mainOutput = project.sourceSets.main.get().output
val resourcesDir = mainOutput.resourcesDir ?: error("Failed to find resources dir for ${project.name}")
if (filePath != null) {
return resourcesDir.resolve(filePath).takeIf { it.exists() } ?: error("Failed to find manifest file for ${project.name} module")
}
val rootManifest = parseManifest(manifestFile(rootProject, "META-INF/plugin.xml"))
val children = ((rootManifest["content"] as? List<*>)?.single() as? Node)?.children()
?: error("Failed to find module declarations in root manifest")
return children.filterIsInstance<Node>()
.flatMap { node ->
if (node.name() != "module") return@flatMap emptyList()
val name = node.attribute("name") as? String ?: return@flatMap emptyList()
listOfNotNull(resourcesDir.resolve ("$name.xml").takeIf { it.exists() })
}.firstOrNull() ?: error("Failed to find manifest file for ${project.name} module")
}
fun findModulePackage(project: Project): String {
// Some gradle projects are not modules from IDEA plugin point of view
// because we use `include` for them inside manifests, i.e. they just a part of another module.
// That's why we delegate manifest search to other projects in some cases
val moduleManifest = when (project.path) {
":", ":educational-core", ":code-insight" -> manifestFile(rootProject, "META-INF/plugin.xml")
":Edu-Python:Idea", ":Edu-Python:PyCharm" -> manifestFile(project.parent!!)
else -> manifestFile(project)
}
val node = parseManifest(moduleManifest)
return node.attribute("package") as? String ?: error("Failed to find package for ${project.name}")
}
fun verifyClasses(project: Project) {
val pkg = findModulePackage(project)
val expectedDir = pkg.replace('.', '/')
var hasErrors = false
for (classesDir in project.sourceSets.main.get().output.classesDirs) {
val basePath = classesDir.toPath()
for (file in classesDir.walk()) {
if (file.isFile && file.extension == "class") {
val relativePath = basePath.relativize(file.toPath())
if (!relativePath.startsWith(expectedDir)) {
logger.error("Wrong package of `${relativePath.joinToString(".").removeSuffix(".class")}` class. Expected `$pkg`")
hasErrors = true
}
}
}
}
if (hasErrors) {
throw GradleException("Classes with wrong package were found. See https://docs.google.com/document/d/1pOy-qNlGOJe6wftHVYHkH8sZOoAfav1fdGDPJgkQWJo")
}
}