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 jalviewjsJalviewTemplateName = string(jalviewjs_name)
298 eclipseWorkspace = null
299 eclipseBinary = string("")
300 eclipseVersion = string("")
309 srcDirs "${jalviewDir}/${sourceDir}"
310 outputDir = file(project.classes)
314 srcDirs "${jalviewDir}/${resourceDir}"
317 jar.destinationDir = file("${jalviewDir}/${packageDir}")
319 compileClasspath = files(sourceSets.main.java.outputDir)
320 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
322 runtimeClasspath = compileClasspath
327 srcDirs = [ cloverInstrDir ]
328 outputDir = file("${buildDir}/${cloverClassesDir}")
332 srcDirs = sourceSets.main.resources.srcDirs
334 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
335 compileClasspath += files(sourceSets.main.java.outputDir)
336 compileClasspath += sourceSets.main.compileClasspath
337 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
338 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
340 runtimeClasspath = compileClasspath
345 srcDirs "${jalviewDir}/${testSourceDir}"
346 outputDir = file("${jalviewDir}/${testOutputDir}")
350 srcDirs = sourceSets.main.resources.srcDirs
353 compileClasspath = files( sourceSets.test.java.outputDir )
356 compileClasspath += sourceSets.clover.compileClasspath
358 compileClasspath += files(sourceSets.main.java.outputDir)
361 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
362 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
363 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
365 runtimeClasspath = compileClasspath
373 cloverCompile 'org.openclover:clover:4.3.1'
374 testCompile 'org.openclover:clover:4.3.1'
381 cloverRuntime.extendsFrom cloverCompile
386 name = eclipse_project_name
388 natures 'org.eclipse.jdt.core.javanature',
389 'org.eclipse.jdt.groovy.core.groovyNature',
390 'org.eclipse.buildship.core.gradleprojectnature'
392 buildCommand 'org.eclipse.jdt.core.javabuilder'
393 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
397 //defaultOutputDir = sourceSets.main.java.outputDir
400 if (it.isCanBeResolved()) {
405 minusConfigurations += removeThese
406 plusConfigurations = [ ]
410 def removeTheseToo = []
411 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
412 cp.entries.each { entry ->
413 if (entry.kind == 'src') {
414 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == sourceDir || entry.path == testSourceDir)) {
415 removeTheseToo += entry
417 alreadyAddedSrcPath.putAt(entry.path, true)
421 cp.entries.removeAll(removeTheseToo)
423 if (file("${jalviewDir}/${eclipse_bin_dir}/main").isDirectory()) {
424 cp.entries += new Output("${eclipse_bin_dir}/main")
426 if (file(helpParentDir).isDirectory()) {
427 cp.entries += new Library(fileReference(helpParentDir))
429 if (file(resourceDir).isDirectory()) {
430 cp.entries += new Library(fileReference(resourceDir))
433 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
435 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.each {
436 //don't want to add outputDir as eclipse is using its own output dir in bin/main
437 if (it.isDirectory() || ! it.exists()) {
438 // don't add dirs to classpath
441 def itPath = it.toString()
442 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
443 // make relative path
444 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
446 if (alreadyAddedLibPath.get(itPath)) {
447 //println("Not adding duplicate entry "+itPath)
449 //println("Adding entry "+itPath)
450 cp.entries += new Library(fileReference(itPath))
451 alreadyAddedLibPath.put(itPath, true)
455 //fileTree(dir: "$jalviewDir/$utilsDir", include: ["test*/*.jar"]).each {
456 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
457 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
458 if (it.isDirectory() || ! it.exists()) {
459 // don't add dirs to classpath
460 return false // groovy "continue" in .any closure
463 def itPath = it.toString()
464 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
465 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
467 if (alreadyAddedLibPath.get(itPath)) {
470 def lib = new Library(fileReference(itPath))
471 lib.entryAttributes["test"] = "true"
473 alreadyAddedLibPath.put(itPath, true)
481 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
486 // for the IDE, use java 11 compatibility
487 sourceCompatibility = compile_source_compatibility
488 targetCompatibility = compile_target_compatibility
489 javaRuntimeName = eclipse_java_runtime_name
491 // add in jalview project specific properties/preferences into eclipse core preferences
493 withProperties { props ->
494 def jalview_prefs = new Properties()
495 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
496 jalview_prefs.load(ins)
498 jalview_prefs.forEach { t, v ->
499 if (props.getAt(t) == null) {
509 // Don't want these to be activated if in headless build
510 //synchronizationTasks "eclipseConfiguration"
511 autoBuildTasks "eclipseAutoBuildTask"
517 // only instrument source, we build test classes as normal
518 inputs.files files (sourceSets.main.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
519 outputs.dir cloverInstrDir
522 delete cloverInstrDir
523 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
524 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
525 argsList.addAll(inputs.files.files.collect({ file ->
528 String[] args = argsList.toArray()
529 println("About to instrument "+args.length +" files")
530 com.atlassian.clover.CloverInstr.mainImpl(args)
536 group = "Verification"
537 description = "Createst the Clover report"
538 inputs.dir "${buildDir}/clover"
539 outputs.dir "${reportsDir}/clover"
541 file("${buildDir}/clover/clover.db").exists()
544 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
545 "-o", "${reportsDir}/clover"]
546 String[] args = argsList.toArray()
547 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
549 // and generate ${reportsDir}/clover/clover.xml
550 args = ["--initstring", "${buildDir}/clover/clover.db",
551 "-o", "${reportsDir}/clover/clover.xml"].toArray()
552 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
561 sourceCompatibility = compile_source_compatibility
562 targetCompatibility = compile_target_compatibility
563 options.compilerArgs = additional_compiler_args
564 print ("Setting target compatibility to "+targetCompatibility+"\n")
572 dependsOn compileCloverJava
573 classpath += configurations.cloverRuntime
575 classpath += sourceSets.main.runtimeClasspath
578 sourceCompatibility = compile_source_compatibility
579 targetCompatibility = compile_target_compatibility
580 options.compilerArgs = additional_compiler_args
581 print ("Setting target compatibility to "+targetCompatibility+"\n")
589 sourceCompatibility = compile_source_compatibility
590 targetCompatibility = compile_target_compatibility
591 options.compilerArgs += additional_compiler_args
592 print ("Setting target compatibility to "+targetCompatibility+"\n")
594 classpath += configurations.cloverRuntime
600 delete sourceSets.main.java.outputDir
607 delete sourceSets.test.java.outputDir
608 delete cloverInstrDir
613 // format is a string like date.format("dd MMMM yyyy")
614 def getDate(format) {
615 def date = new Date()
616 return date.format(format)
621 def hashStdOut = new ByteArrayOutputStream()
623 commandLine "git", "rev-parse", "--short", "HEAD"
624 standardOutput = hashStdOut
628 def branchStdOut = new ByteArrayOutputStream()
630 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
631 standardOutput = branchStdOut
635 gitHash = hashStdOut.toString().trim()
636 gitBranch = branchStdOut.toString().trim()
638 outputs.upToDateWhen { false }
642 task createBuildProperties(type: WriteProperties) {
644 inputs.dir("${jalviewDir}/${sourceDir}")
645 inputs.dir("${jalviewDir}/${resourceDir}")
646 file(buildProperties).getParentFile().mkdirs()
647 outputFile (buildProperties)
648 // taking time specific comment out to allow better incremental builds
649 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
650 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
651 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
652 property "VERSION", JALVIEW_VERSION
653 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
654 outputs.file(outputFile)
658 task cleanBuildingHTML(type: Delete) {
665 task convertBuildingMD(type: Exec) {
666 dependsOn cleanBuildingHTML
667 def buildingMD = "${jalviewDir}/${docDir}/building.md"
668 def css = "${jalviewDir}/${docDir}/github.css"
671 pandoc_exec.split(",").each {
672 if (file(it.trim()).exists()) {
678 def hostname = "hostname".execute().text.trim()
679 if ((pandoc == null || ! file(pandoc).exists()) && hostname.equals("jv-bamboo")) {
680 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
684 if (pandoc != null && file(pandoc).exists()) {
685 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
687 println("Cannot find pandoc. Skipping convert building.md to HTML")
688 throw new StopExecutionException()
694 inputs.file(buildingMD)
696 outputs.file(buildingHTML)
707 task syncDocs(type: Sync) {
708 dependsOn convertBuildingMD
709 def syncDir = "${classes}/${docDir}"
710 from fileTree("${jalviewDir}/${docDir}")
716 task copyHelp(type: Copy) {
717 def inputDir = "${jalviewDir}/${helpParentDir}/${helpDir}"
718 def outputDir = "${classes}/${helpDir}"
723 filter(ReplaceTokens,
727 'Version-Rel': JALVIEW_VERSION,
728 'Year-Rel': getDate("yyyy")
740 outputs.files(helpFile)
741 outputs.dir(outputDir)
745 task syncLib(type: Sync) {
746 def syncDir = "${classes}/${libDistDir}"
747 from fileTree("${jalviewDir}/${libDistDir}")
752 task syncResources(type: Sync) {
753 from "${jalviewDir}/${resourceDir}"
763 dependsOn syncResources
769 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
772 dependsOn compileJava
774 dependsOn cloverInstr
778 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
782 includeGroups testngGroups
784 useDefaultListeners=true
787 workingDir = jalviewDir
788 //systemProperties 'clover.jar' System.properties.clover.jar
789 sourceCompatibility = compile_source_compatibility
790 targetCompatibility = compile_target_compatibility
791 jvmArgs += additional_compiler_args
796 task buildIndices(type: JavaExec) {
798 classpath = sourceSets.main.compileClasspath
799 main = "com.sun.java.help.search.Indexer"
800 workingDir = "${classes}/${helpDir}"
803 inputs.dir("${workingDir}/${argDir}")
805 outputs.dir("${classes}/doc")
806 outputs.dir("${classes}/help")
807 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
808 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
809 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
810 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
811 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
812 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
816 task compileLinkCheck(type: JavaCompile) {
818 classpath = files("${jalviewDir}/${utilsDir}")
819 destinationDir = file("${jalviewDir}/${utilsDir}")
820 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
822 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
823 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
824 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
825 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
829 task linkCheck(type: JavaExec) {
830 dependsOn prepare, compileLinkCheck
832 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
833 classpath = files("${jalviewDir}/${utilsDir}")
834 main = "HelpLinksChecker"
835 workingDir = jalviewDir
836 def help = "${classes}/${helpDir}"
837 args = [ "${classes}/${helpDir}", "-nointernet" ]
839 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
841 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
844 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
848 inputs.dir("${classes}/${helpDir}")
849 outputs.file(helpLinksCheckerOutFile)
852 // import the pubhtmlhelp target
853 ant.properties.basedir = "${jalviewDir}"
854 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes}/${helpDir}"
855 ant.importBuild "${utilsDir}/publishHelp.xml"
858 task cleanPackageDir(type: Delete) {
860 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
866 dependsOn buildIndices
867 dependsOn createBuildProperties
870 attributes "Main-Class": mainClass,
871 "Permissions": "all-permissions",
872 "Application-Name": "Jalview Desktop",
873 "Codebase": application_codebase
876 destinationDir = file("${jalviewDir}/${packageDir}")
877 archiveName = rootProject.name+".jar"
885 inputs.dir("${classes}")
886 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
890 task copyJars(type: Copy) {
891 from fileTree(dir: "${classes}", include: "**/*.jar").files
892 into "${jalviewDir}/${packageDir}"
896 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
897 task syncJars(type: Sync) {
898 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
899 into "${jalviewDir}/${packageDir}"
901 include jar.archiveName
908 description = "Put all required libraries in dist"
909 // order of "cleanPackageDir", "copyJars", "jar" important!
910 jar.mustRunAfter cleanPackageDir
911 syncJars.mustRunAfter cleanPackageDir
912 dependsOn cleanPackageDir
915 outputs.dir("${jalviewDir}/${packageDir}")
920 dependsOn cleanPackageDir
926 group = "distribution"
930 from ("${jalviewDir}/${libDistDir}") {
934 attributes 'Implementation-Version': JALVIEW_VERSION
936 mainClassName = shadowJarMainClass
938 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
943 task getdownWebsite() {
944 group = "distribution"
945 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
950 def getdownWebsiteResourceFilenames = []
951 def getdownTextString = ""
952 def getdownResourceDir = getdownResourceDir
953 def getdownAppDir = getdownAppDir
954 def getdownResourceFilenames = []
957 // clean the getdown website and files dir before creating getdown folders
958 delete getdownWebsiteDir
959 delete getdownFilesDir
963 rename(build_properties_file, getdown_build_properties)
966 getdownWebsiteResourceFilenames += "${getdown_app_dir}/${getdown_build_properties}"
968 // go through properties looking for getdown_txt_...
969 def props = project.properties.sort { it.key }
970 if (getdown_alt_java_min_version.length() > 0) {
971 props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
973 if (getdown_alt_java_max_version.length() > 0) {
974 props.put("getdown_txt_java_max_version", getdown_alt_java_max_version)
976 props.put("getdown_txt_multi_java_location", getdown_alt_multi_java_location)
978 props.put("getdown_txt_appbase", getdown_app_base)
979 props.each{ prop, val ->
980 if (prop.startsWith("getdown_txt_") && val != null) {
981 if (prop.startsWith("getdown_txt_multi_")) {
982 def key = prop.substring(18)
983 val.split(",").each{ v ->
984 def line = "${key} = ${v}\n"
985 getdownTextString += line
988 // file values rationalised
989 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
991 if (val.indexOf('/') == 0) {
994 } else if (val.indexOf('/') > 0) {
995 // relative path (relative to jalviewDir)
996 r = file( "${jalviewDir}/${val}" )
999 val = "${getdown_resource_dir}/" + r.getName()
1000 getdownWebsiteResourceFilenames += val
1001 getdownResourceFilenames += r.getPath()
1004 if (! prop.startsWith("getdown_txt_resource")) {
1005 def line = prop.substring(12) + " = ${val}\n"
1006 getdownTextString += line
1012 getdownWebsiteResourceFilenames.each{ filename ->
1013 getdownTextString += "resource = ${filename}\n"
1015 getdownResourceFilenames.each{ filename ->
1018 into getdownResourceDir
1023 fileTree(file(packageDir)).each{ f ->
1024 if (f.isDirectory()) {
1025 def files = fileTree(dir: f, include: ["*"]).getFiles()
1027 } else if (f.exists()) {
1031 codeFiles.sort().each{f ->
1032 def name = f.getName()
1033 def line = "code = ${getdown_app_dir}/${name}\n"
1034 getdownTextString += line
1041 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1043 if (JAVA_VERSION.equals("11")) {
1044 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1045 j11libFiles.sort().each{f ->
1046 def name = f.getName()
1047 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1048 getdownTextString += line
1051 into getdownJ11libDir
1057 // 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.
1058 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1059 getdownTextString += "resource = ${getdown_launcher_new}\n"
1060 getdownTextString += "class = ${mainClass}\n"
1062 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1063 getdown_txt.write(getdownTextString)
1065 def launch_jvl = file("${getdownWebsiteDir}/${getdown_launch_jvl}")
1066 launch_jvl.write("appbase="+props.get("getdown_txt_appbase"))
1069 from getdownLauncher
1070 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1071 into getdownWebsiteDir
1075 from getdownLauncher
1076 if (file(getdownLauncher).getName() != getdown_launcher) {
1077 rename(file(getdownLauncher).getName(), getdown_launcher)
1079 into getdownWebsiteDir
1082 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1085 from getdownLauncher
1086 from "${getdownWebsiteDir}/${getdown_build_properties}"
1087 if (file(getdownLauncher).getName() != getdown_launcher) {
1088 rename(file(getdownLauncher).getName(), getdown_launcher)
1090 into getdownInstallDir
1094 from getdownInstallDir
1095 into getdownFilesInstallDir
1102 from getdownLauncher
1103 from "${getdownWebsiteDir}/${getdown_build_properties}"
1104 if (file(getdownLauncher).getName() != getdown_launcher) {
1105 rename(file(getdownLauncher).getName(), getdown_launcher)
1107 into getdownFilesDir
1111 from getdownResourceDir
1112 into "${getdownFilesDir}/${getdown_resource_dir}"
1117 inputs.dir("${jalviewDir}/${packageDir}")
1119 outputs.dir(getdownWebsiteDir)
1120 outputs.dir(getdownFilesDir)
1124 task getdownDigest(type: JavaExec) {
1125 group = "distribution"
1126 description = "Digest the getdown website folder"
1127 dependsOn getdownWebsite
1129 classpath = files("${getdownWebsiteDir}/${getdown_launcher}")
1131 main = "com.threerings.getdown.tools.Digester"
1132 args getdownWebsiteDir
1133 inputs.dir(getdownWebsiteDir)
1134 outputs.file("${getdownWebsiteDir}/digest2.txt")
1139 group = "distribution"
1140 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1141 dependsOn getdownDigest
1143 if (reportRsyncCommand) {
1144 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1145 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1146 println "LIKELY RSYNC COMMAND:"
1147 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1148 if (RUNRSYNC == "true") {
1150 commandLine "mkdir", "-p", toDir
1153 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1163 delete getdownWebsiteDir
1164 delete getdownFilesDir
1170 def install4jHomeDir = "/opt/install4j"
1171 def hostname = "hostname".execute().text.trim()
1172 if (hostname.equals("jv-bamboo")) {
1173 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1174 } else if (OperatingSystem.current().isMacOsX()) {
1175 install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app'
1176 if (! file(install4jHomeDir).exists()) {
1177 install4jHomeDir = System.getProperty("user.home")+install4jHomeDir
1179 } else if (OperatingSystem.current().isLinux()) {
1180 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1182 installDir = file(install4jHomeDir)
1183 mediaTypes = Arrays.asList(install4jMediaTypes.split(","))
1184 if (install4jFaster.equals("true")) {
1190 task copyInstall4jTemplate(type: Copy) {
1191 from (install4jDir) {
1192 include install4jTemplate
1193 rename (install4jTemplate, install4jConfFileName)
1194 filter(ReplaceTokens,
1198 '9999999999': JAVA_VERSION
1201 filter(ReplaceTokens,
1205 'JAVA_VERSION': JAVA_VERSION,
1206 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1207 'VERSION': JALVIEW_VERSION,
1208 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1209 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1210 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1211 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1212 'INSTALL4JINFOPLISTFILEASSOCIATIONS': install4jInfoPlistFileAssociations,
1213 'COPYRIGHT_MESSAGE': install4jCopyrightMessage,
1214 'MACOS_BUNDLE_ID': install4jMacOSBundleId,
1215 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1216 'GETDOWN_DIST_DIR': getdown_app_dir,
1217 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1218 'GETDOWN_INSTALL_DIR': getdown_install_dir
1221 if (OSX_KEYPASS == "") {
1222 filter(ReplaceTokens,
1223 beginToken: 'codeSigning macEnabled="',
1226 'true': 'codeSigning macEnabled="false"'
1229 filter(ReplaceTokens,
1230 beginToken: 'runPostProcessor="true" ',
1231 endToken: 'Processor',
1233 'post': 'runPostProcessor="false" postProcessor'
1239 outputs.files(install4jConfFile)
1242 // include file associations in installer
1243 def installerFileAssociationsXml = file("${install4jDir}/${install4jInstallerFileAssociations}").text
1247 match: '<action name="EXTENSIONS_REPLACED_BY_GRADLE".*?</action>',
1248 replace: installerFileAssociationsXml,
1249 file: install4jConfFile
1252 // include uninstaller applescript app files in dmg
1253 def installerDMGUninstallerXml = file("$install4jDir/$install4jDMGUninstallerAppFiles").text
1257 match: '<file name="UNINSTALL_OLD_JALVIEW_APP_REPLACED_IN_GRADLE" file=.*?>',
1258 replace: installerDMGUninstallerXml,
1259 file: install4jConfFile
1268 delete install4jConfFile
1273 task installers(type: com.install4j.gradle.Install4jTask) {
1274 group = "distribution"
1275 description = "Create the install4j installers"
1277 dependsOn copyInstall4jTemplate
1278 projectFile = file(install4jConfFile)
1279 variables = [majorVersion: version.substring(2, 11), build: 001, OSX_KEYSTORE: OSX_KEYSTORE, JSIGN_SH: JSIGN_SH]
1280 destination = "${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}"
1281 buildSelected = true
1284 macKeystorePassword=OSX_KEYPASS
1288 println("Using projectFile "+projectFile)
1291 inputs.dir(getdownWebsiteDir)
1292 inputs.file(install4jConfFile)
1293 inputs.dir(macosJavaVMDir)
1294 inputs.dir(windowsJavaVMDir)
1295 outputs.dir("${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}")
1301 delete install4jConfFile
1306 task sourceDist (type: Tar) {
1308 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1309 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1310 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1312 archiveFileName = outputFileName
1313 } catch (Exception e) {
1314 archiveName = outputFileName
1317 compression Compression.GZIP
1321 def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1326 ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1328 ,"utils/InstallAnywhere"]
1329 def PROCESS_FILES=[ "AUTHORS",
1337 "THIRDPARTYLIBS","TESTNG",
1339 "gradle.properties",
1350 exclude (EXCLUDE_FILES)
1351 include (PROCESS_FILES)
1352 filter(ReplaceTokens,
1356 'Version-Rel': JALVIEW_VERSION,
1357 'Year-Rel': getDate("yyyy")
1362 exclude (EXCLUDE_FILES)
1363 exclude (PROCESS_FILES)
1364 exclude ("appletlib")
1365 exclude ("**/*locales")
1366 exclude ("*locales/**")
1367 exclude ("utils/InstallAnywhere")
1369 exclude (getdown_files_dir)
1370 exclude (getdown_website_dir)
1372 // exluding these as not using jars as modules yet
1373 exclude ("${j11modDir}/**/*.jar")
1375 // from (jalviewDir) {
1376 // // explicit includes for stuff that seemed to not get included
1377 // include(fileTree("test/**/*."))
1378 // exclude(EXCLUDE_FILES)
1379 // exclude(PROCESS_FILES)
1386 dependsOn pubhtmlhelp
1388 inputs.dir("${classes}/${helpDir}")
1389 outputs.dir("${helpOutputDir}")
1393 task j2sSetHeadlessBuild {
1400 task jalviewjsSetEclipseWorkspace {
1401 def propKey = "jalviewjs_eclipse_workspace"
1403 if (project.hasProperty(propKey)) {
1404 propVal = project.getProperty(propKey)
1405 if (propVal.startsWith("~/")) {
1406 propVal = System.getProperty("user.home") + propVal.substring(1)
1409 def propsFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_workspace_location_file}"
1410 def propsFile = file(propsFileName)
1411 def eclipseWsDir = propVal
1412 def props = new Properties()
1414 if (( eclipseWsDir == null || !file(eclipseWsDir).exists() ) && propsFile.exists()) {
1415 def ins = new FileInputStream(propsFileName)
1418 if (props.getProperty(propKey, null) != null) {
1419 eclipseWsDir = props.getProperty(propKey)
1423 def writeProps = false
1424 if (eclipseWsDir == null || !file(eclipseWsDir).exists()) {
1425 def tempDir = File.createTempDir()
1426 eclipseWsDir = tempDir.getAbsolutePath()
1429 eclipseWorkspace = file(eclipseWsDir)
1432 // do not run a headless transpile when we claim to be in Eclipse
1434 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1435 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1437 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1441 props.setProperty(propKey, eclipseWsDir)
1442 propsFile.parentFile.mkdirs()
1443 def bytes = new ByteArrayOutputStream()
1444 props.store(bytes, null)
1445 def propertiesString = bytes.toString()
1446 propsFile.text = propertiesString
1449 println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath())
1452 //inputs.property(propKey, eclipseWsDir) // eclipseWsDir only gets set once this task runs, so will be out-of-date
1453 outputs.file(propsFileName)
1454 outputs.upToDateWhen { eclipseWorkspace.exists() }
1458 task jalviewjsEclipsePaths {
1461 def eclipseRoot = jalviewjs_eclipse_root
1462 if (eclipseRoot.startsWith("~/")) {
1463 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
1465 if (OperatingSystem.current().isMacOsX()) {
1466 eclipseRoot += "/Eclipse.app"
1467 eclipseBinary = "${eclipseRoot}/Contents/MacOS/eclipse"
1468 eclipseProduct = "${eclipseRoot}/Contents/Eclipse/.eclipseproduct"
1469 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
1470 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1471 eclipseRoot += "/eclipse.exe"
1473 eclipseBinary = "${eclipseRoot}/eclipse"
1474 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1475 } else { // linux or unix
1476 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1477 eclipseRoot += "/eclipse"
1479 eclipseBinary = "${eclipseRoot}/eclipse"
1480 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1483 eclipseVersion = "4.13" // default
1484 def assumedVersion = true
1485 if (file(eclipseProduct).exists()) {
1486 def fis = new FileInputStream(eclipseProduct)
1487 def props = new Properties()
1489 eclipseVersion = props.getProperty("version")
1491 assumedVersion = false
1494 def propKey = "eclipse_debug"
1495 eclipseDebug = (project.hasProperty(propKey) && project.getProperty(propKey).equals("true"))
1498 // do not run a headless transpile when we claim to be in Eclipse
1500 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1501 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1503 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1506 if (!assumedVersion) {
1507 println("ECLIPSE VERSION=${eclipseVersion}")
1514 dependsOn eclipseProject
1515 dependsOn eclipseClasspath
1516 dependsOn eclipseJdt
1520 // this version (type: Copy) will delete anything in the eclipse dropins folder that isn't in fromDropinsDir
1521 task jalviewjsEclipseCopyDropins(type: Copy) {
1522 dependsOn jalviewjsEclipsePaths
1524 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_eclipse_dropins_dir}", include: "*.jar")
1525 inputFiles += file("${jalviewDir}/${jalviewjs_j2s_plugin}")
1526 def outputDir = "${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}"
1533 // this eclipse -clean doesn't actually work
1534 task jalviewjsCleanEclipse(type: Exec) {
1535 dependsOn eclipseSetup
1536 dependsOn jalviewjsEclipsePaths
1537 dependsOn jalviewjsEclipseCopyDropins
1539 executable(eclipseBinary)
1540 args(["-nosplash", "--launcher.suppressErrors", "-data", eclipseWorkspace.getPath(), "-clean", "-console", "-consoleLog"])
1546 def inputString = """exit
1549 def inputByteStream = new ByteArrayInputStream(inputString.getBytes())
1550 standardInput = inputByteStream
1553 /* not really working yet
1554 jalviewjsEclipseCopyDropins.finalizedBy jalviewjsCleanEclipse
1558 task jalviewjsTransferUnzipSwingJs {
1559 def file_zip = "${jalviewDir}/${jalviewjs_swingjs_zip}"
1563 from zipTree(file_zip)
1564 into "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1568 inputs.file file_zip
1569 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1573 task jalviewjsTransferUnzipLib {
1574 def zipFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_libjs_dir}", include: "*.zip")
1577 zipFiles.each { file_zip ->
1579 from zipTree(file_zip)
1580 into "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1585 inputs.files zipFiles
1586 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1590 task jalviewjsTransferUnzipAllLibs {
1591 dependsOn jalviewjsTransferUnzipSwingJs
1592 dependsOn jalviewjsTransferUnzipLib
1596 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
1598 description "Create the .j2s file from the j2s.* properties"
1600 outputFile ("${jalviewDir}/${jalviewjs_j2s_settings}")
1601 def j2s_props = project.properties.findAll { it.key.startsWith("j2s.") }.sort { it.key }
1602 def siteDirProperty = "j2s.site.directory"
1603 def setSiteDir = false
1604 j2s_props.each { prop, val ->
1606 if (prop == siteDirProperty) {
1607 if (!(val.startsWith('/') || val.startsWith("file://") )) {
1608 val = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${val}"
1614 if (!setSiteDir) { // default site location, don't override specifically set property
1615 property(siteDirProperty,"${jalviewDir}/${jalviewjsTransferSiteJsDir}")
1618 inputs.properties(j2s_props)
1619 outputs.file(outputFile)
1623 task jalviewjsEclipseSetup {
1624 dependsOn jalviewjsEclipseCopyDropins
1625 dependsOn jalviewjsSetEclipseWorkspace
1626 dependsOn jalviewjsCreateJ2sSettings
1630 task jalviewjsSyncAllLibs (type: Sync) {
1631 dependsOn jalviewjsTransferUnzipAllLibs
1632 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteLibDir}")
1633 inputFiles += fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}")
1634 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1638 def outputFiles = []
1639 rename { filename ->
1640 outputFiles += "${outputDir}/${filename}"
1646 outputs.files outputFiles
1647 inputs.files inputFiles
1651 task jalviewjsSyncResources (type: Sync) {
1652 def inputFiles = fileTree(dir: "${jalviewDir}/${resourceDir}")
1653 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1657 def outputFiles = []
1658 rename { filename ->
1659 outputFiles += "${outputDir}/${filename}"
1665 outputs.files outputFiles
1666 inputs.files inputFiles
1670 task jalviewjsSyncSiteResources (type: Sync) {
1671 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_site_resource_dir}")
1672 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1676 def outputFiles = []
1677 rename { filename ->
1678 outputFiles += "${outputDir}/${filename}"
1684 outputs.files outputFiles
1685 inputs.files inputFiles
1689 task jalviewjsSyncBuildProperties (type: Sync) {
1690 dependsOn createBuildProperties
1691 def inputFiles = [file(buildProperties)]
1692 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1696 def outputFiles = []
1697 rename { filename ->
1698 outputFiles += "${outputDir}/${filename}"
1704 outputs.files outputFiles
1705 inputs.files inputFiles
1709 task jalviewjsProjectImport(type: Exec) {
1710 dependsOn eclipseSetup
1711 dependsOn jalviewjsEclipsePaths
1712 dependsOn jalviewjsEclipseSetup
1715 // do not run a headless import when we claim to be in Eclipse
1717 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1718 throw new StopExecutionException("Not running headless import whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1720 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1724 //def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
1725 def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview"
1726 executable(eclipseBinary)
1727 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
1731 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1733 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
1736 inputs.file("${jalviewDir}/.project")
1737 outputs.upToDateWhen {
1738 file(projdir).exists()
1743 task jalviewjsTranspile(type: Exec) {
1744 dependsOn jalviewjsEclipseSetup
1745 dependsOn jalviewjsProjectImport
1746 dependsOn jalviewjsEclipsePaths
1749 // do not run a headless transpile when we claim to be in Eclipse
1751 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1752 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1754 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1758 executable(eclipseBinary)
1759 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-${jalviewjs_eclipse_build_arg}", eclipse_project_name ])
1763 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1765 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
1771 stdout = new ByteArrayOutputStream()
1772 stderr = new ByteArrayOutputStream()
1774 def logOutFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}"
1775 def logOutFile = file(logOutFileName)
1776 logOutFile.createNewFile()
1777 logOutFile.text = """ROOT: ${jalviewjs_eclipse_root}
1778 BINARY: ${eclipseBinary}
1779 VERSION: ${eclipseVersion}
1780 WORKSPACE: ${eclipseWorkspace}
1781 DEBUG: ${eclipseDebug}
1784 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
1785 // combine stdout and stderr
1786 def logErrFOS = logOutFOS
1788 if (jalviewjs_j2s_to_console.equals("true")) {
1789 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1790 new org.apache.tools.ant.util.TeeOutputStream(
1794 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1795 new org.apache.tools.ant.util.TeeOutputStream(
1800 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1803 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1810 if (stdout.toString().contains("Error processing ")) {
1811 // j2s did not complete transpile
1812 //throw new TaskExecutionException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
1813 throw new GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
1817 inputs.dir("${jalviewDir}/${sourceDir}")
1818 outputs.dir("${jalviewDir}/${jalviewjsTransferSiteJsDir}")
1819 outputs.upToDateWhen( { file("${jalviewDir}/${jalviewjsTransferSiteJsDir}${jalviewjs_server_resource}").exists() } )
1823 def jalviewjsCallCore(FileCollection list, String prefixFile, String suffixFile, String jsfile, String zjsfile, File logOutFile, Boolean logOutConsole) {
1825 def stdout = new ByteArrayOutputStream()
1826 def stderr = new ByteArrayOutputStream()
1828 def coreFile = file(jsfile)
1830 msg = "Generating ${jsfile}"
1832 logOutFile.createNewFile()
1833 logOutFile.append(msg+"\n")
1835 def coreTop = file(prefixFile)
1836 def coreBottom = file(suffixFile)
1837 coreFile.getParentFile().mkdirs()
1838 coreFile.createNewFile()
1839 coreFile.write( coreTop.text )
1844 t.replaceAll("Clazz\\.","Clazz_")
1845 t.replaceAll("Class__","Clazz._")
1846 coreFile.append( t )
1848 msg = "...file '"+f.getPath()+"' does not exist, skipping"
1850 logOutFile.append(msg+"\n")
1853 coreFile.append( coreBottom.text )
1855 msg = "Generating ${zjsfile}"
1857 logOutFile.append(msg+"\n")
1858 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
1859 def logErrFOS = logOutFOS
1862 classpath = files(["${jalviewDir}/tools/closure_compiler.jar"])
1863 args = [ "--js", jsfile, "--js_output_file", zjsfile ]
1865 msg = "\nRunning '"+commandLine.join(' ')+"'\n"
1867 logOutFile.append(msg+"\n")
1869 if (logOutConsole) {
1870 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1871 new org.apache.tools.ant.util.TeeOutputStream(
1875 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1876 new org.apache.tools.ant.util.TeeOutputStream(
1881 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1884 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1891 logOutFile.append(msg+"\n")
1895 task jalviewjsBuildAllCores {
1897 description "Build the core js lib closures listed in the classlists dir"
1898 dependsOn jalviewjsTranspile
1899 dependsOn jalviewjsTransferUnzipSwingJs
1901 def j2sDir = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${jalviewjs_j2s_subdir}"
1902 def jsDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${jalviewjs_js_subdir}"
1903 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}/${jalviewjs_j2s_subdir}/core"
1904 def prefixFile = "${jsDir}/core/coretop2.js"
1905 def suffixFile = "${jsDir}/core/corebottom2.js"
1907 inputs.file prefixFile
1908 inputs.file suffixFile
1910 def classlistFiles = []
1911 // add the classlists found int the jalviewjs_classlists_dir
1912 fileTree(dir: "${jalviewDir}/${jalviewjs_classlists_dir}", include: "*.txt").each {
1914 def name = file.getName() - ".txt"
1921 // _jmol and _jalview cores. Add any other peculiar classlist.txt files here
1922 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jmol}"), 'name': "_jvjmol" ]
1923 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jalview}"), 'name': jalviewjsJalviewCoreName ]
1927 classlistFiles.each {
1930 def file = hash['file']
1931 if (! file.exists()) {
1932 println("...classlist file '"+file.getPath()+"' does not exist, skipping")
1933 return false // this is a "continue" in groovy .each closure
1935 def name = hash['name']
1937 name = file.getName() - ".txt"
1945 def list = fileTree(dir: j2sDir, includes: filelist)
1947 def jsfile = "${outputDir}/core${name}.js"
1948 def zjsfile = "${outputDir}/core${name}.z.js"
1958 outputs.file(jsfile)
1959 outputs.file(zjsfile)
1962 // _stevesoft core. add any cores without a classlist here (and the inputs and outputs)
1963 def stevesoftClasslist = [
1964 'jsfile': "${outputDir}/core_stevesoft.js",
1965 'zjsfile': "${outputDir}/core_stevesoft.z.js",
1966 'list': fileTree(dir: j2sDir, include: "com/stevesoft/pat/**/*.js")
1968 classlists += stevesoftClasslist
1969 inputs.files(stevesoftClasslist['list'])
1970 outputs.file(stevesoftClasslist['jsfile'])
1971 outputs.file(stevesoftClasslist['zjsfile'])
1974 def logOutFile = file("${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_closure_stdout}")
1975 logOutFile.getParentFile().mkdirs()
1976 logOutFile.createNewFile()
1977 logOutFile.write(getDate("yyyy-MM-dd HH:mm:ss")+" jalviewjsBuildAllCores\n----\n")
1980 jalviewjsCallCore(it.list, prefixFile, suffixFile, it.jsfile, it.zjsfile, logOutFile, jalviewjs_j2s_to_console.equals("true"))
1987 task jalviewjsPublishCoreTemplate(type: Sync) {
1988 dependsOn jalviewjsBuildAllCores
1990 def inputFile = file("${jalviewDir}/${j2s_template_html}")
1991 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
1995 def outputFiles = []
1996 jalviewjsJalviewCoreHtmlFile = "${jalviewjsJalviewTemplateName}_${jalviewjsJalviewCoreName}.html"
1997 rename { filename ->
1998 outputFiles += "${outputDir}/${filename}"
1999 if (filename.equals(inputFile.getName())) {
2000 return jalviewjsJalviewCoreHtmlFile
2004 filter(ReplaceTokens,
2008 'MAIN': '"'+mainClass+'"',
2010 'NAME': jalviewjsJalviewTemplateName
2013 filter(ReplaceTokens,
2017 'NONE': jalviewjsJalviewCoreName
2023 outputs.files outputFiles
2024 inputs.files inputFile
2028 task jalviewjsSyncCore (type: Sync) {
2029 dependsOn jalviewjsBuildAllCores
2030 dependsOn jalviewjsPublishCoreTemplate
2031 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteCoreDir}")
2032 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
2036 def outputFiles = []
2037 rename { filename ->
2038 outputFiles += "${outputDir}/${filename}"
2044 outputs.files outputFiles
2045 inputs.files inputFiles
2049 // this Copy version of TransferSiteJs will delete anything else in the target dir
2050 task jalviewjsCopyTransferSiteJs(type: Copy) {
2051 dependsOn jalviewjsTranspile
2052 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2053 into "${jalviewDir}/${jalviewjsSiteDir}"
2057 // this Sync version of TransferSite is used by buildship to keep the website automatically up to date when a file changes
2058 task jalviewjsSyncTransferSiteJs(type: Sync) {
2059 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2061 into "${jalviewDir}/${jalviewjsSiteDir}"
2068 jalviewjsSyncAllLibs.mustRunAfter jalviewjsCopyTransferSiteJs
2069 jalviewjsSyncResources.mustRunAfter jalviewjsCopyTransferSiteJs
2070 jalviewjsSyncSiteResources.mustRunAfter jalviewjsCopyTransferSiteJs
2071 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsCopyTransferSiteJs
2073 jalviewjsSyncAllLibs.mustRunAfter jalviewjsSyncTransferSiteJs
2074 jalviewjsSyncResources.mustRunAfter jalviewjsSyncTransferSiteJs
2075 jalviewjsSyncSiteResources.mustRunAfter jalviewjsSyncTransferSiteJs
2076 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsSyncTransferSiteJs
2079 task jalviewjsPrepareSite {
2081 description "Prepares the website folder including unzipping files and copying resources"
2082 dependsOn jalviewjsSyncAllLibs
2083 dependsOn jalviewjsSyncResources
2084 dependsOn jalviewjsSyncSiteResources
2085 dependsOn jalviewjsSyncBuildProperties
2086 dependsOn jalviewjsSyncCore
2090 task jalviewjsBuildSite {
2092 description "Builds the whole website including transpiled code"
2093 dependsOn jalviewjsCopyTransferSiteJs
2094 dependsOn jalviewjsPrepareSite
2098 task cleanJalviewjsSite {
2100 delete "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2101 delete "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
2102 delete "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
2103 delete "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
2104 delete "${jalviewDir}/${jalviewjsSiteDir}"
2109 task jalviewjsSiteTar(type: Tar) {
2111 description "Creates a tar.gz file for the website"
2112 dependsOn jalviewjsBuildSite
2113 def outputFilename = "jalviewjs-site-${JALVIEW_VERSION}.tar.gz"
2115 archiveFileName = outputFilename
2116 } catch (Exception e) {
2117 archiveName = outputFilename
2120 compression Compression.GZIP
2122 from "${jalviewDir}/${jalviewjsSiteDir}"
2123 into jalviewjs_site_dir // this is inside the tar file
2125 inputs.dir("${jalviewDir}/${jalviewjsSiteDir}")
2129 task jalviewjsServer {
2131 def filename = "jalviewjsTest.html"
2132 description "Starts a webserver on localhost to test the website. See ${filename} to access local site on most recently used port."
2133 def htmlFile = "${jalviewDirAbsolutePath}/${filename}"
2136 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
2137 def port = Integer.valueOf(jalviewjs_server_port)
2142 while(port < start+1000 && !running) {
2144 def doc_root = new File("${jalviewDirAbsolutePath}/${jalviewjsSiteDir}")
2145 def jalviewjsServer = factory.start(doc_root, port)
2147 url = jalviewjsServer.getResourceUrl(jalviewjs_server_resource)
2148 urlcore = jalviewjsServer.getResourceUrl(jalviewjsJalviewCoreHtmlFile)
2149 println("SERVER STARTED with document root ${doc_root}.")
2150 println("Go to "+url+" . Run gradle --stop to stop (kills all gradle daemons).")
2151 println("For debug: "+url+"?j2sdebug")
2152 println("For core: "+urlcore)
2154 file(htmlFile).text = """
2155 <p><a href="${url}">JalviewJS Test. <${url}></a></p>
2156 <p><a href="${url}?j2sdebug">JalviewJS Test with debug. <${url}?j2sdebug<</a></p>
2157 <p><a href="${urlcore}">${jalviewjsJalviewTemplateName} Core Test. <${urlcore}></a></p>
2160 } catch (Exception e) {
2167 outputs.file(htmlFile)
2168 outputs.upToDateWhen({false})
2172 task cleanJalviewjsAll {
2174 description "Delete all configuration and build artifacts to do with JalviewJS build"
2175 dependsOn cleanJalviewjsSite
2176 dependsOn jalviewjsEclipsePaths
2179 delete "${jalviewDir}/${jalviewjsBuildDir}"
2180 delete "${jalviewDir}/${eclipse_bin_dir}"
2181 if (eclipseWorkspace != null && file(eclipseWorkspace.getAbsolutePath()+"/.metadata").exists()) {
2182 delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata")
2184 delete "${jalviewDir}/${jalviewjs_j2s_settings}"
2187 outputs.upToDateWhen( { false } )
2192 task jalviewjsIDE_j2sFile {
2193 group "00 JalviewJS in Eclipse"
2194 description "Creates the .j2s file"
2195 dependsOn jalviewjsCreateJ2sSettings
2199 task jalviewjsIDE_SyncCore {
2200 group "00 JalviewJS in Eclipse"
2201 description "Build the core js lib closures listed in the classlists dir and publish core html from template"
2202 dependsOn jalviewjsSyncCore
2206 task jalviewjsIDE_PrepareSite {
2207 group "00 JalviewJS in Eclipse"
2208 description "Sync libs and resources to site dir, but not closure cores"
2209 dependsOn jalviewjsSyncAllLibs
2210 dependsOn jalviewjsSyncResources
2211 dependsOn jalviewjsSyncSiteResources
2212 dependsOn jalviewjsSyncBuildProperties
2216 task jalviewjsIDE_AssembleSite {
2217 group "00 JalviewJS in Eclipse"
2218 description "Assembles unzipped supporting zipfiles, resources, site resources and closure cores into the Eclipse transpiled site"
2219 dependsOn jalviewjsPrepareSite
2223 task jalviewjsIDE_SiteClean {
2224 group "00 JalviewJS in Eclipse"
2225 description "Deletes the Eclipse transpiled site"
2226 dependsOn cleanJalviewjsSite
2230 task jalviewjsIDE_Server {
2231 group "00 JalviewJS in Eclipse"
2232 description "Starts a webserver on localhost to test the website"
2233 dependsOn jalviewjsServer
2237 // buildship runs this at import
2238 task eclipseConfiguration {
2239 dependsOn eclipseSetup
2240 dependsOn jalviewjsIDE_j2sFile
2244 // buildship runs this at build time
2245 task eclipseAutoBuildTask {
2246 dependsOn jalviewjsIDE_PrepareSite
2258 description "Build the site"
2259 dependsOn jalviewjsBuildSite