1 import org.apache.tools.ant.filters.ReplaceTokens
2 import org.gradle.internal.os.OperatingSystem
3 import org.gradle.plugins.ide.eclipse.model.Output
4 import org.gradle.plugins.ide.eclipse.model.Library
6 import groovy.transform.ExternalizeMethods
10 classpath 'org.openclover:clover:4.3.1'
18 id 'com.github.johnrengelman.shadow' version '4.0.3'
19 id 'com.install4j.gradle' version '7.0.9'
20 id 'com.dorongold.task-tree' version '1.4' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree
33 compile 'org.apache.commons:commons-compress:1.18'
37 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
38 def string(Object o) {
44 jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
46 // local build environment properties
47 def localProps = "${jalviewDirAbsolutePath}/local.properties"
48 if (file(localProps).exists()) {
50 def p = new Properties()
51 def localPropsFIS = new FileInputStream(localProps)
56 def over = getProperty(key) != null
59 println("Overriding property '${key}' with local.properties value '${val}'")
62 } catch (Exception e) {
63 System.out.println("Exception reading local.properties")
68 // this property set when running Eclipse headlessly
69 j2sHeadlessBuildProperty = string("net.sf.j2s.core.headlessbuild")
70 // this property set by Eclipse
71 eclipseApplicationProperty = string("eclipse.application")
72 // CHECK IF RUNNING FROM WITHIN ECLIPSE
73 def eclipseApplicationPropertyVal = System.properties[eclipseApplicationProperty]
74 IN_ECLIPSE = eclipseApplicationPropertyVal != null && eclipseApplicationPropertyVal.startsWith("org.eclipse.ui.")
75 // BUT WITHOUT THE HEADLESS BUILD PROPERTY SET
76 if (System.properties[j2sHeadlessBuildProperty].equals("true")) {
77 println("Setting IN_ECLIPSE to ${IN_ECLIPSE} as System.properties['${j2sHeadlessBuildProperty}'] == '${System.properties[j2sHeadlessBuildProperty]}'")
81 println("WITHIN ECLIPSE IDE")
83 println("HEADLESS BUILD")
86 System.properties.sort { it.key }.each {
87 key, val -> println("SYSTEM PROPERTY ${key}='${val}'")
91 cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
92 classes = string("${jalviewDir}/${classesDir}")
93 if (clover.equals("true")) {
95 classes = string("${buildDir}/${cloverClassesDir}")
98 classes = string("${jalviewDir}/${classesDir}")
101 getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
102 getdownDir = string("")
103 reportRsyncCmd = false
105 buildProperties = build_properties_file
106 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
110 // TODO: get bamboo build artifact URL for getdown artifacts
111 getdown_channel_base = bamboo_channelbase
112 getdown_channel_name = string("${bamboo_planKey}/${JAVA_VERSION}")
113 getdown_app_base = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
114 getdown_app_dir = getdown_app_dir_alt
115 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
119 getdown_channel_name = CHANNEL.toLowerCase()
120 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
121 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
122 getdown_app_dir = getdown_app_dir_release
123 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
124 reportRsyncCommand = true
128 getdown_channel_name = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
129 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
130 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
131 getdown_app_dir = getdown_app_dir_alt
132 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
133 print "Must provide an ARCHIVEDIR value to produce an archive distribution"
136 packageDir = string("${ARCHIVEDIR}/${packageDir}")
137 buildProperties = string("${ARCHIVEDIR}/${classesDir}/${build_properties_file}")
140 reportRsyncCommand = true
144 getdown_channel_name = string("archive/${JALVIEW_VERSION}")
145 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
146 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
147 getdown_app_dir = getdown_app_dir_alt
148 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
149 print "Must provide an ARCHIVEDIR value to produce an archive distribution"
152 packageDir = string("${ARCHIVEDIR}/${packageDir}")
153 buildProperties = string("${ARCHIVEDIR}/${classesDir}/${build_properties_file}")
156 reportRsyncCommand = true
157 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
161 getdown_channel_name = CHANNEL.toLowerCase()
162 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
163 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
164 getdown_app_dir = getdown_app_dir_alt
165 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
166 reportRsyncCommand = true
170 getdown_channel_name = CHANNEL.toLowerCase()
171 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
172 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
173 getdown_app_dir = getdown_app_dir_alt
174 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
175 reportRsyncCommand = true
178 case ~/^SCRATCH(|-[-\w]*)$/:
179 getdown_channel_name = CHANNEL
180 getdownDir = string("${getdown_channel_name}/${JAVA_VERSION}")
181 getdown_app_base = string("${getdown_channel_base}/${getdownDir}")
182 getdown_app_dir = getdown_app_dir_alt
183 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
184 reportRsyncCommand = true
188 getdown_app_base = file(getdownWebsiteDir).toURI().toString()
189 getdown_app_dir = getdown_app_dir_alt
190 buildProperties = string("${jalviewDir}/${classesDir}/${build_properties_file}")
191 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
194 default: // something wrong specified
195 print("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
201 getdownAppDir = string("${getdownWebsiteDir}/${getdown_app_dir}")
202 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
203 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
204 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
205 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
206 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
207 /* compile without modules -- using classpath libraries
208 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
209 modules_runtimeClasspath = modules_compileClasspath
212 gitBranch = string("")
214 println("Using a ${CHANNEL} profile.")
216 additional_compiler_args = []
217 // configure classpath/args for j8/j11 compilation
218 if (JAVA_VERSION.equals("1.8")) {
219 JAVA_INTEGER_VERSION = string("8")
222 libDistDir = j8libDir
223 compile_source_compatibility = 1.8
224 compile_target_compatibility = 1.8
225 // these are getdown.txt properties defined dependent on the JAVA_VERSION
226 getdown_alt_java_min_version = getdown_alt_java8_min_version
227 getdown_alt_java_max_version = getdown_alt_java8_max_version
228 // this property is assigned below and expanded to multiple lines in the getdown task
229 getdown_alt_multi_java_location = getdown_alt_java8_txt_multi_java_location
230 // this property is for the Java library used in eclipse
231 eclipse_java_runtime_name = string("JavaSE-1.8")
232 } else if (JAVA_VERSION.equals("11")) {
233 JAVA_INTEGER_VERSION = string("11")
235 libDistDir = j11libDir
236 compile_source_compatibility = 11
237 compile_target_compatibility = 11
238 getdown_alt_java_min_version = getdown_alt_java11_min_version
239 getdown_alt_java_max_version = getdown_alt_java11_max_version
240 getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
241 eclipse_java_runtime_name = string("JavaSE-11")
242 /* compile without modules -- using classpath libraries
243 additional_compiler_args += [
244 '--module-path', modules_compileClasspath.asPath,
245 '--add-modules', j11modules
248 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
249 JAVA_INTEGER_VERSION = JAVA_VERSION
251 libDistDir = j11libDir
252 compile_source_compatibility = JAVA_VERSION
253 compile_target_compatibility = JAVA_VERSION
254 getdown_alt_java_min_version = getdown_alt_java11_min_version
255 getdown_alt_java_max_version = getdown_alt_java11_max_version
256 getdown_alt_multi_java_location = getdown_alt_java11_txt_multi_java_location
257 eclipse_java_runtime_name = string("JavaSE-11")
258 /* compile without modules -- using classpath libraries
259 additional_compiler_args += [
260 '--module-path', modules_compileClasspath.asPath,
261 '--add-modules', j11modules
265 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
270 macosJavaVMDir = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/macos-jre${JAVA_VERSION}/jre")
271 macosJavaVMTgz = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/macos-jre${JAVA_VERSION}.tar.gz")
272 windowsJavaVMDir = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/getdown/windows-jre${JAVA_VERSION}/jre")
273 windowsJavaVMTgz = string("${System.env.HOME}/buildtools/jre/openjdk-java_vm/install4j/tgz/windows-jre${JAVA_VERSION}.tar.gz")
274 install4jDir = string("${jalviewDir}/${install4jResourceDir}")
275 install4jConfFileName = string("jalview-installers-java${JAVA_VERSION}.install4j")
276 install4jConfFile = string("${install4jDir}/${install4jConfFileName}")
279 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
280 helpFile = string("${classes}/${helpDir}/help.jhm")
283 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
284 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
285 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
287 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
289 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
291 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
292 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
293 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
294 jalviewjsJalviewCoreHtmlFile = string("")
295 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
296 jalviewjsCoreClasslists = []
297 jalviewjsJalviewTemplateName = string(jalviewjs_name)
299 eclipseWorkspace = null
300 eclipseBinary = string("")
301 eclipseVersion = string("")
310 srcDirs "${jalviewDir}/${sourceDir}"
311 outputDir = file(project.classes)
315 srcDirs "${jalviewDir}/${resourceDir}"
318 jar.destinationDir = file("${jalviewDir}/${packageDir}")
320 compileClasspath = files(sourceSets.main.java.outputDir)
321 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
323 runtimeClasspath = compileClasspath
328 srcDirs = [ cloverInstrDir ]
329 outputDir = file("${buildDir}/${cloverClassesDir}")
333 srcDirs = sourceSets.main.resources.srcDirs
335 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
336 compileClasspath += files(sourceSets.main.java.outputDir)
337 compileClasspath += sourceSets.main.compileClasspath
338 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
339 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
341 runtimeClasspath = compileClasspath
346 srcDirs "${jalviewDir}/${testSourceDir}"
347 outputDir = file("${jalviewDir}/${testOutputDir}")
351 srcDirs = sourceSets.main.resources.srcDirs
354 compileClasspath = files( sourceSets.test.java.outputDir )
357 compileClasspath += sourceSets.clover.compileClasspath
359 compileClasspath += files(sourceSets.main.java.outputDir)
362 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
363 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
364 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
366 runtimeClasspath = compileClasspath
374 cloverCompile 'org.openclover:clover:4.3.1'
375 testCompile 'org.openclover:clover:4.3.1'
382 cloverRuntime.extendsFrom cloverCompile
387 name = eclipse_project_name
389 natures 'org.eclipse.jdt.core.javanature',
390 'org.eclipse.jdt.groovy.core.groovyNature',
391 'org.eclipse.buildship.core.gradleprojectnature'
393 buildCommand 'org.eclipse.jdt.core.javabuilder'
394 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
398 //defaultOutputDir = sourceSets.main.java.outputDir
401 if (it.isCanBeResolved()) {
406 minusConfigurations += removeThese
407 plusConfigurations = [ ]
411 def removeTheseToo = []
412 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
413 cp.entries.each { entry ->
414 if (entry.kind == 'src') {
415 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == sourceDir || entry.path == testSourceDir)) {
416 removeTheseToo += entry
418 alreadyAddedSrcPath.putAt(entry.path, true)
422 cp.entries.removeAll(removeTheseToo)
424 if (file("${jalviewDir}/${eclipse_bin_dir}/main").isDirectory()) {
425 cp.entries += new Output("${eclipse_bin_dir}/main")
427 if (file(helpParentDir).isDirectory()) {
428 cp.entries += new Library(fileReference(helpParentDir))
430 if (file(resourceDir).isDirectory()) {
431 cp.entries += new Library(fileReference(resourceDir))
434 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
436 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.each {
437 //don't want to add outputDir as eclipse is using its own output dir in bin/main
438 if (it.isDirectory() || ! it.exists()) {
439 // don't add dirs to classpath
442 def itPath = it.toString()
443 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
444 // make relative path
445 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
447 if (alreadyAddedLibPath.get(itPath)) {
448 //println("Not adding duplicate entry "+itPath)
450 //println("Adding entry "+itPath)
451 cp.entries += new Library(fileReference(itPath))
452 alreadyAddedLibPath.put(itPath, true)
456 //fileTree(dir: "$jalviewDir/$utilsDir", include: ["test*/*.jar"]).each {
457 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
458 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
459 if (it.isDirectory() || ! it.exists()) {
460 // don't add dirs to classpath
461 return false // groovy "continue" in .any closure
464 def itPath = it.toString()
465 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
466 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
468 if (alreadyAddedLibPath.get(itPath)) {
471 def lib = new Library(fileReference(itPath))
472 lib.entryAttributes["test"] = "true"
474 alreadyAddedLibPath.put(itPath, true)
482 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
487 // for the IDE, use java 11 compatibility
488 sourceCompatibility = compile_source_compatibility
489 targetCompatibility = compile_target_compatibility
490 javaRuntimeName = eclipse_java_runtime_name
492 // add in jalview project specific properties/preferences into eclipse core preferences
494 withProperties { props ->
495 def jalview_prefs = new Properties()
496 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
497 jalview_prefs.load(ins)
499 jalview_prefs.forEach { t, v ->
500 if (props.getAt(t) == null) {
510 // Don't want these to be activated if in headless build
511 //synchronizationTasks "eclipseConfiguration"
512 autoBuildTasks "eclipseAutoBuildTask"
518 // only instrument source, we build test classes as normal
519 inputs.files files (sourceSets.main.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
520 outputs.dir cloverInstrDir
523 delete cloverInstrDir
524 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
525 "-d", "${buildDir}/${cloverSourcesInstrDir}"]
526 argsList.addAll(inputs.files.files.collect({ file ->
529 String[] args = argsList.toArray()
530 println("About to instrument "+args.length +" files")
531 com.atlassian.clover.CloverInstr.mainImpl(args)
537 group = "Verification"
538 description = "Createst the Clover report"
539 inputs.dir "${buildDir}/clover"
540 outputs.dir "${reportsDir}/clover"
542 file("${buildDir}/clover/clover.db").exists()
545 def argsList = ["--initstring", "${buildDir}/clover/clover.db",
546 "-o", "${reportsDir}/clover"]
547 String[] args = argsList.toArray()
548 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
550 // and generate ${reportsDir}/clover/clover.xml
551 args = ["--initstring", "${buildDir}/clover/clover.db",
552 "-o", "${reportsDir}/clover/clover.xml"].toArray()
553 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
562 sourceCompatibility = compile_source_compatibility
563 targetCompatibility = compile_target_compatibility
564 options.compilerArgs = additional_compiler_args
565 print ("Setting target compatibility to "+targetCompatibility+"\n")
573 dependsOn compileCloverJava
574 classpath += configurations.cloverRuntime
576 classpath += sourceSets.main.runtimeClasspath
579 sourceCompatibility = compile_source_compatibility
580 targetCompatibility = compile_target_compatibility
581 options.compilerArgs = additional_compiler_args
582 print ("Setting target compatibility to "+targetCompatibility+"\n")
590 sourceCompatibility = compile_source_compatibility
591 targetCompatibility = compile_target_compatibility
592 options.compilerArgs += additional_compiler_args
593 print ("Setting target compatibility to "+targetCompatibility+"\n")
595 classpath += configurations.cloverRuntime
601 delete sourceSets.main.java.outputDir
608 delete sourceSets.test.java.outputDir
609 delete cloverInstrDir
614 // format is a string like date.format("dd MMMM yyyy")
615 def getDate(format) {
616 def date = new Date()
617 return date.format(format)
622 def hashStdOut = new ByteArrayOutputStream()
624 commandLine "git", "rev-parse", "--short", "HEAD"
625 standardOutput = hashStdOut
629 def branchStdOut = new ByteArrayOutputStream()
631 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
632 standardOutput = branchStdOut
636 gitHash = hashStdOut.toString().trim()
637 gitBranch = branchStdOut.toString().trim()
639 outputs.upToDateWhen { false }
643 task createBuildProperties(type: WriteProperties) {
645 inputs.dir("${jalviewDir}/${sourceDir}")
646 inputs.dir("${jalviewDir}/${resourceDir}")
647 file(buildProperties).getParentFile().mkdirs()
648 outputFile (buildProperties)
649 // taking time specific comment out to allow better incremental builds
650 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
651 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
652 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
653 property "VERSION", JALVIEW_VERSION
654 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
655 outputs.file(outputFile)
659 task cleanBuildingHTML(type: Delete) {
666 task convertBuildingMD(type: Exec) {
667 dependsOn cleanBuildingHTML
668 def buildingMD = "${jalviewDir}/${docDir}/building.md"
669 def css = "${jalviewDir}/${docDir}/github.css"
672 pandoc_exec.split(",").each {
673 if (file(it.trim()).exists()) {
679 def hostname = "hostname".execute().text.trim()
680 if ((pandoc == null || ! file(pandoc).exists()) && hostname.equals("jv-bamboo")) {
681 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
685 if (pandoc != null && file(pandoc).exists()) {
686 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
688 println("Cannot find pandoc. Skipping convert building.md to HTML")
689 throw new StopExecutionException()
695 inputs.file(buildingMD)
697 outputs.file(buildingHTML)
708 task syncDocs(type: Sync) {
709 dependsOn convertBuildingMD
710 def syncDir = "${classes}/${docDir}"
711 from fileTree("${jalviewDir}/${docDir}")
717 task copyHelp(type: Copy) {
718 def inputDir = "${jalviewDir}/${helpParentDir}/${helpDir}"
719 def outputDir = "${classes}/${helpDir}"
724 filter(ReplaceTokens,
728 'Version-Rel': JALVIEW_VERSION,
729 'Year-Rel': getDate("yyyy")
741 outputs.files(helpFile)
742 outputs.dir(outputDir)
746 task syncLib(type: Sync) {
747 def syncDir = "${classes}/${libDistDir}"
748 from fileTree("${jalviewDir}/${libDistDir}")
753 task syncResources(type: Sync) {
754 from "${jalviewDir}/${resourceDir}"
764 dependsOn syncResources
770 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
773 dependsOn compileJava
775 dependsOn cloverInstr
779 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
783 includeGroups testngGroups
785 useDefaultListeners=true
788 workingDir = jalviewDir
789 //systemProperties 'clover.jar' System.properties.clover.jar
790 sourceCompatibility = compile_source_compatibility
791 targetCompatibility = compile_target_compatibility
792 jvmArgs += additional_compiler_args
797 task buildIndices(type: JavaExec) {
799 classpath = sourceSets.main.compileClasspath
800 main = "com.sun.java.help.search.Indexer"
801 workingDir = "${classes}/${helpDir}"
804 inputs.dir("${workingDir}/${argDir}")
806 outputs.dir("${classes}/doc")
807 outputs.dir("${classes}/help")
808 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
809 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
810 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
811 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
812 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
813 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
817 task compileLinkCheck(type: JavaCompile) {
819 classpath = files("${jalviewDir}/${utilsDir}")
820 destinationDir = file("${jalviewDir}/${utilsDir}")
821 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
823 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
824 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
825 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
826 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
830 task linkCheck(type: JavaExec) {
831 dependsOn prepare, compileLinkCheck
833 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
834 classpath = files("${jalviewDir}/${utilsDir}")
835 main = "HelpLinksChecker"
836 workingDir = jalviewDir
837 def help = "${classes}/${helpDir}"
838 args = [ "${classes}/${helpDir}", "-nointernet" ]
840 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
842 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
845 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
849 inputs.dir("${classes}/${helpDir}")
850 outputs.file(helpLinksCheckerOutFile)
853 // import the pubhtmlhelp target
854 ant.properties.basedir = "${jalviewDir}"
855 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes}/${helpDir}"
856 ant.importBuild "${utilsDir}/publishHelp.xml"
859 task cleanPackageDir(type: Delete) {
861 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
867 dependsOn buildIndices
868 dependsOn createBuildProperties
871 attributes "Main-Class": mainClass,
872 "Permissions": "all-permissions",
873 "Application-Name": "Jalview Desktop",
874 "Codebase": application_codebase
877 destinationDir = file("${jalviewDir}/${packageDir}")
878 archiveName = rootProject.name+".jar"
886 inputs.dir("${classes}")
887 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
891 task copyJars(type: Copy) {
892 from fileTree(dir: "${classes}", include: "**/*.jar").files
893 into "${jalviewDir}/${packageDir}"
897 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
898 task syncJars(type: Sync) {
899 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
900 into "${jalviewDir}/${packageDir}"
902 include jar.archiveName
909 description = "Put all required libraries in dist"
910 // order of "cleanPackageDir", "copyJars", "jar" important!
911 jar.mustRunAfter cleanPackageDir
912 syncJars.mustRunAfter cleanPackageDir
913 dependsOn cleanPackageDir
916 outputs.dir("${jalviewDir}/${packageDir}")
921 dependsOn cleanPackageDir
927 group = "distribution"
931 from ("${jalviewDir}/${libDistDir}") {
935 attributes 'Implementation-Version': JALVIEW_VERSION
937 mainClassName = shadowJarMainClass
939 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
944 task getdownWebsite() {
945 group = "distribution"
946 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
951 def getdownWebsiteResourceFilenames = []
952 def getdownTextString = ""
953 def getdownResourceDir = getdownResourceDir
954 def getdownAppDir = getdownAppDir
955 def getdownResourceFilenames = []
958 // clean the getdown website and files dir before creating getdown folders
959 delete getdownWebsiteDir
960 delete getdownFilesDir
964 rename(build_properties_file, getdown_build_properties)
967 getdownWebsiteResourceFilenames += "${getdown_app_dir}/${getdown_build_properties}"
969 // go through properties looking for getdown_txt_...
970 def props = project.properties.sort { it.key }
971 if (getdown_alt_java_min_version.length() > 0) {
972 props.put("getdown_txt_java_min_version", getdown_alt_java_min_version)
974 if (getdown_alt_java_max_version.length() > 0) {
975 props.put("getdown_txt_java_max_version", getdown_alt_java_max_version)
977 props.put("getdown_txt_multi_java_location", getdown_alt_multi_java_location)
979 props.put("getdown_txt_appbase", getdown_app_base)
980 props.each{ prop, val ->
981 if (prop.startsWith("getdown_txt_") && val != null) {
982 if (prop.startsWith("getdown_txt_multi_")) {
983 def key = prop.substring(18)
984 val.split(",").each{ v ->
985 def line = "${key} = ${v}\n"
986 getdownTextString += line
989 // file values rationalised
990 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
992 if (val.indexOf('/') == 0) {
995 } else if (val.indexOf('/') > 0) {
996 // relative path (relative to jalviewDir)
997 r = file( "${jalviewDir}/${val}" )
1000 val = "${getdown_resource_dir}/" + r.getName()
1001 getdownWebsiteResourceFilenames += val
1002 getdownResourceFilenames += r.getPath()
1005 if (! prop.startsWith("getdown_txt_resource")) {
1006 def line = prop.substring(12) + " = ${val}\n"
1007 getdownTextString += line
1013 getdownWebsiteResourceFilenames.each{ filename ->
1014 getdownTextString += "resource = ${filename}\n"
1016 getdownResourceFilenames.each{ filename ->
1019 into getdownResourceDir
1024 fileTree(file(packageDir)).each{ f ->
1025 if (f.isDirectory()) {
1026 def files = fileTree(dir: f, include: ["*"]).getFiles()
1028 } else if (f.exists()) {
1032 codeFiles.sort().each{f ->
1033 def name = f.getName()
1034 def line = "code = ${getdown_app_dir}/${name}\n"
1035 getdownTextString += line
1042 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1044 if (JAVA_VERSION.equals("11")) {
1045 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1046 j11libFiles.sort().each{f ->
1047 def name = f.getName()
1048 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1049 getdownTextString += line
1052 into getdownJ11libDir
1058 // 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.
1059 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1060 getdownTextString += "resource = ${getdown_launcher_new}\n"
1061 getdownTextString += "class = ${mainClass}\n"
1063 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1064 getdown_txt.write(getdownTextString)
1066 def launch_jvl = file("${getdownWebsiteDir}/${getdown_launch_jvl}")
1067 launch_jvl.write("appbase="+props.get("getdown_txt_appbase"))
1070 from getdownLauncher
1071 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1072 into getdownWebsiteDir
1076 from getdownLauncher
1077 if (file(getdownLauncher).getName() != getdown_launcher) {
1078 rename(file(getdownLauncher).getName(), getdown_launcher)
1080 into getdownWebsiteDir
1083 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1086 from getdownLauncher
1087 from "${getdownWebsiteDir}/${getdown_build_properties}"
1088 if (file(getdownLauncher).getName() != getdown_launcher) {
1089 rename(file(getdownLauncher).getName(), getdown_launcher)
1091 into getdownInstallDir
1095 from getdownInstallDir
1096 into getdownFilesInstallDir
1103 from getdownLauncher
1104 from "${getdownWebsiteDir}/${getdown_build_properties}"
1105 if (file(getdownLauncher).getName() != getdown_launcher) {
1106 rename(file(getdownLauncher).getName(), getdown_launcher)
1108 into getdownFilesDir
1112 from getdownResourceDir
1113 into "${getdownFilesDir}/${getdown_resource_dir}"
1118 inputs.dir("${jalviewDir}/${packageDir}")
1120 outputs.dir(getdownWebsiteDir)
1121 outputs.dir(getdownFilesDir)
1125 task getdownDigest(type: JavaExec) {
1126 group = "distribution"
1127 description = "Digest the getdown website folder"
1128 dependsOn getdownWebsite
1130 classpath = files("${getdownWebsiteDir}/${getdown_launcher}")
1132 main = "com.threerings.getdown.tools.Digester"
1133 args getdownWebsiteDir
1134 inputs.dir(getdownWebsiteDir)
1135 outputs.file("${getdownWebsiteDir}/digest2.txt")
1140 group = "distribution"
1141 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1142 dependsOn getdownDigest
1144 if (reportRsyncCommand) {
1145 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1146 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1147 println "LIKELY RSYNC COMMAND:"
1148 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1149 if (RUNRSYNC == "true") {
1151 commandLine "mkdir", "-p", toDir
1154 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1164 delete getdownWebsiteDir
1165 delete getdownFilesDir
1171 def install4jHomeDir = "/opt/install4j"
1172 def hostname = "hostname".execute().text.trim()
1173 if (hostname.equals("jv-bamboo")) {
1174 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1175 } else if (OperatingSystem.current().isMacOsX()) {
1176 install4jHomeDir = '/Applications/install4j.app/Contents/Resources/app'
1177 if (! file(install4jHomeDir).exists()) {
1178 install4jHomeDir = System.getProperty("user.home")+install4jHomeDir
1180 } else if (OperatingSystem.current().isLinux()) {
1181 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1183 installDir = file(install4jHomeDir)
1184 mediaTypes = Arrays.asList(install4jMediaTypes.split(","))
1185 if (install4jFaster.equals("true")) {
1191 task copyInstall4jTemplate(type: Copy) {
1192 from (install4jDir) {
1193 include install4jTemplate
1194 rename (install4jTemplate, install4jConfFileName)
1195 filter(ReplaceTokens,
1199 '9999999999': JAVA_VERSION
1202 filter(ReplaceTokens,
1206 'JAVA_VERSION': JAVA_VERSION,
1207 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1208 'VERSION': JALVIEW_VERSION,
1209 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1210 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1211 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1212 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1213 'INSTALL4JINFOPLISTFILEASSOCIATIONS': install4jInfoPlistFileAssociations,
1214 'COPYRIGHT_MESSAGE': install4jCopyrightMessage,
1215 'MACOS_BUNDLE_ID': install4jMacOSBundleId,
1216 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1217 'GETDOWN_DIST_DIR': getdown_app_dir,
1218 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1219 'GETDOWN_INSTALL_DIR': getdown_install_dir
1222 if (OSX_KEYPASS == "") {
1223 filter(ReplaceTokens,
1224 beginToken: 'codeSigning macEnabled="',
1227 'true': 'codeSigning macEnabled="false"'
1230 filter(ReplaceTokens,
1231 beginToken: 'runPostProcessor="true" ',
1232 endToken: 'Processor',
1234 'post': 'runPostProcessor="false" postProcessor'
1240 outputs.files(install4jConfFile)
1243 // include file associations in installer
1244 def installerFileAssociationsXml = file("${install4jDir}/${install4jInstallerFileAssociations}").text
1248 match: '<action name="EXTENSIONS_REPLACED_BY_GRADLE".*?</action>',
1249 replace: installerFileAssociationsXml,
1250 file: install4jConfFile
1253 // include uninstaller applescript app files in dmg
1254 def installerDMGUninstallerXml = file("$install4jDir/$install4jDMGUninstallerAppFiles").text
1258 match: '<file name="UNINSTALL_OLD_JALVIEW_APP_REPLACED_IN_GRADLE" file=.*?>',
1259 replace: installerDMGUninstallerXml,
1260 file: install4jConfFile
1269 delete install4jConfFile
1274 task installers(type: com.install4j.gradle.Install4jTask) {
1275 group = "distribution"
1276 description = "Create the install4j installers"
1278 dependsOn copyInstall4jTemplate
1279 projectFile = file(install4jConfFile)
1280 variables = [majorVersion: version.substring(2, 11), build: 001, OSX_KEYSTORE: OSX_KEYSTORE, JSIGN_SH: JSIGN_SH]
1281 destination = "${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}"
1282 buildSelected = true
1285 macKeystorePassword=OSX_KEYPASS
1289 println("Using projectFile "+projectFile)
1292 inputs.dir(getdownWebsiteDir)
1293 inputs.file(install4jConfFile)
1294 inputs.dir(macosJavaVMDir)
1295 inputs.dir(windowsJavaVMDir)
1296 outputs.dir("${jalviewDir}/${install4jBuildDir}/${JAVA_VERSION}")
1300 task sourceDist (type: Tar) {
1302 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1303 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1304 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1306 archiveFileName = outputFileName
1307 } catch (Exception e) {
1308 archiveName = outputFileName
1311 compression Compression.GZIP
1315 def EXCLUDE_FILES=["build/*","bin/*","test-output/","test-reports","tests","clover*/*"
1320 ,"**/*.class","${j11modDir}/**/*.jar","appletlib","**/*locales"
1322 ,"utils/InstallAnywhere"]
1323 def PROCESS_FILES=[ "AUTHORS",
1331 "THIRDPARTYLIBS","TESTNG",
1333 "gradle.properties",
1344 exclude (EXCLUDE_FILES)
1345 include (PROCESS_FILES)
1346 filter(ReplaceTokens,
1350 'Version-Rel': JALVIEW_VERSION,
1351 'Year-Rel': getDate("yyyy")
1356 exclude (EXCLUDE_FILES)
1357 exclude (PROCESS_FILES)
1358 exclude ("appletlib")
1359 exclude ("**/*locales")
1360 exclude ("*locales/**")
1361 exclude ("utils/InstallAnywhere")
1363 exclude (getdown_files_dir)
1364 exclude (getdown_website_dir)
1366 // exluding these as not using jars as modules yet
1367 exclude ("${j11modDir}/**/*.jar")
1369 // from (jalviewDir) {
1370 // // explicit includes for stuff that seemed to not get included
1371 // include(fileTree("test/**/*."))
1372 // exclude(EXCLUDE_FILES)
1373 // exclude(PROCESS_FILES)
1380 dependsOn pubhtmlhelp
1382 inputs.dir("${classes}/${helpDir}")
1383 outputs.dir("${helpOutputDir}")
1387 task j2sSetHeadlessBuild {
1394 task jalviewjsSetEclipseWorkspace {
1395 def propKey = "jalviewjs_eclipse_workspace"
1397 if (project.hasProperty(propKey)) {
1398 propVal = project.getProperty(propKey)
1399 if (propVal.startsWith("~/")) {
1400 propVal = System.getProperty("user.home") + propVal.substring(1)
1403 def propsFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_workspace_location_file}"
1404 def propsFile = file(propsFileName)
1405 def eclipseWsDir = propVal
1406 def props = new Properties()
1408 if (( eclipseWsDir == null || !file(eclipseWsDir).exists() ) && propsFile.exists()) {
1409 def ins = new FileInputStream(propsFileName)
1412 if (props.getProperty(propKey, null) != null) {
1413 eclipseWsDir = props.getProperty(propKey)
1417 def writeProps = false
1418 if (eclipseWsDir == null || !file(eclipseWsDir).exists()) {
1419 def tempDir = File.createTempDir()
1420 eclipseWsDir = tempDir.getAbsolutePath()
1423 eclipseWorkspace = file(eclipseWsDir)
1426 // do not run a headless transpile when we claim to be in Eclipse
1428 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1429 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1431 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1435 props.setProperty(propKey, eclipseWsDir)
1436 propsFile.parentFile.mkdirs()
1437 def bytes = new ByteArrayOutputStream()
1438 props.store(bytes, null)
1439 def propertiesString = bytes.toString()
1440 propsFile.text = propertiesString
1446 println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath())
1449 //inputs.property(propKey, eclipseWsDir) // eclipseWsDir only gets set once this task runs, so will be out-of-date
1450 outputs.file(propsFileName)
1451 outputs.upToDateWhen { eclipseWorkspace.exists() }
1455 task jalviewjsEclipsePaths {
1458 def eclipseRoot = jalviewjs_eclipse_root
1459 if (eclipseRoot.startsWith("~/")) {
1460 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
1462 if (OperatingSystem.current().isMacOsX()) {
1463 eclipseRoot += "/Eclipse.app"
1464 eclipseBinary = "${eclipseRoot}/Contents/MacOS/eclipse"
1465 eclipseProduct = "${eclipseRoot}/Contents/Eclipse/.eclipseproduct"
1466 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
1467 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1468 eclipseRoot += "/eclipse.exe"
1470 eclipseBinary = "${eclipseRoot}/eclipse"
1471 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1472 } else { // linux or unix
1473 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1474 eclipseRoot += "/eclipse"
1476 eclipseBinary = "${eclipseRoot}/eclipse"
1477 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1480 eclipseVersion = "4.13" // default
1481 def assumedVersion = true
1482 if (file(eclipseProduct).exists()) {
1483 def fis = new FileInputStream(eclipseProduct)
1484 def props = new Properties()
1486 eclipseVersion = props.getProperty("version")
1488 assumedVersion = false
1491 def propKey = "eclipse_debug"
1492 eclipseDebug = (project.hasProperty(propKey) && project.getProperty(propKey).equals("true"))
1495 // do not run a headless transpile when we claim to be in Eclipse
1497 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1498 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1500 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1503 if (!assumedVersion) {
1504 println("ECLIPSE VERSION=${eclipseVersion}")
1511 dependsOn eclipseProject
1512 dependsOn eclipseClasspath
1513 dependsOn eclipseJdt
1517 // this version (type: Copy) will delete anything in the eclipse dropins folder that isn't in fromDropinsDir
1518 task jalviewjsEclipseCopyDropins(type: Copy) {
1519 dependsOn jalviewjsEclipsePaths
1521 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_eclipse_dropins_dir}", include: "*.jar")
1522 inputFiles += file("${jalviewDir}/${jalviewjs_j2s_plugin}")
1523 def outputDir = "${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}"
1530 // this eclipse -clean doesn't actually work
1531 task jalviewjsCleanEclipse(type: Exec) {
1532 dependsOn eclipseSetup
1533 dependsOn jalviewjsEclipsePaths
1534 dependsOn jalviewjsEclipseCopyDropins
1536 executable(eclipseBinary)
1537 args(["-nosplash", "--launcher.suppressErrors", "-data", eclipseWorkspace.getPath(), "-clean", "-console", "-consoleLog"])
1543 def inputString = """exit
1546 def inputByteStream = new ByteArrayInputStream(inputString.getBytes())
1547 standardInput = inputByteStream
1550 /* not really working yet
1551 jalviewjsEclipseCopyDropins.finalizedBy jalviewjsCleanEclipse
1555 task jalviewjsTransferUnzipSwingJs {
1556 def file_zip = "${jalviewDir}/${jalviewjs_swingjs_zip}"
1560 from zipTree(file_zip)
1561 into "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1565 inputs.file file_zip
1566 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1570 task jalviewjsTransferUnzipLib {
1571 def zipFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_libjs_dir}", include: "*.zip")
1574 zipFiles.each { file_zip ->
1576 from zipTree(file_zip)
1577 into "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1582 inputs.files zipFiles
1583 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1587 task jalviewjsTransferUnzipAllLibs {
1588 dependsOn jalviewjsTransferUnzipSwingJs
1589 dependsOn jalviewjsTransferUnzipLib
1593 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
1595 description "Create the .j2s file from the j2s.* properties"
1597 outputFile ("${jalviewDir}/${jalviewjs_j2s_settings}")
1598 def j2s_props = project.properties.findAll { it.key.startsWith("j2s.") }.sort { it.key }
1599 def siteDirProperty = "j2s.site.directory"
1600 def setSiteDir = false
1601 j2s_props.each { prop, val ->
1603 if (prop == siteDirProperty) {
1604 if (!(val.startsWith('/') || val.startsWith("file://") )) {
1605 val = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${val}"
1611 if (!setSiteDir) { // default site location, don't override specifically set property
1612 property(siteDirProperty,"${jalviewDir}/${jalviewjsTransferSiteJsDir}")
1615 inputs.properties(j2s_props)
1616 outputs.file(outputFile)
1620 task jalviewjsEclipseSetup {
1621 dependsOn jalviewjsEclipseCopyDropins
1622 dependsOn jalviewjsSetEclipseWorkspace
1623 dependsOn jalviewjsCreateJ2sSettings
1627 task jalviewjsSyncAllLibs (type: Sync) {
1628 dependsOn jalviewjsTransferUnzipAllLibs
1629 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteLibDir}")
1630 inputFiles += fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}")
1631 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1635 def outputFiles = []
1636 rename { filename ->
1637 outputFiles += "${outputDir}/${filename}"
1643 outputs.files outputFiles
1644 inputs.files inputFiles
1648 task jalviewjsSyncResources (type: Sync) {
1649 def inputFiles = fileTree(dir: "${jalviewDir}/${resourceDir}")
1650 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1654 def outputFiles = []
1655 rename { filename ->
1656 outputFiles += "${outputDir}/${filename}"
1662 outputs.files outputFiles
1663 inputs.files inputFiles
1667 task jalviewjsSyncSiteResources (type: Sync) {
1668 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_site_resource_dir}")
1669 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1673 def outputFiles = []
1674 rename { filename ->
1675 outputFiles += "${outputDir}/${filename}"
1681 outputs.files outputFiles
1682 inputs.files inputFiles
1686 task jalviewjsSyncBuildProperties (type: Sync) {
1687 dependsOn createBuildProperties
1688 def inputFiles = [file(buildProperties)]
1689 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1693 def outputFiles = []
1694 rename { filename ->
1695 outputFiles += "${outputDir}/${filename}"
1701 outputs.files outputFiles
1702 inputs.files inputFiles
1706 task jalviewjsProjectImport(type: Exec) {
1707 dependsOn eclipseSetup
1708 dependsOn jalviewjsEclipsePaths
1709 dependsOn jalviewjsEclipseSetup
1712 // do not run a headless import when we claim to be in Eclipse
1714 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1715 throw new StopExecutionException("Not running headless import whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1717 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1721 //def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
1722 def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview"
1723 executable(eclipseBinary)
1724 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
1728 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1730 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
1733 inputs.file("${jalviewDir}/.project")
1734 outputs.upToDateWhen {
1735 file(projdir).exists()
1740 task jalviewjsTranspile(type: Exec) {
1741 dependsOn jalviewjsEclipseSetup
1742 dependsOn jalviewjsProjectImport
1743 dependsOn jalviewjsEclipsePaths
1746 // do not run a headless transpile when we claim to be in Eclipse
1748 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1749 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1751 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1755 executable(eclipseBinary)
1756 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-${jalviewjs_eclipse_build_arg}", eclipse_project_name ])
1760 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1762 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
1768 stdout = new ByteArrayOutputStream()
1769 stderr = new ByteArrayOutputStream()
1771 def logOutFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}"
1772 def logOutFile = file(logOutFileName)
1773 logOutFile.createNewFile()
1774 logOutFile.text = """ROOT: ${jalviewjs_eclipse_root}
1775 BINARY: ${eclipseBinary}
1776 VERSION: ${eclipseVersion}
1777 WORKSPACE: ${eclipseWorkspace}
1778 DEBUG: ${eclipseDebug}
1781 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
1782 // combine stdout and stderr
1783 def logErrFOS = logOutFOS
1785 if (jalviewjs_j2s_to_console.equals("true")) {
1786 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1787 new org.apache.tools.ant.util.TeeOutputStream(
1791 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1792 new org.apache.tools.ant.util.TeeOutputStream(
1797 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1800 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1807 if (stdout.toString().contains("Error processing ")) {
1808 // j2s did not complete transpile
1809 //throw new TaskExecutionException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
1810 throw new GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
1814 inputs.dir("${jalviewDir}/${sourceDir}")
1815 outputs.dir("${jalviewDir}/${jalviewjsTransferSiteJsDir}")
1816 outputs.upToDateWhen( { file("${jalviewDir}/${jalviewjsTransferSiteJsDir}${jalviewjs_server_resource}").exists() } )
1820 def jalviewjsCallCore(String name, FileCollection list, String prefixFile, String suffixFile, String jsfile, String zjsfile, File logOutFile, Boolean logOutConsole) {
1822 def stdout = new ByteArrayOutputStream()
1823 def stderr = new ByteArrayOutputStream()
1825 def coreFile = file(jsfile)
1827 msg = "Creating core for ${name}...\nGenerating ${jsfile}"
1829 logOutFile.createNewFile()
1830 logOutFile.append(msg+"\n")
1832 def coreTop = file(prefixFile)
1833 def coreBottom = file(suffixFile)
1834 coreFile.getParentFile().mkdirs()
1835 coreFile.createNewFile()
1836 coreFile.write( coreTop.text )
1841 t.replaceAll("Clazz\\.([^_])","Clazz_${1}")
1842 coreFile.append( t )
1844 msg = "...file '"+f.getPath()+"' does not exist, skipping"
1846 logOutFile.append(msg+"\n")
1849 coreFile.append( coreBottom.text )
1851 msg = "Generating ${zjsfile}"
1853 logOutFile.append(msg+"\n")
1854 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
1855 def logErrFOS = logOutFOS
1858 classpath = files(["${jalviewDir}/tools/closure_compiler.jar"])
1859 args = [ "--js", jsfile, "--js_output_file", zjsfile ]
1861 msg = "\nRunning '"+commandLine.join(' ')+"'\n"
1863 logOutFile.append(msg+"\n")
1865 if (logOutConsole) {
1866 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1867 new org.apache.tools.ant.util.TeeOutputStream(
1871 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1872 new org.apache.tools.ant.util.TeeOutputStream(
1877 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1880 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1887 logOutFile.append(msg+"\n")
1891 task jalviewjsBuildAllCores {
1893 description "Build the core js lib closures listed in the classlists dir"
1894 dependsOn jalviewjsTranspile
1895 dependsOn jalviewjsTransferUnzipSwingJs
1897 def j2sDir = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${jalviewjs_j2s_subdir}"
1898 def swingJ2sDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${jalviewjs_j2s_subdir}"
1899 def libJ2sDir = "${jalviewDir}/${jalviewjsTransferSiteLibDir}/${jalviewjs_j2s_subdir}"
1900 def jsDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${jalviewjs_js_subdir}"
1901 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}/${jalviewjs_j2s_subdir}/core"
1902 def prefixFile = "${jsDir}/core/coretop2.js"
1903 def suffixFile = "${jsDir}/core/corebottom2.js"
1905 inputs.file prefixFile
1906 inputs.file suffixFile
1908 def classlistFiles = []
1909 // add the classlists found int the jalviewjs_classlists_dir
1910 fileTree(dir: "${jalviewDir}/${jalviewjs_classlists_dir}", include: "*.txt").each {
1912 def name = file.getName() - ".txt"
1919 // _jmol and _jalview cores. Add any other peculiar classlist.txt files here
1920 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jmol}"), 'name': "_jvjmol" ]
1921 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jalview}"), 'name': jalviewjsJalviewCoreName ]
1923 jalviewjsCoreClasslists = []
1925 classlistFiles.each {
1928 def file = hash['file']
1929 if (! file.exists()) {
1930 println("...classlist file '"+file.getPath()+"' does not exist, skipping")
1931 return false // this is a "continue" in groovy .each closure
1933 def name = hash['name']
1935 name = file.getName() - ".txt"
1943 def list = fileTree(dir: j2sDir, includes: filelist)
1945 def jsfile = "${outputDir}/core${name}.js"
1946 def zjsfile = "${outputDir}/core${name}.z.js"
1948 jalviewjsCoreClasslists += [
1957 outputs.file(jsfile)
1958 outputs.file(zjsfile)
1961 // _stevesoft core. add any cores without a classlist here (and the inputs and outputs)
1962 def stevesoftClasslistName = "_stevesoft"
1963 def stevesoftClasslist = [
1964 'jsfile': "${outputDir}/core${stevesoftClasslistName}.js",
1965 'zjsfile': "${outputDir}/core${stevesoftClasslistName}.z.js",
1966 'list': fileTree(dir: j2sDir, include: "com/stevesoft/pat/**/*.js"),
1967 'name': stevesoftClasslistName
1969 jalviewjsCoreClasslists += stevesoftClasslist
1970 inputs.files(stevesoftClasslist['list'])
1971 outputs.file(stevesoftClasslist['jsfile'])
1972 outputs.file(stevesoftClasslist['zjsfile'])
1975 def allClasslistName = "_all"
1976 def allJsFiles = fileTree(dir: j2sDir, include: "**/*.js")
1977 //allJsFiles += fileTree(dir: libJ2sDir, include: "**/*.js")
1978 //allJsFiles += fileTree(dir: swingJ2sDir, include: "**/*.js")
1979 def allClasslist = [
1980 'jsfile': "${outputDir}/core${allClasslistName}.js",
1981 'zjsfile': "${outputDir}/core${allClasslistName}.z.js",
1983 'name': allClasslistName
1985 jalviewjsCoreClasslists += allClasslist
1986 inputs.files(allClasslist['list'])
1987 outputs.file(allClasslist['jsfile'])
1988 outputs.file(allClasslist['zjsfile'])
1991 def logOutFile = file("${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_closure_stdout}")
1992 logOutFile.getParentFile().mkdirs()
1993 logOutFile.createNewFile()
1994 logOutFile.write(getDate("yyyy-MM-dd HH:mm:ss")+" jalviewjsBuildAllCores\n----\n")
1996 jalviewjsCoreClasslists.each {
1997 jalviewjsCallCore(it.name, it.list, prefixFile, suffixFile, it.jsfile, it.zjsfile, logOutFile, jalviewjs_j2s_to_console.equals("true"))
2004 def jalviewjsPublishCoreTemplate(String coreName, String templateName, File inputFile, String outputFile) {
2007 into file(outputFile).getParentFile()
2008 rename { filename ->
2009 if (filename.equals(inputFile.getName())) {
2010 return file(outputFile).getName()
2014 filter(ReplaceTokens,
2018 'MAIN': '"'+mainClass+'"',
2020 'NAME': jalviewjsJalviewTemplateName+" [core ${coreName}]",
2021 'COREKEY': jalviewjs_core_key,
2022 'CORENAME': coreName
2029 task jalviewjsPublishCoreTemplates {
2030 dependsOn jalviewjsBuildAllCores
2031 def inputFileName = "${jalviewDir}/${j2s_coretemplate_html}"
2032 def inputFile = file(inputFileName)
2033 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
2035 def outputFiles = []
2036 jalviewjsCoreClasslists.each { cl ->
2037 def outputFile = "${outputDir}/${jalviewjsJalviewTemplateName}_${cl.name}.html"
2038 cl['outputfile'] = outputFile
2039 outputFiles += outputFile
2043 jalviewjsCoreClasslists.each { cl ->
2044 jalviewjsPublishCoreTemplate(cl.name, jalviewjsJalviewTemplateName, inputFile, cl.outputfile)
2047 inputs.file(inputFile)
2048 outputs.files(outputFiles)
2052 task jalviewjsSyncCore (type: Sync) {
2053 dependsOn jalviewjsBuildAllCores
2054 dependsOn jalviewjsPublishCoreTemplates
2055 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteCoreDir}")
2056 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
2060 def outputFiles = []
2061 rename { filename ->
2062 outputFiles += "${outputDir}/${filename}"
2068 outputs.files outputFiles
2069 inputs.files inputFiles
2073 // this Copy version of TransferSiteJs will delete anything else in the target dir
2074 task jalviewjsCopyTransferSiteJs(type: Copy) {
2075 dependsOn jalviewjsTranspile
2076 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2077 into "${jalviewDir}/${jalviewjsSiteDir}"
2081 // this Sync version of TransferSite is used by buildship to keep the website automatically up to date when a file changes
2082 task jalviewjsSyncTransferSiteJs(type: Sync) {
2083 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2085 into "${jalviewDir}/${jalviewjsSiteDir}"
2092 jalviewjsSyncAllLibs.mustRunAfter jalviewjsCopyTransferSiteJs
2093 jalviewjsSyncResources.mustRunAfter jalviewjsCopyTransferSiteJs
2094 jalviewjsSyncSiteResources.mustRunAfter jalviewjsCopyTransferSiteJs
2095 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsCopyTransferSiteJs
2097 jalviewjsSyncAllLibs.mustRunAfter jalviewjsSyncTransferSiteJs
2098 jalviewjsSyncResources.mustRunAfter jalviewjsSyncTransferSiteJs
2099 jalviewjsSyncSiteResources.mustRunAfter jalviewjsSyncTransferSiteJs
2100 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsSyncTransferSiteJs
2103 task jalviewjsPrepareSite {
2105 description "Prepares the website folder including unzipping files and copying resources"
2106 dependsOn jalviewjsSyncAllLibs
2107 dependsOn jalviewjsSyncResources
2108 dependsOn jalviewjsSyncSiteResources
2109 dependsOn jalviewjsSyncBuildProperties
2110 dependsOn jalviewjsSyncCore
2114 task jalviewjsBuildSite {
2116 description "Builds the whole website including transpiled code"
2117 dependsOn jalviewjsCopyTransferSiteJs
2118 dependsOn jalviewjsPrepareSite
2122 task cleanJalviewjsSite {
2124 delete "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2125 delete "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
2126 delete "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
2127 delete "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
2128 delete "${jalviewDir}/${jalviewjsSiteDir}"
2133 task jalviewjsSiteTar(type: Tar) {
2135 description "Creates a tar.gz file for the website"
2136 dependsOn jalviewjsBuildSite
2137 def outputFilename = "jalviewjs-site-${JALVIEW_VERSION}.tar.gz"
2139 archiveFileName = outputFilename
2140 } catch (Exception e) {
2141 archiveName = outputFilename
2144 compression Compression.GZIP
2146 from "${jalviewDir}/${jalviewjsSiteDir}"
2147 into jalviewjs_site_dir // this is inside the tar file
2149 inputs.dir("${jalviewDir}/${jalviewjsSiteDir}")
2153 task jalviewjsServer {
2155 def filename = "jalviewjsTest.html"
2156 description "Starts a webserver on localhost to test the website. See ${filename} to access local site on most recently used port."
2157 def htmlFile = "${jalviewDirAbsolutePath}/${filename}"
2160 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
2161 def port = Integer.valueOf(jalviewjs_server_port)
2166 while(port < start+1000 && !running) {
2168 def doc_root = new File("${jalviewDirAbsolutePath}/${jalviewjsSiteDir}")
2169 jalviewjsServer = factory.start(doc_root, port)
2171 url = jalviewjsServer.getResourceUrl(jalviewjs_server_resource)
2172 println("SERVER STARTED with document root ${doc_root}.")
2173 println("Go to "+url+" . Run gradle --stop to stop (kills all gradle daemons).")
2174 println("For debug: "+url+"?j2sdebug")
2175 println("For verbose: "+url+"?j2sverbose")
2176 } catch (Exception e) {
2181 <p><a href="${url}">JalviewJS Test. <${url}></a></p>
2182 <p><a href="${url}?j2sdebug">JalviewJS Test with debug. <${url}?j2sdebug<</a></p>
2184 jalviewjsCoreClasslists.each { cl ->
2185 def urlcore = jalviewjsServer.getResourceUrl(file(cl.outputfile).getName())
2187 <p><a href="${urlcore}">${jalviewjsJalviewTemplateName} [core ${cl.name}]. <${urlcore}></a></p>
2189 println("For core ${cl.name}: "+urlcore)
2192 file(htmlFile).text = htmlText
2195 outputs.file(htmlFile)
2196 outputs.upToDateWhen({false})
2200 task cleanJalviewjsAll {
2202 description "Delete all configuration and build artifacts to do with JalviewJS build"
2203 dependsOn cleanJalviewjsSite
2204 dependsOn jalviewjsEclipsePaths
2207 delete "${jalviewDir}/${jalviewjsBuildDir}"
2208 delete "${jalviewDir}/${eclipse_bin_dir}"
2209 if (eclipseWorkspace != null && file(eclipseWorkspace.getAbsolutePath()+"/.metadata").exists()) {
2210 delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata")
2212 delete "${jalviewDir}/${jalviewjs_j2s_settings}"
2215 outputs.upToDateWhen( { false } )
2220 task jalviewjsIDE_j2sFile {
2221 group "00 JalviewJS in Eclipse"
2222 description "Creates the .j2s file"
2223 dependsOn jalviewjsCreateJ2sSettings
2227 task jalviewjsIDE_SyncCore {
2228 group "00 JalviewJS in Eclipse"
2229 description "Build the core js lib closures listed in the classlists dir and publish core html from template"
2230 dependsOn jalviewjsSyncCore
2234 task jalviewjsIDE_PrepareSite {
2235 group "00 JalviewJS in Eclipse"
2236 description "Sync libs and resources to site dir, but not closure cores"
2237 dependsOn jalviewjsSyncAllLibs
2238 dependsOn jalviewjsSyncResources
2239 dependsOn jalviewjsSyncSiteResources
2240 dependsOn jalviewjsSyncBuildProperties
2244 task jalviewjsIDE_AssembleSite {
2245 group "00 JalviewJS in Eclipse"
2246 description "Assembles unzipped supporting zipfiles, resources, site resources and closure cores into the Eclipse transpiled site"
2247 dependsOn jalviewjsPrepareSite
2251 task jalviewjsIDE_SiteClean {
2252 group "00 JalviewJS in Eclipse"
2253 description "Deletes the Eclipse transpiled site"
2254 dependsOn cleanJalviewjsSite
2258 task jalviewjsIDE_Server {
2259 group "00 JalviewJS in Eclipse"
2260 description "Starts a webserver on localhost to test the website"
2261 dependsOn jalviewjsServer
2265 // buildship runs this at import
2266 task eclipseConfiguration {
2267 dependsOn eclipseSetup
2268 dependsOn jalviewjsIDE_j2sFile
2272 // buildship runs this at build time
2273 task eclipseAutoBuildTask {
2274 dependsOn jalviewjsIDE_PrepareSite
2286 description "Build the site"
2287 dependsOn jalviewjsBuildSite