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.4.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.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 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}")
121 // the following values might be overridden by the CHANNEL switch
122 getdownChannelName = CHANNEL.toLowerCase()
123 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
124 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
125 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
126 getdownAppDistDir = getdown_app_dir_alt
127 buildProperties = string("${classesDir}/${build_properties_file}")
128 reportRsyncCmd = false
129 jvlChannelName = CHANNEL.toLowerCase()
133 // TODO: get bamboo build artifact URL for getdown artifacts
134 getdown_channel_base = bamboo_channelbase
135 getdownChannelName = string("${bamboo_planKey}/${JAVA_VERSION}")
136 getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
137 jvlChannelName += "_${getdownChannelName}"
141 getdownAppDistDir = getdown_app_dir_release
142 reportRsyncCommand = true
146 getdownChannelName = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
147 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
148 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
149 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
150 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
152 packageDir = string("${ARCHIVEDIR}/${packageDir}")
153 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
156 reportRsyncCommand = true
160 getdownChannelName = string("archive/${JALVIEW_VERSION}")
161 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
162 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
163 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
164 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
166 packageDir = string("${ARCHIVEDIR}/${packageDir}")
167 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
170 reportRsyncCommand = true
171 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
175 reportRsyncCommand = true
179 reportRsyncCommand = true
182 case ~/^SCRATCH(|-[-\w]*)$/:
183 getdownChannelName = CHANNEL
184 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
185 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
186 reportRsyncCommand = true
190 if (!file("${LOCALDIR}").exists()) {
191 throw new GradleException("Must provide a LOCALDIR value to produce a local distribution")
193 getdownAppBase = file(file("${LOCALDIR}").getAbsolutePath()).toURI().toString()
194 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
199 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
200 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
203 default: // something wrong specified
204 throw new GradleException("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
208 // override getdownAppBase if requested
209 if (findProperty("getdown_appbase_override") != null) {
210 getdownAppBase = string(getProperty("getdown_appbase_override"))
211 println("Overriding getdown appbase with '${getdownAppBase}'")
213 // sanitise file name for jalview launcher file for this channel
214 jvlChannelName = jvlChannelName.replaceAll(/[^\w\-]/,"_")
216 getdownAppDir = string("${getdownWebsiteDir}/${getdownAppDistDir}")
217 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
218 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
219 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
220 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
221 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
222 /* compile without modules -- using classpath libraries
223 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
224 modules_runtimeClasspath = modules_compileClasspath
227 gitBranch = string("")
229 println("Using a ${CHANNEL} profile.")
231 additional_compiler_args = []
232 // configure classpath/args for j8/j11 compilation
233 if (JAVA_VERSION.equals("1.8")) {
234 JAVA_INTEGER_VERSION = string("8")
237 libDistDir = j8libDir
238 compile_source_compatibility = 1.8
239 compile_target_compatibility = 1.8
240 // these are getdown.txt properties defined dependent on the JAVA_VERSION
241 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java8_min_version"))
242 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java8_max_version"))
243 // this property is assigned below and expanded to multiple lines in the getdown task
244 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java8_txt_multi_java_location"))
245 // this property is for the Java library used in eclipse
246 eclipseJavaRuntimeName = string("JavaSE-1.8")
247 } else if (JAVA_VERSION.equals("11")) {
248 JAVA_INTEGER_VERSION = string("11")
250 libDistDir = j11libDir
251 compile_source_compatibility = 11
252 compile_target_compatibility = 11
253 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
254 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
255 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
256 eclipseJavaRuntimeName = string("JavaSE-11")
257 /* compile without modules -- using classpath libraries
258 additional_compiler_args += [
259 '--module-path', modules_compileClasspath.asPath,
260 '--add-modules', j11modules
263 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
264 JAVA_INTEGER_VERSION = JAVA_VERSION
266 libDistDir = j11libDir
267 compile_source_compatibility = JAVA_VERSION
268 compile_target_compatibility = JAVA_VERSION
269 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
270 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
271 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
272 eclipseJavaRuntimeName = string("JavaSE-11")
273 /* compile without modules -- using classpath libraries
274 additional_compiler_args += [
275 '--module-path', modules_compileClasspath.asPath,
276 '--add-modules', j11modules
280 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
285 JAVA_MIN_VERSION = JAVA_VERSION
286 JAVA_MAX_VERSION = JAVA_VERSION
287 def jreInstallsDir = string(jre_installs_dir)
288 if (jreInstallsDir.startsWith("~/")) {
289 jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
291 macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
292 macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-mac-x64.tar.gz")
293 windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
294 windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-windows-x64.tar.gz")
295 linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
296 linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-linux-x64.tar.gz")
297 install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
298 install4jConfFileName = string("jalview-install4j-conf.install4j")
299 install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
300 install4jHomeDir = install4j_home_dir
301 if (install4jHomeDir.startsWith("~/")) {
302 install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
307 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
308 helpFile = string("${classesDir}/${help_dir}/help.jhm")
309 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
310 helpSourceDir = string("${helpParentDir}/${help_dir}")
313 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
314 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
315 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
317 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
319 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
321 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
322 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
323 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
324 jalviewjsJalviewCoreHtmlFile = string("")
325 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
326 jalviewjsCoreClasslists = []
327 jalviewjsJalviewTemplateName = string(jalviewjs_name)
328 jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
329 jalviewjsJ2sProps = null
331 eclipseWorkspace = null
332 eclipseBinary = string("")
333 eclipseVersion = string("")
343 outputDir = file(classesDir)
348 srcDirs += helpParentDir
351 jar.destinationDir = file("${jalviewDir}/${packageDir}")
353 compileClasspath = files(sourceSets.main.java.outputDir)
354 //compileClasspath += files(sourceSets.main.resources.srcDirs)
355 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
357 runtimeClasspath = compileClasspath
362 srcDirs = [ cloverInstrDir ]
363 outputDir = file("${buildDir}/${cloverClassesDir}")
367 srcDirs = sourceSets.main.resources.srcDirs
369 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
370 compileClasspath += files(sourceSets.main.java.outputDir)
371 compileClasspath += sourceSets.main.compileClasspath
372 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
373 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
375 runtimeClasspath = compileClasspath
380 srcDirs testSourceDir
381 outputDir = file("${jalviewDir}/${testOutputDir}")
385 srcDirs = sourceSets.main.resources.srcDirs
388 compileClasspath = files( sourceSets.test.java.outputDir )
391 compileClasspath = sourceSets.clover.compileClasspath
393 compileClasspath += files(sourceSets.main.java.outputDir)
396 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
397 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
398 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
400 runtimeClasspath = compileClasspath
408 cloverCompile 'org.openclover:clover:4.4.1'
409 testCompile 'org.openclover:clover:4.4.1'
416 cloverRuntime.extendsFrom cloverCompile
421 name = eclipse_project_name
423 natures 'org.eclipse.jdt.core.javanature',
424 'org.eclipse.jdt.groovy.core.groovyNature',
425 'org.eclipse.buildship.core.gradleprojectnature'
427 buildCommand 'org.eclipse.jdt.core.javabuilder'
428 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
432 //defaultOutputDir = sourceSets.main.java.outputDir
435 if (it.isCanBeResolved()) {
440 minusConfigurations += removeThese
441 plusConfigurations = [ ]
445 def removeTheseToo = []
446 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
447 cp.entries.each { entry ->
448 // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
449 // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
450 // we add the resources and help/help dirs in as libs afterwards (see below)
451 if (entry.kind == 'src') {
452 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
453 removeTheseToo += entry
455 alreadyAddedSrcPath.putAt(entry.path, true)
460 cp.entries.removeAll(removeTheseToo)
462 //cp.entries += new Output("${eclipse_bin_dir}/main")
463 if (file(helpParentDir).isDirectory()) {
464 cp.entries += new Library(fileReference(helpParentDir))
466 if (file(resourceDir).isDirectory()) {
467 cp.entries += new Library(fileReference(resourceDir))
470 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
472 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
473 //don't want to add outputDir as eclipse is using its own output dir in bin/main
474 if (it.isDirectory() || ! it.exists()) {
475 // don't add dirs to classpath, especially if they don't exist
476 return false // groovy "continue" in .any closure
478 def itPath = it.toString()
479 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
480 // make relative path
481 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
483 if (alreadyAddedLibPath.get(itPath)) {
484 //println("Not adding duplicate entry "+itPath)
486 //println("Adding entry "+itPath)
487 cp.entries += new Library(fileReference(itPath))
488 alreadyAddedLibPath.put(itPath, true)
492 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
493 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
494 if (it.isDirectory() || ! it.exists()) {
495 // don't add dirs to classpath
496 return false // groovy "continue" in .any closure
499 def itPath = it.toString()
500 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
501 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
503 if (alreadyAddedLibPath.get(itPath)) {
506 def lib = new Library(fileReference(itPath))
507 lib.entryAttributes["test"] = "true"
509 alreadyAddedLibPath.put(itPath, true)
517 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
522 // for the IDE, use java 11 compatibility
523 sourceCompatibility = compile_source_compatibility
524 targetCompatibility = compile_target_compatibility
525 javaRuntimeName = eclipseJavaRuntimeName
527 // add in jalview project specific properties/preferences into eclipse core preferences
529 withProperties { props ->
530 def jalview_prefs = new Properties()
531 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
532 jalview_prefs.load(ins)
534 jalview_prefs.forEach { t, v ->
535 if (props.getAt(t) == null) {
545 // Don't want these to be activated if in headless build
546 synchronizationTasks "eclipseSynchronizationTask"
547 autoBuildTasks "eclipseAutoBuildTask"
554 // only instrument source, we build test classes as normal
555 inputs.files files (sourceSets.main.allJava,sourceSets.test.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
556 outputs.dir cloverInstrDir
559 delete cloverInstrDir
560 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
561 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
562 argsList.addAll(inputs.files.files.collect({ file ->
565 String[] args = argsList.toArray()
566 println("About to instrument "+args.length +" files")
567 com.atlassian.clover.CloverInstr.mainImpl(args)
573 group = "Verification"
574 description = "Createst the Clover report"
575 inputs.dir "${buildDir}/clover"
576 outputs.dir "${reportsDir}/clover"
578 file("${buildDir}/clover/clover.db").exists()
581 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
582 "-o", "${reportsDir}/clover"]
583 String[] args = argsList.toArray()
584 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
586 // and generate ${reportsDir}/clover/clover.xml
587 args = ["--initstring", "${buildDir}/clover/clover.db",
588 "-o", "${reportsDir}/clover/clover.xml"].toArray()
589 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
598 sourceCompatibility = compile_source_compatibility
599 targetCompatibility = compile_target_compatibility
600 options.compilerArgs = additional_compiler_args
601 print ("Setting target compatibility to "+targetCompatibility+"\n")
609 dependsOn compileCloverJava
610 classpath += configurations.cloverRuntime
612 classpath += sourceSets.main.runtimeClasspath
615 sourceCompatibility = compile_source_compatibility
616 targetCompatibility = compile_target_compatibility
617 options.compilerArgs = additional_compiler_args
618 print ("Setting target compatibility to "+targetCompatibility+"\n")
626 sourceCompatibility = compile_source_compatibility
627 targetCompatibility = compile_target_compatibility
628 options.compilerArgs += additional_compiler_args
629 print ("Setting target compatibility to "+targetCompatibility+"\n")
631 classpath += configurations.cloverRuntime
637 delete sourceSets.main.java.outputDir
644 delete sourceSets.test.java.outputDir
645 delete cloverInstrDir
650 // format is a string like date.format("dd MMMM yyyy")
651 def getDate(format) {
652 def date = new Date()
653 return date.format(format)
658 def hashStdOut = new ByteArrayOutputStream()
660 commandLine "git", "rev-parse", "--short", "HEAD"
661 standardOutput = hashStdOut
665 def branchStdOut = new ByteArrayOutputStream()
667 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
668 standardOutput = branchStdOut
672 gitHash = hashStdOut.toString().trim()
673 gitBranch = branchStdOut.toString().trim()
675 outputs.upToDateWhen { false }
679 task createBuildProperties(type: WriteProperties) {
681 inputs.dir(sourceDir)
682 inputs.dir(resourceDir)
683 file(buildProperties).getParentFile().mkdirs()
684 outputFile (buildProperties)
685 // taking time specific comment out to allow better incremental builds
686 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
687 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
688 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
689 property "VERSION", JALVIEW_VERSION
690 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
691 outputs.file(outputFile)
695 task cleanBuildingHTML(type: Delete) {
702 task convertBuildingMD(type: Exec) {
703 dependsOn cleanBuildingHTML
704 def buildingMD = "${jalviewDir}/${docDir}/building.md"
705 def css = "${jalviewDir}/${docDir}/github.css"
708 pandoc_exec.split(",").each {
709 if (file(it.trim()).exists()) {
715 def hostname = "hostname".execute().text.trim()
716 def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
717 if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
718 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
722 if (pandoc != null && file(pandoc).exists()) {
723 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
725 println("Cannot find pandoc. Skipping convert building.md to HTML")
726 throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
732 inputs.file(buildingMD)
734 outputs.file(buildingHTML)
745 task syncDocs(type: Sync) {
746 dependsOn convertBuildingMD
747 def syncDir = "${classesDir}/${docDir}"
748 from fileTree("${jalviewDir}/${docDir}")
754 task copyHelp(type: Copy) {
755 def inputDir = helpSourceDir
756 def outputDir = "${classesDir}/${help_dir}"
761 filter(ReplaceTokens,
765 'Version-Rel': JALVIEW_VERSION,
766 'Year-Rel': getDate("yyyy")
778 outputs.files(helpFile)
779 outputs.dir(outputDir)
783 task syncLib(type: Sync) {
784 def syncDir = "${classesDir}/${libDistDir}"
785 from fileTree("${jalviewDir}/${libDistDir}")
790 task syncResources(type: Sync) {
801 dependsOn syncResources
807 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
810 dependsOn compileJava
812 dependsOn cloverInstr
816 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
820 includeGroups testngGroups
822 useDefaultListeners=true
825 workingDir = jalviewDir
826 //systemProperties 'clover.jar' System.properties.clover.jar
827 sourceCompatibility = compile_source_compatibility
828 targetCompatibility = compile_target_compatibility
829 jvmArgs += additional_compiler_args
834 task buildIndices(type: JavaExec) {
836 classpath = sourceSets.main.compileClasspath
837 main = "com.sun.java.help.search.Indexer"
838 workingDir = "${classesDir}/${help_dir}"
841 inputs.dir("${workingDir}/${argDir}")
843 outputs.dir("${classesDir}/doc")
844 outputs.dir("${classesDir}/help")
845 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
846 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
847 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
848 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
849 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
850 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
854 task compileLinkCheck(type: JavaCompile) {
856 classpath = files("${jalviewDir}/${utilsDir}")
857 destinationDir = file("${jalviewDir}/${utilsDir}")
858 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
860 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
861 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
862 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
863 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
867 task linkCheck(type: JavaExec) {
868 dependsOn prepare, compileLinkCheck
870 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
871 classpath = files("${jalviewDir}/${utilsDir}")
872 main = "HelpLinksChecker"
873 workingDir = jalviewDir
874 args = [ "${classesDir}/${help_dir}", "-nointernet" ]
876 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
878 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
881 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
885 inputs.dir("${classesDir}/${help_dir}")
886 outputs.file(helpLinksCheckerOutFile)
889 // import the pubhtmlhelp target
890 ant.properties.basedir = "${jalviewDir}"
891 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
892 ant.importBuild "${utilsDir}/publishHelp.xml"
895 task cleanPackageDir(type: Delete) {
897 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
903 dependsOn buildIndices
904 dependsOn createBuildProperties
907 attributes "Main-Class": mainClass,
908 "Permissions": "all-permissions",
909 "Application-Name": "Jalview Desktop",
910 "Codebase": application_codebase
913 destinationDir = file("${jalviewDir}/${packageDir}")
914 archiveName = rootProject.name+".jar"
922 inputs.dir(classesDir)
923 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
927 task copyJars(type: Copy) {
928 from fileTree(dir: classesDir, include: "**/*.jar").files
929 into "${jalviewDir}/${packageDir}"
933 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
934 task syncJars(type: Sync) {
935 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
936 into "${jalviewDir}/${packageDir}"
938 include jar.archiveName
945 description = "Put all required libraries in dist"
946 // order of "cleanPackageDir", "copyJars", "jar" important!
947 jar.mustRunAfter cleanPackageDir
948 syncJars.mustRunAfter cleanPackageDir
949 dependsOn cleanPackageDir
952 outputs.dir("${jalviewDir}/${packageDir}")
957 dependsOn cleanPackageDir
963 group = "distribution"
967 from ("${jalviewDir}/${libDistDir}") {
971 attributes 'Implementation-Version': JALVIEW_VERSION
973 mainClassName = shadowJarMainClass
975 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
980 task getdownWebsite() {
981 group = "distribution"
982 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
987 def getdownWebsiteResourceFilenames = []
988 def getdownTextString = ""
989 def getdownResourceDir = getdownResourceDir
990 def getdownResourceFilenames = []
993 // clean the getdown website and files dir before creating getdown folders
994 delete getdownWebsiteDir
995 delete getdownFilesDir
999 rename(build_properties_file, getdown_build_properties)
1002 getdownWebsiteResourceFilenames += "${getdownAppDistDir}/${getdown_build_properties}"
1004 // go through properties looking for getdown_txt_...
1005 def props = project.properties.sort { it.key }
1006 if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
1007 props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
1009 if (getdownAltJavaMaxVersion != null && getdownAltJavaMaxVersion.length() > 0) {
1010 props.put("getdown_txt_java_max_version", getdownAltJavaMaxVersion)
1012 if (getdownAltMultiJavaLocation != null && getdownAltMultiJavaLocation.length() > 0) {
1013 props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
1016 props.put("getdown_txt_appbase", getdownAppBase)
1017 props.each{ prop, val ->
1018 if (prop.startsWith("getdown_txt_") && val != null) {
1019 if (prop.startsWith("getdown_txt_multi_")) {
1020 def key = prop.substring(18)
1021 val.split(",").each{ v ->
1022 def line = "${key} = ${v}\n"
1023 getdownTextString += line
1026 // file values rationalised
1027 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1029 if (val.indexOf('/') == 0) {
1032 } else if (val.indexOf('/') > 0) {
1033 // relative path (relative to jalviewDir)
1034 r = file( "${jalviewDir}/${val}" )
1037 val = "${getdown_resource_dir}/" + r.getName()
1038 getdownWebsiteResourceFilenames += val
1039 getdownResourceFilenames += r.getPath()
1042 if (! prop.startsWith("getdown_txt_resource")) {
1043 def line = prop.substring(12) + " = ${val}\n"
1044 getdownTextString += line
1050 getdownWebsiteResourceFilenames.each{ filename ->
1051 getdownTextString += "resource = ${filename}\n"
1053 getdownResourceFilenames.each{ filename ->
1056 into getdownResourceDir
1061 fileTree(file(packageDir)).each{ f ->
1062 if (f.isDirectory()) {
1063 def files = fileTree(dir: f, include: ["*"]).getFiles()
1065 } else if (f.exists()) {
1069 codeFiles.sort().each{f ->
1070 def name = f.getName()
1071 def line = "code = ${getdownAppDistDir}/${name}\n"
1072 getdownTextString += line
1079 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1081 if (JAVA_VERSION.equals("11")) {
1082 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1083 j11libFiles.sort().each{f ->
1084 def name = f.getName()
1085 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1086 getdownTextString += line
1089 into getdownJ11libDir
1095 // 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.
1096 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1097 getdownTextString += "resource = ${getdown_launcher_new}\n"
1098 getdownTextString += "class = ${mainClass}\n"
1100 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1101 getdown_txt.write(getdownTextString)
1103 def getdownLaunchJvl = getdown_launch_jvl_name + ( (jvlChannelName != null && jvlChannelName.length() > 0)?"-${jvlChannelName}":"" ) + ".jvl"
1104 def launchJvl = file("${getdownWebsiteDir}/${getdownLaunchJvl}")
1105 launchJvl.write("appbase="+props.get("getdown_txt_appbase"))
1108 from getdownLauncher
1109 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1110 into getdownWebsiteDir
1114 from getdownLauncher
1115 if (file(getdownLauncher).getName() != getdown_launcher) {
1116 rename(file(getdownLauncher).getName(), getdown_launcher)
1118 into getdownWebsiteDir
1121 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1124 from getdownLauncher
1125 from "${getdownWebsiteDir}/${getdown_build_properties}"
1126 if (file(getdownLauncher).getName() != getdown_launcher) {
1127 rename(file(getdownLauncher).getName(), getdown_launcher)
1129 into getdownInstallDir
1133 from getdownInstallDir
1134 into getdownFilesInstallDir
1141 from getdownLauncher
1142 from "${getdownWebsiteDir}/${getdown_build_properties}"
1143 if (file(getdownLauncher).getName() != getdown_launcher) {
1144 rename(file(getdownLauncher).getName(), getdown_launcher)
1146 into getdownFilesDir
1150 from getdownResourceDir
1151 into "${getdownFilesDir}/${getdown_resource_dir}"
1156 inputs.dir("${jalviewDir}/${packageDir}")
1158 outputs.dir(getdownWebsiteDir)
1159 outputs.dir(getdownFilesDir)
1163 // a helper task to allow getdown digest of any dir: `gradle getdownDigestDir -PDIGESTDIR=/path/to/my/random/getdown/dir
1164 task getdownDigestDir(type: JavaExec) {
1165 def digestDirPropertyName = "DIGESTDIR"
1166 description = "Digest a local dir (-P${digestDirPropertyName}=...) for getdown"
1168 classpath = files(getdownLauncher)
1169 def digestDir = findProperty(digestDirPropertyName)
1170 if (digestDir == null) {
1171 throw new GradleException("Must provide a DIGESTDIR value to produce an alternative getdown digest")
1175 main = "com.threerings.getdown.tools.Digester"
1179 task getdownDigest(type: JavaExec) {
1180 group = "distribution"
1181 description = "Digest the getdown website folder"
1182 dependsOn getdownWebsite
1184 classpath = files(getdownLauncher)
1186 main = "com.threerings.getdown.tools.Digester"
1187 args getdownWebsiteDir
1188 inputs.dir(getdownWebsiteDir)
1189 outputs.file("${getdownWebsiteDir}/digest2.txt")
1194 group = "distribution"
1195 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1196 dependsOn getdownDigest
1198 if (reportRsyncCommand) {
1199 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1200 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1201 println "LIKELY RSYNC COMMAND:"
1202 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1203 if (RUNRSYNC == "true") {
1205 commandLine "mkdir", "-p", toDir
1208 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1218 delete getdownWebsiteDir
1219 delete getdownFilesDir
1225 if (file(install4jHomeDir).exists()) {
1227 } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1228 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1229 } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1230 install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1232 installDir(file(install4jHomeDir))
1234 mediaTypes = Arrays.asList(install4j_media_types.split(","))
1238 task copyInstall4jTemplate {
1239 def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
1240 def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1241 inputs.file(install4jTemplateFile)
1242 inputs.file(install4jFileAssociationsFile)
1243 outputs.file(install4jConfFile)
1246 def install4jConfigXml = new XmlParser().parse(install4jTemplateFile)
1248 // turn off code signing if no OSX_KEYPASS
1249 if (OSX_KEYPASS == "") {
1250 install4jConfigXml.'**'.codeSigning.each { codeSigning ->
1251 codeSigning.'@macEnabled' = "false"
1253 install4jConfigXml.'**'.windows.each { windows ->
1254 windows.'@runPostProcessor' = "false"
1258 // turn off checksum creation for LOCAL channel
1259 def e = install4jConfigXml.application[0]
1260 if (CHANNEL == "LOCAL") {
1261 e.'@createChecksums' = "false"
1263 e.'@createChecksums' = "true"
1266 // put file association actions where placeholder action is
1267 def install4jFileAssociationsText = install4jFileAssociationsFile.text
1268 def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
1269 install4jConfigXml.'**'.action.any { a ->
1270 if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1271 def parent = a.parent()
1273 fileAssociationActions.each { faa ->
1276 // don't need to continue in .any loop once replacements have been made
1281 // write install4j file
1282 install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
1289 delete install4jConfFile
1294 task installers(type: com.install4j.gradle.Install4jTask) {
1295 group = "distribution"
1296 description = "Create the install4j installers"
1297 dependsOn setGitVals
1299 dependsOn copyInstall4jTemplate
1301 projectFile = install4jConfFile
1303 // create an md5 for the input files to use as version for install4j conf file
1304 def digest = MessageDigest.getInstance("MD5")
1306 (file("${install4jDir}/${install4j_template}").text +
1307 file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1308 file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1309 def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1310 if (filesMd5.length() >= 8) {
1311 filesMd5 = filesMd5.substring(0,8)
1313 def install4jTemplateVersion = "${JALVIEW_VERSION}_F${filesMd5}_C${gitHash}"
1314 // make install4jBuildDir relative to jalviewDir
1315 def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
1318 'JALVIEW_NAME': getdown_txt_title,
1319 'JALVIEW_DIR': "../..",
1320 'OSX_KEYSTORE': OSX_KEYSTORE,
1321 'JSIGN_SH': JSIGN_SH,
1322 'JRE_DIR': getdown_app_dir_java,
1323 'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1324 'JALVIEW_VERSION': JALVIEW_VERSION,
1325 'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1326 'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1327 'JAVA_VERSION': JAVA_VERSION,
1328 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1329 'VERSION': JALVIEW_VERSION,
1330 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1331 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1332 'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
1333 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1334 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1335 'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
1336 'COPYRIGHT_MESSAGE': install4j_copyright_message,
1337 'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1338 'INSTALLER_NAME': install4j_installer_name,
1339 'INSTALL4J_UTILS_DIR': install4j_utils_dir,
1340 'GETDOWN_WEBSITE_DIR': getdown_website_dir,
1341 'GETDOWN_FILES_DIR': getdown_files_dir,
1342 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1343 'GETDOWN_DIST_DIR': getdownAppDistDir,
1344 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1345 'GETDOWN_INSTALL_DIR': getdown_install_dir,
1346 'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
1347 'BUILD_DIR': install4jBuildDir,
1350 destination = "${jalviewDir}/${install4jBuildDir}"
1351 buildSelected = true
1353 if (install4j_faster.equals("true") || CHANNEL.startsWith("LOCAL")) {
1355 disableSigning = true
1359 macKeystorePassword = OSX_KEYPASS
1363 println("Using projectFile "+projectFile)
1366 inputs.dir(getdownWebsiteDir)
1367 inputs.file(install4jConfFile)
1368 inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1369 inputs.dir(macosJavaVMDir)
1370 inputs.dir(windowsJavaVMDir)
1371 outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1375 task sourceDist(type: Tar) {
1377 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1378 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1379 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1381 archiveFileName = outputFileName
1382 } catch (Exception e) {
1383 archiveName = outputFileName
1386 compression Compression.GZIP
1390 def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1395 ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1397 ,"utils/InstallAnywhere"]
1398 def PROCESS_FILES=[ "AUTHORS",
1406 "THIRDPARTYLIBS","TESTNG",
1408 "gradle.properties",
1419 exclude (EXCLUDE_FILES)
1420 include (PROCESS_FILES)
1421 filter(ReplaceTokens,
1425 'Version-Rel': JALVIEW_VERSION,
1426 'Year-Rel': getDate("yyyy")
1431 exclude (EXCLUDE_FILES)
1432 exclude (PROCESS_FILES)
1433 exclude ("appletlib")
1434 exclude ("**/*locales")
1435 exclude ("*locales/**")
1436 exclude ("utils/InstallAnywhere")
1438 exclude (getdown_files_dir)
1439 exclude (getdown_website_dir)
1441 // exluding these as not using jars as modules yet
1442 exclude ("${j11modDir}/**/*.jar")
1444 // from (jalviewDir) {
1445 // // explicit includes for stuff that seemed to not get included
1446 // include(fileTree("test/**/*."))
1447 // exclude(EXCLUDE_FILES)
1448 // exclude(PROCESS_FILES)
1455 dependsOn pubhtmlhelp
1457 inputs.dir("${classesDir}/${help_dir}")
1458 outputs.dir("${buildDir}/distributions/${help_dir}")
1461 // LARGE AMOUNT OF JALVIEWJS STUFF DELETED HERE
1462 task eclipseAutoBuildTask {}
1463 task eclipseSynchronizationTask {}