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
6 import groovy.transform.ExternalizeMethods
10 classpath 'org.openclover:clover:4.3.1'
18 id 'com.github.johnrengelman.shadow' version '4.0.3'
19 id 'com.install4j.gradle' version '7.0.9'
20 id 'com.dorongold.task-tree' version '1.4' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree
33 compile 'org.apache.commons:commons-compress:1.18'
37 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
38 def string(Object o) {
44 jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
46 // local build environment properties
47 def localProps = "${jalviewDirAbsolutePath}/local.properties"
48 if (file(localProps).exists()) {
50 def p = new Properties()
51 def localPropsFIS = new FileInputStream(localProps)
56 def over = getProperty(key) != null
59 println("Overriding property '${key}' with local.properties value '${val}'")
62 } catch (Exception e) {
63 System.out.println("Exception reading local.properties")
68 // this property set when running Eclipse headlessly
69 j2sHeadlessBuildProperty = string("net.sf.j2s.core.headlessbuild")
70 // this property set by Eclipse
71 eclipseApplicationProperty = string("eclipse.application")
72 // CHECK IF RUNNING FROM WITHIN ECLIPSE
73 def eclipseApplicationPropertyVal = System.properties[eclipseApplicationProperty]
74 IN_ECLIPSE = eclipseApplicationPropertyVal != null && eclipseApplicationPropertyVal.startsWith("org.eclipse.ui.")
75 // BUT WITHOUT THE HEADLESS BUILD PROPERTY SET
76 if (System.properties[j2sHeadlessBuildProperty].equals("true")) {
77 println("Setting IN_ECLIPSE to ${IN_ECLIPSE} as System.properties['${j2sHeadlessBuildProperty}'] == '${System.properties[j2sHeadlessBuildProperty]}'")
81 println("WITHIN ECLIPSE IDE")
83 println("HEADLESS BUILD")
86 System.properties.sort { it.key }.each {
87 key, val -> println("SYSTEM PROPERTY ${key}='${val}'")
91 cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
92 classes = string("${jalviewDir}/${classesDir}")
93 if (clover.equals("true")) {
95 classes = string("${buildDir}/${cloverClassesDir}")
98 classes = string("${jalviewDir}/${classesDir}")
101 getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
102 getdownDir = string("")
103 reportRsyncCmd = false
105 buildProperties = build_properties_file
106 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
110 // TODO: get bamboo build artifact URL for getdown artifacts
111 getdown_channel_base = bamboo_channelbase
112 getdown_channel_name = string("${bamboo_planKey}/${JAVA_VERSION}")
113 getdown_app_base = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
114 getdown_app_dir = getdown_app_dir_alt
115 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
119 getdown_channel_name = CHANNEL.toLowerCase()
120 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
121 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
122 getdown_app_dir = getdown_app_dir_release
123 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
124 reportRsyncCommand = true
128 getdown_channel_name = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
129 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
130 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
131 getdown_app_dir = getdown_app_dir_alt
132 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
133 print "Must provide an ARCHIVEDIR value to produce an archive distribution"
136 packageDir = string("${ARCHIVEDIR}/${packageDir}")
137 buildProperties = string("${ARCHIVEDIR}/${classesDir}/${build_properties_file}")
140 reportRsyncCommand = true
144 getdown_channel_name = string("archive/${JALVIEW_VERSION}")
145 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
146 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
147 getdown_app_dir = getdown_app_dir_alt
148 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
149 print "Must provide an ARCHIVEDIR value to produce an archive distribution"
152 packageDir = string("${ARCHIVEDIR}/${packageDir}")
153 buildProperties = string("${ARCHIVEDIR}/${classesDir}/${build_properties_file}")
156 reportRsyncCommand = true
157 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
161 getdown_channel_name = CHANNEL.toLowerCase()
162 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
163 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
164 getdown_app_dir = getdown_app_dir_alt
165 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
166 reportRsyncCommand = true
170 getdown_channel_name = CHANNEL.toLowerCase()
171 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
172 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
173 getdown_app_dir = getdown_app_dir_alt
174 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
175 reportRsyncCommand = true
178 case ~/^SCRATCH(|-[-\w]*)$/:
179 getdown_channel_name = CHANNEL
180 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
181 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
182 getdown_app_dir = getdown_app_dir_alt
183 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
184 reportRsyncCommand = true
188 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
189 getdown_app_dir = getdown_app_dir_alt
190 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
191 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
194 default: // something wrong specified
195 print("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
201 getdownAppDir = string("${getdownWebsiteDir}/${getdown_app_dir}")
202 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
203 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
204 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
205 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
206 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
207 /* compile without modules -- using classpath libraries
208 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
209 modules_runtimeClasspath = modules_compileClasspath
212 gitBranch = string("")
214 println("Using a ${CHANNEL} profile.")
216 additional_compiler_args = []
217 // configure classpath/args for j8/j11 compilation
218 if (JAVA_VERSION.equals("1.8")) {
219 JAVA_INTEGER_VERSION = string("8")
222 libDistDir = j8libDir
223 compile_source_compatibility = 1.8
224 compile_target_compatibility = 1.8
225 // these are getdown.txt properties defined dependent on the JAVA_VERSION
226 getdown_alt_java_min_version = getdown_alt_java8_min_version
227 getdown_alt_java_max_version = getdown_alt_java8_max_version
228 // this property is assigned below and expanded to multiple lines in the getdown task
229 getdown_alt_multi_java_location = getdown_alt_java8_txt_multi_java_location
230 // this property is for the Java library used in eclipse
231 eclipse_java_runtime_name = string("JavaSE-1.8")
232 } else if (JAVA_VERSION.equals("11")) {
233 JAVA_INTEGER_VERSION = string("11")
235 libDistDir = j11libDir
236 compile_source_compatibility = 11
237 compile_target_compatibility = 11
238 getdown_alt_java_min_version = getdown_alt_java11_min_version
239 getdown_alt_java_max_version = getdown_alt_java11_max_version
240 getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
241 eclipse_java_runtime_name = string("JavaSE-11")
242 /* compile without modules -- using classpath libraries
243 additional_compiler_args += [
244 '--module-path', modules_compileClasspath.asPath,
245 '--add-modules', j11modules
248 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
249 JAVA_INTEGER_VERSION = JAVA_VERSION
251 libDistDir = j11libDir
252 compile_source_compatibility = JAVA_VERSION
253 compile_target_compatibility = JAVA_VERSION
254 getdown_alt_java_min_version = getdown_alt_java11_min_version
255 getdown_alt_java_max_version = getdown_alt_java11_max_version
256 getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
257 eclipse_java_runtime_name = string("JavaSE-11")
258 /* compile without modules -- using classpath libraries
259 additional_compiler_args += [
260 '--module-path', modules_compileClasspath.asPath,
261 '--add-modules', j11modules
265 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
270 macosJavaVMDir = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/macos-jre${JAVA_VERSION}/jre")
271 macosJavaVMTgz = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/macos-jre${JAVA_VERSION}.tar.gz")
272 windowsJavaVMDir = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/windows-jre${JAVA_VERSION}/jre")
273 windowsJavaVMTgz = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/windows-jre${JAVA_VERSION}.tar.gz")
274 install4jDir = string("${jalviewDir}/${install4jResourceDir}")
275 install4jConfFileName = string("jalview-installers-java${JAVA_VERSION}.install4j")
276 install4jConfFile = string("${install4jDir}/${install4jConfFileName}")
279 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
280 helpFile = string("${classes}/${helpDir}/help.jhm")
283 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
284 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
285 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
287 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
289 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
291 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
292 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
293 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
294 jalviewjsJalviewCoreHtmlFile = string("")
295 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
296 jalviewjsDefaultCoreName = string(jalviewjs_default_core)
297 jalviewjsCoreClasslists = []
298 jalviewjsJalviewTemplateName = string(jalviewjs_name)
300 eclipseWorkspace = null
301 eclipseBinary = string("")
302 eclipseVersion = string("")
311 srcDirs "${jalviewDir}/${sourceDir}"
312 outputDir = file(project.classes)
316 srcDirs "${jalviewDir}/${resourceDir}"
319 jar.destinationDir = file("${jalviewDir}/${packageDir}")
321 compileClasspath = files(sourceSets.main.java.outputDir)
322 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
324 runtimeClasspath = compileClasspath
329 srcDirs = [ cloverInstrDir ]
330 outputDir = file("${buildDir}/${cloverClassesDir}")
334 srcDirs = sourceSets.main.resources.srcDirs
336 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
337 compileClasspath += files(sourceSets.main.java.outputDir)
338 compileClasspath += sourceSets.main.compileClasspath
339 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
340 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
342 runtimeClasspath = compileClasspath
347 srcDirs "${jalviewDir}/${testSourceDir}"
348 outputDir = file("${jalviewDir}/${testOutputDir}")
352 srcDirs = sourceSets.main.resources.srcDirs
355 compileClasspath = files( sourceSets.test.java.outputDir )
358 compileClasspath += sourceSets.clover.compileClasspath
360 compileClasspath += files(sourceSets.main.java.outputDir)
363 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
364 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
365 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
367 runtimeClasspath = compileClasspath
375 cloverCompile 'org.openclover:clover:4.3.1'
376 testCompile 'org.openclover:clover:4.3.1'
383 cloverRuntime.extendsFrom cloverCompile
388 name = eclipse_project_name
390 natures 'org.eclipse.jdt.core.javanature',
391 'org.eclipse.jdt.groovy.core.groovyNature',
392 'org.eclipse.buildship.core.gradleprojectnature'
394 buildCommand 'org.eclipse.jdt.core.javabuilder'
395 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
399 //defaultOutputDir = sourceSets.main.java.outputDir
402 if (it.isCanBeResolved()) {
407 minusConfigurations += removeThese
408 plusConfigurations = [ ]
412 def removeTheseToo = []
413 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
414 cp.entries.each { entry ->
415 if (entry.kind == 'src') {
416 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == sourceDir || entry.path == testSourceDir)) {
417 removeTheseToo += entry
419 alreadyAddedSrcPath.putAt(entry.path, true)
423 cp.entries.removeAll(removeTheseToo)
425 if (file("${jalviewDir}/${eclipse_bin_dir}/main").isDirectory()) {
426 cp.entries += new Output("${eclipse_bin_dir}/main")
428 if (file(helpParentDir).isDirectory()) {
429 cp.entries += new Library(fileReference(helpParentDir))
431 if (file(resourceDir).isDirectory()) {
432 cp.entries += new Library(fileReference(resourceDir))
435 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
437 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.each {
438 //don't want to add outputDir as eclipse is using its own output dir in bin/main
439 if (it.isDirectory() || ! it.exists()) {
440 // don't add dirs to classpath
443 def itPath = it.toString()
444 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
445 // make relative path
446 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
448 if (alreadyAddedLibPath.get(itPath)) {
449 //println("Not adding duplicate entry "+itPath)
451 //println("Adding entry "+itPath)
452 cp.entries += new Library(fileReference(itPath))
453 alreadyAddedLibPath.put(itPath, true)
457 //fileTree(dir: "$jalviewDir/$utilsDir", include: ["test*/*.jar"]).each {
458 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
459 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
460 if (it.isDirectory() || ! it.exists()) {
461 // don't add dirs to classpath
462 return false // groovy "continue" in .any closure
465 def itPath = it.toString()
466 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
467 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
469 if (alreadyAddedLibPath.get(itPath)) {
472 def lib = new Library(fileReference(itPath))
473 lib.entryAttributes["test"] = "true"
475 alreadyAddedLibPath.put(itPath, true)
483 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
488 // for the IDE, use java 11 compatibility
489 sourceCompatibility = compile_source_compatibility
490 targetCompatibility = compile_target_compatibility
491 javaRuntimeName = eclipse_java_runtime_name
493 // add in jalview project specific properties/preferences into eclipse core preferences
495 withProperties { props ->
496 def jalview_prefs = new Properties()
497 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
498 jalview_prefs.load(ins)
500 jalview_prefs.forEach { t, v ->
501 if (props.getAt(t) == null) {
511 // Don't want these to be activated if in headless build
512 //synchronizationTasks "eclipseConfiguration"
513 autoBuildTasks "eclipseAutoBuildTask"
519 // only instrument source, we build test classes as normal
520 inputs.files files (sourceSets.main.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
521 outputs.dir cloverInstrDir
524 delete cloverInstrDir
525 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
526 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
527 argsList.addAll(inputs.files.files.collect({ file ->
530 String[] args = argsList.toArray()
531 println("About to instrument "+args.length +" files")
532 com.atlassian.clover.CloverInstr.mainImpl(args)
538 group = "Verification"
539 description = "Createst the Clover report"
540 inputs.dir "${buildDir}/clover"
541 outputs.dir "${reportsDir}/clover"
543 file("${buildDir}/clover/clover.db").exists()
546 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
547 "-o", "${reportsDir}/clover"]
548 String[] args = argsList.toArray()
549 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
551 // and generate ${reportsDir}/clover/clover.xml
552 args = ["--initstring", "${buildDir}/clover/clover.db",
553 "-o", "${reportsDir}/clover/clover.xml"].toArray()
554 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
563 sourceCompatibility = compile_source_compatibility
564 targetCompatibility = compile_target_compatibility
565 options.compilerArgs = additional_compiler_args
566 print ("Setting target compatibility to "+targetCompatibility+"\n")
574 dependsOn compileCloverJava
575 classpath += configurations.cloverRuntime
577 classpath += sourceSets.main.runtimeClasspath
580 sourceCompatibility = compile_source_compatibility
581 targetCompatibility = compile_target_compatibility
582 options.compilerArgs = additional_compiler_args
583 print ("Setting target compatibility to "+targetCompatibility+"\n")
591 sourceCompatibility = compile_source_compatibility
592 targetCompatibility = compile_target_compatibility
593 options.compilerArgs += additional_compiler_args
594 print ("Setting target compatibility to "+targetCompatibility+"\n")
596 classpath += configurations.cloverRuntime
602 delete sourceSets.main.java.outputDir
609 delete sourceSets.test.java.outputDir
610 delete cloverInstrDir
615 // format is a string like date.format("dd MMMM yyyy")
616 def getDate(format) {
617 def date = new Date()
618 return date.format(format)
623 def hashStdOut = new ByteArrayOutputStream()
625 commandLine "git", "rev-parse", "--short", "HEAD"
626 standardOutput = hashStdOut
630 def branchStdOut = new ByteArrayOutputStream()
632 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
633 standardOutput = branchStdOut
637 gitHash = hashStdOut.toString().trim()
638 gitBranch = branchStdOut.toString().trim()
640 outputs.upToDateWhen { false }
644 task createBuildProperties(type: WriteProperties) {
646 inputs.dir("${jalviewDir}/${sourceDir}")
647 inputs.dir("${jalviewDir}/${resourceDir}")
648 file(buildProperties).getParentFile().mkdirs()
649 outputFile (buildProperties)
650 // taking time specific comment out to allow better incremental builds
651 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
652 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
653 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
654 property "VERSION", JALVIEW_VERSION
655 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
656 outputs.file(outputFile)
660 task cleanBuildingHTML(type: Delete) {
667 task convertBuildingMD(type: Exec) {
668 dependsOn cleanBuildingHTML
669 def buildingMD = "${jalviewDir}/${docDir}/building.md"
670 def css = "${jalviewDir}/${docDir}/github.css"
673 pandoc_exec.split(",").each {
674 if (file(it.trim()).exists()) {
680 def hostname = "hostname".execute().text.trim()
681 if ((pandoc == null || ! file(pandoc).exists()) && hostname.equals("jv-bamboo")) {
682 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
686 if (pandoc != null && file(pandoc).exists()) {
687 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
689 println("Cannot find pandoc. Skipping convert building.md to HTML")
690 throw new StopExecutionException()
696 inputs.file(buildingMD)
698 outputs.file(buildingHTML)
709 task syncDocs(type: Sync) {
710 dependsOn convertBuildingMD
711 def syncDir = "${classes}/${docDir}"
712 from fileTree("${jalviewDir}/${docDir}")
718 task copyHelp(type: Copy) {
719 def inputDir = "${jalviewDir}/${helpParentDir}/${helpDir}"
720 def outputDir = "${classes}/${helpDir}"
725 filter(ReplaceTokens,
729 'Version-Rel': JALVIEW_VERSION,
730 'Year-Rel': getDate("yyyy")
742 outputs.files(helpFile)
743 outputs.dir(outputDir)
747 task syncLib(type: Sync) {
748 def syncDir = "${classes}/${libDistDir}"
749 from fileTree("${jalviewDir}/${libDistDir}")
754 task syncResources(type: Sync) {
755 from "${jalviewDir}/${resourceDir}"
765 dependsOn syncResources
771 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
774 dependsOn compileJava
776 dependsOn cloverInstr
780 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
784 includeGroups testngGroups
786 useDefaultListeners=true
789 workingDir = jalviewDir
790 //systemProperties 'clover.jar' System.properties.clover.jar
791 sourceCompatibility = compile_source_compatibility
792 targetCompatibility = compile_target_compatibility
793 jvmArgs += additional_compiler_args
798 task buildIndices(type: JavaExec) {
800 classpath = sourceSets.main.compileClasspath
801 main = "com.sun.java.help.search.Indexer"
802 workingDir = "${classes}/${helpDir}"
805 inputs.dir("${workingDir}/${argDir}")
807 outputs.dir("${classes}/doc")
808 outputs.dir("${classes}/help")
809 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
810 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
811 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
812 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
813 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
814 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
818 task compileLinkCheck(type: JavaCompile) {
820 classpath = files("${jalviewDir}/${utilsDir}")
821 destinationDir = file("${jalviewDir}/${utilsDir}")
822 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
824 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
825 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
826 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
827 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
831 task linkCheck(type: JavaExec) {
832 dependsOn prepare, compileLinkCheck
834 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
835 classpath = files("${jalviewDir}/${utilsDir}")
836 main = "HelpLinksChecker"
837 workingDir = jalviewDir
838 def help = "${classes}/${helpDir}"
839 args = [ "${classes}/${helpDir}", "-nointernet" ]
841 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
843 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
846 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
850 inputs.dir("${classes}/${helpDir}")
851 outputs.file(helpLinksCheckerOutFile)
854 // import the pubhtmlhelp target
855 ant.properties.basedir = "${jalviewDir}"
856 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes}/${helpDir}"
857 ant.importBuild "${utilsDir}/publishHelp.xml"
860 task cleanPackageDir(type: Delete) {
862 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
868 dependsOn buildIndices
869 dependsOn createBuildProperties
872 attributes "Main-Class": mainClass,
873 "Permissions": "all-permissions",
874 "Application-Name": "Jalview Desktop",
875 "Codebase": application_codebase
878 destinationDir = file("${jalviewDir}/${packageDir}")
879 archiveName = rootProject.name+".jar"
887 inputs.dir("${classes}")
888 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
892 task copyJars(type: Copy) {
893 from fileTree(dir: "${classes}", include: "**/*.jar").files
894 into "${jalviewDir}/${packageDir}"
898 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
899 task syncJars(type: Sync) {
900 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
901 into "${jalviewDir}/${packageDir}"
903 include jar.archiveName
910 description = "Put all required libraries in dist"
911 // order of "cleanPackageDir", "copyJars", "jar" important!
912 jar.mustRunAfter cleanPackageDir
913 syncJars.mustRunAfter cleanPackageDir
914 dependsOn cleanPackageDir
917 outputs.dir("${jalviewDir}/${packageDir}")
922 dependsOn cleanPackageDir
928 group = "distribution"
932 from ("${jalviewDir}/${libDistDir}") {
936 attributes 'Implementation-Version': JALVIEW_VERSION
938 mainClassName = shadowJarMainClass
940 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
945 task getdownWebsite() {
946 group = "distribution"
947 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
952 def getdownWebsiteResourceFilenames = []
953 def getdownTextString = ""
954 def getdownResourceDir = getdownResourceDir
955 def getdownAppDir = getdownAppDir
956 def getdownResourceFilenames = []
959 // clean the getdown website and files dir before creating getdown folders
960 delete getdownWebsiteDir
961 delete getdownFilesDir
965 rename(build_properties_file, getdown_build_properties)
968 getdownWebsiteResourceFilenames += "${getdown_app_dir}/${getdown_build_properties}"
970 // go through properties looking for getdown_txt_...
971 def props = project.properties.sort { it.key }
972 if (getdown_alt_java_min_version.length() > 0) {
973 props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
975 if (getdown_alt_java_max_version.length() > 0) {
976 props.put("getdown_txt_java_max_version", getdown_alt_java_max_version)
978 props.put("getdown_txt_multi_java_location", getdown_alt_multi_java_location)
980 props.put("getdown_txt_appbase", getdown_app_base)
981 props.each{ prop, val ->
982 if (prop.startsWith("getdown_txt_") && val != null) {
983 if (prop.startsWith("getdown_txt_multi_")) {
984 def key = prop.substring(18)
985 val.split(",").each{ v ->
986 def line = "${key} = ${v}\n"
987 getdownTextString += line
990 // file values rationalised
991 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
993 if (val.indexOf('/') == 0) {
996 } else if (val.indexOf('/') > 0) {
997 // relative path (relative to jalviewDir)
998 r = file( "${jalviewDir}/${val}" )
1001 val = "${getdown_resource_dir}/" + r.getName()
1002 getdownWebsiteResourceFilenames += val
1003 getdownResourceFilenames += r.getPath()
1006 if (! prop.startsWith("getdown_txt_resource")) {
1007 def line = prop.substring(12) + " = ${val}\n"
1008 getdownTextString += line
1014 getdownWebsiteResourceFilenames.each{ filename ->
1015 getdownTextString += "resource = ${filename}\n"
1017 getdownResourceFilenames.each{ filename ->
1020 into getdownResourceDir
1025 fileTree(file(packageDir)).each{ f ->
1026 if (f.isDirectory()) {
1027 def files = fileTree(dir: f, include: ["*"]).getFiles()
1029 } else if (f.exists()) {
1033 codeFiles.sort().each{f ->
1034 def name = f.getName()
1035 def line = "code = ${getdown_app_dir}/${name}\n"
1036 getdownTextString += line
1043 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1045 if (JAVA_VERSION.equals("11")) {
1046 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1047 j11libFiles.sort().each{f ->
1048 def name = f.getName()
1049 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1050 getdownTextString += line
1053 into getdownJ11libDir
1059 // 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.
1060 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1061 getdownTextString += "resource = ${getdown_launcher_new}\n"
1062 getdownTextString += "class = ${mainClass}\n"
1064 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1065 getdown_txt.write(getdownTextString)
1067 def launch_jvl = file("${getdownWebsiteDir}/${getdown_launch_jvl}")
1068 launch_jvl.write("appbase="+props.get("getdown_txt_appbase"))
1071 from getdownLauncher
1072 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1073 into getdownWebsiteDir
1077 from getdownLauncher
1078 if (file(getdownLauncher).getName() != getdown_launcher) {
1079 rename(file(getdownLauncher).getName(), getdown_launcher)
1081 into getdownWebsiteDir
1084 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1087 from getdownLauncher
1088 from "${getdownWebsiteDir}/${getdown_build_properties}"
1089 if (file(getdownLauncher).getName() != getdown_launcher) {
1090 rename(file(getdownLauncher).getName(), getdown_launcher)
1092 into getdownInstallDir
1096 from getdownInstallDir
1097 into getdownFilesInstallDir
1104 from getdownLauncher
1105 from "${getdownWebsiteDir}/${getdown_build_properties}"
1106 if (file(getdownLauncher).getName() != getdown_launcher) {
1107 rename(file(getdownLauncher).getName(), getdown_launcher)
1109 into getdownFilesDir
1113 from getdownResourceDir
1114 into "${getdownFilesDir}/${getdown_resource_dir}"
1119 inputs.dir("${jalviewDir}/${packageDir}")
1121 outputs.dir(getdownWebsiteDir)
1122 outputs.dir(getdownFilesDir)
1126 task getdownDigest(type: JavaExec) {
1127 group = "distribution"
1128 description = "Digest the getdown website folder"
1129 dependsOn getdownWebsite
1131 classpath = files("${getdownWebsiteDir}/${getdown_launcher}")
1133 main = "com.threerings.getdown.tools.Digester"
1134 args getdownWebsiteDir
1135 inputs.dir(getdownWebsiteDir)
1136 outputs.file("${getdownWebsiteDir}/digest2.txt")
1141 group = "distribution"
1142 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1143 dependsOn getdownDigest
1145 if (reportRsyncCommand) {
1146 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1147 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1148 println "LIKELY RSYNC COMMAND:"
1149 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1150 if (RUNRSYNC == "true") {
1152 commandLine "mkdir", "-p", toDir
1155 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1165 delete getdownWebsiteDir
1166 delete getdownFilesDir
1172 def install4jHomeDir = "/opt/install4j"
1173 def hostname = "hostname".execute().text.trim()
1174 if (hostname.equals("jv-bamboo")) {
1175 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1176 } else if (OperatingSystem.current().isMacOsX()) {
1177 install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app'
1178 if (! file(install4jHomeDir).exists()) {
1179 install4jHomeDir = System.getProperty("user.home")+install4jHomeDir
1181 } else if (OperatingSystem.current().isLinux()) {
1182 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1184 installDir = file(install4jHomeDir)
1185 mediaTypes = Arrays.asList(install4jMediaTypes.split(","))
1186 if (install4jFaster.equals("true")) {
1192 task copyInstall4jTemplate(type: Copy) {
1193 from (install4jDir) {
1194 include install4jTemplate
1195 rename (install4jTemplate, install4jConfFileName)
1196 filter(ReplaceTokens,
1200 '9999999999': JAVA_VERSION
1203 filter(ReplaceTokens,
1207 'JAVA_VERSION': JAVA_VERSION,
1208 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1209 'VERSION': JALVIEW_VERSION,
1210 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1211 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1212 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1213 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1214 'INSTALL4JINFOPLISTFILEASSOCIATIONS': install4jInfoPlistFileAssociations,
1215 'COPYRIGHT_MESSAGE': install4jCopyrightMessage,
1216 'MACOS_BUNDLE_ID': install4jMacOSBundleId,
1217 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1218 'GETDOWN_DIST_DIR': getdown_app_dir,
1219 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1220 'GETDOWN_INSTALL_DIR': getdown_install_dir
1223 if (OSX_KEYPASS == "") {
1224 filter(ReplaceTokens,
1225 beginToken: 'codeSigning macEnabled="',
1228 'true': 'codeSigning macEnabled="false"'
1231 filter(ReplaceTokens,
1232 beginToken: 'runPostProcessor="true" ',
1233 endToken: 'Processor',
1235 'post': 'runPostProcessor="false" postProcessor'
1241 outputs.files(install4jConfFile)
1244 // include file associations in installer
1245 def installerFileAssociationsXml = file("${install4jDir}/${install4jInstallerFileAssociations}").text
1249 match: '<action name="EXTENSIONS_REPLACED_BY_GRADLE".*?</action>',
1250 replace: installerFileAssociationsXml,
1251 file: install4jConfFile
1254 // include uninstaller applescript app files in dmg
1255 def installerDMGUninstallerXml = file("$install4jDir/$install4jDMGUninstallerAppFiles").text
1259 match: '<file name="UNINSTALL_OLD_JALVIEW_APP_REPLACED_IN_GRADLE" file=.*?>',
1260 replace: installerDMGUninstallerXml,
1261 file: install4jConfFile
1270 delete install4jConfFile
1275 task installers(type: com.install4j.gradle.Install4jTask) {
1276 group = "distribution"
1277 description = "Create the install4j installers"
1279 dependsOn copyInstall4jTemplate
1280 projectFile = file(install4jConfFile)
1281 variables = [majorVersion: version.substring(2, 11), build: 001, OSX_KEYSTORE: OSX_KEYSTORE, JSIGN_SH: JSIGN_SH]
1282 destination = "${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}"
1283 buildSelected = true
1286 macKeystorePassword=OSX_KEYPASS
1290 println("Using projectFile "+projectFile)
1293 inputs.dir(getdownWebsiteDir)
1294 inputs.file(install4jConfFile)
1295 inputs.dir(macosJavaVMDir)
1296 inputs.dir(windowsJavaVMDir)
1297 outputs.dir("${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}")
1301 task sourceDist (type: Tar) {
1303 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1304 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1305 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1307 archiveFileName = outputFileName
1308 } catch (Exception e) {
1309 archiveName = outputFileName
1312 compression Compression.GZIP
1316 def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1321 ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1323 ,"utils/InstallAnywhere"]
1324 def PROCESS_FILES=[ "AUTHORS",
1332 "THIRDPARTYLIBS","TESTNG",
1334 "gradle.properties",
1345 exclude (EXCLUDE_FILES)
1346 include (PROCESS_FILES)
1347 filter(ReplaceTokens,
1351 'Version-Rel': JALVIEW_VERSION,
1352 'Year-Rel': getDate("yyyy")
1357 exclude (EXCLUDE_FILES)
1358 exclude (PROCESS_FILES)
1359 exclude ("appletlib")
1360 exclude ("**/*locales")
1361 exclude ("*locales/**")
1362 exclude ("utils/InstallAnywhere")
1364 exclude (getdown_files_dir)
1365 exclude (getdown_website_dir)
1367 // exluding these as not using jars as modules yet
1368 exclude ("${j11modDir}/**/*.jar")
1370 // from (jalviewDir) {
1371 // // explicit includes for stuff that seemed to not get included
1372 // include(fileTree("test/**/*."))
1373 // exclude(EXCLUDE_FILES)
1374 // exclude(PROCESS_FILES)
1381 dependsOn pubhtmlhelp
1383 inputs.dir("${classes}/${helpDir}")
1384 outputs.dir("${helpOutputDir}")
1388 task j2sSetHeadlessBuild {
1395 task jalviewjsSetEclipseWorkspace {
1396 def propKey = "jalviewjs_eclipse_workspace"
1398 if (project.hasProperty(propKey)) {
1399 propVal = project.getProperty(propKey)
1400 if (propVal.startsWith("~/")) {
1401 propVal = System.getProperty("user.home") + propVal.substring(1)
1404 def propsFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_workspace_location_file}"
1405 def propsFile = file(propsFileName)
1406 def eclipseWsDir = propVal
1407 def props = new Properties()
1409 if (( eclipseWsDir == null || !file(eclipseWsDir).exists() ) && propsFile.exists()) {
1410 def ins = new FileInputStream(propsFileName)
1413 if (props.getProperty(propKey, null) != null) {
1414 eclipseWsDir = props.getProperty(propKey)
1418 def writeProps = false
1419 if (eclipseWsDir == null || !file(eclipseWsDir).exists()) {
1420 def tempDir = File.createTempDir()
1421 eclipseWsDir = tempDir.getAbsolutePath()
1424 eclipseWorkspace = file(eclipseWsDir)
1427 // do not run a headless transpile when we claim to be in Eclipse
1429 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1430 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1432 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1436 props.setProperty(propKey, eclipseWsDir)
1437 propsFile.parentFile.mkdirs()
1438 def bytes = new ByteArrayOutputStream()
1439 props.store(bytes, null)
1440 def propertiesString = bytes.toString()
1441 propsFile.text = propertiesString
1444 println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath())
1447 //inputs.property(propKey, eclipseWsDir) // eclipseWsDir only gets set once this task runs, so will be out-of-date
1448 outputs.file(propsFileName)
1449 outputs.upToDateWhen { eclipseWorkspace.exists() }
1453 task jalviewjsEclipsePaths {
1456 def eclipseRoot = jalviewjs_eclipse_root
1457 if (eclipseRoot.startsWith("~/")) {
1458 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
1460 if (OperatingSystem.current().isMacOsX()) {
1461 eclipseRoot += "/Eclipse.app"
1462 eclipseBinary = "${eclipseRoot}/Contents/MacOS/eclipse"
1463 eclipseProduct = "${eclipseRoot}/Contents/Eclipse/.eclipseproduct"
1464 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
1465 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1466 eclipseRoot += "/eclipse.exe"
1468 eclipseBinary = "${eclipseRoot}/eclipse"
1469 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1470 } else { // linux or unix
1471 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1472 eclipseRoot += "/eclipse"
1474 eclipseBinary = "${eclipseRoot}/eclipse"
1475 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1478 eclipseVersion = "4.13" // default
1479 def assumedVersion = true
1480 if (file(eclipseProduct).exists()) {
1481 def fis = new FileInputStream(eclipseProduct)
1482 def props = new Properties()
1484 eclipseVersion = props.getProperty("version")
1486 assumedVersion = false
1489 def propKey = "eclipse_debug"
1490 eclipseDebug = (project.hasProperty(propKey) && project.getProperty(propKey).equals("true"))
1493 // do not run a headless transpile when we claim to be in Eclipse
1495 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1496 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1498 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1501 if (!assumedVersion) {
1502 println("ECLIPSE VERSION=${eclipseVersion}")
1509 dependsOn eclipseProject
1510 dependsOn eclipseClasspath
1511 dependsOn eclipseJdt
1515 // this version (type: Copy) will delete anything in the eclipse dropins folder that isn't in fromDropinsDir
1516 task jalviewjsEclipseCopyDropins(type: Copy) {
1517 dependsOn jalviewjsEclipsePaths
1519 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_eclipse_dropins_dir}", include: "*.jar")
1520 inputFiles += file("${jalviewDir}/${jalviewjs_j2s_plugin}")
1521 def outputDir = "${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}"
1528 // this eclipse -clean doesn't actually work
1529 task jalviewjsCleanEclipse(type: Exec) {
1530 dependsOn eclipseSetup
1531 dependsOn jalviewjsEclipsePaths
1532 dependsOn jalviewjsEclipseCopyDropins
1534 executable(eclipseBinary)
1535 args(["-nosplash", "--launcher.suppressErrors", "-data", eclipseWorkspace.getPath(), "-clean", "-console", "-consoleLog"])
1541 def inputString = """exit
1544 def inputByteStream = new ByteArrayInputStream(inputString.getBytes())
1545 standardInput = inputByteStream
1548 /* not really working yet
1549 jalviewjsEclipseCopyDropins.finalizedBy jalviewjsCleanEclipse
1553 task jalviewjsTransferUnzipSwingJs {
1554 def file_zip = "${jalviewDir}/${jalviewjs_swingjs_zip}"
1558 from zipTree(file_zip)
1559 into "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1563 inputs.file file_zip
1564 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1568 task jalviewjsTransferUnzipLib {
1569 def zipFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_libjs_dir}", include: "*.zip")
1572 zipFiles.each { file_zip ->
1574 from zipTree(file_zip)
1575 into "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1580 inputs.files zipFiles
1581 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1585 task jalviewjsTransferUnzipAllLibs {
1586 dependsOn jalviewjsTransferUnzipSwingJs
1587 dependsOn jalviewjsTransferUnzipLib
1591 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
1593 description "Create the .j2s file from the j2s.* properties"
1595 outputFile ("${jalviewDir}/${jalviewjs_j2s_settings}")
1596 def j2s_props = project.properties.findAll { it.key.startsWith("j2s.") }.sort { it.key }
1597 def siteDirProperty = "j2s.site.directory"
1598 def setSiteDir = false
1599 j2s_props.each { prop, val ->
1601 if (prop == siteDirProperty) {
1602 if (!(val.startsWith('/') || val.startsWith("file://") )) {
1603 val = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${val}"
1609 if (!setSiteDir) { // default site location, don't override specifically set property
1610 property(siteDirProperty,"${jalviewDir}/${jalviewjsTransferSiteJsDir}")
1613 inputs.properties(j2s_props)
1614 outputs.file(outputFile)
1618 task jalviewjsEclipseSetup {
1619 dependsOn jalviewjsEclipseCopyDropins
1620 dependsOn jalviewjsSetEclipseWorkspace
1621 dependsOn jalviewjsCreateJ2sSettings
1625 task jalviewjsSyncAllLibs (type: Sync) {
1626 dependsOn jalviewjsTransferUnzipAllLibs
1627 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteLibDir}")
1628 inputFiles += fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}")
1629 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1633 def outputFiles = []
1634 rename { filename ->
1635 outputFiles += "${outputDir}/${filename}"
1641 outputs.files outputFiles
1642 inputs.files inputFiles
1646 task jalviewjsSyncResources (type: Sync) {
1647 def inputFiles = fileTree(dir: "${jalviewDir}/${resourceDir}")
1648 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1652 def outputFiles = []
1653 rename { filename ->
1654 outputFiles += "${outputDir}/${filename}"
1660 outputs.files outputFiles
1661 inputs.files inputFiles
1665 task jalviewjsSyncSiteResources (type: Sync) {
1666 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_site_resource_dir}")
1667 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1671 def outputFiles = []
1672 rename { filename ->
1673 outputFiles += "${outputDir}/${filename}"
1679 outputs.files outputFiles
1680 inputs.files inputFiles
1684 task jalviewjsSyncBuildProperties (type: Sync) {
1685 dependsOn createBuildProperties
1686 def inputFiles = [file(buildProperties)]
1687 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1691 def outputFiles = []
1692 rename { filename ->
1693 outputFiles += "${outputDir}/${filename}"
1699 outputs.files outputFiles
1700 inputs.files inputFiles
1704 task jalviewjsProjectImport(type: Exec) {
1705 dependsOn eclipseSetup
1706 dependsOn jalviewjsEclipsePaths
1707 dependsOn jalviewjsEclipseSetup
1710 // do not run a headless import when we claim to be in Eclipse
1712 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1713 throw new StopExecutionException("Not running headless import whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1715 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1719 //def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
1720 def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview"
1721 executable(eclipseBinary)
1722 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
1726 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1728 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
1731 inputs.file("${jalviewDir}/.project")
1732 outputs.upToDateWhen {
1733 file(projdir).exists()
1738 task jalviewjsTranspile(type: Exec) {
1739 dependsOn jalviewjsEclipseSetup
1740 dependsOn jalviewjsProjectImport
1741 dependsOn jalviewjsEclipsePaths
1744 // do not run a headless transpile when we claim to be in Eclipse
1746 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1747 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1749 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1753 executable(eclipseBinary)
1754 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-${jalviewjs_eclipse_build_arg}", eclipse_project_name ])
1758 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1760 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
1766 stdout = new ByteArrayOutputStream()
1767 stderr = new ByteArrayOutputStream()
1769 def logOutFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}"
1770 def logOutFile = file(logOutFileName)
1771 logOutFile.createNewFile()
1772 logOutFile.text = """ROOT: ${jalviewjs_eclipse_root}
1773 BINARY: ${eclipseBinary}
1774 VERSION: ${eclipseVersion}
1775 WORKSPACE: ${eclipseWorkspace}
1776 DEBUG: ${eclipseDebug}
1779 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
1780 // combine stdout and stderr
1781 def logErrFOS = logOutFOS
1783 if (jalviewjs_j2s_to_console.equals("true")) {
1784 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1785 new org.apache.tools.ant.util.TeeOutputStream(
1789 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1790 new org.apache.tools.ant.util.TeeOutputStream(
1795 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1798 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1805 if (stdout.toString().contains("Error processing ")) {
1806 // j2s did not complete transpile
1807 //throw new TaskExecutionException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
1808 throw new GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
1812 inputs.dir("${jalviewDir}/${sourceDir}")
1813 outputs.dir("${jalviewDir}/${jalviewjsTransferSiteJsDir}")
1814 outputs.upToDateWhen( { file("${jalviewDir}/${jalviewjsTransferSiteJsDir}${jalviewjs_server_resource}").exists() } )
1818 def jalviewjsCallCore(String name, FileCollection list, String prefixFile, String suffixFile, String jsfile, String zjsfile, File logOutFile, Boolean logOutConsole) {
1820 def stdout = new ByteArrayOutputStream()
1821 def stderr = new ByteArrayOutputStream()
1823 def coreFile = file(jsfile)
1825 msg = "Creating core for ${name}...\nGenerating ${jsfile}"
1827 logOutFile.createNewFile()
1828 logOutFile.append(msg+"\n")
1830 def coreTop = file(prefixFile)
1831 def coreBottom = file(suffixFile)
1832 coreFile.getParentFile().mkdirs()
1833 coreFile.createNewFile()
1834 coreFile.write( coreTop.text )
1839 t.replaceAll("Clazz\\.([^_])","Clazz_${1}")
1840 coreFile.append( t )
1842 msg = "...file '"+f.getPath()+"' does not exist, skipping"
1844 logOutFile.append(msg+"\n")
1847 coreFile.append( coreBottom.text )
1849 msg = "Generating ${zjsfile}"
1851 logOutFile.append(msg+"\n")
1852 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
1853 def logErrFOS = logOutFOS
1856 classpath = files(["${jalviewDir}/tools/closure_compiler.jar"])
1857 args = [ "--js", jsfile, "--js_output_file", zjsfile ]
1859 msg = "\nRunning '"+commandLine.join(' ')+"'\n"
1861 logOutFile.append(msg+"\n")
1863 if (logOutConsole) {
1864 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1865 new org.apache.tools.ant.util.TeeOutputStream(
1869 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1870 new org.apache.tools.ant.util.TeeOutputStream(
1875 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1878 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1885 logOutFile.append(msg+"\n")
1889 task jalviewjsBuildAllCores {
1891 description "Build the core js lib closures listed in the classlists dir"
1892 dependsOn jalviewjsTranspile
1893 dependsOn jalviewjsTransferUnzipSwingJs
1895 def j2sDir = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${jalviewjs_j2s_subdir}"
1896 def jsDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${jalviewjs_js_subdir}"
1897 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}/${jalviewjs_j2s_subdir}/core"
1898 def prefixFile = "${jsDir}/core/coretop2.js"
1899 def suffixFile = "${jsDir}/core/corebottom2.js"
1901 inputs.file prefixFile
1902 inputs.file suffixFile
1904 def classlistFiles = []
1905 // add the classlists found int the jalviewjs_classlists_dir
1906 fileTree(dir: "${jalviewDir}/${jalviewjs_classlists_dir}", include: "*.txt").each {
1908 def name = file.getName() - ".txt"
1915 // _jmol and _jalview cores. Add any other peculiar classlist.txt files here
1916 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jmol}"), 'name': "_jvjmol" ]
1917 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jalview}"), 'name': jalviewjsJalviewCoreName ]
1919 jalviewjsCoreClasslists = []
1921 classlistFiles.each {
1924 def file = hash['file']
1925 if (! file.exists()) {
1926 println("...classlist file '"+file.getPath()+"' does not exist, skipping")
1927 return false // this is a "continue" in groovy .each closure
1929 def name = hash['name']
1931 name = file.getName() - ".txt"
1939 def list = fileTree(dir: j2sDir, includes: filelist)
1941 def jsfile = "${outputDir}/core${name}.js"
1942 def zjsfile = "${outputDir}/core${name}.z.js"
1944 jalviewjsCoreClasslists += [
1953 outputs.file(jsfile)
1954 outputs.file(zjsfile)
1957 // _stevesoft core. add any cores without a classlist here (and the inputs and outputs)
1958 def stevesoftClasslistName = "_stevesoft"
1959 def stevesoftClasslist = [
1960 'jsfile': "${outputDir}/core${stevesoftClasslistName}.js",
1961 'zjsfile': "${outputDir}/core${stevesoftClasslistName}.z.js",
1962 'list': fileTree(dir: j2sDir, include: "com/stevesoft/pat/**/*.js"),
1963 'name': stevesoftClasslistName
1965 jalviewjsCoreClasslists += stevesoftClasslist
1966 inputs.files(stevesoftClasslist['list'])
1967 outputs.file(stevesoftClasslist['jsfile'])
1968 outputs.file(stevesoftClasslist['zjsfile'])
1971 def allClasslistName = "_all"
1972 def allClasslist = [
1973 'jsfile': "${outputDir}/core${allClasslistName}.js",
1974 'zjsfile': "${outputDir}/core${allClasslistName}.z.js",
1975 'list': fileTree(dir: j2sDir, include: "**/*.js"),
1976 'name': allClasslistName
1978 jalviewjsCoreClasslists += allClasslist
1979 inputs.files(allClasslist['list'])
1980 outputs.file(allClasslist['jsfile'])
1981 outputs.file(allClasslist['zjsfile'])
1984 def logOutFile = file("${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_closure_stdout}")
1985 logOutFile.getParentFile().mkdirs()
1986 logOutFile.createNewFile()
1987 logOutFile.write(getDate("yyyy-MM-dd HH:mm:ss")+" jalviewjsBuildAllCores\n----\n")
1989 jalviewjsCoreClasslists.each {
1990 jalviewjsCallCore(it.name, it.list, prefixFile, suffixFile, it.jsfile, it.zjsfile, logOutFile, jalviewjs_j2s_to_console.equals("true"))
1997 def jalviewjsPublishCoreTemplate(String coreName, String templateName, File inputFile, String outputFile) {
2000 into file(outputFile).getParentFile()
2001 rename { filename ->
2002 if (filename.equals(inputFile.getName())) {
2003 return file(outputFile).getName()
2007 filter(ReplaceTokens,
2011 'MAIN': '"'+mainClass+'"',
2013 'NAME': jalviewjsJalviewTemplateName+" [core ${coreName}]",
2014 'COREKEY': jalviewjs_core_key,
2015 'CORENAME': coreName
2022 task jalviewjsPublishCoreTemplates {
2023 dependsOn jalviewjsBuildAllCores
2024 def inputFileName = "${jalviewDir}/${j2s_coretemplate_html}"
2025 def inputFile = file(inputFileName)
2026 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
2028 def outputFiles = []
2029 jalviewjsCoreClasslists.each { cl ->
2030 def outputFile = "${outputDir}/${jalviewjsJalviewTemplateName}_${cl.name}.html"
2031 cl['outputfile'] = outputFile
2032 outputFiles += outputFile
2036 jalviewjsCoreClasslists.each { cl ->
2037 jalviewjsPublishCoreTemplate(cl.name, jalviewjsJalviewTemplateName, inputFile, cl.outputfile)
2040 inputs.file(inputFile)
2041 outputs.files(outputFiles)
2045 task jalviewjsSyncCore (type: Sync) {
2046 dependsOn jalviewjsBuildAllCores
2047 dependsOn jalviewjsPublishCoreTemplates
2048 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteCoreDir}")
2049 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
2053 def outputFiles = []
2054 rename { filename ->
2055 outputFiles += "${outputDir}/${filename}"
2061 outputs.files outputFiles
2062 inputs.files inputFiles
2066 // this Copy version of TransferSiteJs will delete anything else in the target dir
2067 task jalviewjsCopyTransferSiteJs(type: Copy) {
2068 dependsOn jalviewjsTranspile
2069 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2070 into "${jalviewDir}/${jalviewjsSiteDir}"
2074 // this Sync version of TransferSite is used by buildship to keep the website automatically up to date when a file changes
2075 task jalviewjsSyncTransferSiteJs(type: Sync) {
2076 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2078 into "${jalviewDir}/${jalviewjsSiteDir}"
2085 jalviewjsSyncAllLibs.mustRunAfter jalviewjsCopyTransferSiteJs
2086 jalviewjsSyncResources.mustRunAfter jalviewjsCopyTransferSiteJs
2087 jalviewjsSyncSiteResources.mustRunAfter jalviewjsCopyTransferSiteJs
2088 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsCopyTransferSiteJs
2090 jalviewjsSyncAllLibs.mustRunAfter jalviewjsSyncTransferSiteJs
2091 jalviewjsSyncResources.mustRunAfter jalviewjsSyncTransferSiteJs
2092 jalviewjsSyncSiteResources.mustRunAfter jalviewjsSyncTransferSiteJs
2093 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsSyncTransferSiteJs
2096 task jalviewjsPrepareSite {
2098 description "Prepares the website folder including unzipping files and copying resources"
2099 dependsOn jalviewjsSyncAllLibs
2100 dependsOn jalviewjsSyncResources
2101 dependsOn jalviewjsSyncSiteResources
2102 dependsOn jalviewjsSyncBuildProperties
2103 dependsOn jalviewjsSyncCore
2107 task jalviewjsBuildSite {
2109 description "Builds the whole website including transpiled code"
2110 dependsOn jalviewjsCopyTransferSiteJs
2111 dependsOn jalviewjsPrepareSite
2115 task cleanJalviewjsSite {
2117 delete "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2118 delete "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
2119 delete "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
2120 delete "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
2121 delete "${jalviewDir}/${jalviewjsSiteDir}"
2126 task jalviewjsSiteTar(type: Tar) {
2128 description "Creates a tar.gz file for the website"
2129 dependsOn jalviewjsBuildSite
2130 def outputFilename = "jalviewjs-site-${JALVIEW_VERSION}.tar.gz"
2132 archiveFileName = outputFilename
2133 } catch (Exception e) {
2134 archiveName = outputFilename
2137 compression Compression.GZIP
2139 from "${jalviewDir}/${jalviewjsSiteDir}"
2140 into jalviewjs_site_dir // this is inside the tar file
2142 inputs.dir("${jalviewDir}/${jalviewjsSiteDir}")
2146 task jalviewjsServer {
2148 def filename = "jalviewjsTest.html"
2149 description "Starts a webserver on localhost to test the website. See ${filename} to access local site on most recently used port."
2150 def htmlFile = "${jalviewDirAbsolutePath}/${filename}"
2153 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
2154 def port = Integer.valueOf(jalviewjs_server_port)
2158 while(port < start+1000 && !running) {
2160 def doc_root = new File("${jalviewDirAbsolutePath}/${jalviewjsSiteDir}")
2161 def jalviewjsServer = factory.start(doc_root, port)
2163 url = jalviewjsServer.getResourceUrl(jalviewjs_server_resource)
2164 println("SERVER STARTED with document root ${doc_root}.")
2165 println("Go to "+url+" . Run gradle --stop to stop (kills all gradle daemons).")
2166 println("For debug: "+url+"?j2sdebug")
2167 println("For core: "+urlcore)
2170 <p><a href="${url}">JalviewJS Test. <${url}></a></p>
2171 <p><a href="${url}?j2sdebug">JalviewJS Test with debug. <${url}?j2sdebug<</a></p>
2173 jalviewjsCoreClasslists.each { cl ->
2174 urlcore = jalviewjsServer.getResourceUrl(file(cl.outputfile).getName())
2176 <p><a href="${urlcore}">${jalviewjsJalviewTemplateName} [core ${cl.name}]. <${urlcore}></a></p>
2180 file(htmlFile).text = htmlText
2182 } catch (Exception e) {
2190 outputs.file(htmlFile)
2191 outputs.upToDateWhen({false})
2195 task cleanJalviewjsAll {
2197 description "Delete all configuration and build artifacts to do with JalviewJS build"
2198 dependsOn cleanJalviewjsSite
2199 dependsOn jalviewjsEclipsePaths
2202 delete "${jalviewDir}/${jalviewjsBuildDir}"
2203 delete "${jalviewDir}/${eclipse_bin_dir}"
2204 if (eclipseWorkspace != null && file(eclipseWorkspace.getAbsolutePath()+"/.metadata").exists()) {
2205 delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata")
2207 delete "${jalviewDir}/${jalviewjs_j2s_settings}"
2210 outputs.upToDateWhen( { false } )
2215 task jalviewjsIDE_j2sFile {
2216 group "00 JalviewJS in Eclipse"
2217 description "Creates the .j2s file"
2218 dependsOn jalviewjsCreateJ2sSettings
2222 task jalviewjsIDE_SyncCore {
2223 group "00 JalviewJS in Eclipse"
2224 description "Build the core js lib closures listed in the classlists dir and publish core html from template"
2225 dependsOn jalviewjsSyncCore
2229 task jalviewjsIDE_PrepareSite {
2230 group "00 JalviewJS in Eclipse"
2231 description "Sync libs and resources to site dir, but not closure cores"
2232 dependsOn jalviewjsSyncAllLibs
2233 dependsOn jalviewjsSyncResources
2234 dependsOn jalviewjsSyncSiteResources
2235 dependsOn jalviewjsSyncBuildProperties
2239 task jalviewjsIDE_AssembleSite {
2240 group "00 JalviewJS in Eclipse"
2241 description "Assembles unzipped supporting zipfiles, resources, site resources and closure cores into the Eclipse transpiled site"
2242 dependsOn jalviewjsPrepareSite
2246 task jalviewjsIDE_SiteClean {
2247 group "00 JalviewJS in Eclipse"
2248 description "Deletes the Eclipse transpiled site"
2249 dependsOn cleanJalviewjsSite
2253 task jalviewjsIDE_Server {
2254 group "00 JalviewJS in Eclipse"
2255 description "Starts a webserver on localhost to test the website"
2256 dependsOn jalviewjsServer
2260 // buildship runs this at import
2261 task eclipseConfiguration {
2262 dependsOn eclipseSetup
2263 dependsOn jalviewjsIDE_j2sFile
2267 // buildship runs this at build time
2268 task eclipseAutoBuildTask {
2269 dependsOn jalviewjsIDE_PrepareSite
2281 description "Build the site"
2282 dependsOn jalviewjsBuildSite