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
12 classpath 'org.openclover:clover:4.3.1'
20 id 'com.github.johnrengelman.shadow' version '4.0.3'
21 id 'com.install4j.gradle' version '8.0.2'
22 id 'com.dorongold.task-tree' version '1.4' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree
35 compile 'org.apache.commons:commons-compress:1.18'
39 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
40 def string(Object o) {
41 return o == null ? "" : o.toString()
46 jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
47 jalviewDirRelativePath = jalviewDir
49 // local build environment properties
50 def localProps = "${jalviewDirAbsolutePath}/local.properties"
51 if (file(localProps).exists()) {
53 def p = new Properties()
54 def localPropsFIS = new FileInputStream(localProps)
59 def oldval = findProperty(key)
62 println("Overriding property '${key}' ('${oldval}') with local.properties value '${val}'")
64 println("Setting unknown property '${key}' with local.properties value '${val}'")
67 } catch (Exception e) {
68 System.out.println("Exception reading local.properties")
72 // this property set when running Eclipse headlessly
73 j2sHeadlessBuildProperty = string("net.sf.j2s.core.headlessbuild")
74 // this property set by Eclipse
75 eclipseApplicationProperty = string("eclipse.application")
76 // CHECK IF RUNNING FROM WITHIN ECLIPSE
77 def eclipseApplicationPropertyVal = System.properties[eclipseApplicationProperty]
78 IN_ECLIPSE = eclipseApplicationPropertyVal != null && eclipseApplicationPropertyVal.startsWith("org.eclipse.ui.")
79 // BUT WITHOUT THE HEADLESS BUILD PROPERTY SET
80 if (System.properties[j2sHeadlessBuildProperty].equals("true")) {
81 println("Setting IN_ECLIPSE to ${IN_ECLIPSE} as System.properties['${j2sHeadlessBuildProperty}'] == '${System.properties[j2sHeadlessBuildProperty]}'")
85 println("WITHIN ECLIPSE IDE")
87 println("HEADLESS BUILD")
90 System.properties.sort { it.key }.each {
91 key, val -> println("SYSTEM PROPERTY ${key}='${val}'")
94 if (false && IN_ECLIPSE) {
95 jalviewDir = jalviewDirAbsolutePath
100 bareSourceDir = string(source_dir)
101 sourceDir = string("${jalviewDir}/${bareSourceDir}")
102 resourceDir = string("${jalviewDir}/${resource_dir}")
103 bareTestSourceDir = string(test_source_dir)
104 testSourceDir = string("${jalviewDir}/${bareTestSourceDir}")
107 cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
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}")
120 getdownDir = string("")
121 reportRsyncCmd = false
123 buildProperties = build_properties_file
124 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
128 // TODO: get bamboo build artifact URL for getdown artifacts
129 getdown_channel_base = bamboo_channelbase
130 getdown_channel_name = string("${bamboo_planKey}/${JAVA_VERSION}")
131 getdown_app_base = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
132 getdown_app_dir = getdown_app_dir_alt
133 buildProperties = string("${classesDir}/${build_properties_file}")
137 getdown_channel_name = CHANNEL.toLowerCase()
138 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
139 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
140 getdown_app_dir = getdown_app_dir_release
141 buildProperties = string("${classesDir}/${build_properties_file}")
142 reportRsyncCommand = true
146 getdown_channel_name = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
147 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
148 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
149 getdown_app_dir = getdown_app_dir_alt
150 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
151 print "Must provide an ARCHIVEDIR value to produce an archive distribution"
154 packageDir = string("${ARCHIVEDIR}/${packageDir}")
155 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
158 reportRsyncCommand = true
162 getdown_channel_name = string("archive/${JALVIEW_VERSION}")
163 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
164 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
165 getdown_app_dir = getdown_app_dir_alt
166 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
167 print "Must provide an ARCHIVEDIR value to produce an archive distribution"
170 packageDir = string("${ARCHIVEDIR}/${packageDir}")
171 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
174 reportRsyncCommand = true
175 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
179 getdown_channel_name = CHANNEL.toLowerCase()
180 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
181 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
182 getdown_app_dir = getdown_app_dir_alt
183 buildProperties = string("${classesDir}/${build_properties_file}")
184 reportRsyncCommand = true
188 getdown_channel_name = CHANNEL.toLowerCase()
189 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
190 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
191 getdown_app_dir = getdown_app_dir_alt
192 buildProperties = string("${classesDir}/${build_properties_file}")
193 reportRsyncCommand = true
196 case ~/^SCRATCH(|-[-\w]*)$/:
197 getdown_channel_name = CHANNEL
198 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
199 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
200 getdown_app_dir = getdown_app_dir_alt
201 buildProperties = string("${classesDir}/${build_properties_file}")
202 reportRsyncCommand = true
206 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
207 getdown_app_dir = getdown_app_dir_alt
208 buildProperties = string("${classesDir}/${build_properties_file}")
209 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
212 default: // something wrong specified
213 println("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
218 // override getdown_app_base if requested
219 if (findProperty("getdown_appbase_override") != null) {
220 getdown_app_base = string(getProperty("getdown_appbase_override"))
221 println("Overriding getdown appbase with '${getdown_app_base}'")
224 getdownAppDir = string("${getdownWebsiteDir}/${getdown_app_dir}")
225 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
226 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
227 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
228 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
229 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
230 /* compile without modules -- using classpath libraries
231 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
232 modules_runtimeClasspath = modules_compileClasspath
235 gitBranch = string("")
237 println("Using a ${CHANNEL} profile.")
239 additional_compiler_args = []
240 // configure classpath/args for j8/j11 compilation
241 if (JAVA_VERSION.equals("1.8")) {
242 JAVA_INTEGER_VERSION = string("8")
245 libDistDir = j8libDir
246 compile_source_compatibility = 1.8
247 compile_target_compatibility = 1.8
248 // these are getdown.txt properties defined dependent on the JAVA_VERSION
249 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java8_min_version"))
250 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java8_max_version"))
251 // this property is assigned below and expanded to multiple lines in the getdown task
252 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java8_txt_multi_java_location"))
253 // this property is for the Java library used in eclipse
254 eclipseJavaRuntimeName = string("JavaSE-1.8")
255 } else if (JAVA_VERSION.equals("11")) {
256 JAVA_INTEGER_VERSION = string("11")
258 libDistDir = j11libDir
259 compile_source_compatibility = 11
260 compile_target_compatibility = 11
261 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
262 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
263 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
264 eclipseJavaRuntimeName = string("JavaSE-11")
265 /* compile without modules -- using classpath libraries
266 additional_compiler_args += [
267 '--module-path', modules_compileClasspath.asPath,
268 '--add-modules', j11modules
271 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
272 JAVA_INTEGER_VERSION = JAVA_VERSION
274 libDistDir = j11libDir
275 compile_source_compatibility = JAVA_VERSION
276 compile_target_compatibility = JAVA_VERSION
277 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
278 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
279 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
280 eclipseJavaRuntimeName = string("JavaSE-11")
281 /* compile without modules -- using classpath libraries
282 additional_compiler_args += [
283 '--module-path', modules_compileClasspath.asPath,
284 '--add-modules', j11modules
288 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
293 JAVA_MIN_VERSION = JAVA_VERSION
294 JAVA_MAX_VERSION = JAVA_VERSION
295 def jreInstallsDir = string(jre_installs_dir)
296 if (jreInstallsDir.startsWith("~/")) {
297 jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
299 macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
300 macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-mac-x64.tar.gz")
301 windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
302 windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-windows-x64.tar.gz")
303 linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
304 linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-linux-x64.tar.gz")
305 install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
306 install4jConfFileName = string("jalview-install4j-conf.install4j")
307 install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
308 install4jHomeDir = install4j_home_dir
309 if (install4jHomeDir.startsWith("~/")) {
310 install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
315 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
316 helpFile = string("${classesDir}/${help_dir}/help.jhm")
317 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
318 helpSourceDir = string("${helpParentDir}/${help_dir}")
321 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
322 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
323 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
325 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
327 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
329 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
330 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
331 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
332 jalviewjsJalviewCoreHtmlFile = string("")
333 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
334 jalviewjsCoreClasslists = []
335 jalviewjsJalviewTemplateName = string(jalviewjs_name)
336 jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
337 jalviewjsJ2sProps = null
339 eclipseWorkspace = null
340 eclipseBinary = string("")
341 eclipseVersion = string("")
351 outputDir = file(classesDir)
356 srcDirs += helpParentDir
359 jar.destinationDir = file("${jalviewDir}/${packageDir}")
361 compileClasspath = files(sourceSets.main.java.outputDir)
362 //compileClasspath += files(sourceSets.main.resources.srcDirs)
363 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
365 runtimeClasspath = compileClasspath
370 srcDirs = [ cloverInstrDir ]
371 outputDir = file("${buildDir}/${cloverClassesDir}")
375 srcDirs = sourceSets.main.resources.srcDirs
377 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
378 compileClasspath += files(sourceSets.main.java.outputDir)
379 compileClasspath += sourceSets.main.compileClasspath
380 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
381 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
383 runtimeClasspath = compileClasspath
388 srcDirs testSourceDir
389 outputDir = file("${jalviewDir}/${testOutputDir}")
393 srcDirs = sourceSets.main.resources.srcDirs
396 compileClasspath = files( sourceSets.test.java.outputDir )
399 compileClasspath += sourceSets.clover.compileClasspath
401 compileClasspath += files(sourceSets.main.java.outputDir)
404 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
405 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
406 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
408 runtimeClasspath = compileClasspath
416 cloverCompile 'org.openclover:clover:4.3.1'
417 testCompile 'org.openclover:clover:4.3.1'
424 cloverRuntime.extendsFrom cloverCompile
429 name = eclipse_project_name
431 natures 'org.eclipse.jdt.core.javanature',
432 'org.eclipse.jdt.groovy.core.groovyNature',
433 'org.eclipse.buildship.core.gradleprojectnature'
435 buildCommand 'org.eclipse.jdt.core.javabuilder'
436 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
440 //defaultOutputDir = sourceSets.main.java.outputDir
443 if (it.isCanBeResolved()) {
448 minusConfigurations += removeThese
449 plusConfigurations = [ ]
453 def removeTheseToo = []
454 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
455 cp.entries.each { entry ->
456 // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
457 // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
458 // we add the resources and help/help dirs in as libs afterwards (see below)
459 if (entry.kind == 'src') {
460 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
461 removeTheseToo += entry
463 alreadyAddedSrcPath.putAt(entry.path, true)
468 cp.entries.removeAll(removeTheseToo)
470 //cp.entries += new Output("${eclipse_bin_dir}/main")
471 if (file(helpParentDir).isDirectory()) {
472 cp.entries += new Library(fileReference(helpParentDir))
474 if (file(resourceDir).isDirectory()) {
475 cp.entries += new Library(fileReference(resourceDir))
478 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
480 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
481 //don't want to add outputDir as eclipse is using its own output dir in bin/main
482 if (it.isDirectory() || ! it.exists()) {
483 // don't add dirs to classpath, especially if they don't exist
484 return false // groovy "continue" in .any closure
486 def itPath = it.toString()
487 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
488 // make relative path
489 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
491 if (alreadyAddedLibPath.get(itPath)) {
492 //println("Not adding duplicate entry "+itPath)
494 //println("Adding entry "+itPath)
495 cp.entries += new Library(fileReference(itPath))
496 alreadyAddedLibPath.put(itPath, true)
500 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
501 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
502 if (it.isDirectory() || ! it.exists()) {
503 // don't add dirs to classpath
504 return false // groovy "continue" in .any closure
507 def itPath = it.toString()
508 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
509 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
511 if (alreadyAddedLibPath.get(itPath)) {
514 def lib = new Library(fileReference(itPath))
515 lib.entryAttributes["test"] = "true"
517 alreadyAddedLibPath.put(itPath, true)
525 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
530 // for the IDE, use java 11 compatibility
531 sourceCompatibility = compile_source_compatibility
532 targetCompatibility = compile_target_compatibility
533 javaRuntimeName = eclipseJavaRuntimeName
535 // add in jalview project specific properties/preferences into eclipse core preferences
537 withProperties { props ->
538 def jalview_prefs = new Properties()
539 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
540 jalview_prefs.load(ins)
542 jalview_prefs.forEach { t, v ->
543 if (props.getAt(t) == null) {
553 // Don't want these to be activated if in headless build
554 synchronizationTasks "eclipseSynchronizationTask"
555 autoBuildTasks "eclipseAutoBuildTask"
562 // only instrument source, we build test classes as normal
563 inputs.files files (sourceSets.main.allJava) // , fileTree(dir: testSourceDir, include: ["**/*.java"]))
564 outputs.dir cloverInstrDir
567 delete cloverInstrDir
568 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
569 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
570 argsList.addAll(inputs.files.files.collect({ file ->
573 String[] args = argsList.toArray()
574 println("About to instrument "+args.length +" files")
575 com.atlassian.clover.CloverInstr.mainImpl(args)
581 group = "Verification"
582 description = "Createst the Clover report"
583 inputs.dir "${buildDir}/clover"
584 outputs.dir "${reportsDir}/clover"
586 file("${buildDir}/clover/clover.db").exists()
589 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
590 "-o", "${reportsDir}/clover"]
591 String[] args = argsList.toArray()
592 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
594 // and generate ${reportsDir}/clover/clover.xml
595 args = ["--initstring", "${buildDir}/clover/clover.db",
596 "-o", "${reportsDir}/clover/clover.xml"].toArray()
597 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
606 sourceCompatibility = compile_source_compatibility
607 targetCompatibility = compile_target_compatibility
608 options.compilerArgs = additional_compiler_args
609 print ("Setting target compatibility to "+targetCompatibility+"\n")
617 dependsOn compileCloverJava
618 classpath += configurations.cloverRuntime
620 classpath += sourceSets.main.runtimeClasspath
623 sourceCompatibility = compile_source_compatibility
624 targetCompatibility = compile_target_compatibility
625 options.compilerArgs = additional_compiler_args
626 print ("Setting target compatibility to "+targetCompatibility+"\n")
634 sourceCompatibility = compile_source_compatibility
635 targetCompatibility = compile_target_compatibility
636 options.compilerArgs += additional_compiler_args
637 print ("Setting target compatibility to "+targetCompatibility+"\n")
639 classpath += configurations.cloverRuntime
645 delete sourceSets.main.java.outputDir
652 delete sourceSets.test.java.outputDir
653 delete cloverInstrDir
658 // format is a string like date.format("dd MMMM yyyy")
659 def getDate(format) {
660 def date = new Date()
661 return date.format(format)
666 def hashStdOut = new ByteArrayOutputStream()
668 commandLine "git", "rev-parse", "--short", "HEAD"
669 standardOutput = hashStdOut
673 def branchStdOut = new ByteArrayOutputStream()
675 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
676 standardOutput = branchStdOut
680 gitHash = hashStdOut.toString().trim()
681 gitBranch = branchStdOut.toString().trim()
683 outputs.upToDateWhen { false }
687 task createBuildProperties(type: WriteProperties) {
689 inputs.dir(sourceDir)
690 inputs.dir(resourceDir)
691 file(buildProperties).getParentFile().mkdirs()
692 outputFile (buildProperties)
693 // taking time specific comment out to allow better incremental builds
694 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
695 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
696 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
697 property "VERSION", JALVIEW_VERSION
698 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
699 outputs.file(outputFile)
703 task cleanBuildingHTML(type: Delete) {
710 task convertBuildingMD(type: Exec) {
711 dependsOn cleanBuildingHTML
712 def buildingMD = "${jalviewDir}/${docDir}/building.md"
713 def css = "${jalviewDir}/${docDir}/github.css"
716 pandoc_exec.split(",").each {
717 if (file(it.trim()).exists()) {
723 def hostname = "hostname".execute().text.trim()
724 def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
725 if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
726 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
730 if (pandoc != null && file(pandoc).exists()) {
731 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
733 println("Cannot find pandoc. Skipping convert building.md to HTML")
734 throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
740 inputs.file(buildingMD)
742 outputs.file(buildingHTML)
753 task syncDocs(type: Sync) {
754 dependsOn convertBuildingMD
755 def syncDir = "${classesDir}/${docDir}"
756 from fileTree("${jalviewDir}/${docDir}")
762 task copyHelp(type: Copy) {
763 def inputDir = helpSourceDir
764 def outputDir = "${classesDir}/${help_dir}"
769 filter(ReplaceTokens,
773 'Version-Rel': JALVIEW_VERSION,
774 'Year-Rel': getDate("yyyy")
786 outputs.files(helpFile)
787 outputs.dir(outputDir)
791 task syncLib(type: Sync) {
792 def syncDir = "${classesDir}/${libDistDir}"
793 from fileTree("${jalviewDir}/${libDistDir}")
798 task syncResources(type: Sync) {
809 dependsOn syncResources
815 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
818 dependsOn compileJava
820 dependsOn cloverInstr
824 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
828 includeGroups testngGroups
830 useDefaultListeners=true
833 workingDir = jalviewDir
834 //systemProperties 'clover.jar' System.properties.clover.jar
835 sourceCompatibility = compile_source_compatibility
836 targetCompatibility = compile_target_compatibility
837 jvmArgs += additional_compiler_args
842 task buildIndices(type: JavaExec) {
844 classpath = sourceSets.main.compileClasspath
845 main = "com.sun.java.help.search.Indexer"
846 workingDir = "${classesDir}/${help_dir}"
849 inputs.dir("${workingDir}/${argDir}")
851 outputs.dir("${classesDir}/doc")
852 outputs.dir("${classesDir}/help")
853 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
854 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
855 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
856 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
857 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
858 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
862 task compileLinkCheck(type: JavaCompile) {
864 classpath = files("${jalviewDir}/${utilsDir}")
865 destinationDir = file("${jalviewDir}/${utilsDir}")
866 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
868 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
869 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
870 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
871 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
875 task linkCheck(type: JavaExec) {
876 dependsOn prepare, compileLinkCheck
878 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
879 classpath = files("${jalviewDir}/${utilsDir}")
880 main = "HelpLinksChecker"
881 workingDir = jalviewDir
882 args = [ "${classesDir}/${help_dir}", "-nointernet" ]
884 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
886 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
889 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
893 inputs.dir("${classesDir}/${help_dir}")
894 outputs.file(helpLinksCheckerOutFile)
897 // import the pubhtmlhelp target
898 ant.properties.basedir = "${jalviewDir}"
899 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
900 ant.importBuild "${utilsDir}/publishHelp.xml"
903 task cleanPackageDir(type: Delete) {
905 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
911 dependsOn buildIndices
912 dependsOn createBuildProperties
915 attributes "Main-Class": mainClass,
916 "Permissions": "all-permissions",
917 "Application-Name": "Jalview Desktop",
918 "Codebase": application_codebase
921 destinationDir = file("${jalviewDir}/${packageDir}")
922 archiveName = rootProject.name+".jar"
930 inputs.dir(classesDir)
931 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
935 task copyJars(type: Copy) {
936 from fileTree(dir: classesDir, include: "**/*.jar").files
937 into "${jalviewDir}/${packageDir}"
941 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
942 task syncJars(type: Sync) {
943 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
944 into "${jalviewDir}/${packageDir}"
946 include jar.archiveName
953 description = "Put all required libraries in dist"
954 // order of "cleanPackageDir", "copyJars", "jar" important!
955 jar.mustRunAfter cleanPackageDir
956 syncJars.mustRunAfter cleanPackageDir
957 dependsOn cleanPackageDir
960 outputs.dir("${jalviewDir}/${packageDir}")
965 dependsOn cleanPackageDir
971 group = "distribution"
975 from ("${jalviewDir}/${libDistDir}") {
979 attributes 'Implementation-Version': JALVIEW_VERSION
981 mainClassName = shadowJarMainClass
983 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
988 task getdownWebsite() {
989 group = "distribution"
990 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
995 def getdownWebsiteResourceFilenames = []
996 def getdownTextString = ""
997 def getdownResourceDir = getdownResourceDir
998 def getdownAppDir = getdownAppDir
999 def getdownResourceFilenames = []
1002 // clean the getdown website and files dir before creating getdown folders
1003 delete getdownWebsiteDir
1004 delete getdownFilesDir
1007 from buildProperties
1008 rename(build_properties_file, getdown_build_properties)
1011 getdownWebsiteResourceFilenames += "${getdown_app_dir}/${getdown_build_properties}"
1013 // go through properties looking for getdown_txt_...
1014 def props = project.properties.sort { it.key }
1015 if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
1016 props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
1018 if (getdownAltJavaMaxVersion != null && getdownAltJavaMaxVersion.length() > 0) {
1019 props.put("getdown_txt_java_max_version", getdownAltJavaMaxVersion)
1021 if (getdownAltMultiJavaLocation != null && getdownAltMultiJavaLocation.length() > 0) {
1022 props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
1025 props.put("getdown_txt_appbase", getdown_app_base)
1026 props.each{ prop, val ->
1027 if (prop.startsWith("getdown_txt_") && val != null) {
1028 if (prop.startsWith("getdown_txt_multi_")) {
1029 def key = prop.substring(18)
1030 val.split(",").each{ v ->
1031 def line = "${key} = ${v}\n"
1032 getdownTextString += line
1035 // file values rationalised
1036 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1038 if (val.indexOf('/') == 0) {
1041 } else if (val.indexOf('/') > 0) {
1042 // relative path (relative to jalviewDir)
1043 r = file( "${jalviewDir}/${val}" )
1046 val = "${getdown_resource_dir}/" + r.getName()
1047 getdownWebsiteResourceFilenames += val
1048 getdownResourceFilenames += r.getPath()
1051 if (! prop.startsWith("getdown_txt_resource")) {
1052 def line = prop.substring(12) + " = ${val}\n"
1053 getdownTextString += line
1059 getdownWebsiteResourceFilenames.each{ filename ->
1060 getdownTextString += "resource = ${filename}\n"
1062 getdownResourceFilenames.each{ filename ->
1065 into getdownResourceDir
1070 fileTree(file(packageDir)).each{ f ->
1071 if (f.isDirectory()) {
1072 def files = fileTree(dir: f, include: ["*"]).getFiles()
1074 } else if (f.exists()) {
1078 codeFiles.sort().each{f ->
1079 def name = f.getName()
1080 def line = "code = ${getdown_app_dir}/${name}\n"
1081 getdownTextString += line
1088 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1090 if (JAVA_VERSION.equals("11")) {
1091 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1092 j11libFiles.sort().each{f ->
1093 def name = f.getName()
1094 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1095 getdownTextString += line
1098 into getdownJ11libDir
1104 // 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.
1105 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1106 getdownTextString += "resource = ${getdown_launcher_new}\n"
1107 getdownTextString += "class = ${mainClass}\n"
1109 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1110 getdown_txt.write(getdownTextString)
1112 def launch_jvl = file("${getdownWebsiteDir}/${getdown_launch_jvl}")
1113 launch_jvl.write("appbase="+props.get("getdown_txt_appbase"))
1116 from getdownLauncher
1117 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1118 into getdownWebsiteDir
1122 from getdownLauncher
1123 if (file(getdownLauncher).getName() != getdown_launcher) {
1124 rename(file(getdownLauncher).getName(), getdown_launcher)
1126 into getdownWebsiteDir
1129 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1132 from getdownLauncher
1133 from "${getdownWebsiteDir}/${getdown_build_properties}"
1134 if (file(getdownLauncher).getName() != getdown_launcher) {
1135 rename(file(getdownLauncher).getName(), getdown_launcher)
1137 into getdownInstallDir
1141 from getdownInstallDir
1142 into getdownFilesInstallDir
1149 from getdownLauncher
1150 from "${getdownWebsiteDir}/${getdown_build_properties}"
1151 if (file(getdownLauncher).getName() != getdown_launcher) {
1152 rename(file(getdownLauncher).getName(), getdown_launcher)
1154 into getdownFilesDir
1158 from getdownResourceDir
1159 into "${getdownFilesDir}/${getdown_resource_dir}"
1164 inputs.dir("${jalviewDir}/${packageDir}")
1166 outputs.dir(getdownWebsiteDir)
1167 outputs.dir(getdownFilesDir)
1171 task getdownDigest(type: JavaExec) {
1172 group = "distribution"
1173 description = "Digest the getdown website folder"
1174 dependsOn getdownWebsite
1176 classpath = files("${getdownWebsiteDir}/${getdown_launcher}")
1178 main = "com.threerings.getdown.tools.Digester"
1179 args getdownWebsiteDir
1180 inputs.dir(getdownWebsiteDir)
1181 outputs.file("${getdownWebsiteDir}/digest2.txt")
1186 group = "distribution"
1187 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1188 dependsOn getdownDigest
1190 if (reportRsyncCommand) {
1191 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1192 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1193 println "LIKELY RSYNC COMMAND:"
1194 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1195 if (RUNRSYNC == "true") {
1197 commandLine "mkdir", "-p", toDir
1200 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1210 delete getdownWebsiteDir
1211 delete getdownFilesDir
1217 if (file(install4jHomeDir).exists()) {
1219 } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1220 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1221 } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1222 install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1224 installDir(file(install4jHomeDir))
1226 mediaTypes = Arrays.asList(install4j_media_types.split(","))
1230 task copyInstall4jTemplate {
1231 def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
1232 def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1233 inputs.file(install4jTemplateFile)
1234 inputs.file(install4jFileAssociationsFile)
1235 outputs.file(install4jConfFile)
1238 def install4jConfigXml = new XmlParser().parse(install4jTemplateFile)
1240 // turn off code signing if no OSX_KEYPASS
1241 if (OSX_KEYPASS == "") {
1242 install4jConfigXml.'**'.codeSigning.each { codeSigning ->
1243 codeSigning.'@macEnabled' = "false"
1245 install4jConfigXml.'**'.windows.each { windows ->
1246 windows.'@runPostProcessor' = "false"
1250 // put file association actions where placeholder action is
1251 def install4jFileAssociationsText = install4jFileAssociationsFile.text
1252 def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
1253 install4jConfigXml.'**'.action.any { a ->
1254 if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1255 def parent = a.parent()
1257 fileAssociationActions.each { faa ->
1260 // don't need to continue in .any loop once replacements have been made
1265 // write install4j file
1266 install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
1273 delete install4jConfFile
1278 task installers(type: com.install4j.gradle.Install4jTask) {
1279 group = "distribution"
1280 description = "Create the install4j installers"
1281 dependsOn setGitVals
1283 dependsOn copyInstall4jTemplate
1285 projectFile = install4jConfFile
1287 // create an md5 for the input files to use as version for install4j conf file
1288 def digest = MessageDigest.getInstance("MD5")
1290 (file("${install4jDir}/${install4j_template}").text +
1291 file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1292 file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1293 def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1294 if (filesMd5.length() >= 8) {
1295 filesMd5 = filesMd5.substring(0,8)
1297 def install4jTemplateVersion = "${JALVIEW_VERSION}_F${filesMd5}_C${gitHash}"
1298 // make install4jBuildDir relative to jalviewDir
1299 def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
1302 'JALVIEW_DIR': "../..",
1303 'OSX_KEYSTORE': OSX_KEYSTORE,
1304 'JSIGN_SH': JSIGN_SH,
1305 'JRE_DIR': getdown_app_dir_java,
1306 'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1307 'JALVIEW_VERSION': JALVIEW_VERSION,
1308 'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1309 'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1310 'JAVA_VERSION': JAVA_VERSION,
1311 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1312 'VERSION': JALVIEW_VERSION,
1313 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1314 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1315 'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
1316 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1317 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1318 'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
1319 'COPYRIGHT_MESSAGE': install4j_copyright_message,
1320 'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1321 'INSTALL4J_UTILS_DIR': install4j_utils_dir,
1322 'GETDOWN_WEBSITE_DIR': getdown_website_dir,
1323 'GETDOWN_FILES_DIR': getdown_files_dir,
1324 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1325 'GETDOWN_DIST_DIR': getdown_app_dir,
1326 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1327 'GETDOWN_INSTALL_DIR': getdown_install_dir,
1328 'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
1329 'BUILD_DIR': install4jBuildDir,
1332 destination = "${jalviewDir}/${install4jBuildDir}"
1333 buildSelected = true
1335 if (install4j_faster.equals("true") || CHANNEL.startsWith("DEVELOP") || CHANNEL.startsWith("LOCAL")) {
1336 // this doesn't seem to work
1338 disableSigning = true
1342 macKeystorePassword = OSX_KEYPASS
1346 println("Using projectFile "+projectFile)
1349 inputs.dir(getdownWebsiteDir)
1350 inputs.file(install4jConfFile)
1351 inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1352 inputs.dir(macosJavaVMDir)
1353 inputs.dir(windowsJavaVMDir)
1354 outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1358 task sourceDist(type: Tar) {
1360 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1361 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1362 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1364 archiveFileName = outputFileName
1365 } catch (Exception e) {
1366 archiveName = outputFileName
1369 compression Compression.GZIP
1373 def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1378 ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1380 ,"utils/InstallAnywhere"]
1381 def PROCESS_FILES=[ "AUTHORS",
1389 "THIRDPARTYLIBS","TESTNG",
1391 "gradle.properties",
1402 exclude (EXCLUDE_FILES)
1403 include (PROCESS_FILES)
1404 filter(ReplaceTokens,
1408 'Version-Rel': JALVIEW_VERSION,
1409 'Year-Rel': getDate("yyyy")
1414 exclude (EXCLUDE_FILES)
1415 exclude (PROCESS_FILES)
1416 exclude ("appletlib")
1417 exclude ("**/*locales")
1418 exclude ("*locales/**")
1419 exclude ("utils/InstallAnywhere")
1421 exclude (getdown_files_dir)
1422 exclude (getdown_website_dir)
1424 // exluding these as not using jars as modules yet
1425 exclude ("${j11modDir}/**/*.jar")
1427 // from (jalviewDir) {
1428 // // explicit includes for stuff that seemed to not get included
1429 // include(fileTree("test/**/*."))
1430 // exclude(EXCLUDE_FILES)
1431 // exclude(PROCESS_FILES)
1438 dependsOn pubhtmlhelp
1440 inputs.dir("${classesDir}/${help_dir}")
1441 outputs.dir("${buildDir}/distributions/${help_dir}")
1444 // LARGE AMOUNT OF JALVIEWJS STUFF DELETED HERE
1445 task eclipseAutoBuildTask {}
1446 task eclipseSynchronizationTask {}