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 mainClassName = string(launcherClass)
93 cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
94 classes = string("${jalviewDir}/${classesDir}")
95 if (clover.equals("true")) {
97 classes = string("${buildDir}/${cloverClassesDir}")
100 classes = string("${jalviewDir}/${classesDir}")
103 getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
104 getdownDir = string("")
105 reportRsyncCmd = false
107 buildProperties = build_properties_file
108 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
112 // TODO: get bamboo build artifact URL for getdown artifacts
113 getdown_channel_base = bamboo_channelbase
114 getdown_channel_name = string("${bamboo_planKey}/${JAVA_VERSION}")
115 getdown_app_base = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
116 getdown_app_dir = getdown_app_dir_alt
117 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
121 getdown_channel_name = CHANNEL.toLowerCase()
122 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
123 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
124 getdown_app_dir = getdown_app_dir_release
125 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
126 reportRsyncCommand = true
130 getdown_channel_name = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
131 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
132 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
133 getdown_app_dir = getdown_app_dir_alt
134 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
135 print "Must provide an ARCHIVEDIR value to produce an archive distribution"
138 packageDir = string("${ARCHIVEDIR}/${packageDir}")
139 buildProperties = string("${ARCHIVEDIR}/${classesDir}/${build_properties_file}")
142 reportRsyncCommand = true
146 getdown_channel_name = string("archive/${JALVIEW_VERSION}")
147 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
148 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
149 getdown_app_dir = getdown_app_dir_alt
150 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
151 print "Must provide an ARCHIVEDIR value to produce an archive distribution"
154 packageDir = string("${ARCHIVEDIR}/${packageDir}")
155 buildProperties = string("${ARCHIVEDIR}/${classesDir}/${build_properties_file}")
158 reportRsyncCommand = true
159 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
163 getdown_channel_name = CHANNEL.toLowerCase()
164 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
165 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
166 getdown_app_dir = getdown_app_dir_alt
167 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
168 reportRsyncCommand = true
172 getdown_channel_name = CHANNEL.toLowerCase()
173 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
174 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
175 getdown_app_dir = getdown_app_dir_alt
176 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
177 reportRsyncCommand = true
180 case ~/^SCRATCH(|-[-\w]*)$/:
181 getdown_channel_name = CHANNEL
182 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
183 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
184 getdown_app_dir = getdown_app_dir_alt
185 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
186 reportRsyncCommand = true
190 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
191 getdown_app_dir = getdown_app_dir_alt
192 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
193 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
196 default: // something wrong specified
197 print("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
203 getdownAppDir = string("${getdownWebsiteDir}/${getdown_app_dir}")
204 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
205 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
206 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
207 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
208 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
209 /* compile without modules -- using classpath libraries
210 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
211 modules_runtimeClasspath = modules_compileClasspath
214 gitBranch = string("")
216 println("Using a ${CHANNEL} profile.")
218 additional_compiler_args = []
219 // configure classpath/args for j8/j11 compilation
220 if (JAVA_VERSION.equals("1.8")) {
221 JAVA_INTEGER_VERSION = string("8")
224 libDistDir = j8libDir
225 compile_source_compatibility = 1.8
226 compile_target_compatibility = 1.8
227 // these are getdown.txt properties defined dependent on the JAVA_VERSION
228 getdown_alt_java_min_version = getdown_alt_java8_min_version
229 getdown_alt_java_max_version = getdown_alt_java8_max_version
230 // this property is assigned below and expanded to multiple lines in the getdown task
231 getdown_alt_multi_java_location = getdown_alt_java8_txt_multi_java_location
232 // this property is for the Java library used in eclipse
233 eclipse_java_runtime_name = string("JavaSE-1.8")
234 } else if (JAVA_VERSION.equals("11")) {
235 JAVA_INTEGER_VERSION = string("11")
237 libDistDir = j11libDir
238 compile_source_compatibility = 11
239 compile_target_compatibility = 11
240 getdown_alt_java_min_version = getdown_alt_java11_min_version
241 getdown_alt_java_max_version = getdown_alt_java11_max_version
242 getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
243 eclipse_java_runtime_name = string("JavaSE-11")
244 /* compile without modules -- using classpath libraries
245 additional_compiler_args += [
246 '--module-path', modules_compileClasspath.asPath,
247 '--add-modules', j11modules
250 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
251 JAVA_INTEGER_VERSION = JAVA_VERSION
253 libDistDir = j11libDir
254 compile_source_compatibility = JAVA_VERSION
255 compile_target_compatibility = JAVA_VERSION
256 getdown_alt_java_min_version = getdown_alt_java11_min_version
257 getdown_alt_java_max_version = getdown_alt_java11_max_version
258 getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
259 eclipse_java_runtime_name = string("JavaSE-11")
260 /* compile without modules -- using classpath libraries
261 additional_compiler_args += [
262 '--module-path', modules_compileClasspath.asPath,
263 '--add-modules', j11modules
267 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
272 macosJavaVMDir = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/macos-jre${JAVA_VERSION}/jre")
273 macosJavaVMTgz = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/macos-jre${JAVA_VERSION}.tar.gz")
274 windowsJavaVMDir = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/windows-jre${JAVA_VERSION}/jre")
275 windowsJavaVMTgz = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/windows-jre${JAVA_VERSION}.tar.gz")
276 install4jDir = string("${jalviewDir}/${install4jResourceDir}")
277 install4jConfFileName = string("jalview-installers-java${JAVA_VERSION}.install4j")
278 install4jConfFile = string("${install4jDir}/${install4jConfFileName}")
281 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
282 helpFile = string("${classes}/${helpDir}/help.jhm")
285 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
286 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
287 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
289 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
291 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
293 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
294 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
295 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
296 jalviewjsJalviewCoreHtmlFile = string("")
297 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
298 jalviewjsJalviewTemplateName = string(jalviewjs_name)
300 eclipseWorkspace = null
301 eclipseBinary = string("")
302 eclipseVersion = string("")
311 srcDirs "${jalviewDir}/${sourceDir}"
312 outputDir = file(project.classes)
316 srcDirs "${jalviewDir}/${resourceDir}"
319 jar.destinationDir = file("${jalviewDir}/${packageDir}")
321 compileClasspath = files(sourceSets.main.java.outputDir)
322 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
324 runtimeClasspath = compileClasspath
329 srcDirs = [ cloverInstrDir ]
330 outputDir = file("${buildDir}/${cloverClassesDir}")
334 srcDirs = sourceSets.main.resources.srcDirs
336 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
337 compileClasspath += files(sourceSets.main.java.outputDir)
338 compileClasspath += sourceSets.main.compileClasspath
339 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
340 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
342 runtimeClasspath = compileClasspath
347 srcDirs "${jalviewDir}/${testSourceDir}"
348 outputDir = file("${jalviewDir}/${testOutputDir}")
352 srcDirs = sourceSets.main.resources.srcDirs
355 compileClasspath = files( sourceSets.test.java.outputDir )
358 compileClasspath += sourceSets.clover.compileClasspath
360 compileClasspath += files(sourceSets.main.java.outputDir)
363 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
364 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
365 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
367 runtimeClasspath = compileClasspath
375 cloverCompile 'org.openclover:clover:4.3.1'
376 testCompile 'org.openclover:clover:4.3.1'
383 cloverRuntime.extendsFrom cloverCompile
388 name = eclipse_project_name
390 natures 'org.eclipse.jdt.core.javanature',
391 'org.eclipse.jdt.groovy.core.groovyNature',
392 'org.eclipse.buildship.core.gradleprojectnature'
394 buildCommand 'org.eclipse.jdt.core.javabuilder'
395 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
399 //defaultOutputDir = sourceSets.main.java.outputDir
402 if (it.isCanBeResolved()) {
407 minusConfigurations += removeThese
408 plusConfigurations = [ ]
412 def removeTheseToo = []
413 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
414 cp.entries.each { entry ->
415 if (entry.kind == 'src') {
416 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == sourceDir || entry.path == testSourceDir)) {
417 removeTheseToo += entry
419 alreadyAddedSrcPath.putAt(entry.path, true)
423 cp.entries.removeAll(removeTheseToo)
425 if (file("${jalviewDir}/${eclipse_bin_dir}/main").isDirectory()) {
426 cp.entries += new Output("${eclipse_bin_dir}/main")
428 if (file(helpParentDir).isDirectory()) {
429 cp.entries += new Library(fileReference(helpParentDir))
431 if (file(resourceDir).isDirectory()) {
432 cp.entries += new Library(fileReference(resourceDir))
435 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
437 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.each {
438 //don't want to add outputDir as eclipse is using its own output dir in bin/main
439 if (it.isDirectory() || ! it.exists()) {
440 // don't add dirs to classpath
443 def itPath = it.toString()
444 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
445 // make relative path
446 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
448 if (alreadyAddedLibPath.get(itPath)) {
449 //println("Not adding duplicate entry "+itPath)
451 //println("Adding entry "+itPath)
452 cp.entries += new Library(fileReference(itPath))
453 alreadyAddedLibPath.put(itPath, true)
457 //fileTree(dir: "$jalviewDir/$utilsDir", include: ["test*/*.jar"]).each {
458 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
459 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
460 if (it.isDirectory() || ! it.exists()) {
461 // don't add dirs to classpath
462 return false // groovy "continue" in .any closure
465 def itPath = it.toString()
466 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
467 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
469 if (alreadyAddedLibPath.get(itPath)) {
472 def lib = new Library(fileReference(itPath))
473 lib.entryAttributes["test"] = "true"
475 alreadyAddedLibPath.put(itPath, true)
483 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
488 // for the IDE, use java 11 compatibility
489 sourceCompatibility = compile_source_compatibility
490 targetCompatibility = compile_target_compatibility
491 javaRuntimeName = eclipse_java_runtime_name
493 // add in jalview project specific properties/preferences into eclipse core preferences
495 withProperties { props ->
496 def jalview_prefs = new Properties()
497 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
498 jalview_prefs.load(ins)
500 jalview_prefs.forEach { t, v ->
501 if (props.getAt(t) == null) {
511 // Don't want these to be activated if in headless build
512 synchronizationTasks "eclipseSynchronizationTask"
513 autoBuildTasks "eclipseAutoBuildTask"
519 // only instrument source, we build test classes as normal
520 inputs.files files (sourceSets.main.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
521 outputs.dir cloverInstrDir
524 delete cloverInstrDir
525 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
526 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
527 argsList.addAll(inputs.files.files.collect({ file ->
530 String[] args = argsList.toArray()
531 println("About to instrument "+args.length +" files")
532 com.atlassian.clover.CloverInstr.mainImpl(args)
538 group = "Verification"
539 description = "Createst the Clover report"
540 inputs.dir "${buildDir}/clover"
541 outputs.dir "${reportsDir}/clover"
543 file("${buildDir}/clover/clover.db").exists()
546 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
547 "-o", "${reportsDir}/clover"]
548 String[] args = argsList.toArray()
549 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
551 // and generate ${reportsDir}/clover/clover.xml
552 args = ["--initstring", "${buildDir}/clover/clover.db",
553 "-o", "${reportsDir}/clover/clover.xml"].toArray()
554 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
563 sourceCompatibility = compile_source_compatibility
564 targetCompatibility = compile_target_compatibility
565 options.compilerArgs = additional_compiler_args
566 print ("Setting target compatibility to "+targetCompatibility+"\n")
574 dependsOn compileCloverJava
575 classpath += configurations.cloverRuntime
577 classpath += sourceSets.main.runtimeClasspath
580 sourceCompatibility = compile_source_compatibility
581 targetCompatibility = compile_target_compatibility
582 options.compilerArgs = additional_compiler_args
583 print ("Setting target compatibility to "+targetCompatibility+"\n")
591 sourceCompatibility = compile_source_compatibility
592 targetCompatibility = compile_target_compatibility
593 options.compilerArgs += additional_compiler_args
594 print ("Setting target compatibility to "+targetCompatibility+"\n")
596 classpath += configurations.cloverRuntime
602 delete sourceSets.main.java.outputDir
609 delete sourceSets.test.java.outputDir
610 delete cloverInstrDir
615 // format is a string like date.format("dd MMMM yyyy")
616 def getDate(format) {
617 def date = new Date()
618 return date.format(format)
623 def hashStdOut = new ByteArrayOutputStream()
625 commandLine "git", "rev-parse", "--short", "HEAD"
626 standardOutput = hashStdOut
630 def branchStdOut = new ByteArrayOutputStream()
632 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
633 standardOutput = branchStdOut
637 gitHash = hashStdOut.toString().trim()
638 gitBranch = branchStdOut.toString().trim()
640 outputs.upToDateWhen { false }
644 task createBuildProperties(type: WriteProperties) {
646 inputs.dir("${jalviewDir}/${sourceDir}")
647 inputs.dir("${jalviewDir}/${resourceDir}")
648 file(buildProperties).getParentFile().mkdirs()
649 outputFile (buildProperties)
650 // taking time specific comment out to allow better incremental builds
651 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
652 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
653 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
654 property "VERSION", JALVIEW_VERSION
655 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
656 outputs.file(outputFile)
660 task cleanBuildingHTML(type: Delete) {
667 task convertBuildingMD(type: Exec) {
668 dependsOn cleanBuildingHTML
669 def buildingMD = "${jalviewDir}/${docDir}/building.md"
670 def css = "${jalviewDir}/${docDir}/github.css"
673 pandoc_exec.split(",").each {
674 if (file(it.trim()).exists()) {
680 def hostname = "hostname".execute().text.trim()
681 if ((pandoc == null || ! file(pandoc).exists()) && hostname.equals("jv-bamboo")) {
682 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
686 if (pandoc != null && file(pandoc).exists()) {
687 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
689 println("Cannot find pandoc. Skipping convert building.md to HTML")
690 throw new StopExecutionException()
696 inputs.file(buildingMD)
698 outputs.file(buildingHTML)
709 task syncDocs(type: Sync) {
710 dependsOn convertBuildingMD
711 def syncDir = "${classes}/${docDir}"
712 from fileTree("${jalviewDir}/${docDir}")
718 task copyHelp(type: Copy) {
719 def inputDir = "${jalviewDir}/${helpParentDir}/${helpDir}"
720 def outputDir = "${classes}/${helpDir}"
725 filter(ReplaceTokens,
729 'Version-Rel': JALVIEW_VERSION,
730 'Year-Rel': getDate("yyyy")
742 outputs.files(helpFile)
743 outputs.dir(outputDir)
747 task syncLib(type: Sync) {
748 def syncDir = "${classes}/${libDistDir}"
749 from fileTree("${jalviewDir}/${libDistDir}")
754 task syncResources(type: Sync) {
755 from "${jalviewDir}/${resourceDir}"
765 dependsOn syncResources
771 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
774 dependsOn compileJava
776 dependsOn cloverInstr
780 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
784 includeGroups testngGroups
786 useDefaultListeners=true
789 workingDir = jalviewDir
790 //systemProperties 'clover.jar' System.properties.clover.jar
791 sourceCompatibility = compile_source_compatibility
792 targetCompatibility = compile_target_compatibility
793 jvmArgs += additional_compiler_args
798 task buildIndices(type: JavaExec) {
800 classpath = sourceSets.main.compileClasspath
801 main = "com.sun.java.help.search.Indexer"
802 workingDir = "${classes}/${helpDir}"
805 inputs.dir("${workingDir}/${argDir}")
807 outputs.dir("${classes}/doc")
808 outputs.dir("${classes}/help")
809 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
810 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
811 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
812 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
813 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
814 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
818 task compileLinkCheck(type: JavaCompile) {
820 classpath = files("${jalviewDir}/${utilsDir}")
821 destinationDir = file("${jalviewDir}/${utilsDir}")
822 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
824 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
825 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
826 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
827 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
831 task linkCheck(type: JavaExec) {
832 dependsOn prepare, compileLinkCheck
834 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
835 classpath = files("${jalviewDir}/${utilsDir}")
836 main = "HelpLinksChecker"
837 workingDir = jalviewDir
838 def help = "${classes}/${helpDir}"
839 args = [ "${classes}/${helpDir}", "-nointernet" ]
841 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
843 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
846 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
850 inputs.dir("${classes}/${helpDir}")
851 outputs.file(helpLinksCheckerOutFile)
854 // import the pubhtmlhelp target
855 ant.properties.basedir = "${jalviewDir}"
856 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes}/${helpDir}"
857 ant.importBuild "${utilsDir}/publishHelp.xml"
860 task cleanPackageDir(type: Delete) {
862 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
868 dependsOn buildIndices
869 dependsOn createBuildProperties
872 attributes "Main-Class": mainClass,
873 "Permissions": "all-permissions",
874 "Application-Name": "Jalview Desktop",
875 "Codebase": application_codebase
878 destinationDir = file("${jalviewDir}/${packageDir}")
879 archiveName = rootProject.name+".jar"
887 inputs.dir("${classes}")
888 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
892 task copyJars(type: Copy) {
893 from fileTree(dir: "${classes}", include: "**/*.jar").files
894 into "${jalviewDir}/${packageDir}"
898 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
899 task syncJars(type: Sync) {
900 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
901 into "${jalviewDir}/${packageDir}"
903 include jar.archiveName
910 description = "Put all required libraries in dist"
911 // order of "cleanPackageDir", "copyJars", "jar" important!
912 jar.mustRunAfter cleanPackageDir
913 syncJars.mustRunAfter cleanPackageDir
914 dependsOn cleanPackageDir
917 outputs.dir("${jalviewDir}/${packageDir}")
922 dependsOn cleanPackageDir
928 group = "distribution"
932 from ("${jalviewDir}/${libDistDir}") {
936 attributes 'Implementation-Version': JALVIEW_VERSION
938 mainClassName = shadowJarMainClass
940 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
945 task getdownWebsite() {
946 group = "distribution"
947 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
952 def getdownWebsiteResourceFilenames = []
953 def getdownTextString = ""
954 def getdownResourceDir = getdownResourceDir
955 def getdownAppDir = getdownAppDir
956 def getdownResourceFilenames = []
959 // clean the getdown website and files dir before creating getdown folders
960 delete getdownWebsiteDir
961 delete getdownFilesDir
965 rename(build_properties_file, getdown_build_properties)
968 getdownWebsiteResourceFilenames += "${getdown_app_dir}/${getdown_build_properties}"
970 // go through properties looking for getdown_txt_...
971 def props = project.properties.sort { it.key }
972 if (getdown_alt_java_min_version.length() > 0) {
973 props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
975 if (getdown_alt_java_max_version.length() > 0) {
976 props.put("getdown_txt_java_max_version", getdown_alt_java_max_version)
978 props.put("getdown_txt_multi_java_location", getdown_alt_multi_java_location)
980 props.put("getdown_txt_appbase", getdown_app_base)
981 props.each{ prop, val ->
982 if (prop.startsWith("getdown_txt_") && val != null) {
983 if (prop.startsWith("getdown_txt_multi_")) {
984 def key = prop.substring(18)
985 val.split(",").each{ v ->
986 def line = "${key} = ${v}\n"
987 getdownTextString += line
990 // file values rationalised
991 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
993 if (val.indexOf('/') == 0) {
996 } else if (val.indexOf('/') > 0) {
997 // relative path (relative to jalviewDir)
998 r = file( "${jalviewDir}/${val}" )
1001 val = "${getdown_resource_dir}/" + r.getName()
1002 getdownWebsiteResourceFilenames += val
1003 getdownResourceFilenames += r.getPath()
1006 if (! prop.startsWith("getdown_txt_resource")) {
1007 def line = prop.substring(12) + " = ${val}\n"
1008 getdownTextString += line
1014 getdownWebsiteResourceFilenames.each{ filename ->
1015 getdownTextString += "resource = ${filename}\n"
1017 getdownResourceFilenames.each{ filename ->
1020 into getdownResourceDir
1025 fileTree(file(packageDir)).each{ f ->
1026 if (f.isDirectory()) {
1027 def files = fileTree(dir: f, include: ["*"]).getFiles()
1029 } else if (f.exists()) {
1033 codeFiles.sort().each{f ->
1034 def name = f.getName()
1035 def line = "code = ${getdown_app_dir}/${name}\n"
1036 getdownTextString += line
1043 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1045 if (JAVA_VERSION.equals("11")) {
1046 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1047 j11libFiles.sort().each{f ->
1048 def name = f.getName()
1049 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1050 getdownTextString += line
1053 into getdownJ11libDir
1059 // getdown-launcher.jar should not be in main application class path so the main application can move it when updated. Listed as a resource so it gets updated.
1060 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1061 getdownTextString += "resource = ${getdown_launcher_new}\n"
1062 getdownTextString += "class = ${mainClass}\n"
1064 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1065 getdown_txt.write(getdownTextString)
1067 def launch_jvl = file("${getdownWebsiteDir}/${getdown_launch_jvl}")
1068 launch_jvl.write("appbase="+props.get("getdown_txt_appbase"))
1071 from getdownLauncher
1072 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1073 into getdownWebsiteDir
1077 from getdownLauncher
1078 if (file(getdownLauncher).getName() != getdown_launcher) {
1079 rename(file(getdownLauncher).getName(), getdown_launcher)
1081 into getdownWebsiteDir
1084 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1087 from getdownLauncher
1088 from "${getdownWebsiteDir}/${getdown_build_properties}"
1089 if (file(getdownLauncher).getName() != getdown_launcher) {
1090 rename(file(getdownLauncher).getName(), getdown_launcher)
1092 into getdownInstallDir
1096 from getdownInstallDir
1097 into getdownFilesInstallDir
1104 from getdownLauncher
1105 from "${getdownWebsiteDir}/${getdown_build_properties}"
1106 if (file(getdownLauncher).getName() != getdown_launcher) {
1107 rename(file(getdownLauncher).getName(), getdown_launcher)
1109 into getdownFilesDir
1113 from getdownResourceDir
1114 into "${getdownFilesDir}/${getdown_resource_dir}"
1119 inputs.dir("${jalviewDir}/${packageDir}")
1121 outputs.dir(getdownWebsiteDir)
1122 outputs.dir(getdownFilesDir)
1126 task getdownDigest(type: JavaExec) {
1127 group = "distribution"
1128 description = "Digest the getdown website folder"
1129 dependsOn getdownWebsite
1131 classpath = files("${getdownWebsiteDir}/${getdown_launcher}")
1133 main = "com.threerings.getdown.tools.Digester"
1134 args getdownWebsiteDir
1135 inputs.dir(getdownWebsiteDir)
1136 outputs.file("${getdownWebsiteDir}/digest2.txt")
1141 group = "distribution"
1142 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1143 dependsOn getdownDigest
1145 if (reportRsyncCommand) {
1146 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1147 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1148 println "LIKELY RSYNC COMMAND:"
1149 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1150 if (RUNRSYNC == "true") {
1152 commandLine "mkdir", "-p", toDir
1155 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1165 delete getdownWebsiteDir
1166 delete getdownFilesDir
1172 def install4jHomeDir = "/opt/install4j"
1173 def hostname = "hostname".execute().text.trim()
1174 if (hostname.equals("jv-bamboo")) {
1175 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1176 } else if (OperatingSystem.current().isMacOsX()) {
1177 install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app'
1178 if (! file(install4jHomeDir).exists()) {
1179 install4jHomeDir = System.getProperty("user.home")+install4jHomeDir
1181 } else if (OperatingSystem.current().isLinux()) {
1182 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1184 installDir = file(install4jHomeDir)
1185 mediaTypes = Arrays.asList(install4jMediaTypes.split(","))
1186 if (install4jFaster.equals("true")) {
1192 task copyInstall4jTemplate(type: Copy) {
1193 from (install4jDir) {
1194 include install4jTemplate
1195 rename (install4jTemplate, install4jConfFileName)
1196 filter(ReplaceTokens,
1200 '9999999999': JAVA_VERSION
1203 filter(ReplaceTokens,
1207 'JAVA_VERSION': JAVA_VERSION,
1208 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1209 'VERSION': JALVIEW_VERSION,
1210 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1211 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1212 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1213 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1214 'INSTALL4JINFOPLISTFILEASSOCIATIONS': install4jInfoPlistFileAssociations,
1215 'COPYRIGHT_MESSAGE': install4jCopyrightMessage,
1216 'MACOS_BUNDLE_ID': install4jMacOSBundleId,
1217 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1218 'GETDOWN_DIST_DIR': getdown_app_dir,
1219 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1220 'GETDOWN_INSTALL_DIR': getdown_install_dir
1223 if (OSX_KEYPASS == "") {
1224 filter(ReplaceTokens,
1225 beginToken: 'codeSigning macEnabled="',
1228 'true': 'codeSigning macEnabled="false"'
1231 filter(ReplaceTokens,
1232 beginToken: 'runPostProcessor="true" ',
1233 endToken: 'Processor',
1235 'post': 'runPostProcessor="false" postProcessor'
1241 outputs.files(install4jConfFile)
1244 // include file associations in installer
1245 def installerFileAssociationsXml = file("${install4jDir}/${install4jInstallerFileAssociations}").text
1249 match: '<action name="EXTENSIONS_REPLACED_BY_GRADLE".*?</action>',
1250 replace: installerFileAssociationsXml,
1251 file: install4jConfFile
1254 // include uninstaller applescript app files in dmg
1255 def installerDMGUninstallerXml = file("$install4jDir/$install4jDMGUninstallerAppFiles").text
1259 match: '<file name="UNINSTALL_OLD_JALVIEW_APP_REPLACED_IN_GRADLE" file=.*?>',
1260 replace: installerDMGUninstallerXml,
1261 file: install4jConfFile
1270 delete install4jConfFile
1275 task installers(type: com.install4j.gradle.Install4jTask) {
1276 group = "distribution"
1277 description = "Create the install4j installers"
1279 dependsOn copyInstall4jTemplate
1280 projectFile = file(install4jConfFile)
1281 variables = [majorVersion: version.substring(2, 11), build: 001, OSX_KEYSTORE: OSX_KEYSTORE, JSIGN_SH: JSIGN_SH]
1282 destination = "${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}"
1283 buildSelected = true
1286 macKeystorePassword=OSX_KEYPASS
1290 println("Using projectFile "+projectFile)
1293 inputs.dir(getdownWebsiteDir)
1294 inputs.file(install4jConfFile)
1295 inputs.dir(macosJavaVMDir)
1296 inputs.dir(windowsJavaVMDir)
1297 outputs.dir("${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}")
1303 delete install4jConfFile
1308 task sourceDist (type: Tar) {
1310 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1311 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1312 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1314 archiveFileName = outputFileName
1315 } catch (Exception e) {
1316 archiveName = outputFileName
1319 compression Compression.GZIP
1323 def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1328 ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1330 ,"utils/InstallAnywhere"]
1331 def PROCESS_FILES=[ "AUTHORS",
1339 "THIRDPARTYLIBS","TESTNG",
1341 "gradle.properties",
1352 exclude (EXCLUDE_FILES)
1353 include (PROCESS_FILES)
1354 filter(ReplaceTokens,
1358 'Version-Rel': JALVIEW_VERSION,
1359 'Year-Rel': getDate("yyyy")
1364 exclude (EXCLUDE_FILES)
1365 exclude (PROCESS_FILES)
1366 exclude ("appletlib")
1367 exclude ("**/*locales")
1368 exclude ("*locales/**")
1369 exclude ("utils/InstallAnywhere")
1371 exclude (getdown_files_dir)
1372 exclude (getdown_website_dir)
1374 // exluding these as not using jars as modules yet
1375 exclude ("${j11modDir}/**/*.jar")
1377 // from (jalviewDir) {
1378 // // explicit includes for stuff that seemed to not get included
1379 // include(fileTree("test/**/*."))
1380 // exclude(EXCLUDE_FILES)
1381 // exclude(PROCESS_FILES)
1388 dependsOn pubhtmlhelp
1390 inputs.dir("${classes}/${helpDir}")
1391 outputs.dir("${helpOutputDir}")
1395 task j2sSetHeadlessBuild {
1402 task jalviewjsSetEclipseWorkspace {
1403 def propKey = "jalviewjs_eclipse_workspace"
1405 if (project.hasProperty(propKey)) {
1406 propVal = project.getProperty(propKey)
1407 if (propVal.startsWith("~/")) {
1408 propVal = System.getProperty("user.home") + propVal.substring(1)
1411 def propsFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_workspace_location_file}"
1412 def propsFile = file(propsFileName)
1413 def eclipseWsDir = propVal
1414 def props = new Properties()
1416 if (( eclipseWsDir == null || !file(eclipseWsDir).exists() ) && propsFile.exists()) {
1417 def ins = new FileInputStream(propsFileName)
1420 if (props.getProperty(propKey, null) != null) {
1421 eclipseWsDir = props.getProperty(propKey)
1425 def writeProps = false
1426 if (eclipseWsDir == null || !file(eclipseWsDir).exists()) {
1427 def tempDir = File.createTempDir()
1428 eclipseWsDir = tempDir.getAbsolutePath()
1431 eclipseWorkspace = file(eclipseWsDir)
1434 // do not run a headless transpile when we claim to be in Eclipse
1436 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1437 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1439 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1443 props.setProperty(propKey, eclipseWsDir)
1444 propsFile.parentFile.mkdirs()
1445 def bytes = new ByteArrayOutputStream()
1446 props.store(bytes, null)
1447 def propertiesString = bytes.toString()
1448 propsFile.text = propertiesString
1451 println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath())
1454 //inputs.property(propKey, eclipseWsDir) // eclipseWsDir only gets set once this task runs, so will be out-of-date
1455 outputs.file(propsFileName)
1456 outputs.upToDateWhen { eclipseWorkspace.exists() }
1460 task jalviewjsEclipsePaths {
1463 def eclipseRoot = jalviewjs_eclipse_root
1464 if (eclipseRoot.startsWith("~/")) {
1465 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
1467 if (OperatingSystem.current().isMacOsX()) {
1468 eclipseRoot += "/Eclipse.app"
1469 eclipseBinary = "${eclipseRoot}/Contents/MacOS/eclipse"
1470 eclipseProduct = "${eclipseRoot}/Contents/Eclipse/.eclipseproduct"
1471 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
1472 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1473 eclipseRoot += "/eclipse.exe"
1475 eclipseBinary = "${eclipseRoot}/eclipse"
1476 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1477 } else { // linux or unix
1478 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1479 eclipseRoot += "/eclipse"
1481 eclipseBinary = "${eclipseRoot}/eclipse"
1482 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1485 eclipseVersion = "4.13" // default
1486 def assumedVersion = true
1487 if (file(eclipseProduct).exists()) {
1488 def fis = new FileInputStream(eclipseProduct)
1489 def props = new Properties()
1491 eclipseVersion = props.getProperty("version")
1493 assumedVersion = false
1496 def propKey = "eclipse_debug"
1497 eclipseDebug = (project.hasProperty(propKey) && project.getProperty(propKey).equals("true"))
1500 // do not run a headless transpile when we claim to be in Eclipse
1502 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1503 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1505 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1508 if (!assumedVersion) {
1509 println("ECLIPSE VERSION=${eclipseVersion}")
1516 dependsOn eclipseProject
1517 dependsOn eclipseClasspath
1518 dependsOn eclipseJdt
1522 // this version (type: Copy) will delete anything in the eclipse dropins folder that isn't in fromDropinsDir
1523 task jalviewjsEclipseCopyDropins(type: Copy) {
1524 dependsOn jalviewjsEclipsePaths
1526 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_eclipse_dropins_dir}", include: "*.jar")
1527 inputFiles += file("${jalviewDir}/${jalviewjs_j2s_plugin}")
1528 def outputDir = "${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}"
1535 // this eclipse -clean doesn't actually work
1536 task jalviewjsCleanEclipse(type: Exec) {
1537 dependsOn eclipseSetup
1538 dependsOn jalviewjsEclipsePaths
1539 dependsOn jalviewjsEclipseCopyDropins
1541 executable(eclipseBinary)
1542 args(["-nosplash", "--launcher.suppressErrors", "-data", eclipseWorkspace.getPath(), "-clean", "-console", "-consoleLog"])
1548 def inputString = """exit
1551 def inputByteStream = new ByteArrayInputStream(inputString.getBytes())
1552 standardInput = inputByteStream
1555 /* not really working yet
1556 jalviewjsEclipseCopyDropins.finalizedBy jalviewjsCleanEclipse
1560 task jalviewjsTransferUnzipSwingJs {
1561 def file_zip = "${jalviewDir}/${jalviewjs_swingjs_zip}"
1565 from zipTree(file_zip)
1566 into "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1570 inputs.file file_zip
1571 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1575 task jalviewjsTransferUnzipLib {
1576 def zipFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_libjs_dir}", include: "*.zip")
1579 zipFiles.each { file_zip ->
1581 from zipTree(file_zip)
1582 into "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1587 inputs.files zipFiles
1588 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1592 task jalviewjsTransferUnzipAllLibs {
1593 dependsOn jalviewjsTransferUnzipSwingJs
1594 dependsOn jalviewjsTransferUnzipLib
1598 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
1600 description "Create the .j2s file from the j2s.* properties"
1602 outputFile ("${jalviewDir}/${jalviewjs_j2s_settings}")
1603 def j2s_props = project.properties.findAll { it.key.startsWith("j2s.") }.sort { it.key }
1604 def siteDirProperty = "j2s.site.directory"
1605 def setSiteDir = false
1606 j2s_props.each { prop, val ->
1608 if (prop == siteDirProperty) {
1609 if (!(val.startsWith('/') || val.startsWith("file://") )) {
1610 val = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${val}"
1616 if (!setSiteDir) { // default site location, don't override specifically set property
1617 property(siteDirProperty,"${jalviewDir}/${jalviewjsTransferSiteJsDir}")
1620 inputs.properties(j2s_props)
1621 outputs.file(outputFile)
1625 task jalviewjsEclipseSetup {
1626 dependsOn jalviewjsEclipseCopyDropins
1627 dependsOn jalviewjsSetEclipseWorkspace
1628 dependsOn jalviewjsCreateJ2sSettings
1632 task jalviewjsSyncAllLibs (type: Sync) {
1633 dependsOn jalviewjsTransferUnzipAllLibs
1634 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteLibDir}")
1635 inputFiles += fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}")
1636 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1640 def outputFiles = []
1641 rename { filename ->
1642 outputFiles += "${outputDir}/${filename}"
1648 outputs.files outputFiles
1649 inputs.files inputFiles
1653 task jalviewjsSyncResources (type: Sync) {
1654 def inputFiles = fileTree(dir: "${jalviewDir}/${resourceDir}")
1655 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1659 def outputFiles = []
1660 rename { filename ->
1661 outputFiles += "${outputDir}/${filename}"
1667 outputs.files outputFiles
1668 inputs.files inputFiles
1672 task jalviewjsSyncSiteResources (type: Sync) {
1673 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_site_resource_dir}")
1674 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1678 def outputFiles = []
1679 rename { filename ->
1680 outputFiles += "${outputDir}/${filename}"
1686 outputs.files outputFiles
1687 inputs.files inputFiles
1691 task jalviewjsSyncBuildProperties (type: Sync) {
1692 dependsOn createBuildProperties
1693 def inputFiles = [file(buildProperties)]
1694 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1698 def outputFiles = []
1699 rename { filename ->
1700 outputFiles += "${outputDir}/${filename}"
1706 outputs.files outputFiles
1707 inputs.files inputFiles
1711 task jalviewjsProjectImport(type: Exec) {
1712 dependsOn eclipseSetup
1713 dependsOn jalviewjsEclipsePaths
1714 dependsOn jalviewjsEclipseSetup
1717 // do not run a headless import when we claim to be in Eclipse
1719 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1720 throw new StopExecutionException("Not running headless import whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1722 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1726 //def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
1727 def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview"
1728 executable(eclipseBinary)
1729 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
1733 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1735 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
1738 inputs.file("${jalviewDir}/.project")
1739 outputs.upToDateWhen {
1740 file(projdir).exists()
1745 task jalviewjsTranspile(type: Exec) {
1746 dependsOn jalviewjsEclipseSetup
1747 dependsOn jalviewjsProjectImport
1748 dependsOn jalviewjsEclipsePaths
1751 // do not run a headless transpile when we claim to be in Eclipse
1753 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1754 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1756 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1760 executable(eclipseBinary)
1761 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-${jalviewjs_eclipse_build_arg}", eclipse_project_name ])
1765 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1767 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
1773 stdout = new ByteArrayOutputStream()
1774 stderr = new ByteArrayOutputStream()
1776 def logOutFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}"
1777 def logOutFile = file(logOutFileName)
1778 logOutFile.createNewFile()
1779 logOutFile.text = """ROOT: ${jalviewjs_eclipse_root}
1780 BINARY: ${eclipseBinary}
1781 VERSION: ${eclipseVersion}
1782 WORKSPACE: ${eclipseWorkspace}
1783 DEBUG: ${eclipseDebug}
1786 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
1787 // combine stdout and stderr
1788 def logErrFOS = logOutFOS
1790 if (jalviewjs_j2s_to_console.equals("true")) {
1791 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1792 new org.apache.tools.ant.util.TeeOutputStream(
1796 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1797 new org.apache.tools.ant.util.TeeOutputStream(
1802 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1805 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1812 if (stdout.toString().contains("Error processing ")) {
1813 // j2s did not complete transpile
1814 //throw new TaskExecutionException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
1815 throw new GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
1819 inputs.dir("${jalviewDir}/${sourceDir}")
1820 outputs.dir("${jalviewDir}/${jalviewjsTransferSiteJsDir}")
1821 outputs.upToDateWhen( { file("${jalviewDir}/${jalviewjsTransferSiteJsDir}${jalviewjs_server_resource}").exists() } )
1825 def jalviewjsCallCore(FileCollection list, String prefixFile, String suffixFile, String jsfile, String zjsfile, File logOutFile, Boolean logOutConsole) {
1827 def stdout = new ByteArrayOutputStream()
1828 def stderr = new ByteArrayOutputStream()
1830 def coreFile = file(jsfile)
1832 msg = "Generating ${jsfile}"
1834 logOutFile.createNewFile()
1835 logOutFile.append(msg+"\n")
1837 def coreTop = file(prefixFile)
1838 def coreBottom = file(suffixFile)
1839 coreFile.getParentFile().mkdirs()
1840 coreFile.createNewFile()
1841 coreFile.write( coreTop.text )
1846 t.replaceAll("Clazz\\.","Clazz_")
1847 t.replaceAll("Class__","Clazz._")
1848 coreFile.append( t )
1850 msg = "...file '"+f.getPath()+"' does not exist, skipping"
1852 logOutFile.append(msg+"\n")
1855 coreFile.append( coreBottom.text )
1857 msg = "Generating ${zjsfile}"
1859 logOutFile.append(msg+"\n")
1860 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
1861 def logErrFOS = logOutFOS
1864 classpath = files(["${jalviewDir}/tools/closure_compiler.jar"])
1865 args = [ "--js", jsfile, "--js_output_file", zjsfile ]
1867 msg = "\nRunning '"+commandLine.join(' ')+"'\n"
1869 logOutFile.append(msg+"\n")
1871 if (logOutConsole) {
1872 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1873 new org.apache.tools.ant.util.TeeOutputStream(
1877 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1878 new org.apache.tools.ant.util.TeeOutputStream(
1883 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1886 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1893 logOutFile.append(msg+"\n")
1897 task jalviewjsBuildAllCores {
1899 description "Build the core js lib closures listed in the classlists dir"
1900 dependsOn jalviewjsTranspile
1901 dependsOn jalviewjsTransferUnzipSwingJs
1903 def j2sDir = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${jalviewjs_j2s_subdir}"
1904 def jsDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${jalviewjs_js_subdir}"
1905 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}/${jalviewjs_j2s_subdir}/core"
1906 def prefixFile = "${jsDir}/core/coretop2.js"
1907 def suffixFile = "${jsDir}/core/corebottom2.js"
1909 inputs.file prefixFile
1910 inputs.file suffixFile
1912 def classlistFiles = []
1913 // add the classlists found int the jalviewjs_classlists_dir
1914 fileTree(dir: "${jalviewDir}/${jalviewjs_classlists_dir}", include: "*.txt").each {
1916 def name = file.getName() - ".txt"
1923 // _jmol and _jalview cores. Add any other peculiar classlist.txt files here
1924 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jmol}"), 'name': "_jvjmol" ]
1925 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jalview}"), 'name': jalviewjsJalviewCoreName ]
1929 classlistFiles.each {
1932 def file = hash['file']
1933 if (! file.exists()) {
1934 println("...classlist file '"+file.getPath()+"' does not exist, skipping")
1935 return false // this is a "continue" in groovy .each closure
1937 def name = hash['name']
1939 name = file.getName() - ".txt"
1947 def list = fileTree(dir: j2sDir, includes: filelist)
1949 def jsfile = "${outputDir}/core${name}.js"
1950 def zjsfile = "${outputDir}/core${name}.z.js"
1960 outputs.file(jsfile)
1961 outputs.file(zjsfile)
1964 // _stevesoft core. add any cores without a classlist here (and the inputs and outputs)
1965 def stevesoftClasslist = [
1966 'jsfile': "${outputDir}/core_stevesoft.js",
1967 'zjsfile': "${outputDir}/core_stevesoft.z.js",
1968 'list': fileTree(dir: j2sDir, include: "com/stevesoft/pat/**/*.js")
1970 classlists += stevesoftClasslist
1971 inputs.files(stevesoftClasslist['list'])
1972 outputs.file(stevesoftClasslist['jsfile'])
1973 outputs.file(stevesoftClasslist['zjsfile'])
1976 def logOutFile = file("${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_closure_stdout}")
1977 logOutFile.getParentFile().mkdirs()
1978 logOutFile.createNewFile()
1979 logOutFile.write(getDate("yyyy-MM-dd HH:mm:ss")+" jalviewjsBuildAllCores\n----\n")
1982 jalviewjsCallCore(it.list, prefixFile, suffixFile, it.jsfile, it.zjsfile, logOutFile, jalviewjs_j2s_to_console.equals("true"))
1989 task jalviewjsPublishCoreTemplate(type: Sync) {
1990 dependsOn jalviewjsBuildAllCores
1992 def inputFile = file("${jalviewDir}/${j2s_template_html}")
1993 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
1997 def outputFiles = []
1998 jalviewjsJalviewCoreHtmlFile = "${jalviewjsJalviewTemplateName}_${jalviewjsJalviewCoreName}.html"
1999 rename { filename ->
2000 outputFiles += "${outputDir}/${filename}"
2001 if (filename.equals(inputFile.getName())) {
2002 return jalviewjsJalviewCoreHtmlFile
2006 filter(ReplaceTokens,
2010 'MAIN': '"'+mainClassName+'"',
2012 'NAME': jalviewjsJalviewTemplateName
2015 filter(ReplaceTokens,
2019 'NONE': jalviewjsJalviewCoreName
2025 outputs.files outputFiles
2026 inputs.files inputFile
2030 task jalviewjsSyncCore (type: Sync) {
2031 dependsOn jalviewjsBuildAllCores
2032 dependsOn jalviewjsPublishCoreTemplate
2033 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteCoreDir}")
2034 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
2038 def outputFiles = []
2039 rename { filename ->
2040 outputFiles += "${outputDir}/${filename}"
2046 outputs.files outputFiles
2047 inputs.files inputFiles
2051 // this Copy version of TransferSiteJs will delete anything else in the target dir
2052 task jalviewjsCopyTransferSiteJs(type: Copy) {
2053 dependsOn jalviewjsTranspile
2054 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2055 into "${jalviewDir}/${jalviewjsSiteDir}"
2059 // this Sync version of TransferSite is used by buildship to keep the website automatically up to date when a file changes
2060 task jalviewjsSyncTransferSiteJs(type: Sync) {
2061 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2063 into "${jalviewDir}/${jalviewjsSiteDir}"
2070 jalviewjsSyncAllLibs.mustRunAfter jalviewjsCopyTransferSiteJs
2071 jalviewjsSyncResources.mustRunAfter jalviewjsCopyTransferSiteJs
2072 jalviewjsSyncSiteResources.mustRunAfter jalviewjsCopyTransferSiteJs
2073 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsCopyTransferSiteJs
2075 jalviewjsSyncAllLibs.mustRunAfter jalviewjsSyncTransferSiteJs
2076 jalviewjsSyncResources.mustRunAfter jalviewjsSyncTransferSiteJs
2077 jalviewjsSyncSiteResources.mustRunAfter jalviewjsSyncTransferSiteJs
2078 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsSyncTransferSiteJs
2081 task jalviewjsPrepareSite {
2083 description "Prepares the website folder including unzipping files and copying resources"
2084 dependsOn jalviewjsSyncAllLibs
2085 dependsOn jalviewjsSyncResources
2086 dependsOn jalviewjsSyncSiteResources
2087 dependsOn jalviewjsSyncBuildProperties
2088 dependsOn jalviewjsSyncCore
2092 task jalviewjsBuildSite {
2094 description "Builds the whole website including transpiled code"
2095 dependsOn jalviewjsCopyTransferSiteJs
2096 dependsOn jalviewjsPrepareSite
2100 task cleanJalviewjsSite {
2102 delete "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2103 delete "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
2104 delete "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
2105 delete "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
2106 delete "${jalviewDir}/${jalviewjsSiteDir}"
2111 task jalviewjsSiteTar(type: Tar) {
2113 description "Creates a tar.gz file for the website"
2114 dependsOn jalviewjsBuildSite
2115 def outputFilename = "jalviewjs-site-${JALVIEW_VERSION}.tar.gz"
2117 archiveFileName = outputFilename
2118 } catch (Exception e) {
2119 archiveName = outputFilename
2122 compression Compression.GZIP
2124 from "${jalviewDir}/${jalviewjsSiteDir}"
2125 into jalviewjs_site_dir // this is inside the tar file
2127 inputs.dir("${jalviewDir}/${jalviewjsSiteDir}")
2131 task jalviewjsServer {
2133 def filename = "jalviewjsTest.html"
2134 description "Starts a webserver on localhost to test the website. See ${filename} to access local site on most recently used port."
2135 def htmlFile = "${jalviewDirAbsolutePath}/${filename}"
2138 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
2139 def port = Integer.valueOf(jalviewjs_server_port)
2144 while(port < start+1000 && !running) {
2146 def doc_root = new File("${jalviewDirAbsolutePath}/${jalviewjsSiteDir}")
2147 def jalviewjsServer = factory.start(doc_root, port)
2149 url = jalviewjsServer.getResourceUrl(jalviewjs_server_resource)
2150 urlcore = jalviewjsServer.getResourceUrl(jalviewjsJalviewCoreHtmlFile)
2151 println("SERVER STARTED with document root ${doc_root}.")
2152 println("Go to "+url+" . Run gradle --stop to stop (kills all gradle daemons).")
2153 println("For debug: "+url+"?j2sdebug")
2154 println("For core: "+urlcore)
2156 file(htmlFile).text = """
2157 <p><a href="${url}">JalviewJS Test. <${url}></a></p>
2158 <p><a href="${url}?j2sdebug">JalviewJS Test with debug. <${url}?j2sdebug<</a></p>
2159 <p><a href="${urlcore}">${jalviewjsJalviewTemplateName} Core Test. <${urlcore}></a></p>
2162 } catch (Exception e) {
2169 outputs.file(htmlFile)
2170 outputs.upToDateWhen({false})
2174 task cleanJalviewjsAll {
2176 description "Delete all configuration and build artifacts to do with JalviewJS build"
2177 dependsOn cleanJalviewjsSite
2178 dependsOn jalviewjsEclipsePaths
2181 delete "${jalviewDir}/${jalviewjsBuildDir}"
2182 delete "${jalviewDir}/${eclipse_bin_dir}"
2183 if (eclipseWorkspace != null && file(eclipseWorkspace.getAbsolutePath()+"/.metadata").exists()) {
2184 delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata")
2186 delete "${jalviewDir}/${jalviewjs_j2s_settings}"
2189 outputs.upToDateWhen( { false } )
2194 task jalviewjsIDE_CopyTransferSiteJs(type: Copy) {
2195 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2196 into "${jalviewDir}/${jalviewjsSiteDir}"
2200 task jalviewjsIDE_j2sFile {
2201 group "00 JalviewJS in Eclipse"
2202 description "Creates the .j2s file"
2203 dependsOn jalviewjsCreateJ2sSettings
2207 task jalviewjsIDE_SyncCore {
2208 group "00 JalviewJS in Eclipse"
2209 description "Build the core js lib closures listed in the classlists dir and publish core html from template"
2210 dependsOn jalviewjsSyncCore
2214 task jalviewjsIDE_PrepareSite {
2215 group "00 JalviewJS in Eclipse"
2216 description "Sync libs and resources to site dir, but not closure cores"
2217 dependsOn jalviewjsSyncAllLibs
2218 dependsOn jalviewjsSyncResources
2219 dependsOn jalviewjsSyncSiteResources
2220 dependsOn jalviewjsSyncBuildProperties
2224 task jalviewjsIDE_AssembleSite {
2225 group "00 JalviewJS in Eclipse"
2226 description "Assembles the Eclipse transpiled site and unzips supporting zipfiles"
2227 dependsOn jalviewjsIDE_CopyTransferSiteJs
2228 dependsOn jalviewjsPrepareSite
2232 task jalviewjsIDE_SiteClean {
2233 group "00 JalviewJS in Eclipse"
2234 description "Deletes the Eclipse transpiled site"
2235 dependsOn cleanJalviewjsSite
2239 task jalviewjsIDE_Server {
2240 group "00 JalviewJS in Eclipse"
2241 description "Starts a webserver on localhost to test the website"
2242 dependsOn jalviewjsServer
2246 // buildship runs this at import
2247 task eclipseSynchronizationTask {
2248 dependsOn eclipseSetup
2249 dependsOn jalviewjsIDE_j2sFile
2253 // buildship runs this at build time
2254 task eclipseAutoBuildTask {
2255 dependsOn jalviewjsIDE_PrepareSite
2267 description "Build the site"
2268 dependsOn jalviewjsBuildSite