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
5 import java.security.MessageDigest
6 import groovy.transform.ExternalizeMethods
7 import groovy.util.XmlParser
8 import groovy.xml.XmlUtil
17 classpath 'org.openclover:clover:4.4.1'
26 id 'com.github.johnrengelman.shadow' version '4.0.3'
27 id 'com.install4j.gradle' version '8.0.4'
28 id 'com.dorongold.task-tree' version '1.5' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree
38 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
39 def string(Object o) {
40 return o == null ? "" : o.toString()
45 jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
46 jalviewDirRelativePath = jalviewDir
48 // local build environment properties
49 // can be "projectDir/local.properties"
50 def localProps = "${projectDir}/local.properties"
52 if (file(localProps).exists()) {
53 propsFile = localProps
55 // or "../projectDir_local.properties"
56 def dirLocalProps = projectDir.getParent() + "/" + projectDir.getName() + "_local.properties"
57 if (file(dirLocalProps).exists()) {
58 propsFile = dirLocalProps
60 if (propsFile != null) {
62 def p = new Properties()
63 def localPropsFIS = new FileInputStream(propsFile)
68 def oldval = findProperty(key)
71 println("Overriding property '${key}' ('${oldval}') with ${file(propsFile).getName()} value '${val}'")
73 println("Setting unknown property '${key}' with ${file(propsFile).getName()}s value '${val}'")
76 } catch (Exception e) {
77 System.out.println("Exception reading local.properties")
81 // this property set when running Eclipse headlessly
82 j2sHeadlessBuildProperty = string("net.sf.j2s.core.headlessbuild")
83 // this property set by Eclipse
84 eclipseApplicationProperty = string("eclipse.application")
85 // CHECK IF RUNNING FROM WITHIN ECLIPSE
86 def eclipseApplicationPropertyVal = System.properties[eclipseApplicationProperty]
87 IN_ECLIPSE = eclipseApplicationPropertyVal != null && eclipseApplicationPropertyVal.startsWith("org.eclipse.ui.")
88 // BUT WITHOUT THE HEADLESS BUILD PROPERTY SET
89 if (System.properties[j2sHeadlessBuildProperty].equals("true")) {
90 println("Setting IN_ECLIPSE to ${IN_ECLIPSE} as System.properties['${j2sHeadlessBuildProperty}'] == '${System.properties[j2sHeadlessBuildProperty]}'")
94 println("WITHIN ECLIPSE IDE")
96 println("HEADLESS BUILD")
99 J2S_ENABLED = (project.hasProperty('j2s.compiler.status') && project['j2s.compiler.status'] != null && project['j2s.compiler.status'] == "enable")
101 println("J2S ENABLED")
105 System.properties.sort { it.key }.each {
106 key, val -> println("SYSTEM PROPERTY ${key}='${val}'")
109 if (false && IN_ECLIPSE) {
110 jalviewDir = jalviewDirAbsolutePath
115 bareSourceDir = string(source_dir)
116 sourceDir = string("${jalviewDir}/${bareSourceDir}")
117 resourceDir = string("${jalviewDir}/${resource_dir}")
118 bareTestSourceDir = string(test_source_dir)
119 testSourceDir = string("${jalviewDir}/${bareTestSourceDir}")
122 cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
123 cloverDb = string("${buildDir}/clover/clover.db")
124 classesDir = string("${jalviewDir}/${classes_dir}")
125 if (clover.equals("true")) {
127 classesDir = string("${buildDir}/${cloverClassesDir}")
130 classesDir = string("${jalviewDir}/${classes_dir}")
135 getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
138 // the following values might be overridden by the CHANNEL switch
139 getdownChannelName = CHANNEL.toLowerCase()
140 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
141 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
142 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
143 getdownAppDistDir = getdown_app_dir_alt
144 buildProperties = string("${resourceDir}/${build_properties_file}")
145 reportRsyncCommand = false
146 jvlChannelName = CHANNEL.toLowerCase()
150 // TODO: get bamboo build artifact URL for getdown artifacts
151 getdown_channel_base = bamboo_channelbase
152 getdownChannelName = string("${bamboo_planKey}/${JAVA_VERSION}")
153 getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
154 jvlChannelName += "_${getdownChannelName}"
155 // automatically add the test group Not-bamboo for exclusion
156 if ("".equals(testngExcludedGroups)) {
157 testngExcludedGroups = "Not-bamboo"
162 getdownAppDistDir = getdown_app_dir_release
163 reportRsyncCommand = true
164 // Don't ignore transpile errors for release build
165 if (jalviewjs_ignore_transpile_errors.equals("true")) {
166 jalviewjs_ignore_transpile_errors = "false"
167 println("Setting jalviewjs_ignore_transpile_errors to 'false'")
172 getdownChannelName = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
173 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
174 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
175 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
176 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
178 packageDir = string("${ARCHIVEDIR}/${packageDir}")
179 buildProperties = string("${buildDir}/archive/${build_properties_file}")
182 reportRsyncCommand = true
186 getdownChannelName = string("archive/${JALVIEW_VERSION}")
187 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
188 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
189 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
190 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
192 packageDir = string("${ARCHIVEDIR}/${packageDir}")
193 buildProperties = string("${buildDir}/archive/${build_properties_file}")
196 reportRsyncCommand = true
197 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
201 reportRsyncCommand = true
205 reportRsyncCommand = true
206 // Don't ignore transpile errors for release build
207 if (jalviewjs_ignore_transpile_errors.equals("true")) {
208 jalviewjs_ignore_transpile_errors = "false"
209 println("Setting jalviewjs_ignore_transpile_errors to 'false'")
213 case ~/^SCRATCH(|-[-\w]*)$/:
214 getdownChannelName = CHANNEL
215 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
216 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
217 reportRsyncCommand = true
221 if (!file("${LOCALDIR}").exists()) {
222 throw new GradleException("Must provide a LOCALDIR value to produce a local distribution")
224 getdownAppBase = file(file("${LOCALDIR}").getAbsolutePath()).toURI().toString()
225 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
230 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
231 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
234 default: // something wrong specified
235 throw new GradleException("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
239 // override getdownAppBase if requested
240 if (findProperty("getdown_appbase_override") != null) {
241 getdownAppBase = string(getProperty("getdown_appbase_override"))
242 println("Overriding getdown appbase with '${getdownAppBase}'")
244 // sanitise file name for jalview launcher file for this channel
245 jvlChannelName = jvlChannelName.replaceAll(/[^\w\-]/,"_")
247 getdownAppDir = string("${getdownWebsiteDir}/${getdownAppDistDir}")
248 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
249 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
250 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
251 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
252 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
253 /* compile without modules -- using classpath libraries
254 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
255 modules_runtimeClasspath = modules_compileClasspath
258 gitBranch = string("")
260 println("Using a ${CHANNEL} profile.")
262 additional_compiler_args = []
263 // configure classpath/args for j8/j11 compilation
264 if (JAVA_VERSION.equals("1.8")) {
265 JAVA_INTEGER_VERSION = string("8")
268 libDistDir = j8libDir
269 compile_source_compatibility = 1.8
270 compile_target_compatibility = 1.8
271 // these are getdown.txt properties defined dependent on the JAVA_VERSION
272 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java8_min_version"))
273 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java8_max_version"))
274 // this property is assigned below and expanded to multiple lines in the getdown task
275 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java8_txt_multi_java_location"))
276 // this property is for the Java library used in eclipse
277 eclipseJavaRuntimeName = string("JavaSE-1.8")
278 } else if (JAVA_VERSION.equals("11")) {
279 JAVA_INTEGER_VERSION = string("11")
281 libDistDir = j11libDir
282 compile_source_compatibility = 11
283 compile_target_compatibility = 11
284 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
285 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
286 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
287 eclipseJavaRuntimeName = string("JavaSE-11")
288 /* compile without modules -- using classpath libraries
289 additional_compiler_args += [
290 '--module-path', modules_compileClasspath.asPath,
291 '--add-modules', j11modules
294 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
295 JAVA_INTEGER_VERSION = JAVA_VERSION
297 libDistDir = j11libDir
298 compile_source_compatibility = JAVA_VERSION
299 compile_target_compatibility = JAVA_VERSION
300 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
301 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
302 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
303 eclipseJavaRuntimeName = string("JavaSE-11")
304 /* compile without modules -- using classpath libraries
305 additional_compiler_args += [
306 '--module-path', modules_compileClasspath.asPath,
307 '--add-modules', j11modules
311 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
316 JAVA_MIN_VERSION = JAVA_VERSION
317 JAVA_MAX_VERSION = JAVA_VERSION
318 def jreInstallsDir = string(jre_installs_dir)
319 if (jreInstallsDir.startsWith("~/")) {
320 jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
322 macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
323 macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-mac-x64.tar.gz")
324 windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
325 windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-windows-x64.tar.gz")
326 linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
327 linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-linux-x64.tar.gz")
328 install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
329 install4jConfFileName = string("jalview-install4j-conf.install4j")
330 install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
331 install4jHomeDir = install4j_home_dir
332 if (install4jHomeDir.startsWith("~/")) {
333 install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
338 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
339 helpFile = string("${classesDir}/${help_dir}/help.jhm")
340 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
341 helpSourceDir = string("${helpParentDir}/${help_dir}")
344 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
345 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
346 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
348 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
350 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
352 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
353 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
354 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
355 jalviewjsJalviewCoreHtmlFile = string("")
356 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
357 jalviewjsCoreClasslists = []
358 jalviewjsJalviewTemplateName = string(jalviewjs_name)
359 jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
360 jalviewjsJ2sProps = null
361 jalviewjsJ2sPlugin = jalviewjs_j2s_plugin
363 eclipseWorkspace = null
364 eclipseBinary = string("")
365 eclipseVersion = string("")
375 outputDir = file(classesDir)
380 srcDirs += helpParentDir
383 jar.destinationDir = file("${jalviewDir}/${packageDir}")
385 compileClasspath = files(sourceSets.main.java.outputDir)
386 //compileClasspath += files(sourceSets.main.resources.srcDirs)
387 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
389 runtimeClasspath = compileClasspath
394 srcDirs = [ cloverInstrDir ]
395 outputDir = file("${buildDir}/${cloverClassesDir}")
399 srcDirs = sourceSets.main.resources.srcDirs
401 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
402 compileClasspath += files(sourceSets.main.java.outputDir)
403 compileClasspath += sourceSets.main.compileClasspath
404 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
405 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
407 runtimeClasspath = compileClasspath
412 srcDirs testSourceDir
413 outputDir = file("${jalviewDir}/${testOutputDir}")
417 srcDirs = sourceSets.main.resources.srcDirs
420 compileClasspath = files( sourceSets.test.java.outputDir )
423 compileClasspath = sourceSets.clover.compileClasspath
425 compileClasspath += files(sourceSets.main.java.outputDir)
428 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
429 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
430 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
432 runtimeClasspath = compileClasspath
440 cloverCompile 'org.openclover:clover:4.4.1'
441 testCompile 'org.openclover:clover:4.4.1'
448 cloverRuntime.extendsFrom cloverCompile
452 // eclipse project and settings files creation, also used by buildship
455 name = eclipse_project_name
457 natures 'org.eclipse.jdt.core.javanature',
458 'org.eclipse.jdt.groovy.core.groovyNature',
459 'org.eclipse.buildship.core.gradleprojectnature'
461 buildCommand 'org.eclipse.jdt.core.javabuilder'
462 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
466 //defaultOutputDir = sourceSets.main.java.outputDir
469 if (it.isCanBeResolved()) {
474 minusConfigurations += removeThese
475 plusConfigurations = [ ]
479 def removeTheseToo = []
480 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
481 cp.entries.each { entry ->
482 // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
483 // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
484 // we add the resources and help/help dirs in as libs afterwards (see below)
485 if (entry.kind == 'src') {
486 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
487 removeTheseToo += entry
489 alreadyAddedSrcPath.putAt(entry.path, true)
494 cp.entries.removeAll(removeTheseToo)
496 //cp.entries += new Output("${eclipse_bin_dir}/main")
497 if (file(helpParentDir).isDirectory()) {
498 cp.entries += new Library(fileReference(helpParentDir))
500 if (file(resourceDir).isDirectory()) {
501 cp.entries += new Library(fileReference(resourceDir))
504 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
506 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
507 //don't want to add outputDir as eclipse is using its own output dir in bin/main
508 if (it.isDirectory() || ! it.exists()) {
509 // don't add dirs to classpath, especially if they don't exist
510 return false // groovy "continue" in .any closure
512 def itPath = it.toString()
513 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
514 // make relative path
515 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
517 if (alreadyAddedLibPath.get(itPath)) {
518 //println("Not adding duplicate entry "+itPath)
520 //println("Adding entry "+itPath)
521 cp.entries += new Library(fileReference(itPath))
522 alreadyAddedLibPath.put(itPath, true)
526 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
527 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
528 if (it.isDirectory() || ! it.exists()) {
529 // don't add dirs to classpath
530 return false // groovy "continue" in .any closure
533 def itPath = it.toString()
534 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
535 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
537 if (alreadyAddedLibPath.get(itPath)) {
540 def lib = new Library(fileReference(itPath))
541 lib.entryAttributes["test"] = "true"
543 alreadyAddedLibPath.put(itPath, true)
551 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
556 // for the IDE, use java 11 compatibility
557 sourceCompatibility = compile_source_compatibility
558 targetCompatibility = compile_target_compatibility
559 javaRuntimeName = eclipseJavaRuntimeName
561 // add in jalview project specific properties/preferences into eclipse core preferences
562 // and also the codestyle XML file
564 withProperties { props ->
565 def jalview_prefs = new Properties()
566 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
567 jalview_prefs.load(ins)
569 jalview_prefs.forEach { t, v ->
570 if (props.getAt(t) == null) {
574 // codestyle file -- overrides previous formatter prefs
575 def csFile = file("${jalviewDirAbsolutePath}/${eclipse_codestyle_file}")
576 if (csFile.exists()) {
577 XmlParser parser = new XmlParser()
578 def profiles = parser.parse(csFile)
579 def profile = profiles.'profile'.find { p -> (p.'@kind' == "CodeFormatterProfile" && p.'@name' == "Jalview") }
580 if (profile != null) {
581 profile.'setting'.each { s ->
583 def value = s.'@value'
584 if (id != null && value != null) {
585 props.putAt(id, value)
596 // Don't want these to be activated if in headless build
597 synchronizationTasks "eclipseSynchronizationTask"
598 //autoBuildTasks "eclipseAutoBuildTask"
605 // only instrument source, we build test classes as normal
606 inputs.files files (sourceSets.main.allJava,sourceSets.test.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
607 outputs.dir cloverInstrDir
610 delete cloverInstrDir
615 cloverInstrDir.getPath(),
618 inputs.files.files.collect(
619 { file -> file.absolutePath }
622 String[] args = argsList.toArray()
623 println("About to instrument "+args.length +" files")
624 com.atlassian.clover.CloverInstr.mainImpl(args)
629 cloverClasses.dependsOn cloverInstr
633 group = "Verification"
634 description = "Creates the Clover report"
635 inputs.dir "${buildDir}/clover"
636 outputs.dir "${reportsDir}/clover"
638 file(cloverDb).exists()
645 "${reportsDir}/clover"
647 String[] args = argsList.toArray()
648 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
650 // and generate ${reportsDir}/clover/clover.xml
655 "${reportsDir}/clover/clover.xml"
657 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
665 sourceCompatibility = compile_source_compatibility
666 targetCompatibility = compile_target_compatibility
667 options.compilerArgs += additional_compiler_args
668 print ("Setting target compatibility to "+targetCompatibility+"\n")
670 classpath += configurations.cloverRuntime
676 delete cloverInstrDir
686 sourceCompatibility = compile_source_compatibility
687 targetCompatibility = compile_target_compatibility
688 options.compilerArgs = additional_compiler_args
689 print ("Setting target compatibility to "+targetCompatibility+"\n")
697 dependsOn compileCloverJava
698 classpath += configurations.cloverRuntime
700 classpath += sourceSets.main.runtimeClasspath
703 sourceCompatibility = compile_source_compatibility
704 targetCompatibility = compile_target_compatibility
705 options.compilerArgs = additional_compiler_args
706 print ("Setting target compatibility to "+targetCompatibility+"\n")
713 delete sourceSets.main.java.outputDir
719 dependsOn cleanClover
721 delete sourceSets.test.java.outputDir
726 // format is a string like date.format("dd MMMM yyyy")
727 def getDate(format) {
728 def date = new Date()
729 return date.format(format)
734 def hashStdOut = new ByteArrayOutputStream()
736 commandLine "git", "rev-parse", "--short", "HEAD"
737 standardOutput = hashStdOut
741 def branchStdOut = new ByteArrayOutputStream()
743 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
744 standardOutput = branchStdOut
748 gitHash = hashStdOut.toString().trim()
749 gitBranch = branchStdOut.toString().trim()
751 outputs.upToDateWhen { false }
755 task createBuildProperties(type: WriteProperties) {
757 description = "Create the ${buildProperties} file"
759 inputs.dir(sourceDir)
760 inputs.dir(resourceDir)
761 file(buildProperties).getParentFile().mkdirs()
762 outputFile (buildProperties)
763 // taking time specific comment out to allow better incremental builds
764 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
765 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
766 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
767 property "VERSION", JALVIEW_VERSION
768 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
769 outputs.file(outputFile)
775 delete buildProperties
780 task cleanBuildingHTML(type: Delete) {
787 task convertBuildingMD(type: Exec) {
788 dependsOn cleanBuildingHTML
789 def buildingMD = "${jalviewDir}/${docDir}/building.md"
790 def css = "${jalviewDir}/${docDir}/github.css"
793 pandoc_exec.split(",").each {
794 if (file(it.trim()).exists()) {
800 def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
801 if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
802 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
806 if (pandoc != null && file(pandoc).exists()) {
807 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
809 println("Cannot find pandoc. Skipping convert building.md to HTML")
810 throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
816 inputs.file(buildingMD)
818 outputs.file(buildingHTML)
829 task syncDocs(type: Sync) {
830 dependsOn convertBuildingMD
831 def syncDir = "${classesDir}/${docDir}"
832 from fileTree("${jalviewDir}/${docDir}")
838 task copyHelp(type: Copy) {
839 def inputDir = helpSourceDir
840 def outputDir = "${classesDir}/${help_dir}"
845 filter(ReplaceTokens,
849 'Version-Rel': JALVIEW_VERSION,
850 'Year-Rel': getDate("yyyy")
862 outputs.files(helpFile)
863 outputs.dir(outputDir)
867 task syncLib(type: Sync) {
868 def syncDir = "${classesDir}/${libDistDir}"
869 from fileTree("${jalviewDir}/${libDistDir}")
874 task syncResources(type: Sync) {
875 dependsOn createBuildProperties
886 dependsOn syncResources
892 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
895 dependsOn compileJava
897 dependsOn cloverInstr
901 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
905 includeGroups testngGroups
906 excludeGroups testngExcludedGroups
908 useDefaultListeners=true
911 maxHeapSize = "1024m"
913 workingDir = jalviewDir
914 //systemProperties 'clover.jar' System.properties.clover.jar
915 sourceCompatibility = compile_source_compatibility
916 targetCompatibility = compile_target_compatibility
917 jvmArgs += additional_compiler_args
922 task buildIndices(type: JavaExec) {
924 classpath = sourceSets.main.compileClasspath
925 main = "com.sun.java.help.search.Indexer"
926 workingDir = "${classesDir}/${help_dir}"
929 inputs.dir("${workingDir}/${argDir}")
931 outputs.dir("${classesDir}/doc")
932 outputs.dir("${classesDir}/help")
933 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
934 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
935 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
936 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
937 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
938 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
942 task compileLinkCheck(type: JavaCompile) {
944 classpath = files("${jalviewDir}/${utilsDir}")
945 destinationDir = file("${jalviewDir}/${utilsDir}")
946 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
948 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
949 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
950 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
951 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
955 task linkCheck(type: JavaExec) {
956 dependsOn prepare, compileLinkCheck
958 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
959 classpath = files("${jalviewDir}/${utilsDir}")
960 main = "HelpLinksChecker"
961 workingDir = jalviewDir
962 args = [ "${classesDir}/${help_dir}", "-nointernet" ]
964 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
966 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
969 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
973 inputs.dir("${classesDir}/${help_dir}")
974 outputs.file(helpLinksCheckerOutFile)
977 // import the pubhtmlhelp target
978 ant.properties.basedir = "${jalviewDir}"
979 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
980 ant.importBuild "${utilsDir}/publishHelp.xml"
983 task cleanPackageDir(type: Delete) {
985 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
992 dependsOn buildIndices
993 dependsOn createBuildProperties
996 attributes "Main-Class": mainClass,
997 "Permissions": "all-permissions",
998 "Application-Name": "Jalview Desktop",
999 "Codebase": application_codebase
1002 destinationDir = file("${jalviewDir}/${packageDir}")
1003 archiveName = rootProject.name+".jar"
1009 exclude "**/*.jar.*"
1011 inputs.dir(classesDir)
1012 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
1016 task copyJars(type: Copy) {
1017 from fileTree(dir: classesDir, include: "**/*.jar").files
1018 into "${jalviewDir}/${packageDir}"
1022 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
1023 task syncJars(type: Sync) {
1024 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
1025 into "${jalviewDir}/${packageDir}"
1027 include jar.archiveName
1034 description = "Put all required libraries in dist"
1035 // order of "cleanPackageDir", "copyJars", "jar" important!
1036 jar.mustRunAfter cleanPackageDir
1037 syncJars.mustRunAfter cleanPackageDir
1038 dependsOn cleanPackageDir
1041 outputs.dir("${jalviewDir}/${packageDir}")
1046 dependsOn cleanPackageDir
1052 group = "distribution"
1056 from ("${jalviewDir}/${libDistDir}") {
1060 attributes 'Implementation-Version': JALVIEW_VERSION
1062 mainClassName = shadowJarMainClass
1064 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
1069 task getdownWebsite() {
1070 group = "distribution"
1071 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
1076 def getdownWebsiteResourceFilenames = []
1077 def getdownTextString = ""
1078 def getdownResourceDir = getdownResourceDir
1079 def getdownResourceFilenames = []
1082 // clean the getdown website and files dir before creating getdown folders
1083 delete getdownWebsiteDir
1084 delete getdownFilesDir
1087 from buildProperties
1088 rename(build_properties_file, getdown_build_properties)
1091 getdownWebsiteResourceFilenames += "${getdownAppDistDir}/${getdown_build_properties}"
1093 // go through properties looking for getdown_txt_...
1094 def props = project.properties.sort { it.key }
1095 if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
1096 props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
1098 if (getdownAltJavaMaxVersion != null && getdownAltJavaMaxVersion.length() > 0) {
1099 props.put("getdown_txt_java_max_version", getdownAltJavaMaxVersion)
1101 if (getdownAltMultiJavaLocation != null && getdownAltMultiJavaLocation.length() > 0) {
1102 props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
1105 props.put("getdown_txt_appbase", getdownAppBase)
1106 props.each{ prop, val ->
1107 if (prop.startsWith("getdown_txt_") && val != null) {
1108 if (prop.startsWith("getdown_txt_multi_")) {
1109 def key = prop.substring(18)
1110 val.split(",").each{ v ->
1111 def line = "${key} = ${v}\n"
1112 getdownTextString += line
1115 // file values rationalised
1116 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1118 if (val.indexOf('/') == 0) {
1121 } else if (val.indexOf('/') > 0) {
1122 // relative path (relative to jalviewDir)
1123 r = file( "${jalviewDir}/${val}" )
1126 val = "${getdown_resource_dir}/" + r.getName()
1127 getdownWebsiteResourceFilenames += val
1128 getdownResourceFilenames += r.getPath()
1131 if (! prop.startsWith("getdown_txt_resource")) {
1132 def line = prop.substring(12) + " = ${val}\n"
1133 getdownTextString += line
1139 getdownWebsiteResourceFilenames.each{ filename ->
1140 getdownTextString += "resource = ${filename}\n"
1142 getdownResourceFilenames.each{ filename ->
1145 into getdownResourceDir
1150 fileTree(file(packageDir)).each{ f ->
1151 if (f.isDirectory()) {
1152 def files = fileTree(dir: f, include: ["*"]).getFiles()
1154 } else if (f.exists()) {
1158 codeFiles.sort().each{f ->
1159 def name = f.getName()
1160 def line = "code = ${getdownAppDistDir}/${name}\n"
1161 getdownTextString += line
1168 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1170 if (JAVA_VERSION.equals("11")) {
1171 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1172 j11libFiles.sort().each{f ->
1173 def name = f.getName()
1174 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1175 getdownTextString += line
1178 into getdownJ11libDir
1184 // 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.
1185 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1186 getdownTextString += "resource = ${getdown_launcher_new}\n"
1187 getdownTextString += "class = ${mainClass}\n"
1189 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1190 getdown_txt.write(getdownTextString)
1192 def getdownLaunchJvl = getdown_launch_jvl_name + ( (jvlChannelName != null && jvlChannelName.length() > 0)?"-${jvlChannelName}":"" ) + ".jvl"
1193 def launchJvl = file("${getdownWebsiteDir}/${getdownLaunchJvl}")
1194 launchJvl.write("appbase="+props.get("getdown_txt_appbase"))
1197 from getdownLauncher
1198 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1199 into getdownWebsiteDir
1203 from getdownLauncher
1204 if (file(getdownLauncher).getName() != getdown_launcher) {
1205 rename(file(getdownLauncher).getName(), getdown_launcher)
1207 into getdownWebsiteDir
1210 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1213 from getdownLauncher
1214 from "${getdownWebsiteDir}/${getdown_build_properties}"
1215 if (file(getdownLauncher).getName() != getdown_launcher) {
1216 rename(file(getdownLauncher).getName(), getdown_launcher)
1218 into getdownInstallDir
1222 from getdownInstallDir
1223 into getdownFilesInstallDir
1230 from getdownLauncher
1231 from "${getdownWebsiteDir}/${getdown_build_properties}"
1232 if (file(getdownLauncher).getName() != getdown_launcher) {
1233 rename(file(getdownLauncher).getName(), getdown_launcher)
1235 into getdownFilesDir
1239 from getdownResourceDir
1240 into "${getdownFilesDir}/${getdown_resource_dir}"
1245 inputs.dir("${jalviewDir}/${packageDir}")
1247 outputs.dir(getdownWebsiteDir)
1248 outputs.dir(getdownFilesDir)
1252 // a helper task to allow getdown digest of any dir: `gradle getdownDigestDir -PDIGESTDIR=/path/to/my/random/getdown/dir
1253 task getdownDigestDir(type: JavaExec) {
1254 def digestDirPropertyName = "DIGESTDIR"
1255 description = "Digest a local dir (-P${digestDirPropertyName}=...) for getdown"
1257 classpath = files(getdownLauncher)
1258 def digestDir = findProperty(digestDirPropertyName)
1259 if (digestDir == null) {
1260 throw new GradleException("Must provide a DIGESTDIR value to produce an alternative getdown digest")
1264 main = "com.threerings.getdown.tools.Digester"
1268 task getdownDigest(type: JavaExec) {
1269 group = "distribution"
1270 description = "Digest the getdown website folder"
1271 dependsOn getdownWebsite
1273 classpath = files(getdownLauncher)
1275 main = "com.threerings.getdown.tools.Digester"
1276 args getdownWebsiteDir
1277 inputs.dir(getdownWebsiteDir)
1278 outputs.file("${getdownWebsiteDir}/digest2.txt")
1283 group = "distribution"
1284 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1285 dependsOn getdownDigest
1287 if (reportRsyncCommand) {
1288 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1289 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1290 println "LIKELY RSYNC COMMAND:"
1291 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1292 if (RUNRSYNC == "true") {
1294 commandLine "mkdir", "-p", toDir
1297 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1307 delete getdownWebsiteDir
1308 delete getdownFilesDir
1314 if (file(install4jHomeDir).exists()) {
1316 } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1317 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1318 } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1319 install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1321 installDir(file(install4jHomeDir))
1323 mediaTypes = Arrays.asList(install4j_media_types.split(","))
1327 task copyInstall4jTemplate {
1328 def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
1329 def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1330 inputs.file(install4jTemplateFile)
1331 inputs.file(install4jFileAssociationsFile)
1332 outputs.file(install4jConfFile)
1335 def install4jConfigXml = new XmlParser().parse(install4jTemplateFile)
1337 // turn off code signing if no OSX_KEYPASS
1338 if (OSX_KEYPASS == "") {
1339 install4jConfigXml.'**'.codeSigning.each { codeSigning ->
1340 codeSigning.'@macEnabled' = "false"
1342 install4jConfigXml.'**'.windows.each { windows ->
1343 windows.'@runPostProcessor' = "false"
1347 // turn off checksum creation for LOCAL channel
1348 def e = install4jConfigXml.application[0]
1349 if (CHANNEL == "LOCAL") {
1350 e.'@createChecksums' = "false"
1352 e.'@createChecksums' = "true"
1355 // put file association actions where placeholder action is
1356 def install4jFileAssociationsText = install4jFileAssociationsFile.text
1357 def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
1358 install4jConfigXml.'**'.action.any { a ->
1359 if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1360 def parent = a.parent()
1362 fileAssociationActions.each { faa ->
1365 // don't need to continue in .any loop once replacements have been made
1370 // write install4j file
1371 install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
1378 delete install4jConfFile
1383 task installers(type: com.install4j.gradle.Install4jTask) {
1384 group = "distribution"
1385 description = "Create the install4j installers"
1386 dependsOn setGitVals
1388 dependsOn copyInstall4jTemplate
1390 projectFile = install4jConfFile
1392 // create an md5 for the input files to use as version for install4j conf file
1393 def digest = MessageDigest.getInstance("MD5")
1395 (file("${install4jDir}/${install4j_template}").text +
1396 file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1397 file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1398 def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1399 if (filesMd5.length() >= 8) {
1400 filesMd5 = filesMd5.substring(0,8)
1402 def install4jTemplateVersion = "${JALVIEW_VERSION}_F${filesMd5}_C${gitHash}"
1403 // make install4jBuildDir relative to jalviewDir
1404 def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
1407 'JALVIEW_NAME': getdown_txt_title,
1408 'JALVIEW_DIR': "../..",
1409 'OSX_KEYSTORE': OSX_KEYSTORE,
1410 'JSIGN_SH': JSIGN_SH,
1411 'JRE_DIR': getdown_app_dir_java,
1412 'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1413 'JALVIEW_VERSION': JALVIEW_VERSION,
1414 'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1415 'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1416 'JAVA_VERSION': JAVA_VERSION,
1417 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1418 'VERSION': JALVIEW_VERSION,
1419 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1420 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1421 'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
1422 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1423 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1424 'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
1425 'COPYRIGHT_MESSAGE': install4j_copyright_message,
1426 'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1427 'INSTALLER_NAME': install4j_installer_name,
1428 'INSTALL4J_UTILS_DIR': install4j_utils_dir,
1429 'GETDOWN_WEBSITE_DIR': getdown_website_dir,
1430 'GETDOWN_FILES_DIR': getdown_files_dir,
1431 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1432 'GETDOWN_DIST_DIR': getdownAppDistDir,
1433 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1434 'GETDOWN_INSTALL_DIR': getdown_install_dir,
1435 'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
1436 'BUILD_DIR': install4jBuildDir,
1439 destination = "${jalviewDir}/${install4jBuildDir}"
1440 buildSelected = true
1442 if (install4j_faster.equals("true") || CHANNEL.startsWith("LOCAL")) {
1444 disableSigning = true
1448 macKeystorePassword = OSX_KEYPASS
1452 println("Using projectFile "+projectFile)
1455 inputs.dir(getdownWebsiteDir)
1456 inputs.file(install4jConfFile)
1457 inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1458 inputs.dir(macosJavaVMDir)
1459 inputs.dir(windowsJavaVMDir)
1460 outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1464 task sourceDist(type: Tar) {
1466 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1467 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1468 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1470 archiveFileName = outputFileName
1471 } catch (Exception e) {
1472 archiveName = outputFileName
1475 compression Compression.GZIP
1490 "**/*.class","$j11modDir/**/*.jar","appletlib","**/*locales",
1492 "utils/InstallAnywhere",
1507 "gradle.properties",
1518 ".settings/org.eclipse.jdt.core.jalview.prefs",
1522 exclude (EXCLUDE_FILES)
1523 include (PROCESS_FILES)
1524 filter(ReplaceTokens,
1528 'Version-Rel': JALVIEW_VERSION,
1529 'Year-Rel': getDate("yyyy")
1534 exclude (EXCLUDE_FILES)
1535 exclude (PROCESS_FILES)
1536 exclude ("appletlib")
1537 exclude ("**/*locales")
1538 exclude ("*locales/**")
1539 exclude ("utils/InstallAnywhere")
1541 exclude (getdown_files_dir)
1542 exclude (getdown_website_dir)
1544 // exluding these as not using jars as modules yet
1545 exclude ("${j11modDir}/**/*.jar")
1548 include(INCLUDE_FILES)
1550 // from (jalviewDir) {
1551 // // explicit includes for stuff that seemed to not get included
1552 // include(fileTree("test/**/*."))
1553 // exclude(EXCLUDE_FILES)
1554 // exclude(PROCESS_FILES)
1561 dependsOn pubhtmlhelp
1563 inputs.dir("${classesDir}/${help_dir}")
1564 outputs.dir("${buildDir}/distributions/${help_dir}")
1568 task j2sSetHeadlessBuild {
1575 task jalviewjsSetEclipseWorkspace {
1576 def propKey = "jalviewjs_eclipse_workspace"
1578 if (project.hasProperty(propKey)) {
1579 propVal = project.getProperty(propKey)
1580 if (propVal.startsWith("~/")) {
1581 propVal = System.getProperty("user.home") + propVal.substring(1)
1584 def propsFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_workspace_location_file}"
1585 def propsFile = file(propsFileName)
1586 def eclipseWsDir = propVal
1587 def props = new Properties()
1589 def writeProps = true
1590 if (( eclipseWsDir == null || !file(eclipseWsDir).exists() ) && propsFile.exists()) {
1591 def ins = new FileInputStream(propsFileName)
1594 if (props.getProperty(propKey, null) != null) {
1595 eclipseWsDir = props.getProperty(propKey)
1600 if (eclipseWsDir == null || !file(eclipseWsDir).exists()) {
1601 def tempDir = File.createTempDir()
1602 eclipseWsDir = tempDir.getAbsolutePath()
1605 eclipseWorkspace = file(eclipseWsDir)
1608 // do not run a headless transpile when we claim to be in Eclipse
1610 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1611 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1613 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1617 props.setProperty(propKey, eclipseWsDir)
1618 propsFile.parentFile.mkdirs()
1619 def bytes = new ByteArrayOutputStream()
1620 props.store(bytes, null)
1621 def propertiesString = bytes.toString()
1622 propsFile.text = propertiesString
1628 println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath())
1631 //inputs.property(propKey, eclipseWsDir) // eclipseWsDir only gets set once this task runs, so will be out-of-date
1632 outputs.file(propsFileName)
1633 outputs.upToDateWhen { eclipseWorkspace.exists() && propsFile.exists() }
1637 task jalviewjsEclipsePaths {
1640 def eclipseRoot = jalviewjs_eclipse_root
1641 if (eclipseRoot.startsWith("~/")) {
1642 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
1644 if (OperatingSystem.current().isMacOsX()) {
1645 eclipseRoot += "/Eclipse.app"
1646 eclipseBinary = "${eclipseRoot}/Contents/MacOS/eclipse"
1647 eclipseProduct = "${eclipseRoot}/Contents/Eclipse/.eclipseproduct"
1648 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
1649 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1650 eclipseRoot += "/eclipse.exe"
1652 eclipseBinary = "${eclipseRoot}/eclipse"
1653 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1654 } else { // linux or unix
1655 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1656 eclipseRoot += "/eclipse"
1658 eclipseBinary = "${eclipseRoot}/eclipse"
1659 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1662 eclipseVersion = "4.13" // default
1663 def assumedVersion = true
1664 if (file(eclipseProduct).exists()) {
1665 def fis = new FileInputStream(eclipseProduct)
1666 def props = new Properties()
1668 eclipseVersion = props.getProperty("version")
1670 assumedVersion = false
1673 def propKey = "eclipse_debug"
1674 eclipseDebug = (project.hasProperty(propKey) && project.getProperty(propKey).equals("true"))
1677 // do not run a headless transpile when we claim to be in Eclipse
1679 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1680 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1682 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1685 if (!assumedVersion) {
1686 println("ECLIPSE VERSION=${eclipseVersion}")
1692 task printProperties {
1694 description "Output to console all System.properties"
1696 System.properties.each { key, val -> System.out.println("Property: ${key}=${val}") }
1702 dependsOn eclipseProject
1703 dependsOn eclipseClasspath
1704 dependsOn eclipseJdt
1708 // this version (type: Copy) will delete anything in the eclipse dropins folder that isn't in fromDropinsDir
1709 task jalviewjsEclipseCopyDropins(type: Copy) {
1710 dependsOn jalviewjsEclipsePaths
1712 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_eclipse_dropins_dir}", include: "*.jar")
1713 inputFiles += file("${jalviewDir}/${jalviewjsJ2sPlugin}")
1714 def outputDir = "${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}"
1721 // this eclipse -clean doesn't actually work
1722 task jalviewjsCleanEclipse(type: Exec) {
1723 dependsOn eclipseSetup
1724 dependsOn jalviewjsEclipsePaths
1725 dependsOn jalviewjsEclipseCopyDropins
1727 executable(eclipseBinary)
1728 args(["-nosplash", "--launcher.suppressErrors", "-data", eclipseWorkspace.getPath(), "-clean", "-console", "-consoleLog"])
1734 def inputString = """exit
1737 def inputByteStream = new ByteArrayInputStream(inputString.getBytes())
1738 standardInput = inputByteStream
1741 /* not really working yet
1742 jalviewjsEclipseCopyDropins.finalizedBy jalviewjsCleanEclipse
1746 task jalviewjsTransferUnzipSwingJs {
1747 def file_zip = "${jalviewDir}/${jalviewjs_swingjs_zip}"
1751 from zipTree(file_zip)
1752 into "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1756 inputs.file file_zip
1757 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1761 task jalviewjsTransferUnzipLib {
1762 def zipFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_libjs_dir}", include: "*.zip")
1765 zipFiles.each { file_zip ->
1767 from zipTree(file_zip)
1768 into "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1773 inputs.files zipFiles
1774 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1778 task jalviewjsTransferUnzipAllLibs {
1779 dependsOn jalviewjsTransferUnzipSwingJs
1780 dependsOn jalviewjsTransferUnzipLib
1784 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
1786 description "Create the .j2s file from the j2s.* properties"
1788 jalviewjsJ2sProps = project.properties.findAll { it.key.startsWith("j2s.") }.sort { it.key }
1789 def siteDirProperty = "j2s.site.directory"
1790 def setSiteDir = false
1791 jalviewjsJ2sProps.each { prop, val ->
1793 if (prop == siteDirProperty) {
1794 if (!(val.startsWith('/') || val.startsWith("file://") )) {
1795 val = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${val}"
1801 if (!setSiteDir) { // default site location, don't override specifically set property
1802 property(siteDirProperty,"${jalviewDirRelativePath}/${jalviewjsTransferSiteJsDir}")
1805 outputFile = jalviewjsJ2sSettingsFileName
1808 inputs.properties(jalviewjsJ2sProps)
1809 outputs.file(jalviewjsJ2sSettingsFileName)
1814 task jalviewjsEclipseSetup {
1815 dependsOn jalviewjsEclipseCopyDropins
1816 dependsOn jalviewjsSetEclipseWorkspace
1817 dependsOn jalviewjsCreateJ2sSettings
1821 task jalviewjsSyncAllLibs (type: Sync) {
1822 dependsOn jalviewjsTransferUnzipAllLibs
1823 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteLibDir}")
1824 inputFiles += fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}")
1825 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1829 def outputFiles = []
1830 rename { filename ->
1831 outputFiles += "${outputDir}/${filename}"
1837 outputs.files outputFiles
1838 inputs.files inputFiles
1842 task jalviewjsSyncResources (type: Sync) {
1843 def inputFiles = fileTree(dir: resourceDir)
1844 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1848 def outputFiles = []
1849 rename { filename ->
1850 outputFiles += "${outputDir}/${filename}"
1856 outputs.files outputFiles
1857 inputs.files inputFiles
1861 task jalviewjsSyncSiteResources (type: Sync) {
1862 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_site_resource_dir}")
1863 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1867 def outputFiles = []
1868 rename { filename ->
1869 outputFiles += "${outputDir}/${filename}"
1875 outputs.files outputFiles
1876 inputs.files inputFiles
1880 task jalviewjsSyncBuildProperties (type: Sync) {
1881 dependsOn createBuildProperties
1882 def inputFiles = [file(buildProperties)]
1883 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1887 def outputFiles = []
1888 rename { filename ->
1889 outputFiles += "${outputDir}/${filename}"
1895 outputs.files outputFiles
1896 inputs.files inputFiles
1900 task jalviewjsProjectImport(type: Exec) {
1901 dependsOn eclipseSetup
1902 dependsOn jalviewjsEclipsePaths
1903 dependsOn jalviewjsEclipseSetup
1906 // do not run a headless import when we claim to be in Eclipse
1908 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1909 throw new StopExecutionException("Not running headless import whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1911 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1915 //def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
1916 def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview"
1917 executable(eclipseBinary)
1918 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
1922 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1924 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
1927 inputs.file("${jalviewDir}/.project")
1928 outputs.upToDateWhen {
1929 file(projdir).exists()
1934 task jalviewjsTranspile(type: Exec) {
1935 dependsOn jalviewjsEclipseSetup
1936 dependsOn jalviewjsProjectImport
1937 dependsOn jalviewjsEclipsePaths
1940 // do not run a headless transpile when we claim to be in Eclipse
1942 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1943 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1945 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1949 executable(eclipseBinary)
1950 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-${jalviewjs_eclipse_build_arg}", eclipse_project_name ])
1954 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1956 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
1962 stdout = new ByteArrayOutputStream()
1963 stderr = new ByteArrayOutputStream()
1965 def logOutFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}"
1966 def logOutFile = file(logOutFileName)
1967 logOutFile.createNewFile()
1968 logOutFile.text = """ROOT: ${jalviewjs_eclipse_root}
1969 BINARY: ${eclipseBinary}
1970 VERSION: ${eclipseVersion}
1971 WORKSPACE: ${eclipseWorkspace}
1972 DEBUG: ${eclipseDebug}
1975 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
1976 // combine stdout and stderr
1977 def logErrFOS = logOutFOS
1979 if (jalviewjs_j2s_to_console.equals("true")) {
1980 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1981 new org.apache.tools.ant.util.TeeOutputStream(
1985 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1986 new org.apache.tools.ant.util.TeeOutputStream(
1991 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1994 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
2001 if (stdout.toString().contains("Error processing ")) {
2002 // j2s did not complete transpile
2003 //throw new TaskExecutionException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
2004 if (jalviewjs_ignore_transpile_errors.equals("true")) {
2005 println("IGNORING TRANSPILE ERRORS")
2006 println("See eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
2008 throw new GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
2013 inputs.dir("${jalviewDir}/${sourceDir}")
2014 outputs.dir("${jalviewDir}/${jalviewjsTransferSiteJsDir}")
2015 outputs.upToDateWhen( { file("${jalviewDir}/${jalviewjsTransferSiteJsDir}${jalviewjs_server_resource}").exists() } )
2019 def jalviewjsCallCore(String name, FileCollection list, String prefixFile, String suffixFile, String jsfile, String zjsfile, File logOutFile, Boolean logOutConsole) {
2021 def stdout = new ByteArrayOutputStream()
2022 def stderr = new ByteArrayOutputStream()
2024 def coreFile = file(jsfile)
2026 msg = "Creating core for ${name}...\nGenerating ${jsfile}"
2028 logOutFile.createNewFile()
2029 logOutFile.append(msg+"\n")
2031 def coreTop = file(prefixFile)
2032 def coreBottom = file(suffixFile)
2033 coreFile.getParentFile().mkdirs()
2034 coreFile.createNewFile()
2035 coreFile.write( coreTop.text )
2040 t.replaceAll("Clazz\\.([^_])","Clazz_${1}")
2041 coreFile.append( t )
2043 msg = "...file '"+f.getPath()+"' does not exist, skipping"
2045 logOutFile.append(msg+"\n")
2048 coreFile.append( coreBottom.text )
2050 msg = "Generating ${zjsfile}"
2052 logOutFile.append(msg+"\n")
2053 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
2054 def logErrFOS = logOutFOS
2057 classpath = files(["${jalviewDir}/tools/closure_compiler.jar"])
2058 args = [ "--js", jsfile, "--js_output_file", zjsfile ]
2061 msg = "\nRunning '"+commandLine.join(' ')+"'\n"
2063 logOutFile.append(msg+"\n")
2065 if (logOutConsole) {
2066 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
2067 new org.apache.tools.ant.util.TeeOutputStream(
2071 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
2072 new org.apache.tools.ant.util.TeeOutputStream(
2077 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
2080 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
2087 logOutFile.append(msg+"\n")
2091 task jalviewjsBuildAllCores {
2093 description "Build the core js lib closures listed in the classlists dir"
2094 dependsOn jalviewjsTranspile
2095 dependsOn jalviewjsTransferUnzipSwingJs
2097 def j2sDir = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${jalviewjs_j2s_subdir}"
2098 def swingJ2sDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${jalviewjs_j2s_subdir}"
2099 def libJ2sDir = "${jalviewDir}/${jalviewjsTransferSiteLibDir}/${jalviewjs_j2s_subdir}"
2100 def jsDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${jalviewjs_js_subdir}"
2101 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}/${jalviewjs_j2s_subdir}/core"
2102 def prefixFile = "${jsDir}/core/coretop2.js"
2103 def suffixFile = "${jsDir}/core/corebottom2.js"
2105 inputs.file prefixFile
2106 inputs.file suffixFile
2108 def classlistFiles = []
2109 // add the classlists found int the jalviewjs_classlists_dir
2110 fileTree(dir: "${jalviewDir}/${jalviewjs_classlists_dir}", include: "*.txt").each {
2112 def name = file.getName() - ".txt"
2119 // _jmol and _jalview cores. Add any other peculiar classlist.txt files here
2120 //classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jmol}"), 'name': "_jvjmol" ]
2121 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jalview}"), 'name': jalviewjsJalviewCoreName ]
2123 jalviewjsCoreClasslists = []
2125 classlistFiles.each {
2128 def file = hash['file']
2129 if (! file.exists()) {
2130 //println("...classlist file '"+file.getPath()+"' does not exist, skipping")
2131 return false // this is a "continue" in groovy .each closure
2133 def name = hash['name']
2135 name = file.getName() - ".txt"
2143 def list = fileTree(dir: j2sDir, includes: filelist)
2145 def jsfile = "${outputDir}/core${name}.js"
2146 def zjsfile = "${outputDir}/core${name}.z.js"
2148 jalviewjsCoreClasslists += [
2157 outputs.file(jsfile)
2158 outputs.file(zjsfile)
2161 // _stevesoft core. add any cores without a classlist here (and the inputs and outputs)
2162 def stevesoftClasslistName = "_stevesoft"
2163 def stevesoftClasslist = [
2164 'jsfile': "${outputDir}/core${stevesoftClasslistName}.js",
2165 'zjsfile': "${outputDir}/core${stevesoftClasslistName}.z.js",
2166 'list': fileTree(dir: j2sDir, include: "com/stevesoft/pat/**/*.js"),
2167 'name': stevesoftClasslistName
2169 jalviewjsCoreClasslists += stevesoftClasslist
2170 inputs.files(stevesoftClasslist['list'])
2171 outputs.file(stevesoftClasslist['jsfile'])
2172 outputs.file(stevesoftClasslist['zjsfile'])
2175 def allClasslistName = "_all"
2176 def allJsFiles = fileTree(dir: j2sDir, include: "**/*.js")
2177 allJsFiles += fileTree(
2181 // these exlusions are files that the closure-compiler produces errors for. Should fix them
2182 "**/org/jmol/jvxl/readers/IsoIntersectFileReader.js",
2183 "**/org/jmol/export/JSExporter.js"
2186 allJsFiles += fileTree(
2190 // these exlusions are files that the closure-compiler produces errors for. Should fix them
2191 "**/sun/misc/Unsafe.js",
2192 "**/swingjs/jquery/jquery-editable-select.js",
2193 "**/swingjs/jquery/j2sComboBox.js",
2194 "**/sun/misc/FloatingDecimal.js"
2197 def allClasslist = [
2198 'jsfile': "${outputDir}/core${allClasslistName}.js",
2199 'zjsfile': "${outputDir}/core${allClasslistName}.z.js",
2201 'name': allClasslistName
2203 // not including this version of "all" core at the moment
2204 //jalviewjsCoreClasslists += allClasslist
2205 inputs.files(allClasslist['list'])
2206 outputs.file(allClasslist['jsfile'])
2207 outputs.file(allClasslist['zjsfile'])
2210 def logOutFile = file("${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_closure_stdout}")
2211 logOutFile.getParentFile().mkdirs()
2212 logOutFile.createNewFile()
2213 logOutFile.write(getDate("yyyy-MM-dd HH:mm:ss")+" jalviewjsBuildAllCores\n----\n")
2215 jalviewjsCoreClasslists.each {
2216 jalviewjsCallCore(it.name, it.list, prefixFile, suffixFile, it.jsfile, it.zjsfile, logOutFile, jalviewjs_j2s_to_console.equals("true"))
2223 def jalviewjsPublishCoreTemplate(String coreName, String templateName, File inputFile, String outputFile) {
2226 into file(outputFile).getParentFile()
2227 rename { filename ->
2228 if (filename.equals(inputFile.getName())) {
2229 return file(outputFile).getName()
2233 filter(ReplaceTokens,
2237 'MAIN': '"'+mainClass+'"',
2239 'NAME': jalviewjsJalviewTemplateName+" [core ${coreName}]",
2240 'COREKEY': jalviewjs_core_key,
2241 'CORENAME': coreName
2248 task jalviewjsPublishCoreTemplates {
2249 dependsOn jalviewjsBuildAllCores
2250 def inputFileName = "${jalviewDir}/${j2s_coretemplate_html}"
2251 def inputFile = file(inputFileName)
2252 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
2254 def outputFiles = []
2255 jalviewjsCoreClasslists.each { cl ->
2256 def outputFile = "${outputDir}/${jalviewjsJalviewTemplateName}_${cl.name}.html"
2257 cl['outputfile'] = outputFile
2258 outputFiles += outputFile
2262 jalviewjsCoreClasslists.each { cl ->
2263 jalviewjsPublishCoreTemplate(cl.name, jalviewjsJalviewTemplateName, inputFile, cl.outputfile)
2266 inputs.file(inputFile)
2267 outputs.files(outputFiles)
2271 task jalviewjsSyncCore (type: Sync) {
2272 dependsOn jalviewjsBuildAllCores
2273 dependsOn jalviewjsPublishCoreTemplates
2274 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteCoreDir}")
2275 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
2279 def outputFiles = []
2280 rename { filename ->
2281 outputFiles += "${outputDir}/${filename}"
2287 outputs.files outputFiles
2288 inputs.files inputFiles
2292 // this Copy version of TransferSiteJs will delete anything else in the target dir
2293 task jalviewjsCopyTransferSiteJs(type: Copy) {
2294 dependsOn jalviewjsTranspile
2295 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2296 into "${jalviewDir}/${jalviewjsSiteDir}"
2300 // this Sync version of TransferSite is used by buildship to keep the website automatically up to date when a file changes
2301 task jalviewjsSyncTransferSiteJs(type: Sync) {
2302 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2304 into "${jalviewDir}/${jalviewjsSiteDir}"
2311 jalviewjsSyncAllLibs.mustRunAfter jalviewjsCopyTransferSiteJs
2312 jalviewjsSyncResources.mustRunAfter jalviewjsCopyTransferSiteJs
2313 jalviewjsSyncSiteResources.mustRunAfter jalviewjsCopyTransferSiteJs
2314 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsCopyTransferSiteJs
2316 jalviewjsSyncAllLibs.mustRunAfter jalviewjsSyncTransferSiteJs
2317 jalviewjsSyncResources.mustRunAfter jalviewjsSyncTransferSiteJs
2318 jalviewjsSyncSiteResources.mustRunAfter jalviewjsSyncTransferSiteJs
2319 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsSyncTransferSiteJs
2322 task jalviewjsPrepareSite {
2324 description "Prepares the website folder including unzipping files and copying resources"
2325 dependsOn jalviewjsSyncAllLibs
2326 dependsOn jalviewjsSyncResources
2327 dependsOn jalviewjsSyncSiteResources
2328 dependsOn jalviewjsSyncBuildProperties
2329 dependsOn jalviewjsSyncCore
2333 task jalviewjsBuildSite {
2335 description "Builds the whole website including transpiled code"
2336 dependsOn jalviewjsCopyTransferSiteJs
2337 dependsOn jalviewjsPrepareSite
2341 task cleanJalviewjsTransferSite {
2343 delete "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2344 delete "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
2345 delete "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
2346 delete "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
2351 task cleanJalviewjsSite {
2352 dependsOn cleanJalviewjsTransferSite
2354 delete "${jalviewDir}/${jalviewjsSiteDir}"
2359 task jalviewjsSiteTar(type: Tar) {
2361 description "Creates a tar.gz file for the website"
2362 dependsOn jalviewjsBuildSite
2363 def outputFilename = "jalviewjs-site-${JALVIEW_VERSION}.tar.gz"
2365 archiveFileName = outputFilename
2366 } catch (Exception e) {
2367 archiveName = outputFilename
2370 compression Compression.GZIP
2372 from "${jalviewDir}/${jalviewjsSiteDir}"
2373 into jalviewjs_site_dir // this is inside the tar file
2375 inputs.dir("${jalviewDir}/${jalviewjsSiteDir}")
2379 task jalviewjsServer {
2381 def filename = "jalviewjsTest.html"
2382 description "Starts a webserver on localhost to test the website. See ${filename} to access local site on most recently used port."
2383 def htmlFile = "${jalviewDirAbsolutePath}/${filename}"
2386 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
2387 def port = Integer.valueOf(jalviewjs_server_port)
2392 while(port < start+1000 && !running) {
2394 def doc_root = new File("${jalviewDirAbsolutePath}/${jalviewjsSiteDir}")
2395 jalviewjsServer = factory.start(doc_root, port)
2397 url = jalviewjsServer.getResourceUrl(jalviewjs_server_resource)
2398 println("SERVER STARTED with document root ${doc_root}.")
2399 println("Go to "+url+" . Run gradle --stop to stop (kills all gradle daemons).")
2400 println("For debug: "+url+"?j2sdebug")
2401 println("For verbose: "+url+"?j2sverbose")
2402 } catch (Exception e) {
2407 <p><a href="${url}">JalviewJS Test. <${url}></a></p>
2408 <p><a href="${url}?j2sdebug">JalviewJS Test with debug. <${url}?j2sdebug></a></p>
2409 <p><a href="${url}?j2sverbose">JalviewJS Test with verbose. <${url}?j2sdebug></a></p>
2411 jalviewjsCoreClasslists.each { cl ->
2412 def urlcore = jalviewjsServer.getResourceUrl(file(cl.outputfile).getName())
2414 <p><a href="${urlcore}">${jalviewjsJalviewTemplateName} [core ${cl.name}]. <${urlcore}></a></p>
2416 println("For core ${cl.name}: "+urlcore)
2419 file(htmlFile).text = htmlText
2422 outputs.file(htmlFile)
2423 outputs.upToDateWhen({false})
2427 task cleanJalviewjsAll {
2429 description "Delete all configuration and build artifacts to do with JalviewJS build"
2430 dependsOn cleanJalviewjsSite
2431 dependsOn jalviewjsEclipsePaths
2434 delete "${jalviewDir}/${jalviewjsBuildDir}"
2435 delete "${jalviewDir}/${eclipse_bin_dir}"
2436 if (eclipseWorkspace != null && file(eclipseWorkspace.getAbsolutePath()+"/.metadata").exists()) {
2437 delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata")
2439 delete "${jalviewDir}/${jalviewjs_j2s_settings}"
2442 outputs.upToDateWhen( { false } )
2446 task jalviewjsIDE_checkJ2sPlugin {
2447 group "00 JalviewJS in Eclipse"
2448 description "Compare the swingjs/net.sf.j2s.core(-j11)?.jar file with the Eclipse IDE's plugin version (found in the 'dropins' dir)"
2451 def j2sPlugin = string("${jalviewDir}/${jalviewjsJ2sPlugin}")
2452 def j2sPluginFile = file(j2sPlugin)
2453 def eclipseHome = System.properties["eclipse.home.location"]
2454 if (eclipseHome == null || ! IN_ECLIPSE) {
2455 throw new StopExecutionException("Cannot find running Eclipse home from System.properties['eclipse.home.location']. Skipping J2S Plugin Check.")
2457 def eclipseJ2sPlugin = "${eclipseHome}/dropins/${j2sPluginFile.getName()}"
2458 def eclipseJ2sPluginFile = file(eclipseJ2sPlugin)
2459 if (!eclipseJ2sPluginFile.exists()) {
2460 def msg = "Eclipse J2S Plugin is not installed (could not find '${eclipseJ2sPlugin}')\nTry running task jalviewjsIDE_copyJ2sPlugin"
2461 System.err.println(msg)
2462 throw new StopExecutionException(msg)
2465 def digest = MessageDigest.getInstance("MD5")
2467 digest.update(j2sPluginFile.text.bytes)
2468 def j2sPluginMd5 = new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
2470 digest.update(eclipseJ2sPluginFile.text.bytes)
2471 def eclipseJ2sPluginMd5 = new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
2473 if (j2sPluginMd5 != eclipseJ2sPluginMd5) {
2474 def msg = "WARNING! Eclipse J2S Plugin '${eclipseJ2sPlugin}' is different to this commit's version '${j2sPlugin}'"
2475 System.err.println(msg)
2476 throw new StopExecutionException(msg)
2478 def msg = "Eclipse J2S Plugin is the same as '${j2sPlugin}' (this is good)"
2484 task jalviewjsIDE_copyJ2sPlugin {
2485 group "00 JalviewJS in Eclipse"
2486 description "Copy the swingjs/net.sf.j2s.core(-j11)?.jar file into the Eclipse IDE's 'dropins' dir"
2489 def j2sPlugin = string("${jalviewDir}/${jalviewjsJ2sPlugin}")
2490 def j2sPluginFile = file(j2sPlugin)
2491 def eclipseHome = System.properties["eclipse.home.location"]
2492 if (eclipseHome == null || ! IN_ECLIPSE) {
2493 throw new StopExecutionException("Cannot find running Eclipse home from System.properties['eclipse.home.location']. NOT copying J2S Plugin.")
2495 def eclipseJ2sPlugin = "${eclipseHome}/dropins/${j2sPluginFile.getName()}"
2496 def eclipseJ2sPluginFile = file(eclipseJ2sPlugin)
2497 def msg = "WARNING! Copying this commit's j2s plugin '${j2sPlugin}' to Eclipse J2S Plugin '${eclipseJ2sPlugin}'\n* May require an Eclipse restart"
2498 System.err.println(msg)
2501 eclipseJ2sPluginFile.getParentFile().mkdirs()
2502 into eclipseJ2sPluginFile.getParent()
2508 task jalviewjsIDE_j2sFile {
2509 group "00 JalviewJS in Eclipse"
2510 description "Creates the .j2s file"
2511 dependsOn jalviewjsCreateJ2sSettings
2515 task jalviewjsIDE_SyncCore {
2516 group "00 JalviewJS in Eclipse"
2517 description "Build the core js lib closures listed in the classlists dir and publish core html from template"
2518 dependsOn jalviewjsSyncCore
2522 task jalviewjsIDE_SyncSiteAll {
2523 dependsOn jalviewjsSyncAllLibs
2524 dependsOn jalviewjsSyncResources
2525 dependsOn jalviewjsSyncSiteResources
2526 dependsOn jalviewjsSyncBuildProperties
2530 cleanJalviewjsTransferSite.mustRunAfter jalviewjsIDE_SyncSiteAll
2533 task jalviewjsIDE_PrepareSite {
2534 group "00 JalviewJS in Eclipse"
2535 description "Sync libs and resources to site dir, but not closure cores"
2537 dependsOn jalviewjsIDE_SyncSiteAll
2538 dependsOn cleanJalviewjsTransferSite
2542 task jalviewjsIDE_AssembleSite {
2543 group "00 JalviewJS in Eclipse"
2544 description "Assembles unzipped supporting zipfiles, resources, site resources and closure cores into the Eclipse transpiled site"
2545 dependsOn jalviewjsPrepareSite
2549 task jalviewjsIDE_SiteClean {
2550 group "00 JalviewJS in Eclipse"
2551 description "Deletes the Eclipse transpiled site"
2552 dependsOn cleanJalviewjsSite
2556 task jalviewjsIDE_Server {
2557 group "00 JalviewJS in Eclipse"
2558 description "Starts a webserver on localhost to test the website"
2559 dependsOn jalviewjsServer
2563 // buildship runs this at import or gradle refresh
2564 task eclipseSynchronizationTask {
2565 //dependsOn eclipseSetup
2566 dependsOn createBuildProperties
2568 dependsOn jalviewjsIDE_j2sFile
2569 dependsOn jalviewjsIDE_checkJ2sPlugin
2570 dependsOn jalviewjsIDE_PrepareSite
2575 // buildship runs this at build time or project refresh
2576 task eclipseAutoBuildTask {
2577 //dependsOn jalviewjsIDE_checkJ2sPlugin
2578 //dependsOn jalviewjsIDE_PrepareSite
2584 description "Build the site"
2585 dependsOn jalviewjsBuildSite