2315313db58a081261fa1c4ff0b988979b158041
[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         module("javac-ref-scanner-8")
213       }
214
215       jar("jps-model.jar") {
216         jpsCommonModules.each { module it }
217       }
218       jar("jps-builders.jar") {
219         module("jps-builders")
220       }
221
222       fileset(dir: "$home/jps/lib") {
223         include(name: "optimizedFileManager.jar")
224       }
225
226       fileset(dir: "$home/lib", includesfile: "${home}/lib/required_for_dist.txt")
227
228       fileset(dir: "$home/build/kotlinc/lib") {
229         include(name: "kotlin-runtime.jar")
230         include(name: "kotlin-reflect.jar")
231       }
232
233       fileset(dir: "$home/xml/relaxng/lib", includes: "*.jar")
234
235       dir("ant") {
236         fileset(dir: "$home/lib/ant") {
237           exclude(name: "**/src/**")
238         }
239       }
240     }
241
242     dir("redist") {
243       jar("annotations-java8.jar") {
244         module("annotations-common")
245         module("annotations-java8")
246       }
247     }
248
249     layoutCommunityPlugins(home, context)
250
251     dir("plugins") {
252       dir("javaFX") {
253         dir("lib") {
254           jar("javaFX.jar") {
255             noResources("javaFX")
256             noResources("javaFX-CE")
257           }
258           resources(["javaFX", "javaFX-CE"])
259           jar("javaFX-jps-plugin.jar") {
260             module("javaFX-jps-plugin")
261           }
262           jar("common-javaFX-plugin.jar") {
263             module("common-javaFX-plugin")
264           }
265           fileset(dir: "${home}/plugins/javaFX/lib", includes: "SceneBuilderKit-8.1.1.jar");
266         }
267       }
268     }
269
270     dir("plugins") {
271       dir("IntelliLang") {
272         dir("lib") {
273           jar("IntelliLang.jar") {
274             module("IntelliLang")
275             module("IntelliLang-java")
276             module("IntelliLang-xml")
277           }
278           jar("intellilang-jps-plugin.jar") {
279             module("intellilang-jps-plugin")
280           }
281         }
282       }
283     }
284   }
285
286   reorder(home, targetDirectory)
287   return info
288 }
289
290 /**
291  * @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
292  * in third-party products); specify non-trivial layout of plugins in {@link org.jetbrains.intellij.build.CommunityRepositoryModules} instead
293  */
294 public def layoutCommunityPlugins(String home, BuildContext buildContext = null) {
295   if (!isDefined("pluginFilter") || pluginFilter.contains("android")) {
296     if (buildContext == null) {
297       projectBuilder.error("Cannot build Android plugin: buildContext isn't defined")
298     }
299     def androidModule = buildContext.findModule("android")
300     def sdklibModule = buildContext.findModule("sdklib")
301     if (androidModule == null) projectBuilder.error("Cannot build Android plugin: 'android' module isn't included into the project")
302     if (sdklibModule == null) projectBuilder.error("Cannot build Android plugin: 'sdklib' module isn't included into the project")
303
304     def androidHome = JpsPathUtil.urlToPath(androidModule.contentRootsList.urls.first())
305     def androidToolsBaseHome = JpsPathUtil.urlToFile(sdklibModule.contentRootsList.urls.first()).parentFile.canonicalPath
306     [androidHome, androidToolsBaseHome].each {
307       if (!new File(it).exists()) projectBuilder.error("Cannot build Android plugin: $it doesn't exist")
308     }
309     layoutAndroid(androidHome, androidToolsBaseHome)
310   }
311
312   dir("plugins") {
313     def simplePlugins = ["copyright", "java-i18n", "hg4idea", "github"] //, "tasks-time-tracking"]
314
315     simplePlugins.each {
316       layoutPlugin it
317     }
318
319     layoutPlugin("ant", "ant", "antIntegration") {
320       jar("ant-jps-plugin.jar") {
321         module("ant-jps-plugin")
322       }
323     }
324     layoutPlugin("uiDesigner", "ui-designer", "uiDesigner") {
325       dir("jps") {
326         jar("ui-designer-jps-plugin.jar") {
327           module("ui-designer-jps-plugin")
328         }
329       }
330     }
331
332     pluginDir("properties") {
333       dir("lib") {
334         jar("properties.jar") {
335           module("properties-psi-api")
336           module("properties-psi-impl")
337           module("properties")
338         }
339       }
340     }
341
342     layoutPlugin("maven") {
343       jar("maven-jps-plugin.jar") {
344         module("maven-jps-plugin")
345       }
346       jar("aether-dependency-resolver.jar") {
347         module("aether-dependency-resolver")
348       }
349       jar("maven-server-api.jar") {
350         module("maven-server-api")
351       }
352       jar("maven2-server-impl.jar") {
353         module("maven2-server-impl")
354       }
355       jar("maven3-server-common.jar") {
356         module("maven3-server-common")
357       }
358       jar("maven30-server-impl.jar") {
359         module("maven30-server-impl")
360       }
361       jar("maven3-server-impl.jar") {
362         module("maven3-server-impl")
363       }
364
365       jar("artifact-resolver-m2.jar") {
366         module("maven-artifact-resolver-m2")
367         module("maven-artifact-resolver-common")
368       }
369
370       jar("artifact-resolver-m3.jar") {
371         module("maven-artifact-resolver-m3")
372         module("maven-artifact-resolver-common")
373       }
374
375       jar("artifact-resolver-m31.jar") {
376         module("maven-artifact-resolver-m31")
377         module("maven-artifact-resolver-common")
378       }
379
380       dir("maven3-server-lib") {
381         fileset(dir: "$home/plugins/maven/maven3-server-common/lib") {include(name: "*.jar")}
382       }
383       dir("maven3") {
384         fileset(dir: "$home/plugins/maven/maven3-server-impl/lib/maven3")
385       }
386
387       dir("maven2-server-lib") {
388         fileset(dir: "$home/lib/") { include(name: "jaxb*.jar")}
389         fileset(dir: "$home/plugins/maven/maven2-server-impl/lib") {include(name: "*.jar")}
390       }
391       dir("maven2") {
392         fileset(dir: "$home/plugins/maven/maven2-server-impl/lib/maven2")
393       }
394
395       fileset(dir: "$home/plugins/maven/lib")
396       fileset(dir: "$home/plugins/maven/maven-server-api/lib")
397     }
398
399     layoutPlugin("gradle") {
400       jar("gradle-jps-plugin.jar") {
401         module("gradle-jps-plugin")
402       }
403
404       jar("gradle-tooling-extension-api.jar") {
405         module("gradle-tooling-extension-api")
406       }
407
408       jar("gradle-tooling-extension-impl.jar") {
409         module("gradle-tooling-extension-impl")
410       }
411       fileset(dir: "$home/plugins/gradle/lib") { include(name: "*.jar") }
412       // add kryo lib
413       fileset(dir: "$home/lib/") {
414         include(name: "kryo-*.jar")
415         include(name: "reflectasm-*.jar")
416         include(name: "objenesis-*.jar")
417         include(name: "minlog-*.jar")
418       }
419     }
420
421     layoutPlugin("git4idea") {
422       jar("git4idea-rt.jar") {
423         module("git4idea-rt")
424       }
425       jar("remote-servers-git.jar") {
426         moduleOptional("remote-servers-git")
427         moduleOptional("remote-servers-git-java")
428       }
429       fileset(dir: "$home/plugins/git4idea/lib") {
430         include(name: "trilead-ssh2.jar")
431       }
432       fileset(dir: "$home/plugins/git4idea/lib/ini4j") {
433         include(name: "ini4j*.jar")
434         exclude(name: "ini4j*sources.jar")
435       }
436     }
437
438     layoutPlugin("svn4idea") {
439       fileset(dir: "$home/plugins/svn4idea/lib") {
440         exclude(name: "svnkitsrc.zip")
441         exclude(name: "sqljetsrc.zip")
442         exclude(name: "svnkit-javahl16.zip")
443         exclude(name: "trileadsrc.zip")
444       }
445     }
446
447     layoutPlugin("junit", "junit", "idea-junit") {
448       jar("junit-rt.jar") {
449         module("junit_rt")
450       }
451       jar("junit5-rt.jar") {
452         module("junit5_rt")
453       }
454       fileset(dir: "$home/plugins/junit5_rt/lib") {
455         include(name: "*.jar")
456       }
457     }
458
459     pluginDir("ByteCodeViewer") {
460       dir("lib") {
461         jar("byteCodeViewer.jar") {
462           noResources("ByteCodeViewer")
463         }
464       }
465     }
466
467     pluginDir("cvsIntegration") {
468       dir("lib") {
469         jar("cvs_util.jar") {noResources("cvs-core")}
470         jar("cvsIntegration.jar") {noResources("cvs-plugin")}
471         jar("javacvs-src.jar") {noResources("javacvs-src")}
472         jar("smartcvs-src.jar") {noResources("smartcvs-src")}
473
474         resources(["cvs-core", "cvs-plugin", "javacvs-src", "smartcvs-src"])
475
476         fileset(dir: "${home}/plugins/cvs/lib")
477       }
478     }
479
480     pluginDir("testng") {
481       dir("lib") {
482         jar("testng-plugin.jar") {
483           noResources("testng")
484           noResources("testng_rt")
485         }
486
487         resources("testng")
488
489         fileset(dir: "$home/plugins/testng/lib") {
490           include(name: "testng.jar")
491           include(name: "jcommander.jar")
492         }
493       }
494     }
495
496     layoutPlugin("xpath") {
497       dir("rt") {
498         jar("xslt-rt.jar") {module("xslt-rt")}
499       }
500     }
501
502     layoutPlugin("xslt-debugger") {
503       jar("xslt-debugger-engine.jar") {
504         module("xslt-debugger-engine") {
505           excludes: "lib"
506         }
507       }
508       fileset(dir: "$home/plugins/xslt-debugger/engine/lib") {
509         include(name: "**/rmi-stubs.jar")
510       }
511       dir("rt") {
512         jar("xslt-debugger-engine-impl.jar") {
513           module("xslt-debugger-engine-impl") {
514             exclude(name: "lib")
515             exclude(name: "**/*.jar")
516             exclude(name: "**/*.html")
517           }
518         }
519         fileset(dir: "$home/plugins/xslt-debugger/engine/impl/lib") {
520           include(name: "**/*.jar")
521           exclude(name: "**/rmi-stubs.jar")
522           include(name: "**/*.html")
523         }
524       }
525     }
526
527     pluginDir("Groovy") {
528       dir("lib") {
529         jar("Groovy.jar") {
530           module("jetgroovy")
531           module("groovy-psi") {
532             exclude(name: "standardDsls/**")
533           }
534           module("structuralsearch-groovy")
535         }
536         //layout of groovy jars must be consistent with GroovyBuilder.getGroovyRtRoot method
537         jar("groovy-jps-plugin.jar") {
538           module("groovy-jps-plugin")
539         }
540         jar("groovy_rt.jar") {
541           module("groovy_rt")
542         }
543         jar("groovy-rt-constants.jar") {
544           module("groovy-rt-constants")
545         }
546         dir("standardDsls") {
547           fileset(dir: "$home/plugins/groovy/groovy-psi/resources/standardDsls")
548         }
549         dir("agent") {
550           fileset(dir: "${home}/plugins/groovy/hotswap") {
551             include(name: "gragent.jar")
552           }
553         }
554
555
556         fileset(dir: "$home/plugins/groovy/groovy-psi/resources/conf")
557       }
558     }
559
560     pluginDir("tasks") {
561       dir("lib") {
562         jar("tasks-api.jar") { module("tasks-api") }
563         jar("jira.jar") { module("jira") }
564         jar("tasks-core.jar") { module("tasks-core") }
565         jar("jira.jar") { module("jira") }
566         jar("tasks-java.jar") { moduleOptional("tasks-java") }
567         fileset(dir: "${home}/plugins/tasks/tasks-core/lib") {
568           include(name: "**/*.jar")
569         }
570       }
571     }
572
573     layoutPlugin("devkit") {
574       jar("devkit-jps-plugin.jar") {
575         module("devkit-jps-plugin")
576       }
577       fileset(dir: "${home}/plugins/devkit/lib") {
578         include(name: "**/*.jar")
579       }
580     }
581     layoutPlugin("eclipse") {
582       jar("eclipse-jps-plugin.jar") {
583         module("eclipse-jps-plugin")
584       }
585       jar("common-eclipse-util.jar") {
586         module("common-eclipse-util")
587       }
588     }
589
590     layoutPlugin("terminal") {
591       fileset(dir: "$home/plugins/terminal/lib") {
592         include(name: "*.jar")
593         include(name: "*.in")
594       }
595     }
596
597     layoutPlugin("editorconfig") {
598       fileset(dir: "$home/plugins/editorconfig/lib") {
599         include(name: "**/*.jar")
600       }
601     }
602
603     pluginDir("coverage") {
604       dir("lib") {
605         jar("coverage.jar") {
606           noResources("coverage-common")
607           noResources("coverage")
608         }
609
610         jar("coverage_rt.jar") {
611           noResources("coverage_rt")
612         }
613
614         jar("resources_en.jar") {
615           module("coverage-common") {
616             patternset(refid: "resources.included")
617           }
618           module("coverage") {
619             patternset(refid: "resources.included")
620           }
621         }
622
623         fileset(dir: "${home}/plugins/coverage/lib", excludes: "**/jacoco_src.zip")
624       }
625     }
626
627     pluginDir("java-decompiler") {
628       dir("lib") {
629         jar("java-decompiler.jar") {
630           module("java-decompiler-engine")
631           module("java-decompiler-plugin")
632         }
633       }
634     }
635
636     pluginDir("Kotlin") {
637       fileset(dir: "${home}/build/kotlinc/plugin/Kotlin")
638     }
639
640     layoutPlugin("settings-repository") {
641       fileset(dir: "$home/plugins/settings-repository/lib", excludes: "**/*-sources.jar,**/*.xml,**/com/**,**/org/**,**/java/**,**/dev/**")
642     }
643
644     pluginDir("yaml") {
645       dir("lib") {
646         jar("yaml.jar") {
647           noResources("yaml")
648           module("yaml")
649         }
650         resources("yaml")
651       }
652     }
653
654   }
655 }
656
657 def setPluginVersionAndSince(String moduleName, String version) {
658   def file = new File(projectBuilder.moduleOutput(findModule(moduleName)) + "/META-INF/plugin.xml")
659   if (file.isFile()) {
660     def text = file.text
661     if (!text.contains("<version>")) {
662       def dotIndex = version.indexOf('.')
663       def untilBuild = dotIndex > 0 ? Integer.parseInt(version.substring(0, dotIndex)) + ".*" : version
664       def anchor = text.contains("</id>") ? "</id>" : "</name>"
665       file.text = text.replace(anchor, "${anchor}\n  <version>${version}</version>\n  <idea-version since-build=\"${version}\" until-build=\"${untilBuild}\"/>\n")
666     }
667   }
668 }
669
670 def layoutPlugin(String moduleName) {
671   layoutPlugin(moduleName, moduleName, {})
672 }
673
674 def layoutPlugin(String moduleName, Closure custom) {
675   layoutPlugin(moduleName, moduleName, custom)
676 }
677
678 def layoutPlugin(String pluginName, String moduleName) {
679   layoutPlugin(pluginName, moduleName, {})
680 }
681
682 def layoutPlugin(String pluginName, String moduleName, Closure custom) {
683   layoutPlugin(pluginName, moduleName, pluginName, custom)
684 }
685
686 def layoutPlugin(String pluginName, String moduleName, String jarName) {
687   layoutPlugin(pluginName, moduleName, jarName, {})
688 }
689
690 def layoutPlugin(String pluginName, String moduleName, String jarName, Closure custom) {
691   if (isDefined("pluginFilter")) {
692     if (!pluginFilter.contains(moduleName) && !pluginFilter.contains(pluginName)) return
693   }
694
695   def excludedPlugins = getExcludedPlugins()
696   if (excludedPlugins.contains(moduleName) || excludedPlugins.contains(pluginName)) {
697     return
698   }
699
700   if (setPluginAndIDEVersionInPluginXml()) {
701     def version = requireProperty("buildNumber", requireProperty("build.number", snapshot))
702     //do not set 'until-build' for snapshot builds compiled locally. Otherwise if you build from sources of e.g. 145 branch you'll get
703     // 'until-build=146.0' in plugin.xml in module outputs and won't be able to run IDE from sources of 'master' branch.
704     if (!version.toLowerCase().endsWith("snapshot")) {
705       setPluginVersionAndSince(moduleName, version)
706     }
707   }
708
709   dir(pluginName) {
710     dir("lib") {
711       jar("${jarName}.jar") {
712         noResources(moduleName)
713       }
714
715       resources(moduleName)
716       custom()
717     }
718   }
719 }
720
721 def pluginDir(String dirName, Closure initializer) {
722   if (isDefined("pluginFilter")) {
723     if (!pluginFilter.contains(dirName)) return
724   }
725
726   def excludedPlugins = getExcludedPlugins()
727   if (excludedPlugins.contains(dirName)) {
728     return
729   }
730
731   dir(dirName) {
732     initializer()
733   }
734 }
735
736 private def resources(List<String> modules) {
737   jar("resources_en.jar") {
738     modules.each {
739       module(it) {
740         patternset(refid: "resources.included")
741       }
742     }
743   }
744 }
745
746 private def resources(String moduleName) {
747   jar("resources_en.jar") {
748     module(moduleName) {
749       patternset(refid: "resources.included")
750     }
751   }
752 }
753
754 private def noResources(String moduleName) {
755   module(moduleName) {
756     patternset(refid: "resources.excluded")
757   }
758 }
759
760 def moduleOptional(String name) {
761   if (isDefined("pluginFilter")) {
762     if (!pluginFilter.contains(name)) return
763   }
764
765   module(name)
766 }
767
768 def moduleOptional(String name, Closure init) {
769   if (isDefined("pluginFilter")) {
770     if (!pluginFilter.contains(name)) return
771   }
772
773   module(name, init)
774 }
775
776 def reorder(String home, String targetDirectory) {
777   projectBuilder.info("Reordering JARs in $targetDirectory")
778   ant.java(classname: "com.intellij.util.io.zip.ReorderJarsMain", fork: true, failonerror: true) {
779     arg(value: "${home}/build/order.txt")
780     arg(value: targetDirectory)
781     arg(value: targetDirectory)
782     arg(value: "${home}/lib")
783     classpath {
784       projectBuilder.moduleRuntimeClasspath(findModule("util"), false).each {
785         pathelement(location: it)
786       }
787     }
788   }
789 }
790
791 /**
792  * @deprecated this method isn't used in new build scripts (it's still used in Android Studio build scripts which aren't rewritten yet);
793  * layout of Android plugin in specified in {@link org.jetbrains.intellij.build.CommunityRepositoryModules}
794  */
795 def layoutAndroid(String androidHome, String androidToolsBaseHome) {
796   dir("plugins") {
797     layoutPlugin("android") {
798       fileset(dir: "$androidHome/lib") {
799         include(name: "**/*.jar")
800         exclude(name: "**/fest-*.jar")
801         exclude(name: "src/*.jar")
802       }
803
804       jar("android-common.jar") {
805         module("android-common")
806       }
807
808       jar("android-rt.jar") {
809         module("android-rt")
810       }
811
812       jar("common.jar") {
813         module("common")
814       }
815       jar("sdklib.jar") {
816         module("sdklib")
817       }
818       jar("sdk-common.jar") {
819         module("sdk-common")
820       }
821       jar("layoutlib-api.jar") {
822         module("layoutlib-api")
823       }
824       jar("manifest-merger.jar") {
825         module("manifest-merger")
826       }
827       jar("repository.jar") {
828         module("repository")
829       }
830       jar("sdk-tools.jar") {
831         module("assetstudio")
832         module("ddmlib")
833         module("dvlib")
834         module("draw9patch")
835         module("lint-api")
836         module("lint-checks")
837         module("ninepatch")
838         module("perflib")
839         module("rpclib")
840         module("chartlib")
841         module("builder-model")
842         module("builder-test-api")
843         module("instant-run-common")
844         module("instant-run-client")
845         module("instant-run-runtime")
846       }
847       jar("androidAnnotations.jar") {
848         fileset(dir: "$androidHome/annotations")
849       }
850       dir("jps") {
851         jar("android-gradle-jps.jar") { module("android-gradle-jps") }
852       }
853       dir("device-art-resources") {
854         fileset(dir: "$androidHome/device-art-resources")
855       }
856
857       dir("jps") {
858         jar("android-jps-plugin.jar") { module("android-jps-plugin") }
859       }
860       dir("templates") {
861         fileset(dir: "$androidToolsBaseHome/templates")
862       }
863     }
864   }
865 }
866
867 def layoutJps(String home, String targetDir, String buildNumber, Closure additionalJars) {
868   layout(targetDir) {
869     zip("standalone-jps-${buildNumber}.zip") {
870       jar("util.jar") {
871         module("annotations-common")
872         module("annotations")
873         module("util-rt")
874         module("util")
875       }
876
877       jar("jps-launcher.jar") {
878         module("jps-launcher")
879       }
880
881       jar("jps-model.jar") {
882         module("jps-model-api")
883         module("jps-model-impl")
884         module("jps-model-serialization")
885       }
886       jar("jps-builders.jar") {
887         module("forms_rt")
888         module("forms-compiler")
889         module("instrumentation-util")
890         module("instrumentation-util-8")
891         module("javac-ref-scanner-8")
892         module("jps-builders")
893         module("jps-standalone-builder")
894         module("java-runtime")
895       }
896       jar("jps-plugin-system.jar") {
897         module("jps-plugin-system")
898       }
899       //layout of groovy jars must be consistent with GroovyBuilder.getGroovyRtRoots method
900       jar("groovy-jps-plugin.jar") {
901         module("groovy-jps-plugin")
902       }
903       jar("groovy_rt.jar") {
904         module("groovy_rt")
905       }
906       jar("groovy-rt-constants.jar") {
907         module("groovy-rt-constants")
908       }
909       jar("ui-designer-jps-plugin.jar") { module("ui-designer-jps-plugin") }
910
911
912       jar("maven-jps-plugin.jar") { module("maven-jps-plugin") }
913       jar("aether-dependency-resolver.jar") { module("aether-dependency-resolver") }
914       fileset(dir: "$home/plugins/maven/lib") {
915         include(name: "aether-*.jar")
916         include(name: "maven-aether-provider-*.jar")
917       }
918       jar("gradle-jps-plugin.jar") { module("gradle-jps-plugin") }
919       fileset(dir: "$home/plugins/maven/maven30-server-impl/lib/maven3/lib") {include(name: "plexus-utils-*.jar")}
920
921       jar("eclipse-jps-plugin.jar") {
922         module("common-eclipse-util")
923         module("eclipse-jps-plugin")
924       }
925       jar("devkit-jps-plugin.jar") { module("devkit-jps-plugin") }
926       jar("intellilang-jps-plugin.jar") { module("intellilang-jps-plugin") }
927       fileset(dir: "$home/lib") {
928         include(name: "jdom.jar")
929         include(name: "jna.jar")
930         include(name: "trove4j.jar")
931         include(name: "asm-all.jar")
932         include(name: "nanoxml-*.jar")
933         include(name: "protobuf-*.jar")
934         include(name: "cli-parser-*.jar")
935         include(name: "log4j.jar")
936         include(name: "jgoodies-forms.jar")
937         include(name: "ecj*.jar")
938         include(name: "netty-all-*.jar")
939         include(name: "snappy-in-java-*.jar")
940       }
941       fileset(dir: "$home/jps/lib") {
942         include(name: "optimizedFileManager.jar")
943       }
944       jar("ant-jps-plugin.jar") { module("ant-jps-plugin") }
945       additionalJars()
946     }
947     jar("jps-build-test-${buildNumber}.jar") {
948       moduleTests("jps-builders")
949       moduleTests("jps-model-tests")
950       moduleTests("jps-serialization-tests")
951     }
952   }
953 }
954
955 def layout_core(String home, String target) {
956   layout(target) {
957     jar("intellij-core.jar") {
958       module("util-rt")
959       module("util")
960       module("core-api")
961       module("core-impl")
962       module("extensions")
963       module("java-psi-api")
964       module("java-psi-impl")
965     }
966
967     jar("annotations.jar") {
968       module("annotations-common")
969       module("annotations")
970     }
971
972     jar("intellij-core-analysis.jar") {
973       analysisApiModules.each { module it; }
974       analysisImplModules.each { module it; }
975     }
976
977     fileset(dir: "$home/lib") {
978       include(name: "guava-19.0.jar")
979       include(name: "picocontainer.jar")
980       include(name: "trove4j.jar")
981       include(name: "cli-parser-1.1.jar")
982       include(name: "snappy-in-java-0.5.1.jar")
983       include(name: "jayatana-1.2.4.jar")
984       include(name: "imgscalr-lib-4.2.jar")
985       include(name: "batik-all.jar")
986       include(name: "xmlgraphics-commons-1.5.jar")
987       include(name: "xml-apis-ext.jar")
988     }
989   }
990 }