1 import org.apache.tools.ant.filters.ReplaceTokens
2 import org.gradle.internal.os.OperatingSystem
3 import org.gradle.plugins.ide.eclipse.model.Output
4 import org.gradle.plugins.ide.eclipse.model.Library
5 import java.security.MessageDigest
6 import groovy.transform.ExternalizeMethods
7 import groovy.util.XmlParser
8 import groovy.xml.XmlUtil
17 classpath 'org.openclover:clover:4.4.1'
26 id 'com.github.johnrengelman.shadow' version '4.0.3'
27 id 'com.install4j.gradle' version '8.0.4'
28 id 'com.dorongold.task-tree' version '1.5' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree
38 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
39 def string(Object o) {
40 return o == null ? "" : o.toString()
45 jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
46 jalviewDirRelativePath = jalviewDir
48 // local build environment properties
49 // can be "projectDir/local.properties"
50 def localProps = "${projectDir}/local.properties"
52 if (file(localProps).exists()) {
53 propsFile = localProps
55 // or "../projectDir_local.properties"
56 def dirLocalProps = projectDir.getParent() + "/" + projectDir.getName() + "_local.properties"
57 if (file(dirLocalProps).exists()) {
58 propsFile = dirLocalProps
60 if (propsFile != null) {
62 def p = new Properties()
63 def localPropsFIS = new FileInputStream(propsFile)
68 def oldval = findProperty(key)
71 println("Overriding property '${key}' ('${oldval}') with ${file(propsFile).getName()} value '${val}'")
73 println("Setting unknown property '${key}' with ${file(propsFile).getName()}s value '${val}'")
76 } catch (Exception e) {
77 System.out.println("Exception reading local.properties")
81 // this property set when running Eclipse headlessly
82 j2sHeadlessBuildProperty = string("net.sf.j2s.core.headlessbuild")
83 // this property set by Eclipse
84 eclipseApplicationProperty = string("eclipse.application")
85 // CHECK IF RUNNING FROM WITHIN ECLIPSE
86 def eclipseApplicationPropertyVal = System.properties[eclipseApplicationProperty]
87 IN_ECLIPSE = eclipseApplicationPropertyVal != null && eclipseApplicationPropertyVal.startsWith("org.eclipse.ui.")
88 // BUT WITHOUT THE HEADLESS BUILD PROPERTY SET
89 if (System.properties[j2sHeadlessBuildProperty].equals("true")) {
90 println("Setting IN_ECLIPSE to ${IN_ECLIPSE} as System.properties['${j2sHeadlessBuildProperty}'] == '${System.properties[j2sHeadlessBuildProperty]}'")
94 println("WITHIN ECLIPSE IDE")
96 println("HEADLESS BUILD")
99 System.properties.sort { it.key }.each {
100 key, val -> println("SYSTEM PROPERTY ${key}='${val}'")
103 if (false && IN_ECLIPSE) {
104 jalviewDir = jalviewDirAbsolutePath
109 bareSourceDir = string(source_dir)
110 sourceDir = string("${jalviewDir}/${bareSourceDir}")
111 resourceDir = string("${jalviewDir}/${resource_dir}")
112 bareTestSourceDir = string(test_source_dir)
113 testSourceDir = string("${jalviewDir}/${bareTestSourceDir}")
116 cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
117 cloverDb = string("${buildDir}/clover/clover.db")
118 classesDir = string("${jalviewDir}/${classes_dir}")
119 if (clover.equals("true")) {
121 classesDir = string("${buildDir}/${cloverClassesDir}")
124 classesDir = string("${jalviewDir}/${classes_dir}")
129 getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
132 // the following values might be overridden by the CHANNEL switch
133 getdownChannelName = CHANNEL.toLowerCase()
134 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
135 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
136 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
137 getdownAppDistDir = getdown_app_dir_alt
138 buildProperties = string("${classesDir}/${build_properties_file}")
139 reportRsyncCommand = false
140 jvlChannelName = CHANNEL.toLowerCase()
141 install4jSuffix = CHANNEL.substring(0, 1).toUpperCase() + CHANNEL.substring(1).toLowerCase(); // BUILD -> Build
142 install4jDSStore = "DS_Store-NON-RELEASE"
143 install4jDMGBackgroundImage = "jalview_dmg_background-NON-RELEASE.png"
144 install4jInstallerName = "${jalview_name} Installer"
145 install4jExecutableName = jalview_name.replaceAll("[^\\w]+", "_").toLowerCase()
146 install4jExtraScheme = "jalviewx"
150 // TODO: get bamboo build artifact URL for getdown artifacts
151 getdown_channel_base = bamboo_channelbase
152 getdownChannelName = string("${bamboo_planKey}/${JAVA_VERSION}")
153 getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
154 jvlChannelName += "_${getdownChannelName}"
155 // automatically add the test group Not-bamboo for exclusion
156 if ("".equals(testngExcludedGroups)) {
157 testngExcludedGroups = "Not-bamboo"
162 getdownAppDistDir = getdown_app_dir_release
163 reportRsyncCommand = true
165 install4jDSStore = "DS_Store"
166 install4jDMGBackgroundImage = "jalview_dmg_background.png"
170 getdownChannelName = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
171 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
172 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
173 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
174 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
176 packageDir = string("${ARCHIVEDIR}/${packageDir}")
177 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
180 reportRsyncCommand = true
184 getdownChannelName = string("archive/${JALVIEW_VERSION}")
185 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
186 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
187 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
188 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
190 packageDir = string("${ARCHIVEDIR}/${packageDir}")
191 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
194 reportRsyncCommand = true
195 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
196 install4jSuffix = "Archive"
200 reportRsyncCommand = true
204 reportRsyncCommand = true
205 install4jSuffix = "Test"
206 JALVIEW_VERSION = "TEST"
207 install4jExtraScheme = "jalviewt"
210 case ~/^SCRATCH(|-[-\w]*)$/:
211 getdownChannelName = CHANNEL
212 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
213 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
214 reportRsyncCommand = true
215 install4jSuffix = "Scratch"
219 if (!file("${LOCALDIR}").exists()) {
220 throw new GradleException("Must provide a LOCALDIR value to produce a local distribution")
222 getdownAppBase = file(file("${LOCALDIR}").getAbsolutePath()).toURI().toString()
223 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
225 install4jSuffix = "Test-Local"
226 JALVIEW_VERSION = "TEST"
227 install4jExtraScheme = "jalviewt"
231 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
232 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
235 default: // something wrong specified
236 throw new GradleException("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
240 // override getdownAppBase if requested
241 if (findProperty("getdown_appbase_override") != null) {
242 getdownAppBase = string(getProperty("getdown_appbase_override"))
243 println("Overriding getdown appbase with '${getdownAppBase}'")
245 // sanitise file name for jalview launcher file for this channel
246 jvlChannelName = jvlChannelName.replaceAll("[^\\w\\-]+", "_")
247 // install4j application and folder names
248 if (install4jSuffix == "") {
249 install4jApplicationName = "${jalview_name}"
251 install4jApplicationName = "${jalview_name} ${install4jSuffix}"
252 install4jInstallerName = "${jalview_name} Non-Release Installer"
254 // sanitise folder names
255 install4jApplicationFolder = install4jApplicationName
256 .replaceAll("[\"'~:\\\\]+", "_") // replace all awkward filename chars
257 install4jUnixApplicationFolder = install4jApplicationFolder
260 .replaceAll("[^\\w\\-\\.]+", "_") // replace other non [alphanumeric,_,-,.]
261 .replaceAll("_+", "_")
262 .replaceAll("_*-_*", "-")
264 getdownAppDir = string("${getdownWebsiteDir}/${getdownAppDistDir}")
265 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
266 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
267 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
268 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
269 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
270 /* compile without modules -- using classpath libraries
271 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
272 modules_runtimeClasspath = modules_compileClasspath
275 gitBranch = string("")
277 println("Using a ${CHANNEL} profile.")
279 additional_compiler_args = []
280 // configure classpath/args for j8/j11 compilation
281 if (JAVA_VERSION.equals("1.8")) {
282 JAVA_INTEGER_VERSION = string("8")
285 libDistDir = j8libDir
286 compile_source_compatibility = 1.8
287 compile_target_compatibility = 1.8
288 // these are getdown.txt properties defined dependent on the JAVA_VERSION
289 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java8_min_version"))
290 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java8_max_version"))
291 // this property is assigned below and expanded to multiple lines in the getdown task
292 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java8_txt_multi_java_location"))
293 // this property is for the Java library used in eclipse
294 eclipseJavaRuntimeName = string("JavaSE-1.8")
295 } else if (JAVA_VERSION.equals("11")) {
296 JAVA_INTEGER_VERSION = string("11")
298 libDistDir = j11libDir
299 compile_source_compatibility = 11
300 compile_target_compatibility = 11
301 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
302 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
303 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
304 eclipseJavaRuntimeName = string("JavaSE-11")
305 /* compile without modules -- using classpath libraries
306 additional_compiler_args += [
307 '--module-path', modules_compileClasspath.asPath,
308 '--add-modules', j11modules
311 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
312 JAVA_INTEGER_VERSION = JAVA_VERSION
314 libDistDir = j11libDir
315 compile_source_compatibility = JAVA_VERSION
316 compile_target_compatibility = JAVA_VERSION
317 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
318 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
319 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
320 eclipseJavaRuntimeName = string("JavaSE-11")
321 /* compile without modules -- using classpath libraries
322 additional_compiler_args += [
323 '--module-path', modules_compileClasspath.asPath,
324 '--add-modules', j11modules
328 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
333 JAVA_MIN_VERSION = JAVA_VERSION
334 JAVA_MAX_VERSION = JAVA_VERSION
335 def jreInstallsDir = string(jre_installs_dir)
336 if (jreInstallsDir.startsWith("~/")) {
337 jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
339 macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
340 macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-mac-x64.tar.gz")
341 windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
342 windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-windows-x64.tar.gz")
343 linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
344 linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-linux-x64.tar.gz")
345 install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
346 install4jConfFileName = string("jalview-install4j-conf.install4j")
347 install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
348 install4jHomeDir = install4j_home_dir
349 if (install4jHomeDir.startsWith("~/")) {
350 install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
355 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
356 helpFile = string("${classesDir}/${help_dir}/help.jhm")
357 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
358 helpSourceDir = string("${helpParentDir}/${help_dir}")
361 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
362 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
363 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
365 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
367 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
369 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
370 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
371 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
372 jalviewjsJalviewCoreHtmlFile = string("")
373 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
374 jalviewjsCoreClasslists = []
375 jalviewjsJalviewTemplateName = string(jalviewjs_name)
376 jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
377 jalviewjsJ2sProps = null
379 eclipseWorkspace = null
380 eclipseBinary = string("")
381 eclipseVersion = string("")
391 outputDir = file(classesDir)
396 srcDirs += helpParentDir
399 jar.destinationDir = file("${jalviewDir}/${packageDir}")
401 compileClasspath = files(sourceSets.main.java.outputDir)
402 //compileClasspath += files(sourceSets.main.resources.srcDirs)
403 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
405 runtimeClasspath = compileClasspath
410 srcDirs = [ cloverInstrDir ]
411 outputDir = file("${buildDir}/${cloverClassesDir}")
415 srcDirs = sourceSets.main.resources.srcDirs
417 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
418 compileClasspath += files(sourceSets.main.java.outputDir)
419 compileClasspath += sourceSets.main.compileClasspath
420 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
421 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
423 runtimeClasspath = compileClasspath
428 srcDirs testSourceDir
429 outputDir = file("${jalviewDir}/${testOutputDir}")
433 srcDirs = sourceSets.main.resources.srcDirs
436 compileClasspath = files( sourceSets.test.java.outputDir )
439 compileClasspath = sourceSets.clover.compileClasspath
441 compileClasspath += files(sourceSets.main.java.outputDir)
444 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
445 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
446 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
448 runtimeClasspath = compileClasspath
456 cloverCompile 'org.openclover:clover:4.4.1'
457 testCompile 'org.openclover:clover:4.4.1'
463 cloverRuntime.extendsFrom cloverCompile
467 // eclipse project and settings files creation, also used by buildship
470 name = eclipse_project_name
472 natures 'org.eclipse.jdt.core.javanature',
473 'org.eclipse.jdt.groovy.core.groovyNature',
474 'org.eclipse.buildship.core.gradleprojectnature'
476 buildCommand 'org.eclipse.jdt.core.javabuilder'
477 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
481 //defaultOutputDir = sourceSets.main.java.outputDir
484 if (it.isCanBeResolved()) {
489 minusConfigurations += removeThese
490 plusConfigurations = [ ]
494 def removeTheseToo = []
495 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
496 cp.entries.each { entry ->
497 // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
498 // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
499 // we add the resources and help/help dirs in as libs afterwards (see below)
500 if (entry.kind == 'src') {
501 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
502 removeTheseToo += entry
504 alreadyAddedSrcPath.putAt(entry.path, true)
509 cp.entries.removeAll(removeTheseToo)
511 //cp.entries += new Output("${eclipse_bin_dir}/main")
512 if (file(helpParentDir).isDirectory()) {
513 cp.entries += new Library(fileReference(helpParentDir))
515 if (file(resourceDir).isDirectory()) {
516 cp.entries += new Library(fileReference(resourceDir))
519 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
521 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
522 //don't want to add outputDir as eclipse is using its own output dir in bin/main
523 if (it.isDirectory() || ! it.exists()) {
524 // don't add dirs to classpath, especially if they don't exist
525 return false // groovy "continue" in .any closure
527 def itPath = it.toString()
528 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
529 // make relative path
530 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
532 if (alreadyAddedLibPath.get(itPath)) {
533 //println("Not adding duplicate entry "+itPath)
535 //println("Adding entry "+itPath)
536 cp.entries += new Library(fileReference(itPath))
537 alreadyAddedLibPath.put(itPath, true)
541 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
542 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
543 if (it.isDirectory() || ! it.exists()) {
544 // don't add dirs to classpath
545 return false // groovy "continue" in .any closure
548 def itPath = it.toString()
549 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
550 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
552 if (alreadyAddedLibPath.get(itPath)) {
555 def lib = new Library(fileReference(itPath))
556 lib.entryAttributes["test"] = "true"
558 alreadyAddedLibPath.put(itPath, true)
566 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
571 // for the IDE, use java 11 compatibility
572 sourceCompatibility = compile_source_compatibility
573 targetCompatibility = compile_target_compatibility
574 javaRuntimeName = eclipseJavaRuntimeName
576 // add in jalview project specific properties/preferences into eclipse core preferences
578 withProperties { props ->
579 def jalview_prefs = new Properties()
580 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
581 jalview_prefs.load(ins)
583 jalview_prefs.forEach { t, v ->
584 if (props.getAt(t) == null) {
594 // Don't want these to be activated if in headless build
595 synchronizationTasks "eclipseSynchronizationTask"
596 autoBuildTasks "eclipseAutoBuildTask"
603 // only instrument source, we build test classes as normal
604 inputs.files files (sourceSets.main.allJava,sourceSets.test.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
605 outputs.dir cloverInstrDir
608 delete cloverInstrDir
613 cloverInstrDir.getPath(),
616 inputs.files.files.collect(
617 { file -> file.absolutePath }
620 String[] args = argsList.toArray()
621 println("About to instrument "+args.length +" files")
622 com.atlassian.clover.CloverInstr.mainImpl(args)
627 cloverClasses.dependsOn cloverInstr
631 group = "Verification"
632 description = "Creates the Clover report"
633 inputs.dir "${buildDir}/clover"
634 outputs.dir "${reportsDir}/clover"
636 file(cloverDb).exists()
643 "${reportsDir}/clover"
645 String[] args = argsList.toArray()
646 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
648 // and generate ${reportsDir}/clover/clover.xml
653 "${reportsDir}/clover/clover.xml"
655 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
663 sourceCompatibility = compile_source_compatibility
664 targetCompatibility = compile_target_compatibility
665 options.compilerArgs += additional_compiler_args
666 print ("Setting target compatibility to "+targetCompatibility+"\n")
668 classpath += configurations.cloverRuntime
674 delete cloverInstrDir
684 sourceCompatibility = compile_source_compatibility
685 targetCompatibility = compile_target_compatibility
686 options.compilerArgs = additional_compiler_args
687 print ("Setting target compatibility to "+targetCompatibility+"\n")
695 dependsOn compileCloverJava
696 classpath += configurations.cloverRuntime
698 classpath += sourceSets.main.runtimeClasspath
701 sourceCompatibility = compile_source_compatibility
702 targetCompatibility = compile_target_compatibility
703 options.compilerArgs = additional_compiler_args
704 print ("Setting target compatibility to "+targetCompatibility+"\n")
711 delete sourceSets.main.java.outputDir
717 dependsOn cleanClover
719 delete sourceSets.test.java.outputDir
724 // format is a string like date.format("dd MMMM yyyy")
725 def getDate(format) {
726 def date = new Date()
727 return date.format(format)
732 def hashStdOut = new ByteArrayOutputStream()
734 commandLine "git", "rev-parse", "--short", "HEAD"
735 standardOutput = hashStdOut
739 def branchStdOut = new ByteArrayOutputStream()
741 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
742 standardOutput = branchStdOut
746 gitHash = hashStdOut.toString().trim()
747 gitBranch = branchStdOut.toString().trim()
749 outputs.upToDateWhen { false }
753 task createBuildProperties(type: WriteProperties) {
755 inputs.dir(sourceDir)
756 inputs.dir(resourceDir)
757 file(buildProperties).getParentFile().mkdirs()
758 outputFile (buildProperties)
759 // taking time specific comment out to allow better incremental builds
760 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
761 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
762 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
763 property "VERSION", JALVIEW_VERSION
764 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
765 outputs.file(outputFile)
769 task cleanBuildingHTML(type: Delete) {
776 task convertBuildingMD(type: Exec) {
777 dependsOn cleanBuildingHTML
778 def buildingMD = "${jalviewDir}/${docDir}/building.md"
779 def css = "${jalviewDir}/${docDir}/github.css"
782 pandoc_exec.split(",").each {
783 if (file(it.trim()).exists()) {
789 def hostname = "hostname".execute().text.trim()
790 def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
791 if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
792 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
796 if (pandoc != null && file(pandoc).exists()) {
797 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
799 println("Cannot find pandoc. Skipping convert building.md to HTML")
800 throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
806 inputs.file(buildingMD)
808 outputs.file(buildingHTML)
819 task syncDocs(type: Sync) {
820 dependsOn convertBuildingMD
821 def syncDir = "${classesDir}/${docDir}"
822 from fileTree("${jalviewDir}/${docDir}")
828 task copyHelp(type: Copy) {
829 def inputDir = helpSourceDir
830 def outputDir = "${classesDir}/${help_dir}"
835 filter(ReplaceTokens,
839 'Version-Rel': JALVIEW_VERSION,
840 'Year-Rel': getDate("yyyy")
852 outputs.files(helpFile)
853 outputs.dir(outputDir)
857 task syncLib(type: Sync) {
858 def syncDir = "${classesDir}/${libDistDir}"
859 from fileTree("${jalviewDir}/${libDistDir}")
864 task syncResources(type: Sync) {
875 dependsOn syncResources
881 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
884 dependsOn compileJava
886 dependsOn cloverInstr
890 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
894 includeGroups testngGroups
895 excludeGroups testngExcludedGroups
897 useDefaultListeners=true
900 maxHeapSize = "1024m"
902 workingDir = jalviewDir
903 //systemProperties 'clover.jar' System.properties.clover.jar
904 sourceCompatibility = compile_source_compatibility
905 targetCompatibility = compile_target_compatibility
906 jvmArgs += additional_compiler_args
911 task buildIndices(type: JavaExec) {
913 classpath = sourceSets.main.compileClasspath
914 main = "com.sun.java.help.search.Indexer"
915 workingDir = "${classesDir}/${help_dir}"
918 inputs.dir("${workingDir}/${argDir}")
920 outputs.dir("${classesDir}/doc")
921 outputs.dir("${classesDir}/help")
922 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
923 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
924 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
925 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
926 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
927 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
931 task compileLinkCheck(type: JavaCompile) {
933 classpath = files("${jalviewDir}/${utilsDir}")
934 destinationDir = file("${jalviewDir}/${utilsDir}")
935 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
937 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
938 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
939 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
940 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
944 task linkCheck(type: JavaExec) {
945 dependsOn prepare, compileLinkCheck
947 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
948 classpath = files("${jalviewDir}/${utilsDir}")
949 main = "HelpLinksChecker"
950 workingDir = jalviewDir
951 args = [ "${classesDir}/${help_dir}", "-nointernet" ]
953 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
955 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
958 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
962 inputs.dir("${classesDir}/${help_dir}")
963 outputs.file(helpLinksCheckerOutFile)
966 // import the pubhtmlhelp target
967 ant.properties.basedir = "${jalviewDir}"
968 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
969 ant.importBuild "${utilsDir}/publishHelp.xml"
972 task cleanPackageDir(type: Delete) {
974 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
980 dependsOn buildIndices
981 dependsOn createBuildProperties
984 attributes "Main-Class": mainClass,
985 "Permissions": "all-permissions",
986 "Application-Name": "Jalview Desktop",
987 "Codebase": application_codebase
990 destinationDir = file("${jalviewDir}/${packageDir}")
991 archiveName = rootProject.name+".jar"
999 inputs.dir(classesDir)
1000 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
1004 task copyJars(type: Copy) {
1005 from fileTree(dir: classesDir, include: "**/*.jar").files
1006 into "${jalviewDir}/${packageDir}"
1010 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
1011 task syncJars(type: Sync) {
1012 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
1013 into "${jalviewDir}/${packageDir}"
1015 include jar.archiveName
1022 description = "Put all required libraries in dist"
1023 // order of "cleanPackageDir", "copyJars", "jar" important!
1024 jar.mustRunAfter cleanPackageDir
1025 syncJars.mustRunAfter cleanPackageDir
1026 dependsOn cleanPackageDir
1029 outputs.dir("${jalviewDir}/${packageDir}")
1034 dependsOn cleanPackageDir
1040 group = "distribution"
1044 from ("${jalviewDir}/${libDistDir}") {
1048 attributes 'Implementation-Version': JALVIEW_VERSION
1050 mainClassName = shadowJarMainClass
1052 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
1057 task getdownWebsite() {
1058 group = "distribution"
1059 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
1064 def getdownWebsiteResourceFilenames = []
1065 def getdownTextString = ""
1066 def getdownResourceDir = getdownResourceDir
1067 def getdownResourceFilenames = []
1070 // clean the getdown website and files dir before creating getdown folders
1071 delete getdownWebsiteDir
1072 delete getdownFilesDir
1075 from buildProperties
1076 rename(build_properties_file, getdown_build_properties)
1079 getdownWebsiteResourceFilenames += "${getdownAppDistDir}/${getdown_build_properties}"
1081 // set some getdown_txt_ properties then go through all properties looking for getdown_txt_...
1082 def props = project.properties.sort { it.key }
1083 if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
1084 props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
1086 if (getdownAltJavaMaxVersion != null && getdownAltJavaMaxVersion.length() > 0) {
1087 props.put("getdown_txt_java_max_version", getdownAltJavaMaxVersion)
1089 if (getdownAltMultiJavaLocation != null && getdownAltMultiJavaLocation.length() > 0) {
1090 props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
1093 props.put("getdown_txt_title", jalview_name)
1094 props.put("getdown_txt_ui.name", install4jApplicationName)
1096 // start with appbase
1097 getdownTextString += "appbase = ${getdownAppBase}\n"
1098 props.each{ prop, val ->
1099 if (prop.startsWith("getdown_txt_") && val != null) {
1100 if (prop.startsWith("getdown_txt_multi_")) {
1101 def key = prop.substring(18)
1102 val.split(",").each{ v ->
1103 def line = "${key} = ${v}\n"
1104 getdownTextString += line
1107 // file values rationalised
1108 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1110 if (val.indexOf('/') == 0) {
1113 } else if (val.indexOf('/') > 0) {
1114 // relative path (relative to jalviewDir)
1115 r = file( "${jalviewDir}/${val}" )
1118 val = "${getdown_resource_dir}/" + r.getName()
1119 getdownWebsiteResourceFilenames += val
1120 getdownResourceFilenames += r.getPath()
1123 if (! prop.startsWith("getdown_txt_resource")) {
1124 def line = prop.substring(12) + " = ${val}\n"
1125 getdownTextString += line
1131 getdownWebsiteResourceFilenames.each{ filename ->
1132 getdownTextString += "resource = ${filename}\n"
1134 getdownResourceFilenames.each{ filename ->
1137 into getdownResourceDir
1142 fileTree(file(packageDir)).each{ f ->
1143 if (f.isDirectory()) {
1144 def files = fileTree(dir: f, include: ["*"]).getFiles()
1146 } else if (f.exists()) {
1150 codeFiles.sort().each{f ->
1151 def name = f.getName()
1152 def line = "code = ${getdownAppDistDir}/${name}\n"
1153 getdownTextString += line
1160 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1162 if (JAVA_VERSION.equals("11")) {
1163 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1164 j11libFiles.sort().each{f ->
1165 def name = f.getName()
1166 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1167 getdownTextString += line
1170 into getdownJ11libDir
1176 // 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.
1177 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1178 getdownTextString += "resource = ${getdown_launcher_new}\n"
1179 getdownTextString += "class = ${mainClass}\n"
1181 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1182 getdown_txt.write(getdownTextString)
1184 def getdownLaunchJvl = getdown_launch_jvl_name + ( (jvlChannelName != null && jvlChannelName.length() > 0)?"-${jvlChannelName}":"" ) + ".jvl"
1185 def launchJvl = file("${getdownWebsiteDir}/${getdownLaunchJvl}")
1186 launchJvl.write("appbase=${getdownAppBase}")
1189 from getdownLauncher
1190 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1191 into getdownWebsiteDir
1195 from getdownLauncher
1196 if (file(getdownLauncher).getName() != getdown_launcher) {
1197 rename(file(getdownLauncher).getName(), getdown_launcher)
1199 into getdownWebsiteDir
1202 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1205 from getdownLauncher
1206 from "${getdownWebsiteDir}/${getdown_build_properties}"
1207 if (file(getdownLauncher).getName() != getdown_launcher) {
1208 rename(file(getdownLauncher).getName(), getdown_launcher)
1210 into getdownInstallDir
1214 from getdownInstallDir
1215 into getdownFilesInstallDir
1222 from getdownLauncher
1223 from "${getdownWebsiteDir}/${getdown_build_properties}"
1224 if (file(getdownLauncher).getName() != getdown_launcher) {
1225 rename(file(getdownLauncher).getName(), getdown_launcher)
1227 into getdownFilesDir
1231 from getdownResourceDir
1232 into "${getdownFilesDir}/${getdown_resource_dir}"
1237 inputs.dir("${jalviewDir}/${packageDir}")
1239 outputs.dir(getdownWebsiteDir)
1240 outputs.dir(getdownFilesDir)
1244 // a helper task to allow getdown digest of any dir: `gradle getdownDigestDir -PDIGESTDIR=/path/to/my/random/getdown/dir
1245 task getdownDigestDir(type: JavaExec) {
1246 def digestDirPropertyName = "DIGESTDIR"
1247 description = "Digest a local dir (-P${digestDirPropertyName}=...) for getdown"
1249 classpath = files(getdownLauncher)
1250 def digestDir = findProperty(digestDirPropertyName)
1251 if (digestDir == null) {
1252 throw new GradleException("Must provide a DIGESTDIR value to produce an alternative getdown digest")
1256 main = "com.threerings.getdown.tools.Digester"
1260 task getdownDigest(type: JavaExec) {
1261 group = "distribution"
1262 description = "Digest the getdown website folder"
1263 dependsOn getdownWebsite
1265 classpath = files(getdownLauncher)
1267 main = "com.threerings.getdown.tools.Digester"
1268 args getdownWebsiteDir
1269 inputs.dir(getdownWebsiteDir)
1270 outputs.file("${getdownWebsiteDir}/digest2.txt")
1275 group = "distribution"
1276 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1277 dependsOn getdownDigest
1279 if (reportRsyncCommand) {
1280 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1281 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1282 println "LIKELY RSYNC COMMAND:"
1283 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1284 if (RUNRSYNC == "true") {
1286 commandLine "mkdir", "-p", toDir
1289 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1299 delete getdownWebsiteDir
1300 delete getdownFilesDir
1306 if (file(install4jHomeDir).exists()) {
1308 } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1309 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1310 } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1311 install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1313 installDir(file(install4jHomeDir))
1315 mediaTypes = Arrays.asList(install4j_media_types.split(","))
1319 task copyInstall4jTemplate {
1320 def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
1321 def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1322 inputs.file(install4jTemplateFile)
1323 inputs.file(install4jFileAssociationsFile)
1324 outputs.file(install4jConfFile)
1327 def install4jConfigXml = new XmlParser().parse(install4jTemplateFile)
1329 // turn off code signing if no OSX_KEYPASS
1330 if (OSX_KEYPASS == "") {
1331 install4jConfigXml.'**'.codeSigning.each { codeSigning ->
1332 codeSigning.'@macEnabled' = "false"
1334 install4jConfigXml.'**'.windows.each { windows ->
1335 windows.'@runPostProcessor' = "false"
1339 // turn off checksum creation for LOCAL channel
1340 def e = install4jConfigXml.application[0]
1341 if (CHANNEL == "LOCAL") {
1342 e.'@createChecksums' = "false"
1344 e.'@createChecksums' = "true"
1347 // put file association actions where placeholder action is
1348 def install4jFileAssociationsText = install4jFileAssociationsFile.text
1349 def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
1350 install4jConfigXml.'**'.action.any { a ->
1351 if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1352 def parent = a.parent()
1354 fileAssociationActions.each { faa ->
1357 // don't need to continue in .any loop once replacements have been made
1362 // write install4j file
1363 install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
1370 delete install4jConfFile
1375 task installers(type: com.install4j.gradle.Install4jTask) {
1376 group = "distribution"
1377 description = "Create the install4j installers"
1378 dependsOn setGitVals
1380 dependsOn copyInstall4jTemplate
1382 projectFile = install4jConfFile
1384 // create an md5 for the input files to use as version for install4j conf file
1385 def digest = MessageDigest.getInstance("MD5")
1387 (file("${install4jDir}/${install4j_template}").text +
1388 file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1389 file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1390 def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1391 if (filesMd5.length() >= 8) {
1392 filesMd5 = filesMd5.substring(0,8)
1394 def install4jTemplateVersion = "${JALVIEW_VERSION}_F${filesMd5}_C${gitHash}"
1395 // make install4jBuildDir relative to jalviewDir
1396 def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
1399 'JALVIEW_NAME': install4jApplicationName,
1400 'JALVIEW_DIR': "../..",
1401 'OSX_KEYSTORE': OSX_KEYSTORE,
1402 'JSIGN_SH': JSIGN_SH,
1403 'JRE_DIR': getdown_app_dir_java,
1404 'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1405 'JALVIEW_VERSION': JALVIEW_VERSION,
1406 'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1407 'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1408 'JAVA_VERSION': JAVA_VERSION,
1409 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1410 'VERSION': JALVIEW_VERSION,
1411 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1412 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1413 'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
1414 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1415 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1416 'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
1417 'COPYRIGHT_MESSAGE': install4j_copyright_message,
1418 'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1419 'MACOS_DS_STORE': install4jDSStore,
1420 'MACOS_DMG_BG_IMAGE': install4jDMGBackgroundImage,
1421 'INSTALLER_NAME': install4jInstallerName,
1422 'INSTALL4J_UTILS_DIR': install4j_utils_dir,
1423 'GETDOWN_WEBSITE_DIR': getdown_website_dir,
1424 'GETDOWN_FILES_DIR': getdown_files_dir,
1425 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1426 'GETDOWN_DIST_DIR': getdownAppDistDir,
1427 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1428 'GETDOWN_INSTALL_DIR': getdown_install_dir,
1429 'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
1430 'BUILD_DIR': install4jBuildDir,
1431 'UNIX_DESKTOP_ADDITIONS': install4j_unix_desktop_additions,
1432 'APPLICATION_FOLDER': install4jApplicationFolder,
1433 'UNIX_APPLICATION_FOLDER': install4jUnixApplicationFolder,
1434 'EXECUTABLE_NAME': install4jExecutableName,
1435 'EXTRA_SCHEME': install4jExtraScheme,
1438 destination = "${jalviewDir}/${install4jBuildDir}"
1439 buildSelected = true
1441 if (install4j_faster.equals("true") || CHANNEL.startsWith("LOCAL")) {
1443 disableSigning = true
1447 macKeystorePassword = OSX_KEYPASS
1451 println("Using projectFile "+projectFile)
1454 inputs.dir(getdownWebsiteDir)
1455 inputs.file(install4jConfFile)
1456 inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1457 inputs.dir(macosJavaVMDir)
1458 inputs.dir(windowsJavaVMDir)
1459 outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1463 task sourceDist(type: Tar) {
1465 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1466 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1467 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1469 archiveFileName = outputFileName
1470 } catch (Exception e) {
1471 archiveName = outputFileName
1474 compression Compression.GZIP
1489 "**/*.class","$j11modDir/**/*.jar","appletlib","**/*locales",
1491 "utils/InstallAnywhere",
1506 "gradle.properties",
1517 ".settings/org.eclipse.jdt.core.jalview.prefs",
1521 exclude (EXCLUDE_FILES)
1522 include (PROCESS_FILES)
1523 filter(ReplaceTokens,
1527 'Version-Rel': JALVIEW_VERSION,
1528 'Year-Rel': getDate("yyyy")
1533 exclude (EXCLUDE_FILES)
1534 exclude (PROCESS_FILES)
1535 exclude ("appletlib")
1536 exclude ("**/*locales")
1537 exclude ("*locales/**")
1538 exclude ("utils/InstallAnywhere")
1540 exclude (getdown_files_dir)
1541 exclude (getdown_website_dir)
1543 // exluding these as not using jars as modules yet
1544 exclude ("$j11modDir/**/*.jar")
1547 include(INCLUDE_FILES)
1549 // from (jalviewDir) {
1550 // // explicit includes for stuff that seemed to not get included
1551 // include(fileTree("test/**/*."))
1552 // exclude(EXCLUDE_FILES)
1553 // exclude(PROCESS_FILES)
1560 dependsOn pubhtmlhelp
1562 inputs.dir("${classesDir}/${help_dir}")
1563 outputs.dir("${buildDir}/distributions/${help_dir}")
1566 // LARGE AMOUNT OF JALVIEWJS STUFF DELETED HERE
1567 task eclipseAutoBuildTask {}
1568 task eclipseSynchronizationTask {}