JAL-3130 gradle test now runs open clover 4.3.1 and new cloverReport task
[jalview.git] / build.gradle
index ec8267a..c6f86d6 100644 (file)
@@ -4,7 +4,7 @@ import org.gradle.internal.os.OperatingSystem
 
 buildscript {
   dependencies {
-    //classpath files("$gradlePluginsDir/gradle-macappbundle-2.3.0-patched-2.3.0.jar")
+        classpath 'org.openclover:clover:4.3.1'
   }
 }
 
@@ -18,12 +18,14 @@ plugins {
 repositories {
   jcenter()
   mavenCentral()
+  mavenLocal()
   flatDir {
     dirs gradlePluginsDir
   }
 }
 
 mainClassName = launcherClass
+def cloverInstrDir = file("$buildDir/sources-instr")
 
 sourceSets {
 
@@ -42,14 +44,43 @@ sourceSets {
 
     compileClasspath = files(sourceSets.main.java.outputDir)
     compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
-    //compileClasspath += fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
+    if (JAVA_VERSION.equals("1.8")) {
+      print("ADDING J11LIBS TO CLASSPATH")
+      compileClasspath += fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
+    }
 
     runtimeClasspath = compileClasspath
   }
 
+  modules {
+    compileClasspath = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
+
+    runtimeClasspath = compileClasspath
+  }
+  
+  clover {
+    java {
+        srcDirs = [ cloverInstrDir ]
+        outputDir = file("$jalviewDir/$testOutputDir")
+    }
+    
+    resources {
+      srcDirs = sourceSets.main.resources.srcDirs
+    }
+    compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
+    compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
+    compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
+    if (JAVA_VERSION.equals("1.8")) {
+      print("ADDING J11LIBS TO CLASSPATH")
+      compileClasspath += fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
+    }
+
+    runtimeClasspath = compileClasspath
+  }
+  
   test {
     java {
-      srcDirs "$jalviewDir/$testSourceDir"
+      srcDirs = [ cloverInstrDir ]
       outputDir = file("$jalviewDir/$testOutputDir")
     }
 
@@ -57,21 +88,66 @@ sourceSets {
       srcDirs = sourceSets.main.resources.srcDirs
     }
 
-    compileClasspath = sourceSets.main.compileClasspath
-    compileClasspath += files( sourceSets.test.java.outputDir )
+
+    compileClasspath += configurations.cloverRuntime + files( sourceSets.test.java.outputDir )
     compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"])
+    compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"])
+    if (JAVA_VERSION.equals("1.8")) {
+      print("ADDING J11LIBS TO CLASSPATH")
+      compileClasspath += fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
+    }
 
     runtimeClasspath = compileClasspath
   }
+}
 
-  modules {
-    compileClasspath = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"])
+// clover bits
+dependencies {
+  cloverCompile 'org.openclover:clover:4.3.1'
+  testCompile 'org.openclover:clover:4.3.1'
+}
 
-    runtimeClasspath = compileClasspath
-  }
+configurations {
+    cloverRuntime
+    cloverRuntime.extendsFrom cloverCompile
+}
+task cloverInstr() {
+    inputs.files files (sourceSets.main.allJava, fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
+    outputs.dir cloverInstrDir
 
+    doFirst {
+        delete cloverInstrDir
+        def argsList = ["--initstring", "${buildDir}/clover/clover.db",
+                        "-d", "${buildDir}/sources-instr"]
+        argsList.addAll(inputs.files.files.collect({ file ->
+            file.absolutePath
+        }))
+        String[] args = argsList.toArray()
+        println("About to instrument "+args.length +" files")
+        com.atlassian.clover.CloverInstr.mainImpl(args)
+    }
 }
 
+test.dependsOn cloverInstr
+task cloverReport {
+    inputs.dir "${buildDir}/clover"
+    outputs.dir "${reportsDir}/clover"
+    onlyIf {
+        file("${buildDir}/clover/clover.db").exists()
+    }
+    doFirst {
+        def argsList = ["--initstring", "${buildDir}/clover/clover.db",
+                        "-o", "${reportsDir}/clover"]
+        String[] args = argsList.toArray()
+        com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
+    }
+}
+
+// end clover bits
+
+
 compileJava {
 
   doFirst {
@@ -87,16 +163,59 @@ compileJava {
         '--add-modules', j11modules
       ]
     }
+    print ("Setting target compatibility to "+targetCompatibility+"\n")
   }
 
 }
 
+compileTestJava {
+
+  doFirst {
+    if (JAVA_VERSION.equals("1.8")) {
+      sourceCompatibility = 1.8
+      targetCompatibility = 1.8
+    } else if (JAVA_VERSION.equals("11")) {
+      sourceCompatibility = 11
+      targetCompatibility = 11
+
+      options.compilerArgs = [
+        '--module-path', sourceSets.modules.compileClasspath.asPath,
+        '--add-modules', j11modules
+      ]
+    }
+    print ("Setting target compatibility to "+targetCompatibility+"\n")
+  }
+  classpath += configurations.cloverRuntime
+}
+
+
+//compileCloverJava {
+//
+//  doFirst {
+//    if (JAVA_VERSION.equals("1.8")) {
+//      sourceCompatibility = 1.8
+//      targetCompatibility = 1.8
+//    } else if (JAVA_VERSION.equals("11")) {
+//      sourceCompatibility = 11
+//      targetCompatibility = 11
+//
+//      options.compilerArgs += [
+//        '--module-path', sourceSets.modules.compileClasspath.asPath,
+//        '--add-modules', j11modules
+//      ]
+//    }
+//    print ("Setting target compatibility to "+targetCompatibility+"\n")
+//  }
+//  classpath += configurations.cloverRuntime
+//}
+
 clean {
   delete sourceSets.main.java.outputDir
 }
 
 cleanTest {
   delete sourceSets.test.java.outputDir
+  delete cloverInstrDir
 }
 
 def getDate(format) {
@@ -176,6 +295,7 @@ task syncLib(type: Sync) {
 task syncResources(type: Sync) {
   from "$jalviewDir/$resourceDir"
   include "**/*.*"
+  exclude "install4j"
   into "$jalviewDir/$classesDir"
   preserve {
     include "**"
@@ -188,15 +308,35 @@ task prepare {
   dependsOn copyHelp
 }
 
+
 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
 test {
   dependsOn prepare
-  dependsOn compileJava
-  useTestNG {
+  
+  
+  useTestNG()
+  options {
     includeGroups testngGroups
+    preserveOrder true
   }
+  
   workingDir = jalviewDir
   //systemProperties 'clover.jar' System.properties.clover.jar
+  if (JAVA_VERSION.equals("1.8")) {
+    sourceCompatibility = 1.8
+    targetCompatibility = 1.8
+  } else if (JAVA_VERSION.equals("11")) {
+    sourceCompatibility = 11
+    targetCompatibility = 11
+
+    jvmArgs += [
+      '--module-path',
+      sourceSets.modules.compileClasspath.asPath,
+      '--add-modules',
+      j11modules
+    ]
+  }
+  print ("Setting target compatibility to "+targetCompatibility+"\n")
 }
 
 task buildIndices(type: JavaExec) {
@@ -340,24 +480,32 @@ task getdownWebsite() {
     }
     props.each{ prop, val ->
       if (prop.startsWith("getdown_txt_") && val != null) {
-        // file values rationalised
-        if (val.indexOf('/') > -1) {
-          def r = null
-          if (val.indexOf('/') == 0) {
-            // absolute path
-            r = file(val)
-          } else if (val.indexOf('/') > 0) {
-            // relative path (relative to jalviewDir)
-            r = file( jalviewDir + '/' + val )
+        if (prop.startsWith("getdown_txt_multi_")) {
+          def key = prop.substring(18)
+          val.split(",").each{ v ->
+            def line = key + " = " + v + "\n"
+            getdownTextString += line
           }
-          if (r.exists()) {
-            val = getdown_resource_dir + '/' + r.getName()
-            getdownWebsiteResourceFilenames += val
-            getdownResourceFilenames += r.getPath()
+        } else {
+          // file values rationalised
+          if (val.indexOf('/') > -1) {
+            def r = null
+            if (val.indexOf('/') == 0) {
+              // absolute path
+              r = file(val)
+            } else if (val.indexOf('/') > 0) {
+              // relative path (relative to jalviewDir)
+              r = file( jalviewDir + '/' + val )
+            }
+            if (r.exists()) {
+              val = getdown_resource_dir + '/' + r.getName()
+              getdownWebsiteResourceFilenames += val
+              getdownResourceFilenames += r.getPath()
+            }
           }
+          def line = prop.substring(12) + " = " + val + "\n"
+          getdownTextString += line
         }
-        def line = prop.substring(12) + " = " + val + "\n"
-        getdownTextString += line
       }
     }
 
@@ -479,3 +627,4 @@ task installers(type: com.install4j.gradle.Install4jTask) {
   inputs.dir(project.ext.getdownWebsiteDir)
   outputs.dir("$jalviewDir/$install4jBuildDir")
 }
+