build scripts cleanup: unused methods removed, some method names corrected, obsolete...
[idea/community.git] / build / scripts / layouts.gant
1 /*
2  * Copyright 2000-2016 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 import org.jetbrains.intellij.build.*
19 import org.jetbrains.intellij.build.impl.BuildTasksImpl
20 import org.jetbrains.jps.util.JpsPathUtil
21
22 import static org.jetbrains.jps.idea.IdeaProjectLoader.guessHome
23
24 includeTargets << new File("${guessHome(this)}/build/scripts/utils.gant")
25
26 /**
27  * @deprecated use 'update-from-sources' from dist.gant instead
28  */
29 target('default': "Developers update") {
30   //when IDEA CE is updated from IDEA UE sources project should be loaded from IDEA UE directory
31   String projectHome = isDefined("devIdeaHome") ? devIdeaHome : home
32   def options = new BuildOptions()
33   options.useCompiledClassesFromProjectOutput = true
34   def context = BuildContext.createContext(ant, projectBuilder, project, global, home, projectHome, new IdeaCommunityProperties(home),
35                                            ProprietaryBuildTools.DUMMY, options)
36   context.paths.distAll = deploy
37   layoutFull(context)
38 }
39
40 boolean setPluginAndIDEVersionInPluginXml() {
41   return !isDefined("productProperties") || productProperties.setPluginAndIDEVersionInPluginXml
42 }
43
44 List<String> getExcludedPlugins() {
45   return []
46 }
47
48 /**
49  * @deprecated this method isn't called anymore, it's temporary left for compatibility only; modify {@link org.jetbrains.intellij.build.IdeaCommunityProperties} instead
50  */
51 def layoutFull(BuildContext context) {
52   binding.setVariable("productProperties", context.productProperties)
53   String home = context.paths.communityHome
54   String targetDirectory = context.paths.distAll
55   File patchedApplicationInfo = ((BuildTasksImpl)BuildTasks.create(context)).patchApplicationInfo()
56   projectBuilder.stage("layout to $targetDirectory")
57
58   List<String> jpsCommonModules = ["jps-model-impl", "jps-model-serialization"]
59   List<String> openapiModules = [platformApiModules,
60     "compiler-openapi",
61     "debugger-openapi",
62     "dom-openapi",
63     "execution-openapi",
64     "java-analysis-api",
65     "java-indexing-api",
66     "java-psi-api",
67     "jsp-openapi",
68     "jsp-base-openapi",
69     "openapi",
70     "remote-servers-java-api",
71     "testFramework-java",
72   ].flatten()
73
74   List<String> implementationModules = [platformImplementationModules,
75     "compiler-impl",
76     "debugger-impl",
77     "dom-impl",
78     "duplicates-analysis",
79     "execution-impl",
80     "external-system-impl",
81     "idea-ui",
82     "java-analysis-impl",
83     "java-indexing-impl",
84     "java-impl",
85     "java-psi-impl",
86     "java-structure-view",
87     "jsp-spi",
88     "manifest",
89     "platform-main",
90     "remote-servers-java-impl",
91     "structuralsearch",
92     "structuralsearch-java",
93     "testFramework",
94     "tests_bootstrap",
95     "typeMigration",
96     "ui-designer-core",
97   ].flatten()
98   implementationModules.removeAll(jpsCommonModules) //todo[nik] remove jps modules from platformImplementationModules instead and update layouts of minor IDEs accordingly
99
100   ant.patternset(id: "resources.included") {
101     include(name: "**/*.properties")
102     include(name: "fileTemplates/**/*")
103     include(name: "inspectionDescriptions/**/*")
104     include(name: "intentionDescriptions/**/*")
105     include(name: "tips/**/*")
106   }
107
108   ant.patternset(id: "resources.excluded") {
109     exclude(name: "**/*.properties")
110     exclude(name: "fileTemplates/**/*")
111     exclude(name: "fileTemplates")
112     exclude(name: "inspectionDescriptions/**/*")
113     exclude(name: "inspectionDescriptions")
114     exclude(name: "intentionDescriptions/**/*")
115     exclude(name: "intentionDescriptions")
116     exclude(name: "tips/**/*")
117     exclude(name: "tips")
118   }
119
120   def info = layout(targetDirectory) {
121     dir("lib") {
122       dir("rt") {
123         fileset(dir: "${home}/lib/rt", includesfile: "${home}/lib/rt/required_for_dist.txt")
124         jar("jps-plugin-system.jar") {
125           module("jps-plugin-system")
126         }
127       }
128
129       dir("libpty") {
130         fileset(dir: "$home/lib/libpty") {
131           exclude(name: "readme.txt")
132         }
133       }
134
135       jar("util.jar") {
136         module("util")
137         module("util-rt")
138       }
139
140       jar("openapi.jar") {
141         openapiModules.each { module it}
142       }
143
144       jar("annotations.jar") {
145         module("annotations-common")
146         module("annotations")
147       }
148       jar("jdkAnnotations.jar") {
149         fileset(dir: "${home}/java/jdkAnnotations")
150       }
151
152       jar("extensions.jar") { module("extensions")}
153
154       jar("external-system-rt.jar") { module("external-system-rt")}
155
156       jar([name: "idea.jar", duplicate: "preserve"]) {
157         implementationModules.each { module it}
158       }
159
160       jar("bootstrap.jar") { module("bootstrap") }
161
162       jar("jps-launcher.jar") { module("jps-launcher") }
163
164       jar("resources.jar") {
165         module("colorSchemes")
166         module("resources")
167         module("platform-resources")
168
169         def appInfoModule = context.productProperties.applicationInfoModule
170         if ("community-resources" == appInfoModule) {
171           module("community-resources") {
172             if (patchedApplicationInfo != null) {
173               exclude(name: "idea/$patchedApplicationInfo.name")
174             }
175           }
176         } else {
177           module("community-resources")
178           module(appInfoModule) {
179             if (patchedApplicationInfo != null) {
180               exclude(name: "idea/$patchedApplicationInfo.name")
181             }
182           }
183         }
184         if (patchedApplicationInfo != null) {
185           dir("idea") {
186             fileset(file: patchedApplicationInfo.path)
187           }
188         }
189       }
190
191       jar("idea_rt.jar") { module("java-runtime")}
192
193       jar("forms_rt.jar") {
194         module("forms_rt")
195         module("forms-compiler")
196       }
197
198       jar("resources_en.jar") {
199         module("resources-en")
200         module("platform-resources-en")
201       }
202
203       jar("icons.jar") { module("icons") }
204       jar("boot.jar") { module("boot") }
205
206       jar("javac2.jar") {
207         module("javac2")
208         module("forms-compiler")
209         module("forms_rt")
210         module("instrumentation-util")
211         module("instrumentation-util-8")
212       }
213
214       jar("jps-model.jar") {
215         jpsCommonModules.each { module it }
216       }
217       jar("jps-builders.jar") {
218         module("jps-builders")
219       }
220
221       fileset(dir: "$home/jps/lib") {
222         include(name: "optimizedFileManager.jar")
223       }
224
225       fileset(dir: "$home/lib", includesfile: "${home}/lib/required_for_dist.txt")
226
227       fileset(dir: "$home/build/kotlinc/lib") {
228         include(name: "kotlin-runtime.jar")
229         include(name: "kotlin-reflect.jar")
230       }
231
232       fileset(dir: "$home/xml/relaxng/lib", includes: "*.jar")
233
234       dir("ant") {
235         fileset(dir: "$home/lib/ant") {
236           exclude(name: "**/src/**")
237         }
238       }
239     }
240
241     dir("redist") {
242       jar("annotations-java8.jar") {
243         module("annotations-common")
244         module("annotations-java8")
245       }
246     }
247
248     layoutCommunityPlugins(home, context)
249
250     dir("plugins") {
251       dir("javaFX") {
252         dir("lib") {
253           jar("javaFX.jar") {
254             noResources("javaFX")
255             noResources("javaFX-CE")
256           }
257           resources(["javaFX", "javaFX-CE"])
258           jar("javaFX-jps-plugin.jar") {
259             module("javaFX-jps-plugin")
260           }
261           jar("common-javaFX-plugin.jar") {
262             module("common-javaFX-plugin")
263           }
264           fileset(dir: "${home}/plugins/javaFX/lib", includes: "SceneBuilderKit-8.1.1.jar");
265         }
266       }
267     }
268
269     dir("plugins") {
270       dir("IntelliLang") {
271         dir("lib") {
272           jar("IntelliLang.jar") {
273             module("IntelliLang")
274             module("IntelliLang-java")
275             module("IntelliLang-xml")
276           }
277           jar("intellilang-jps-plugin.jar") {
278             module("intellilang-jps-plugin")
279           }
280         }
281       }
282     }
283   }
284
285   reorder(home, targetDirectory)
286   return info
287 }
288
289 /**
290  * @deprecated this method isn't used in new build scripts (it's still used in CLion and AppCode build scripts which aren't rewritten yet and
291  * in third-party products); specify non-trivial layout of plugins in {@link org.jetbrains.intellij.build.CommunityRepositoryModules} instead
292  */
293 public def layoutCommunityPlugins(String home, BuildContext buildContext = null) {
294   if (!isDefined("pluginFilter") || pluginFilter.contains("android")) {
295     if (buildContext == null) {
296       projectBuilder.error("Cannot build Android plugin: buildContext isn't defined")
297     }
298     def androidModule = buildContext.findModule("android")
299     def sdklibModule = buildContext.findModule("sdklib")
300     if (androidModule == null) projectBuilder.error("Cannot build Android plugin: 'android' module isn't included into the project")
301     if (sdklibModule == null) projectBuilder.error("Cannot build Android plugin: 'sdklib' module isn't included into the project")
302
303     def androidHome = JpsPathUtil.urlToPath(androidModule.contentRootsList.urls.first())
304     def androidToolsBaseHome = JpsPathUtil.urlToFile(sdklibModule.contentRootsList.urls.first()).parentFile.canonicalPath
305     [androidHome, androidToolsBaseHome].each {
306       if (!new File(it).exists()) projectBuilder.error("Cannot build Android plugin: $it doesn't exist")
307     }
308     layoutAndroid(androidHome, androidToolsBaseHome)
309   }
310
311   dir("plugins") {
312     def simplePlugins = ["copyright", "java-i18n", "hg4idea", "github"] //, "tasks-time-tracking"]
313
314     simplePlugins.each {
315       layoutPlugin it
316     }
317
318     layoutPlugin("ant", "ant", "antIntegration") {
319       jar("ant-jps-plugin.jar") {
320         module("ant-jps-plugin")
321       }
322     }
323     layoutPlugin("uiDesigner", "ui-designer", "uiDesigner") {
324       dir("jps") {
325         jar("ui-designer-jps-plugin.jar") {
326           module("ui-designer-jps-plugin")
327         }
328       }
329     }
330
331     pluginDir("properties") {
332       dir("lib") {
333         jar("properties.jar") {
334           module("properties-psi-api")
335           module("properties-psi-impl")
336           module("properties")
337         }
338       }
339     }
340
341     layoutPlugin("maven") {
342       jar("maven-jps-plugin.jar") {
343         module("maven-jps-plugin")
344       }
345       jar("aether-dependency-resolver.jar") {
346         module("aether-dependency-resolver")
347       }
348       jar("maven-server-api.jar") {
349         module("maven-server-api")
350       }
351       jar("maven2-server-impl.jar") {
352         module("maven2-server-impl")
353       }
354       jar("maven3-server-common.jar") {
355         module("maven3-server-common")
356       }
357       jar("maven30-server-impl.jar") {
358         module("maven30-server-impl")
359       }
360       jar("maven3-server-impl.jar") {
361         module("maven3-server-impl")
362       }
363
364       jar("artifact-resolver-m2.jar") {
365         module("maven-artifact-resolver-m2")
366         module("maven-artifact-resolver-common")
367       }
368
369       jar("artifact-resolver-m3.jar") {
370         module("maven-artifact-resolver-m3")
371         module("maven-artifact-resolver-common")
372       }
373
374       jar("artifact-resolver-m31.jar") {
375         module("maven-artifact-resolver-m31")
376         module("maven-artifact-resolver-common")
377       }
378
379       dir("maven3-server-lib") {
380         fileset(dir: "$home/plugins/maven/maven3-server-common/lib") {include(name: "*.jar")}
381       }
382       dir("maven3") {
383         fileset(dir: "$home/plugins/maven/maven3-server-impl/lib/maven3")
384       }
385
386       dir("maven2-server-lib") {
387         fileset(dir: "$home/lib/") { include(name: "jaxb*.jar")}
388         fileset(dir: "$home/plugins/maven/maven2-server-impl/lib") {include(name: "*.jar")}
389       }
390       dir("maven2") {
391         fileset(dir: "$home/plugins/maven/maven2-server-impl/lib/maven2")
392       }
393
394       fileset(dir: "$home/plugins/maven/lib")
395       fileset(dir: "$home/plugins/maven/maven-server-api/lib")
396     }
397
398     layoutPlugin("gradle") {
399       jar("gradle-jps-plugin.jar") {
400         module("gradle-jps-plugin")
401       }
402
403       jar("gradle-tooling-extension-api.jar") {
404         module("gradle-tooling-extension-api")
405       }
406
407       jar("gradle-tooling-extension-impl.jar") {
408         module("gradle-tooling-extension-impl")
409       }
410       fileset(dir: "$home/plugins/gradle/lib") { include(name: "*.jar") }
411       // add kryo lib
412       fileset(dir: "$home/lib/") {
413         include(name: "kryo-*.jar")
414         include(name: "reflectasm-*.jar")
415         include(name: "objenesis-*.jar")
416         include(name: "minlog-*.jar")
417       }
418     }
419
420     layoutPlugin("git4idea") {
421       jar("git4idea-rt.jar") {
422         module("git4idea-rt")
423       }
424       jar("remote-servers-git.jar") {
425         moduleOptional("remote-servers-git")
426         moduleOptional("remote-servers-git-java")
427       }
428       fileset(dir: "$home/plugins/git4idea/lib") {
429         include(name: "trilead-ssh2.jar")
430       }
431       fileset(dir: "$home/plugins/git4idea/lib/ini4j") {
432         include(name: "ini4j*.jar")
433         exclude(name: "ini4j*sources.jar")
434       }
435     }
436
437     layoutPlugin("svn4idea") {
438       fileset(dir: "$home/plugins/svn4idea/lib") {
439         exclude(name: "svnkitsrc.zip")
440         exclude(name: "sqljetsrc.zip")
441         exclude(name: "svnkit-javahl16.zip")
442         exclude(name: "trileadsrc.zip")
443       }
444     }
445
446     layoutPlugin("junit", "junit", "idea-junit") {
447       jar("junit-rt.jar") {
448         module("junit_rt")
449       }
450       jar("junit5-rt.jar") {
451         module("junit5_rt")
452       }
453       fileset(dir: "$home/plugins/junit5_rt/lib") {
454         include(name: "*.jar")
455       }
456     }
457
458     pluginDir("ByteCodeViewer") {
459       dir("lib") {
460         jar("byteCodeViewer.jar") {
461           noResources("ByteCodeViewer")
462         }
463       }
464     }
465
466     pluginDir("cvsIntegration") {
467       dir("lib") {
468         jar("cvs_util.jar") {noResources("cvs-core")}
469         jar("cvsIntegration.jar") {noResources("cvs-plugin")}
470         jar("javacvs-src.jar") {noResources("javacvs-src")}
471         jar("smartcvs-src.jar") {noResources("smartcvs-src")}
472
473         resources(["cvs-core", "cvs-plugin", "javacvs-src", "smartcvs-src"])
474
475         fileset(dir: "${home}/plugins/cvs/lib")
476       }
477     }
478
479     pluginDir("testng") {
480       dir("lib") {
481         jar("testng-plugin.jar") {
482           noResources("testng")
483           noResources("testng_rt")
484         }
485
486         resources("testng")
487
488         fileset(dir: "$home/plugins/testng/lib") {
489           include(name: "testng.jar")
490           include(name: "jcommander.jar")
491         }
492       }
493     }
494
495     layoutPlugin("xpath") {
496       dir("rt") {
497         jar("xslt-rt.jar") {module("xslt-rt")}
498       }
499     }
500
501     layoutPlugin("xslt-debugger") {
502       jar("xslt-debugger-engine.jar") {
503         module("xslt-debugger-engine") {
504           excludes: "lib"
505         }
506       }
507       fileset(dir: "$home/plugins/xslt-debugger/engine/lib") {
508         include(name: "**/rmi-stubs.jar")
509       }
510       dir("rt") {
511         jar("xslt-debugger-engine-impl.jar") {
512           module("xslt-debugger-engine-impl") {
513             exclude(name: "lib")
514             exclude(name: "**/*.jar")
515             exclude(name: "**/*.html")
516           }
517         }
518         fileset(dir: "$home/plugins/xslt-debugger/engine/impl/lib") {
519           include(name: "**/*.jar")
520           exclude(name: "**/rmi-stubs.jar")
521           include(name: "**/*.html")
522         }
523       }
524     }
525
526     pluginDir("Groovy") {
527       dir("lib") {
528         jar("Groovy.jar") {
529           module("jetgroovy")
530           module("groovy-psi") {
531             exclude(name: "standardDsls/**")
532           }
533           module("structuralsearch-groovy")
534         }
535         //layout of groovy jars must be consistent with GroovyBuilder.getGroovyRtRoot method
536         jar("groovy-jps-plugin.jar") {
537           module("groovy-jps-plugin")
538         }
539         jar("groovy_rt.jar") {
540           module("groovy_rt")
541         }
542         jar("groovy-rt-constants.jar") {
543           module("groovy-rt-constants")
544         }
545         dir("standardDsls") {
546           fileset(dir: "$home/plugins/groovy/groovy-psi/resources/standardDsls")
547         }
548         dir("agent") {
549           fileset(dir: "${home}/plugins/groovy/hotswap") {
550             include(name: "gragent.jar")
551           }
552         }
553
554
555         fileset(dir: "$home/plugins/groovy/groovy-psi/resources/conf")
556       }
557     }
558
559     pluginDir("tasks") {
560       dir("lib") {
561         jar("tasks-api.jar") { module("tasks-api") }
562         jar("jira.jar") { module("jira") }
563         jar("tasks-core.jar") { module("tasks-core") }
564         jar("jira.jar") { module("jira") }
565         jar("tasks-java.jar") { moduleOptional("tasks-java") }
566         fileset(dir: "${home}/plugins/tasks/tasks-core/lib") {
567           include(name: "**/*.jar")
568         }
569       }
570     }
571
572     layoutPlugin("devkit") {
573       jar("devkit-jps-plugin.jar") {
574         module("devkit-jps-plugin")
575       }
576       fileset(dir: "${home}/plugins/devkit/lib") {
577         include(name: "**/*.jar")
578       }
579     }
580     layoutPlugin("eclipse") {
581       jar("eclipse-jps-plugin.jar") {
582         module("eclipse-jps-plugin")
583       }
584       jar("common-eclipse-util.jar") {
585         module("common-eclipse-util")
586       }
587     }
588
589     layoutPlugin("terminal") {
590       fileset(dir: "$home/plugins/terminal/lib") {
591         include(name: "*.jar")
592         include(name: "*.in")
593       }
594     }
595
596     layoutPlugin("editorconfig") {
597       fileset(dir: "$home/plugins/editorconfig/lib") {
598         include(name: "**/*.jar")
599       }
600     }
601
602     pluginDir("coverage") {
603       dir("lib") {
604         jar("coverage.jar") {
605           noResources("coverage-common")
606           noResources("coverage")
607         }
608
609         jar("coverage_rt.jar") {
610           noResources("coverage_rt")
611         }
612
613         jar("resources_en.jar") {
614           module("coverage-common") {
615             patternset(refid: "resources.included")
616           }
617           module("coverage") {
618             patternset(refid: "resources.included")
619           }
620         }
621
622         fileset(dir: "${home}/plugins/coverage/lib", excludes: "**/jacoco_src.zip")
623       }
624     }
625
626     pluginDir("java-decompiler") {
627       dir("lib") {
628         jar("java-decompiler.jar") {
629           module("java-decompiler-engine")
630           module("java-decompiler-plugin")
631         }
632       }
633     }
634
635     pluginDir("Kotlin") {
636       fileset(dir: "${home}/build/kotlinc/plugin/Kotlin")
637     }
638
639     layoutPlugin("settings-repository") {
640       fileset(dir: "$home/plugins/settings-repository/lib", excludes: "**/*-sources.jar,**/*.xml,**/com/**,**/org/**,**/java/**,**/dev/**")
641     }
642
643     pluginDir("yaml") {
644       dir("lib") {
645         jar("yaml.jar") {
646           noResources("yaml")
647           module("yaml")
648         }
649         resources("yaml")
650       }
651     }
652
653   }
654 }
655
656 def setPluginVersionAndSince(String moduleName, String version) {
657   def file = new File(projectBuilder.moduleOutput(findModule(moduleName)) + "/META-INF/plugin.xml")
658   if (file.isFile()) {
659     def text = file.text
660     if (!text.contains("<version>")) {
661       def dotIndex = version.indexOf('.')
662       def untilBuild = dotIndex > 0 ? Integer.parseInt(version.substring(0, dotIndex)) + ".*" : version
663       def anchor = text.contains("</id>") ? "</id>" : "</name>"
664       file.text = text.replace(anchor, "${anchor}\n  <version>${version}</version>\n  <idea-version since-build=\"${version}\" until-build=\"${untilBuild}\"/>\n")
665     }
666   }
667 }
668
669 def layoutPlugin(String moduleName) {
670   layoutPlugin(moduleName, moduleName, {})
671 }
672
673 def layoutPlugin(String moduleName, Closure custom) {
674   layoutPlugin(moduleName, moduleName, custom)
675 }
676
677 def layoutPlugin(String pluginName, String moduleName) {
678   layoutPlugin(pluginName, moduleName, {})
679 }
680
681 def layoutPlugin(String pluginName, String moduleName, Closure custom) {
682   layoutPlugin(pluginName, moduleName, pluginName, custom)
683 }
684
685 def layoutPlugin(String pluginName, String moduleName, String jarName) {
686   layoutPlugin(pluginName, moduleName, jarName, {})
687 }
688
689 def layoutPlugin(String pluginName, String moduleName, String jarName, Closure custom) {
690   if (isDefined("pluginFilter")) {
691     if (!pluginFilter.contains(moduleName) && !pluginFilter.contains(pluginName)) return
692   }
693
694   def excludedPlugins = getExcludedPlugins()
695   if (excludedPlugins.contains(moduleName) || excludedPlugins.contains(pluginName)) {
696     return
697   }
698
699   if (setPluginAndIDEVersionInPluginXml()) {
700     def version = requireProperty("buildNumber", requireProperty("build.number", snapshot))
701     //do not set 'until-build' for snapshot builds compiled locally. Otherwise if you build from sources of e.g. 145 branch you'll get
702     // 'until-build=146.0' in plugin.xml in module outputs and won't be able to run IDE from sources of 'master' branch.
703     if (!version.toLowerCase().endsWith("snapshot")) {
704       setPluginVersionAndSince(moduleName, version)
705     }
706   }
707
708   dir(pluginName) {
709     dir("lib") {
710       jar("${jarName}.jar") {
711         noResources(moduleName)
712       }
713
714       resources(moduleName)
715       custom()
716     }
717   }
718 }
719
720 def pluginDir(String dirName, Closure initializer) {
721   if (isDefined("pluginFilter")) {
722     if (!pluginFilter.contains(dirName)) return
723   }
724
725   def excludedPlugins = getExcludedPlugins()
726   if (excludedPlugins.contains(dirName)) {
727     return
728   }
729
730   dir(dirName) {
731     initializer()
732   }
733 }
734
735 private def resources(List<String> modules) {
736   jar("resources_en.jar") {
737     modules.each {
738       module(it) {
739         patternset(refid: "resources.included")
740       }
741     }
742   }
743 }
744
745 private def resources(String moduleName) {
746   jar("resources_en.jar") {
747     module(moduleName) {
748       patternset(refid: "resources.included")
749     }
750   }
751 }
752
753 private def noResources(String moduleName) {
754   module(moduleName) {
755     patternset(refid: "resources.excluded")
756   }
757 }
758
759 def moduleOptional(String name) {
760   if (isDefined("pluginFilter")) {
761     if (!pluginFilter.contains(name)) return
762   }
763
764   module(name)
765 }
766
767 def moduleOptional(String name, Closure init) {
768   if (isDefined("pluginFilter")) {
769     if (!pluginFilter.contains(name)) return
770   }
771
772   module(name, init)
773 }
774
775 def reorder(String home, String targetDirectory) {
776   projectBuilder.info("Reordering JARs in $targetDirectory")
777   ant.java(classname: "com.intellij.util.io.zip.ReorderJarsMain", fork: true, failonerror: true) {
778     arg(value: "${home}/build/order.txt")
779     arg(value: targetDirectory)
780     arg(value: targetDirectory)
781     arg(value: "${home}/lib")
782     classpath {
783       projectBuilder.moduleRuntimeClasspath(findModule("util"), false).each {
784         pathelement(location: it)
785       }
786     }
787   }
788 }
789
790 /**
791  * @deprecated this method isn't used in new build scripts (it's still used in Android Studio build scripts which aren't rewritten yet);
792  * layout of Android plugin in specified in {@link org.jetbrains.intellij.build.CommunityRepositoryModules}
793  */
794 def layoutAndroid(String androidHome, String androidToolsBaseHome) {
795   dir("plugins") {
796     layoutPlugin("android") {
797       fileset(dir: "$androidHome/lib") {
798         include(name: "**/*.jar")
799         exclude(name: "**/fest-*.jar")
800         exclude(name: "src/*.jar")
801       }
802
803       jar("android-common.jar") {
804         module("android-common")
805       }
806
807       jar("android-rt.jar") {
808         module("android-rt")
809       }
810
811       jar("common.jar") {
812         module("common")
813       }
814       jar("sdklib.jar") {
815         module("sdklib")
816       }
817       jar("sdk-common.jar") {
818         module("sdk-common")
819       }
820       jar("layoutlib-api.jar") {
821         module("layoutlib-api")
822       }
823       jar("manifest-merger.jar") {
824         module("manifest-merger")
825       }
826       jar("repository.jar") {
827         module("repository")
828       }
829       jar("sdk-tools.jar") {
830         module("assetstudio")
831         module("ddmlib")
832         module("dvlib")
833         module("draw9patch")
834         module("lint-api")
835         module("lint-checks")
836         module("ninepatch")
837         module("perflib")
838         module("rpclib")
839         module("chartlib")
840         module("builder-model")
841         module("builder-test-api")
842         module("instant-run-common")
843         module("instant-run-client")
844         module("instant-run-runtime")
845       }
846       jar("androidAnnotations.jar") {
847         fileset(dir: "$androidHome/annotations")
848       }
849       dir("jps") {
850         jar("android-gradle-jps.jar") { module("android-gradle-jps") }
851       }
852       dir("device-art-resources") {
853         fileset(dir: "$androidHome/device-art-resources")
854       }
855
856       dir("jps") {
857         jar("android-jps-plugin.jar") { module("android-jps-plugin") }
858       }
859       dir("templates") {
860         fileset(dir: "$androidToolsBaseHome/templates")
861       }
862     }
863   }
864 }
865
866 def layoutJps(String home, String targetDir, String buildNumber, Closure additionalJars) {
867   layout(targetDir) {
868     zip("standalone-jps-${buildNumber}.zip") {
869       jar("util.jar") {
870         module("annotations-common")
871         module("annotations")
872         module("util-rt")
873         module("util")
874       }
875
876       jar("jps-launcher.jar") {
877         module("jps-launcher")
878       }
879
880       jar("jps-model.jar") {
881         module("jps-model-api")
882         module("jps-model-impl")
883         module("jps-model-serialization")
884       }
885       jar("jps-builders.jar") {
886         module("forms_rt")
887         module("forms-compiler")
888         module("instrumentation-util")
889         module("instrumentation-util-8")
890         module("jps-builders")
891         module("jps-standalone-builder")
892         module("java-runtime")
893       }
894       jar("jps-plugin-system.jar") {
895         module("jps-plugin-system")
896       }
897       //layout of groovy jars must be consistent with GroovyBuilder.getGroovyRtRoots method
898       jar("groovy-jps-plugin.jar") {
899         module("groovy-jps-plugin")
900       }
901       jar("groovy_rt.jar") {
902         module("groovy_rt")
903       }
904       jar("groovy-rt-constants.jar") {
905         module("groovy-rt-constants")
906       }
907       jar("ui-designer-jps-plugin.jar") { module("ui-designer-jps-plugin") }
908
909
910       jar("maven-jps-plugin.jar") { module("maven-jps-plugin") }
911       jar("aether-dependency-resolver.jar") { module("aether-dependency-resolver") }
912       fileset(dir: "$home/plugins/maven/lib") {
913         include(name: "aether-*.jar")
914         include(name: "maven-aether-provider-*.jar")
915       }
916       jar("gradle-jps-plugin.jar") { module("gradle-jps-plugin") }
917       fileset(dir: "$home/plugins/maven/maven30-server-impl/lib/maven3/lib") {include(name: "plexus-utils-*.jar")}
918
919       jar("eclipse-jps-plugin.jar") {
920         module("common-eclipse-util")
921         module("eclipse-jps-plugin")
922       }
923       jar("devkit-jps-plugin.jar") { module("devkit-jps-plugin") }
924       jar("intellilang-jps-plugin.jar") { module("intellilang-jps-plugin") }
925       fileset(dir: "$home/lib") {
926         include(name: "jdom.jar")
927         include(name: "jna.jar")
928         include(name: "trove4j.jar")
929         include(name: "asm-all.jar")
930         include(name: "nanoxml-*.jar")
931         include(name: "protobuf-*.jar")
932         include(name: "cli-parser-*.jar")
933         include(name: "log4j.jar")
934         include(name: "jgoodies-forms.jar")
935         include(name: "ecj*.jar")
936         include(name: "netty-all-*.jar")
937         include(name: "snappy-in-java-*.jar")
938       }
939       fileset(dir: "$home/jps/lib") {
940         include(name: "optimizedFileManager.jar")
941       }
942       jar("ant-jps-plugin.jar") { module("ant-jps-plugin") }
943       additionalJars()
944     }
945     jar("jps-build-test-${buildNumber}.jar") {
946       moduleTests("jps-builders")
947       moduleTests("jps-model-tests")
948       moduleTests("jps-serialization-tests")
949     }
950   }
951 }
952
953 def layout_core(String home, String target) {
954   layout(target) {
955     jar("intellij-core.jar") {
956       module("util-rt")
957       module("util")
958       module("core-api")
959       module("core-impl")
960       module("extensions")
961       module("java-psi-api")
962       module("java-psi-impl")
963     }
964
965     jar("annotations.jar") {
966       module("annotations-common")
967       module("annotations")
968     }
969
970     jar("intellij-core-analysis.jar") {
971       analysisApiModules.each { module it; }
972       analysisImplModules.each { module it; }
973     }
974
975     fileset(dir: "$home/lib") {
976       include(name: "guava-19.0.jar")
977       include(name: "picocontainer.jar")
978       include(name: "trove4j.jar")
979       include(name: "cli-parser-1.1.jar")
980       include(name: "snappy-in-java-0.5.1.jar")
981       include(name: "jayatana-1.2.4.jar")
982       include(name: "imgscalr-lib-4.2.jar")
983       include(name: "batik-all.jar")
984       include(name: "xmlgraphics-commons-1.5.jar")
985       include(name: "xml-apis-ext.jar")
986     }
987   }
988 }