JAL-3541 Individual tests now instrumented and reported. Added cloverConsoleReport.
authorBen Soares <bsoares@dundee.ac.uk>
Thu, 14 May 2020 14:53:00 +0000 (15:53 +0100)
committerBen Soares <bsoares@dundee.ac.uk>
Thu, 14 May 2020 14:53:00 +0000 (15:53 +0100)
build.gradle

index ae84585..92d735d 100644 (file)
@@ -127,19 +127,26 @@ ext {
   sourceDir = string("${jalviewDir}/${bareSourceDir}")
   resourceDir = string("${jalviewDir}/${resource_dir}")
   bareTestSourceDir = string(test_source_dir)
-  testSourceDir = string("${jalviewDir}/${bareTestSourceDir}")
+  testDir = string("${jalviewDir}/${bareTestSourceDir}")
 
   classesDir = string("${jalviewDir}/${classes_dir}")
 
   // clover
   useClover = clover.equals("true")
-  cloverInstrDir = file("${buildDir}/clover/${clover_sources_instr_dir}")
-  cloverClassesDir = file("${buildDir}/clover/${clover_classes_dir}")
-  cloverReportDir = file("${buildDir}/clover/${clover_report_dir}")
-  cloverDb = string("${buildDir}/clover/clover.db")
+  cloverBuildDir = "${buildDir}/clover"
+  cloverInstrDir = file("${cloverBuildDir}/clover-instr")
+  cloverClassesDir = file("${cloverBuildDir}/clover-classes")
+  cloverReportDir = file("${cloverBuildDir}/clover-report")
+  cloverTestInstrDir = file("${cloverBuildDir}/clover-test-instr")
+  cloverTestClassesDir = file("${cloverBuildDir}/clover-test-classes")
+  //cloverTestClassesDir = cloverClassesDir
+  cloverDb = string("${cloverBuildDir}/clover.db")
 
   resourceClassesDir = useClover ? cloverClassesDir : classesDir
 
+  testSourceDir = useClover ? cloverTestInstrDir : testDir
+  testClassesDir = useClover ? cloverTestClassesDir : "${jalviewDir}/${test_output_dir}"
+
   getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
   buildDist = true
 
@@ -466,8 +473,10 @@ sourceSets {
     }
 
     compileClasspath = files( sourceSets.clover.java.outputDir )
+    //compileClasspath += files( testClassesDir )
     compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
     compileClasspath += fileTree(dir: "${jalviewDir}/${clover_lib_dir}", include: ["*.jar"])
+    compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["**/*.jar"])
 
     runtimeClasspath = compileClasspath
   }
