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.XmlSlurper
8 import groovy.util.XmlParser
9 import groovy.xml.XmlUtil
13 classpath 'org.openclover:clover:4.3.1'
21 id 'com.github.johnrengelman.shadow' version '4.0.3'
22 id 'com.install4j.gradle' version '8.0.2'
23 id 'com.dorongold.task-tree' version '1.4' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree
36 compile 'org.apache.commons:commons-compress:1.18'
40 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
41 def string(Object o) {
47 jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
48 jalviewDirRelativePath = jalviewDir
50 // local build environment properties
51 def localProps = "${jalviewDirAbsolutePath}/local.properties"
52 if (file(localProps).exists()) {
54 def p = new Properties()
55 def localPropsFIS = new FileInputStream(localProps)
60 def over = getProperty(key) != null
63 println("Overriding 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 classesDir = string("${jalviewDir}/${classes_dir}")
108 if (clover.equals("true")) {
110 classesDir = string("${buildDir}/${cloverClassesDir}")
113 classesDir = string("${jalviewDir}/${classes_dir}")
118 getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
119 getdownDir = string("")
120 reportRsyncCmd = false
122 buildProperties = build_properties_file
123 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
127 // TODO: get bamboo build artifact URL for getdown artifacts
128 getdown_channel_base = bamboo_channelbase
129 getdown_channel_name = string("${bamboo_planKey}/${JAVA_VERSION}")
130 getdown_app_base = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
131 getdown_app_dir = getdown_app_dir_alt
132 buildProperties = string("${classesDir}/${build_properties_file}")
136 getdown_channel_name = CHANNEL.toLowerCase()
137 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
138 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
139 getdown_app_dir = getdown_app_dir_release
140 buildProperties = string("${classesDir}/${build_properties_file}")
141 reportRsyncCommand = true
145 getdown_channel_name = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
146 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
147 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
148 getdown_app_dir = getdown_app_dir_alt
149 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
150 print "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 getdown_channel_name = string("archive/${JALVIEW_VERSION}")
162 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
163 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
164 getdown_app_dir = getdown_app_dir_alt
165 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
166 print "Must provide an ARCHIVEDIR value to produce an archive distribution"
169 packageDir = string("${ARCHIVEDIR}/${packageDir}")
170 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
173 reportRsyncCommand = true
174 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
178 getdown_channel_name = CHANNEL.toLowerCase()
179 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
180 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
181 getdown_app_dir = getdown_app_dir_alt
182 buildProperties = string("${classesDir}/${build_properties_file}")
183 reportRsyncCommand = true
187 getdown_channel_name = CHANNEL.toLowerCase()
188 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
189 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
190 getdown_app_dir = getdown_app_dir_alt
191 buildProperties = string("${classesDir}/${build_properties_file}")
192 reportRsyncCommand = true
195 case ~/^SCRATCH(|-[-\w]*)$/:
196 getdown_channel_name = CHANNEL
197 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
198 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
199 getdown_app_dir = getdown_app_dir_alt
200 buildProperties = string("${classesDir}/${build_properties_file}")
201 reportRsyncCommand = true
205 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
206 getdown_app_dir = getdown_app_dir_alt
207 buildProperties = string("${classesDir}/${build_properties_file}")
208 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
211 default: // something wrong specified
212 print("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
218 getdownAppDir = string("${getdownWebsiteDir}/${getdown_app_dir}")
219 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
220 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
221 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
222 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
223 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
224 /* compile without modules -- using classpath libraries
225 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
226 modules_runtimeClasspath = modules_compileClasspath
229 gitBranch = string("")
231 println("Using a ${CHANNEL} profile.")
233 additional_compiler_args = []
234 // configure classpath/args for j8/j11 compilation
235 if (JAVA_VERSION.equals("1.8")) {
236 JAVA_INTEGER_VERSION = string("8")
239 libDistDir = j8libDir
240 compile_source_compatibility = 1.8
241 compile_target_compatibility = 1.8
242 // these are getdown.txt properties defined dependent on the JAVA_VERSION
243 getdown_alt_java_min_version = getdown_alt_java8_min_version
244 getdown_alt_java_max_version = getdown_alt_java8_max_version
245 // this property is assigned below and expanded to multiple lines in the getdown task
246 getdown_alt_multi_java_location = getdown_alt_java8_txt_multi_java_location
247 // this property is for the Java library used in eclipse
248 eclipse_java_runtime_name = string("JavaSE-1.8")
249 } else if (JAVA_VERSION.equals("11")) {
250 JAVA_INTEGER_VERSION = string("11")
252 libDistDir = j11libDir
253 compile_source_compatibility = 11
254 compile_target_compatibility = 11
255 getdown_alt_java_min_version = getdown_alt_java11_min_version
256 getdown_alt_java_max_version = getdown_alt_java11_max_version
257 getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
258 eclipse_java_runtime_name = string("JavaSE-11")
259 /* compile without modules -- using classpath libraries
260 additional_compiler_args += [
261 '--module-path', modules_compileClasspath.asPath,
262 '--add-modules', j11modules
265 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
266 JAVA_INTEGER_VERSION = JAVA_VERSION
268 libDistDir = j11libDir
269 compile_source_compatibility = JAVA_VERSION
270 compile_target_compatibility = JAVA_VERSION
271 getdown_alt_java_min_version = getdown_alt_java11_min_version
272 getdown_alt_java_max_version = getdown_alt_java11_max_version
273 getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
274 eclipse_java_runtime_name = string("JavaSE-11")
275 /* compile without modules -- using classpath libraries
276 additional_compiler_args += [
277 '--module-path', modules_compileClasspath.asPath,
278 '--add-modules', j11modules
282 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
287 JAVA_MIN_VERSION = JAVA_VERSION
288 JAVA_MAX_VERSION = JAVA_VERSION
289 macosJavaVMDir = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/macos-jre${JAVA_VERSION}/jre")
290 macosJavaVMTgz = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/macos-jre${JAVA_VERSION}.tar.gz")
291 windowsJavaVMDir = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/windows-jre${JAVA_VERSION}/jre")
292 windowsJavaVMTgz = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/windows-jre${JAVA_VERSION}.tar.gz")
293 install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
294 install4jConfFileName = string("jalview-installers-java${JAVA_VERSION}.install4j")
295 install4jConfFile = string("${install4jDir}/${install4jConfFileName}")
296 install4jHomeDir = install4j_home_dir
297 if (install4jHomeDir.startsWith("~/")) {
298 install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
303 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
304 helpFile = string("${classesDir}/${help_dir}/help.jhm")
305 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
306 helpDir = string("${help_dir}")
307 helpSourceDir = string("${helpParentDir}/${helpDir}")
310 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
311 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
312 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
314 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
316 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
318 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
319 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
320 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
321 jalviewjsJalviewCoreHtmlFile = string("")
322 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
323 jalviewjsCoreClasslists = []
324 jalviewjsJalviewTemplateName = string(jalviewjs_name)
325 jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
326 jalviewjsJ2sProps = null
328 eclipseWorkspace = null
329 eclipseBinary = string("")
330 eclipseVersion = string("")
340 outputDir = file(classesDir)
347 jar.destinationDir = file("${jalviewDir}/${packageDir}")
349 compileClasspath = files(sourceSets.main.java.outputDir)
350 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
352 runtimeClasspath = compileClasspath
357 srcDirs = [ cloverInstrDir ]
358 outputDir = file("${buildDir}/${cloverClassesDir}")
362 srcDirs = sourceSets.main.resources.srcDirs
364 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
365 compileClasspath += files(sourceSets.main.java.outputDir)
366 compileClasspath += sourceSets.main.compileClasspath
367 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
368 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
370 runtimeClasspath = compileClasspath
375 srcDirs testSourceDir
376 outputDir = file("${jalviewDir}/${testOutputDir}")
380 srcDirs = sourceSets.main.resources.srcDirs
383 compileClasspath = files( sourceSets.test.java.outputDir )
386 compileClasspath += sourceSets.clover.compileClasspath
388 compileClasspath += files(sourceSets.main.java.outputDir)
391 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
392 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
393 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
395 runtimeClasspath = compileClasspath
403 cloverCompile 'org.openclover:clover:4.3.1'
404 testCompile 'org.openclover:clover:4.3.1'
411 cloverRuntime.extendsFrom cloverCompile
416 name = eclipse_project_name
418 natures 'org.eclipse.jdt.core.javanature',
419 'org.eclipse.jdt.groovy.core.groovyNature',
420 'org.eclipse.buildship.core.gradleprojectnature'
422 buildCommand 'org.eclipse.jdt.core.javabuilder'
423 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
427 //defaultOutputDir = sourceSets.main.java.outputDir
430 if (it.isCanBeResolved()) {
435 minusConfigurations += removeThese
436 plusConfigurations = [ ]
440 def removeTheseToo = []
441 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
442 cp.entries.each { entry ->
443 // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
444 // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
445 // we add the resources and help/help dirs in as libs afterwards (see below)
446 if (entry.kind == 'src') {
447 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
448 removeTheseToo += entry
450 alreadyAddedSrcPath.putAt(entry.path, true)
455 cp.entries.removeAll(removeTheseToo)
457 //cp.entries += new Output("${eclipse_bin_dir}/main")
458 if (file(helpSourceDir).isDirectory()) {
459 cp.entries += new Library(fileReference(helpSourceDir))
461 if (file(resourceDir).isDirectory()) {
462 cp.entries += new Library(fileReference(resourceDir))
465 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
467 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.each {
468 //don't want to add outputDir as eclipse is using its own output dir in bin/main
469 if (it.isDirectory() || ! it.exists()) {
470 // don't add dirs to classpath, especially if they don't exist
471 return false // groovy "continue" in .any closure
473 def itPath = it.toString()
474 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
475 // make relative path
476 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
478 if (alreadyAddedLibPath.get(itPath)) {
479 //println("Not adding duplicate entry "+itPath)
481 //println("Adding entry "+itPath)
482 cp.entries += new Library(fileReference(itPath))
483 alreadyAddedLibPath.put(itPath, true)
487 //fileTree(dir: "$jalviewDir/$utilsDir", include: ["test*/*.jar"]).each {
488 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
489 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
490 if (it.isDirectory() || ! it.exists()) {
491 // don't add dirs to classpath
492 return false // groovy "continue" in .any closure
495 def itPath = it.toString()
496 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
497 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
499 if (alreadyAddedLibPath.get(itPath)) {
502 def lib = new Library(fileReference(itPath))
503 lib.entryAttributes["test"] = "true"
505 alreadyAddedLibPath.put(itPath, true)
513 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
518 // for the IDE, use java 11 compatibility
519 sourceCompatibility = compile_source_compatibility
520 targetCompatibility = compile_target_compatibility
521 javaRuntimeName = eclipse_java_runtime_name
523 // add in jalview project specific properties/preferences into eclipse core preferences
525 withProperties { props ->
526 def jalview_prefs = new Properties()
527 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
528 jalview_prefs.load(ins)
530 jalview_prefs.forEach { t, v ->
531 if (props.getAt(t) == null) {
541 // Don't want these to be activated if in headless build
542 synchronizationTasks "eclipseSynchronizationTask"
543 autoBuildTasks "eclipseAutoBuildTask"
550 // only instrument source, we build test classes as normal
551 inputs.files files (sourceSets.main.allJava) // , fileTree(dir: testSourceDir, include: ["**/*.java"]))
552 outputs.dir cloverInstrDir
555 delete cloverInstrDir
556 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
557 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
558 argsList.addAll(inputs.files.files.collect({ file ->
561 String[] args = argsList.toArray()
562 println("About to instrument "+args.length +" files")
563 com.atlassian.clover.CloverInstr.mainImpl(args)
569 group = "Verification"
570 description = "Createst the Clover report"
571 inputs.dir "${buildDir}/clover"
572 outputs.dir "${reportsDir}/clover"
574 file("${buildDir}/clover/clover.db").exists()
577 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
578 "-o", "${reportsDir}/clover"]
579 String[] args = argsList.toArray()
580 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
582 // and generate ${reportsDir}/clover/clover.xml
583 args = ["--initstring", "${buildDir}/clover/clover.db",
584 "-o", "${reportsDir}/clover/clover.xml"].toArray()
585 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
594 sourceCompatibility = compile_source_compatibility
595 targetCompatibility = compile_target_compatibility
596 options.compilerArgs = additional_compiler_args
597 print ("Setting target compatibility to "+targetCompatibility+"\n")
605 dependsOn compileCloverJava
606 classpath += configurations.cloverRuntime
608 classpath += sourceSets.main.runtimeClasspath
611 sourceCompatibility = compile_source_compatibility
612 targetCompatibility = compile_target_compatibility
613 options.compilerArgs = additional_compiler_args
614 print ("Setting target compatibility to "+targetCompatibility+"\n")
622 sourceCompatibility = compile_source_compatibility
623 targetCompatibility = compile_target_compatibility
624 options.compilerArgs += additional_compiler_args
625 print ("Setting target compatibility to "+targetCompatibility+"\n")
627 classpath += configurations.cloverRuntime
633 delete sourceSets.main.java.outputDir
640 delete sourceSets.test.java.outputDir
641 delete cloverInstrDir
646 // format is a string like date.format("dd MMMM yyyy")
647 def getDate(format) {
648 def date = new Date()
649 return date.format(format)
654 def hashStdOut = new ByteArrayOutputStream()
656 commandLine "git", "rev-parse", "--short", "HEAD"
657 standardOutput = hashStdOut
661 def branchStdOut = new ByteArrayOutputStream()
663 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
664 standardOutput = branchStdOut
668 gitHash = hashStdOut.toString().trim()
669 gitBranch = branchStdOut.toString().trim()
671 outputs.upToDateWhen { false }
675 task createBuildProperties(type: WriteProperties) {
677 inputs.dir(sourceDir)
678 inputs.dir(resourceDir)
679 file(buildProperties).getParentFile().mkdirs()
680 outputFile (buildProperties)
681 // taking time specific comment out to allow better incremental builds
682 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
683 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
684 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
685 property "VERSION", JALVIEW_VERSION
686 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
687 outputs.file(outputFile)
691 task cleanBuildingHTML(type: Delete) {
698 task convertBuildingMD(type: Exec) {
699 dependsOn cleanBuildingHTML
700 def buildingMD = "${jalviewDir}/${docDir}/building.md"
701 def css = "${jalviewDir}/${docDir}/github.css"
704 pandoc_exec.split(",").each {
705 if (file(it.trim()).exists()) {
711 def hostname = "hostname".execute().text.trim()
712 if ((pandoc == null || ! file(pandoc).exists()) && hostname.equals("jv-bamboo")) {
713 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
717 if (pandoc != null && file(pandoc).exists()) {
718 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
720 println("Cannot find pandoc. Skipping convert building.md to HTML")
721 throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
727 inputs.file(buildingMD)
729 outputs.file(buildingHTML)
740 task syncDocs(type: Sync) {
741 dependsOn convertBuildingMD
742 def syncDir = "${classesDir}/${docDir}"
743 from fileTree("${jalviewDir}/${docDir}")
749 task copyHelp(type: Copy) {
750 def inputDir = helpSourceDir
751 def outputDir = "${classesDir}/${helpDir}"
756 filter(ReplaceTokens,
760 'Version-Rel': JALVIEW_VERSION,
761 'Year-Rel': getDate("yyyy")
773 outputs.files(helpFile)
774 outputs.dir(outputDir)
778 task syncLib(type: Sync) {
779 def syncDir = "${classesDir}/${libDistDir}"
780 from fileTree("${jalviewDir}/${libDistDir}")
785 task syncResources(type: Sync) {
796 dependsOn syncResources
802 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
805 dependsOn compileJava
807 dependsOn cloverInstr
811 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
815 includeGroups testngGroups
817 useDefaultListeners=true
820 workingDir = jalviewDir
821 //systemProperties 'clover.jar' System.properties.clover.jar
822 sourceCompatibility = compile_source_compatibility
823 targetCompatibility = compile_target_compatibility
824 jvmArgs += additional_compiler_args
829 task buildIndices(type: JavaExec) {
831 classpath = sourceSets.main.compileClasspath
832 main = "com.sun.java.help.search.Indexer"
833 workingDir = "${classesDir}/${helpDir}"
836 inputs.dir("${workingDir}/${argDir}")
838 outputs.dir("${classesDir}/doc")
839 outputs.dir("${classesDir}/help")
840 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
841 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
842 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
843 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
844 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
845 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
849 task compileLinkCheck(type: JavaCompile) {
851 classpath = files("${jalviewDir}/${utilsDir}")
852 destinationDir = file("${jalviewDir}/${utilsDir}")
853 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
855 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
856 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
857 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
858 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
862 task linkCheck(type: JavaExec) {
863 dependsOn prepare, compileLinkCheck
865 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
866 classpath = files("${jalviewDir}/${utilsDir}")
867 main = "HelpLinksChecker"
868 workingDir = jalviewDir
869 def help = "${classesDir}/${helpDir}"
870 args = [ "${classesDir}/${helpDir}", "-nointernet" ]
872 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
874 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
877 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
881 inputs.dir("${classesDir}/${helpDir}")
882 outputs.file(helpLinksCheckerOutFile)
885 // import the pubhtmlhelp target
886 ant.properties.basedir = "${jalviewDir}"
887 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${helpDir}"
888 ant.importBuild "${utilsDir}/publishHelp.xml"
891 task cleanPackageDir(type: Delete) {
893 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
899 dependsOn buildIndices
900 dependsOn createBuildProperties
903 attributes "Main-Class": mainClass,
904 "Permissions": "all-permissions",
905 "Application-Name": "Jalview Desktop",
906 "Codebase": application_codebase
909 destinationDir = file("${jalviewDir}/${packageDir}")
910 archiveName = rootProject.name+".jar"
918 inputs.dir(classesDir)
919 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
923 task copyJars(type: Copy) {
924 from fileTree(dir: classesDir, include: "**/*.jar").files
925 into "${jalviewDir}/${packageDir}"
929 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
930 task syncJars(type: Sync) {
931 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
932 into "${jalviewDir}/${packageDir}"
934 include jar.archiveName
941 description = "Put all required libraries in dist"
942 // order of "cleanPackageDir", "copyJars", "jar" important!
943 jar.mustRunAfter cleanPackageDir
944 syncJars.mustRunAfter cleanPackageDir
945 dependsOn cleanPackageDir
948 outputs.dir("${jalviewDir}/${packageDir}")
953 dependsOn cleanPackageDir
959 group = "distribution"
963 from ("${jalviewDir}/${libDistDir}") {
967 attributes 'Implementation-Version': JALVIEW_VERSION
969 mainClassName = shadowJarMainClass
971 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
976 task getdownWebsite() {
977 group = "distribution"
978 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
983 def getdownWebsiteResourceFilenames = []
984 def getdownTextString = ""
985 def getdownResourceDir = getdownResourceDir
986 def getdownAppDir = getdownAppDir
987 def getdownResourceFilenames = []
990 // clean the getdown website and files dir before creating getdown folders
991 delete getdownWebsiteDir
992 delete getdownFilesDir
996 rename(build_properties_file, getdown_build_properties)
999 getdownWebsiteResourceFilenames += "${getdown_app_dir}/${getdown_build_properties}"
1001 // go through properties looking for getdown_txt_...
1002 def props = project.properties.sort { it.key }
1003 if (getdown_alt_java_min_version.length() > 0) {
1004 props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
1006 if (getdown_alt_java_max_version.length() > 0) {
1007 props.put("getdown_txt_java_max_version", getdown_alt_java_max_version)
1009 props.put("getdown_txt_multi_java_location", getdown_alt_multi_java_location)
1011 props.put("getdown_txt_appbase", getdown_app_base)
1012 props.each{ prop, val ->
1013 if (prop.startsWith("getdown_txt_") && val != null) {
1014 if (prop.startsWith("getdown_txt_multi_")) {
1015 def key = prop.substring(18)
1016 val.split(",").each{ v ->
1017 def line = "${key} = ${v}\n"
1018 getdownTextString += line
1021 // file values rationalised
1022 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1024 if (val.indexOf('/') == 0) {
1027 } else if (val.indexOf('/') > 0) {
1028 // relative path (relative to jalviewDir)
1029 r = file( "${jalviewDir}/${val}" )
1032 val = "${getdown_resource_dir}/" + r.getName()
1033 getdownWebsiteResourceFilenames += val
1034 getdownResourceFilenames += r.getPath()
1037 if (! prop.startsWith("getdown_txt_resource")) {
1038 def line = prop.substring(12) + " = ${val}\n"
1039 getdownTextString += line
1045 getdownWebsiteResourceFilenames.each{ filename ->
1046 getdownTextString += "resource = ${filename}\n"
1048 getdownResourceFilenames.each{ filename ->
1051 into getdownResourceDir
1056 fileTree(file(packageDir)).each{ f ->
1057 if (f.isDirectory()) {
1058 def files = fileTree(dir: f, include: ["*"]).getFiles()
1060 } else if (f.exists()) {
1064 codeFiles.sort().each{f ->
1065 def name = f.getName()
1066 def line = "code = ${getdown_app_dir}/${name}\n"
1067 getdownTextString += line
1074 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1076 if (JAVA_VERSION.equals("11")) {
1077 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1078 j11libFiles.sort().each{f ->
1079 def name = f.getName()
1080 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1081 getdownTextString += line
1084 into getdownJ11libDir
1090 // 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.
1091 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1092 getdownTextString += "resource = ${getdown_launcher_new}\n"
1093 getdownTextString += "class = ${mainClass}\n"
1095 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1096 getdown_txt.write(getdownTextString)
1098 def launch_jvl = file("${getdownWebsiteDir}/${getdown_launch_jvl}")
1099 launch_jvl.write("appbase="+props.get("getdown_txt_appbase"))
1102 from getdownLauncher
1103 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1104 into getdownWebsiteDir
1108 from getdownLauncher
1109 if (file(getdownLauncher).getName() != getdown_launcher) {
1110 rename(file(getdownLauncher).getName(), getdown_launcher)
1112 into getdownWebsiteDir
1115 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1118 from getdownLauncher
1119 from "${getdownWebsiteDir}/${getdown_build_properties}"
1120 if (file(getdownLauncher).getName() != getdown_launcher) {
1121 rename(file(getdownLauncher).getName(), getdown_launcher)
1123 into getdownInstallDir
1127 from getdownInstallDir
1128 into getdownFilesInstallDir
1135 from getdownLauncher
1136 from "${getdownWebsiteDir}/${getdown_build_properties}"
1137 if (file(getdownLauncher).getName() != getdown_launcher) {
1138 rename(file(getdownLauncher).getName(), getdown_launcher)
1140 into getdownFilesDir
1144 from getdownResourceDir
1145 into "${getdownFilesDir}/${getdown_resource_dir}"
1150 inputs.dir("${jalviewDir}/${packageDir}")
1152 outputs.dir(getdownWebsiteDir)
1153 outputs.dir(getdownFilesDir)
1157 task getdownDigest(type: JavaExec) {
1158 group = "distribution"
1159 description = "Digest the getdown website folder"
1160 dependsOn getdownWebsite
1162 classpath = files("${getdownWebsiteDir}/${getdown_launcher}")
1164 main = "com.threerings.getdown.tools.Digester"
1165 args getdownWebsiteDir
1166 inputs.dir(getdownWebsiteDir)
1167 outputs.file("${getdownWebsiteDir}/digest2.txt")
1172 group = "distribution"
1173 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1174 dependsOn getdownDigest
1176 if (reportRsyncCommand) {
1177 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1178 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1179 println "LIKELY RSYNC COMMAND:"
1180 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1181 if (RUNRSYNC == "true") {
1183 commandLine "mkdir", "-p", toDir
1186 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1196 delete getdownWebsiteDir
1197 delete getdownFilesDir
1203 if (file(install4jHomeDir).exists()) {
1205 } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1206 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1207 } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1208 install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1210 installDir(file(install4jHomeDir))
1212 mediaTypes = Arrays.asList(install4j_media_types.split(","))
1216 task copyInstall4jTemplate(type: Copy) {
1217 dependsOn setGitVals
1219 inputs.file("${install4jDir}/${install4j_template}")
1220 inputs.file("${install4jDir}/${install4j_installer_file_associations}")
1221 outputs.files(install4jConfFile)
1223 from (install4jDir) {
1224 include install4j_template
1225 rename (install4j_template, install4jConfFileName)
1226 // TODO change these ReplaceTokens to something better. Possibly ${compiler:variables} but also the ant.replaceregexp below, or perhaps a proper xmldom parse
1229 if (OSX_KEYPASS == "") {
1230 filter(ReplaceTokens,
1231 beginToken: 'codeSigning macEnabled="',
1234 'true': 'codeSigning macEnabled="false"'
1237 filter(ReplaceTokens,
1238 beginToken: 'runPostProcessor="true" ',
1239 endToken: 'Processor',
1241 'post': 'runPostProcessor="false" postProcessor'
1250 // include file associations in installer
1251 def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1252 def install4jFileAssociationsText = install4jFileAssociationsFile.text
1257 match: '<action name="EXTENSIONS_REPLACED_BY_GRADLE".*?</action>',
1258 replace: install4jFileAssociationsText,
1259 file: install4jConfFile
1263 def install4jFileAssociations = new XmlParser().parseText('''
1264 <install4jFileAssociations>
1265 ${install4jFileAssociationsText}
1266 </install4jFileAssociations>
1270 println("TEXT=${install4jFileAssociationsText}")
1272 install4jFileAssociationsXml.action.each { a ->
1273 println("ACTION="+XmlUtil.serialize(a))
1277 def install4j = new XmlParser().parse(install4jConfFile)
1279 if (OSX_KEYPASS == "") {
1280 install4j.application.codeSigning.each { codeSigning ->
1281 codeSigning.'@macEnabled' = "false"
1283 install4j.mediaSets.windows.each { windows ->
1284 windows.'@runPostProcessor' = "false"
1288 //install4j = new XmlSlurper().parseText(XmlUtil.serialize(install4j))
1290 install4j.'**'.action.each { a ->
1291 if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1292 //a.replaceNode(install4jFileAssociationsXml.action[0])
1296 //install4j = new XmlSlurper().parseText(XmlUtil.serialize(install4j))
1298 file(install4jConfFile).text = XmlUtil.serialize(install4j)
1301 // include uninstaller applescript app files in dmg
1302 def installerDMGUninstallerXml = file("$install4jDir/$install4j_DMG_uninstaller_app_files").text
1306 match: '<file name="UNINSTALL_OLD_JALVIEW_APP_REPLACED_IN_GRADLE" file=.*?>',
1307 replace: installerDMGUninstallerXml,
1308 file: install4jConfFile
1317 delete install4jConfFile
1322 task installers(type: com.install4j.gradle.Install4jTask) {
1323 group = "distribution"
1324 description = "Create the install4j installers"
1326 dependsOn copyInstall4jTemplate
1327 projectFile = file(install4jConfFile)
1329 def install4jTemplateMd5 = ""
1330 def digest = MessageDigest.getInstance("MD5")
1332 (file("${install4jDir}/${install4j_template}").text +
1333 file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1334 file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1335 def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1336 if (filesMd5.length() >= 8) {
1337 filesMd5 = filesMd5.substring(0,8)
1339 install4jTemplateMd5 += filesMd5
1340 install4jTemplateMd5 += "_${gitHash}"
1341 def install4jTemplateVersion = "${JALVIEW_VERSION}_${install4jTemplateMd5}"
1342 def infoPlistFileAssociations = file("${install4jDir}/${install4j_info_plist_file_associations}").text
1345 'OSX_KEYSTORE': OSX_KEYSTORE,
1346 'JSIGN_SH': JSIGN_SH,
1347 'JALVIEW_VERSION': JALVIEW_VERSION,
1348 'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1349 'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1350 'JAVA_VERSION': JAVA_VERSION,
1351 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1352 'VERSION': JALVIEW_VERSION,
1353 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1354 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1355 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1356 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1357 'INSTALL4JINFOPLISTFILEASSOCIATIONS': install4j_info_plist_file_associations,
1358 'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1359 'COPYRIGHT_MESSAGE': install4j_copyright_message,
1360 'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1361 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1362 'GETDOWN_DIST_DIR': getdown_app_dir,
1363 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1364 'GETDOWN_INSTALL_DIR': getdown_install_dir,
1365 'INFO_PLIST_FILE_ASSOCIATIONS': infoPlistFileAssociations
1367 destination = "${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}"
1368 buildSelected = true
1370 if (install4j_faster.equals("true") || CHANNEL.startsWith("DEVELOP") || CHANNEL.startsWith("LOCAL")) {
1371 // this doesn't seem to work
1373 disableSigning = true
1377 macKeystorePassword=OSX_KEYPASS
1381 println("Using projectFile "+projectFile)
1384 inputs.dir(getdownWebsiteDir)
1385 inputs.file(install4jConfFile)
1386 inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1387 inputs.dir(macosJavaVMDir)
1388 inputs.dir(windowsJavaVMDir)
1389 outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1393 task sourceDist (type: Tar) {
1395 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1396 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1397 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1399 archiveFileName = outputFileName
1400 } catch (Exception e) {
1401 archiveName = outputFileName
1404 compression Compression.GZIP
1408 def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1413 ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1415 ,"utils/InstallAnywhere"]
1416 def PROCESS_FILES=[ "AUTHORS",
1424 "THIRDPARTYLIBS","TESTNG",
1426 "gradle.properties",
1437 exclude (EXCLUDE_FILES)
1438 include (PROCESS_FILES)
1439 filter(ReplaceTokens,
1443 'Version-Rel': JALVIEW_VERSION,
1444 'Year-Rel': getDate("yyyy")
1449 exclude (EXCLUDE_FILES)
1450 exclude (PROCESS_FILES)
1451 exclude ("appletlib")
1452 exclude ("**/*locales")
1453 exclude ("*locales/**")
1454 exclude ("utils/InstallAnywhere")
1456 exclude (getdown_files_dir)
1457 exclude (getdown_website_dir)
1459 // exluding these as not using jars as modules yet
1460 exclude ("${j11modDir}/**/*.jar")
1462 // from (jalviewDir) {
1463 // // explicit includes for stuff that seemed to not get included
1464 // include(fileTree("test/**/*."))
1465 // exclude(EXCLUDE_FILES)
1466 // exclude(PROCESS_FILES)
1473 dependsOn pubhtmlhelp
1475 inputs.dir("${classesDir}/${helpDir}")
1476 outputs.dir("${buildDir}/distributions/${helpDir}")
1479 // LARGE AMOUNT OF JALVIEWJS STUFF DELETED HERE
1480 task eclipseAutoBuildTask {}
1481 task eclipseSynchronizationTask {}