-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle
274 lines (236 loc) · 9.36 KB
/
build.gradle
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
import org.apache.tools.ant.util.TeeOutputStream
// the mps version we build (and install) the plugins for. Necessary to compute a user's plugin directory
ext.mpsMajor = "2019.3"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.apache.ant', name: 'ant-junit', version: '1.9.7'
}
}
apply plugin: 'base'
repositories {
maven {
mavenCentral()
url 'https://projects.itemis.de/nexus/content/groups/OS'
}
}
configurations {
mps
mpsPlugins
compile
git4mpsCompile
}
dependencies {
// Plugin dependencies for project
mpsPlugins group: 'com.mbeddr', name: 'platform', version: '2019.3.+'
// Compile-time dependencies
// Multiple configurations allow us to easily copy the deps to the required locations
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
compile group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.10.0'
mps group: 'com.jetbrains', name: 'mps', version: '2019.3.3'
git4mpsCompile files('artifacts/MPS/plugins/git4idea/lib/git4idea.jar')
git4mpsCompile files('artifacts/MPS/plugins/git4idea/lib/git4idea-rt.jar')
}
task unzipMps(type: Copy, description: "Unzips MPS into the artifacts folder.") {
dependsOn configurations.mps
from {
configurations.mps.resolve().collect { zipTree(it) }
}
into 'artifacts/MPS'
}
task unzipPlugins(type: Copy, description: "Unzips the IDE plugins into the artifacts folder") {
dependsOn configurations.mpsPlugins
from {
configurations.mpsPlugins.resolve().collect { zipTree(it) }
}
into 'artifacts'
}
task syncCompileDependenciesToLib(type: Sync) {
// sync because these should be the only files in this lib directory
from {
configurations.compile.resolve()
}
into 'solutions/com.workday.mps.review/lib'
}
task copyGit4mpsCompileDependenciesToLib(type: Copy) {
from {
configurations.git4mpsCompile.resolve()
}
into 'solutions/git4mps/lib'
}
copyGit4mpsCompileDependenciesToLib.mustRunAfter unzipMps
task copyCompileDependenciesToLib(dependsOn: [copyGit4mpsCompileDependenciesToLib,
syncCompileDependenciesToLib])
task setup(group: 'Project',
description: 'Initializes the project for development',
dependsOn: [unzipMps,
unzipPlugins,
copyCompileDependenciesToLib])
clean.doFirst {
delete 'artifacts'
delete 'dist'
delete 'test'
// delete all generated code
ant.delete(includeemptydirs: true) {
fileset(dir: "${rootDir}", defaultexcludes: false) {
include(name: '**/lib/**')
include(name: '**/source_gen/**')
include(name: '**/source_gen.caches/**')
include(name: '**/classes_gen/**')
include(name: '**/classes_gen.caches/**')
include(name: '**/test_gen/**')
include(name: '**/test_gen.caches/**')
}
}
}
task generateBuildScripts(group: 'MPS Build',
description: 'Generates all Ant build scripts',
dependsOn: setup) {
doLast {
println 'Generating ant scripts ==========================================='
runAnt "${rootDir}/buildScripts/reviewPluginBuildScripts.xml", 'generate'
println 'Ant scripts have been successfully generated ====================='
println()
}
}
task buildPluginIncremental(group: 'MPS Build',
description: 'Assembles the code reviewer plugin from generated source. Useful when working with MPS',
dependsOn: generateBuildScripts) {
doLast {
println 'Building code reviewer plugin ===================================='
runAnt "${rootDir}/dist/git4mpsPlugin.xml", 'build'
runAnt "${rootDir}/dist/reviewPlugin.xml", 'build'
println 'Code reviewer plugin has been successfully built ================='
println()
}
}
task buildPlugin(group: 'MPS Build',
description: 'Generates and assembles the code reviewer plugin',
dependsOn: generateBuildScripts) {
doLast {
println 'Building code reviewer plugin ===================================='
runAnt "${rootDir}/dist/git4mpsPlugin.xml", 'clean', 'generate', 'build'
runAnt "${rootDir}/dist/reviewPlugin.xml", 'clean', 'generate', 'build'
println 'Code reviewer plugin has been successfully built ================='
println()
}
}
task zipGit4mpsBuildPlugin(group: 'MPS Build',
type: Zip,
description: 'Archive git4mps build plugin into a zip file') {
from "${rootDir}/dist/build/artifacts/git4mpsPlugin/"
include "com.workday.mps.git4mps.build/**"
destinationDir = file("${rootDir}/dist/build/artifacts/")
archiveName = 'com.workday.mps.git4mps.build.zip'
}
task zipGit4mpsPlugin(group: 'MPS Build',
type: Zip,
description: 'Archive git4mps plugin into a zip file') {
from "${rootDir}/dist/build/artifacts/git4mpsPlugin/"
include "com.workday.mps.git4mps/**"
destinationDir = file("${rootDir}/dist/build/artifacts/")
archiveName = 'com.workday.mps.git4mps.zip'
}
zipGit4mpsPlugin.mustRunAfter buildPlugin
task zipGit4mpsWithBuildPlugin(group: 'MPS Build',
type: Zip,
description: 'Archive both git4mps plugin and git4mps build plugin into a zip file') {
from "${rootDir}/dist/build/artifacts/"
include "git4mpsPlugin/**"
destinationDir = file("${rootDir}/dist/build/artifacts/")
archiveName = 'git4mps.zip'
}
zipGit4mpsWithBuildPlugin.mustRunAfter buildPlugin
task zipCodeReviewerPlugin(group: 'MPS Build',
type: Zip,
description: 'Archive code reviewer plugin into a zip file') {
from "${rootDir}/dist/build/artifacts/reviewPlugin/"
include "com.workday.mps.review/**"
destinationDir = file("${rootDir}/dist/build/artifacts/")
archiveName = 'com.workday.mps.review.zip'
}
zipCodeReviewerPlugin.mustRunAfter buildPlugin
task zipPlugins(group: 'MPS Build',
description: 'Archive plugins into zip files',
dependsOn: [zipGit4mpsBuildPlugin, zipGit4mpsPlugin, zipGit4mpsWithBuildPlugin, zipCodeReviewerPlugin]) {
doLast {
println 'Plugins have been successfully zipped ================='
println()
}
}
zipPlugins.mustRunAfter buildPlugin
defaultTasks 'build'
assemble.dependsOn buildPlugin
// TODO: run tests as part of check
void runAnt(Object buildfile, String... targets) {
exec 'BUILD FAILED', ['ant', '-buildfile', buildfile, *targets] as Object[]
}
void exec(String textToFind, Object... args) {
exec {
commandLine = args
}
}
void execAndFailIfTextFound(String textToFind, Object... args) {
def taskOutput = new ByteArrayOutputStream()
def teeOutput = new TeeOutputStream(taskOutput, System.out)
exec {
ignoreExitValue = true
commandLine = args
standardOutput = teeOutput
errorOutput = teeOutput
}
String testOutput = taskOutput.toString()
if (testOutput.contains(textToFind)) {
throw new GradleException('ANT build failure')
}
}
def userHome = System.properties['user.home']
def mpsPluginsDirPattern
if (System.properties['os.name'].toLowerCase().contains('mac')) {
mpsPluginsDirPattern = "$userHome/Library/Application Support/%s"
} else {
mpsPluginsDirPattern = "$userHome/.%s/config/plugins"
}
if (project.hasProperty("MPS_PATHS_SELECTOR")) {
ext.mpsPluginsDir = sprintf(mpsPluginsDirPattern, project.getProperty("MPS_PATHS_SELECTOR"))
} else {
ext.mpsPluginsDir = sprintf(mpsPluginsDirPattern, "MPS$mpsMajor")
}
task install_git4mps(type: Copy,
description: "Install git4mps into the MPS plugin repository",
dependsOn: [buildPlugin, zipGit4mpsWithBuildPlugin]) {
from zipTree("$rootDir/dist/build/artifacts/git4mps.zip")
into "$mpsPluginsDir"
}
task install_mpsreview(type: Copy,
description: "Install mps.review into the MPS plugin repository",
dependsOn: [buildPlugin, zipCodeReviewerPlugin]) {
from zipTree("$rootDir/dist/build/artifacts/com.workday.mps.review.zip")
into "$mpsPluginsDir"
}
task install(description: "Install the required plugins into the MPS plugin repository by copying them into the user's home dir",
group: "MPS Build",
dependsOn: [install_git4mps, install_mpsreview]) {
doFirst {
// check parent gradle file for definition of the variables
println "Installing required mps-code-reviewer plugins to '$mpsPluginsDir'"
if (!project.hasProperty("MPS_PATHS_SELECTOR")) {
println "To change 'MPS<VERSION>' part, pass MPS_PATHS_SELECTOR property to gradle with -PMPS_PATHS_SELECTOR=<custom path selector>"
println "The path selector only contains the actual selector fragment (i.e. \"MPS2019.1\") and not the fully qualified path to the user plugin directory."
}
}
}
task uninstall(type: Delete, description: "uninstall the plugins from the MPS plugin repository",
group: "MPS Build") {
delete "$mpsPluginsDir"+"/git4mps", "$mpsPluginsDir"+"/com.workday.mps.review"
doFirst {
// check parent gradle file for definition of the variables
println "Uninstalling required mps-code-reviewer plugins from '$mpsPluginsDir'"
if (!project.hasProperty("MPS_PATHS_SELECTOR")) {
println "To change 'MPS<VERSION>' part, pass MPS_PATHS_SELECTOR property to gradle with -PMPS_PATHS_SELECTOR=<custom path selector>"
println "The path selector only contains the actual selector fragment (i.e. \"MPS2019.1\") and not the fully qualified path to the user plugin directory."
}
}
}