1 import java.util.jar.JarEntry;
7 def String getProjectProperty(String propertyName) {
8 String propertyValue = "null"
9 if (hasProperty(propertyName)) {
10 propertyValue = this.properties[propertyName]
13 throw GradleScriptException("PropertyName " + propertyName + " is not defined in properties file")
17 def projectName = "voldemort"
19 def sourceDir = getProjectProperty('src.dir')
20 def distDir = getProjectProperty('dist.dir')
21 def classesDir = getProjectProperty('classes.dir')
22 def javaDir = getProjectProperty('java.dir')
23 def libDir = getProjectProperty('lib.dir')
24 def resourcesDir = getProjectProperty('resources.dir')
25 def javaDocDir = getProjectProperty('javadoc.dir')
27 def voldTestClassesDir = getProjectProperty('testclasses.dir')
29 def commonTestSrcDir = getProjectProperty('commontestsrc.dir')
30 def unitTestSrcDir = getProjectProperty('unittestsrc.dir')
31 def intTestSrcDir = getProjectProperty('inttestsrc.dir')
32 def longTestSrcDir = getProjectProperty('longtestsrc.dir')
34 def contribClassesDir = getProjectProperty('contrib.classes.dir')
35 def contribRootDir = getProjectProperty('contrib.root.dir')
37 def voldVersion = getProjectProperty('curr.release')
38 def javacVersion = getProjectProperty('javac.version')
39 def scalaVersion = getProjectProperty('scalac.version')
41 //This is the javaCompile variable version. Directly defining 'def version' will override this and cause nightmare
44 def archiveDirectoryName = projectName + '-' + version
45 def archiveDirectoryPath = distDir + "/" + archiveDirectoryName
47 def deleteDirectoryContents(directory) {
48 project.file(directory).deleteDir()
49 project.file(directory).mkdirs()
52 println 'java source target compatibility version ' + javacVersion
53 sourceCompatibility = javacVersion
54 targetCompatibility = javacVersion
55 compileJava.options.debug = true
58 tasks.withType(ScalaCompile) {
59 scalaClasspath = files("lib/scala-compiler-${scalaVersion}.jar",
60 "lib/scala-reflect-${scalaVersion}.jar",
61 "lib/scala-library-${scalaVersion}.jar")
65 flatDir { dirs libDir }
66 flatDir { dirs contribRootDir }
72 java { srcDirs = [javaDir]}
79 include '**/*.xsd', 'log4j.properties'
81 output.classesDir = classesDir
82 output.resourcesDir = resourcesDir
93 output.classesDir = voldTestClassesDir
96 java { srcDirs = [contribRootDir] }
97 compileClasspath += sourceSets.main.runtimeClasspath
98 output.classesDir = contribClassesDir
104 from (javaDir) { exclude '**/*.java','**/*.html','**/*.scala', '**/log4j.properties' }
109 compileTestJava.doLast {
111 from (commonTestSrcDir) { exclude '**/*.java','**/*.html' }
112 from (unitTestSrcDir) { exclude '**/*.java','**/*.html' }
113 into voldTestClassesDir
117 compileContribJava.doLast {
119 from (contribRootDir + '/ec2-testing/resources')
120 into contribClassesDir
125 compile fileTree(dir: libDir, includes: ['**/*.jar'])
127 contribCompile sourceSets.main.output
128 contribCompile sourceSets.test.output
130 contribCompile fileTree(dir: contribRootDir, includes: ['**/*.jar'])
131 testCompile 'junit:junit:4.6'
134 task testJar(type: Jar) {
135 baseName = projectName + "-test"
136 from sourceSets.test.output
137 destinationDir = project.file(distDir)
140 task voldJar(type:Jar) {
141 baseName = projectName
143 attributes 'Voldemort-Implementation-Version' : version,
144 'Implementation-Title': 'Voldemort',
145 'Implementation-Version': version,
146 'Implementation-Vendor' :'LinkedIn'
148 from sourceSets.main.output
149 destinationDir = project.file(distDir)
152 task contribJar(type:Jar) {
153 dependsOn voldJar, testJar, sourceSets.contrib.output
154 baseName = projectName + "-contrib"
155 from sourceSets.contrib.output
156 destinationDir = project.file(distDir)
159 task srcJar(type: Jar, dependsOn: classes) {
161 from sourceSets.main.java.srcDirs
162 destinationDir = project.file(distDir)
174 doLast { deleteDirectoryContents(javaDocDir) }
177 task copySources (type: Copy) {
178 from ('.') { include 'bin/**' }
179 from ('.') { include distDir + '/*.jar'}
180 from ('.') { exclude distDir + '/**' ,'bin/**' , 'build/**', '.git/**' , '.gradle/**' }
181 into archiveDirectoryPath
184 task zip (type: Zip) {
185 dependsOn copySources
186 baseName = projectName
189 include archiveDirectoryName + '/bin/**'
193 include archiveDirectoryName + '/**'
194 exclude archiveDirectoryName + '/bin/**'
197 destinationDir = project.file(distDir)
200 task tar (type: Tar) {
201 dependsOn copySources
202 compression = Compression.GZIP
203 baseName = projectName
207 include archiveDirectoryName + '/bin/**'
211 include archiveDirectoryName + '/**'
212 exclude archiveDirectoryName + '/bin/**'
215 destinationDir = project.file(distDir)
218 jar.dependsOn contribJar,srcJar
219 compileContribJava.dependsOn voldJar
220 copySources.dependsOn jar
222 tasks.withType(Test) {
223 // ant restarts jvm for each tests, If not restarted the test runs into outOfMemory even
224 // if you set the JVM to 8gb. On inspecting most of the space is consumed by int[] of
225 // Histogram in the NioSelectorManager. I believe this could be explained by
226 // creating lots of client factory which creates lot of NIO threads. Did not proceed
227 // further as I will be maintaining compatbility with ant. Also if you dont fork for each
228 // tests JMX bean related tests will fail.
230 // Do not set the max parallelism as there are tests that uses the same port and will
231 // run into bind exceptions.
236 // If ignoreFailures is not set, then merged reports will not be generated
237 // Gradle aborts further tasks on test failure. so if you run junitAll
238 // which runs 3 tests, reports task will never be run on failure cases.
239 ignoreFailures = true
244 events "passed", "skipped", "failed"
245 exceptionFormat = 'full'
248 afterTest { test, result ->
249 logger.lifecycle("testFinished: $test, result: $result.resultType")
253 def classesSize = candidateClassFiles.files.size()
254 logger.lifecycle("{} starts executing {} test classes {}",
255 path, classesSize, classesSize > 0? "(" + candidateClassFiles.files*.name[0] + ", ...)" : "")
258 //all standard error messages from tests will get routed to 'DEBUG' level messages.
259 //logging.captureStandardError(LogLevel.DEBUG)
260 //all standard output messages from tests will get routed to 'DEBUG' level messages.
261 //logging.captureStandardOutput(LogLevel.DEBUG)
263 //Set reasonable defaults for reports location
264 reports.html.destination = file("$project.buildDir/reports/$name")
265 reports.junitXml.destination = file("$project.buildDir/$name-results")
267 //Set reasonable defaults classpath and classes dir. They can be reconfigured in an individual task.
268 it.testClassesDir = sourceSets.test.output.classesDir
269 classpath = sourceSets.test.runtimeClasspath
272 task junit(dependsOn: test)
274 Collection<String> testClassesFrom(String dir, String include = '**/*Test.*') {
275 //take all *Test.java files found in given dir, make the path relative and replace .java with .class
276 fileTree(dir: dir, includes: [include]).collect { it.absolutePath.replaceAll(file(dir).absolutePath + "/", "").replaceAll(".java\$", ".class")}
280 description = "Runs acceptance tests"
281 include testClassesFrom(unitTestSrcDir)
284 task junitLong(type: Test) {
285 description = "Runs long junit tests"
286 include testClassesFrom(longTestSrcDir)
289 task junitRebalance(type: Test) {
290 include testClassesFrom(unitTestSrcDir, '**/*Rebalance*Test.java')
293 task junitRebalanceLong(type: Test) {
294 include testClassesFrom(longTestSrcDir, '**/*Rebalance*Test.java')
297 task contribJunit(type: Test) {
298 description = "Run contrib junit tests except EC2 and Krati tests."
299 it.testClassesDir = file(contribClassesDir)
301 exclude '**/*PerformanceTest.class'
302 exclude '**/*RemoteTest.class'
303 exclude '**/Ec2*Test.class'
304 exclude '**/Krati*Test.class'
305 exclude '**/HadoopStoreBuilder*Test.class'
307 classpath += sourceSets.contrib.runtimeClasspath + sourceSets.contrib.output
310 task junitAll(type: TestReport) {
311 reportOn test, junitLong, contribJunit
312 destinationDir = file("$project.buildDir/reports/$name")
315 task aggregatedJunit(type: TestReport) {
316 destinationDir = file("$project.buildDir/reports/$name")
319 tasks.withType(Test) {
320 finalizedBy aggregatedJunit
322 aggregatedJunit.reportOn it.binResultsDir