-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
183 lines (135 loc) · 4.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
apply plugin: 'scala'
apply plugin: 'idea'
apply plugin: 'eclipse'
repositories {
mavenCentral()
maven {
url 'http://repository.excilys.com/content/groups/public'
}
}
dependencies {
compile 'org.scala-lang:scala-library:2.11.7'
testCompile 'io.gatling.highcharts:gatling-charts-highcharts:2.1.+'
}
sourceSets {
test {
resources {
srcDir 'conf'
}
}
}
/**
* Run Gatling Tests
*/
task gatling(dependsOn: 'compileTestScala') << {
def absPath = System.getProperty("user.dir");
// target/test-classes is required by gatling to be run
def targetTestClassesFolder = new File(absPath, 'target/test-classes')
targetTestClassesFolder.mkdirs()
// create build/reports folder
def targetReportsFolder = new File(project.buildDir.absolutePath, '/reports')
targetReportsFolder.mkdirs()
def runReports = true
if (project.hasProperty("noReport")) {
runReports = false
}
// if only one
if (project.hasProperty("sim")) {
def gatlingScenarioClass = sim
logger.lifecycle(" ---- Executing single Gatling Simulations: ${gatlingScenarioClass} ----")
runGatlingSimulation(gatlingScenarioClass, runReports)
} else {
def iSims = "";
def splitiSims = []
if (project.hasProperty("ignoreSims")) {
iSims = ignoreSims
splitiSims = iSims.split(',')
}
logger.lifecycle(" ---- Executing all Gatling Simulations from: ${sourceSets.test.output.classesDir} ----")
sourceSets.test.output.classesDir.eachFileRecurse { file ->
if (file.isFile()) {
def gatlingScenarioClass = (file.getPath() - (sourceSets.test.output.classesDir.getPath() + File.separator) - '.class')
.replace(File.separator, '.')
def foundGatlingSim = gatlingScenarioClass.lastIndexOf("Simulation");
if (foundGatlingSim > 0 && !splitiSims.contains(gatlingScenarioClass)) {
runGatlingSimulation(gatlingScenarioClass, runReports)
}
}
}
}
logger.lifecycle(" ---- Done executing all Gatling scenarios ----")
}
/**
* List all gatling simulations
*/
task listSims(dependsOn: 'compileTestScala') << {
logger.lifecycle("\nListing all Gatling Simulations from: ${sourceSets.test.output.classesDir}:")
logger.lifecycle("")
sourceSets.test.output.classesDir.eachFileRecurse { file ->
if (file.isFile()) {
def gatlingScenarioClass = (file.getPath() - (sourceSets.test.output.classesDir.getPath() + File.separator) - '.class')
.replace(File.separator, '.')
def foundGatlingSim = gatlingScenarioClass.lastIndexOf("Simulation");
if (foundGatlingSim > 0) {
logger.lifecycle("\t${gatlingScenarioClass}")
}
}
}
}
/**
* Merge Multiple Simulation Logs into a single log
*/
task mergeReports(dependsOn: 'compileTestScala') << {
def simulationLogDir = project.buildDir.absolutePath + '/reports/mergedSimulationLogs'
if (project.hasProperty("simLogsDir")) {
simulationLogDir = simLogsDir
}
def simulationLogFolder = new File(simulationLogDir)
simulationLogFolder.mkdirs()
def reportDir = new File(project.buildDir.absolutePath + '/reports/')
logger.lifecycle("----- Moving all simulation.log files to build/simLogs directory -----")
reportDir.eachFileRecurse { file ->
if (file.toString() != simulationLogDir) {
if (file.isFile()) {
if (file.getName() == "simulation.log") {
def dirSplit = file.toString().split('/')
def newFileName = simulationLogDir + '/' + dirSplit[dirSplit.length - 2] + '.log'
file.renameTo(newFileName)
}
}
}
}
logger.lifecycle("----- Merging all Simulations into one Report -----")
javaexec {
main = 'io.gatling.app.Gatling'
classpath = sourceSets.test.output + sourceSets.test.runtimeClasspath
args '-ro', simulationLogDir
}
}
/**
* Run the gatling tests w/ params
*
* @param gatlingScenarioClass
* @param runReports
* @return
*/
def runGatlingSimulation(gatlingScenarioClass, runReports = true) {
def absPath = System.getProperty("user.dir");
javaexec {
if (project.hasProperty('jvmArgs')) {
jvmArgs project.jvmArgs.split('\\s+')
}
main = 'io.gatling.app.Gatling'
classpath = sourceSets.test.output + sourceSets.test.runtimeClasspath
args '-sf', sourceSets.test.output.classesDir,
'-s', gatlingScenarioClass,
'-rf', project.buildDir.absolutePath + '/reports/',
'-df', absPath + '/data/'
if (runReports == false) {
args '-nr'
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.2'
}