1 /* Convention for properties. Read from gradle.properties, use lower_case_underlines for property names.
2 * For properties set within build.gradle, use camelCaseNoSpace.
4 import org.apache.tools.ant.filters.ReplaceTokens
5 import com.vladsch.flexmark.util.ast.Node
6 import com.vladsch.flexmark.html.HtmlRenderer
7 import com.vladsch.flexmark.parser.Parser
8 import com.vladsch.flexmark.util.data.MutableDataSet
9 import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension
10 import com.vladsch.flexmark.ext.tables.TablesExtension
11 import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension
12 import com.vladsch.flexmark.ext.autolink.AutolinkExtension
13 import com.vladsch.flexmark.ext.anchorlink.AnchorLinkExtension
14 import com.vladsch.flexmark.ext.toc.TocExtension
18 classpath "com.vladsch.flexmark:flexmark-all:0.62.0"
25 id 'com.palantir.git-version' version '0.12.3'
28 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
29 def string(Object o) {
30 return o == null ? "" : o.toString()
33 def overrideProperties(String propsFileName, boolean output = false) {
34 if (propsFileName == null) {
37 def propsFile = file(propsFileName)
38 if (propsFile != null && propsFile.exists()) {
39 println("Using properties from file '${propsFileName}'")
41 def p = new Properties()
42 def localPropsFIS = new FileInputStream(propsFile)
48 if (project.hasProperty(key)) {
49 oldval = project.findProperty(key)
50 project.setProperty(key, val)
52 println("Overriding property '${key}' ('${oldval}') with ${file(propsFile).getName()} value '${val}'")
55 ext.setProperty(key, val)
57 println("Setting ext property '${key}' with ${file(propsFile).getName()}s value '${val}'")
61 } catch (Exception e) {
62 println("Exception reading local.properties")
69 jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
70 jalviewDirRelativePath = jalviewDir
72 propertiesChannelName = "release"
73 channelDir = string("${jalviewDir}/${channel_properties_dir}/${propertiesChannelName}")
74 channelGradleProperties = string("${channelDir}/channel_gradle.properties")
75 overrideProperties(channelGradleProperties, false)
78 // Import releaseProps from the RELEASE file
79 // or a file specified via JALVIEW_RELEASE_FILE if defined
80 // Expect jalview.version and target release branch in jalview.release
81 def releaseProps = new Properties();
82 def releasePropFile = findProperty("JALVIEW_RELEASE_FILE");
83 def defaultReleasePropFile = "${jalviewDirAbsolutePath}/RELEASE";
85 (new File(releasePropFile!=null ? releasePropFile : defaultReleasePropFile)).withInputStream {
88 } catch (Exception fileLoadError) {
89 throw new Error("Couldn't load release properties file "+(releasePropFile==null ? defaultReleasePropFile : "from custom location: releasePropFile"),fileLoadError);
92 // Set JALVIEW_VERSION if it is not already set
93 if (findProperty("JALVIEW_VERSION")==null || "".equals(JALVIEW_VERSION)) {
94 JALVIEW_VERSION = releaseProps.get("jalview.version")
98 bareSourceDir = string(source_dir)
99 sourceDir = string("${jalviewDir}/${bareSourceDir}")
100 resourceDir = string("${jalviewDir}/${resource_dir}")
101 bareTestSourceDir = string(test_source_dir)
102 testDir = string("${jalviewDir}/${bareTestSourceDir}")
104 classesDir = string("${jalviewDir}/${classes_dir}")
106 resourceClassesDir = classesDir
108 testSourceDir = testDir
109 testClassesDir = "${jalviewDir}/${test_output_dir}"
111 buildProperties = string("${classesDir}/${build_properties_file}")
112 getdownSetAppBaseProperty = false // whether to pass the appbase and appdistdir to the application
114 install4jApplicationName = "${jalview_name}"
116 def details = versionDetails()
117 gitHash = details.gitHash
118 gitBranch = details.branchName
120 println("Using a ${CHANNEL} profile.")
122 additional_compiler_args = []
123 // configure classpath/args for j8/j11 compilation
124 if (JAVA_VERSION.equals("1.8")) {
125 JAVA_INTEGER_VERSION = string("8")
128 libDistDir = j8libDir
129 compile_source_compatibility = 1.8
130 compile_target_compatibility = 1.8
131 } else if (JAVA_VERSION.equals("11")) {
132 JAVA_INTEGER_VERSION = string("11")
134 libDistDir = j11libDir
135 compile_source_compatibility = 11
136 compile_target_compatibility = 11
138 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
141 resourceBuildDir = string("${buildDir}/resources")
142 resourcesBuildDir = string("${resourceBuildDir}/resources_build")
143 helpBuildDir = string("${resourceBuildDir}/help_build")
144 docBuildDir = string("${resourceBuildDir}/doc_build")
146 if (buildProperties == null) {
147 buildProperties = string("${resourcesBuildDir}/${build_properties_file}")
149 buildingHTML = string("${jalviewDir}/${doc_dir}/building.html")
150 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
151 helpSourceDir = string("${helpParentDir}/${help_dir}")
152 helpFile = string("${helpBuildDir}/${help_dir}/help.jhm")
162 outputDir = file(classesDir)
167 srcDirs += helpParentDir
170 jar.destinationDir = file("${jalviewDir}/${package_dir}")
172 compileClasspath = files(sourceSets.main.java.outputDir)
173 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
175 runtimeClasspath = compileClasspath
180 srcDirs testSourceDir
181 outputDir = file(testClassesDir)
185 srcDirs = sourceSets.main.resources.srcDirs
188 compileClasspath = files( sourceSets.test.java.outputDir )
189 compileClasspath += sourceSets.main.compileClasspath
190 compileClasspath += fileTree(dir: "${jalviewDir}/${utils_dir}/testnglibs", include: ["**/*.jar"])
192 runtimeClasspath = compileClasspath
199 sourceCompatibility = compile_source_compatibility
200 targetCompatibility = compile_target_compatibility
201 options.compilerArgs = additional_compiler_args
203 print ("Setting target compatibility to "+compile_target_compatibility+"\n")
210 sourceCompatibility = compile_source_compatibility
211 targetCompatibility = compile_target_compatibility
212 options.compilerArgs = additional_compiler_args
213 print ("Setting target compatibility to "+targetCompatibility+"\n")
220 delete sourceSets.main.java.outputDir
227 delete sourceSets.test.java.outputDir
232 // format is a string like date.format("dd MMMM yyyy")
233 def getDate(format) {
234 def date = new Date()
235 return date.format(format)
239 def convertMdToHtml (FileTree mdFiles, File cssFile) {
240 MutableDataSet options = new MutableDataSet()
242 def extensions = new ArrayList<>()
243 extensions.add(AnchorLinkExtension.create())
244 extensions.add(AutolinkExtension.create())
245 extensions.add(StrikethroughExtension.create())
246 extensions.add(TaskListExtension.create())
247 extensions.add(TablesExtension.create())
248 extensions.add(TocExtension.create())
250 options.set(Parser.EXTENSIONS, extensions)
252 // set GFM table parsing options
253 options.set(TablesExtension.WITH_CAPTION, false)
254 options.set(TablesExtension.COLUMN_SPANS, false)
255 options.set(TablesExtension.MIN_HEADER_ROWS, 1)
256 options.set(TablesExtension.MAX_HEADER_ROWS, 1)
257 options.set(TablesExtension.APPEND_MISSING_COLUMNS, true)
258 options.set(TablesExtension.DISCARD_EXTRA_COLUMNS, true)
259 options.set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true)
261 options.set(AnchorLinkExtension.ANCHORLINKS_SET_ID, false)
262 options.set(AnchorLinkExtension.ANCHORLINKS_ANCHOR_CLASS, "anchor")
263 options.set(AnchorLinkExtension.ANCHORLINKS_SET_NAME, true)
264 options.set(AnchorLinkExtension.ANCHORLINKS_TEXT_PREFIX, "<span class=\"octicon octicon-link\"></span>")
266 Parser parser = Parser.builder(options).build()
267 HtmlRenderer renderer = HtmlRenderer.builder(options).build()
269 mdFiles.each { mdFile ->
270 // add table of contents
271 def mdText = "[TOC]\n"+mdFile.text
273 // grab the first top-level title
275 def titleRegex = /(?m)^#(\s+|([^#]))(.*)/
276 def matcher = mdText =~ titleRegex
277 if (matcher.size() > 0) {
278 // matcher[0][2] is the first character of the title if there wasn't any whitespace after the #
279 title = (matcher[0][2] != null ? matcher[0][2] : "")+matcher[0][3]
281 // or use the filename if none found
283 title = mdFile.getName()
286 Node document = parser.parse(mdText)
287 String htmlBody = renderer.render(document)
288 def htmlText = '''<html>
289 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
290 <html xmlns="http://www.w3.org/1999/xhtml">
292 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
293 <meta http-equiv="Content-Style-Type" content="text/css" />
294 <meta name="generator" content="flexmark" />
296 htmlText += ((title != null) ? " <title>${title}</title>" : '' )
298 <style type="text/css">code{white-space: pre;}</style>
300 htmlText += ((cssFile != null) ? cssFile.text : '')
301 htmlText += '''</head>
310 def htmlFilePath = mdFile.getPath().replaceAll(/\..*?$/, ".html")
311 def htmlFile = file(htmlFilePath)
312 println("Creating ${htmlFilePath}")
313 htmlFile.text = htmlText
318 task copyDocs(type: Copy) {
319 def inputDir = "${jalviewDir}/${doc_dir}"
320 def outputDir = "${docBuildDir}/${doc_dir}"
326 filter(ReplaceTokens,
330 'Version-Rel': JALVIEW_VERSION,
331 'Year-Rel': getDate("yyyy")
344 outputs.dir(outputDir)
348 task convertMdFiles {
350 def mdFiles = fileTree(dir: docBuildDir, include: "**/*.md")
351 def cssFile = file("${jalviewDir}/${flexmark_css}")
354 convertMdToHtml(mdFiles, cssFile)
357 inputs.files(mdFiles)
361 mdFiles.each { mdFile ->
362 def htmlFilePath = mdFile.getPath().replaceAll(/\..*?$/, ".html")
363 htmlFiles.add(file(htmlFilePath))
365 outputs.files(htmlFiles)
369 task copyHelp(type: Copy) {
370 def inputDir = helpSourceDir
371 def outputDir = "${helpBuildDir}/${help_dir}"
379 filter(ReplaceTokens,
383 'Version-Rel': JALVIEW_VERSION,
384 'Year-Rel': getDate("yyyy")
399 outputs.files(helpFile)
400 outputs.dir(outputDir)
404 task copyResources(type: Copy) {
406 description = "Copy (and make text substitutions in) the resources dir to the build area"
408 def inputDir = resourceDir
409 def outputDir = resourcesBuildDir
415 filter(ReplaceTokens,
419 'Version-Rel': JALVIEW_VERSION,
420 'Year-Rel': getDate("yyyy")
433 outputs.dir(outputDir)
436 task copyChannelResources(type: Copy) {
437 dependsOn copyResources
439 description = "Copy the channel resources dir to the build resources area"
441 def inputDir = "${channelDir}/${resource_dir}"
442 def outputDir = resourcesBuildDir
447 outputs.dir(outputDir)
450 task createBuildProperties(type: WriteProperties) {
451 dependsOn copyResources
453 description = "Create the ${buildProperties} file"
455 inputs.dir(sourceDir)
456 inputs.dir(resourcesBuildDir)
457 outputFile (buildProperties)
458 // taking time specific comment out to allow better incremental builds
459 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
460 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
461 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
462 property "VERSION", JALVIEW_VERSION
463 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
464 if (getdownSetAppBaseProperty) {
465 property "GETDOWNAPPBASE", getdownAppBase
466 property "GETDOWNAPPDISTDIR", getdownAppDistDir
468 outputs.file(outputFile)
472 task buildIndices(type: JavaExec) {
474 classpath = sourceSets.main.compileClasspath
475 main = "com.sun.java.help.search.Indexer"
476 workingDir = "${helpBuildDir}/${help_dir}"
479 inputs.dir("${workingDir}/${argDir}")
481 outputs.dir("${classesDir}/doc")
482 outputs.dir("${classesDir}/help")
483 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
484 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
485 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
486 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
487 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
488 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
491 task buildResources {
492 dependsOn copyResources
493 dependsOn copyChannelResources
494 dependsOn createBuildProperties
498 dependsOn buildResources
501 dependsOn convertMdFiles
502 dependsOn buildIndices
506 compileJava.dependsOn prepare
507 run.dependsOn compileJava
508 //run.dependsOn prepare
511 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
514 dependsOn compileJava //?
517 includeGroups testng_groups
518 excludeGroups testng_excluded_groups
520 useDefaultListeners=true
523 maxHeapSize = "1024m"
525 workingDir = jalviewDir
526 //systemProperties 'clover.jar' System.properties.clover.jar
527 def testLaf = project.findProperty("test_laf")
528 if (testLaf != null) {
529 println("Setting Test LaF to '${testLaf}'")
530 systemProperty "laf", testLaf
532 def testHiDPIScale = project.findProperty("test_HiDPIScale")
533 if (testHiDPIScale != null) {
534 println("Setting Test HiDPI Scale to '${testHiDPIScale}'")
535 systemProperty "sun.java2d.uiScale", testHiDPIScale
537 sourceCompatibility = compile_source_compatibility
538 targetCompatibility = compile_target_compatibility
539 jvmArgs += additional_compiler_args
546 task compileLinkCheck(type: JavaCompile) {
548 classpath = files("${jalviewDir}/${utils_dir}")
549 destinationDir = file("${jalviewDir}/${utils_dir}")
550 source = fileTree(dir: "${jalviewDir}/${utils_dir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
552 inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
553 inputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.java")
554 outputs.file("${jalviewDir}/${utils_dir}/HelpLinksChecker.class")
555 outputs.file("${jalviewDir}/${utils_dir}/BufferedLineReader.class")
559 task linkCheck(type: JavaExec) {
561 dependsOn compileLinkCheck
563 def helpLinksCheckerOutFile = file("${jalviewDir}/${utils_dir}/HelpLinksChecker.out")
564 classpath = files("${jalviewDir}/${utils_dir}")
565 main = "HelpLinksChecker"
566 workingDir = jalviewDir
567 args = [ "${helpBuildDir}/${help_dir}", "-nointernet" ]
569 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
570 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
573 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
577 inputs.dir(helpBuildDir)
578 outputs.file(helpLinksCheckerOutFile)
582 // import the pubhtmlhelp target
583 ant.properties.basedir = "${jalviewDir}"
584 ant.properties.helpBuildDir = "${helpBuildDir}/${help_dir}"
585 ant.importBuild "${utils_dir}/publishHelp.xml"
588 task cleanPackageDir(type: Delete) {
590 delete fileTree(dir: "${jalviewDir}/${package_dir}", include: "*.jar")
600 attributes "Main-Class": main_class,
601 "Permissions": "all-permissions",
602 "Application-Name": install4jApplicationName,
603 "Codebase": application_codebase,
604 "Implementation-Version": JALVIEW_VERSION
607 def outputDir = "${jalviewDir}/${package_dir}"
608 destinationDirectory = file(outputDir)
609 archiveFileName = rootProject.name+".jar"
617 inputs.dir(sourceSets.main.java.outputDir)
618 outputs.file("${outputDir}/${archiveFileName}")