CPP-434 Returns lost color schemes to plugin
[idea/community.git] / python / build / python_plugin_build.gant
1 import static org.jetbrains.jps.idea.IdeaProjectLoader.guessHome
2
3 setProperty("projectHome", guessHome(this as Script))
4 setProperty("home", projectHome)
5
6 includeTargets << new File("${projectHome}/build/scripts/utils.gant")
7
8 setProperty("outDir", "${projectHome}/out/python")
9 setProperty("ideaDir", "${outDir}/ideaCE")
10 requireProperty("ideaPath", ideaDir)
11
12 setProperty("pluginHelp", "${outDir}/help")
13
14 setProperty("buildNumber", requireProperty("build.number", snapshot))
15 setProperty("ideaBuildNumber", requireProperty("idea.build.number"))
16
17 setProperty("ideaSinceBuildNumber", ("${ideaBuildNumber}" =~ /(\d+\.[A-Z0-9]+)/)[0][1])
18
19 setProperty("ideaHomePacked", "${ideaDir}/jdk16") //compiled idea
20 setProperty("ideaHome", "${ideaDir}/jdk16/idea-IC-${ideaBuildNumber}") //compiled idea
21
22 setProperty("pluginHome", "${projectHome}/python")
23 setProperty("pluginRevision", "${buildNumber}")
24
25 setProperty("ideaLib", "${ideaHome}/lib")
26 setProperty("ideaPlugins", "${ideaHome}/plugins") //compiled plugins
27
28
29 setProperty("output", "${projectHome}/python/distCE")
30
31 setProperty("zipdir", "${output}/zip")
32 setProperty("plugindir", "${zipdir}/python")
33 setProperty("zipname", "python-community-${pluginRevision}.zip")
34
35 setProperty("srcDir", "${pluginHome}/src")
36
37 setProperty("classesRootDir", "${outDir}/classes")
38 setProperty("classesDir", "${classesRootDir}/python")
39
40 //Compiler options
41 setProperty("compilerDebug", "on")
42 setProperty("compilerGenerateNoWarnings", "off")
43 setProperty("compilerArgs", "")
44 setProperty("compilerMaxMemory", "256m")
45
46 ant.patternset(id: "resources.pt") {
47   include(name: "**/?*.properties")
48   include(name: "**/?*.template")
49   include(name: "**/?*.xml")
50   include(name: "**/?*.gif")
51   include(name: "**/?*.png")
52   include(name: "**/?*.txt")
53   include(name: "**/?*.jpeg")
54   include(name: "**/?*.jpg")
55   include(name: "**/?*.html")
56   include(name: "**/?*.dtd")
57   include(name: "**/?*.tld")
58   include(name: "**/?*.py")
59   include(name: "**/?*.ft")
60   include(name: "**/?*.dic")
61   exclude(name: "**/plugin.xml")
62 }
63
64 target(name: "clean", description: "Cleanup output") {
65   ant.echo("Cleaning ${output}")
66   ant.delete(dir: "${output}", failonerror: "false")
67   ant.echo("Cleaning ${classesRootDir}")
68   ant.delete(dir: "${classesRootDir}", failonerror: "false")
69   ant.echo("Cleaning ${ideaHome}")
70   ant.delete(dir: "${ideaHome}", failonerror: "false")          // out/python/idea/
71 }
72
73 target(name: "unzip") {
74   ant.mkdir(dir: "${ideaHomePacked}")
75   ant.gunzip(src: "${ideaPath}/ideaIC-${ideaBuildNumber}.tar.gz")
76   ant.untar(src: "${ideaPath}/ideaIC-${ideaBuildNumber}.tar", dest: "${ideaHomePacked}")
77 }
78
79 target(name: "compile", description: "Compile module python") {
80   depends("unzip")
81
82   ant.path(id: "classpath.lib") {
83     fileset(dir: "${ideaLib}") {
84       include(name: "?*.jar")
85     }
86     fileset(dir: "${ideaPlugins}/terminal/lib") {
87       include(name: "*.jar")
88     }
89     fileset(dir: "${ideaPlugins}/IntelliLang/lib") {
90       include(name: "*.jar")
91     }
92     fileset(dir: "${pluginHome}/ipnb/lib") {
93       include(name: "*.jar")
94     }
95   }
96
97   ant.path(id: "sourcepath") {
98     dirset(dir: "${pluginHome}") {
99       include(name: "src")
100       include(name: "gen")
101       include(name: "pluginCore")
102       include(name: "pluginJava")
103       include(name: "pydevSrc")
104       include(name: "openapi/src")
105       include(name: "psi-api/src")
106       include(name: "IntelliLang-python/src")
107       include(name: "ipnb/src")
108     }
109   }
110   //The task requires the following libraries from IntelliJ IDEA distribution:
111   //javac2.jar; jdom.jar; asm.jar; asm-commons.jar
112   ant.taskdef(name: "javac2", classname: "com.intellij.ant.Javac2") {
113     classpath {
114       fileset(dir: "${ideaLib}") {
115         include(name: "?*.jar")
116       }
117     }
118   }
119
120   ant.mkdir(dir: "${classesDir}")
121
122   //compile
123   ant.javac2(destdir: "${classesDir}",
124              debug: "${compilerDebug}",
125              nowarn: "${compilerGenerateNoWarnings}",
126              memorymaximumsize: "${compilerMaxMemory}",
127              fork: "true") {
128     compilerarg(line: "${compilerArgs}")
129     classpath(refid: "classpath.lib")
130     src(refid: "sourcepath")
131   }
132
133   //copy resources
134   ant.copy(todir: "${classesDir}") {
135     fileset(dir: "${pluginHome}/resources") {
136       patternset(refid: "resources.pt")
137       type(type: "file")
138     }
139     fileset(dir: "${pluginHome}/python-community-ide-resources/resources") {
140       patternset(refid: "resources.pt")
141       type(type: "file")
142     }
143     fileset(dir: "${pluginHome}/src") {
144       patternset(refid: "resources.pt")
145       type(type: "file")
146     }
147     fileset(dir: "${pluginHome}/psi-api/resources") {
148       patternset(refid: "resources.pt")
149       type(type: "file")
150     }
151     fileset(dir: "${pluginHome}/IntelliLang-python/resources") {
152       patternset(refid: "resources.pt")
153       type(type: "file")
154     }
155     fileset(dir: "${pluginHome}/IntelliLang-python/src") {
156       include(name: "resources/*.xml")
157     }
158     fileset(dir: "${home}/colorSchemes/src")
159     fileset(dir: "${pluginHome}/ipnb/resources") {
160       patternset(refid: "resources.pt")
161       type(type: "file")
162     }
163   }
164
165   //copy plugin.xml
166   ant.mkdir(dir: "${classesDir}/META-INF")
167   ant.copy(todir: "${classesDir}/META-INF") {
168     fileset(file: "${pluginHome}/pluginCore/META-INF/python-community-plugin-core.xml")
169     fileset(file: "${pluginHome}/pluginJava/META-INF/python-community-plugin-java.xml")
170     fileset(file: "${pluginHome}/pluginResources/META-INF/plugin.xml")
171     fileset(file: "${pluginHome}/build/python-plugin-dependencies.xml")
172   }
173
174   // set version to PyCharm current version from ApplicationInfo.xml
175   ant.loadfile(property: "appInfo", srcFile: "${pluginHome}/python-community-ide-resources/resources/idea/PyCharmCoreApplicationInfo.xml") {
176   }
177
178   major = ("${appInfo}" =~ /major\s*=\s*\"([^"])\"/)[0][1]
179   minor = ("${appInfo}" =~ /minor\s*=\s*\"([^"])\"/)[0][1]
180
181
182   ant.replaceregexp(file: "${classesDir}/META-INF/plugin.xml",
183                     match: "@@PYCHARM_VERSION@@",
184                     replace: "${major}.${minor}")
185
186   // set since-build to the current idea build number
187   ant.replace(file: "${classesDir}/META-INF/plugin.xml") {
188     replacefilter(token: "@@BUILD_NUMBER@@", value: "${buildNumber}")
189   }
190
191   ant.replaceregexp(file: "${classesDir}/META-INF/plugin.xml",
192                     match: "since-build=\"\\d+\\.\\d+\"",
193                     replace: "since-build=\"${ideaSinceBuildNumber}\"")
194 }
195
196 target(name: "jar", description: "Generate jar file") {
197   depends("compile")
198   ant.mkdir(dir: "${output}")
199   ant.jar(destfile: "${output}/python-community.jar", basedir: "${classesDir}") {
200     manifest() {
201       attribute(name: "Revision", value: "${pluginRevision}")
202       //<!--<attribute name="Build" value="${plugin.version}"/>-->
203     }
204   }
205 }
206
207 target(name: "zip", description: "Generate zip plugin file") {
208   depends("jar")
209
210   ant.mkdir(dir: "${zipdir}")
211
212   // copy plugin jar
213   ant.mkdir(dir: "${plugindir}/lib")
214   ant.move(file: "${output}/python-community.jar", todir: "${plugindir}/lib")
215
216   ant.copy(todir: "${plugindir}/lib") {
217     fileset(dir: "${pluginHome}/ipnb/lib") {
218       include(name: "*.jar")
219     }
220   }
221
222   ant.mkdir(dir: "${plugindir}/helpers")
223   ant.copy(todir: "${plugindir}/helpers") {
224     fileset(dir: "${pluginHome}/helpers") {
225       include(name: "**/*")
226     }
227   }
228
229   ant.mkdir(dir: "${plugindir}/help")
230   ant.copy(file: "${pluginHelp}/pytonpluginhelp.jar", tofile: "${plugindir}/help/pythonpluginhelp.jar", failonerror: false)
231   ant.copy(file: "${pluginHelp}/pytonpluginhelp_mac.jar", tofile: "${plugindir}/help/pythonpluginhelp_mac.jar", failonerror: false)
232
233   ant.zip(basedir: "${zipdir}", destfile: "${output}/${zipname}")
234 }
235
236 target(name: "build") {
237   depends("unzip")
238   depends("compile")
239 }
240
241 target(name: "dist", description: "main target") {
242   depends("clean")
243   depends("build")
244   depends("zip")
245 }
246
247 target('default': "Build artifacts") {
248   depends("dist")
249 }