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'
22 // local build environment properties
23 def localProps = "${jalviewDir}/local.properties"
24 if (file(localProps).exists()) {
26 def p = new Properties()
27 def localPropsFIS = new FileInputStream(localProps)
32 def over = getProperty(key) != null
35 println("Overriding property '${key}' with local.properties value '${val}'")
38 } catch (Exception e) {
39 System.out.println("Exception reading local.properties")
53 compile 'org.apache.commons:commons-compress:1.18'
56 mainClassName = launcherClass
57 def cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
58 def classes = "${jalviewDir}/${classesDir}"
60 if (clover.equals("true")) {
62 classes = "${buildDir}/${cloverClassesDir}"
65 classes = "${jalviewDir}/${classesDir}"
68 // configure classpath/args for j8/j11 compilation
70 def jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
73 def compile_source_compatibility
74 def compile_target_compatibility
78 getdownWebsiteDir = "${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}"
80 reportRsyncCmd = false
82 buildProperties = build_properties_file
83 getdownLauncher = "${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}"
87 // TODO: get bamboo build artifact URL for getdown artifacts
88 getdown_channel_base = bamboo_channelbase
89 getdown_channel_name = "${bamboo_planKey}/${JAVA_VERSION}"
90 getdown_app_base = "${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}"
91 getdown_app_dir = getdown_app_dir_alt
92 buildProperties = "${jalviewDir}/${classesDir}/${build_properties_file}"
96 getdown_channel_name = CHANNEL.toLowerCase()
97 getdownDir = "${getdown_channel_name}/${JAVA_VERSION}"
98 getdown_app_base = "${getdown_channel_base}/${getdownDir}"
99 getdown_app_dir = getdown_app_dir_release
100 buildProperties = "${jalviewDir}/${classesDir}/${build_properties_file}"
101 reportRsyncCommand = true
105 getdown_channel_name = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
106 getdownDir = "${getdown_channel_name}/${JAVA_VERSION}"
107 getdown_app_base = "${getdown_channel_base}/${getdownDir}"
108 getdown_app_dir = getdown_app_dir_alt
109 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
110 print "Must provide an ARCHIVEDIR value to produce an archive distribution"
113 packageDir = "${ARCHIVEDIR}/${packageDir}"
114 buildProperties = "${ARCHIVEDIR}/${classesDir}/${build_properties_file}"
117 reportRsyncCommand = true
121 getdown_channel_name = "archive/${JALVIEW_VERSION}"
122 getdownDir = "${getdown_channel_name}/${JAVA_VERSION}"
123 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
124 getdown_app_dir = getdown_app_dir_alt
125 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
126 print "Must provide an ARCHIVEDIR value to produce an archive distribution"
129 packageDir = "${ARCHIVEDIR}/${packageDir}"
130 buildProperties = "${ARCHIVEDIR}/${classesDir}/${build_properties_file}"
133 reportRsyncCommand = true
134 getdownLauncher = "${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}"
138 getdown_channel_name = CHANNEL.toLowerCase()
139 getdownDir = "${getdown_channel_name}/${JAVA_VERSION}"
140 getdown_app_base = "${getdown_channel_base}/${getdownDir}"
141 getdown_app_dir = getdown_app_dir_alt
142 buildProperties = "${jalviewDir}/${classesDir}/${build_properties_file}"
143 reportRsyncCommand = true
147 getdown_channel_name = CHANNEL.toLowerCase()
148 getdownDir = "${getdown_channel_name}/${JAVA_VERSION}"
149 getdown_app_base = "${getdown_channel_base}/${getdownDir}"
150 getdown_app_dir = getdown_app_dir_alt
151 buildProperties = "${jalviewDir}/${classesDir}/${build_properties_file}"
152 reportRsyncCommand = true
155 case ~/^SCRATCH(|-[-\w]*)$/:
156 getdown_channel_name = CHANNEL
157 getdownDir = "${getdown_channel_name}/${JAVA_VERSION}"
158 getdown_app_base = "${getdown_channel_base}/${getdownDir}"
159 getdown_app_dir = getdown_app_dir_alt
160 buildProperties = "${jalviewDir}/${classesDir}/${build_properties_file}"
161 reportRsyncCommand = true
165 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
166 getdown_app_dir = getdown_app_dir_alt
167 buildProperties = "${jalviewDir}/${classesDir}/${build_properties_file}"
168 getdownLauncher = "${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}"
171 default: // something wrong specified
172 print("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
178 getdownAppDir = "${getdownWebsiteDir}/${getdown_app_dir}"
179 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
180 getdownResourceDir = "${getdownWebsiteDir}/${getdown_resource_dir}"
181 getdownInstallDir = "${getdownWebsiteDir}/${getdown_install_dir}"
182 getdownFilesDir = "${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/"
183 getdownFilesInstallDir = "${getdownFilesDir}/${getdown_install_dir}"
184 /* compile without modules -- using classpath libraries
185 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
186 modules_runtimeClasspath = modules_compileClasspath
191 println("Using a ${CHANNEL} profile.")
194 def JAVA_INTEGER_VERSION
195 def additional_compiler_args = []
196 // these are getdown.txt properties defined dependent on the JAVA_VERSION
197 def getdown_alt_java_min_version
198 def getdown_alt_java_max_version
199 // this property is assigned below and expanded to multiple lines in the getdown task
200 def getdown_alt_multi_java_location
201 // this property is for the Java library used in eclipse
202 def eclipse_java_runtime_name
203 if (JAVA_VERSION.equals("1.8")) {
204 JAVA_INTEGER_VERSION = "8"
207 libDistDir = j8libDir
208 compile_source_compatibility = 1.8
209 compile_target_compatibility = 1.8
210 getdown_alt_java_min_version = getdown_alt_java8_min_version
211 getdown_alt_java_max_version = getdown_alt_java8_max_version
212 getdown_alt_multi_java_location = getdown_alt_java8_txt_multi_java_location
213 eclipse_java_runtime_name = "JavaSE-1.8"
214 } else if (JAVA_VERSION.equals("11")) {
215 JAVA_INTEGER_VERSION = "11"
217 libDistDir = j11libDir
218 compile_source_compatibility = 11
219 compile_target_compatibility = 11
220 getdown_alt_java_min_version = getdown_alt_java11_min_version
221 getdown_alt_java_max_version = getdown_alt_java11_max_version
222 getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
223 eclipse_java_runtime_name = "JavaSE-11"
224 /* compile without modules -- using classpath libraries
225 additional_compiler_args += [
226 '--module-path', ext.modules_compileClasspath.asPath,
227 '--add-modules', j11modules
230 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
231 JAVA_INTEGER_VERSION = JAVA_VERSION
233 libDistDir = j11libDir
234 compile_source_compatibility = JAVA_VERSION
235 compile_target_compatibility = JAVA_VERSION
236 getdown_alt_java_min_version = getdown_alt_java11_min_version
237 getdown_alt_java_max_version = getdown_alt_java11_max_version
238 getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
239 eclipse_java_runtime_name = "JavaSE-11"
240 /* compile without modules -- using classpath libraries
241 additional_compiler_args += [
242 '--module-path', ext.modules_compileClasspath.asPath,
243 '--add-modules', j11modules
247 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
255 srcDirs "${jalviewDir}/${sourceDir}"
256 outputDir = file("${classes}")
260 srcDirs "${jalviewDir}/${resourceDir}"
263 jar.destinationDir = file("${jalviewDir}/${packageDir}")
265 compileClasspath = files(sourceSets.main.java.outputDir)
266 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
268 runtimeClasspath = compileClasspath
273 srcDirs = [ cloverInstrDir ]
274 outputDir = file("${buildDir}/${cloverClassesDir}")
278 srcDirs = sourceSets.main.resources.srcDirs
280 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
281 compileClasspath += files(sourceSets.main.java.outputDir)
282 compileClasspath += sourceSets.main.compileClasspath
283 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
284 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
286 runtimeClasspath = compileClasspath
291 srcDirs "${jalviewDir}/${testSourceDir}"
292 outputDir = file("${jalviewDir}/${testOutputDir}")
296 srcDirs = sourceSets.main.resources.srcDirs
299 compileClasspath = files( sourceSets.test.java.outputDir )
302 compileClasspath += sourceSets.clover.compileClasspath
304 compileClasspath += files(sourceSets.main.java.outputDir)
307 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
308 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
309 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
311 runtimeClasspath = compileClasspath
319 cloverCompile 'org.openclover:clover:4.3.1'
320 testCompile 'org.openclover:clover:4.3.1'
327 cloverRuntime.extendsFrom cloverCompile
333 name = eclipse_project_name
335 natures 'org.eclipse.jdt.core.javanature',
336 'org.eclipse.jdt.groovy.core.groovyNature',
337 'org.eclipse.buildship.core.gradleprojectnature'
339 buildCommand 'org.eclipse.jdt.core.javabuilder'
340 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
344 //defaultOutputDir = sourceSets.main.java.outputDir
347 if (it.isCanBeResolved()) {
352 minusConfigurations += removeThese
353 plusConfigurations = [ ]
357 def removeTheseToo = []
358 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
359 cp.entries.each { entry ->
360 if (entry.kind == 'src') {
361 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == sourceDir || entry.path == testSourceDir)) {
362 removeTheseToo += entry
364 alreadyAddedSrcPath.putAt(entry.path, true)
368 cp.entries.removeAll(removeTheseToo)
370 if (file("${jalviewDir}/${eclipse_bin_dir}/main").isDirectory()) {
371 cp.entries += new Output("${eclipse_bin_dir}/main")
373 if (file(helpParentDir).isDirectory()) {
374 cp.entries += new Library(fileReference(helpParentDir))
376 if (file(resourceDir).isDirectory()) {
377 cp.entries += new Library(fileReference(resourceDir))
380 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
382 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.each {
383 //don't want to add outputDir as eclipse is using its own output dir in bin/main
384 if (it.isDirectory() || ! it.exists()) {
385 // don't add dirs to classpath
388 def itPath = it.toString()
389 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
390 // make relative path
391 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
393 if (alreadyAddedLibPath.get(itPath)) {
394 //println("Not adding duplicate entry "+itPath)
396 //println("Adding entry "+itPath)
397 cp.entries += new Library(fileReference(itPath))
398 alreadyAddedLibPath.put(itPath, true)
402 //fileTree(dir: "$jalviewDir/$utilsDir", include: ["test*/*.jar"]).each {
403 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
404 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
405 if (it.isDirectory() || ! it.exists()) {
406 // don't add dirs to classpath
407 return false // groovy "continue" in .any closure
410 def itPath = it.toString()
411 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
412 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
414 if (alreadyAddedLibPath.get(itPath)) {
417 def lib = new Library(fileReference(itPath))
418 lib.entryAttributes["test"] = "true"
420 alreadyAddedLibPath.put(itPath, true)
428 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
433 // for the IDE, use java 11 compatibility
434 sourceCompatibility = compile_source_compatibility
435 targetCompatibility = compile_target_compatibility
436 javaRuntimeName = eclipse_java_runtime_name
438 // add in jalview project specific properties/preferences into eclipse core preferences
440 withProperties { props ->
441 def jalview_prefs = new Properties()
442 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
443 jalview_prefs.load(ins)
445 jalview_prefs.forEach { t, v ->
446 if (props.getAt(t) == null) {
455 synchronizationTasks "eclipseSynchronizationTask"
456 autoBuildTasks "eclipseAutoBuildTask"
462 // only instrument source, we build test classes as normal
463 inputs.files files (sourceSets.main.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
464 outputs.dir cloverInstrDir
467 delete cloverInstrDir
468 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
469 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
470 argsList.addAll(inputs.files.files.collect({ file ->
473 String[] args = argsList.toArray()
474 println("About to instrument "+args.length +" files")
475 com.atlassian.clover.CloverInstr.mainImpl(args)
481 group = "Verification"
482 description = "Createst the Clover report"
483 inputs.dir "${buildDir}/clover"
484 outputs.dir "${reportsDir}/clover"
486 file("${buildDir}/clover/clover.db").exists()
489 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
490 "-o", "${reportsDir}/clover"]
491 String[] args = argsList.toArray()
492 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
494 // and generate ${reportsDir}/clover/clover.xml
495 args = ["--initstring", "${buildDir}/clover/clover.db",
496 "-o", "${reportsDir}/clover/clover.xml"].toArray()
497 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
506 sourceCompatibility = compile_source_compatibility
507 targetCompatibility = compile_target_compatibility
508 options.compilerArgs = additional_compiler_args
509 print ("Setting target compatibility to "+targetCompatibility+"\n")
517 dependsOn compileCloverJava
518 classpath += configurations.cloverRuntime
520 classpath += sourceSets.main.runtimeClasspath
523 sourceCompatibility = compile_source_compatibility
524 targetCompatibility = compile_target_compatibility
525 options.compilerArgs = additional_compiler_args
526 print ("Setting target compatibility to "+targetCompatibility+"\n")
534 sourceCompatibility = compile_source_compatibility
535 targetCompatibility = compile_target_compatibility
536 options.compilerArgs += additional_compiler_args
537 print ("Setting target compatibility to "+targetCompatibility+"\n")
539 classpath += configurations.cloverRuntime
545 delete sourceSets.main.java.outputDir
552 delete sourceSets.test.java.outputDir
553 delete cloverInstrDir
558 // format is a string like date.format("dd MMMM yyyy")
559 def getDate(format) {
560 def date = new Date()
561 return date.format(format)
566 def hashStdOut = new ByteArrayOutputStream()
568 commandLine "git", "rev-parse", "--short", "HEAD"
569 standardOutput = hashStdOut
573 def branchStdOut = new ByteArrayOutputStream()
575 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
576 standardOutput = branchStdOut
580 project.ext.gitHash = hashStdOut.toString().trim()
581 project.ext.gitBranch = branchStdOut.toString().trim()
583 outputs.upToDateWhen { false }
587 task createBuildProperties(type: WriteProperties) {
589 inputs.dir("${jalviewDir}/${sourceDir}")
590 inputs.dir("${jalviewDir}/${resourceDir}")
591 file(buildProperties).getParentFile().mkdirs()
592 outputFile (buildProperties)
593 // taking time specific comment out to allow better incremental builds
594 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
595 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
596 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
597 property "VERSION", JALVIEW_VERSION
598 property "INSTALLATION", INSTALLATION+" git-commit:"+project.ext.gitHash+" ["+project.ext.gitBranch+"]"
599 outputs.file(outputFile)
603 def buildingHTML = "${jalviewDir}/${docDir}/building.html"
604 task cleanBuildingHTML(type: Delete) {
611 task convertBuildingMD(type: Exec) {
612 dependsOn cleanBuildingHTML
613 def buildingMD = "${jalviewDir}/${docDir}/building.md"
614 def css = "${jalviewDir}/${docDir}/github.css"
617 pandoc_exec.split(",").each {
618 if (file(it.trim()).exists()) {
624 def hostname = "hostname".execute().text.trim()
625 if ((pandoc == null || ! file(pandoc).exists()) && hostname.equals("jv-bamboo")) {
626 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
630 if (pandoc != null && file(pandoc).exists()) {
631 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
633 println("Cannot find pandoc. Skipping convert building.md to HTML")
634 throw new StopExecutionException()
640 inputs.file(buildingMD)
642 outputs.file(buildingHTML)
653 task syncDocs(type: Sync) {
654 dependsOn convertBuildingMD
655 def syncDir = "${classes}/${docDir}"
656 from fileTree("${jalviewDir}/${docDir}")
662 def helpFile = "${classes}/${helpDir}/help.jhm"
663 task copyHelp(type: Copy) {
664 def inputDir = "${jalviewDir}/${helpParentDir}/${helpDir}"
665 def outputDir = "${classes}/${helpDir}"
670 filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['Version-Rel': JALVIEW_VERSION,'Year-Rel': getDate("yyyy")])
680 outputs.files(helpFile)
681 outputs.dir(outputDir)
685 task syncLib(type: Sync) {
686 def syncDir = "${classes}/${libDistDir}"
687 from fileTree("${jalviewDir}/${libDistDir}")
692 task syncResources(type: Sync) {
693 from "${jalviewDir}/${resourceDir}"
703 dependsOn syncResources
709 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
712 dependsOn compileJava
714 dependsOn cloverInstr
718 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
722 includeGroups testngGroups
724 useDefaultListeners=true
727 workingDir = jalviewDir
728 //systemProperties 'clover.jar' System.properties.clover.jar
729 sourceCompatibility = compile_source_compatibility
730 targetCompatibility = compile_target_compatibility
731 jvmArgs += additional_compiler_args
736 task buildIndices(type: JavaExec) {
738 classpath = sourceSets.main.compileClasspath
739 main = "com.sun.java.help.search.Indexer"
740 workingDir = "${classes}/${helpDir}"
743 inputs.dir("${workingDir}/${argDir}")
745 outputs.dir("${classes}/doc")
746 outputs.dir("${classes}/help")
747 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
748 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
749 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
750 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
751 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
752 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
756 task compileLinkCheck(type: JavaCompile) {
758 classpath = files("${jalviewDir}/${utilsDir}")
759 destinationDir = file("${jalviewDir}/${utilsDir}")
760 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
762 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
763 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
764 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
765 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
769 task linkCheck(type: JavaExec) {
770 dependsOn prepare, compileLinkCheck
772 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
773 classpath = files("${jalviewDir}/${utilsDir}")
774 main = "HelpLinksChecker"
775 workingDir = jalviewDir
776 def help = "${classes}/${helpDir}"
777 args = [ "${classes}/${helpDir}", "-nointernet" ]
779 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
781 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
784 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
788 inputs.dir("${classes}/${helpDir}")
789 outputs.file(helpLinksCheckerOutFile)
792 // import the pubhtmlhelp target
793 ant.properties.basedir = "${jalviewDir}"
794 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes}/${helpDir}"
795 ant.importBuild "${utilsDir}/publishHelp.xml"
798 task cleanPackageDir(type: Delete) {
800 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
806 dependsOn buildIndices
807 dependsOn createBuildProperties
810 attributes "Main-Class": mainClass,
811 "Permissions": "all-permissions",
812 "Application-Name": "Jalview Desktop",
813 "Codebase": application_codebase
816 destinationDir = file("${jalviewDir}/${packageDir}")
817 archiveName = rootProject.name+".jar"
825 inputs.dir("${classes}")
826 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
830 task copyJars(type: Copy) {
831 from fileTree(dir: "${classes}", include: "**/*.jar").files
832 into "${jalviewDir}/${packageDir}"
836 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
837 task syncJars(type: Sync) {
838 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
839 into "${jalviewDir}/${packageDir}"
841 include jar.archiveName
848 description = "Put all required libraries in dist"
849 // order of "cleanPackageDir", "copyJars", "jar" important!
850 jar.mustRunAfter cleanPackageDir
851 syncJars.mustRunAfter cleanPackageDir
852 dependsOn cleanPackageDir
855 outputs.dir("${jalviewDir}/${packageDir}")
860 dependsOn cleanPackageDir
866 group = "distribution"
870 from ("${jalviewDir}/${libDistDir}") {
874 attributes 'Implementation-Version': JALVIEW_VERSION
876 mainClassName = shadowJarMainClass
878 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
883 task getdownWebsite() {
884 group = "distribution"
885 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
890 def getdownWebsiteResourceFilenames = []
891 def getdownTextString = ""
892 def getdownResourceDir = project.ext.getdownResourceDir
893 def getdownAppDir = project.ext.getdownAppDir
894 def getdownResourceFilenames = []
897 // clean the getdown website and files dir before creating getdown folders
898 delete project.ext.getdownWebsiteDir
899 delete project.ext.getdownFilesDir
903 rename(build_properties_file, getdown_build_properties)
904 into project.ext.getdownAppDir
906 getdownWebsiteResourceFilenames += "${getdown_app_dir}/${getdown_build_properties}"
908 // go through properties looking for getdown_txt_...
909 def props = project.properties.sort { it.key }
910 if (getdown_alt_java_min_version.length() > 0) {
911 props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
913 if (getdown_alt_java_max_version.length() > 0) {
914 props.put("getdown_txt_java_max_version", getdown_alt_java_max_version)
916 props.put("getdown_txt_multi_java_location", getdown_alt_multi_java_location)
918 props.put("getdown_txt_appbase", getdown_app_base)
919 props.each{ prop, val ->
920 if (prop.startsWith("getdown_txt_") && val != null) {
921 if (prop.startsWith("getdown_txt_multi_")) {
922 def key = prop.substring(18)
923 val.split(",").each{ v ->
924 def line = "${key} = ${v}\n"
925 getdownTextString += line
928 // file values rationalised
929 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
931 if (val.indexOf('/') == 0) {
934 } else if (val.indexOf('/') > 0) {
935 // relative path (relative to jalviewDir)
936 r = file( "${jalviewDir}/${val}" )
939 val = "${getdown_resource_dir}/" + r.getName()
940 getdownWebsiteResourceFilenames += val
941 getdownResourceFilenames += r.getPath()
944 if (! prop.startsWith("getdown_txt_resource")) {
945 def line = prop.substring(12) + " = ${val}\n"
946 getdownTextString += line
952 getdownWebsiteResourceFilenames.each{ filename ->
953 getdownTextString += "resource = ${filename}\n"
955 getdownResourceFilenames.each{ filename ->
958 into project.ext.getdownResourceDir
963 fileTree(file(packageDir)).each{ f ->
964 if (f.isDirectory()) {
965 def files = fileTree(dir: f, include: ["*"]).getFiles()
967 } else if (f.exists()) {
971 codeFiles.sort().each{f ->
972 def name = f.getName()
973 def line = "code = ${getdown_app_dir}/${name}\n"
974 getdownTextString += line
977 into project.ext.getdownAppDir
981 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
983 if (JAVA_VERSION.equals("11")) {
984 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
985 j11libFiles.sort().each{f ->
986 def name = f.getName()
987 def line = "code = ${getdown_j11lib_dir}/${name}\n"
988 getdownTextString += line
991 into project.ext.getdownJ11libDir
997 // 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.
998 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
999 getdownTextString += "resource = ${getdown_launcher_new}\n"
1000 getdownTextString += "class = ${mainClass}\n"
1002 def getdown_txt = file("${project.ext.getdownWebsiteDir}/getdown.txt")
1003 getdown_txt.write(getdownTextString)
1005 def launch_jvl = file("${project.ext.getdownWebsiteDir}/${getdown_launch_jvl}")
1006 launch_jvl.write("appbase="+props.get("getdown_txt_appbase"))
1009 from getdownLauncher
1010 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1011 into project.ext.getdownWebsiteDir
1015 from getdownLauncher
1016 if (file(getdownLauncher).getName() != getdown_launcher) {
1017 rename(file(getdownLauncher).getName(), getdown_launcher)
1019 into project.ext.getdownWebsiteDir
1022 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1025 from getdownLauncher
1026 from "${getdownWebsiteDir}/${getdown_build_properties}"
1027 if (file(getdownLauncher).getName() != getdown_launcher) {
1028 rename(file(getdownLauncher).getName(), getdown_launcher)
1030 into getdownInstallDir
1034 from getdownInstallDir
1035 into getdownFilesInstallDir
1042 from getdownLauncher
1043 from "${getdownWebsiteDir}/${getdown_build_properties}"
1044 if (file(getdownLauncher).getName() != getdown_launcher) {
1045 rename(file(getdownLauncher).getName(), getdown_launcher)
1047 into getdownFilesDir
1051 from getdownResourceDir
1052 into "${project.ext.getdownFilesDir}/${getdown_resource_dir}"
1057 inputs.dir("${jalviewDir}/${packageDir}")
1059 outputs.dir(project.ext.getdownWebsiteDir)
1060 outputs.dir(project.ext.getdownFilesDir)
1064 task getdownDigest(type: JavaExec) {
1065 group = "distribution"
1066 description = "Digest the getdown website folder"
1067 dependsOn getdownWebsite
1069 classpath = files("${getdownWebsiteDir}/${getdown_launcher}")
1071 main = "com.threerings.getdown.tools.Digester"
1072 args project.ext.getdownWebsiteDir
1073 inputs.dir(project.ext.getdownWebsiteDir)
1074 outputs.file("${project.ext.getdownWebsiteDir}/digest2.txt")
1079 group = "distribution"
1080 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1081 dependsOn getdownDigest
1083 if (reportRsyncCommand) {
1084 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1085 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1086 println "LIKELY RSYNC COMMAND:"
1087 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1088 if (RUNRSYNC == "true") {
1090 commandLine "mkdir", "-p", toDir
1093 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1103 delete project.ext.getdownWebsiteDir
1104 delete project.ext.getdownFilesDir
1110 def install4jHomeDir = "/opt/install4j"
1111 def hostname = "hostname".execute().text.trim()
1112 if (hostname.equals("jv-bamboo")) {
1113 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1114 } else if (OperatingSystem.current().isMacOsX()) {
1115 install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app'
1116 if (! file(install4jHomeDir).exists()) {
1117 install4jHomeDir = System.getProperty("user.home")+install4jHomeDir
1119 } else if (OperatingSystem.current().isLinux()) {
1120 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1122 installDir = file(install4jHomeDir)
1123 mediaTypes = Arrays.asList(install4jMediaTypes.split(","))
1124 if (install4jFaster.equals("true")) {
1133 def windowsJavaVMDir
1134 def windowsJavaVMTgz
1135 def install4jDir = "${jalviewDir}/${install4jResourceDir}"
1136 def install4jConfFile = "jalview-installers-java${JAVA_VERSION}.install4j"
1137 install4jConf = "${install4jDir}/${install4jConfFile}"
1139 task copyInstall4jTemplate(type: Copy) {
1140 macosJavaVMDir = "${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/macos-jre${JAVA_VERSION}/jre"
1141 macosJavaVMTgz = "${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/macos-jre${JAVA_VERSION}.tar.gz"
1142 windowsJavaVMDir = "${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/windows-jre${JAVA_VERSION}/jre"
1143 windowsJavaVMTgz = "${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/windows-jre${JAVA_VERSION}.tar.gz"
1144 from (install4jDir) {
1145 include install4jTemplate
1146 rename (install4jTemplate, install4jConfFile)
1147 filter(ReplaceTokens, beginToken: '', endToken: '', tokens: ['9999999999': JAVA_VERSION])
1148 filter(ReplaceTokens, beginToken: '$$', endToken: '$$',
1150 'JAVA_VERSION': JAVA_VERSION,
1151 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1152 'VERSION': JALVIEW_VERSION,
1153 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1154 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1155 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1156 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1157 'INSTALL4JINFOPLISTFILEASSOCIATIONS': install4jInfoPlistFileAssociations,
1158 'COPYRIGHT_MESSAGE': install4jCopyrightMessage,
1159 'MACOS_BUNDLE_ID': install4jMacOSBundleId,
1160 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1161 'GETDOWN_DIST_DIR': getdown_app_dir,
1162 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1163 'GETDOWN_INSTALL_DIR': getdown_install_dir
1166 if (OSX_KEYPASS=="") {
1167 filter(ReplaceTokens, beginToken: 'codeSigning macEnabled="', endToken: '"', tokens: ['true':'codeSigning macEnabled="false"'])
1168 filter(ReplaceTokens, beginToken: 'runPostProcessor="true" ',endToken: 'Processor', tokens: ['post':'runPostProcessor="false" postProcessor'])
1172 outputs.files(install4jConf)
1175 // include file associations in installer
1176 def installerFileAssociationsXml = file("${install4jDir}/${install4jInstallerFileAssociations}").text
1180 match: '<action name="EXTENSIONS_REPLACED_BY_GRADLE".*?</action>',
1181 replace: installerFileAssociationsXml,
1185 // include uninstaller applescript app files in dmg
1186 def installerDMGUninstallerXml = file("$install4jDir/$install4jDMGUninstallerAppFiles").text
1190 match: '<file name="UNINSTALL_OLD_JALVIEW_APP_REPLACED_IN_GRADLE" file=.*?>',
1191 replace: installerDMGUninstallerXml,
1199 task installers(type: com.install4j.gradle.Install4jTask) {
1200 group = "distribution"
1201 description = "Create the install4j installers"
1203 dependsOn copyInstall4jTemplate
1204 projectFile = file(install4jConf)
1205 variables = [majorVersion: version.substring(2, 11), build: 001, OSX_KEYSTORE: OSX_KEYSTORE, JSIGN_SH: JSIGN_SH]
1206 destination = "${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}"
1207 buildSelected = true
1210 macKeystorePassword=OSX_KEYPASS
1214 println("Using projectFile "+projectFile)
1217 inputs.dir(project.ext.getdownWebsiteDir)
1218 inputs.file(install4jConf)
1219 inputs.dir(macosJavaVMDir)
1220 inputs.dir(windowsJavaVMDir)
1221 outputs.dir("${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}")
1227 delete install4jConf
1232 task sourceDist (type: Tar) {
1234 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1235 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1236 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1238 archiveFileName = outputFileName
1239 } catch (Exception e) {
1240 archiveName = outputFileName
1243 compression Compression.GZIP
1247 def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1252 ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1254 ,"utils/InstallAnywhere"]
1255 def PROCESS_FILES=[ "AUTHORS",
1263 "THIRDPARTYLIBS","TESTNG",
1265 "gradle.properties",
1276 exclude (EXCLUDE_FILES)
1277 include (PROCESS_FILES)
1278 filter(ReplaceTokens, beginToken: '$$', endToken: '$$', tokens: ['Version-Rel': JALVIEW_VERSION,'Year-Rel': getDate("yyyy")])
1281 exclude (EXCLUDE_FILES)
1282 exclude (PROCESS_FILES)
1283 exclude ("appletlib")
1284 exclude ("**/*locales")
1285 exclude ("*locales/**")
1286 exclude ("utils/InstallAnywhere")
1288 exclude (getdown_files_dir)
1289 exclude (getdown_website_dir)
1291 // exluding these as not using jars as modules yet
1292 exclude ("${j11modDir}/**/*.jar")
1294 // from (jalviewDir) {
1295 // // explicit includes for stuff that seemed to not get included
1296 // include(fileTree("test/**/*."))
1297 // exclude(EXCLUDE_FILES)
1298 // exclude(PROCESS_FILES)
1305 dependsOn pubhtmlhelp
1307 inputs.dir("${classes}/${helpDir}")
1308 outputs.dir("${helpOutputDir}")
1312 def jalviewjsBuildDir
1313 def jalviewjsSiteDir
1314 def jalviewjsTransferSiteJsDir
1315 def jalviewjsTransferSiteLibDir
1316 def jalviewjsTransferSiteSwingJsDir
1317 def jalviewjsTransferSiteCoreDir
1318 task jalviewjsSitePath {
1319 def relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
1320 jalviewjsBuildDir = "${relativeBuildDir}/jalviewjs"
1321 jalviewjsSiteDir = "${jalviewjsBuildDir}/${jalviewjs_site_dir}"
1322 jalviewjsTransferSiteJsDir = "${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js"
1323 jalviewjsTransferSiteLibDir = "${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib"
1324 jalviewjsTransferSiteSwingJsDir = "${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs"
1325 jalviewjsTransferSiteCoreDir = "${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core"
1329 def eclipseWorkspace
1330 task jalviewjsSetEclipseWorkspace {
1331 def propKey = "jalviewjs_eclipse_workspace"
1333 if (project.hasProperty(propKey)) {
1334 propVal = project.getProperty(propKey)
1335 if (propVal.startsWith("~/")) {
1336 propVal = System.getProperty("user.home") + propVal.substring(1)
1339 def propsFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_workspace_location_file}"
1340 def propsFile = file(propsFileName)
1341 def eclipseWsDir = propVal
1342 def props = new Properties()
1344 if (( eclipseWsDir == null || !file(eclipseWsDir).exists() ) && propsFile.exists()) {
1345 def ins = new FileInputStream(propsFileName)
1348 if (props.getProperty(propKey, null) != null) {
1349 eclipseWsDir = props.getProperty(propKey)
1353 def writeProps = false
1354 if (eclipseWsDir == null || !file(eclipseWsDir).exists()) {
1355 def tempDir = File.createTempDir()
1356 eclipseWsDir = tempDir.getAbsolutePath()
1359 eclipseWorkspace = file(eclipseWsDir)
1363 props.setProperty(propKey, eclipseWsDir)
1364 propsFile.parentFile.mkdirs()
1365 def bytes = new ByteArrayOutputStream()
1366 props.store(bytes, null)
1367 def propertiesString = bytes.toString()
1368 propsFile.text = propertiesString
1371 println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath())
1374 //inputs.property(propKey, eclipseWsDir) // eclipseWsDir only gets set once this task runs, so will be out-of-date
1375 outputs.file(propsFileName)
1376 outputs.upToDateWhen { eclipseWorkspace.exists() }
1382 def eclipseDebug = false
1383 def eclipseVersionSuffix = ""
1384 task jalviewjsEclipsePaths {
1387 def eclipseRoot = jalviewjs_eclipse_root
1388 if (eclipseRoot.startsWith("~/")) {
1389 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
1391 if (OperatingSystem.current().isMacOsX()) {
1392 eclipseRoot += "/Eclipse.app"
1393 eclipseBinary = "${eclipseRoot}/Contents/MacOS/eclipse"
1394 eclipseProduct = "${eclipseRoot}/Contents/Eclipse/.eclipseproduct"
1395 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
1396 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1397 eclipseRoot += "/eclipse.exe"
1399 eclipseBinary = "${eclipseRoot}/eclipse"
1400 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1401 } else { // linux or unix
1402 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1403 eclipseRoot += "/eclipse"
1405 eclipseBinary = "${eclipseRoot}/eclipse"
1406 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1409 eclipseVersion = "4.13" // default
1410 def assumedVersion = true
1411 if (file(eclipseProduct).exists()) {
1412 def fis = new FileInputStream(eclipseProduct)
1413 def props = new Properties()
1415 eclipseVersion = props.getProperty("version")
1417 assumedVersion = false
1420 def propKey = "eclipse_debug"
1421 eclipseDebug = (project.hasProperty(propKey) && project.getProperty(propKey).equals("true"))
1424 if (!assumedVersion) {
1425 println("ECLIPSE VERSION=${eclipseVersion}")
1432 dependsOn eclipseProject
1433 dependsOn eclipseClasspath
1434 dependsOn eclipseJdt
1438 // this version (type: Copy) will delete anything in the eclipse dropins folder that isn't in fromDropinsDir
1439 task jalviewjsEclipseCopyDropins(type: Copy) {
1440 dependsOn jalviewjsEclipsePaths
1442 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_eclipse_dropins_dir}", include: "*.jar")
1443 inputFiles += file("${jalviewDir}/${jalviewjs_j2s_plugin}")
1444 def outputDir = "${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}"
1451 // this eclipse -clean doesn't actually work
1452 task jalviewjsCleanEclipse(type: Exec) {
1453 dependsOn eclipseSetup
1454 dependsOn jalviewjsEclipsePaths
1455 dependsOn jalviewjsEclipseCopyDropins
1457 executable(eclipseBinary)
1458 args(["-nosplash", "--launcher.suppressErrors", "-data", eclipseWorkspace.getPath(), "-clean", "-console", "-consoleLog"])
1464 def inputString = """exit
1467 def inputByteStream = new ByteArrayInputStream(inputString.getBytes())
1468 standardInput = inputByteStream
1471 /* not really working yet
1472 jalviewjsEclipseCopyDropins.finalizedBy jalviewjsCleanEclipse
1476 task jalviewjsTransferUnzipSwingJs {
1477 dependsOn jalviewjsSitePath
1479 def file_zip = "${jalviewDir}/${jalviewjs_swingjs_zip}"
1483 from zipTree(file_zip)
1484 into "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1488 inputs.file file_zip
1489 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1493 task jalviewjsTransferUnzipLib {
1494 dependsOn jalviewjsSitePath
1496 def zipFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_libjs_dir}", include: "*.zip")
1499 zipFiles.each { file_zip ->
1501 from zipTree(file_zip)
1502 into "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1507 inputs.files zipFiles
1508 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1512 task jalviewjsTransferUnzipAllLibs {
1513 dependsOn jalviewjsTransferUnzipSwingJs
1514 dependsOn jalviewjsTransferUnzipLib
1518 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
1520 description "Create the .j2s file from the j2s.* properties"
1522 dependsOn jalviewjsSitePath
1524 outputFile ("${jalviewDir}/${jalviewjs_j2s_settings}")
1525 def j2s_props = project.properties.findAll { it.key.startsWith("j2s.") }.sort { it.key }
1526 def siteDirProperty = "j2s.site.directory"
1527 def setSiteDir = false
1528 j2s_props.each { prop, val ->
1530 if (prop == siteDirProperty) {
1531 if (!(val.startsWith('/') || val.startsWith("file://") )) {
1532 val = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${val}"
1538 if (!setSiteDir) { // default site location, don't override specifically set property
1539 property(siteDirProperty,"${jalviewDir}/${jalviewjsTransferSiteJsDir}")
1542 inputs.properties(j2s_props)
1543 outputs.file(outputFile)
1547 task jalviewjsEclipseSetup {
1548 dependsOn jalviewjsEclipseCopyDropins
1549 dependsOn jalviewjsSetEclipseWorkspace
1550 dependsOn jalviewjsCreateJ2sSettings
1554 task jalviewjsSyncAllLibs (type: Sync) {
1555 dependsOn jalviewjsSitePath
1556 dependsOn jalviewjsTransferUnzipAllLibs
1557 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteLibDir}")
1558 inputFiles += fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}")
1559 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1563 def outputFiles = []
1564 rename { filename ->
1565 outputFiles += "${outputDir}/${filename}"
1571 outputs.files outputFiles
1572 inputs.files inputFiles
1576 task jalviewjsSyncResources (type: Sync) {
1577 dependsOn jalviewjsSitePath
1578 def inputFiles = fileTree(dir: "${jalviewDir}/${resourceDir}")
1579 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1583 def outputFiles = []
1584 rename { filename ->
1585 outputFiles += "${outputDir}/${filename}"
1591 outputs.files outputFiles
1592 inputs.files inputFiles
1596 task jalviewjsSyncSiteResources (type: Sync) {
1597 dependsOn jalviewjsSitePath
1598 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_site_resource_dir}")
1599 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1603 def outputFiles = []
1604 rename { filename ->
1605 outputFiles += "${outputDir}/${filename}"
1611 outputs.files outputFiles
1612 inputs.files inputFiles
1616 task jalviewjsSyncBuildProperties (type: Sync) {
1617 dependsOn jalviewjsSitePath
1618 dependsOn createBuildProperties
1619 def inputFiles = [file(buildProperties)]
1620 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1624 def outputFiles = []
1625 rename { filename ->
1626 outputFiles += "${outputDir}/${filename}"
1632 outputs.files outputFiles
1633 inputs.files inputFiles
1637 task jalviewjsProjectImport(type: Exec) {
1638 dependsOn eclipseSetup
1639 dependsOn jalviewjsEclipsePaths
1640 dependsOn jalviewjsEclipseSetup
1642 //def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
1643 def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview"
1644 executable(eclipseBinary)
1645 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
1649 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1651 inputs.file("${jalviewDir}/.project")
1652 outputs.upToDateWhen {
1653 file(projdir).exists()
1658 task jalviewjsTranspile(type: Exec) {
1659 dependsOn jalviewjsEclipseSetup
1660 dependsOn jalviewjsProjectImport
1661 dependsOn jalviewjsEclipsePaths
1663 executable(eclipseBinary)
1664 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-${jalviewjs_eclipse_build_arg}", eclipse_project_name ])
1668 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1673 stdout = new ByteArrayOutputStream()
1674 stderr = new ByteArrayOutputStream()
1676 def logOutFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}"
1677 def logOutFile = file(logOutFileName)
1678 logOutFile.createNewFile()
1679 logOutFile.text = """ROOT: ${jalviewjs_eclipse_root}
1680 BINARY: ${eclipseBinary}
1681 VERSION: ${eclipseVersion}
1682 WORKSPACE: ${eclipseWorkspace}
1683 DEBUG: ${eclipseDebug}
1686 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
1687 //def logErrFileName = "${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}"
1688 //def logErrFile = file(logFileName)
1689 //logErrFile.createNewFile()
1690 //def logErrFOS = new FileErrputStream(logErrFile, false)
1691 // combine stdout and stderr
1692 def logErrFOS = logOutFOS
1694 if (jalviewjs_j2s_to_console.equals("true")) {
1695 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1696 new org.apache.tools.ant.util.TeeOutputStream(
1700 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1701 new org.apache.tools.ant.util.TeeOutputStream(
1706 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1709 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1716 if (stdout.toString().contains("Error processing ")) {
1717 // j2s did not complete transpile
1718 throw new GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
1722 inputs.dir("${jalviewDir}/${sourceDir}")
1723 outputs.dir("${jalviewDir}/${jalviewjsTransferSiteJsDir}")
1724 outputs.upToDateWhen( { file("${jalviewDir}/${jalviewjsTransferSiteJsDir}${jalviewjs_server_resource}").exists() } )
1728 task jalviewjsNoTranspileSyncCore (type: Sync) {
1729 dependsOn jalviewjsSitePath
1730 dependsOn "jalviewjsNoTranspileBuildAllCores"
1731 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteCoreDir}")
1732 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1736 def outputFiles = []
1737 rename { filename ->
1738 outputFiles += "${outputDir}/${filename}"
1744 outputs.files outputFiles
1745 inputs.files inputFiles
1749 task jalviewjsSyncCore (type: Sync) {
1750 dependsOn jalviewjsTranspile
1751 dependsOn jalviewjsNoTranspileSyncCore
1752 dependsOn "jalviewjsBuildAllCores"
1756 // this Copy version of TransferSiteJs will delete anything else in the target dir
1757 task jalviewjsCopyTransferSiteJs(type: Copy) {
1758 dependsOn jalviewjsTranspile
1759 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
1760 into "${jalviewDir}/${jalviewjsSiteDir}"
1764 // this Sync version of TransferSite is used by buildship to keep the website automatically up to date when a file changes
1765 task jalviewjsNoTranspileSyncTransferSiteJs(type: Sync) {
1766 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
1768 into "${jalviewDir}/${jalviewjsSiteDir}"
1774 jalviewjsSyncAllLibs.mustRunAfter jalviewjsCopyTransferSiteJs
1775 jalviewjsSyncResources.mustRunAfter jalviewjsCopyTransferSiteJs
1776 jalviewjsSyncSiteResources.mustRunAfter jalviewjsCopyTransferSiteJs
1777 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsCopyTransferSiteJs
1779 jalviewjsSyncAllLibs.mustRunAfter jalviewjsNoTranspileSyncTransferSiteJs
1780 jalviewjsSyncResources.mustRunAfter jalviewjsNoTranspileSyncTransferSiteJs
1781 jalviewjsSyncSiteResources.mustRunAfter jalviewjsNoTranspileSyncTransferSiteJs
1782 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsNoTranspileSyncTransferSiteJs
1785 task jalviewjsNoTranspilePrepareSite {
1786 dependsOn jalviewjsSyncAllLibs
1787 dependsOn jalviewjsSyncResources
1788 dependsOn jalviewjsSyncSiteResources
1789 dependsOn jalviewjsSyncBuildProperties
1790 dependsOn jalviewjsNoTranspileSyncCore
1794 task jalviewjsPrepareSite {
1796 description "Prepares the website folder including unzipping files and copying resources"
1797 dependsOn jalviewjsSyncAllLibs
1798 dependsOn jalviewjsSyncResources
1799 dependsOn jalviewjsSyncSiteResources
1800 dependsOn jalviewjsSyncBuildProperties
1801 dependsOn jalviewjsSyncCore
1805 task jalviewjsBuildSite {
1807 description "Builds the whole website including transpiled code"
1808 dependsOn jalviewjsCopyTransferSiteJs
1809 dependsOn jalviewjsPrepareSite
1813 task cleanJalviewjsSite {
1815 delete "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
1816 delete "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1817 delete "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1818 delete "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
1819 delete "${jalviewDir}/${jalviewjsSiteDir}"
1824 task jalviewjsSiteTar(type: Tar) {
1826 description "Creates a tar.gz file for the website"
1827 dependsOn jalviewjsBuildSite
1828 def outputFilename = "jalviewjs-site-${JALVIEW_VERSION}.tar.gz"
1830 archiveFileName = outputFilename
1831 } catch (Exception e) {
1832 archiveName = outputFilename
1835 compression Compression.GZIP
1837 from "${jalviewDir}/${jalviewjsSiteDir}"
1838 into jalviewjs_site_dir // this is inside the tar file
1840 inputs.dir("${jalviewDir}/${jalviewjsSiteDir}")
1844 task jalviewjsServer {
1846 def filename = "jalviewjsTest.html"
1847 description "Starts a webserver on localhost to test the website. See ${filename} to access local site on most recently used port."
1848 dependsOn jalviewjsSitePath
1849 def htmlFile = "${jalviewDirAbsolutePath}/${filename}"
1852 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
1853 def port = Integer.valueOf(jalviewjs_server_port)
1857 while(port < start+1000 && !running) {
1859 def doc_root = new File("${jalviewDirAbsolutePath}/${jalviewjsSiteDir}")
1860 def jalviewjsServer = factory.start(doc_root, port)
1862 url = jalviewjsServer.getResourceUrl(jalviewjs_server_resource)
1863 println("SERVER STARTED with document root ${doc_root}.")
1864 println("Go to "+url+" . Run gradle --stop to stop (kills all gradle daemons).")
1865 println("For debug: "+url+"?j2sdebug")
1867 file(htmlFile).text = """
1868 <p><a href="${url}">Jalview JS Test. <${url}></a></p>
1869 <p><a href="${url}?j2sdebug">Jalview JS Test with debug. <${url}?j2sdebug<</a></p>
1872 } catch (Exception e) {
1879 outputs.file(htmlFile)
1880 outputs.upToDateWhen({false})
1884 task cleanJalviewjsAll {
1886 description "Delete all configuration and build artifacts to do with JalviewJS build"
1887 dependsOn cleanJalviewjsSite
1888 dependsOn jalviewjsEclipsePaths
1891 delete "${jalviewDir}/${jalviewjsBuildDir}"
1892 delete "${jalviewDir}/${eclipse_bin_dir}"
1893 if (eclipseWorkspace != null && file(eclipseWorkspace.getAbsolutePath()+"/.metadata").exists()) {
1894 delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata")
1896 delete "${jalviewDir}/${jalviewjs_j2s_settings}"
1899 outputs.upToDateWhen( { false } )
1905 description "Build the site"
1906 dependsOn jalviewjsBuildSite
1911 task jalviewjsIDE_CopyTransferSiteJs(type: Copy) {
1912 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
1913 into "${jalviewDir}/${jalviewjsSiteDir}"
1917 task jalviewjsIDE_j2sFile {
1918 group "00 JalviewJS in Eclipse"
1919 description "Creates the .j2s file"
1920 dependsOn jalviewjsCreateJ2sSettings
1924 task jalviewjsIDE_AssembleSite {
1925 group "00 JalviewJS in Eclipse"
1926 description "Assembles the Eclipse transpiled site and unzips supporting zipfiles"
1927 dependsOn jalviewjsIDE_CopyTransferSiteJs
1928 dependsOn jalviewjsNoTranspilePrepareSite
1932 task jalviewjsIDE_SiteClean {
1933 group "00 JalviewJS in Eclipse"
1934 description "Deletes the Eclipse transpiled site"
1935 dependsOn cleanJalviewjsSite
1939 task jalviewjsIDE_Server {
1940 group "00 JalviewJS in Eclipse"
1941 description "Starts a webserver on localhost to test the website"
1942 dependsOn jalviewjsServer
1946 // buildship runs this at import
1947 task eclipseSynchronizationTask {
1948 dependsOn eclipseSetup
1949 dependsOn jalviewjsIDE_j2sFile
1953 // buildship runs this at build time
1954 task eclipseAutoBuildTask {
1955 dependsOn jalviewjsNoTranspileSyncTransferSiteJs
1956 dependsOn jalviewjsNoTranspilePrepareSite
1968 def jalviewjsCallCore(FileCollection list, String prefixFile, String suffixFile, String jsfile, String zjsfile, File logOutFile, Boolean logOutConsole) {
1970 def stdout = new ByteArrayOutputStream()
1971 def stderr = new ByteArrayOutputStream()
1973 def coreFile = file(jsfile)
1975 msg = "Generating ${jsfile}"
1977 logOutFile.createNewFile()
1978 logOutFile.append(msg+"\n")
1980 def coreTop = file(prefixFile)
1981 def coreBottom = file(suffixFile)
1982 coreFile.getParentFile().mkdirs()
1983 coreFile.createNewFile()
1984 coreFile.write( coreTop.text )
1989 t.replaceAll("Clazz\\.","Clazz_")
1990 t.replaceAll("Class__","Clazz._")
1991 coreFile.append( t )
1993 msg = "...file '"+f.getPath()+"' does not exist, skipping"
1995 logOutFile.append(msg+"\n")
1998 coreFile.append( coreBottom.text )
2000 msg = "Generating ${zjsfile}"
2002 logOutFile.append(msg+"\n")
2003 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
2004 def logErrFOS = logOutFOS
2007 classpath = files(["${jalviewDir}/tools/closure_compiler.jar"])
2008 args = [ "--js", jsfile, "--js_output_file", zjsfile ]
2010 msg = "\nRunning '"+commandLine.join(' ')+"'\n"
2012 logOutFile.append(msg+"\n")
2014 if (logOutConsole) {
2015 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
2016 new org.apache.tools.ant.util.TeeOutputStream(
2020 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
2021 new org.apache.tools.ant.util.TeeOutputStream(
2026 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
2029 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
2036 logOutFile.append(msg+"\n")
2040 task jalviewjsNoTranspileBuildAllCores {
2041 dependsOn jalviewjsSitePath
2042 dependsOn jalviewjsTransferUnzipSwingJs
2044 def j2sDir = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${jalviewjs_j2s_subdir}"
2045 def jsDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${jalviewjs_js_subdir}"
2046 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}/${jalviewjs_j2s_subdir}/core"
2047 def prefixFile = "${jsDir}/core/coretop2.js"
2048 def suffixFile = "${jsDir}/core/corebottom2.js"
2050 inputs.file prefixFile
2051 inputs.file suffixFile
2053 def classlistFiles = []
2054 // add the classlists found int the jalviewjs_classlists_dir
2055 fileTree(dir: "${jalviewDir}/${jalviewjs_classlists_dir}", include: "*.txt").each {
2057 def name = file.getName() - ".txt"
2064 // _jmol and _jalview cores. Add any other peculiar classlist.txt files here
2065 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jmol}"), 'name': "_jvjmol" ]
2066 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jalview}"), 'name': "_jalview" ]
2070 classlistFiles.each {
2073 def file = hash['file']
2074 if (! file.exists()) {
2075 println("...classlist file '"+file.getPath()+"' does not exist, skipping")
2076 return false // this is a "continue" in groovy .each closure
2078 def name = hash['name']
2080 name = file.getName() - ".txt"
2088 def list = fileTree(dir: j2sDir, includes: filelist)
2090 def jsfile = "${outputDir}/core${name}.js"
2091 def zjsfile = "${outputDir}/core${name}.z.js"
2101 outputs.file(jsfile)
2102 outputs.file(zjsfile)
2105 // _stevesoft core. add any cores without a classlist here (and the inputs and outputs)
2106 def stevesoftClasslist = [
2107 'jsfile': "${outputDir}/core_stevesoft.js",
2108 'zjsfile': "${outputDir}/core_stevesoft.z.js",
2109 'list': fileTree(dir: j2sDir, include: "com/stevesoft/pat/**/*.js")
2111 classlists += stevesoftClasslist
2112 inputs.files(stevesoftClasslist['list'])
2113 outputs.file(stevesoftClasslist['jsfile'])
2114 outputs.file(stevesoftClasslist['zjsfile'])
2117 def logOutFile = file("${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_closure_stdout}")
2118 logOutFile.getParentFile().mkdirs()
2119 logOutFile.createNewFile()
2120 logOutFile.write(getDate("yyyy-MM-dd HH:mm:ss")+" jalviewjsNoTranspileBuildAllCores\n----\n")
2123 jalviewjsCallCore(it.list, prefixFile, suffixFile, it.jsfile, it.zjsfile, logOutFile, jalviewjs_j2s_to_console.equals("true"))
2130 jalviewjsNoTranspileBuildAllCores.mustRunAfter jalviewjsTranspile
2133 task jalviewjsBuildAllCores {
2135 description "Build the core js lib closures listed in the classlists dir"
2136 dependsOn jalviewjsTranspile
2137 dependsOn jalviewjsNoTranspileBuildAllCores
2141 task jalviewjsIDE_BuildAllCores {
2142 group "00 JalviewJS in Eclipse"
2143 description "Build the core js lib closures listed in the classlists dir"
2144 dependsOn jalviewjsNoTranspileBuildAllCores
2148 task jalviewjsPublishCoreTemplate {
2149 dependsOn jalviewjsBuildAllCores