import org.apache.tools.ant.filters.ReplaceTokens import org.gradle.internal.os.OperatingSystem buildscript { dependencies { classpath 'org.openclover:clover:4.3.1' } } plugins { id 'java' id 'application' id 'com.github.johnrengelman.shadow' version '4.0.3' id 'com.install4j.gradle' version '7.0.9' } 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("$classes") } resources { srcDirs "$jalviewDir/$resourceDir" srcDirs "$jalviewDir/$libDir" } jar.destinationDir = file("$jalviewDir/$packageDir") compileClasspath = files(sourceSets.main.java.outputDir) 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 { 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" outputDir = file("$jalviewDir/$testOutputDir") } resources { srcDirs = sourceSets.main.resources.srcDirs } 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 } } // 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 { 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") } } 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) { def date = new Date() //return date.format("dd MMMM yyyy") return date.format(format) } def getGitHash() { def stdout = new ByteArrayOutputStream() exec { commandLine "git", "rev-parse", "--short", "HEAD" standardOutput = stdout workingDir = jalviewDir } return stdout.toString().trim() } def getGitBranch() { def stdout = new ByteArrayOutputStream() exec { commandLine "git", "rev-parse", "--abbrev-ref", "HEAD" standardOutput = stdout workingDir = jalviewDir } return stdout.toString().trim() } task createBuildProperties(type: WriteProperties) { inputs.dir("$jalviewDir/$sourceDir") inputs.dir("$jalviewDir/$resourceDir") 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") property "BUILD_DATE", getDate("dd MMMM yyyy") property "VERSION", JALVIEW_VERSION property "INSTALLATION", INSTALLATION+" git-commit:"+getGitHash()+" ["+getGitBranch()+"]" outputs.file(outputFile) outputs.dir("$classes") } task syncDocs(type: Sync) { def syncDir = "$classes/$docDir" from fileTree("$jalviewDir/$docDir") into syncDir } def helpFile = "$classes/$helpDir/help.jhm" task syncHelp(type: Sync) { inputs.files("$jalviewDir/$helpDir") outputs.files(helpFile) def syncDir = "$classes/$helpDir" from fileTree("$jalviewDir/$helpDir") into syncDir } task copyHelp(type: Copy) { def inputDir = "$jalviewDir/$helpDir" def outputDir = "$classes/$helpDir" from inputDir into outputDir filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['Version-Rel': "USING_FILTER"]) inputs.dir(inputDir) outputs.files(helpFile) outputs.dir(outputDir) } task syncLib(type: Sync) { def syncDir = "$classes/$libDir" from fileTree("$jalviewDir/$libDir") into syncDir } task syncResources(type: Sync) { from "$jalviewDir/$resourceDir" include "**/*.*" exclude "install4j" into "$classes" preserve { include "**" } } task prepare { dependsOn syncResources dependsOn syncDocs dependsOn copyHelp } //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir test { dependsOn prepare dependsOn compileJava 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 = "$classes/$helpDir" def argDir = "html" args = [ argDir ] inputs.dir("$workingDir/$argDir") outputs.dir("$classes/doc") outputs.dir("$classes/help") outputs.file("$workingDir/JavaHelpSearch/DOCS") outputs.file("$workingDir/JavaHelpSearch/DOCS.TAB") outputs.file("$workingDir/JavaHelpSearch/OFFSETS") outputs.file("$workingDir/JavaHelpSearch/POSITIONS") outputs.file("$workingDir/JavaHelpSearch/SCHEMA") outputs.file("$workingDir/JavaHelpSearch/TMAP") } 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"]) outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.class") outputs.file("$jalviewDir/$utilsDir/BufferedLineReader.class") } task linkCheck(type: JavaExec) { dependsOn prepare, compileLinkCheck classpath = files("$jalviewDir/$utilsDir") main = "HelpLinksChecker" workingDir = jalviewDir def help = "$classes/$helpDir" args = [ "$classes/$helpDir", "-nointernet" ] //args = [ "$classesDir/$helpDir", "-nointernet" ] doFirst { standardOutput new FileOutputStream("$jalviewDir/$utilsDir/HelpLinksChecker.out") } outputs.file("$jalviewDir/$utilsDir/HelpLinksChecker.out") } task cleanPackageDir(type: Delete) { delete fileTree("$jalviewDir/$packageDir").include("*.jar") } jar { dependsOn linkCheck dependsOn buildIndices dependsOn createBuildProperties manifest { attributes "Main-Class": mainClass, "Permissions": "all-permissions", "Application-Name": "Jalview Desktop", "Codebase": application_codebase } destinationDir = file("$jalviewDir/$packageDir") archiveName = rootProject.name+".jar" exclude "cache*/**" exclude "*.jar" exclude "*.jar.*" exclude "**/*.jar" exclude "**/*.jar.*" inputs.dir("$classes") outputs.file("$jalviewDir/$packageDir/$archiveName") } task copyJars(type: Copy) { from fileTree("$classes").include("**/*.jar").include("*.jar").files into "$jalviewDir/$packageDir" } // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well task syncJars(type: Sync) { from fileTree("$jalviewDir/$libDir").include("**/*.jar").include("*.jar").files into "$jalviewDir/$packageDir" preserve { include jar.archiveName } } task makeDist { // order of "cleanPackageDir", "copyJars", "jar" important! jar.mustRunAfter cleanPackageDir syncJars.mustRunAfter cleanPackageDir dependsOn cleanPackageDir dependsOn syncJars dependsOn jar outputs.dir("$jalviewDir/$packageDir") } task cleanDist { dependsOn cleanPackageDir dependsOn cleanTest dependsOn clean } shadowJar { dependsOn makeDist if (JAVA_VERSION.equals("11")) { from ("$jalviewDir/$j11libDir") { include("*.jar") } } mainClassName = shadowJarMainClass mergeServiceFiles() classifier = "all" minimize() } ext { getdownWebsiteDir = jalviewDir + '/' + getdown_website_dir getdownAppDir = getdownWebsiteDir + '/' + getdown_app_dir getdownJ11libDir = getdownWebsiteDir + '/' + getdown_j11lib_dir getdownResourceDir = getdownWebsiteDir + '/' + getdown_resource_dir getdownLauncher = jalviewDir + '/' + getdown_launcher getdownFilesDir = jalviewDir + '/' + getdown_files_dir } task getdownWebsite() { dependsOn makeDist def getdownWebsiteResourceFilenames = [] def getdownTextString = "" def getdownResourceDir = project.ext.getdownResourceDir def getdownAppDir = project.ext.getdownAppDir def getdownResourceFilenames = [] doFirst { // go through properties looking for getdown_txt_... def props = project.properties.sort { it.key } if (JAVA_VERSION.equals("11")) { props.put("getdown_txt_java_min_version", getdown_alt_java11_min_version) } else { props.put("getdown_txt_java_min_version", getdown_alt_java8_min_version) } props.each{ prop, val -> if (prop.startsWith("getdown_txt_") && val != null) { if (prop.startsWith("getdown_txt_multi_")) { def key = prop.substring(18) val.split(",").each{ v -> def line = key + " = " + v + "\n" getdownTextString += line } } 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 } } } getdownWebsiteResourceFilenames.each{ filename -> getdownTextString += "resource = "+filename+"\n" } getdownResourceFilenames.each{ filename -> copy { from filename into project.ext.getdownResourceDir } } def codeFiles = [] makeDist.outputs.files.each{ f -> if (f.isDirectory()) { def files = fileTree(dir: f, include: ["*"]).getFiles() codeFiles += files } else if (f.exists()) { codeFiles += f } } codeFiles.sort().each{f -> def line = "code = " + getdown_app_dir + '/' + f.getName() + "\n" getdownTextString += line copy { from f.getPath() into project.ext.getdownAppDir } } if (JAVA_VERSION.equals("11")) { def j11libFiles = fileTree(dir: "$jalviewDir/$j11libDir", include: ["*.jar"]).getFiles() j11libFiles.sort().each{f -> def line = "code = " + getdown_j11lib_dir + '/' + f.getName() + "\n" getdownTextString += line copy { from f.getPath() into project.ext.getdownJ11libDir } } } getdownTextString += "code = " + file(getdownLauncher).getName() + "\n" getdownTextString += "class = " + mainClass + "\n" def getdown_txt = file(project.ext.getdownWebsiteDir + "/getdown.txt") getdown_txt.write(getdownTextString) copy { from getdown_txt into project.ext.getdownFilesDir } copy { from getdownLauncher into project.ext.getdownWebsiteDir } copy { from getdownLauncher into project.ext.getdownFilesDir } copy { from jalviewDir + '/' + project.getProperty('getdown_txt_ui.background_image') from jalviewDir + '/' + project.getProperty('getdown_txt_ui.error_background') from jalviewDir + '/' + project.getProperty('getdown_txt_ui.progress_image') from jalviewDir + '/' + project.getProperty('getdown_txt_ui.icon') from jalviewDir + '/' + project.getProperty('getdown_txt_ui.mac_dock_icon') into project.ext.getdownFilesDir + '/' + getdown_resource_dir } } inputs.dir(jalviewDir + '/' + packageDir) outputs.dir(project.ext.getdownWebsiteDir) outputs.dir(project.ext.getdownFilesDir) } task getdownDigest(type: JavaExec) { dependsOn getdownWebsite classpath = files(jalviewDir + '/' + getdown_core) main = "com.threerings.getdown.tools.Digester" args project.ext.getdownWebsiteDir outputs.file(project.ext.getdownWebsiteDir + '/' + "digest2.txt") } task getdown() { dependsOn getdownDigest } clean { delete project.ext.getdownWebsiteDir delete project.ext.getdownFilesDir } install4j { def install4jHomeDir = "/opt/install4j" def hostname = "hostname".execute().text.trim() if (hostname.equals("jv-bamboo")) { install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j" } else if (OperatingSystem.current().isMacOsX()) { install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app' if (! file(install4jHomeDir).exists()) { install4jHomeDir = System.getProperty("user.home")+install4jHomeDir } } else if (OperatingSystem.current().isLinux()) { install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j" } installDir = file(install4jHomeDir) } task installers(type: com.install4j.gradle.Install4jTask) { dependsOn getdown projectFile = "$jalviewDir/$install4jResourceDir/$install4jConf" variables = [majorVersion: version.substring(2, 11), build: 001] destination = "$jalviewDir/$install4jBuildDir" buildSelected = true inputs.dir(project.ext.getdownWebsiteDir) outputs.dir("$jalviewDir/$install4jBuildDir") }