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
38 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
39 def string(Object o) {
40 return o == null ? "" : o.toString()
45 jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
46 jalviewDirRelativePath = jalviewDir
48 // local build environment properties
49 def localProps = "${jalviewDirAbsolutePath}/local.properties"
50 if (file(localProps).exists()) {
52 def p = new Properties()
53 def localPropsFIS = new FileInputStream(localProps)
58 def oldval = findProperty(key)
61 println("Overriding property '${key}' ('${oldval}') with local.properties value '${val}'")
63 println("Setting unknown property '${key}' with local.properties value '${val}'")
66 } catch (Exception e) {
67 System.out.println("Exception reading local.properties")
71 // this property set when running Eclipse headlessly
72 j2sHeadlessBuildProperty = string("net.sf.j2s.core.headlessbuild")
73 // this property set by Eclipse
74 eclipseApplicationProperty = string("eclipse.application")
75 // CHECK IF RUNNING FROM WITHIN ECLIPSE
76 def eclipseApplicationPropertyVal = System.properties[eclipseApplicationProperty]
77 IN_ECLIPSE = eclipseApplicationPropertyVal != null && eclipseApplicationPropertyVal.startsWith("org.eclipse.ui.")
78 // BUT WITHOUT THE HEADLESS BUILD PROPERTY SET
79 if (System.properties[j2sHeadlessBuildProperty].equals("true")) {
80 println("Setting IN_ECLIPSE to ${IN_ECLIPSE} as System.properties['${j2sHeadlessBuildProperty}'] == '${System.properties[j2sHeadlessBuildProperty]}'")
84 println("WITHIN ECLIPSE IDE")
86 println("HEADLESS BUILD")
89 System.properties.sort { it.key }.each {
90 key, val -> println("SYSTEM PROPERTY ${key}='${val}'")
93 if (false && IN_ECLIPSE) {
94 jalviewDir = jalviewDirAbsolutePath
99 bareSourceDir = string(source_dir)
100 sourceDir = string("${jalviewDir}/${bareSourceDir}")
101 resourceDir = string("${jalviewDir}/${resource_dir}")
102 bareTestSourceDir = string(test_source_dir)
103 testSourceDir = string("${jalviewDir}/${bareTestSourceDir}")
106 cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
107 classesDir = string("${jalviewDir}/${classes_dir}")
108 if (clover.equals("true")) {
110 classesDir = string("${buildDir}/${cloverClassesDir}")
113 classesDir = string("${jalviewDir}/${classes_dir}")
118 getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
121 // the following values might be overridden by the CHANNEL switch
122 getdownChannelName = CHANNEL.toLowerCase()
123 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
124 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
125 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
126 getdownAppDistDir = getdown_app_dir_alt
127 buildProperties = string("${classesDir}/${build_properties_file}")
128 reportRsyncCmd = false
132 // TODO: get bamboo build artifact URL for getdown artifacts
133 getdown_channel_base = bamboo_channelbase
134 getdownChannelName = string("${bamboo_planKey}/${JAVA_VERSION}")
135 getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
139 getdownAppDistDir = getdown_app_dir_release
140 reportRsyncCommand = true
144 getdownChannelName = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
145 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
146 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
147 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
148 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
150 packageDir = string("${ARCHIVEDIR}/${packageDir}")
151 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
154 reportRsyncCommand = true
158 getdownChannelName = string("archive/${JALVIEW_VERSION}")
159 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
160 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
161 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
162 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
164 packageDir = string("${ARCHIVEDIR}/${packageDir}")
165 buildProperties = string("${ARCHIVEDIR}/${classes_dir}/${build_properties_file}")
168 reportRsyncCommand = true
169 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
173 reportRsyncCommand = true
177 reportRsyncCommand = true
180 case ~/^SCRATCH(|-[-\w]*)$/:
181 getdownChannelName = CHANNEL
182 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
183 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
184 reportRsyncCommand = true
188 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
189 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
192 default: // something wrong specified
193 throw new GradleException("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
197 // override getdownAppBase if requested
198 if (findProperty("getdown_appbase_override") != null) {
199 getdownAppBase = string(getProperty("getdown_appbase_override"))
200 println("Overriding getdown appbase with '${getdownAppBase}'")
203 getdownAppDir = string("${getdownWebsiteDir}/${getdownAppDistDir}")
204 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
205 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
206 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
207 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
208 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
209 /* compile without modules -- using classpath libraries
210 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
211 modules_runtimeClasspath = modules_compileClasspath
214 gitBranch = string("")
216 println("Using a ${CHANNEL} profile.")
218 additional_compiler_args = []
219 // configure classpath/args for j8/j11 compilation
220 if (JAVA_VERSION.equals("1.8")) {
221 JAVA_INTEGER_VERSION = string("8")
224 libDistDir = j8libDir
225 compile_source_compatibility = 1.8
226 compile_target_compatibility = 1.8
227 // these are getdown.txt properties defined dependent on the JAVA_VERSION
228 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java8_min_version"))
229 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java8_max_version"))
230 // this property is assigned below and expanded to multiple lines in the getdown task
231 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java8_txt_multi_java_location"))
232 // this property is for the Java library used in eclipse
233 eclipseJavaRuntimeName = string("JavaSE-1.8")
234 } else if (JAVA_VERSION.equals("11")) {
235 JAVA_INTEGER_VERSION = string("11")
237 libDistDir = j11libDir
238 compile_source_compatibility = 11
239 compile_target_compatibility = 11
240 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
241 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
242 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
243 eclipseJavaRuntimeName = string("JavaSE-11")
244 /* compile without modules -- using classpath libraries
245 additional_compiler_args += [
246 '--module-path', modules_compileClasspath.asPath,
247 '--add-modules', j11modules
250 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
251 JAVA_INTEGER_VERSION = JAVA_VERSION
253 libDistDir = j11libDir
254 compile_source_compatibility = JAVA_VERSION
255 compile_target_compatibility = JAVA_VERSION
256 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
257 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
258 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
259 eclipseJavaRuntimeName = string("JavaSE-11")
260 /* compile without modules -- using classpath libraries
261 additional_compiler_args += [
262 '--module-path', modules_compileClasspath.asPath,
263 '--add-modules', j11modules
267 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
272 JAVA_MIN_VERSION = JAVA_VERSION
273 JAVA_MAX_VERSION = JAVA_VERSION
274 def jreInstallsDir = string(jre_installs_dir)
275 if (jreInstallsDir.startsWith("~/")) {
276 jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
278 macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
279 macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-mac-x64.tar.gz")
280 windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
281 windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-windows-x64.tar.gz")
282 linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
283 linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-linux-x64.tar.gz")
284 install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
285 install4jConfFileName = string("jalview-install4j-conf.install4j")
286 install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
287 install4jHomeDir = install4j_home_dir
288 if (install4jHomeDir.startsWith("~/")) {
289 install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
294 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
295 helpFile = string("${classesDir}/${help_dir}/help.jhm")
296 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
297 helpSourceDir = string("${helpParentDir}/${help_dir}")
300 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
301 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
302 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
304 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
306 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
308 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
309 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
310 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
311 jalviewjsJalviewCoreHtmlFile = string("")
312 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
313 jalviewjsCoreClasslists = []
314 jalviewjsJalviewTemplateName = string(jalviewjs_name)
315 jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
316 jalviewjsJ2sProps = null
318 eclipseWorkspace = null
319 eclipseBinary = string("")
320 eclipseVersion = string("")
330 outputDir = file(classesDir)
335 srcDirs += helpParentDir
338 jar.destinationDir = file("${jalviewDir}/${packageDir}")
340 compileClasspath = files(sourceSets.main.java.outputDir)
341 //compileClasspath += files(sourceSets.main.resources.srcDirs)
342 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
344 runtimeClasspath = compileClasspath
349 srcDirs = [ cloverInstrDir ]
350 outputDir = file("${buildDir}/${cloverClassesDir}")
354 srcDirs = sourceSets.main.resources.srcDirs
356 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
357 compileClasspath += files(sourceSets.main.java.outputDir)
358 compileClasspath += sourceSets.main.compileClasspath
359 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
360 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
362 runtimeClasspath = compileClasspath
367 srcDirs testSourceDir
368 outputDir = file("${jalviewDir}/${testOutputDir}")
372 srcDirs = sourceSets.main.resources.srcDirs
375 compileClasspath = files( sourceSets.test.java.outputDir )
378 compileClasspath += sourceSets.clover.compileClasspath
380 compileClasspath += files(sourceSets.main.java.outputDir)
383 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
384 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
385 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
387 runtimeClasspath = compileClasspath
395 cloverCompile 'org.openclover:clover:4.3.1'
396 testCompile 'org.openclover:clover:4.3.1'
403 cloverRuntime.extendsFrom cloverCompile
408 name = eclipse_project_name
410 natures 'org.eclipse.jdt.core.javanature',
411 'org.eclipse.jdt.groovy.core.groovyNature',
412 'org.eclipse.buildship.core.gradleprojectnature'
414 buildCommand 'org.eclipse.jdt.core.javabuilder'
415 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
419 //defaultOutputDir = sourceSets.main.java.outputDir
422 if (it.isCanBeResolved()) {
427 minusConfigurations += removeThese
428 plusConfigurations = [ ]
432 def removeTheseToo = []
433 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
434 cp.entries.each { entry ->
435 // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
436 // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
437 // we add the resources and help/help dirs in as libs afterwards (see below)
438 if (entry.kind == 'src') {
439 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
440 removeTheseToo += entry
442 alreadyAddedSrcPath.putAt(entry.path, true)
447 cp.entries.removeAll(removeTheseToo)
449 //cp.entries += new Output("${eclipse_bin_dir}/main")
450 if (file(helpParentDir).isDirectory()) {
451 cp.entries += new Library(fileReference(helpParentDir))
453 if (file(resourceDir).isDirectory()) {
454 cp.entries += new Library(fileReference(resourceDir))
457 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
459 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
460 //don't want to add outputDir as eclipse is using its own output dir in bin/main
461 if (it.isDirectory() || ! it.exists()) {
462 // don't add dirs to classpath, especially if they don't exist
463 return false // groovy "continue" in .any closure
465 def itPath = it.toString()
466 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
467 // make relative path
468 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
470 if (alreadyAddedLibPath.get(itPath)) {
471 //println("Not adding duplicate entry "+itPath)
473 //println("Adding entry "+itPath)
474 cp.entries += new Library(fileReference(itPath))
475 alreadyAddedLibPath.put(itPath, true)
479 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
480 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
481 if (it.isDirectory() || ! it.exists()) {
482 // don't add dirs to classpath
483 return false // groovy "continue" in .any closure
486 def itPath = it.toString()
487 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
488 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
490 if (alreadyAddedLibPath.get(itPath)) {
493 def lib = new Library(fileReference(itPath))
494 lib.entryAttributes["test"] = "true"
496 alreadyAddedLibPath.put(itPath, true)
504 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
509 // for the IDE, use java 11 compatibility
510 sourceCompatibility = compile_source_compatibility
511 targetCompatibility = compile_target_compatibility
512 javaRuntimeName = eclipseJavaRuntimeName
514 // add in jalview project specific properties/preferences into eclipse core preferences
516 withProperties { props ->
517 def jalview_prefs = new Properties()
518 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
519 jalview_prefs.load(ins)
521 jalview_prefs.forEach { t, v ->
522 if (props.getAt(t) == null) {
532 // Don't want these to be activated if in headless build
533 synchronizationTasks "eclipseSynchronizationTask"
534 autoBuildTasks "eclipseAutoBuildTask"
541 // only instrument source, we build test classes as normal
542 inputs.files files (sourceSets.main.allJava) // , fileTree(dir: testSourceDir, include: ["**/*.java"]))
543 outputs.dir cloverInstrDir
546 delete cloverInstrDir
547 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
548 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
549 argsList.addAll(inputs.files.files.collect({ file ->
552 String[] args = argsList.toArray()
553 println("About to instrument "+args.length +" files")
554 com.atlassian.clover.CloverInstr.mainImpl(args)
560 group = "Verification"
561 description = "Createst the Clover report"
562 inputs.dir "${buildDir}/clover"
563 outputs.dir "${reportsDir}/clover"
565 file("${buildDir}/clover/clover.db").exists()
568 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
569 "-o", "${reportsDir}/clover"]
570 String[] args = argsList.toArray()
571 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
573 // and generate ${reportsDir}/clover/clover.xml
574 args = ["--initstring", "${buildDir}/clover/clover.db",
575 "-o", "${reportsDir}/clover/clover.xml"].toArray()
576 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
585 sourceCompatibility = compile_source_compatibility
586 targetCompatibility = compile_target_compatibility
587 options.compilerArgs = additional_compiler_args
588 print ("Setting target compatibility to "+targetCompatibility+"\n")
596 dependsOn compileCloverJava
597 classpath += configurations.cloverRuntime
599 classpath += sourceSets.main.runtimeClasspath
602 sourceCompatibility = compile_source_compatibility
603 targetCompatibility = compile_target_compatibility
604 options.compilerArgs = additional_compiler_args
605 print ("Setting target compatibility to "+targetCompatibility+"\n")
613 sourceCompatibility = compile_source_compatibility
614 targetCompatibility = compile_target_compatibility
615 options.compilerArgs += additional_compiler_args
616 print ("Setting target compatibility to "+targetCompatibility+"\n")
618 classpath += configurations.cloverRuntime
624 delete sourceSets.main.java.outputDir
631 delete sourceSets.test.java.outputDir
632 delete cloverInstrDir
637 // format is a string like date.format("dd MMMM yyyy")
638 def getDate(format) {
639 def date = new Date()
640 return date.format(format)
645 def hashStdOut = new ByteArrayOutputStream()
647 commandLine "git", "rev-parse", "--short", "HEAD"
648 standardOutput = hashStdOut
652 def branchStdOut = new ByteArrayOutputStream()
654 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
655 standardOutput = branchStdOut
659 gitHash = hashStdOut.toString().trim()
660 gitBranch = branchStdOut.toString().trim()
662 outputs.upToDateWhen { false }
666 task createBuildProperties(type: WriteProperties) {
668 inputs.dir(sourceDir)
669 inputs.dir(resourceDir)
670 file(buildProperties).getParentFile().mkdirs()
671 outputFile (buildProperties)
672 // taking time specific comment out to allow better incremental builds
673 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
674 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
675 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
676 property "VERSION", JALVIEW_VERSION
677 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
678 outputs.file(outputFile)
682 task cleanBuildingHTML(type: Delete) {
689 task convertBuildingMD(type: Exec) {
690 dependsOn cleanBuildingHTML
691 def buildingMD = "${jalviewDir}/${docDir}/building.md"
692 def css = "${jalviewDir}/${docDir}/github.css"
695 pandoc_exec.split(",").each {
696 if (file(it.trim()).exists()) {
702 def hostname = "hostname".execute().text.trim()
703 def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
704 if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
705 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
709 if (pandoc != null && file(pandoc).exists()) {
710 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
712 println("Cannot find pandoc. Skipping convert building.md to HTML")
713 throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
719 inputs.file(buildingMD)
721 outputs.file(buildingHTML)
732 task syncDocs(type: Sync) {
733 dependsOn convertBuildingMD
734 def syncDir = "${classesDir}/${docDir}"
735 from fileTree("${jalviewDir}/${docDir}")
741 task copyHelp(type: Copy) {
742 def inputDir = helpSourceDir
743 def outputDir = "${classesDir}/${help_dir}"
748 filter(ReplaceTokens,
752 'Version-Rel': JALVIEW_VERSION,
753 'Year-Rel': getDate("yyyy")
765 outputs.files(helpFile)
766 outputs.dir(outputDir)
770 task syncLib(type: Sync) {
771 def syncDir = "${classesDir}/${libDistDir}"
772 from fileTree("${jalviewDir}/${libDistDir}")
777 task syncResources(type: Sync) {
788 dependsOn syncResources
794 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
797 dependsOn compileJava
799 dependsOn cloverInstr
803 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
807 includeGroups testngGroups
809 useDefaultListeners=true
812 workingDir = jalviewDir
813 //systemProperties 'clover.jar' System.properties.clover.jar
814 sourceCompatibility = compile_source_compatibility
815 targetCompatibility = compile_target_compatibility
816 jvmArgs += additional_compiler_args
821 task buildIndices(type: JavaExec) {
823 classpath = sourceSets.main.compileClasspath
824 main = "com.sun.java.help.search.Indexer"
825 workingDir = "${classesDir}/${help_dir}"
828 inputs.dir("${workingDir}/${argDir}")
830 outputs.dir("${classesDir}/doc")
831 outputs.dir("${classesDir}/help")
832 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
833 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
834 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
835 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
836 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
837 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
841 task compileLinkCheck(type: JavaCompile) {
843 classpath = files("${jalviewDir}/${utilsDir}")
844 destinationDir = file("${jalviewDir}/${utilsDir}")
845 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
847 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
848 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
849 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
850 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
854 task linkCheck(type: JavaExec) {
855 dependsOn prepare, compileLinkCheck
857 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
858 classpath = files("${jalviewDir}/${utilsDir}")
859 main = "HelpLinksChecker"
860 workingDir = jalviewDir
861 args = [ "${classesDir}/${help_dir}", "-nointernet" ]
863 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
865 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
868 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
872 inputs.dir("${classesDir}/${help_dir}")
873 outputs.file(helpLinksCheckerOutFile)
876 // import the pubhtmlhelp target
877 ant.properties.basedir = "${jalviewDir}"
878 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
879 ant.importBuild "${utilsDir}/publishHelp.xml"
882 task cleanPackageDir(type: Delete) {
884 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
890 dependsOn buildIndices
891 dependsOn createBuildProperties
894 attributes "Main-Class": mainClass,
895 "Permissions": "all-permissions",
896 "Application-Name": "Jalview Desktop",
897 "Codebase": application_codebase
900 destinationDir = file("${jalviewDir}/${packageDir}")
901 archiveName = rootProject.name+".jar"
909 inputs.dir(classesDir)
910 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
914 task copyJars(type: Copy) {
915 from fileTree(dir: classesDir, include: "**/*.jar").files
916 into "${jalviewDir}/${packageDir}"
920 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
921 task syncJars(type: Sync) {
922 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
923 into "${jalviewDir}/${packageDir}"
925 include jar.archiveName
932 description = "Put all required libraries in dist"
933 // order of "cleanPackageDir", "copyJars", "jar" important!
934 jar.mustRunAfter cleanPackageDir
935 syncJars.mustRunAfter cleanPackageDir
936 dependsOn cleanPackageDir
939 outputs.dir("${jalviewDir}/${packageDir}")
944 dependsOn cleanPackageDir
950 group = "distribution"
954 from ("${jalviewDir}/${libDistDir}") {
958 attributes 'Implementation-Version': JALVIEW_VERSION
960 mainClassName = shadowJarMainClass
962 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
967 task getdownWebsite() {
968 group = "distribution"
969 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
974 def getdownWebsiteResourceFilenames = []
975 def getdownTextString = ""
976 def getdownResourceDir = getdownResourceDir
977 def getdownResourceFilenames = []
980 // clean the getdown website and files dir before creating getdown folders
981 delete getdownWebsiteDir
982 delete getdownFilesDir
986 rename(build_properties_file, getdown_build_properties)
989 getdownWebsiteResourceFilenames += "${getdownAppDistDir}/${getdown_build_properties}"
991 // go through properties looking for getdown_txt_...
992 def props = project.properties.sort { it.key }
993 if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
994 props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
996 if (getdownAltJavaMaxVersion != null && getdownAltJavaMaxVersion.length() > 0) {
997 props.put("getdown_txt_java_max_version", getdownAltJavaMaxVersion)
999 if (getdownAltMultiJavaLocation != null && getdownAltMultiJavaLocation.length() > 0) {
1000 props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
1003 props.put("getdown_txt_appbase", getdownAppBase)
1004 props.each{ prop, val ->
1005 if (prop.startsWith("getdown_txt_") && val != null) {
1006 if (prop.startsWith("getdown_txt_multi_")) {
1007 def key = prop.substring(18)
1008 val.split(",").each{ v ->
1009 def line = "${key} = ${v}\n"
1010 getdownTextString += line
1013 // file values rationalised
1014 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1016 if (val.indexOf('/') == 0) {
1019 } else if (val.indexOf('/') > 0) {
1020 // relative path (relative to jalviewDir)
1021 r = file( "${jalviewDir}/${val}" )
1024 val = "${getdown_resource_dir}/" + r.getName()
1025 getdownWebsiteResourceFilenames += val
1026 getdownResourceFilenames += r.getPath()
1029 if (! prop.startsWith("getdown_txt_resource")) {
1030 def line = prop.substring(12) + " = ${val}\n"
1031 getdownTextString += line
1037 getdownWebsiteResourceFilenames.each{ filename ->
1038 getdownTextString += "resource = ${filename}\n"
1040 getdownResourceFilenames.each{ filename ->
1043 into getdownResourceDir
1048 fileTree(file(packageDir)).each{ f ->
1049 if (f.isDirectory()) {
1050 def files = fileTree(dir: f, include: ["*"]).getFiles()
1052 } else if (f.exists()) {
1056 codeFiles.sort().each{f ->
1057 def name = f.getName()
1058 def line = "code = ${getdownAppDistDir}/${name}\n"
1059 getdownTextString += line
1066 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1068 if (JAVA_VERSION.equals("11")) {
1069 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1070 j11libFiles.sort().each{f ->
1071 def name = f.getName()
1072 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1073 getdownTextString += line
1076 into getdownJ11libDir
1082 // 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.
1083 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1084 getdownTextString += "resource = ${getdown_launcher_new}\n"
1085 getdownTextString += "class = ${mainClass}\n"
1087 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1088 getdown_txt.write(getdownTextString)
1090 def getdownLaunchJvl = ( (getdownChannelName != null && getdownChannelName.length() > 0)?"${getdownChannelName}_":"" ) + getdown_launch_jvl
1091 def launch_jvl = file("${getdownWebsiteDir}/${getdown_launch_jvl}")
1092 launch_jvl.write("appbase="+props.get("getdown_txt_appbase"))
1095 from getdownLauncher
1096 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1097 into getdownWebsiteDir
1101 from getdownLauncher
1102 if (file(getdownLauncher).getName() != getdown_launcher) {
1103 rename(file(getdownLauncher).getName(), getdown_launcher)
1105 into getdownWebsiteDir
1108 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1111 from getdownLauncher
1112 from "${getdownWebsiteDir}/${getdown_build_properties}"
1113 if (file(getdownLauncher).getName() != getdown_launcher) {
1114 rename(file(getdownLauncher).getName(), getdown_launcher)
1116 into getdownInstallDir
1120 from getdownInstallDir
1121 into getdownFilesInstallDir
1128 from getdownLauncher
1129 from "${getdownWebsiteDir}/${getdown_build_properties}"
1130 if (file(getdownLauncher).getName() != getdown_launcher) {
1131 rename(file(getdownLauncher).getName(), getdown_launcher)
1133 into getdownFilesDir
1137 from getdownResourceDir
1138 into "${getdownFilesDir}/${getdown_resource_dir}"
1143 inputs.dir("${jalviewDir}/${packageDir}")
1145 outputs.dir(getdownWebsiteDir)
1146 outputs.dir(getdownFilesDir)
1150 task getdownDigest(type: JavaExec) {
1151 group = "distribution"
1152 description = "Digest the getdown website folder"
1153 dependsOn getdownWebsite
1155 classpath = files(getdownLauncher)
1157 main = "com.threerings.getdown.tools.Digester"
1158 args getdownWebsiteDir
1159 inputs.dir(getdownWebsiteDir)
1160 outputs.file("${getdownWebsiteDir}/digest2.txt")
1165 group = "distribution"
1166 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1167 dependsOn getdownDigest
1169 if (reportRsyncCommand) {
1170 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1171 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1172 println "LIKELY RSYNC COMMAND:"
1173 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1174 if (RUNRSYNC == "true") {
1176 commandLine "mkdir", "-p", toDir
1179 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1189 delete getdownWebsiteDir
1190 delete getdownFilesDir
1196 if (file(install4jHomeDir).exists()) {
1198 } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1199 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1200 } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1201 install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1203 installDir(file(install4jHomeDir))
1205 mediaTypes = Arrays.asList(install4j_media_types.split(","))
1209 task copyInstall4jTemplate {
1210 def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
1211 def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1212 inputs.file(install4jTemplateFile)
1213 inputs.file(install4jFileAssociationsFile)
1214 outputs.file(install4jConfFile)
1217 def install4jConfigXml = new XmlParser().parse(install4jTemplateFile)
1219 // turn off code signing if no OSX_KEYPASS
1220 if (OSX_KEYPASS == "") {
1221 install4jConfigXml.'**'.codeSigning.each { codeSigning ->
1222 codeSigning.'@macEnabled' = "false"
1224 install4jConfigXml.'**'.windows.each { windows ->
1225 windows.'@runPostProcessor' = "false"
1229 // turn off checksum creation for LOCAL channel
1230 def e = install4jConfigXml.application[0]
1231 if (CHANNEL == "LOCAL") {
1232 e.'@createChecksums' = "false"
1234 e.'@createChecksums' = "true"
1237 // put file association actions where placeholder action is
1238 def install4jFileAssociationsText = install4jFileAssociationsFile.text
1239 def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
1240 install4jConfigXml.'**'.action.any { a ->
1241 if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1242 def parent = a.parent()
1244 fileAssociationActions.each { faa ->
1247 // don't need to continue in .any loop once replacements have been made
1252 // write install4j file
1253 install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
1260 delete install4jConfFile
1265 task installers(type: com.install4j.gradle.Install4jTask) {
1266 group = "distribution"
1267 description = "Create the install4j installers"
1268 dependsOn setGitVals
1270 dependsOn copyInstall4jTemplate
1272 projectFile = install4jConfFile
1274 // create an md5 for the input files to use as version for install4j conf file
1275 def digest = MessageDigest.getInstance("MD5")
1277 (file("${install4jDir}/${install4j_template}").text +
1278 file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1279 file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1280 def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1281 if (filesMd5.length() >= 8) {
1282 filesMd5 = filesMd5.substring(0,8)
1284 def install4jTemplateVersion = "${JALVIEW_VERSION}_F${filesMd5}_C${gitHash}"
1285 // make install4jBuildDir relative to jalviewDir
1286 def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
1289 'JALVIEW_NAME': getdown_txt_title,
1290 'JALVIEW_DIR': "../..",
1291 'OSX_KEYSTORE': OSX_KEYSTORE,
1292 'JSIGN_SH': JSIGN_SH,
1293 'JRE_DIR': getdown_app_dir_java,
1294 'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1295 'JALVIEW_VERSION': JALVIEW_VERSION,
1296 'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1297 'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1298 'JAVA_VERSION': JAVA_VERSION,
1299 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1300 'VERSION': JALVIEW_VERSION,
1301 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1302 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1303 'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
1304 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1305 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1306 'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
1307 'COPYRIGHT_MESSAGE': install4j_copyright_message,
1308 'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1309 'INSTALLER_NAME': install4j_installer_name,
1310 'INSTALL4J_UTILS_DIR': install4j_utils_dir,
1311 'GETDOWN_WEBSITE_DIR': getdown_website_dir,
1312 'GETDOWN_FILES_DIR': getdown_files_dir,
1313 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1314 'GETDOWN_DIST_DIR': getdownAppDistDir,
1315 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1316 'GETDOWN_INSTALL_DIR': getdown_install_dir,
1317 'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
1318 'BUILD_DIR': install4jBuildDir,
1321 destination = "${jalviewDir}/${install4jBuildDir}"
1322 buildSelected = true
1324 if (install4j_faster.equals("true") || CHANNEL.startsWith("LOCAL")) {
1326 disableSigning = true
1330 macKeystorePassword = OSX_KEYPASS
1334 println("Using projectFile "+projectFile)
1337 inputs.dir(getdownWebsiteDir)
1338 inputs.file(install4jConfFile)
1339 inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1340 inputs.dir(macosJavaVMDir)
1341 inputs.dir(windowsJavaVMDir)
1342 outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1346 task sourceDist(type: Tar) {
1348 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1349 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1350 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1352 archiveFileName = outputFileName
1353 } catch (Exception e) {
1354 archiveName = outputFileName
1357 compression Compression.GZIP
1361 def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1366 ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1368 ,"utils/InstallAnywhere"]
1369 def PROCESS_FILES=[ "AUTHORS",
1377 "THIRDPARTYLIBS","TESTNG",
1379 "gradle.properties",
1390 exclude (EXCLUDE_FILES)
1391 include (PROCESS_FILES)
1392 filter(ReplaceTokens,
1396 'Version-Rel': JALVIEW_VERSION,
1397 'Year-Rel': getDate("yyyy")
1402 exclude (EXCLUDE_FILES)
1403 exclude (PROCESS_FILES)
1404 exclude ("appletlib")
1405 exclude ("**/*locales")
1406 exclude ("*locales/**")
1407 exclude ("utils/InstallAnywhere")
1409 exclude (getdown_files_dir)
1410 exclude (getdown_website_dir)
1412 // exluding these as not using jars as modules yet
1413 exclude ("${j11modDir}/**/*.jar")
1415 // from (jalviewDir) {
1416 // // explicit includes for stuff that seemed to not get included
1417 // include(fileTree("test/**/*."))
1418 // exclude(EXCLUDE_FILES)
1419 // exclude(PROCESS_FILES)
1426 dependsOn pubhtmlhelp
1428 inputs.dir("${classesDir}/${help_dir}")
1429 outputs.dir("${buildDir}/distributions/${help_dir}")
1432 // LARGE AMOUNT OF JALVIEWJS STUFF DELETED HERE
1433 task eclipseAutoBuildTask {}
1434 task eclipseSynchronizationTask {}