From: Ben Soares Date: Tue, 12 May 2020 22:05:14 +0000 (+0100) Subject: JAL-3541 JavaExec tasks for cloverInstr and cloverReport. Rationalised compileClasspa... X-Git-Tag: Release_2_11_1_1~13^2~26^2^2~7 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ef3fcd7746645316925b66c36cd56dd68b4a38b7;p=jalview.git JAL-3541 JavaExec tasks for cloverInstr and cloverReport. Rationalised compileClasspaths for main, clover and test. --- diff --git a/build.gradle b/build.gradle index 2c7f138..431c67b 100644 --- a/build.gradle +++ b/build.gradle @@ -13,9 +13,6 @@ buildscript { mavenCentral() mavenLocal() } - dependencies { - classpath 'org.openclover:clover:4.4.1' - } } @@ -132,19 +129,16 @@ ext { bareTestSourceDir = string(test_source_dir) testSourceDir = string("${jalviewDir}/${bareTestSourceDir}") + classesDir = string("${jalviewDir}/${classes_dir}") + // clover - cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}") + 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") - classesDir = string("${jalviewDir}/${classes_dir}") - if (clover.equals("true")) { - use_clover = true - classesDir = string("${buildDir}/${cloverClassesDir}") - } else { - use_clover = false - classesDir = string("${jalviewDir}/${classes_dir}") - } - classes = classesDir + resourceClassesDir = useClover ? cloverClassesDir : classesDir getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}") buildDist = true @@ -173,8 +167,8 @@ ext { getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}") jvlChannelName += "_${getdownChannelName}" // automatically add the test group Not-bamboo for exclusion - if ("".equals(testngExcludedGroups)) { - testngExcludedGroups = "Not-bamboo" + if ("".equals(testng_excluded_groups)) { + testng_excluded_groups = "Not-bamboo" } install4jExtraScheme = "jalviewb" break @@ -409,8 +403,8 @@ ext { - buildingHTML = string("${jalviewDir}/${docDir}/building.html") - helpFile = string("${classesDir}/${help_dir}/help.jhm") + buildingHTML = string("${jalviewDir}/${doc_dir}/building.html") + helpFile = string("${resourceClassesDir}/${help_dir}/help.jhm") helpParentDir = string("${jalviewDir}/${help_parent_dir}") helpSourceDir = string("${helpParentDir}/${help_dir}") @@ -456,7 +450,6 @@ sourceSets { jar.destinationDir = file("${jalviewDir}/${packageDir}") compileClasspath = files(sourceSets.main.java.outputDir) - //compileClasspath += files(sourceSets.main.resources.srcDirs) compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"]) runtimeClasspath = compileClasspath @@ -464,18 +457,17 @@ sourceSets { clover { java { - srcDirs = [ cloverInstrDir ] - outputDir = file("${buildDir}/${cloverClassesDir}") + srcDirs cloverInstrDir + outputDir = cloverClassesDir } resources { srcDirs = sourceSets.main.resources.srcDirs } - compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir ) - compileClasspath += files(sourceSets.main.java.outputDir) - compileClasspath += sourceSets.main.compileClasspath - compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"]) + + compileClasspath = files( sourceSets.clover.java.outputDir ) compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"]) + compileClasspath += fileTree(dir: "${jalviewDir}/${clover_lib_dir}", include: ["*.jar"]) runtimeClasspath = compileClasspath } @@ -483,44 +475,22 @@ sourceSets { test { java { srcDirs testSourceDir - outputDir = file("${jalviewDir}/${testOutputDir}") + outputDir = file("${jalviewDir}/${test_output_dir}") } resources { - srcDirs = sourceSets.main.resources.srcDirs + srcDirs = useClover ? sourceSets.clover.resources.srcDirs : sourceSets.main.resources.srcDirs } compileClasspath = files( sourceSets.test.java.outputDir ) - - if (use_clover) { - compileClasspath = sourceSets.clover.compileClasspath - } else { - compileClasspath += files(sourceSets.main.java.outputDir) - } - - compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"]) - compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"]) - compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"]) + compileClasspath += useClover ? sourceSets.clover.compileClasspath : sourceSets.main.compileClasspath + compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["**/*.jar"]) runtimeClasspath = compileClasspath } } -// clover bits -dependencies { - if (use_clover) { - cloverCompile 'org.openclover:clover:4.4.1' - testCompile 'org.openclover:clover:4.4.1' - } -} - -configurations { - cloverRuntime - cloverRuntime.extendsFrom cloverCompile -} - - // eclipse project and settings files creation, also used by buildship eclipse { project { @@ -656,27 +626,40 @@ eclipse { } -task cloverInstr { - // only instrument source, we build test classes as normal - inputs.files files (sourceSets.main.allJava,sourceSets.test.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"])) - outputs.dir cloverInstrDir +// clover bits + + +task cloverInstr(type: JavaExec) { + group = "Verification" + description = "Create clover instrumented source files" + + inputs.files(sourceSets.main.allJava) + outputs.dir(cloverInstrDir) + + //classpath = fileTree(dir: "${jalviewDir}/${clover_lib_dir}", include: ["*.jar"]) + classpath = sourceSets.clover.compileClasspath + main = "com.atlassian.clover.CloverInstr" + + def argsList = [ + "--encoding", + "UTF-8", + "--initstring", + cloverDb, + "--destdir", + cloverInstrDir.getPath(), + ] + def srcFiles = sourceSets.main.allJava.files + argsList.addAll( + srcFiles.collect( + { file -> file.absolutePath } + ) + ) + args argsList.toArray() doFirst { delete cloverInstrDir - def argsList = [ - "--initstring", - cloverDb, - "-d", - cloverInstrDir.getPath(), - ] - 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) + delete cloverDb + println("Clover: About to instrument "+srcFiles.size() +" files") } } @@ -684,33 +667,62 @@ task cloverInstr { cloverClasses.dependsOn cloverInstr -task cloverReport { +task cloverXmlReport(type: JavaExec) { group = "Verification" - description = "Creates the Clover report" - inputs.dir "${buildDir}/clover" - outputs.dir "${reportsDir}/clover" + description = "Creates clover XML report" + + inputs.dir cloverClassesDir + outputs.dir cloverReportDir onlyIf { file(cloverDb).exists() } - doFirst { - def argsList = [ - "--initstring", - cloverDb, - "-o", - "${reportsDir}/clover" - ] - String[] args = argsList.toArray() - com.atlassian.clover.reporters.html.HtmlReporter.runReport(args) - - // and generate ${reportsDir}/clover/clover.xml - args = [ - "--initstring", - cloverDb, - "-o", - "${reportsDir}/clover/clover.xml" - ].toArray() - com.atlassian.clover.reporters.xml.XMLReporter.runReport(args) + + classpath = sourceSets.clover.runtimeClasspath + main = "com.atlassian.clover.reporters.xml.XMLReporter" + + def argsList = [ + "--alwaysreport", + "--initstring", + cloverDb, + "--outfile", + "${cloverReportDir}/clover.xml" + ] + + args argsList.toArray() +} + + +task cloverHtmlReport(type: JavaExec) { + group = "Verification" + description = "Creates clover HTML report" + + inputs.dir cloverClassesDir + outputs.dir cloverReportDir + onlyIf { + file(cloverDb).exists() } + + classpath = sourceSets.clover.runtimeClasspath + main = "com.atlassian.clover.reporters.html.HtmlReporter" + + def argsList = [ + "--alwaysreport", + "--initstring", + cloverDb, + "--outputdir", + "${cloverReportDir}/clover" + ] + + args argsList.toArray() +} + + +task cloverReport { + group = "Verification" + description = "Creates clover reports" + + dependsOn cloverXmlReport + dependsOn cloverHtmlReport } @@ -728,8 +740,7 @@ compileCloverJava { task cleanClover { doFirst { - delete cloverInstrDir - delete cloverDb + delete "${buildDir/clover}" } } // end clover bits @@ -748,12 +759,6 @@ compileJava { compileTestJava { - if (use_clover) { - dependsOn compileCloverJava - classpath += configurations.cloverRuntime - } else { - classpath += sourceSets.main.runtimeClasspath - } doFirst { sourceCompatibility = compile_source_compatibility targetCompatibility = compile_target_compatibility @@ -832,8 +837,8 @@ task cleanBuildingHTML(type: Delete) { task convertBuildingMD(type: Exec) { dependsOn cleanBuildingHTML - def buildingMD = "${jalviewDir}/${docDir}/building.md" - def css = "${jalviewDir}/${docDir}/github.css" + def buildingMD = "${jalviewDir}/${doc_dir}/building.md" + def css = "${jalviewDir}/${doc_dir}/github.css" def pandoc = null pandoc_exec.split(",").each { @@ -875,8 +880,8 @@ clean { task syncDocs(type: Sync) { dependsOn convertBuildingMD - def syncDir = "${classesDir}/${docDir}" - from fileTree("${jalviewDir}/${docDir}") + def syncDir = "${resourceClassesDir}/${doc_dir}" + from fileTree("${jalviewDir}/${doc_dir}") into syncDir } @@ -884,7 +889,7 @@ task syncDocs(type: Sync) { task copyHelp(type: Copy) { def inputDir = helpSourceDir - def outputDir = "${classesDir}/${help_dir}" + def outputDir = "${resourceClassesDir}/${help_dir}" from(inputDir) { exclude '**/*.gif' exclude '**/*.jpg' @@ -912,7 +917,7 @@ task copyHelp(type: Copy) { task syncLib(type: Sync) { - def syncDir = "${classesDir}/${libDistDir}" + def syncDir = "${resourceClassesDir}/${libDistDir}" from fileTree("${jalviewDir}/${libDistDir}") into syncDir } @@ -921,7 +926,7 @@ task syncLib(type: Sync) { task syncResources(type: Sync) { from resourceDir include "**/*.*" - into "${classesDir}" + into "${resourceClassesDir}" preserve { include "**" } @@ -938,18 +943,16 @@ task prepare { //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir test { dependsOn prepare - dependsOn compileJava - if (use_clover) { - dependsOn cloverInstr - } - if (use_clover) { - print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n") + if (useClover) { + dependsOn cloverClasses + } else { + dependsOn compileJava } useTestNG() { - includeGroups testngGroups - excludeGroups testngExcludedGroups + includeGroups testng_groups + excludeGroups testng_excluded_groups preserveOrder true useDefaultListeners=true } @@ -972,6 +975,11 @@ test { targetCompatibility = compile_target_compatibility jvmArgs += additional_compiler_args + doFirst { + if (useClover) { + print("Running tests " + (useClover?"WITH":"WITHOUT") + " clover [clover="+useClover+"]\n") + } + } } @@ -997,22 +1005,22 @@ task buildIndices(type: JavaExec) { task compileLinkCheck(type: JavaCompile) { options.fork = true - classpath = files("${jalviewDir}/${utilsDir}") - destinationDir = file("${jalviewDir}/${utilsDir}") - source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"]) - - inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java") - inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java") - outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class") - outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class") + classpath = files("${jalviewDir}/${utils_dir}") + destinationDir = file("${jalviewDir}/${utils_dir}") + source = fileTree(dir: "${jalviewDir}/${utils_dir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"]) + + inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java") + inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java") + outputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.class") + outputs.file("${jalviewDir}/${utils_dir}/BufferedLineReader.class") } task linkCheck(type: JavaExec) { dependsOn prepare, compileLinkCheck - def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out") - classpath = files("${jalviewDir}/${utilsDir}") + def helpLinksCheckerOutFile = file("${jalviewDir}/${utils_dir}/HelpLinksChecker.out") + classpath = files("${jalviewDir}/${utils_dir}") main = "HelpLinksChecker" workingDir = jalviewDir args = [ "${classesDir}/${help_dir}", "-nointernet" ] @@ -1033,7 +1041,7 @@ task linkCheck(type: JavaExec) { // import the pubhtmlhelp target ant.properties.basedir = "${jalviewDir}" ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}" -ant.importBuild "${utilsDir}/publishHelp.xml" +ant.importBuild "${utils_dir}/publishHelp.xml" task cleanPackageDir(type: Delete) { @@ -1048,7 +1056,7 @@ jar { dependsOn createBuildProperties manifest { - attributes "Main-Class": mainClass, + attributes "Main-Class": main_class, "Permissions": "all-permissions", "Application-Name": "Jalview Desktop", "Codebase": application_codebase @@ -1114,7 +1122,7 @@ shadowJar { manifest { attributes 'Implementation-Version': JALVIEW_VERSION } - mainClassName = shadowJarMainClass + mainClassName = shadow_jar_main_class mergeServiceFiles() classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION minimize() diff --git a/gradle.properties b/gradle.properties index 782a495..5b80dae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,38 +23,35 @@ proxyHost = sqid jalview_keyalg = SHA1withRSA jalview_keydig = SHA1 -testngGroups = Functional -testngExcludedGroups = +testng_groups = Functional +testng_excluded_groups = j8libDir = j8lib j11libDir = j11lib resource_dir = resources help_parent_dir = help help_dir = help -docDir = doc -schemaDir = schemas +doc_dir = doc classes_dir = classes -examplesDir = examples clover = false -use_clover = false +clover_classes_dir = clover-classes +clover_sources_instr_dir = clover-instr +clover_report_dir = clover-report +clover_lib_dir = utils/clover/lib cloverReportJVMHeap = 2g cloverReportJVMArgs = -Dfile.encoding=UTF-8 cloverReportHTMLOptions = cloverReportXMLOptions = -cloverClassesDir = clover-classes -cloverSourcesInstrDir = sources-instr packageDir = dist ARCHIVEDIR = -outputJar = jalview.jar -testOutputDir = tests -utilsDir = utils +test_output_dir = tests +utils_dir = utils build_properties_file = .build_properties application_codebase = *.jalview.org -mainClass = jalview.bin.Jalview -shadowJarMainClass = jalview.bin.Launcher -launcherClass = jalview.bin.Jalview +main_class = jalview.bin.Jalview +shadow_jar_main_class = jalview.bin.Launcher jalview_name = Jalview diff --git a/utils/clover/lib/clover-ant-4.4.1.jar b/utils/clover/lib/clover-ant-4.4.1.jar new file mode 100644 index 0000000..4f92395 Binary files /dev/null and b/utils/clover/lib/clover-ant-4.4.1.jar differ