Fix since-until build number in Python plugin for Rider Public EAP
[idea/community.git] / python / build / python_plugin_build.gant
1 import org.jetbrains.intellij.build.impl.BuildUtils
2 import org.jetbrains.jps.model.library.JpsOrderRootType
3
4 import static org.jetbrains.jps.idea.IdeaProjectLoader.guessHome
5
6 setProperty("projectHome", guessHome(this as Script))
7
8 includeTargets << new File("${projectHome}/build/scripts/utils.gant")
9
10 setProperty("dryRun", false)
11
12 setProperty("communityHome", "${projectHome}/python")
13
14 setProperty("pythonPluginVersion", requireProperty("build.number", snapshot))
15
16 def buildModules(List modules, List libDirs) {
17   def forbiddenJars = [
18     "/dev/", "/rt/", "/ant/",
19     "ls-client-api", "/ideaLicenseDecoder", "jcip-annotations",
20     "/eawtstub.jar", "/y.jar", "/ysvg.jar"
21   ]
22
23   def normalizedHome = home.replace('\\', '/')
24   def approvedJars = ["$normalizedHome/lib/", "$normalizedHome/xml/relaxng/lib/"]
25   libDirs.each { approvedJars.add("$normalizedHome/$it/") }
26
27   buildModulesAndCollectUsedJars(modules, approvedJars, forbiddenJars)
28 }
29
30
31 target('default': "Build Python Plugin") {
32   def pythonHome = "$home/python"
33   ant.property(file: "$pythonHome/build/build-plugin.properties")
34   BuildUtils.addToClassPath("$home/python/build/groovy", ant)
35
36   def communityModules = [
37     "IntelliLang-python",
38     "ipnb",
39     "python-openapi",
40     "python-community-plugin-core",
41     "python-community-plugin-java",
42     "python-psi-api",
43     "python-pydev",
44     "python-community-ide-resources",
45     "python-community"
46   ]
47
48
49   def modules = communityModules
50
51   def outDir = "$home/out/python"
52   def ideaDistDir = "$outDir/idea"
53   def helpDir = "$outDir/help"
54   loadProject()
55
56   if (dryRun) {
57     projectBuilder.targetFolder = "$home/out/classes"
58   }
59   else {
60     projectBuilder.targetFolder = "$outDir/classes"
61   }
62   projectBuilder.dryRun = dryRun
63
64   projectBuilder.stage("Cleaning up sandbox folder")
65   if (!dryRun) {
66     forceDelete("$outDir/classes")
67   }
68
69   buildModules(modules, [])
70
71   def ideaBuildTxt = new File(ideaDistDir, "build.txt")
72   def currentIdeaBranch
73   def currentIdeaBuild
74   if (ideaBuildTxt.exists()) {
75     def matcher = (ideaBuildTxt.text =~ /IU-(\d+)\.(\d+).*/)
76     currentIdeaBranch = matcher[0][1]
77     currentIdeaBuild = matcher[0][2]
78   }
79   else {
80     currentIdeaBranch = null
81     currentIdeaBuild = null
82   }
83
84   def sinceBuild
85   def untilBuild
86   if (currentIdeaBranch != null && currentIdeaBuild != null) {
87     sinceBuild = "${currentIdeaBranch}.${currentIdeaBuild}"
88     untilBuildNum = (currentIdeaBranch.toInteger() + 1).toString()
89     untilBuild = "$untilBuildNum.0"
90   } else {
91     sinceBuild = null
92     untilBuild = null
93   }
94
95   //  def pluginVersion = "$pythonPluginVersion.${new SimpleDateFormat("yyyyMMdd").format(new Date())}"
96   def pluginVersion = "$pythonPluginVersion"
97
98   // set version to PyCharm current version from ApplicationInfo.xml
99   ant.loadfile(property: "appInfo", srcFile: "${communityHome}/python-community-ide-resources/resources/idea/PyCharmCoreApplicationInfo.xml") {
100   }
101
102   ant.xmlproperty(file: "${communityHome}/python-community-ide-resources/resources/idea/PyCharmCoreApplicationInfo.xml", collapseAttributes: "true")
103
104   def pythonPluginVersionString = "${versionSelector()}.${pluginVersion}"
105
106
107   ant.mkdir(dir: "$outDir/plugins/python-ce")
108   ant.copy(file: "$communityHome/pluginResources/META-INF/plugin.xml", todir: "$outDir/plugins/python-ce")
109   ant.replace(file: "$outDir/plugins/python-ce/plugin.xml") {
110     replacefilter(token: "@@PYCHARM_VERSION@@", value: "$pythonPluginVersionString")
111   }
112
113 //  if (sinceBuild != null && untilBuild != null) {
114 //    ant.replaceregexp(file: "$outDir/plugins/python-ce/plugin.xml",
115 //                      match: "since-build=\"[^\"]+\"",
116 //                      replace: "since-build=\"${sinceBuild}\"")
117 //  }
118
119   layout("$outDir/layout-ce") {
120     dir("python") {
121       dir("lib") {
122         jar("python.jar") {
123           communityModules.each {
124             module(it) {
125               exclude(name: "**/plugin.xml")
126               exclude(name: "**/python-plugin-dependencies.xml")
127             }
128           }
129           dir("META-INF") {
130             fileset(file: "$outDir/plugins/python-ce/plugin.xml")
131             fileset(file: "$communityHome/build/python-plugin-dependencies.xml")
132           }
133         }
134         fileset(dir: "${communityHome}/ipnb/lib") {
135           include(name: "*.jar")
136         }
137       }
138       dir("help") {
139         fileset(dir: "${helpDir}") {
140           include(name: "pytonpluginhelp.jar")
141           include(name: "pytonpluginhelp_mac.jar")
142         }
143       }
144       dir("helpers") {
145         fileset(dir: "${communityHome}/helpers") {
146           include(name: "**/*")
147         }
148       }
149     }
150   }
151
152   def zipFilePathCE = "$outDir/python-community-${pluginVersion}.zip"
153   ant.delete(file: zipFilePathCE)
154   ant.zip(destfile: zipFilePathCE) {
155     fileset(dir: "$outDir/layout-ce")
156   }
157   notifyArtifactBuilt(zipFilePathCE)
158
159   def pluginsPaths = []
160   pluginsPaths << zipFilePathCE
161
162
163   new File(outDir, "plugins-paths.txt").text = pluginsPaths.join("\n")
164 }