+compileJava {
+ // JBP->BS should the print statement in doFirst refer to compile_target_compatibility ?
+ sourceCompatibility = compile_source_compatibility
+ targetCompatibility = compile_target_compatibility
+ options.compilerArgs = additional_compiler_args
+ options.encoding = "UTF-8"
+ doFirst {
+ print ("Setting target compatibility to "+compile_target_compatibility+"\n")
+ }
+
+}
+
+
+compileTestJava {
+ sourceCompatibility = compile_source_compatibility
+ targetCompatibility = compile_target_compatibility
+ options.compilerArgs = additional_compiler_args
+ doFirst {
+ print ("Setting target compatibility to "+targetCompatibility+"\n")
+ }
+}
+
+
+clean {
+ doFirst {
+ delete sourceSets.main.java.outputDir
+ }
+}
+
+
+cleanTest {
+ dependsOn cleanClover
+ doFirst {
+ delete sourceSets.test.java.outputDir
+ }
+}
+
+
+// format is a string like date.format("dd MMMM yyyy")
+def getDate(format) {
+ def date = new Date()
+ return date.format(format)
+}
+
+
+def convertMdToHtml (FileTree mdFiles, File cssFile) {
+ MutableDataSet options = new MutableDataSet()
+
+ def extensions = new ArrayList<>()
+ extensions.add(AnchorLinkExtension.create())
+ extensions.add(AutolinkExtension.create())
+ extensions.add(StrikethroughExtension.create())
+ extensions.add(TaskListExtension.create())
+ extensions.add(TablesExtension.create())
+ extensions.add(TocExtension.create())
+
+ options.set(Parser.EXTENSIONS, extensions)
+
+ // set GFM table parsing options
+ options.set(TablesExtension.WITH_CAPTION, false)
+ options.set(TablesExtension.COLUMN_SPANS, false)
+ options.set(TablesExtension.MIN_HEADER_ROWS, 1)
+ options.set(TablesExtension.MAX_HEADER_ROWS, 1)
+ options.set(TablesExtension.APPEND_MISSING_COLUMNS, true)
+ options.set(TablesExtension.DISCARD_EXTRA_COLUMNS, true)
+ options.set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true)
+ // GFM anchor links
+ options.set(AnchorLinkExtension.ANCHORLINKS_SET_ID, false)
+ options.set(AnchorLinkExtension.ANCHORLINKS_ANCHOR_CLASS, "anchor")
+ options.set(AnchorLinkExtension.ANCHORLINKS_SET_NAME, true)
+ options.set(AnchorLinkExtension.ANCHORLINKS_TEXT_PREFIX, "<span class=\"octicon octicon-link\"></span>")
+
+ Parser parser = Parser.builder(options).build()
+ HtmlRenderer renderer = HtmlRenderer.builder(options).build()
+
+ mdFiles.each { mdFile ->
+ // add table of contents
+ def mdText = "[TOC]\n"+mdFile.text
+
+ // grab the first top-level title
+ def title = null
+ def titleRegex = /(?m)^#(\s+|([^#]))(.*)/
+ def matcher = mdText =~ titleRegex
+ if (matcher.size() > 0) {
+ // matcher[0][2] is the first character of the title if there wasn't any whitespace after the #
+ title = (matcher[0][2] != null ? matcher[0][2] : "")+matcher[0][3]
+ }
+ // or use the filename if none found
+ if (title == null) {
+ title = mdFile.getName()
+ }
+
+ Node document = parser.parse(mdText)
+ String htmlBody = renderer.render(document)
+ def htmlText = '''<html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+ <meta http-equiv="Content-Style-Type" content="text/css" />
+ <meta name="generator" content="flexmark" />
+'''
+ htmlText += ((title != null) ? " <title>${title}</title>" : '' )
+ htmlText += '''
+ <style type="text/css">code{white-space: pre;}</style>
+'''
+ htmlText += ((cssFile != null) ? cssFile.text : '')
+ htmlText += '''</head>
+ <body>
+'''
+ htmlText += htmlBody
+ htmlText += '''
+ </body>
+</html>
+'''
+
+ def htmlFilePath = mdFile.getPath().replaceAll(/\..*?$/, ".html")
+ def htmlFile = file(htmlFilePath)
+ println("Creating ${htmlFilePath}")
+ htmlFile.text = htmlText
+ }
+}
+
+
+task copyDocs(type: Copy) {
+ def inputDir = "${jalviewDir}/${doc_dir}"
+ def outputDir = "${docBuildDir}/${doc_dir}"
+ from(inputDir) {
+ include('**/*.txt')
+ include('**/*.md')
+ include('**/*.html')
+ include('**/*.xml')
+ filter(ReplaceTokens,
+ beginToken: '$$',
+ endToken: '$$',
+ tokens: [
+ 'Version-Rel': JALVIEW_VERSION,
+ 'Year-Rel': getDate("yyyy")
+ ]
+ )
+ }
+ from(inputDir) {
+ exclude('**/*.txt')
+ exclude('**/*.md')
+ exclude('**/*.html')
+ exclude('**/*.xml')
+ }
+ into outputDir
+
+ inputs.dir(inputDir)
+ outputs.dir(outputDir)
+}
+
+
+task convertMdFiles {
+ dependsOn copyDocs
+ def mdFiles = fileTree(dir: docBuildDir, include: "**/*.md")
+ def cssFile = file("${jalviewDir}/${flexmark_css}")
+
+ doLast {
+ convertMdToHtml(mdFiles, cssFile)
+ }
+
+ inputs.files(mdFiles)
+ inputs.file(cssFile)
+
+ def htmlFiles = []
+ mdFiles.each { mdFile ->
+ def htmlFilePath = mdFile.getPath().replaceAll(/\..*?$/, ".html")
+ htmlFiles.add(file(htmlFilePath))
+ }
+ outputs.files(htmlFiles)
+}
+
+
+task copyHelp(type: Copy) {
+ def inputDir = helpSourceDir
+ def outputDir = "${helpBuildDir}/${help_dir}"
+ from(inputDir) {
+ include('**/*.txt')
+ include('**/*.md')
+ include('**/*.html')
+ include('**/*.hs')
+ include('**/*.xml')
+ include('**/*.jhm')
+ filter(ReplaceTokens,
+ beginToken: '$$',
+ endToken: '$$',
+ tokens: [
+ 'Version-Rel': JALVIEW_VERSION,
+ 'Year-Rel': getDate("yyyy")
+ ]
+ )
+ }
+ from(inputDir) {
+ exclude('**/*.txt')
+ exclude('**/*.md')
+ exclude('**/*.html')
+ exclude('**/*.hs')
+ exclude('**/*.xml')
+ exclude('**/*.jhm')
+ }
+ into outputDir
+
+ inputs.dir(inputDir)
+ outputs.files(helpFile)
+ outputs.dir(outputDir)
+}
+
+
+task copyResources(type: Copy) {
+ group = "build"
+ description = "Copy (and make text substitutions in) the resources dir to the build area"
+
+ def inputDir = resourceDir
+ def outputDir = resourcesBuildDir
+ from(inputDir) {
+ include('**/*.txt')
+ include('**/*.md')
+ include('**/*.html')
+ include('**/*.xml')
+ filter(ReplaceTokens,
+ beginToken: '$$',
+ endToken: '$$',
+ tokens: [
+ 'Version-Rel': JALVIEW_VERSION,
+ 'Year-Rel': getDate("yyyy")
+ ]
+ )
+ }
+ from(inputDir) {
+ exclude('**/*.txt')
+ exclude('**/*.md')
+ exclude('**/*.html')
+ exclude('**/*.xml')
+ }
+ into outputDir
+
+ inputs.dir(inputDir)
+ outputs.dir(outputDir)
+}
+
+task copyChannelResources(type: Copy) {
+ dependsOn copyResources
+ group = "build"
+ description = "Copy the channel resources dir to the build resources area"
+
+ def inputDir = "${channelDir}/${resource_dir}"
+ def outputDir = resourcesBuildDir
+ from inputDir
+ into outputDir
+
+ inputs.dir(inputDir)
+ outputs.dir(outputDir)
+}
+
+task createBuildProperties(type: WriteProperties) {
+ dependsOn copyResources
+ group = "build"
+ description = "Create the ${buildProperties} file"
+
+ inputs.dir(sourceDir)
+ inputs.dir(resourcesBuildDir)
+ outputFile (buildProperties)
+ // taking time 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("HH:mm:ss dd MMMM yyyy")
+ property "VERSION", JALVIEW_VERSION
+ property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
+ if (getdownSetAppBaseProperty) {
+ property "GETDOWNAPPBASE", getdownAppBase
+ property "GETDOWNAPPDISTDIR", getdownAppDistDir
+ }
+ outputs.file(outputFile)
+}
+
+
+task buildIndices(type: JavaExec) {
+ dependsOn copyHelp
+ classpath = sourceSets.main.compileClasspath
+ main = "com.sun.java.help.search.Indexer"
+ workingDir = "${helpBuildDir}/${help_dir}"
+ def argDir = "html"
+ args = [ argDir ]
+ inputs.dir("${workingDir}/${argDir}")
+
+ outputs.dir("${classesDir}/doc")
+ outputs.dir("${classesDir}/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 buildResources {
+ dependsOn copyResources
+ dependsOn copyChannelResources
+ dependsOn createBuildProperties
+}
+
+task prepare {
+ dependsOn buildResources
+ dependsOn copyDocs
+ dependsOn copyHelp
+ dependsOn convertMdFiles
+ dependsOn buildIndices
+}
+
+
+compileJava.dependsOn prepare
+run.dependsOn compileJava
+//run.dependsOn prepare
+
+
+//testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
+test {
+ dependsOn prepare
+
+ if (useClover) {
+ dependsOn cloverClasses
+ } else { //?
+ dependsOn compileJava //?
+ }
+
+ useTestNG() {
+ includeGroups testng_groups
+ excludeGroups testng_excluded_groups
+ preserveOrder true
+ useDefaultListeners=true
+ }
+
+ maxHeapSize = "1024m"
+
+ workingDir = jalviewDir
+ def testLaf = project.findProperty("test_laf")
+ if (testLaf != null) {
+ println("Setting Test LaF to '${testLaf}'")
+ systemProperty "laf", testLaf
+ }
+ def testHiDPIScale = project.findProperty("test_HiDPIScale")
+ if (testHiDPIScale != null) {
+ println("Setting Test HiDPI Scale to '${testHiDPIScale}'")
+ systemProperty "sun.java2d.uiScale", testHiDPIScale
+ }
+ sourceCompatibility = compile_source_compatibility
+ targetCompatibility = compile_target_compatibility
+ jvmArgs += additional_compiler_args
+
+ doFirst {
+ if (useClover) {
+ println("Running tests " + (useClover?"WITH":"WITHOUT") + " clover")
+ }
+ }
+}
+
+
+task compileLinkCheck(type: JavaCompile) {
+ options.fork = true
+ 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
+ dependsOn compileLinkCheck
+
+ def helpLinksCheckerOutFile = file("${jalviewDir}/${utils_dir}/HelpLinksChecker.out")
+ classpath = files("${jalviewDir}/${utils_dir}")
+ main = "HelpLinksChecker"
+ workingDir = jalviewDir
+ args = [ "${helpBuildDir}/${help_dir}", "-nointernet" ]
+
+ def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
+ standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
+ outFOS,
+ System.out)
+ errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
+ outFOS,
+ System.err)
+
+ inputs.dir(helpBuildDir)
+ outputs.file(helpLinksCheckerOutFile)
+}
+
+
+// import the pubhtmlhelp target
+ant.properties.basedir = "${jalviewDir}"
+ant.properties.helpBuildDir = "${helpBuildDir}/${help_dir}"
+ant.importBuild "${utils_dir}/publishHelp.xml"
+
+
+task cleanPackageDir(type: Delete) {
+ doFirst {
+ delete fileTree(dir: "${jalviewDir}/${package_dir}", include: "*.jar")
+ }
+}
+
+
+jar {
+ dependsOn prepare
+ dependsOn linkCheck
+
+ manifest {
+ attributes "Main-Class": main_class,
+ "Permissions": "all-permissions",
+ "Application-Name": install4jApplicationName,
+ "Codebase": application_codebase,
+ "Implementation-Version": JALVIEW_VERSION
+ }
+
+ def outputDir = "${jalviewDir}/${package_dir}"
+ destinationDirectory = file(outputDir)
+ archiveFileName = rootProject.name+".jar"
+ duplicatesStrategy "EXCLUDE"