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.5' // 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}")
122 // the following values might be overridden by the CHANNEL switch
123 getdown_channel_name = CHANNEL.toLowerCase()
124 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
125 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
126 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
127 getdownAppDir = getdown_app_dir_alt
128 buildProperties = string("${classesDir}/${build_properties_file}")
129 reportRsyncCmd = false
133 // TODO: get bamboo build artifact URL for getdown artifacts
134 getdown_channel_base = bamboo_channelbase
135 getdown_channel_name = string("${bamboo_planKey}/${JAVA_VERSION}")
136 getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
140 getdownAppDir = getdown_app_dir_release
141 reportRsyncCommand = true
145 getdown_channel_name = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
146 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
147 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
148 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
149 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
151 packageDir = string("${ARCHIVEDIR}/${packageDir}")
152 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
155 reportRsyncCommand = true
159 getdown_channel_name = string("archive/${JALVIEW_VERSION}")
160 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
161 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
162 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
163 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
165 packageDir = string("${ARCHIVEDIR}/${packageDir}")
166 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
169 reportRsyncCommand = true
170 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
174 reportRsyncCommand = true
178 reportRsyncCommand = true
181 case ~/^SCRATCH(|-[-\w]*)$/:
182 getdown_channel_name = CHANNEL
183 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
184 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
185 reportRsyncCommand = true
189 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
190 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
193 default: // something wrong specified
194 throw new GradleException("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
198 // override getdownAppBase if requested
199 if (findProperty("getdown_appbase_override") != null) {
200 getdownAppBase = string(getProperty("getdown_appbase_override"))
201 println("Overriding getdown appbase with '${getdownAppBase}'")
204 getdownAppDir = string("${getdownWebsiteDir}/${getdownAppDir}")
205 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
206 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
207 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
208 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
209 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
210 /* compile without modules -- using classpath libraries
211 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
212 modules_runtimeClasspath = modules_compileClasspath
215 gitBranch = string("")
217 println("Using a ${CHANNEL} profile.")
219 additional_compiler_args = []
220 // configure classpath/args for j8/j11 compilation
221 if (JAVA_VERSION.equals("1.8")) {
222 JAVA_INTEGER_VERSION = string("8")
225 libDistDir = j8libDir
226 compile_source_compatibility = 1.8
227 compile_target_compatibility = 1.8
228 // these are getdown.txt properties defined dependent on the JAVA_VERSION
229 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java8_min_version"))
230 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java8_max_version"))
231 // this property is assigned below and expanded to multiple lines in the getdown task
232 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java8_txt_multi_java_location"))
233 // this property is for the Java library used in eclipse
234 eclipseJavaRuntimeName = string("JavaSE-1.8")
235 } else if (JAVA_VERSION.equals("11")) {
236 JAVA_INTEGER_VERSION = string("11")
238 libDistDir = j11libDir
239 compile_source_compatibility = 11
240 compile_target_compatibility = 11
241 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
242 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
243 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
244 eclipseJavaRuntimeName = string("JavaSE-11")
245 /* compile without modules -- using classpath libraries
246 additional_compiler_args += [
247 '--module-path', modules_compileClasspath.asPath,
248 '--add-modules', j11modules
251 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
252 JAVA_INTEGER_VERSION = JAVA_VERSION
254 libDistDir = j11libDir
255 compile_source_compatibility = JAVA_VERSION
256 compile_target_compatibility = JAVA_VERSION
257 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
258 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
259 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
260 eclipseJavaRuntimeName = string("JavaSE-11")
261 /* compile without modules -- using classpath libraries
262 additional_compiler_args += [
263 '--module-path', modules_compileClasspath.asPath,
264 '--add-modules', j11modules
268 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
273 JAVA_MIN_VERSION = JAVA_VERSION
274 JAVA_MAX_VERSION = JAVA_VERSION
275 def jreInstallsDir = string(jre_installs_dir)
276 if (jreInstallsDir.startsWith("~/")) {
277 jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
279 macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
280 macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-mac-x64.tar.gz")
281 windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
282 windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-windows-x64.tar.gz")
283 linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
284 linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-linux-x64.tar.gz")
285 install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
286 install4jConfFileName = string("jalview-install4j-conf.install4j")
287 install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
288 install4jHomeDir = install4j_home_dir
289 if (install4jHomeDir.startsWith("~/")) {
290 install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
295 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
296 helpFile = string("${classesDir}/${help_dir}/help.jhm")
297 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
298 helpSourceDir = string("${helpParentDir}/${help_dir}")
301 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
302 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
303 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
305 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
307 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
309 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
310 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
311 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
312 jalviewjsJalviewCoreHtmlFile = string("")
313 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
314 jalviewjsCoreClasslists = []
315 jalviewjsJalviewTemplateName = string(jalviewjs_name)
316 jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
317 jalviewjsJ2sProps = null
319 eclipseWorkspace = null
320 eclipseBinary = string("")
321 eclipseVersion = string("")
331 outputDir = file(classesDir)
336 srcDirs += helpParentDir
339 jar.destinationDir = file("${jalviewDir}/${packageDir}")
341 compileClasspath = files(sourceSets.main.java.outputDir)
342 //compileClasspath += files(sourceSets.main.resources.srcDirs)
343 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
345 runtimeClasspath = compileClasspath
350 srcDirs = [ cloverInstrDir ]
351 outputDir = file("${buildDir}/${cloverClassesDir}")
355 srcDirs = sourceSets.main.resources.srcDirs
357 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
358 compileClasspath += files(sourceSets.main.java.outputDir)
359 compileClasspath += sourceSets.main.compileClasspath
360 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
361 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
363 runtimeClasspath = compileClasspath
368 srcDirs testSourceDir
369 outputDir = file("${jalviewDir}/${testOutputDir}")
373 srcDirs = sourceSets.main.resources.srcDirs
376 compileClasspath = files( sourceSets.test.java.outputDir )
379 compileClasspath += sourceSets.clover.compileClasspath
381 compileClasspath += files(sourceSets.main.java.outputDir)
384 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
385 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
386 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
388 runtimeClasspath = compileClasspath
396 cloverCompile 'org.openclover:clover:4.3.1'
397 testCompile 'org.openclover:clover:4.3.1'
404 cloverRuntime.extendsFrom cloverCompile
409 name = eclipse_project_name
411 natures 'org.eclipse.jdt.core.javanature',
412 'org.eclipse.jdt.groovy.core.groovyNature',
413 'org.eclipse.buildship.core.gradleprojectnature'
415 buildCommand 'org.eclipse.jdt.core.javabuilder'
416 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
420 //defaultOutputDir = sourceSets.main.java.outputDir
423 if (it.isCanBeResolved()) {
428 minusConfigurations += removeThese
429 plusConfigurations = [ ]
433 def removeTheseToo = []
434 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
435 cp.entries.each { entry ->
436 // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
437 // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
438 // we add the resources and help/help dirs in as libs afterwards (see below)
439 if (entry.kind == 'src') {
440 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
441 removeTheseToo += entry
443 alreadyAddedSrcPath.putAt(entry.path, true)
448 cp.entries.removeAll(removeTheseToo)
450 //cp.entries += new Output("${eclipse_bin_dir}/main")
451 if (file(helpParentDir).isDirectory()) {
452 cp.entries += new Library(fileReference(helpParentDir))
454 if (file(resourceDir).isDirectory()) {
455 cp.entries += new Library(fileReference(resourceDir))
458 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
460 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
461 //don't want to add outputDir as eclipse is using its own output dir in bin/main
462 if (it.isDirectory() || ! it.exists()) {
463 // don't add dirs to classpath, especially if they don't exist
464 return false // groovy "continue" in .any closure
466 def itPath = it.toString()
467 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
468 // make relative path
469 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
471 if (alreadyAddedLibPath.get(itPath)) {
472 //println("Not adding duplicate entry "+itPath)
474 //println("Adding entry "+itPath)
475 cp.entries += new Library(fileReference(itPath))
476 alreadyAddedLibPath.put(itPath, true)
480 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
481 //no longer 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
484 return false // groovy "continue" in .any closure
487 def itPath = it.toString()
488 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
489 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
491 if (alreadyAddedLibPath.get(itPath)) {
494 def lib = new Library(fileReference(itPath))
495 lib.entryAttributes["test"] = "true"
497 alreadyAddedLibPath.put(itPath, true)
505 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
510 // for the IDE, use java 11 compatibility
511 sourceCompatibility = compile_source_compatibility
512 targetCompatibility = compile_target_compatibility
513 javaRuntimeName = eclipseJavaRuntimeName
515 // add in jalview project specific properties/preferences into eclipse core preferences
517 withProperties { props ->
518 def jalview_prefs = new Properties()
519 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
520 jalview_prefs.load(ins)
522 jalview_prefs.forEach { t, v ->
523 if (props.getAt(t) == null) {
533 // Don't want these to be activated if in headless build
534 synchronizationTasks "eclipseSynchronizationTask"
535 autoBuildTasks "eclipseAutoBuildTask"
542 // only instrument source, we build test classes as normal
543 inputs.files files (sourceSets.main.allJava) // , fileTree(dir: testSourceDir, include: ["**/*.java"]))
544 outputs.dir cloverInstrDir
547 delete cloverInstrDir
548 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
549 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
550 argsList.addAll(inputs.files.files.collect({ file ->
553 String[] args = argsList.toArray()
554 println("About to instrument "+args.length +" files")
555 com.atlassian.clover.CloverInstr.mainImpl(args)
561 group = "Verification"
562 description = "Createst the Clover report"
563 inputs.dir "${buildDir}/clover"
564 outputs.dir "${reportsDir}/clover"
566 file("${buildDir}/clover/clover.db").exists()
569 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
570 "-o", "${reportsDir}/clover"]
571 String[] args = argsList.toArray()
572 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
574 // and generate ${reportsDir}/clover/clover.xml
575 args = ["--initstring", "${buildDir}/clover/clover.db",
576 "-o", "${reportsDir}/clover/clover.xml"].toArray()
577 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
586 sourceCompatibility = compile_source_compatibility
587 targetCompatibility = compile_target_compatibility
588 options.compilerArgs = additional_compiler_args
589 print ("Setting target compatibility to "+targetCompatibility+"\n")
597 dependsOn compileCloverJava
598 classpath += configurations.cloverRuntime
600 classpath += sourceSets.main.runtimeClasspath
603 sourceCompatibility = compile_source_compatibility
604 targetCompatibility = compile_target_compatibility
605 options.compilerArgs = additional_compiler_args
606 print ("Setting target compatibility to "+targetCompatibility+"\n")
614 sourceCompatibility = compile_source_compatibility
615 targetCompatibility = compile_target_compatibility
616 options.compilerArgs += additional_compiler_args
617 print ("Setting target compatibility to "+targetCompatibility+"\n")
619 classpath += configurations.cloverRuntime
625 delete sourceSets.main.java.outputDir
632 delete sourceSets.test.java.outputDir
633 delete cloverInstrDir
638 // format is a string like date.format("dd MMMM yyyy")
639 def getDate(format) {
640 def date = new Date()
641 return date.format(format)
646 def hashStdOut = new ByteArrayOutputStream()
648 commandLine "git", "rev-parse", "--short", "HEAD"
649 standardOutput = hashStdOut
653 def branchStdOut = new ByteArrayOutputStream()
655 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
656 standardOutput = branchStdOut
660 gitHash = hashStdOut.toString().trim()
661 gitBranch = branchStdOut.toString().trim()
663 outputs.upToDateWhen { false }
667 task createBuildProperties(type: WriteProperties) {
669 inputs.dir(sourceDir)
670 inputs.dir(resourceDir)
671 file(buildProperties).getParentFile().mkdirs()
672 outputFile (buildProperties)
673 // taking time specific comment out to allow better incremental builds
674 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
675 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
676 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
677 property "VERSION", JALVIEW_VERSION
678 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
679 outputs.file(outputFile)
683 task cleanBuildingHTML(type: Delete) {
690 task convertBuildingMD(type: Exec) {
691 dependsOn cleanBuildingHTML
692 def buildingMD = "${jalviewDir}/${docDir}/building.md"
693 def css = "${jalviewDir}/${docDir}/github.css"
696 pandoc_exec.split(",").each {
697 if (file(it.trim()).exists()) {
703 def hostname = "hostname".execute().text.trim()
704 def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
705 if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
706 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
710 if (pandoc != null && file(pandoc).exists()) {
711 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
713 println("Cannot find pandoc. Skipping convert building.md to HTML")
714 throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
720 inputs.file(buildingMD)
722 outputs.file(buildingHTML)
733 task syncDocs(type: Sync) {
734 dependsOn convertBuildingMD
735 def syncDir = "${classesDir}/${docDir}"
736 from fileTree("${jalviewDir}/${docDir}")
742 task copyHelp(type: Copy) {
743 def inputDir = helpSourceDir
744 def outputDir = "${classesDir}/${help_dir}"
749 filter(ReplaceTokens,
753 'Version-Rel': JALVIEW_VERSION,
754 'Year-Rel': getDate("yyyy")
766 outputs.files(helpFile)
767 outputs.dir(outputDir)
771 task syncLib(type: Sync) {
772 def syncDir = "${classesDir}/${libDistDir}"
773 from fileTree("${jalviewDir}/${libDistDir}")
778 task syncResources(type: Sync) {
789 dependsOn syncResources
795 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
798 dependsOn compileJava
800 dependsOn cloverInstr
804 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
808 includeGroups testngGroups
810 useDefaultListeners=true
813 workingDir = jalviewDir
814 //systemProperties 'clover.jar' System.properties.clover.jar
815 sourceCompatibility = compile_source_compatibility
816 targetCompatibility = compile_target_compatibility
817 jvmArgs += additional_compiler_args
822 task buildIndices(type: JavaExec) {
824 classpath = sourceSets.main.compileClasspath
825 main = "com.sun.java.help.search.Indexer"
826 workingDir = "${classesDir}/${help_dir}"
829 inputs.dir("${workingDir}/${argDir}")
831 outputs.dir("${classesDir}/doc")
832 outputs.dir("${classesDir}/help")
833 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
834 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
835 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
836 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
837 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
838 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
842 task compileLinkCheck(type: JavaCompile) {
844 classpath = files("${jalviewDir}/${utilsDir}")
845 destinationDir = file("${jalviewDir}/${utilsDir}")
846 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
848 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
849 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
850 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
851 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
855 task linkCheck(type: JavaExec) {
856 dependsOn prepare, compileLinkCheck
858 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
859 classpath = files("${jalviewDir}/${utilsDir}")
860 main = "HelpLinksChecker"
861 workingDir = jalviewDir
862 args = [ "${classesDir}/${help_dir}", "-nointernet" ]
864 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
866 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
869 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
873 inputs.dir("${classesDir}/${help_dir}")
874 outputs.file(helpLinksCheckerOutFile)
877 // import the pubhtmlhelp target
878 ant.properties.basedir = "${jalviewDir}"
879 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
880 ant.importBuild "${utilsDir}/publishHelp.xml"
883 task cleanPackageDir(type: Delete) {
885 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
891 dependsOn buildIndices
892 dependsOn createBuildProperties
895 attributes "Main-Class": mainClass,
896 "Permissions": "all-permissions",
897 "Application-Name": "Jalview Desktop",
898 "Codebase": application_codebase
901 destinationDir = file("${jalviewDir}/${packageDir}")
902 archiveName = rootProject.name+".jar"
910 inputs.dir(classesDir)
911 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
915 task copyJars(type: Copy) {
916 from fileTree(dir: classesDir, include: "**/*.jar").files
917 into "${jalviewDir}/${packageDir}"
921 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
922 task syncJars(type: Sync) {
923 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
924 into "${jalviewDir}/${packageDir}"
926 include jar.archiveName
933 description = "Put all required libraries in dist"
934 // order of "cleanPackageDir", "copyJars", "jar" important!
935 jar.mustRunAfter cleanPackageDir
936 syncJars.mustRunAfter cleanPackageDir
937 dependsOn cleanPackageDir
940 outputs.dir("${jalviewDir}/${packageDir}")
945 dependsOn cleanPackageDir
951 group = "distribution"
955 from ("${jalviewDir}/${libDistDir}") {
959 attributes 'Implementation-Version': JALVIEW_VERSION
961 mainClassName = shadowJarMainClass
963 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
968 task getdownWebsite() {
969 group = "distribution"
970 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
975 def getdownWebsiteResourceFilenames = []
976 def getdownTextString = ""
977 def getdownResourceDir = getdownResourceDir
978 def getdownAppDir = getdownAppDir
979 def getdownResourceFilenames = []
982 // clean the getdown website and files dir before creating getdown folders
983 delete getdownWebsiteDir
984 delete getdownFilesDir
988 rename(build_properties_file, getdown_build_properties)
991 getdownWebsiteResourceFilenames += "${getdownAppDir}/${getdown_build_properties}"
993 // go through properties looking for getdown_txt_...
994 def props = project.properties.sort { it.key }
995 if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
996 props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
998 if (getdownAltJavaMaxVersion != null && getdownAltJavaMaxVersion.length() > 0) {
999 props.put("getdown_txt_java_max_version", getdownAltJavaMaxVersion)
1001 if (getdownAltMultiJavaLocation != null && getdownAltMultiJavaLocation.length() > 0) {
1002 props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
1005 props.put("getdown_txt_appbase", getdownAppBase)
1006 props.each{ prop, val ->
1007 if (prop.startsWith("getdown_txt_") && val != null) {
1008 if (prop.startsWith("getdown_txt_multi_")) {
1009 def key = prop.substring(18)
1010 val.split(",").each{ v ->
1011 def line = "${key} = ${v}\n"
1012 getdownTextString += line
1015 // file values rationalised
1016 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1018 if (val.indexOf('/') == 0) {
1021 } else if (val.indexOf('/') > 0) {
1022 // relative path (relative to jalviewDir)
1023 r = file( "${jalviewDir}/${val}" )
1026 val = "${getdown_resource_dir}/" + r.getName()
1027 getdownWebsiteResourceFilenames += val
1028 getdownResourceFilenames += r.getPath()
1031 if (! prop.startsWith("getdown_txt_resource")) {
1032 def line = prop.substring(12) + " = ${val}\n"
1033 getdownTextString += line
1039 getdownWebsiteResourceFilenames.each{ filename ->
1040 getdownTextString += "resource = ${filename}\n"
1042 getdownResourceFilenames.each{ filename ->
1045 into getdownResourceDir
1050 fileTree(file(packageDir)).each{ f ->
1051 if (f.isDirectory()) {
1052 def files = fileTree(dir: f, include: ["*"]).getFiles()
1054 } else if (f.exists()) {
1058 codeFiles.sort().each{f ->
1059 def name = f.getName()
1060 def line = "code = ${getdownAppDir}/${name}\n"
1061 getdownTextString += line
1068 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1070 if (JAVA_VERSION.equals("11")) {
1071 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1072 j11libFiles.sort().each{f ->
1073 def name = f.getName()
1074 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1075 getdownTextString += line
1078 into getdownJ11libDir
1084 // 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.
1085 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1086 getdownTextString += "resource = ${getdown_launcher_new}\n"
1087 getdownTextString += "class = ${mainClass}\n"
1089 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1090 getdown_txt.write(getdownTextString)
1092 def launch_jvl = file("${getdownWebsiteDir}/${getdown_launch_jvl}")
1093 launch_jvl.write("appbase="+props.get("getdown_txt_appbase"))
1096 from getdownLauncher
1097 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1098 into getdownWebsiteDir
1102 from getdownLauncher
1103 if (file(getdownLauncher).getName() != getdown_launcher) {
1104 rename(file(getdownLauncher).getName(), getdown_launcher)
1106 into getdownWebsiteDir
1109 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1112 from getdownLauncher
1113 from "${getdownWebsiteDir}/${getdown_build_properties}"
1114 if (file(getdownLauncher).getName() != getdown_launcher) {
1115 rename(file(getdownLauncher).getName(), getdown_launcher)
1117 into getdownInstallDir
1121 from getdownInstallDir
1122 into getdownFilesInstallDir
1129 from getdownLauncher
1130 from "${getdownWebsiteDir}/${getdown_build_properties}"
1131 if (file(getdownLauncher).getName() != getdown_launcher) {
1132 rename(file(getdownLauncher).getName(), getdown_launcher)
1134 into getdownFilesDir
1138 from getdownResourceDir
1139 into "${getdownFilesDir}/${getdown_resource_dir}"
1144 inputs.dir("${jalviewDir}/${packageDir}")
1146 outputs.dir(getdownWebsiteDir)
1147 outputs.dir(getdownFilesDir)
1151 task getdownDigest(type: JavaExec) {
1152 group = "distribution"
1153 description = "Digest the getdown website folder"
1154 dependsOn getdownWebsite
1156 classpath = files("${getdownWebsiteDir}/${getdown_launcher}")
1158 main = "com.threerings.getdown.tools.Digester"
1159 args getdownWebsiteDir
1160 inputs.dir(getdownWebsiteDir)
1161 outputs.file("${getdownWebsiteDir}/digest2.txt")
1166 group = "distribution"
1167 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1168 dependsOn getdownDigest
1170 if (reportRsyncCommand) {
1171 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1172 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1173 println "LIKELY RSYNC COMMAND:"
1174 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1175 if (RUNRSYNC == "true") {
1177 commandLine "mkdir", "-p", toDir
1180 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1190 delete getdownWebsiteDir
1191 delete getdownFilesDir
1197 if (file(install4jHomeDir).exists()) {
1199 } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1200 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1201 } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1202 install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1204 installDir(file(install4jHomeDir))
1206 mediaTypes = Arrays.asList(install4j_media_types.split(","))
1210 task copyInstall4jTemplate {
1211 def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
1212 def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1213 inputs.file(install4jTemplateFile)
1214 inputs.file(install4jFileAssociationsFile)
1215 outputs.file(install4jConfFile)
1218 def install4jConfigXml = new XmlParser().parse(install4jTemplateFile)
1220 // turn off code signing if no OSX_KEYPASS
1221 if (OSX_KEYPASS == "") {
1222 install4jConfigXml.'**'.codeSigning.each { codeSigning ->
1223 codeSigning.'@macEnabled' = "false"
1225 install4jConfigXml.'**'.windows.each { windows ->
1226 windows.'@runPostProcessor' = "false"
1230 // put file association actions where placeholder action is
1231 def install4jFileAssociationsText = install4jFileAssociationsFile.text
1232 def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
1233 install4jConfigXml.'**'.action.any { a ->
1234 if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1235 def parent = a.parent()
1237 fileAssociationActions.each { faa ->
1240 // don't need to continue in .any loop once replacements have been made
1245 // write install4j file
1246 install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
1253 delete install4jConfFile
1258 task installers(type: com.install4j.gradle.Install4jTask) {
1259 group = "distribution"
1260 description = "Create the install4j installers"
1261 dependsOn setGitVals
1263 dependsOn copyInstall4jTemplate
1265 projectFile = install4jConfFile
1267 // create an md5 for the input files to use as version for install4j conf file
1268 def digest = MessageDigest.getInstance("MD5")
1270 (file("${install4jDir}/${install4j_template}").text +
1271 file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1272 file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1273 def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1274 if (filesMd5.length() >= 8) {
1275 filesMd5 = filesMd5.substring(0,8)
1277 def install4jTemplateVersion = "${JALVIEW_VERSION}_F${filesMd5}_C${gitHash}"
1278 // make install4jBuildDir relative to jalviewDir
1279 def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
1282 'JALVIEW_DIR': "../..",
1283 'OSX_KEYSTORE': OSX_KEYSTORE,
1284 'JSIGN_SH': JSIGN_SH,
1285 'JRE_DIR': getdown_app_dir_java,
1286 'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1287 'JALVIEW_VERSION': JALVIEW_VERSION,
1288 'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1289 'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1290 'JAVA_VERSION': JAVA_VERSION,
1291 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1292 'VERSION': JALVIEW_VERSION,
1293 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1294 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1295 'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
1296 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1297 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1298 'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
1299 'COPYRIGHT_MESSAGE': install4j_copyright_message,
1300 'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1301 'INSTALL4J_UTILS_DIR': install4j_utils_dir,
1302 'GETDOWN_WEBSITE_DIR': getdown_website_dir,
1303 'GETDOWN_FILES_DIR': getdown_files_dir,
1304 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1305 'GETDOWN_DIST_DIR': getdownAppDir,
1306 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1307 'GETDOWN_INSTALL_DIR': getdown_install_dir,
1308 'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
1309 'BUILD_DIR': install4jBuildDir,
1312 destination = "${jalviewDir}/${install4jBuildDir}"
1313 buildSelected = true
1315 if (install4j_faster.equals("true") || CHANNEL.startsWith("DEVELOP") || CHANNEL.startsWith("LOCAL")) {
1316 // this doesn't seem to work
1318 disableSigning = true
1322 macKeystorePassword = OSX_KEYPASS
1326 println("Using projectFile "+projectFile)
1329 inputs.dir(getdownWebsiteDir)
1330 inputs.file(install4jConfFile)
1331 inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1332 inputs.dir(macosJavaVMDir)
1333 inputs.dir(windowsJavaVMDir)
1334 outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1338 task sourceDist(type: Tar) {
1340 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1341 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1342 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1344 archiveFileName = outputFileName
1345 } catch (Exception e) {
1346 archiveName = outputFileName
1349 compression Compression.GZIP
1353 def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1358 ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1360 ,"utils/InstallAnywhere"]
1361 def PROCESS_FILES=[ "AUTHORS",
1369 "THIRDPARTYLIBS","TESTNG",
1371 "gradle.properties",
1382 exclude (EXCLUDE_FILES)
1383 include (PROCESS_FILES)
1384 filter(ReplaceTokens,
1388 'Version-Rel': JALVIEW_VERSION,
1389 'Year-Rel': getDate("yyyy")
1394 exclude (EXCLUDE_FILES)
1395 exclude (PROCESS_FILES)
1396 exclude ("appletlib")
1397 exclude ("**/*locales")
1398 exclude ("*locales/**")
1399 exclude ("utils/InstallAnywhere")
1401 exclude (getdown_files_dir)
1402 exclude (getdown_website_dir)
1404 // exluding these as not using jars as modules yet
1405 exclude ("${j11modDir}/**/*.jar")
1407 // from (jalviewDir) {
1408 // // explicit includes for stuff that seemed to not get included
1409 // include(fileTree("test/**/*."))
1410 // exclude(EXCLUDE_FILES)
1411 // exclude(PROCESS_FILES)
1418 dependsOn pubhtmlhelp
1420 inputs.dir("${classesDir}/${help_dir}")
1421 outputs.dir("${buildDir}/distributions/${help_dir}")
1424 // LARGE AMOUNT OF JALVIEWJS STUFF DELETED HERE
1425 task eclipseAutoBuildTask {}
1426 task eclipseSynchronizationTask {}