forked from ow2-proactive/connector-r
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
496 lines (407 loc) · 17.9 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
apply plugin: 'java'
buildscript {
repositories {
if (project.hasProperty('local')) {
mavenLocal()
}
jcenter()
maven { url 'http://repository.activeeon.com/content/groups/proactive/' }
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
url "http://repository.activeeon.com/content/groups/proactive/"
}
}
dependencies {
classpath "com.diffplug.gradle.spotless:spotless:2.4.0"
classpath "org.ow2.proactive:coding-rules:1.0.0"
delete "gradle/ext"
ant.unjar src: configurations.classpath.find { it.name.startsWith("coding-rules") }, dest: 'gradle/ext'
}
}
subprojects {
apply plugin: 'maven'
group = 'org.ow2.proactive.r_connector'
version = "${rConnectorVersion}"
rootProject.buildscript.repositories.each {
repositories.add(it)
}
configurations {
addons
}
}
apply from: "$rootDir/gradle/ext/coding-format.gradle"
def isWindows = System.properties['os.name'].toLowerCase().contains('windows')
def isMac = System.properties['os.name'].toLowerCase().contains('mac')
def isLinux = System.properties['os.name'].toLowerCase().contains('linux')
def rHome = System.getenv('R_HOME')
def rExec
def rScript
def rBinDir = rHome ? rHome + File.separator + 'bin' + File.separator : null
if (isWindows) {
def ARCH = System.getenv('ProgramFiles(x86)') != null ? 'x64' : 'i386'
rExec = rBinDir ? rBinDir + ARCH + File.separator + 'R.exe' : 'R.exe'
rScript = rBinDir ? rBinDir + ARCH + File.separator + 'Rscript.exe' : 'Rscript.exe'
} else {
rExec = rBinDir ? rBinDir + 'R' : 'R'
rScript = rBinDir ? rBinDir + 'Rscript' : 'Rscript'
}
task checkRCommands() << {
def res1 = exec {
commandLine rExec, '--version'
ignoreExitValue = true
}
if (res1.getExitValue() != 0) {
throw "R command seems not accessible (using " + rExec + "), please check that R is installed properly"
}
def res2 = exec {
commandLine rScript, '--version'
ignoreExitValue = true
}
if (res2.getExitValue() != 0) {
throw "RScript command seems not accessible (using " + rScript + "), please check that R is installed properly"
}
}
project(':pa-rengine-common') {
apply plugin: 'java'
sourceCompatibility = 1.7
dependencies {
compile configurations.addons
compile 'log4j:log4j:1.2.17'
compile 'org.apache.commons:commons-lang3:3.1'
compile 'commons-io:commons-io:2.4'
compile group: 'com.google.guava', name: 'guava', version: '17.0'
compile "org.objectweb.proactive:programming-extension-dataspaces:${programmingVersion}"
compile "org.ow2.proactive:scheduler-api:${schedulingVersion}"
compile "org.ow2.proactive:common-api:${schedulingVersion}"
compile "org.ow2.proactive:rm-node:${schedulingVersion}"
testCompile 'junit:junit:4.12'
}
task testJar(type: Jar) {
baseName = "test-${project.archivesBaseName}"
from sourceSets.test.output
}
configurations {
tests
}
artifacts {
tests testJar
}
}
project(':pa-rserve') {
apply plugin: 'java'
sourceCompatibility = 1.7
dependencies {
compile configurations.addons
compile project(':pa-rengine-common')
addons "org.rosuda.REngine:REngine:2.1.0"
addons "org.rosuda.REngine:Rserve:1.8.1"
testCompile project(path: ':pa-rengine-common', configuration: 'tests')
testCompile 'junit:junit:4.12'
}
task installRserve(type: Exec) {
commandLine rExec, '-q', '--no-save', '-e', 'if (length(find.package(\'Rserve\', quiet=TRUE)) == 0) {install.packages(\'Rserve\', repos=c(\'http://cran.r-project.org\'))}'
}
task addon(type: Zip) {
from project(':pa-rengine-common').jar
from configurations.addons
from jar
}
artifacts { archives addon }
test.dependsOn(installRserve)
build.dependsOn(addon)
}
project(':pa-jri') {
apply plugin: 'java'
sourceCompatibility = 1.7
dependencies {
compile configurations.addons
compile project(':pa-rengine-common')
addons "org.rosuda:jriengine:0.5.x"
addons "org.rosuda:jri:0.5.x"
addons "org.rosuda:rengine:1.7.x"
testCompile project(path: ':pa-rengine-common', configuration: 'tests')
testCompile 'junit:junit:4.12'
}
task installrJava(type: Exec, dependsOn: checkRCommands) {
commandLine rExec, '-q', '--no-save', '-e', 'if (length(find.package(\'rJava\', quiet=TRUE)) == 0) {install.packages(\'rJava\', repos=c(\'http://cran.r-project.org\'))}'
}
task addon(type: Zip) {
from project(':pa-rengine-common').jar
from configurations.addons
from jar
}
artifacts { archives addon }
test.dependsOn(installrJava)
build.dependsOn(addon)
}
project(':pa-rconnector') {
apply plugin: 'base'
configurations {
scheduler
restJars
rengine
}
dependencies {
scheduler group: "org.ow2.proactive", name: "scheduling", version: schedulingVersion, ext: "zip"
restJars 'xerces:xercesImpl:2.11.0'
restJars "org.ow2.proactive_grid_cloud_portal:rest-client:${schedulingVersion}"
rengine "org.rosuda.REngine:REngine:2.1.0"
}
def schedHome = "${rootProject.buildDir}/scheduler"
def rSrc = "${buildDir}/PARConnector"
def env = [:]
env.putAll(System.getenv())
if (!isMac) {
if (env.get('JAVA_HOME') == null) {
throw new IllegalStateException("Please set JAVA_HOME environment variable")
}
if (!env.get('JAVA_HOME').endsWith("jre")) {
env.put('JAVA_HOME', env.get('JAVA_HOME') + File.separator + 'jre')
}
}
if (isLinux) {
def ldLib
if (System.getProperty('os.arch').contains('64')) {
ldLib = new File(env.get('JAVA_HOME'), 'lib/amd64/server')
} else {
ldLib = new File(env.get('JAVA_HOME'), 'lib/i386/client')
}
env.put('LD_LIBRARY_PATH', ldLib.getAbsolutePath())
}
def schedProcess
task copyRSources(type: Copy) {
from "${projectDir}/src/main/PARConnector"
include("**/*")
exclude("**/.*")
into rSrc
}
if (isLinux) {
task javareconf(type: Exec, dependsOn: checkRCommands) {
commandLine rExec, 'CMD', 'javareconf'
}
} else {
// empty task
task javareconf
}
task installrJava(type: Exec, dependsOn: javareconf) {
commandLine rExec, '-q', '--no-save', '-e', 'if (length(find.package(\'rJava\', quiet=TRUE)) == 0) {install.packages(\'rJava\', repos=c(\'http://cran.r-project.org\'))}'
}
task installDevTools(type: Exec, dependsOn: [checkRCommands]) {
commandLine rExec, '-q', '--no-save', '-e', 'if (length(find.package(\'devtools\', quiet=TRUE)) == 0) {install.packages(\'devtools\', repos=c(\'http://cran.r-project.org\'))}'
}
task installRoxygen2(type: Exec, dependsOn: [checkRCommands]) {
commandLine rExec, '-q', '--no-save', '-e', 'if (length(find.package(\'roxygen2\', quiet=TRUE)) == 0) {install.packages(\'roxygen2\', repos=c(\'http://cran.r-project.org\'))}'
}
// this task updates the version inside PARConnector package Description file
task updateVersion(dependsOn: copyRSources) << {
def patternToExtractVersionFromVariable = java.util.regex.Pattern.compile("^((\\d+\\.)*(\\d+))");
def matcherToExtractVersionFromVariable = patternToExtractVersionFromVariable.matcher("${rConnectorVersion}");
def foundValidVersionNumber = matcherToExtractVersionFromVariable.find();
if (!foundValidVersionNumber) {
throw new InvalidUserDataException("Invalid version number: ${rConnectorVersion}. It should match ^((\\d+\\.)*(\\d+))");
}
def newVersionNumber = matcherToExtractVersionFromVariable.group(0);
// replace version number in the DESCRIPTION file
def descFile = file("${rSrc}/DESCRIPTION")
def pattern = java.util.regex.Pattern.compile("Version: ((\\d+\\.)*(\\d+))")
def matcher = pattern.matcher(descFile.getText())
matcher.find()
def descFileContent = matcher.replaceFirst("Version: " + newVersionNumber)
descFile.write(descFileContent)
}
task copyRDependencies(type: Copy) {
from configurations.restJars, configurations.rengine
into "${rSrc}/inst/java"
}
task installGtools(type: Exec, dependsOn: [checkRCommands]) {
commandLine rExec, '-q', '--no-save', '-e', 'if (length(find.package(\'gtools\', quiet=TRUE)) == 0) {install.packages(\'gtools\', repos=c(\'http://cran.r-project.org\'))}'
}
task installCodeTools(type: Exec, dependsOn: [checkRCommands]) {
commandLine rExec, '-q', '--no-save', '-e', 'if (length(find.package(\'codetools\', quiet=TRUE)) == 0) {install.packages(\'codetools\', repos=c(\'http://cran.r-project.org\'))}'
}
task installStringR(type: Exec, dependsOn: [checkRCommands]) {
commandLine rExec, '-q', '--no-save', '-e', 'if (length(find.package(\'stringr\', quiet=TRUE)) == 0) {install.packages(\'stringr\', repos=c(\'http://cran.r-project.org\'))}'
}
task generateDocumentation(type: Exec, dependsOn: [checkRCommands, installRoxygen2, installDevTools, installGtools, installCodeTools, installStringR, installrJava, installDevTools, copyRSources, updateVersion, copyRDependencies]) {
inputs.dir(rSrc)
outputs.dir(buildDir)
workingDir rSrc
commandLine rExec, '-q', '--no-save', '-e', 'library(roxygen2);library(devtools);library(rJava);library(codetools);library(stringr);library(gtools);document()'
environment env
}
task addLibsToNamespace(dependsOn: generateDocumentation) << {
def descFile = file("${rSrc}/NAMESPACE")
def nl = System.getProperty("line.separator")
def text = descFile.getText()
text = text.concat(nl + "import(rJava, stringr, codetools, gtools)" + nl)
descFile.write(text)
}
task checkRPackage(type: Exec, dependsOn: [checkRCommands, addLibsToNamespace, generateDocumentation, copyRSources, updateVersion, copyRDependencies]) {
inputs.dir(rSrc)
outputs.dir(buildDir)
workingDir buildDir
commandLine rExec, 'CMD', 'check', '--no-codoc', '--no-manual', '--no-multiarch', rSrc
environment env
}
task buildRPackage(type: Exec, dependsOn: [checkRCommands, copyRSources, updateVersion, copyRDependencies, checkRPackage]) {
inputs.dir(rSrc)
outputs.dir(buildDir)
workingDir buildDir
commandLine rExec, 'CMD', 'INSTALL', '--build', '--preclean', '--with-keep.source', '--no-multiarch', rSrc
environment env
}
task buildRPackageSrc(type: Exec, dependsOn: [checkRCommands, copyRSources, updateVersion, copyRDependencies, checkRPackage]) {
inputs.dir(rSrc)
outputs.dir(buildDir)
workingDir buildDir
commandLine rExec, 'CMD', 'build', '--preclean', '--no-resave-data', rSrc
environment env
}
task build(dependsOn: [buildRPackage, buildRPackageSrc])
// ReInstall PARConnector package to apply changes
task reinstallRPackage(dependsOn: [checkRCommands, buildRPackage]) << {
logger.info('Reinstallling ...')
def packageFile = file(buildDir).listFiles().find {
it.name.endsWith('tar.gz') ||
it.name.endsWith('tgz') ||
it.name.endsWith('zip') }
exec {
workingDir buildDir
commandLine rExec, 'CMD', 'INSTALL', '--no-multiarch', packageFile.getAbsolutePath()
environment env
}
}
task clearAddons(type: Delete) {
delete fileTree(dir: "${schedHome}/addons", include: "*.jar")
}
task installPARserveJars(type: Copy) {
from project(':pa-rengine-common').jar
from project(':pa-rserve').jar
from project(":pa-rserve").configurations.addons
into "${schedHome}/addons"
}
task installPAJRIJars(type: Copy) {
from project(':pa-rengine-common').jar
from project(':pa-jri').jar
from project(":pa-jri").configurations.addons
into "${schedHome}/addons"
}
// The following task will unzip the scheduler project into build/scheduler dir
task distScheduler(type: Copy) {
from mainArtifactsAsZipTree(configurations.scheduler)
into "${rootProject.buildDir}/scheduler"
eachFile { fileCopyDetails ->
fileCopyDetails.path = fileCopyDetails.path.replaceAll(/(.*\/?)scheduling-${schedulingVersion}\/(.*)/, '$1$2')
}
includeEmptyDirs = false
}
// Rserve must be executed in non-fork mode
task changeSchedulerSettingsRServe(dependsOn: distScheduler) << {
def schediniFile = file("${rootProject.buildDir}/scheduler/config/scheduler/settings.ini")
def pattern = java.util.regex.Pattern.compile("pa\\.scheduler\\.task\\.fork=.*")
def matcher = pattern.matcher(schediniFile.getText())
matcher.find()
def fileContent = matcher.replaceFirst("pa.scheduler.task.fork=false")
schediniFile.write(fileContent)
def rminiFile = file("${rootProject.buildDir}/scheduler/config/rm/settings.ini")
def pattern2 = java.util.regex.Pattern.compile("pa\\.rm\\.nodelookup\\.timeout=.*")
def matcher2 = pattern2.matcher(rminiFile.getText())
matcher2.find()
def fileContent2 = matcher2.replaceFirst("pa.rm.nodelookup.timeout=60000")
rminiFile.write(fileContent2)
}
// JRI must be executed in fork mode
task changeSchedulerSettingsJRI(dependsOn: distScheduler) << {
def schediniFile = file("${rootProject.buildDir}/scheduler/config/scheduler/settings.ini")
def pattern = java.util.regex.Pattern.compile("pa\\.scheduler\\.task\\.fork=.*")
def matcher = pattern.matcher(schediniFile.getText())
matcher.find()
def fileContent = matcher.replaceFirst("pa.scheduler.task.fork=true")
schediniFile.write(fileContent)
def rminiFile = file("${rootProject.buildDir}/scheduler/config/rm/settings.ini")
def pattern2 = java.util.regex.Pattern.compile("pa\\.rm\\.nodelookup\\.timeout=.*")
def matcher2 = pattern2.matcher(rminiFile.getText())
matcher2.find()
def fileContent2 = matcher2.replaceFirst("pa.rm.nodelookup.timeout=60000")
rminiFile.write(fileContent2)
}
task startScheduler() << {
schedProcess = ['java', '-classpath', 'dist/lib/*', 'org.ow2.proactive.scheduler.util.SchedulerStarter', '-c', '-ln', '3', '-t', '60000'].execute(null, new File(schedHome))
try {
schedProcess.inputStream.eachLine {
println '>> ' + it
if (it.contains('rest created')) {
throw new Exception()
}
}
} catch (ignored) {
}
try {
int value = schedProcess.exitValue();
if (value != 0) {
throw new Exception('Could not start the Scheduler java exited with code ' + value);
}
} catch (IllegalThreadStateException e) {/* the process is still running */
}
}
task runFuncTests() << {
def funcTestsDir = file("${projectDir}/src/main/test/r/functionalTests")
try {
funcTestsDir.listFiles().each {
if (it.getName().startsWith('test')) {
println '\n######################\n# RUNNING functional test ' + it + ' ... \n######################'
def toRun = "" + it.getAbsolutePath()
exec {
workingDir funcTestsDir
commandLine rScript, '--slave', '--verbose', '--no-save', '--no-restore-history', toRun, 'QUITONERROR'
environment env
}
}
}
} finally {
println '\n######################\n# SHUTTING down the Scheduler ... \n######################'
// Use client to remove 'LocalNodes' node source to avoid orphan nodes processes
def clientProcess = ['java', '-classpath', 'dist/lib/*', 'org.ow2.proactive_grid_cloud_portal.cli.CommonEntryPoint',
'-l', 'admin', '-p', 'admin', '-r', 'LocalNodes'].execute(null, new File(schedHome))
try {
clientProcess.inputStream.eachLine {
println '>> ' + it
if (it.contains('deleted successfully'))
throw new Exception()
}
} catch (e) {
}
schedProcess.destroy();
// workaround for killing PARServe on windows/linux as removing local nodes creates R zombies
try {
if (isWindows) {
['taskkill', '/F', '/im', 'RServe.exe'].execute()
['taskkill', '/F', '/im', 'Rterm.exe'].execute()
} else {
['killall', '-u', System.getenv("USER"), 'R'].execute()
}
} catch (e) {
}
}
}
task startSchedulerPARserve(dependsOn: [distScheduler, clearAddons, installPARserveJars, changeSchedulerSettingsRServe, reinstallRPackage]) << {
tasks.startScheduler.execute()
}
task startSchedulerPAJRI(dependsOn: [distScheduler, clearAddons, installPAJRIJars, changeSchedulerSettingsJRI, reinstallRPackage]) << {
tasks.startScheduler.execute()
}
task runFuncTestsPARserve(dependsOn: startSchedulerPARserve) << {
tasks.runFuncTests.execute();
}
task runFuncTestsPAJRI(dependsOn: startSchedulerPAJRI) << {
tasks.runFuncTests.execute();
}
}
def mainArtifacts(configuration) {
configuration.resolvedConfiguration.firstLevelModuleDependencies.moduleArtifacts.file
}
def mainArtifactsAsZipTree(configuration) {
zipTree(mainArtifacts(configuration)[0][0])
}