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()
149 // TODO: get bamboo build artifact URL for getdown artifacts
150 getdown_channel_base = bamboo_channelbase
151 getdownChannelName = string("${bamboo_planKey}/${JAVA_VERSION}")
152 getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
153 jvlChannelName += "_${getdownChannelName}"
154 // automatically add the test group Not-bamboo for exclusion
155 if ("".equals(testngExcludedGroups)) {
156 testngExcludedGroups = "Not-bamboo"
161 getdownAppDistDir = getdown_app_dir_release
162 reportRsyncCommand = true
164 install4jDSStore = "DS_Store"
165 install4jDMGBackgroundImage = "jalview_dmg_background.png"
169 getdownChannelName = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
170 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
171 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
172 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
173 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
175 packageDir = string("${ARCHIVEDIR}/${packageDir}")
176 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
179 reportRsyncCommand = true
183 getdownChannelName = string("archive/${JALVIEW_VERSION}")
184 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
185 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
186 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
187 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
189 packageDir = string("${ARCHIVEDIR}/${packageDir}")
190 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
193 reportRsyncCommand = true
194 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
195 install4jSuffix = "Archive"
199 reportRsyncCommand = true
203 reportRsyncCommand = true
204 install4jSuffix = "Test"
205 JALVIEW_VERSION = "TEST"
208 case ~/^SCRATCH(|-[-\w]*)$/:
209 getdownChannelName = CHANNEL
210 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
211 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
212 reportRsyncCommand = true
213 install4jSuffix = "Scratch"
217 if (!file("${LOCALDIR}").exists()) {
218 throw new GradleException("Must provide a LOCALDIR value to produce a local distribution")
220 getdownAppBase = file(file("${LOCALDIR}").getAbsolutePath()).toURI().toString()
221 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
223 install4jSuffix = "Test-Local"
224 JALVIEW_VERSION = "TEST"
228 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
229 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
232 default: // something wrong specified
233 throw new GradleException("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
237 // override getdownAppBase if requested
238 if (findProperty("getdown_appbase_override") != null) {
239 getdownAppBase = string(getProperty("getdown_appbase_override"))
240 println("Overriding getdown appbase with '${getdownAppBase}'")
242 // sanitise file name for jalview launcher file for this channel
243 jvlChannelName = jvlChannelName.replaceAll("[^\\w\\-]+", "_")
244 // install4j application and folder names
245 if (install4jSuffix == "") {
246 install4jApplicationName = "${jalview_name}"
248 install4jApplicationName = "${jalview_name} ${install4jSuffix}"
249 install4jInstallerName = "${jalview_name} Non-Release Installer"
251 // sanitise folder names
252 install4jApplicationFolder = install4jApplicationName
253 .replaceAll("[\"'~:\\\\]+", "_") // replace all awkward filename chars
254 install4jUnixApplicationFolder = install4jApplicationFolder
257 .replaceAll("[^\\w\\-\\.]+", "_") // replace other non [alphanumeric,_,-,.]
258 .replaceAll("_+", "_")
259 .replaceAll("_*-_*", "-")
261 getdownAppDir = string("${getdownWebsiteDir}/${getdownAppDistDir}")
262 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
263 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
264 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
265 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
266 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
267 /* compile without modules -- using classpath libraries
268 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
269 modules_runtimeClasspath = modules_compileClasspath
272 gitBranch = string("")
274 println("Using a ${CHANNEL} profile.")
276 additional_compiler_args = []
277 // configure classpath/args for j8/j11 compilation
278 if (JAVA_VERSION.equals("1.8")) {
279 JAVA_INTEGER_VERSION = string("8")
282 libDistDir = j8libDir
283 compile_source_compatibility = 1.8
284 compile_target_compatibility = 1.8
285 // these are getdown.txt properties defined dependent on the JAVA_VERSION
286 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java8_min_version"))
287 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java8_max_version"))
288 // this property is assigned below and expanded to multiple lines in the getdown task
289 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java8_txt_multi_java_location"))
290 // this property is for the Java library used in eclipse
291 eclipseJavaRuntimeName = string("JavaSE-1.8")
292 } else if (JAVA_VERSION.equals("11")) {
293 JAVA_INTEGER_VERSION = string("11")
295 libDistDir = j11libDir
296 compile_source_compatibility = 11
297 compile_target_compatibility = 11
298 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
299 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
300 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
301 eclipseJavaRuntimeName = string("JavaSE-11")
302 /* compile without modules -- using classpath libraries
303 additional_compiler_args += [
304 '--module-path', modules_compileClasspath.asPath,
305 '--add-modules', j11modules
308 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
309 JAVA_INTEGER_VERSION = JAVA_VERSION
311 libDistDir = j11libDir
312 compile_source_compatibility = JAVA_VERSION
313 compile_target_compatibility = JAVA_VERSION
314 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
315 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
316 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
317 eclipseJavaRuntimeName = string("JavaSE-11")
318 /* compile without modules -- using classpath libraries
319 additional_compiler_args += [
320 '--module-path', modules_compileClasspath.asPath,
321 '--add-modules', j11modules
325 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
330 JAVA_MIN_VERSION = JAVA_VERSION
331 JAVA_MAX_VERSION = JAVA_VERSION
332 def jreInstallsDir = string(jre_installs_dir)
333 if (jreInstallsDir.startsWith("~/")) {
334 jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
336 macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
337 macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-mac-x64.tar.gz")
338 windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
339 windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-windows-x64.tar.gz")
340 linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
341 linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-linux-x64.tar.gz")
342 install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
343 install4jConfFileName = string("jalview-install4j-conf.install4j")
344 install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
345 install4jHomeDir = install4j_home_dir
346 if (install4jHomeDir.startsWith("~/")) {
347 install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
352 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
353 helpFile = string("${classesDir}/${help_dir}/help.jhm")
354 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
355 helpSourceDir = string("${helpParentDir}/${help_dir}")
358 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
359 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
360 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
362 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
364 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
366 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
367 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
368 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
369 jalviewjsJalviewCoreHtmlFile = string("")
370 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
371 jalviewjsCoreClasslists = []
372 jalviewjsJalviewTemplateName = string(jalviewjs_name)
373 jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
374 jalviewjsJ2sProps = null
376 eclipseWorkspace = null
377 eclipseBinary = string("")
378 eclipseVersion = string("")
388 outputDir = file(classesDir)
393 srcDirs += helpParentDir
396 jar.destinationDir = file("${jalviewDir}/${packageDir}")
398 compileClasspath = files(sourceSets.main.java.outputDir)
399 //compileClasspath += files(sourceSets.main.resources.srcDirs)
400 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
402 runtimeClasspath = compileClasspath
407 srcDirs = [ cloverInstrDir ]
408 outputDir = file("${buildDir}/${cloverClassesDir}")
412 srcDirs = sourceSets.main.resources.srcDirs
414 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
415 compileClasspath += files(sourceSets.main.java.outputDir)
416 compileClasspath += sourceSets.main.compileClasspath
417 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
418 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
420 runtimeClasspath = compileClasspath
425 srcDirs testSourceDir
426 outputDir = file("${jalviewDir}/${testOutputDir}")
430 srcDirs = sourceSets.main.resources.srcDirs
433 compileClasspath = files( sourceSets.test.java.outputDir )
436 compileClasspath = sourceSets.clover.compileClasspath
438 compileClasspath += files(sourceSets.main.java.outputDir)
441 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
442 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
443 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
445 runtimeClasspath = compileClasspath
453 cloverCompile 'org.openclover:clover:4.4.1'
454 testCompile 'org.openclover:clover:4.4.1'
460 cloverRuntime.extendsFrom cloverCompile
464 // eclipse project and settings files creation, also used by buildship
467 name = eclipse_project_name
469 natures 'org.eclipse.jdt.core.javanature',
470 'org.eclipse.jdt.groovy.core.groovyNature',
471 'org.eclipse.buildship.core.gradleprojectnature'
473 buildCommand 'org.eclipse.jdt.core.javabuilder'
474 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
478 //defaultOutputDir = sourceSets.main.java.outputDir
481 if (it.isCanBeResolved()) {
486 minusConfigurations += removeThese
487 plusConfigurations = [ ]
491 def removeTheseToo = []
492 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
493 cp.entries.each { entry ->
494 // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
495 // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
496 // we add the resources and help/help dirs in as libs afterwards (see below)
497 if (entry.kind == 'src') {
498 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
499 removeTheseToo += entry
501 alreadyAddedSrcPath.putAt(entry.path, true)
506 cp.entries.removeAll(removeTheseToo)
508 //cp.entries += new Output("${eclipse_bin_dir}/main")
509 if (file(helpParentDir).isDirectory()) {
510 cp.entries += new Library(fileReference(helpParentDir))
512 if (file(resourceDir).isDirectory()) {
513 cp.entries += new Library(fileReference(resourceDir))
516 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
518 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
519 //don't want to add outputDir as eclipse is using its own output dir in bin/main
520 if (it.isDirectory() || ! it.exists()) {
521 // don't add dirs to classpath, especially if they don't exist
522 return false // groovy "continue" in .any closure
524 def itPath = it.toString()
525 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
526 // make relative path
527 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
529 if (alreadyAddedLibPath.get(itPath)) {
530 //println("Not adding duplicate entry "+itPath)
532 //println("Adding entry "+itPath)
533 cp.entries += new Library(fileReference(itPath))
534 alreadyAddedLibPath.put(itPath, true)
538 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
539 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
540 if (it.isDirectory() || ! it.exists()) {
541 // don't add dirs to classpath
542 return false // groovy "continue" in .any closure
545 def itPath = it.toString()
546 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
547 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
549 if (alreadyAddedLibPath.get(itPath)) {
552 def lib = new Library(fileReference(itPath))
553 lib.entryAttributes["test"] = "true"
555 alreadyAddedLibPath.put(itPath, true)
563 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
568 // for the IDE, use java 11 compatibility
569 sourceCompatibility = compile_source_compatibility
570 targetCompatibility = compile_target_compatibility
571 javaRuntimeName = eclipseJavaRuntimeName
573 // add in jalview project specific properties/preferences into eclipse core preferences
575 withProperties { props ->
576 def jalview_prefs = new Properties()
577 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
578 jalview_prefs.load(ins)
580 jalview_prefs.forEach { t, v ->
581 if (props.getAt(t) == null) {
591 // Don't want these to be activated if in headless build
592 synchronizationTasks "eclipseSynchronizationTask"
593 autoBuildTasks "eclipseAutoBuildTask"
600 // only instrument source, we build test classes as normal
601 inputs.files files (sourceSets.main.allJava,sourceSets.test.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
602 outputs.dir cloverInstrDir
605 delete cloverInstrDir
610 cloverInstrDir.getPath(),
613 inputs.files.files.collect(
614 { file -> file.absolutePath }
617 String[] args = argsList.toArray()
618 println("About to instrument "+args.length +" files")
619 com.atlassian.clover.CloverInstr.mainImpl(args)
624 cloverClasses.dependsOn cloverInstr
628 group = "Verification"
629 description = "Creates the Clover report"
630 inputs.dir "${buildDir}/clover"
631 outputs.dir "${reportsDir}/clover"
633 file(cloverDb).exists()
640 "${reportsDir}/clover"
642 String[] args = argsList.toArray()
643 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
645 // and generate ${reportsDir}/clover/clover.xml
650 "${reportsDir}/clover/clover.xml"
652 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
660 sourceCompatibility = compile_source_compatibility
661 targetCompatibility = compile_target_compatibility
662 options.compilerArgs += additional_compiler_args
663 print ("Setting target compatibility to "+targetCompatibility+"\n")
665 classpath += configurations.cloverRuntime
671 delete cloverInstrDir
681 sourceCompatibility = compile_source_compatibility
682 targetCompatibility = compile_target_compatibility
683 options.compilerArgs = additional_compiler_args
684 print ("Setting target compatibility to "+targetCompatibility+"\n")
692 dependsOn compileCloverJava
693 classpath += configurations.cloverRuntime
695 classpath += sourceSets.main.runtimeClasspath
698 sourceCompatibility = compile_source_compatibility
699 targetCompatibility = compile_target_compatibility
700 options.compilerArgs = additional_compiler_args
701 print ("Setting target compatibility to "+targetCompatibility+"\n")
708 delete sourceSets.main.java.outputDir
714 dependsOn cleanClover
716 delete sourceSets.test.java.outputDir
721 // format is a string like date.format("dd MMMM yyyy")
722 def getDate(format) {
723 def date = new Date()
724 return date.format(format)
729 def hashStdOut = new ByteArrayOutputStream()
731 commandLine "git", "rev-parse", "--short", "HEAD"
732 standardOutput = hashStdOut
736 def branchStdOut = new ByteArrayOutputStream()
738 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
739 standardOutput = branchStdOut
743 gitHash = hashStdOut.toString().trim()
744 gitBranch = branchStdOut.toString().trim()
746 outputs.upToDateWhen { false }
750 task createBuildProperties(type: WriteProperties) {
752 inputs.dir(sourceDir)
753 inputs.dir(resourceDir)
754 file(buildProperties).getParentFile().mkdirs()
755 outputFile (buildProperties)
756 // taking time specific comment out to allow better incremental builds
757 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
758 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
759 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
760 property "VERSION", JALVIEW_VERSION
761 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
762 outputs.file(outputFile)
766 task cleanBuildingHTML(type: Delete) {
773 task convertBuildingMD(type: Exec) {
774 dependsOn cleanBuildingHTML
775 def buildingMD = "${jalviewDir}/${docDir}/building.md"
776 def css = "${jalviewDir}/${docDir}/github.css"
779 pandoc_exec.split(",").each {
780 if (file(it.trim()).exists()) {
786 def hostname = "hostname".execute().text.trim()
787 def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
788 if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
789 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
793 if (pandoc != null && file(pandoc).exists()) {
794 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
796 println("Cannot find pandoc. Skipping convert building.md to HTML")
797 throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
803 inputs.file(buildingMD)
805 outputs.file(buildingHTML)
816 task syncDocs(type: Sync) {
817 dependsOn convertBuildingMD
818 def syncDir = "${classesDir}/${docDir}"
819 from fileTree("${jalviewDir}/${docDir}")
825 task copyHelp(type: Copy) {
826 def inputDir = helpSourceDir
827 def outputDir = "${classesDir}/${help_dir}"
832 filter(ReplaceTokens,
836 'Version-Rel': JALVIEW_VERSION,
837 'Year-Rel': getDate("yyyy")
849 outputs.files(helpFile)
850 outputs.dir(outputDir)
854 task syncLib(type: Sync) {
855 def syncDir = "${classesDir}/${libDistDir}"
856 from fileTree("${jalviewDir}/${libDistDir}")
861 task syncResources(type: Sync) {
872 dependsOn syncResources
878 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
881 dependsOn compileJava
883 dependsOn cloverInstr
887 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
891 includeGroups testngGroups
892 excludeGroups testngExcludedGroups
894 useDefaultListeners=true
897 maxHeapSize = "1024m"
899 workingDir = jalviewDir
900 //systemProperties 'clover.jar' System.properties.clover.jar
901 sourceCompatibility = compile_source_compatibility
902 targetCompatibility = compile_target_compatibility
903 jvmArgs += additional_compiler_args
908 task buildIndices(type: JavaExec) {
910 classpath = sourceSets.main.compileClasspath
911 main = "com.sun.java.help.search.Indexer"
912 workingDir = "${classesDir}/${help_dir}"
915 inputs.dir("${workingDir}/${argDir}")
917 outputs.dir("${classesDir}/doc")
918 outputs.dir("${classesDir}/help")
919 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
920 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
921 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
922 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
923 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
924 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
928 task compileLinkCheck(type: JavaCompile) {
930 classpath = files("${jalviewDir}/${utilsDir}")
931 destinationDir = file("${jalviewDir}/${utilsDir}")
932 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
934 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
935 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
936 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
937 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
941 task linkCheck(type: JavaExec) {
942 dependsOn prepare, compileLinkCheck
944 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
945 classpath = files("${jalviewDir}/${utilsDir}")
946 main = "HelpLinksChecker"
947 workingDir = jalviewDir
948 args = [ "${classesDir}/${help_dir}", "-nointernet" ]
950 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
952 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
955 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
959 inputs.dir("${classesDir}/${help_dir}")
960 outputs.file(helpLinksCheckerOutFile)
963 // import the pubhtmlhelp target
964 ant.properties.basedir = "${jalviewDir}"
965 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
966 ant.importBuild "${utilsDir}/publishHelp.xml"
969 task cleanPackageDir(type: Delete) {
971 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
977 dependsOn buildIndices
978 dependsOn createBuildProperties
981 attributes "Main-Class": mainClass,
982 "Permissions": "all-permissions",
983 "Application-Name": "Jalview Desktop",
984 "Codebase": application_codebase
987 destinationDir = file("${jalviewDir}/${packageDir}")
988 archiveName = rootProject.name+".jar"
996 inputs.dir(classesDir)
997 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
1001 task copyJars(type: Copy) {
1002 from fileTree(dir: classesDir, include: "**/*.jar").files
1003 into "${jalviewDir}/${packageDir}"
1007 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
1008 task syncJars(type: Sync) {
1009 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
1010 into "${jalviewDir}/${packageDir}"
1012 include jar.archiveName
1019 description = "Put all required libraries in dist"
1020 // order of "cleanPackageDir", "copyJars", "jar" important!
1021 jar.mustRunAfter cleanPackageDir
1022 syncJars.mustRunAfter cleanPackageDir
1023 dependsOn cleanPackageDir
1026 outputs.dir("${jalviewDir}/${packageDir}")
1031 dependsOn cleanPackageDir
1037 group = "distribution"
1041 from ("${jalviewDir}/${libDistDir}") {
1045 attributes 'Implementation-Version': JALVIEW_VERSION
1047 mainClassName = shadowJarMainClass
1049 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
1054 task getdownWebsite() {
1055 group = "distribution"
1056 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
1061 def getdownWebsiteResourceFilenames = []
1062 def getdownTextString = ""
1063 def getdownResourceDir = getdownResourceDir
1064 def getdownResourceFilenames = []
1067 // clean the getdown website and files dir before creating getdown folders
1068 delete getdownWebsiteDir
1069 delete getdownFilesDir
1072 from buildProperties
1073 rename(build_properties_file, getdown_build_properties)
1076 getdownWebsiteResourceFilenames += "${getdownAppDistDir}/${getdown_build_properties}"
1078 // set some getdown_txt_ properties then go through all properties looking for getdown_txt_...
1079 def props = project.properties.sort { it.key }
1080 if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
1081 props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
1083 if (getdownAltJavaMaxVersion != null && getdownAltJavaMaxVersion.length() > 0) {
1084 props.put("getdown_txt_java_max_version", getdownAltJavaMaxVersion)
1086 if (getdownAltMultiJavaLocation != null && getdownAltMultiJavaLocation.length() > 0) {
1087 props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
1090 props.put("getdown_txt_title", jalview_name)
1091 props.put("getdown_txt_ui.name", install4jApplicationName)
1093 // start with appbase
1094 getdownTextString += "appbase = ${getdownAppBase}\n"
1095 props.each{ prop, val ->
1096 if (prop.startsWith("getdown_txt_") && val != null) {
1097 if (prop.startsWith("getdown_txt_multi_")) {
1098 def key = prop.substring(18)
1099 val.split(",").each{ v ->
1100 def line = "${key} = ${v}\n"
1101 getdownTextString += line
1104 // file values rationalised
1105 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1107 if (val.indexOf('/') == 0) {
1110 } else if (val.indexOf('/') > 0) {
1111 // relative path (relative to jalviewDir)
1112 r = file( "${jalviewDir}/${val}" )
1115 val = "${getdown_resource_dir}/" + r.getName()
1116 getdownWebsiteResourceFilenames += val
1117 getdownResourceFilenames += r.getPath()
1120 if (! prop.startsWith("getdown_txt_resource")) {
1121 def line = prop.substring(12) + " = ${val}\n"
1122 getdownTextString += line
1128 getdownWebsiteResourceFilenames.each{ filename ->
1129 getdownTextString += "resource = ${filename}\n"
1131 getdownResourceFilenames.each{ filename ->
1134 into getdownResourceDir
1139 fileTree(file(packageDir)).each{ f ->
1140 if (f.isDirectory()) {
1141 def files = fileTree(dir: f, include: ["*"]).getFiles()
1143 } else if (f.exists()) {
1147 codeFiles.sort().each{f ->
1148 def name = f.getName()
1149 def line = "code = ${getdownAppDistDir}/${name}\n"
1150 getdownTextString += line
1157 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1159 if (JAVA_VERSION.equals("11")) {
1160 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1161 j11libFiles.sort().each{f ->
1162 def name = f.getName()
1163 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1164 getdownTextString += line
1167 into getdownJ11libDir
1173 // 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.
1174 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1175 getdownTextString += "resource = ${getdown_launcher_new}\n"
1176 getdownTextString += "class = ${mainClass}\n"
1178 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1179 getdown_txt.write(getdownTextString)
1181 def getdownLaunchJvl = getdown_launch_jvl_name + ( (jvlChannelName != null && jvlChannelName.length() > 0)?"-${jvlChannelName}":"" ) + ".jvl"
1182 def launchJvl = file("${getdownWebsiteDir}/${getdownLaunchJvl}")
1183 launchJvl.write("appbase=${getdownAppBase}")
1186 from getdownLauncher
1187 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1188 into getdownWebsiteDir
1192 from getdownLauncher
1193 if (file(getdownLauncher).getName() != getdown_launcher) {
1194 rename(file(getdownLauncher).getName(), getdown_launcher)
1196 into getdownWebsiteDir
1199 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1202 from getdownLauncher
1203 from "${getdownWebsiteDir}/${getdown_build_properties}"
1204 if (file(getdownLauncher).getName() != getdown_launcher) {
1205 rename(file(getdownLauncher).getName(), getdown_launcher)
1207 into getdownInstallDir
1211 from getdownInstallDir
1212 into getdownFilesInstallDir
1219 from getdownLauncher
1220 from "${getdownWebsiteDir}/${getdown_build_properties}"
1221 if (file(getdownLauncher).getName() != getdown_launcher) {
1222 rename(file(getdownLauncher).getName(), getdown_launcher)
1224 into getdownFilesDir
1228 from getdownResourceDir
1229 into "${getdownFilesDir}/${getdown_resource_dir}"
1234 inputs.dir("${jalviewDir}/${packageDir}")
1236 outputs.dir(getdownWebsiteDir)
1237 outputs.dir(getdownFilesDir)
1241 // a helper task to allow getdown digest of any dir: `gradle getdownDigestDir -PDIGESTDIR=/path/to/my/random/getdown/dir
1242 task getdownDigestDir(type: JavaExec) {
1243 def digestDirPropertyName = "DIGESTDIR"
1244 description = "Digest a local dir (-P${digestDirPropertyName}=...) for getdown"
1246 classpath = files(getdownLauncher)
1247 def digestDir = findProperty(digestDirPropertyName)
1248 if (digestDir == null) {
1249 throw new GradleException("Must provide a DIGESTDIR value to produce an alternative getdown digest")
1253 main = "com.threerings.getdown.tools.Digester"
1257 task getdownDigest(type: JavaExec) {
1258 group = "distribution"
1259 description = "Digest the getdown website folder"
1260 dependsOn getdownWebsite
1262 classpath = files(getdownLauncher)
1264 main = "com.threerings.getdown.tools.Digester"
1265 args getdownWebsiteDir
1266 inputs.dir(getdownWebsiteDir)
1267 outputs.file("${getdownWebsiteDir}/digest2.txt")
1272 group = "distribution"
1273 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1274 dependsOn getdownDigest
1276 if (reportRsyncCommand) {
1277 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1278 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1279 println "LIKELY RSYNC COMMAND:"
1280 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1281 if (RUNRSYNC == "true") {
1283 commandLine "mkdir", "-p", toDir
1286 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1296 delete getdownWebsiteDir
1297 delete getdownFilesDir
1303 if (file(install4jHomeDir).exists()) {
1305 } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1306 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1307 } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1308 install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1310 installDir(file(install4jHomeDir))
1312 mediaTypes = Arrays.asList(install4j_media_types.split(","))
1316 task copyInstall4jTemplate {
1317 def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
1318 def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1319 inputs.file(install4jTemplateFile)
1320 inputs.file(install4jFileAssociationsFile)
1321 outputs.file(install4jConfFile)
1324 def install4jConfigXml = new XmlParser().parse(install4jTemplateFile)
1326 // turn off code signing if no OSX_KEYPASS
1327 if (OSX_KEYPASS == "") {
1328 install4jConfigXml.'**'.codeSigning.each { codeSigning ->
1329 codeSigning.'@macEnabled' = "false"
1331 install4jConfigXml.'**'.windows.each { windows ->
1332 windows.'@runPostProcessor' = "false"
1336 // turn off checksum creation for LOCAL channel
1337 def e = install4jConfigXml.application[0]
1338 if (CHANNEL == "LOCAL") {
1339 e.'@createChecksums' = "false"
1341 e.'@createChecksums' = "true"
1344 // put file association actions where placeholder action is
1345 def install4jFileAssociationsText = install4jFileAssociationsFile.text
1346 def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
1347 install4jConfigXml.'**'.action.any { a ->
1348 if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1349 def parent = a.parent()
1351 fileAssociationActions.each { faa ->
1354 // don't need to continue in .any loop once replacements have been made
1359 // write install4j file
1360 install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
1367 delete install4jConfFile
1372 task installers(type: com.install4j.gradle.Install4jTask) {
1373 group = "distribution"
1374 description = "Create the install4j installers"
1375 dependsOn setGitVals
1377 dependsOn copyInstall4jTemplate
1379 projectFile = install4jConfFile
1381 // create an md5 for the input files to use as version for install4j conf file
1382 def digest = MessageDigest.getInstance("MD5")
1384 (file("${install4jDir}/${install4j_template}").text +
1385 file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1386 file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1387 def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1388 if (filesMd5.length() >= 8) {
1389 filesMd5 = filesMd5.substring(0,8)
1391 def install4jTemplateVersion = "${JALVIEW_VERSION}_F${filesMd5}_C${gitHash}"
1392 // make install4jBuildDir relative to jalviewDir
1393 def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
1396 'JALVIEW_NAME': install4jApplicationName,
1397 'JALVIEW_DIR': "../..",
1398 'OSX_KEYSTORE': OSX_KEYSTORE,
1399 'JSIGN_SH': JSIGN_SH,
1400 'JRE_DIR': getdown_app_dir_java,
1401 'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1402 'JALVIEW_VERSION': JALVIEW_VERSION,
1403 'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1404 'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1405 'JAVA_VERSION': JAVA_VERSION,
1406 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1407 'VERSION': JALVIEW_VERSION,
1408 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1409 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1410 'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
1411 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1412 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1413 'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
1414 'COPYRIGHT_MESSAGE': install4j_copyright_message,
1415 'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1416 'MACOS_DS_STORE': install4jDSStore,
1417 'MACOS_DMG_BG_IMAGE': install4jDMGBackgroundImage,
1418 'INSTALLER_NAME': install4jInstallerName,
1419 'INSTALL4J_UTILS_DIR': install4j_utils_dir,
1420 'GETDOWN_WEBSITE_DIR': getdown_website_dir,
1421 'GETDOWN_FILES_DIR': getdown_files_dir,
1422 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1423 'GETDOWN_DIST_DIR': getdownAppDistDir,
1424 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1425 'GETDOWN_INSTALL_DIR': getdown_install_dir,
1426 'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
1427 'BUILD_DIR': install4jBuildDir,
1428 'UNIX_DESKTOP_ADDITIONS': install4j_unix_desktop_additions,
1429 'APPLICATION_FOLDER': install4jApplicationFolder,
1430 'UNIX_APPLICATION_FOLDER': install4jUnixApplicationFolder,
1431 'EXECUTABLE_NAME': install4jExecutableName,
1434 destination = "${jalviewDir}/${install4jBuildDir}"
1435 buildSelected = true
1437 if (install4j_faster.equals("true") || CHANNEL.startsWith("LOCAL")) {
1439 disableSigning = true
1443 macKeystorePassword = OSX_KEYPASS
1447 println("Using projectFile "+projectFile)
1450 inputs.dir(getdownWebsiteDir)
1451 inputs.file(install4jConfFile)
1452 inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1453 inputs.dir(macosJavaVMDir)
1454 inputs.dir(windowsJavaVMDir)
1455 outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1459 task sourceDist(type: Tar) {
1461 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1462 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1463 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1465 archiveFileName = outputFileName
1466 } catch (Exception e) {
1467 archiveName = outputFileName
1470 compression Compression.GZIP
1485 "**/*.class","$j11modDir/**/*.jar","appletlib","**/*locales",
1487 "utils/InstallAnywhere",
1502 "gradle.properties",
1513 ".settings/org.eclipse.jdt.core.jalview.prefs",
1517 exclude (EXCLUDE_FILES)
1518 include (PROCESS_FILES)
1519 filter(ReplaceTokens,
1523 'Version-Rel': JALVIEW_VERSION,
1524 'Year-Rel': getDate("yyyy")
1529 exclude (EXCLUDE_FILES)
1530 exclude (PROCESS_FILES)
1531 exclude ("appletlib")
1532 exclude ("**/*locales")
1533 exclude ("*locales/**")
1534 exclude ("utils/InstallAnywhere")
1536 exclude (getdown_files_dir)
1537 exclude (getdown_website_dir)
1539 // exluding these as not using jars as modules yet
1540 exclude ("$j11modDir/**/*.jar")
1543 include(INCLUDE_FILES)
1545 // from (jalviewDir) {
1546 // // explicit includes for stuff that seemed to not get included
1547 // include(fileTree("test/**/*."))
1548 // exclude(EXCLUDE_FILES)
1549 // exclude(PROCESS_FILES)
1556 dependsOn pubhtmlhelp
1558 inputs.dir("${classesDir}/${help_dir}")
1559 outputs.dir("${buildDir}/distributions/${help_dir}")
1562 // LARGE AMOUNT OF JALVIEWJS STUFF DELETED HERE
1563 task eclipseAutoBuildTask {}
1564 task eclipseSynchronizationTask {}