X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=build.gradle;h=c34128e84bd183f50a02abcfa3e0f12829f18209;hb=refs%2Fheads%2Fjims%2FJAL-3130_Java11_Gradle_publishing;hp=4a63af94f043bb9f88575885c7ba7b70d5f3d29c;hpb=49a555c3890bc93583a5e0d8f0f237db21f5e3d3;p=jalview.git diff --git a/build.gradle b/build.gradle index 4a63af9..c34128e 100644 --- a/build.gradle +++ b/build.gradle @@ -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,19 +18,29 @@ plugins { repositories { jcenter() mavenCentral() + mavenLocal() flatDir { dirs gradlePluginsDir } } mainClassName = launcherClass +def cloverInstrDir = file("$buildDir/$cloverSourcesInstrDir") +def classes = "$jalviewDir/$classesDir" +if (clover.equals("true")) { + use_clover = true + classes = "$buildDir/$cloverClassesDir" +} else { + use_clover = false + classes = "$jalviewDir/$classesDir" +} sourceSets { main { java { srcDirs "$jalviewDir/$sourceDir" - outputDir = file("$jalviewDir/$classesDir") + outputDir = file("$classes") } resources { @@ -43,13 +53,39 @@ sourceSets { compileClasspath = files(sourceSets.main.java.outputDir) compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"]) if (JAVA_VERSION.equals("1.8")) { - print("ADDING J11LIBS TO CLASSPATH") + print("ADDING J11LIBS TO CLASSPATH\n") 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("${buildDir}/${cloverClassesDir}") + } + + 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\n") + compileClasspath += fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"]) + } + + runtimeClasspath = compileClasspath + } + test { java { srcDirs "$jalviewDir/$testSourceDir" @@ -60,21 +96,79 @@ sourceSets { srcDirs = sourceSets.main.resources.srcDirs } - compileClasspath = sourceSets.main.compileClasspath - compileClasspath += files( sourceSets.test.java.outputDir ) + compileClasspath = files( sourceSets.test.java.outputDir ) + if (use_clover) { + compileClasspath += sourceSets.clover.compileClasspath + } else { + compileClasspath += sourceSets.main.compileClasspath + compileClasspath += files(sourceSets.main.java.outputDir) + } + compileClasspath += files( sourceSets.main.resources.srcDirs) 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\n") + compileClasspath += fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"]) + } runtimeClasspath = compileClasspath } +} - modules { - compileClasspath = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"]) - - runtimeClasspath = compileClasspath +// clover bits +dependencies { + if (use_clover) { + cloverCompile 'org.openclover:clover:4.3.1' + testCompile 'org.openclover:clover:4.3.1' } +} +configurations { + cloverRuntime + cloverRuntime.extendsFrom cloverCompile +} + +task cloverInstr() { + // only instrument source, we build test classes as normal + 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}/${cloverSourcesInstrDir}"] + 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) + } +} + + +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) + + // and generate ${reportsDir}/clover/clover.xml + args = ["--initstring", "${buildDir}/clover/clover.db", + "-o", "${reportsDir}/clover/clover.xml"].toArray() + com.atlassian.clover.reporters.xml.XMLReporter.runReport(args) + } } +// end clover bits + + compileJava { doFirst { @@ -95,12 +189,59 @@ compileJava { } +compileTestJava { + + if (use_clover) { + dependsOn compileCloverJava + classpath += configurations.cloverRuntime + } else { + classpath += sourceSets.main.runtimeClasspath + } + 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") + } +} + + +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) { @@ -132,7 +273,7 @@ def getGitBranch() { task createBuildProperties(type: WriteProperties) { inputs.dir("$jalviewDir/$sourceDir") inputs.dir("$jalviewDir/$resourceDir") - outputFile "$jalviewDir/$classesDir/$buildPropertiesFile" + outputFile "$classes/$buildPropertiesFile" /* taking time/date specific comment out to allow better incremental builds */ //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss") comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd") @@ -140,29 +281,29 @@ task createBuildProperties(type: WriteProperties) { property "VERSION", JALVIEW_VERSION property "INSTALLATION", INSTALLATION+" git-commit:"+getGitHash()+" ["+getGitBranch()+"]" outputs.file(outputFile) - outputs.dir("$jalviewDir/$classesDir") + outputs.dir("$classes") } task syncDocs(type: Sync) { - def syncDir = "$jalviewDir/$classesDir/$docDir" + def syncDir = "$classes/$docDir" from fileTree("$jalviewDir/$docDir") into syncDir } -def helpFile = "$jalviewDir/$classesDir/$helpDir/help.jhm" +def helpFile = "$classes/$helpDir/help.jhm" task syncHelp(type: Sync) { inputs.files("$jalviewDir/$helpDir") outputs.files(helpFile) - def syncDir = "$jalviewDir/$classesDir/$helpDir" + def syncDir = "$classes/$helpDir" from fileTree("$jalviewDir/$helpDir") into syncDir } task copyHelp(type: Copy) { def inputDir = "$jalviewDir/$helpDir" - def outputDir = "$jalviewDir/$classesDir/$helpDir" + def outputDir = "$classes/$helpDir" from inputDir into outputDir filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['Version-Rel': "USING_FILTER"]) @@ -172,7 +313,7 @@ task copyHelp(type: Copy) { } task syncLib(type: Sync) { - def syncDir = "$jalviewDir/$classesDir/$libDir" + def syncDir = "$classes/$libDir" from fileTree("$jalviewDir/$libDir") into syncDir } @@ -181,7 +322,7 @@ task syncResources(type: Sync) { from "$jalviewDir/$resourceDir" include "**/*.*" exclude "install4j" - into "$jalviewDir/$classesDir" + into "$classes" preserve { include "**" } @@ -193,28 +334,52 @@ task prepare { dependsOn copyHelp } + //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir test { dependsOn prepare dependsOn compileJava - useTestNG { + if (use_clover) { + dependsOn cloverInstr + } + print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n") + + useTestNG() { includeGroups testngGroups + preserveOrder true + useDefaultListeners=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) { dependsOn copyHelp classpath = sourceSets.main.compileClasspath main = "com.sun.java.help.search.Indexer" - workingDir = "$jalviewDir/$classesDir/$helpDir" + workingDir = "$classes/$helpDir" def argDir = "html" args = [ argDir ] inputs.dir("$workingDir/$argDir") - outputs.dir("$jalviewDir/$classesDir/doc") - outputs.dir("$jalviewDir/$classesDir/help") + outputs.dir("$classes/doc") + outputs.dir("$classes/help") outputs.file("$workingDir/JavaHelpSearch/DOCS") outputs.file("$workingDir/JavaHelpSearch/DOCS.TAB") outputs.file("$workingDir/JavaHelpSearch/OFFSETS") @@ -237,8 +402,10 @@ task linkCheck(type: JavaExec) { dependsOn prepare, compileLinkCheck classpath = files("$jalviewDir/$utilsDir") main = "HelpLinksChecker" - workingDir = "$jalviewDir" - args = [ "$classesDir/$helpDir", "-nointernet" ] + workingDir = jalviewDir + def help = "$classes/$helpDir" + args = [ "$classes/$helpDir", "-nointernet" ] + //args = [ "$classesDir/$helpDir", "-nointernet" ] doFirst { standardOutput new FileOutputStream("$jalviewDir/$utilsDir/HelpLinksChecker.out") @@ -272,12 +439,12 @@ jar { exclude "**/*.jar" exclude "**/*.jar.*" - inputs.dir("$jalviewDir/$classesDir") + inputs.dir("$classes") outputs.file("$jalviewDir/$packageDir/$archiveName") } task copyJars(type: Copy) { - from fileTree("$jalviewDir/$classesDir").include("**/*.jar").include("*.jar").files + from fileTree("$classes").include("**/*.jar").include("*.jar").files into "$jalviewDir/$packageDir" } @@ -492,3 +659,4 @@ task installers(type: com.install4j.gradle.Install4jTask) { inputs.dir(project.ext.getdownWebsiteDir) outputs.dir("$jalviewDir/$install4jBuildDir") } +