1 import org.apache.tools.ant.filters.ReplaceTokens
2 import org.gradle.internal.os.OperatingSystem
3 import org.gradle.plugins.ide.eclipse.model.Output
4 import org.gradle.plugins.ide.eclipse.model.Library
5 import java.security.MessageDigest
6 import groovy.transform.ExternalizeMethods
7 import groovy.util.XmlParser
8 import groovy.xml.XmlUtil
17 classpath 'org.openclover:clover:4.4.1'
26 id 'com.github.johnrengelman.shadow' version '4.0.3'
27 id 'com.install4j.gradle' version '8.0.4'
28 id 'com.dorongold.task-tree' version '1.5' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree
38 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
39 def string(Object o) {
40 return o == null ? "" : o.toString()
45 jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
46 jalviewDirRelativePath = jalviewDir
48 // local build environment properties
49 def localProps = "${jalviewDirAbsolutePath}/local.properties"
50 if (file(localProps).exists()) {
52 def p = new Properties()
53 def localPropsFIS = new FileInputStream(localProps)
58 def oldval = findProperty(key)
61 println("Overriding property '${key}' ('${oldval}') with local.properties value '${val}'")
63 println("Setting unknown property '${key}' with local.properties value '${val}'")
66 } catch (Exception e) {
67 System.out.println("Exception reading local.properties")
71 // this property set when running Eclipse headlessly
72 j2sHeadlessBuildProperty = string("net.sf.j2s.core.headlessbuild")
73 // this property set by Eclipse
74 eclipseApplicationProperty = string("eclipse.application")
75 // CHECK IF RUNNING FROM WITHIN ECLIPSE
76 def eclipseApplicationPropertyVal = System.properties[eclipseApplicationProperty]
77 IN_ECLIPSE = eclipseApplicationPropertyVal != null && eclipseApplicationPropertyVal.startsWith("org.eclipse.ui.")
78 // BUT WITHOUT THE HEADLESS BUILD PROPERTY SET
79 if (System.properties[j2sHeadlessBuildProperty].equals("true")) {
80 println("Setting IN_ECLIPSE to ${IN_ECLIPSE} as System.properties['${j2sHeadlessBuildProperty}'] == '${System.properties[j2sHeadlessBuildProperty]}'")
84 println("WITHIN ECLIPSE IDE")
86 println("HEADLESS BUILD")
89 System.properties.sort { it.key }.each {
90 key, val -> println("SYSTEM PROPERTY ${key}='${val}'")
93 if (false && IN_ECLIPSE) {
94 jalviewDir = jalviewDirAbsolutePath
99 bareSourceDir = string(source_dir)
100 sourceDir = string("${jalviewDir}/${bareSourceDir}")
101 resourceDir = string("${jalviewDir}/${resource_dir}")
102 bareTestSourceDir = string(test_source_dir)
103 testSourceDir = string("${jalviewDir}/${bareTestSourceDir}")
106 cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
107 cloverDb = string("${buildDir}/clover/clover.db")
108 classesDir = string("${jalviewDir}/${classes_dir}")
109 if (clover.equals("true")) {
111 classesDir = string("${buildDir}/${cloverClassesDir}")
114 classesDir = string("${jalviewDir}/${classes_dir}")
119 getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
122 // the following values might be overridden by the CHANNEL switch
123 getdownChannelName = CHANNEL.toLowerCase()
124 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
125 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
126 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
127 getdownAppDistDir = getdown_app_dir_alt
128 buildProperties = string("${classesDir}/${build_properties_file}")
129 reportRsyncCmd = false
130 jvlChannelName = CHANNEL.toLowerCase()
134 // TODO: get bamboo build artifact URL for getdown artifacts
135 getdown_channel_base = bamboo_channelbase
136 getdownChannelName = string("${bamboo_planKey}/${JAVA_VERSION}")
137 getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
138 jvlChannelName += "_${getdownChannelName}"
142 getdownAppDistDir = getdown_app_dir_release
143 reportRsyncCommand = true
147 getdownChannelName = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
148 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
149 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
150 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
151 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
153 packageDir = string("${ARCHIVEDIR}/${packageDir}")
154 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
157 reportRsyncCommand = true
161 getdownChannelName = string("archive/${JALVIEW_VERSION}")
162 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
163 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
164 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
165 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
167 packageDir = string("${ARCHIVEDIR}/${packageDir}")
168 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
171 reportRsyncCommand = true
172 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
176 reportRsyncCommand = true
180 reportRsyncCommand = true
183 case ~/^SCRATCH(|-[-\w]*)$/:
184 getdownChannelName = CHANNEL
185 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
186 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
187 reportRsyncCommand = true
191 if (!file("${LOCALDIR}").exists()) {
192 throw new GradleException("Must provide a LOCALDIR value to produce a local distribution")
194 getdownAppBase = file(file("${LOCALDIR}").getAbsolutePath()).toURI().toString()
195 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
200 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
201 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
204 default: // something wrong specified
205 throw new GradleException("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
209 // override getdownAppBase if requested
210 if (findProperty("getdown_appbase_override") != null) {
211 getdownAppBase = string(getProperty("getdown_appbase_override"))
212 println("Overriding getdown appbase with '${getdownAppBase}'")
214 // sanitise file name for jalview launcher file for this channel
215 jvlChannelName = jvlChannelName.replaceAll(/[^\w\-]/,"_")
217 getdownAppDir = string("${getdownWebsiteDir}/${getdownAppDistDir}")
218 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
219 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
220 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
221 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
222 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
223 /* compile without modules -- using classpath libraries
224 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
225 modules_runtimeClasspath = modules_compileClasspath
228 gitBranch = string("")
230 println("Using a ${CHANNEL} profile.")
232 additional_compiler_args = []
233 // configure classpath/args for j8/j11 compilation
234 if (JAVA_VERSION.equals("1.8")) {
235 JAVA_INTEGER_VERSION = string("8")
238 libDistDir = j8libDir
239 compile_source_compatibility = 1.8
240 compile_target_compatibility = 1.8
241 // these are getdown.txt properties defined dependent on the JAVA_VERSION
242 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java8_min_version"))
243 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java8_max_version"))
244 // this property is assigned below and expanded to multiple lines in the getdown task
245 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java8_txt_multi_java_location"))
246 // this property is for the Java library used in eclipse
247 eclipseJavaRuntimeName = string("JavaSE-1.8")
248 } else if (JAVA_VERSION.equals("11")) {
249 JAVA_INTEGER_VERSION = string("11")
251 libDistDir = j11libDir
252 compile_source_compatibility = 11
253 compile_target_compatibility = 11
254 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
255 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
256 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
257 eclipseJavaRuntimeName = string("JavaSE-11")
258 /* compile without modules -- using classpath libraries
259 additional_compiler_args += [
260 '--module-path', modules_compileClasspath.asPath,
261 '--add-modules', j11modules
264 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
265 JAVA_INTEGER_VERSION = JAVA_VERSION
267 libDistDir = j11libDir
268 compile_source_compatibility = JAVA_VERSION
269 compile_target_compatibility = JAVA_VERSION
270 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
271 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
272 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
273 eclipseJavaRuntimeName = string("JavaSE-11")
274 /* compile without modules -- using classpath libraries
275 additional_compiler_args += [
276 '--module-path', modules_compileClasspath.asPath,
277 '--add-modules', j11modules
281 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
286 JAVA_MIN_VERSION = JAVA_VERSION
287 JAVA_MAX_VERSION = JAVA_VERSION
288 def jreInstallsDir = string(jre_installs_dir)
289 if (jreInstallsDir.startsWith("~/")) {
290 jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
292 macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
293 macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-mac-x64.tar.gz")
294 windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
295 windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-windows-x64.tar.gz")
296 linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
297 linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-linux-x64.tar.gz")
298 install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
299 install4jConfFileName = string("jalview-install4j-conf.install4j")
300 install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
301 install4jHomeDir = install4j_home_dir
302 if (install4jHomeDir.startsWith("~/")) {
303 install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
308 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
309 helpFile = string("${classesDir}/${help_dir}/help.jhm")
310 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
311 helpSourceDir = string("${helpParentDir}/${help_dir}")
314 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
315 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
316 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
318 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
320 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
322 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
323 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
324 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
325 jalviewjsJalviewCoreHtmlFile = string("")
326 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
327 jalviewjsCoreClasslists = []
328 jalviewjsJalviewTemplateName = string(jalviewjs_name)
329 jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
330 jalviewjsJ2sProps = null
332 eclipseWorkspace = null
333 eclipseBinary = string("")
334 eclipseVersion = string("")
344 outputDir = file(classesDir)
349 srcDirs += helpParentDir
352 jar.destinationDir = file("${jalviewDir}/${packageDir}")
354 compileClasspath = files(sourceSets.main.java.outputDir)
355 //compileClasspath += files(sourceSets.main.resources.srcDirs)
356 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
358 runtimeClasspath = compileClasspath
363 srcDirs = [ cloverInstrDir ]
364 outputDir = file("${buildDir}/${cloverClassesDir}")
368 srcDirs = sourceSets.main.resources.srcDirs
370 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
371 compileClasspath += files(sourceSets.main.java.outputDir)
372 compileClasspath += sourceSets.main.compileClasspath
373 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
374 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
376 runtimeClasspath = compileClasspath
381 srcDirs testSourceDir
382 outputDir = file("${jalviewDir}/${testOutputDir}")
386 srcDirs = sourceSets.main.resources.srcDirs
389 compileClasspath = files( sourceSets.test.java.outputDir )
392 compileClasspath = sourceSets.clover.compileClasspath
394 compileClasspath += files(sourceSets.main.java.outputDir)
397 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
398 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
399 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
401 runtimeClasspath = compileClasspath
408 cloverCompile 'org.openclover:clover:4.4.1'
410 testCompile 'org.openclover:clover:4.4.1'
416 cloverRuntime.extendsFrom cloverCompile
420 // eclipse project and settings files creation, also used by buildship
423 name = eclipse_project_name
425 natures 'org.eclipse.jdt.core.javanature',
426 'org.eclipse.jdt.groovy.core.groovyNature',
427 'org.eclipse.buildship.core.gradleprojectnature'
429 buildCommand 'org.eclipse.jdt.core.javabuilder'
430 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
434 //defaultOutputDir = sourceSets.main.java.outputDir
437 if (it.isCanBeResolved()) {
442 minusConfigurations += removeThese
443 plusConfigurations = [ ]
447 def removeTheseToo = []
448 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
449 cp.entries.each { entry ->
450 // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
451 // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
452 // we add the resources and help/help dirs in as libs afterwards (see below)
453 if (entry.kind == 'src') {
454 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
455 removeTheseToo += entry
457 alreadyAddedSrcPath.putAt(entry.path, true)
462 cp.entries.removeAll(removeTheseToo)
464 //cp.entries += new Output("${eclipse_bin_dir}/main")
465 if (file(helpParentDir).isDirectory()) {
466 cp.entries += new Library(fileReference(helpParentDir))
468 if (file(resourceDir).isDirectory()) {
469 cp.entries += new Library(fileReference(resourceDir))
472 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
474 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
475 //don't want to add outputDir as eclipse is using its own output dir in bin/main
476 if (it.isDirectory() || ! it.exists()) {
477 // don't add dirs to classpath, especially if they don't exist
478 return false // groovy "continue" in .any closure
480 def itPath = it.toString()
481 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
482 // make relative path
483 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
485 if (alreadyAddedLibPath.get(itPath)) {
486 //println("Not adding duplicate entry "+itPath)
488 //println("Adding entry "+itPath)
489 cp.entries += new Library(fileReference(itPath))
490 alreadyAddedLibPath.put(itPath, true)
494 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
495 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
496 if (it.isDirectory() || ! it.exists()) {
497 // don't add dirs to classpath
498 return false // groovy "continue" in .any closure
501 def itPath = it.toString()
502 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
503 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
505 if (alreadyAddedLibPath.get(itPath)) {
508 def lib = new Library(fileReference(itPath))
509 lib.entryAttributes["test"] = "true"
511 alreadyAddedLibPath.put(itPath, true)
519 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
524 // for the IDE, use java 11 compatibility
525 sourceCompatibility = compile_source_compatibility
526 targetCompatibility = compile_target_compatibility
527 javaRuntimeName = eclipseJavaRuntimeName
529 // add in jalview project specific properties/preferences into eclipse core preferences
531 withProperties { props ->
532 def jalview_prefs = new Properties()
533 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
534 jalview_prefs.load(ins)
536 jalview_prefs.forEach { t, v ->
537 if (props.getAt(t) == null) {
547 // Don't want these to be activated if in headless build
548 synchronizationTasks "eclipseSynchronizationTask"
549 autoBuildTasks "eclipseAutoBuildTask"
556 // only instrument source, we build test classes as normal
557 inputs.files files (sourceSets.main.allJava,sourceSets.test.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
558 outputs.dir cloverInstrDir
561 //delete cloverInstrDir
566 cloverInstrDir.getPath(),
569 inputs.files.files.collect(
570 { file -> file.absolutePath }
573 String[] args = argsList.toArray()
574 println("About to instrument "+args.length +" files")
575 com.atlassian.clover.CloverInstr.mainImpl(args)
580 cloverClasses.dependsOn cloverInstr
584 group = "Verification"
585 description = "Creates the Clover report"
586 inputs.dir "${buildDir}/clover"
587 outputs.dir "${reportsDir}/clover"
589 file(cloverDb).exists()
596 "${reportsDir}/clover"
598 String[] args = argsList.toArray()
599 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
601 // and generate ${reportsDir}/clover/clover.xml
606 "${reportsDir}/clover/clover.xml"
608 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
617 sourceCompatibility = compile_source_compatibility
618 targetCompatibility = compile_target_compatibility
619 options.compilerArgs = additional_compiler_args
620 print ("Setting target compatibility to "+targetCompatibility+"\n")
628 dependsOn compileCloverJava
629 classpath += configurations.cloverRuntime
631 classpath += sourceSets.main.runtimeClasspath
634 sourceCompatibility = compile_source_compatibility
635 targetCompatibility = compile_target_compatibility
636 options.compilerArgs = additional_compiler_args
637 print ("Setting target compatibility to "+targetCompatibility+"\n")
645 sourceCompatibility = compile_source_compatibility
646 targetCompatibility = compile_target_compatibility
647 options.compilerArgs += additional_compiler_args
648 print ("Setting target compatibility to "+targetCompatibility+"\n")
650 classpath += configurations.cloverRuntime
656 delete sourceSets.main.java.outputDir
663 delete cloverInstrDir
670 dependsOn cleanClover
672 delete sourceSets.test.java.outputDir
677 // format is a string like date.format("dd MMMM yyyy")
678 def getDate(format) {
679 def date = new Date()
680 return date.format(format)
685 def hashStdOut = new ByteArrayOutputStream()
687 commandLine "git", "rev-parse", "--short", "HEAD"
688 standardOutput = hashStdOut
692 def branchStdOut = new ByteArrayOutputStream()
694 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
695 standardOutput = branchStdOut
699 gitHash = hashStdOut.toString().trim()
700 gitBranch = branchStdOut.toString().trim()
702 outputs.upToDateWhen { false }
706 task createBuildProperties(type: WriteProperties) {
708 inputs.dir(sourceDir)
709 inputs.dir(resourceDir)
710 file(buildProperties).getParentFile().mkdirs()
711 outputFile (buildProperties)
712 // taking time specific comment out to allow better incremental builds
713 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
714 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
715 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
716 property "VERSION", JALVIEW_VERSION
717 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
718 outputs.file(outputFile)
722 task cleanBuildingHTML(type: Delete) {
729 task convertBuildingMD(type: Exec) {
730 dependsOn cleanBuildingHTML
731 def buildingMD = "${jalviewDir}/${docDir}/building.md"
732 def css = "${jalviewDir}/${docDir}/github.css"
735 pandoc_exec.split(",").each {
736 if (file(it.trim()).exists()) {
742 def hostname = "hostname".execute().text.trim()
743 def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
744 if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
745 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
749 if (pandoc != null && file(pandoc).exists()) {
750 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
752 println("Cannot find pandoc. Skipping convert building.md to HTML")
753 throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
759 inputs.file(buildingMD)
761 outputs.file(buildingHTML)
772 task syncDocs(type: Sync) {
773 dependsOn convertBuildingMD
774 def syncDir = "${classesDir}/${docDir}"
775 from fileTree("${jalviewDir}/${docDir}")
781 task copyHelp(type: Copy) {
782 def inputDir = helpSourceDir
783 def outputDir = "${classesDir}/${help_dir}"
788 filter(ReplaceTokens,
792 'Version-Rel': JALVIEW_VERSION,
793 'Year-Rel': getDate("yyyy")
805 outputs.files(helpFile)
806 outputs.dir(outputDir)
810 task syncLib(type: Sync) {
811 def syncDir = "${classesDir}/${libDistDir}"
812 from fileTree("${jalviewDir}/${libDistDir}")
817 task syncResources(type: Sync) {
828 dependsOn syncResources
834 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
837 dependsOn compileJava
839 dependsOn cloverInstr
843 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
847 includeGroups testngGroups
849 useDefaultListeners=true
852 workingDir = jalviewDir
853 //systemProperties 'clover.jar' System.properties.clover.jar
854 sourceCompatibility = compile_source_compatibility
855 targetCompatibility = compile_target_compatibility
856 jvmArgs += additional_compiler_args
861 task buildIndices(type: JavaExec) {
863 classpath = sourceSets.main.compileClasspath
864 main = "com.sun.java.help.search.Indexer"
865 workingDir = "${classesDir}/${help_dir}"
868 inputs.dir("${workingDir}/${argDir}")
870 outputs.dir("${classesDir}/doc")
871 outputs.dir("${classesDir}/help")
872 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
873 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
874 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
875 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
876 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
877 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
881 task compileLinkCheck(type: JavaCompile) {
883 classpath = files("${jalviewDir}/${utilsDir}")
884 destinationDir = file("${jalviewDir}/${utilsDir}")
885 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
887 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
888 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
889 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
890 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
894 task linkCheck(type: JavaExec) {
895 dependsOn prepare, compileLinkCheck
897 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
898 classpath = files("${jalviewDir}/${utilsDir}")
899 main = "HelpLinksChecker"
900 workingDir = jalviewDir
901 args = [ "${classesDir}/${help_dir}", "-nointernet" ]
903 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
905 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
908 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
912 inputs.dir("${classesDir}/${help_dir}")
913 outputs.file(helpLinksCheckerOutFile)
916 // import the pubhtmlhelp target
917 ant.properties.basedir = "${jalviewDir}"
918 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
919 ant.importBuild "${utilsDir}/publishHelp.xml"
922 task cleanPackageDir(type: Delete) {
924 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
930 dependsOn buildIndices
931 dependsOn createBuildProperties
934 attributes "Main-Class": mainClass,
935 "Permissions": "all-permissions",
936 "Application-Name": "Jalview Desktop",
937 "Codebase": application_codebase
940 destinationDir = file("${jalviewDir}/${packageDir}")
941 archiveName = rootProject.name+".jar"
949 inputs.dir(classesDir)
950 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
954 task copyJars(type: Copy) {
955 from fileTree(dir: classesDir, include: "**/*.jar").files
956 into "${jalviewDir}/${packageDir}"
960 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
961 task syncJars(type: Sync) {
962 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
963 into "${jalviewDir}/${packageDir}"
965 include jar.archiveName
972 description = "Put all required libraries in dist"
973 // order of "cleanPackageDir", "copyJars", "jar" important!
974 jar.mustRunAfter cleanPackageDir
975 syncJars.mustRunAfter cleanPackageDir
976 dependsOn cleanPackageDir
979 outputs.dir("${jalviewDir}/${packageDir}")
984 dependsOn cleanPackageDir
990 group = "distribution"
994 from ("${jalviewDir}/${libDistDir}") {
998 attributes 'Implementation-Version': JALVIEW_VERSION
1000 mainClassName = shadowJarMainClass
1002 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
1007 task getdownWebsite() {
1008 group = "distribution"
1009 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
1014 def getdownWebsiteResourceFilenames = []
1015 def getdownTextString = ""
1016 def getdownResourceDir = getdownResourceDir
1017 def getdownResourceFilenames = []
1020 // clean the getdown website and files dir before creating getdown folders
1021 delete getdownWebsiteDir
1022 delete getdownFilesDir
1025 from buildProperties
1026 rename(build_properties_file, getdown_build_properties)
1029 getdownWebsiteResourceFilenames += "${getdownAppDistDir}/${getdown_build_properties}"
1031 // go through properties looking for getdown_txt_...
1032 def props = project.properties.sort { it.key }
1033 if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
1034 props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
1036 if (getdownAltJavaMaxVersion != null && getdownAltJavaMaxVersion.length() > 0) {
1037 props.put("getdown_txt_java_max_version", getdownAltJavaMaxVersion)
1039 if (getdownAltMultiJavaLocation != null && getdownAltMultiJavaLocation.length() > 0) {
1040 props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
1043 props.put("getdown_txt_appbase", getdownAppBase)
1044 props.each{ prop, val ->
1045 if (prop.startsWith("getdown_txt_") && val != null) {
1046 if (prop.startsWith("getdown_txt_multi_")) {
1047 def key = prop.substring(18)
1048 val.split(",").each{ v ->
1049 def line = "${key} = ${v}\n"
1050 getdownTextString += line
1053 // file values rationalised
1054 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1056 if (val.indexOf('/') == 0) {
1059 } else if (val.indexOf('/') > 0) {
1060 // relative path (relative to jalviewDir)
1061 r = file( "${jalviewDir}/${val}" )
1064 val = "${getdown_resource_dir}/" + r.getName()
1065 getdownWebsiteResourceFilenames += val
1066 getdownResourceFilenames += r.getPath()
1069 if (! prop.startsWith("getdown_txt_resource")) {
1070 def line = prop.substring(12) + " = ${val}\n"
1071 getdownTextString += line
1077 getdownWebsiteResourceFilenames.each{ filename ->
1078 getdownTextString += "resource = ${filename}\n"
1080 getdownResourceFilenames.each{ filename ->
1083 into getdownResourceDir
1088 fileTree(file(packageDir)).each{ f ->
1089 if (f.isDirectory()) {
1090 def files = fileTree(dir: f, include: ["*"]).getFiles()
1092 } else if (f.exists()) {
1096 codeFiles.sort().each{f ->
1097 def name = f.getName()
1098 def line = "code = ${getdownAppDistDir}/${name}\n"
1099 getdownTextString += line
1106 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1108 if (JAVA_VERSION.equals("11")) {
1109 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1110 j11libFiles.sort().each{f ->
1111 def name = f.getName()
1112 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1113 getdownTextString += line
1116 into getdownJ11libDir
1122 // getdown-launcher.jar should not be in main application class path so the main application can move it when updated. Listed as a resource so it gets updated.
1123 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1124 getdownTextString += "resource = ${getdown_launcher_new}\n"
1125 getdownTextString += "class = ${mainClass}\n"
1127 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1128 getdown_txt.write(getdownTextString)
1130 def getdownLaunchJvl = getdown_launch_jvl_name + ( (jvlChannelName != null && jvlChannelName.length() > 0)?"-${jvlChannelName}":"" ) + ".jvl"
1131 def launchJvl = file("${getdownWebsiteDir}/${getdownLaunchJvl}")
1132 launchJvl.write("appbase="+props.get("getdown_txt_appbase"))
1135 from getdownLauncher
1136 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1137 into getdownWebsiteDir
1141 from getdownLauncher
1142 if (file(getdownLauncher).getName() != getdown_launcher) {
1143 rename(file(getdownLauncher).getName(), getdown_launcher)
1145 into getdownWebsiteDir
1148 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1151 from getdownLauncher
1152 from "${getdownWebsiteDir}/${getdown_build_properties}"
1153 if (file(getdownLauncher).getName() != getdown_launcher) {
1154 rename(file(getdownLauncher).getName(), getdown_launcher)
1156 into getdownInstallDir
1160 from getdownInstallDir
1161 into getdownFilesInstallDir
1168 from getdownLauncher
1169 from "${getdownWebsiteDir}/${getdown_build_properties}"
1170 if (file(getdownLauncher).getName() != getdown_launcher) {
1171 rename(file(getdownLauncher).getName(), getdown_launcher)
1173 into getdownFilesDir
1177 from getdownResourceDir
1178 into "${getdownFilesDir}/${getdown_resource_dir}"
1183 inputs.dir("${jalviewDir}/${packageDir}")
1185 outputs.dir(getdownWebsiteDir)
1186 outputs.dir(getdownFilesDir)
1190 // a helper task to allow getdown digest of any dir: `gradle getdownDigestDir -PDIGESTDIR=/path/to/my/random/getdown/dir
1191 task getdownDigestDir(type: JavaExec) {
1192 def digestDirPropertyName = "DIGESTDIR"
1193 description = "Digest a local dir (-P${digestDirPropertyName}=...) for getdown"
1195 classpath = files(getdownLauncher)
1196 def digestDir = findProperty(digestDirPropertyName)
1197 if (digestDir == null) {
1198 throw new GradleException("Must provide a DIGESTDIR value to produce an alternative getdown digest")
1202 main = "com.threerings.getdown.tools.Digester"
1206 task getdownDigest(type: JavaExec) {
1207 group = "distribution"
1208 description = "Digest the getdown website folder"
1209 dependsOn getdownWebsite
1211 classpath = files(getdownLauncher)
1213 main = "com.threerings.getdown.tools.Digester"
1214 args getdownWebsiteDir
1215 inputs.dir(getdownWebsiteDir)
1216 outputs.file("${getdownWebsiteDir}/digest2.txt")
1221 group = "distribution"
1222 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1223 dependsOn getdownDigest
1225 if (reportRsyncCommand) {
1226 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1227 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1228 println "LIKELY RSYNC COMMAND:"
1229 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1230 if (RUNRSYNC == "true") {
1232 commandLine "mkdir", "-p", toDir
1235 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1245 delete getdownWebsiteDir
1246 delete getdownFilesDir
1252 if (file(install4jHomeDir).exists()) {
1254 } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1255 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1256 } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1257 install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1259 installDir(file(install4jHomeDir))
1261 mediaTypes = Arrays.asList(install4j_media_types.split(","))
1265 task copyInstall4jTemplate {
1266 def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
1267 def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1268 inputs.file(install4jTemplateFile)
1269 inputs.file(install4jFileAssociationsFile)
1270 outputs.file(install4jConfFile)
1273 def install4jConfigXml = new XmlParser().parse(install4jTemplateFile)
1275 // turn off code signing if no OSX_KEYPASS
1276 if (OSX_KEYPASS == "") {
1277 install4jConfigXml.'**'.codeSigning.each { codeSigning ->
1278 codeSigning.'@macEnabled' = "false"
1280 install4jConfigXml.'**'.windows.each { windows ->
1281 windows.'@runPostProcessor' = "false"
1285 // turn off checksum creation for LOCAL channel
1286 def e = install4jConfigXml.application[0]
1287 if (CHANNEL == "LOCAL") {
1288 e.'@createChecksums' = "false"
1290 e.'@createChecksums' = "true"
1293 // put file association actions where placeholder action is
1294 def install4jFileAssociationsText = install4jFileAssociationsFile.text
1295 def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
1296 install4jConfigXml.'**'.action.any { a ->
1297 if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1298 def parent = a.parent()
1300 fileAssociationActions.each { faa ->
1303 // don't need to continue in .any loop once replacements have been made
1308 // write install4j file
1309 install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
1316 delete install4jConfFile
1321 task installers(type: com.install4j.gradle.Install4jTask) {
1322 group = "distribution"
1323 description = "Create the install4j installers"
1324 dependsOn setGitVals
1326 dependsOn copyInstall4jTemplate
1328 projectFile = install4jConfFile
1330 // create an md5 for the input files to use as version for install4j conf file
1331 def digest = MessageDigest.getInstance("MD5")
1333 (file("${install4jDir}/${install4j_template}").text +
1334 file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1335 file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1336 def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1337 if (filesMd5.length() >= 8) {
1338 filesMd5 = filesMd5.substring(0,8)
1340 def install4jTemplateVersion = "${JALVIEW_VERSION}_F${filesMd5}_C${gitHash}"
1341 // make install4jBuildDir relative to jalviewDir
1342 def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
1345 'JALVIEW_NAME': getdown_txt_title,
1346 'JALVIEW_DIR': "../..",
1347 'OSX_KEYSTORE': OSX_KEYSTORE,
1348 'JSIGN_SH': JSIGN_SH,
1349 'JRE_DIR': getdown_app_dir_java,
1350 'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1351 'JALVIEW_VERSION': JALVIEW_VERSION,
1352 'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1353 'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1354 'JAVA_VERSION': JAVA_VERSION,
1355 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1356 'VERSION': JALVIEW_VERSION,
1357 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1358 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1359 'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
1360 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1361 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1362 'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
1363 'COPYRIGHT_MESSAGE': install4j_copyright_message,
1364 'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1365 'INSTALLER_NAME': install4j_installer_name,
1366 'INSTALL4J_UTILS_DIR': install4j_utils_dir,
1367 'GETDOWN_WEBSITE_DIR': getdown_website_dir,
1368 'GETDOWN_FILES_DIR': getdown_files_dir,
1369 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1370 'GETDOWN_DIST_DIR': getdownAppDistDir,
1371 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1372 'GETDOWN_INSTALL_DIR': getdown_install_dir,
1373 'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
1374 'BUILD_DIR': install4jBuildDir,
1377 destination = "${jalviewDir}/${install4jBuildDir}"
1378 buildSelected = true
1380 if (install4j_faster.equals("true") || CHANNEL.startsWith("LOCAL")) {
1382 disableSigning = true
1386 macKeystorePassword = OSX_KEYPASS
1390 println("Using projectFile "+projectFile)
1393 inputs.dir(getdownWebsiteDir)
1394 inputs.file(install4jConfFile)
1395 inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1396 inputs.dir(macosJavaVMDir)
1397 inputs.dir(windowsJavaVMDir)
1398 outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1402 task sourceDist(type: Tar) {
1404 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1405 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1406 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1408 archiveFileName = outputFileName
1409 } catch (Exception e) {
1410 archiveName = outputFileName
1413 compression Compression.GZIP
1428 "**/*.class","$j11modDir/**/*.jar","appletlib","**/*locales",
1430 "utils/InstallAnywhere",
1445 "gradle.properties",
1456 ".settings/org.eclipse.jdt.core.jalview.prefs",
1460 exclude (EXCLUDE_FILES)
1461 include (PROCESS_FILES)
1462 filter(ReplaceTokens,
1466 'Version-Rel': JALVIEW_VERSION,
1467 'Year-Rel': getDate("yyyy")
1472 exclude (EXCLUDE_FILES)
1473 exclude (PROCESS_FILES)
1474 exclude ("appletlib")
1475 exclude ("**/*locales")
1476 exclude ("*locales/**")
1477 exclude ("utils/InstallAnywhere")
1479 exclude (getdown_files_dir)
1480 exclude (getdown_website_dir)
1482 // exluding these as not using jars as modules yet
1483 exclude ("$j11modDir/**/*.jar")
1486 include(INCLUDE_FILES)
1488 // from (jalviewDir) {
1489 // // explicit includes for stuff that seemed to not get included
1490 // include(fileTree("test/**/*."))
1491 // exclude(EXCLUDE_FILES)
1492 // exclude(PROCESS_FILES)
1499 dependsOn pubhtmlhelp
1501 inputs.dir("${classesDir}/${help_dir}")
1502 outputs.dir("${buildDir}/distributions/${help_dir}")
1505 // LARGE AMOUNT OF JALVIEWJS STUFF DELETED HERE
1506 task eclipseAutoBuildTask {}
1507 task eclipseSynchronizationTask {}