@@ -475,7 +484,7 @@ sourceSets {
   test {
     java {
       srcDirs testSourceDir
-      outputDir = file("${jalviewDir}/${test_output_dir}")
+      outputDir = file(testClassesDir)
     }
 
     resources {
@@ -488,6 +497,7 @@ sourceSets {
 
     runtimeClasspath = compileClasspath
   }
+
 }
 
 
@@ -629,9 +639,18 @@ eclipse {
 // clover bits
 
 
-task cloverInstr(type: JavaExec) {
+task cleanClover {
+  doFirst {
+    delete cloverBuildDir
+  }
+}
+
+
+task cloverInstrJava(type: JavaExec) {
   group = "Verification"
-  description = "Create clover instrumented source files"
+  description = "Create clover instrumented source java files"
+
+  dependsOn cleanClover
 
   inputs.files(sourceSets.main.allJava)
   outputs.dir(cloverInstrDir)
@@ -658,34 +677,72 @@ task cloverInstr(type: JavaExec) {
 
   doFirst {
     delete cloverInstrDir
-    delete cloverDb
     println("Clover: About to instrument "+srcFiles.size() +" files")
   }
 }
 
 
+task cloverInstrTests(type: JavaExec) {
+  group = "Verification"
+  description = "Create clover instrumented source test files"
+
+  dependsOn cleanClover
+
+  inputs.files(testDir)
+  outputs.dir(cloverTestInstrDir)
+
+  classpath = sourceSets.clover.compileClasspath
+  main = "com.atlassian.clover.CloverInstr"
+
+  def argsList = [
+    "--encoding",
+    "UTF-8",
+    "--initstring",
+    cloverDb,
+    "--srcdir",
+    testDir,
+    "--destdir",
+    cloverTestInstrDir.getPath(),
+  ]
+  args argsList.toArray()
+
+  doFirst {
+    delete cloverTestInstrDir
+    println("Clover: About to instrument test files")
+  }
+}
+
+
+task cloverInstr {
+  group = "Verification"
+  description = "Create clover instrumented all source files"
+
+  dependsOn cloverInstrJava
+  dependsOn cloverInstrTests
+}
+
+
 cloverClasses.dependsOn cloverInstr
 
 
-task cloverXmlReport(type: JavaExec) {
+task cloverConsoleReport(type: JavaExec) {
   group = "Verification"
-  description = "Creates clover XML report"
+  description = "Creates clover console report"
 
-  inputs.dir cloverClassesDir
-  outputs.dir cloverReportDir
   onlyIf {
     file(cloverDb).exists()
   }
 
+  inputs.dir cloverClassesDir
+
   classpath = sourceSets.clover.runtimeClasspath
-  main = "com.atlassian.clover.reporters.xml.XMLReporter"
+  main = "com.atlassian.clover.reporters.console.ConsoleReporter"
 
   def argsList = [
     "--alwaysreport",
     "--initstring",
     cloverDb,
-    "--outfile",
-    "${cloverReportDir}/clover.xml"
+    "--unittests"
   ]
 
   args argsList.toArray()
@@ -696,12 +753,14 @@ task cloverHtmlReport(type: JavaExec) {
   group = "Verification"
   description = "Creates clover HTML report"
 
-  inputs.dir cloverClassesDir
-  outputs.dir cloverReportDir
   onlyIf {
     file(cloverDb).exists()
   }
 
+  def cloverHtmlDir = "${cloverReportDir}/clover"
+  inputs.dir cloverClassesDir
+  outputs.dir cloverHtmlDir
+
   classpath = sourceSets.clover.runtimeClasspath
   main = "com.atlassian.clover.reporters.html.HtmlReporter"
 
@@ -710,7 +769,34 @@ task cloverHtmlReport(type: JavaExec) {
     "--initstring",
     cloverDb,
     "--outputdir",
-    "${cloverReportDir}/clover"
+    cloverHtmlDir
+  ]
+
+  args argsList.toArray()
+}
+
+
+task cloverXmlReport(type: JavaExec) {
+  group = "Verification"
+  description = "Creates clover XML report"
+
+  onlyIf {
+    file(cloverDb).exists()
+  }
+
+  def cloverXmlFile = "${cloverReportDir}/clover.xml"
+  inputs.dir cloverClassesDir
+  outputs.file cloverXmlFile
+
+  classpath = sourceSets.clover.runtimeClasspath
+  main = "com.atlassian.clover.reporters.xml.XMLReporter"
+
+  def argsList = [
+    "--alwaysreport",
+    "--initstring",
+    cloverDb,
+    "--outfile",
+    cloverXmlFile
   ]
 
   args argsList.toArray()
@@ -734,14 +820,7 @@ compileCloverJava {
     options.compilerArgs += additional_compiler_args
     print ("Setting target compatibility to "+targetCompatibility+"\n")
   }
-  classpath += configurations.cloverRuntime
-}
-
-
-task cleanClover {
-  doFirst {
-    delete "${buildDir/clover}"
-  }
+  //classpath += configurations.cloverRuntime
 }
 // end clover bits
 
@@ -943,11 +1022,12 @@ task prepare {
 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
 test {
   dependsOn prepare
+  //dependsOn compileJava ////? DELETE
 
   if (useClover) {
     dependsOn cloverClasses
-  } else {
-    dependsOn compileJava
+   } else { //?
+     dependsOn compileJava //?
   }
 
   useTestNG() {