This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
409 lines (346 loc) · 14.5 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
import org.apache.tools.ant.BuildException
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'scala'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'checkstyle' //for java code conventions
apply plugin: 'jdepend' //for dependency analysis
apply plugin: 'findbugs' //for static code analysis
apply plugin: 'pmd'
idea {
module {
testSourceDirs += file('acceptance-tests/drivers/java/driver-version-2.11.3')
testSourceDirs += file('acceptance-tests/journeys/scala')
}
}
defaultTasks 'clean', 'build'
clean.dependsOn = ['killMidas']
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
project.ext {
//App Config
appConfigUrl = new URL("file:///${projectDir}/AppConfig.groovy")
appConfig = new ConfigSlurper('configuration').parse(appConfigUrl).configuration
manifest = appConfig.product.distribution.jar.manifest.details
project.archivesBaseName = appConfig.product.distribution.name
previousArchiveName = appConfig.product.distribution.previousArchiveName
//libs
mongoDriver = 'org.mongodb:mongo-java-driver:2.11.3'
groovy = 'org.codehaus.groovy:groovy-all:2.2.0'
scala = 'org.scala-lang:scala-library:2.10.2'
asm = 'org.ow2.asm:asm:4.1'
junit = 'junit:junit:4.8.1'
mockito = 'org.mockito:mockito-all:1.9.5'
specs2 = 'org.specs2:specs2_2.10:2.2.2'
//for acceptance-test reporting
pegdown = 'org.pegdown:pegdown:1.2.1'
spock = 'org.spockframework:spock-core:0.7-groovy-2.0'
slf4j = 'org.slf4j:slf4j-api:1.7.5'
log4jBinding = 'org.slf4j:slf4j-log4j12:1.7.5'
cglib = 'cglib:cglib-nodep:2.2'
scopt = 'com.github.scopt:scopt_2.10:3.2.0'
disruptor = 'com.lmax:disruptor:3.0.0.beta1'
//for scala style plugin
scalaStyle = 'org.scalastyle:scalastyle_2.10:0.3.2'
scalaStyleReportsDirName = "$reporting.baseDir/scalastyle"
//code coverage lib
coberturaCoverageReportsDirName = "$reporting.baseDir/cobertura"
coberturaLineCoverageBaseline = 88
coberturaBranchCoverageBaseline = 38.5 //reduced from 70
//dependency analysis
jdepend = 'jdepend:jdepend:2.9.1'
//Distribution settings
distsTemplateDir = 'distribution-template'
distsBinDirName = "$project.distsDir/bin"
distsZipFileName = "${project.distsDir}/${project.archivesBaseName}.zip"
resourcesDir = 'src/main/resources'
//Explode Distributables here
explodedDir = "$project.buildDir/exploded"
//Runtime Configurations
DEFAULT_PORT_PREFIX = 270
portPrefix = System.getProperty('mongoVersion', "$DEFAULT_PORT_PREFIX")
DEFAULT_LANGUAGE = 'java'
language = System.getProperty('language', "$DEFAULT_LANGUAGE")
MIDAS_SERVER = 'localhost'
midasServer = System.getProperty('midasServer', "$MIDAS_SERVER")
MONGODB_SERVER = 'localhost'
mongoDB = System.getProperty('mongoDB', "$MONGODB_SERVER")
acceptanceTestDir = 'acceptance-tests'
acceptanceTestReportsDir = "${reporting.baseDir}/acceptance-tests"
smokeTestsDir = "smoke-tests"
smokeTestReportsDir = "${reporting.baseDir}/${smokeTestsDir}"
documentationDir = "distribution-template/documentation/"
journeysDir = "${documentationDir}/journeys"
javaAcceptanceTestDir = "$acceptanceTestDir/drivers/java/driver-version-2.11.3"
javaAcceptanceTestReportsDir = "$acceptanceTestReportsDir/java"
pythonAcceptanceTestDir = "$acceptanceTestDir/drivers/python/driver-version-2.6.3"
pythonAcceptanceTestReportsDir = "$acceptanceTestReportsDir/python"
acceptanceJourneyTestDir = "$acceptanceTestDir/journeys/scala"
acceptanceJourneyTestReportsDir = "$acceptanceTestReportsDir/journeys"
transformsPackage = 'com/ee/midas/transform/'
deltas = "deltas"
transformations = "generated"
templates = "templates"
transformationsDir = "${project.buildDir}/resources/main/$transformations"
deltasDir = "${project.buildDir}/resources/main/$deltas"
templatesDir = "${project.buildDir}/resources/main/$templates"
}
sourceSets {
test {
scala {
srcDirs 'smoke-tests', 'acceptance-tests'
}
}
}
//sourceSets.main.java.srcDirs = []
sourceSets.main.scala.srcDirs += ["src/main/java", "src/main/groovy"]
//http://forums.gradle.org/gradle/topics/how_to_compile_groovy_sources_mixed_with_java_sources
sourceSets.main.groovy.srcDirs += ["src/main/java"]
test {
exclude '**/smoke/*.class', '**/sample/*.class', '**/run/*.class'
}
task ('smoke-tests') << {
println "Running smoke tests..."
javaexec {
main = 'specs2.run'
classpath = project.sourceSets.test.runtimeClasspath
args = ['com.ee.midas.smoke.CrudSpecs']
}
}
task ('acceptance-tests', dependsOn: ['cleanAcceptanceReportsDir', 'journey-tests', 'driver-tests']) << {
println "Running acceptance tests (journeys and driver-tests)"
}
task ('cleanAcceptanceReportsDir') {
File dir = new File(project.ext.acceptanceTestReportsDir)
!dir.exists() ?: dir.deleteDir()
}
task ('driver-tests', dependsOn: ['cleanDriverTestsReportsDir']) << {
println "Running driver-tests..."
project.ext.language == 'python'? runPythonAcceptanceTests(project.ext.pythonAcceptanceTestDir, project.ext.pythonAcceptanceTestReportsDir) :
runJVMAcceptanceTests(project.ext.javaAcceptanceTestDir, project.ext.javaAcceptanceTestReportsDir)
}
task ('cleanDriverTestsReportsDir') {
File javaReportsDir = new File(project.ext.javaAcceptanceTestReportsDir)
!javaReportsDir.exists() ?: javaReportsDir.deleteDir()
File pythonReportsDir = new File(project.ext.pythonAcceptanceTestReportsDir)
!pythonReportsDir.exists() ?: pythonReportsDir.deleteDir()
}
task ('journey-tests', dependsOn: ['cleanJourneyTestReportsDir']) << {
println "Running journey tests..."
project.ext.language == runJVMAcceptanceTests(project.ext.acceptanceJourneyTestDir, project.ext.acceptanceJourneyTestReportsDir)
copy {
from (project.ext.acceptanceJourneyTestReportsDir)
into "${project.ext.journeysDir}"
}
}
task ('cleanJourneyTestReportsDir') {
File dir = new File(project.ext.acceptanceJourneyTestReportsDir)
!dir.exists() ?: dir.deleteDir()
}
task ('startMidas', dependsOn: ['killMidas', 'unzip']) << {
def os = System.getProperty("os.name")
def winCmd = """cmd /c midas.bat --host localhost --port 27020 --source localhost --mongoPort ${project.ext.portPrefix}17"""
def command = os ==~ /Win.*/ ? "$winCmd" : "sh midas.sh localhost 27020 localhost ${project.ext.portPrefix}17"
command.execute(null, new File(project.ext.explodedDir))
println "started midas... using mongo on port ${project.ext.portPrefix}."
}
task ('killMidas') << {
killFirst("com.ee.midas.Main")
}
def runJVMAcceptanceTests(String srcFolder, String reportsFolder) {
javaexec {
systemProperties['specs2.srcTestDir'] = srcFolder
systemProperties['specs2.outDir'] = reportsFolder
systemProperties['specs2.junit.outDir'] = reportsFolder
main = 'org.specs2.files'
classpath = project.sourceSets.test.runtimeClasspath
args = ['html', 'junitxml', 'filesrunner.pattern', '(.*Specs)|(Index.*)'] //'filesrunner.verbose'
}
}
def runPythonAcceptanceTests(String srcFolder, String reportsFolder) {
println "cleaning reports directory..."
def os = System.getProperty("os.name")
println "running python tests"
def winCmd = """cmd /c python MidasWithPythonDriverTest.py ${reportsFolder}"""
def command = os ==~ /Win.*/ ? "$winCmd" : "python MidasWithPythonDriverTest.py ${reportsFolder}"
def process = command.execute(null, new File(srcFolder))
println "available bytes: " + process.in.available()
process.err.eachLine { line ->
if(line.contains('FAILED') || line.contains("Error") || line.contains("Exception")) {
throw new BuildException("python acceptance tests failed.")
}
}
}
// Apply External Plugins
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'net.saliman:gradle-cobertura-plugin:2.2.2'
}
}
apply plugin: 'cobertura'
repositories {
mavenCentral()
mavenLocal()
maven {
url 'http://code.google.com/p/google-maven-repository'
url 'https://oss.sonatype.org/content/repositories/snapshots'
url 'http://mvnrepository.com/artifact/com.github.scopt'
}
}
dependencies {
compile(project.ext.mongoDriver, project.ext.groovy, project.ext.scala, project.ext.asm, project.ext.scalaStyle, project.ext.slf4j, project.ext.log4jBinding, project.ext.cglib, project.ext.scopt, project.ext.disruptor)
testCompile(project.ext.junit, project.ext.specs2, project.ext.mockito, project.ext.spock, project.ext.pegdown)
}
jar {
manifest {
attributes.putAll(project.ext.manifest)
attributes(['Sealed' : 'false'], "${project.ext.transformsPackage}")
}
excludes = [project.ext.deltas, project.ext.transformations, project.ext.templates]
doLast {
copy {
from (configurations.compile.asPath.split(File.pathSeparator))
into "$libsDir"
}
}
}
task ('createTestJar', type: Jar) {
baseName = "${project.archivesBaseName}-test"
destinationDir = project.distsDir
includes = ['**/smoke/*.class', '**/fixtures/*.class', '**/run/*.class']
includeEmptyDirs = false
from sourceSets.test.output
}
//FindBugs Configuration
findbugs {
toolVersion = '2.0.2'
reportsDir = file("$reporting.baseDir/findbugs")
effort = "max"
reportLevel = "high"
}
tasks.withType(FindBugs) {
excludeFilter = file("${projectDir}/tools-config/findbugs/excludeFilter.xml")
}
findbugsTest.enabled = false
//CheckStyle Configuration
checkstyle {
configFile = file("${projectDir}/tools-config/checkstyle/checkstyle.xml")
}
checkstyleTest {
exclude('**/*/*Specs.java')
}
//Scala Style task
task scalastyle(description: 'Run scalaStyle analysis for main and test classes') << {
// ant.mkdir(dir: project.ext.scalaStyleReportsDirName)
// javaexec {
// main = 'org.scalastyle.Main'
// classpath = sourceSets.main.runtimeClasspath
// ext.configDir = file("${projectDir}/tools-config/scalastyle/scalaStyle.xml")
// ext.sourceDir = 'src'
// ext.xmlOut = file("$project.ext.scalaStyleReportsDirName/main.xml")
// args '--config',configDir, '--xmlOutput', xmlOut, '--verbose', false, '--warnings', false, sourceDir
// }
}
//Cobertura Configuration
cobertura {
coverageReportDir = file(project.ext.coberturaCoverageReportsDirName)
cobertura.coverageExcludes = ['.*net.saliman.*', '.*com.ee.midas.transform.Transformations.*',
'.*MidasConfig.*', '.*com.ee.midas.dsl.Translate.*']
coverageFormats = ['html', 'xml']
coverageCheckTotalLineRate = project.ext.coberturaLineCoverageBaseline
coverageCheckTotalBranchRate = project.ext.coberturaBranchCoverageBaseline
coverageCheckHaltOnFailure = true
}
task distribute(type:Zip, dependsOn: ['assemble', 'journey-tests']) {
doFirst {
ant.mkdir(dir:"$distsBinDirName")
prepareExecutables()
}
from project.ext.distsBinDirName
from (project.ext.distsTemplateDir) {
include ('**/*.txt')
}
from (project.ext.documentationDir) { include ('**/*.pdf') into ('docs') }
from (project.ext.acceptanceJourneyTestReportsDir) { into ('docs/journeys') }
from (project.ext.resourcesDir) {
exclude('*.properties')
}
from ("$libsDir") { into ('libs') }
from ("${project.ext.deltasDir}") { into ("${project.ext.deltas}") }
from ("${project.ext.transformationsDir}") {
exclude ('**/*.scala', '**/*.class')
into ("${project.ext.transformations}")
}
from ("${project.ext.templatesDir}") { into ("${project.ext.templates}") }
includeEmptyDirs = false
}
def prepareExecutables() {
def allLibFiles = new File("$libsDir").list().collect { "libs/$it" }
new File("$distsTemplateDir").list().each { filename ->
if (filename.startsWith('midas')) {
def contents = new File("$distsTemplateDir/$filename").text
new FileWriter("$distsBinDirName/$filename").withWriter { writer ->
if(filename.endsWith('.sh')) {
writer.append contents.replace('%%JAVA_CLASS_PATH%%', allLibFiles.collect({"\$MIDAS_HOME/$it"}).join(":"))
}
if(filename.endsWith('.bat')) {
writer.append contents.replace('%%JAVA_CLASS_PATH%%', allLibFiles.collect({"%MIDAS_HOME%/$it"}).join(";"))
}
}
}
}
}
task unzip(type: Copy) {
def zipFile = file("$distsZipFileName")
def outputDir = file(project.ext.explodedDir)
from zipTree(zipFile)
into outputDir
}
task run(description: "Runs $project.archivesBaseName", dependsOn: [distribute, unzip]) << {
//Run Midas from exploded dir
def runtimeClasspath = fileTree(dir: "${project.ext.explodedDir}/libs", include: '*.jar')
runtimeClasspath = runtimeClasspath + fileTree(dir: project.distsDir, include: '*.jar')
javaexec {
systemProperties['portPrefix'] = project.ext.portPrefix
main = 'com.ee.midas.Main'
classpath = runtimeClasspath
args = ["$project.ext.midasServer", "${project.ext.portPrefix}20", "${project.ext.mongoDB}", "${project.ext.portPrefix}17"]
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
def getProcessId(def processName, def os) {
def winProcessCmd = "wmic process where \"name='java.exe' and commandLine like '%$processName%'\" get processid"
def processCmd = os ==~ /Win.*/ ? "$winProcessCmd " : 'ps -ef'
println "Executing $processCmd on $os..."
def killableProcessId = os ==~ /Win.*/ ?
processCmd.execute().in.readLines().each { it.trim() }.join(" ")
: processCmd.execute().in.filterLine {it.contains("$processName".replaceAll('\"',''))
}
def args = "$killableProcessId".split() as List
def processIdToKill = ''
if(args) {
processIdToKill = args[1]
}
processIdToKill
}
def killFirst(def processName) {
def os = System.getProperty("os.name")
def processIdToKill = getProcessId(processName, os)
if(!processIdToKill.isEmpty()) {
println "Killing the process $processName with processId: $processIdToKill"
def killProcessCmd = os ==~ /Win.*/ ? "taskkill /pid $processIdToKill /f" : "kill -15 $processIdToKill"
println "Executing $killProcessCmd on $os..."
killProcessCmd.execute().in.eachLine { println it }
} else {
println "Nothing to kill by name $processName"
}
}
check.dependsOn << ['scalastyle']
build.dependsOn = ['check', 'cobertura', 'coberturaCheck', 'distribute']