1 import org.apache.tools.ant.filters.ReplaceTokens
2 import org.gradle.internal.os.OperatingSystem
3 import org.gradle.plugins.ide.internal.generator.PropertiesPersistableConfigurationObject
4 import org.gradle.api.internal.PropertiesTransformer
5 import org.gradle.util.ConfigureUtil
6 import org.gradle.plugins.ide.eclipse.model.Output
7 import org.gradle.plugins.ide.eclipse.model.Library
8 import java.security.MessageDigest
9 import groovy.transform.ExternalizeMethods
10 import groovy.util.XmlParser
11 import groovy.xml.XmlUtil
20 classpath 'org.openclover:clover:4.4.1'
29 id 'com.github.johnrengelman.shadow' version '4.0.3'
30 id 'com.install4j.gradle' version '8.0.4'
31 id 'com.dorongold.task-tree' version '1.5' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree
41 // in ext the values are cast to Object. Ensure string values are cast as String (and not GStringImpl) for later use
42 def string(Object o) {
43 return o == null ? "" : o.toString()
48 jalviewDirAbsolutePath = file(jalviewDir).getAbsolutePath()
49 jalviewDirRelativePath = jalviewDir
51 // local build environment properties
52 // can be "projectDir/local.properties"
53 def localProps = "${projectDir}/local.properties"
55 if (file(localProps).exists()) {
56 propsFile = localProps
58 // or "../projectDir_local.properties"
59 def dirLocalProps = projectDir.getParent() + "/" + projectDir.getName() + "_local.properties"
60 if (file(dirLocalProps).exists()) {
61 propsFile = dirLocalProps
63 if (propsFile != null) {
65 def p = new Properties()
66 def localPropsFIS = new FileInputStream(propsFile)
71 def oldval = findProperty(key)
74 println("Overriding property '${key}' ('${oldval}') with ${file(propsFile).getName()} value '${val}'")
76 println("Setting unknown property '${key}' with ${file(propsFile).getName()}s value '${val}'")
79 } catch (Exception e) {
80 System.out.println("Exception reading local.properties")
84 // this property set when running Eclipse headlessly
85 j2sHeadlessBuildProperty = string("net.sf.j2s.core.headlessbuild")
86 // this property set by Eclipse
87 eclipseApplicationProperty = string("eclipse.application")
88 // CHECK IF RUNNING FROM WITHIN ECLIPSE
89 def eclipseApplicationPropertyVal = System.properties[eclipseApplicationProperty]
90 IN_ECLIPSE = eclipseApplicationPropertyVal != null && eclipseApplicationPropertyVal.startsWith("org.eclipse.ui.")
91 // BUT WITHOUT THE HEADLESS BUILD PROPERTY SET
92 if (System.properties[j2sHeadlessBuildProperty].equals("true")) {
93 println("Setting IN_ECLIPSE to ${IN_ECLIPSE} as System.properties['${j2sHeadlessBuildProperty}'] == '${System.properties[j2sHeadlessBuildProperty]}'")
97 println("WITHIN ECLIPSE IDE")
99 println("HEADLESS BUILD")
102 J2S_ENABLED = (project.hasProperty('j2s.compiler.status') && project['j2s.compiler.status'] != null && project['j2s.compiler.status'] == "enable")
104 println("J2S ENABLED")
108 System.properties.sort { it.key }.each {
109 key, val -> println("SYSTEM PROPERTY ${key}='${val}'")
112 if (false && IN_ECLIPSE) {
113 jalviewDir = jalviewDirAbsolutePath
118 bareSourceDir = string(source_dir)
119 sourceDir = string("${jalviewDir}/${bareSourceDir}")
120 resourceDir = string("${jalviewDir}/${resource_dir}")
121 bareTestSourceDir = string(test_source_dir)
122 testSourceDir = string("${jalviewDir}/${bareTestSourceDir}")
125 cloverInstrDir = file("${buildDir}/${cloverSourcesInstrDir}")
126 cloverDb = string("${buildDir}/clover/clover.db")
127 classesDir = string("${jalviewDir}/${classes_dir}")
128 if (clover.equals("true")) {
130 classesDir = string("${buildDir}/${cloverClassesDir}")
133 classesDir = string("${jalviewDir}/${classes_dir}")
138 getdownWebsiteDir = string("${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}")
141 // the following values might be overridden by the CHANNEL switch
142 getdownChannelName = CHANNEL.toLowerCase()
143 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
144 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
145 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher}")
146 getdownAppDistDir = getdown_app_dir_alt
147 buildProperties = string("${resourceDir}/${build_properties_file}")
148 reportRsyncCommand = false
149 jvlChannelName = CHANNEL.toLowerCase()
153 // TODO: get bamboo build artifact URL for getdown artifacts
154 getdown_channel_base = bamboo_channelbase
155 getdownChannelName = string("${bamboo_planKey}/${JAVA_VERSION}")
156 getdownAppBase = string("${bamboo_channelbase}/${bamboo_planKey}${bamboo_getdown_channel_suffix}/${JAVA_VERSION}")
157 jvlChannelName += "_${getdownChannelName}"
158 // automatically add the test group Not-bamboo for exclusion
159 if ("".equals(testngExcludedGroups)) {
160 testngExcludedGroups = "Not-bamboo"
165 getdownAppDistDir = getdown_app_dir_release
166 reportRsyncCommand = true
167 // Don't ignore transpile errors for release build
168 if (jalviewjs_ignore_transpile_errors.equals("true")) {
169 jalviewjs_ignore_transpile_errors = "false"
170 println("Setting jalviewjs_ignore_transpile_errors to 'false'")
175 getdownChannelName = CHANNEL.toLowerCase()+"/${JALVIEW_VERSION}"
176 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
177 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
178 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
179 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
181 packageDir = string("${ARCHIVEDIR}/${packageDir}")
182 buildProperties = string("${buildDir}/archive/${build_properties_file}")
185 reportRsyncCommand = true
189 getdownChannelName = string("archive/${JALVIEW_VERSION}")
190 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
191 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
192 if (!file("${ARCHIVEDIR}/${packageDir}").exists()) {
193 throw new GradleException("Must provide an ARCHIVEDIR value to produce an archive distribution")
195 packageDir = string("${ARCHIVEDIR}/${packageDir}")
196 buildProperties = string("${buildDir}/archive/${build_properties_file}")
199 reportRsyncCommand = true
200 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
204 reportRsyncCommand = true
208 reportRsyncCommand = true
209 // Don't ignore transpile errors for release build
210 if (jalviewjs_ignore_transpile_errors.equals("true")) {
211 jalviewjs_ignore_transpile_errors = "false"
212 println("Setting jalviewjs_ignore_transpile_errors to 'false'")
216 case ~/^SCRATCH(|-[-\w]*)$/:
217 getdownChannelName = CHANNEL
218 getdownDir = string("${getdownChannelName}/${JAVA_VERSION}")
219 getdownAppBase = string("${getdown_channel_base}/${getdownDir}")
220 reportRsyncCommand = true
224 if (!file("${LOCALDIR}").exists()) {
225 throw new GradleException("Must provide a LOCALDIR value to produce a local distribution")
227 getdownAppBase = file(file("${LOCALDIR}").getAbsolutePath()).toURI().toString()
228 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
233 getdownAppBase = file(getdownWebsiteDir).toURI().toString()
234 getdownLauncher = string("${jalviewDir}/${getdown_lib_dir}/${getdown_launcher_local}")
237 default: // something wrong specified
238 throw new GradleException("CHANNEL must be one of BUILD, RELEASE, ARCHIVE, DEVELOP, TEST-RELEASE, SCRATCH-..., LOCAL [default]")
242 // override getdownAppBase if requested
243 if (findProperty("getdown_appbase_override") != null) {
244 getdownAppBase = string(getProperty("getdown_appbase_override"))
245 println("Overriding getdown appbase with '${getdownAppBase}'")
247 // sanitise file name for jalview launcher file for this channel
248 jvlChannelName = jvlChannelName.replaceAll(/[^\w\-]/,"_")
250 getdownAppDir = string("${getdownWebsiteDir}/${getdownAppDistDir}")
251 //getdownJ11libDir = "${getdownWebsiteDir}/${getdown_j11lib_dir}"
252 getdownResourceDir = string("${getdownWebsiteDir}/${getdown_resource_dir}")
253 getdownInstallDir = string("${getdownWebsiteDir}/${getdown_install_dir}")
254 getdownFilesDir = string("${jalviewDir}/${getdown_files_dir}/${JAVA_VERSION}/")
255 getdownFilesInstallDir = string("${getdownFilesDir}/${getdown_install_dir}")
256 /* compile without modules -- using classpath libraries
257 modules_compileClasspath = fileTree(dir: "${jalviewDir}/${j11modDir}", include: ["*.jar"])
258 modules_runtimeClasspath = modules_compileClasspath
261 gitBranch = string("")
263 println("Using a ${CHANNEL} profile.")
265 additional_compiler_args = []
266 // configure classpath/args for j8/j11 compilation
267 if (JAVA_VERSION.equals("1.8")) {
268 JAVA_INTEGER_VERSION = string("8")
271 libDistDir = j8libDir
272 compile_source_compatibility = 1.8
273 compile_target_compatibility = 1.8
274 // these are getdown.txt properties defined dependent on the JAVA_VERSION
275 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java8_min_version"))
276 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java8_max_version"))
277 // this property is assigned below and expanded to multiple lines in the getdown task
278 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java8_txt_multi_java_location"))
279 // this property is for the Java library used in eclipse
280 eclipseJavaRuntimeName = string("JavaSE-1.8")
281 } else if (JAVA_VERSION.equals("11")) {
282 JAVA_INTEGER_VERSION = string("11")
284 libDistDir = j11libDir
285 compile_source_compatibility = 11
286 compile_target_compatibility = 11
287 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
288 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
289 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
290 eclipseJavaRuntimeName = string("JavaSE-11")
291 /* compile without modules -- using classpath libraries
292 additional_compiler_args += [
293 '--module-path', modules_compileClasspath.asPath,
294 '--add-modules', j11modules
297 } else if (JAVA_VERSION.equals("12") || JAVA_VERSION.equals("13")) {
298 JAVA_INTEGER_VERSION = JAVA_VERSION
300 libDistDir = j11libDir
301 compile_source_compatibility = JAVA_VERSION
302 compile_target_compatibility = JAVA_VERSION
303 getdownAltJavaMinVersion = string(findProperty("getdown_alt_java11_min_version"))
304 getdownAltJavaMaxVersion = string(findProperty("getdown_alt_java11_max_version"))
305 getdownAltMultiJavaLocation = string(findProperty("getdown_alt_java11_txt_multi_java_location"))
306 eclipseJavaRuntimeName = string("JavaSE-11")
307 /* compile without modules -- using classpath libraries
308 additional_compiler_args += [
309 '--module-path', modules_compileClasspath.asPath,
310 '--add-modules', j11modules
314 throw new GradleException("JAVA_VERSION=${JAVA_VERSION} not currently supported by Jalview")
319 JAVA_MIN_VERSION = JAVA_VERSION
320 JAVA_MAX_VERSION = JAVA_VERSION
321 def jreInstallsDir = string(jre_installs_dir)
322 if (jreInstallsDir.startsWith("~/")) {
323 jreInstallsDir = System.getProperty("user.home") + jreInstallsDir.substring(1)
325 macosJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-mac-x64/jre")
326 macosJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-mac-x64.tar.gz")
327 windowsJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-windows-x64/jre")
328 windowsJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-windows-x64.tar.gz")
329 linuxJavaVMDir = string("${jreInstallsDir}/jre-${JAVA_INTEGER_VERSION}-linux-x64/jre")
330 linuxJavaVMTgz = string("${jreInstallsDir}/tgz/jre-${JAVA_INTEGER_VERSION}-linux-x64.tar.gz")
331 install4jDir = string("${jalviewDir}/${install4j_utils_dir}")
332 install4jConfFileName = string("jalview-install4j-conf.install4j")
333 install4jConfFile = file("${install4jDir}/${install4jConfFileName}")
334 install4jHomeDir = install4j_home_dir
335 if (install4jHomeDir.startsWith("~/")) {
336 install4jHomeDir = System.getProperty("user.home") + install4jHomeDir.substring(1)
341 buildingHTML = string("${jalviewDir}/${docDir}/building.html")
342 helpFile = string("${classesDir}/${help_dir}/help.jhm")
343 helpParentDir = string("${jalviewDir}/${help_parent_dir}")
344 helpSourceDir = string("${helpParentDir}/${help_dir}")
347 relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath())
348 jalviewjsBuildDir = string("${relativeBuildDir}/jalviewjs")
349 jalviewjsSiteDir = string("${jalviewjsBuildDir}/${jalviewjs_site_dir}")
351 jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir)
353 jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js")
355 jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib")
356 jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs")
357 jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core")
358 jalviewjsJalviewCoreHtmlFile = string("")
359 jalviewjsJalviewCoreName = string(jalviewjs_core_name)
360 jalviewjsCoreClasslists = []
361 jalviewjsJalviewTemplateName = string(jalviewjs_name)
362 jalviewjsJ2sSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_settings}")
363 jalviewjsJ2sProps = null
364 jalviewjsJ2sPlugin = jalviewjs_j2s_plugin
366 eclipseWorkspace = null
367 eclipseBinary = string("")
368 eclipseVersion = string("")
378 outputDir = file(classesDir)
383 srcDirs += helpParentDir
386 jar.destinationDir = file("${jalviewDir}/${packageDir}")
388 compileClasspath = files(sourceSets.main.java.outputDir)
389 //compileClasspath += files(sourceSets.main.resources.srcDirs)
390 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
392 runtimeClasspath = compileClasspath
397 srcDirs = [ cloverInstrDir ]
398 outputDir = file("${buildDir}/${cloverClassesDir}")
402 srcDirs = sourceSets.main.resources.srcDirs
404 compileClasspath = configurations.cloverRuntime + files( sourceSets.clover.java.outputDir )
405 compileClasspath += files(sourceSets.main.java.outputDir)
406 compileClasspath += sourceSets.main.compileClasspath
407 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["**/*.jar"])
408 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
410 runtimeClasspath = compileClasspath
415 srcDirs testSourceDir
416 outputDir = file("${jalviewDir}/${testOutputDir}")
420 srcDirs = sourceSets.main.resources.srcDirs
423 compileClasspath = files( sourceSets.test.java.outputDir )
426 compileClasspath = sourceSets.clover.compileClasspath
428 compileClasspath += files(sourceSets.main.java.outputDir)
431 compileClasspath += fileTree(dir: "${jalviewDir}/${libDir}", include: ["*.jar"])
432 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testnglibs", include: ["**/*.jar"])
433 compileClasspath += fileTree(dir: "${jalviewDir}/${utilsDir}/testlibs", include: ["**/*.jar"])
435 runtimeClasspath = compileClasspath
443 cloverCompile 'org.openclover:clover:4.4.1'
444 testCompile 'org.openclover:clover:4.4.1'
451 cloverRuntime.extendsFrom cloverCompile
455 // eclipse project and settings files creation, also used by buildship
458 name = eclipse_project_name
460 natures 'org.eclipse.jdt.core.javanature',
461 'org.eclipse.jdt.groovy.core.groovyNature',
462 'org.eclipse.buildship.core.gradleprojectnature'
464 buildCommand 'org.eclipse.jdt.core.javabuilder'
465 buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
469 //defaultOutputDir = sourceSets.main.java.outputDir
472 if (it.isCanBeResolved()) {
477 minusConfigurations += removeThese
478 plusConfigurations = [ ]
482 def removeTheseToo = []
483 HashMap<String, Boolean> alreadyAddedSrcPath = new HashMap<>();
484 cp.entries.each { entry ->
485 // This conditional removes all src classpathentries that a) have already been added or b) aren't "src" or "test".
486 // e.g. this removes the resources dir being copied into bin/main, bin/test AND bin/clover
487 // we add the resources and help/help dirs in as libs afterwards (see below)
488 if (entry.kind == 'src') {
489 if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == bareSourceDir || entry.path == bareTestSourceDir)) {
490 removeTheseToo += entry
492 alreadyAddedSrcPath.putAt(entry.path, true)
497 cp.entries.removeAll(removeTheseToo)
499 //cp.entries += new Output("${eclipse_bin_dir}/main")
500 if (file(helpParentDir).isDirectory()) {
501 cp.entries += new Library(fileReference(helpParentDir))
503 if (file(resourceDir).isDirectory()) {
504 cp.entries += new Library(fileReference(resourceDir))
507 HashMap<String, Boolean> alreadyAddedLibPath = new HashMap<>();
509 sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
510 //don't want to add outputDir as eclipse is using its own output dir in bin/main
511 if (it.isDirectory() || ! it.exists()) {
512 // don't add dirs to classpath, especially if they don't exist
513 return false // groovy "continue" in .any closure
515 def itPath = it.toString()
516 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
517 // make relative path
518 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
520 if (alreadyAddedLibPath.get(itPath)) {
521 //println("Not adding duplicate entry "+itPath)
523 //println("Adding entry "+itPath)
524 cp.entries += new Library(fileReference(itPath))
525 alreadyAddedLibPath.put(itPath, true)
529 sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.any {
530 //no longer want to add outputDir as eclipse is using its own output dir in bin/main
531 if (it.isDirectory() || ! it.exists()) {
532 // don't add dirs to classpath
533 return false // groovy "continue" in .any closure
536 def itPath = it.toString()
537 if (itPath.startsWith("${jalviewDirAbsolutePath}/")) {
538 itPath = itPath.substring(jalviewDirAbsolutePath.length()+1)
540 if (alreadyAddedLibPath.get(itPath)) {
543 def lib = new Library(fileReference(itPath))
544 lib.entryAttributes["test"] = "true"
546 alreadyAddedLibPath.put(itPath, true)
554 containers 'org.eclipse.buildship.core.gradleclasspathcontainer'
559 // for the IDE, use java 11 compatibility
560 sourceCompatibility = compile_source_compatibility
561 targetCompatibility = compile_target_compatibility
562 javaRuntimeName = eclipseJavaRuntimeName
564 // add in jalview project specific properties/preferences into eclipse core preferences
565 // and also the codestyle XML file
567 withProperties { props ->
568 def jalview_prefs = new Properties()
569 def ins = new FileInputStream("${jalviewDirAbsolutePath}/${eclipse_extra_jdt_prefs_file}")
570 jalview_prefs.load(ins)
572 jalview_prefs.forEach { t, v ->
573 if (props.getAt(t) == null) {
577 // codestyle file -- overrides previous formatter prefs
578 def csFile = file("${jalviewDirAbsolutePath}/${eclipse_codestyle_file}")
579 if (csFile.exists()) {
580 XmlParser parser = new XmlParser()
581 def profiles = parser.parse(csFile)
582 def profile = profiles.'profile'.find { p -> (p.'@kind' == "CodeFormatterProfile" && p.'@name' == "Jalview") }
583 if (profile != null) {
584 profile.'setting'.each { s ->
586 def value = s.'@value'
587 if (id != null && value != null) {
588 props.putAt(id, value)
599 // Don't want these to be activated if in headless build
600 synchronizationTasks "eclipseSynchronizationTask"
601 //autoBuildTasks "eclipseAutoBuildTask"
607 /* hack to change eclipse prefs in .settings files other than org.eclipse.jdt.core.prefs */
608 // Class to allow updating arbitrary properties files
609 class PropertiesFile extends PropertiesPersistableConfigurationObject {
610 public PropertiesFile(PropertiesTransformer t) { super(t); }
611 @Override protected void load(Properties properties) { }
612 @Override protected void store(Properties properties) { }
613 @Override protected String getDefaultResourceName() { return ""; }
614 // This is necessary, because PropertiesPersistableConfigurationObject fails
615 // if no default properties file exists.
616 @Override public void loadDefaults() { load(new StringBufferInputStream("")); }
619 // Task to update arbitrary properties files (set outputFile)
620 class PropertiesFileTask extends PropertiesGeneratorTask<PropertiesFile> {
621 private final PropertiesFileContentMerger file;
622 public PropertiesFileTask() { file = new PropertiesFileContentMerger(getTransformer()); }
623 protected PropertiesFile create() { return new PropertiesFile(getTransformer()); }
624 protected void configure(PropertiesFile props) {
625 file.getBeforeMerged().execute(props); file.getWhenMerged().execute(props);
627 public void file(Closure closure) { ConfigureUtil.configure(closure, file); }
630 task eclipseUIPreferences(type: PropertiesFileTask) {
631 description = "Generate Eclipse additional settings"
632 def filename = "org.eclipse.jdt.ui.prefs"
633 outputFile = "$projectDir/.settings/${filename}" as File
636 it.load new FileInputStream("$projectDir/utils/eclipse/${filename}" as String)
641 task eclipseGroovyCorePreferences(type: PropertiesFileTask) {
642 description = "Generate Eclipse additional settings"
643 def filename = "org.eclipse.jdt.groovy.core.prefs"
644 outputFile = "$projectDir/.settings/${filename}" as File
647 it.load new FileInputStream("$projectDir/utils/eclipse/${filename}" as String)
652 task eclipseAllPreferences {
654 dependsOn eclipseUIPreferences
655 dependsOn eclipseGroovyCorePreferences
658 eclipseUIPreferences.mustRunAfter eclipseJdt
659 eclipseGroovyCorePreferences.mustRunAfter eclipseJdt
661 /* end of eclipse preferences hack */
665 // only instrument source, we build test classes as normal
666 inputs.files files (sourceSets.main.allJava,sourceSets.test.allJava) // , fileTree(dir:"$jalviewDir/$testSourceDir", include: ["**/*.java"]))
667 outputs.dir cloverInstrDir
670 delete cloverInstrDir
675 cloverInstrDir.getPath(),
678 inputs.files.files.collect(
679 { file -> file.absolutePath }
682 String[] args = argsList.toArray()
683 println("About to instrument "+args.length +" files")
684 com.atlassian.clover.CloverInstr.mainImpl(args)
689 cloverClasses.dependsOn cloverInstr
693 group = "Verification"
694 description = "Creates the Clover report"
695 inputs.dir "${buildDir}/clover"
696 outputs.dir "${reportsDir}/clover"
698 file(cloverDb).exists()
705 "${reportsDir}/clover"
707 String[] args = argsList.toArray()
708 com.atlassian.clover.reporters.html.HtmlReporter.runReport(args)
710 // and generate ${reportsDir}/clover/clover.xml
715 "${reportsDir}/clover/clover.xml"
717 com.atlassian.clover.reporters.xml.XMLReporter.runReport(args)
725 sourceCompatibility = compile_source_compatibility
726 targetCompatibility = compile_target_compatibility
727 options.compilerArgs += additional_compiler_args
728 print ("Setting target compatibility to "+targetCompatibility+"\n")
730 classpath += configurations.cloverRuntime
736 delete cloverInstrDir
746 sourceCompatibility = compile_source_compatibility
747 targetCompatibility = compile_target_compatibility
748 options.compilerArgs = additional_compiler_args
749 print ("Setting target compatibility to "+targetCompatibility+"\n")
757 dependsOn compileCloverJava
758 classpath += configurations.cloverRuntime
760 classpath += sourceSets.main.runtimeClasspath
763 sourceCompatibility = compile_source_compatibility
764 targetCompatibility = compile_target_compatibility
765 options.compilerArgs = additional_compiler_args
766 print ("Setting target compatibility to "+targetCompatibility+"\n")
773 delete sourceSets.main.java.outputDir
779 dependsOn cleanClover
781 delete sourceSets.test.java.outputDir
786 // format is a string like date.format("dd MMMM yyyy")
787 def getDate(format) {
788 def date = new Date()
789 return date.format(format)
794 def hashStdOut = new ByteArrayOutputStream()
796 commandLine "git", "rev-parse", "--short", "HEAD"
797 standardOutput = hashStdOut
801 def branchStdOut = new ByteArrayOutputStream()
803 commandLine "git", "rev-parse", "--abbrev-ref", "HEAD"
804 standardOutput = branchStdOut
808 gitHash = hashStdOut.toString().trim()
809 gitBranch = branchStdOut.toString().trim()
811 outputs.upToDateWhen { false }
815 task createBuildProperties(type: WriteProperties) {
817 description = "Create the ${buildProperties} file"
819 inputs.dir(sourceDir)
820 inputs.dir(resourceDir)
821 file(buildProperties).getParentFile().mkdirs()
822 outputFile (buildProperties)
823 // taking time specific comment out to allow better incremental builds
824 comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd HH:mm:ss")
825 //comment "--Jalview Build Details--\n"+getDate("yyyy-MM-dd")
826 property "BUILD_DATE", getDate("HH:mm:ss dd MMMM yyyy")
827 property "VERSION", JALVIEW_VERSION
828 property "INSTALLATION", INSTALLATION+" git-commit:"+gitHash+" ["+gitBranch+"]"
829 outputs.file(outputFile)
835 delete buildProperties
840 task cleanBuildingHTML(type: Delete) {
847 task convertBuildingMD(type: Exec) {
848 dependsOn cleanBuildingHTML
849 def buildingMD = "${jalviewDir}/${docDir}/building.md"
850 def css = "${jalviewDir}/${docDir}/github.css"
853 pandoc_exec.split(",").each {
854 if (file(it.trim()).exists()) {
860 def buildtoolsPandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
861 if ((pandoc == null || ! file(pandoc).exists()) && file(buildtoolsPandoc).exists()) {
862 pandoc = System.getProperty("user.home")+"/buildtools/pandoc/bin/pandoc"
866 if (pandoc != null && file(pandoc).exists()) {
867 commandLine pandoc, '-s', '-o', buildingHTML, '--metadata', 'pagetitle="Building Jalview from Source"', '--toc', '-H', css, buildingMD
869 println("Cannot find pandoc. Skipping convert building.md to HTML")
870 throw new StopExecutionException("Cannot find pandoc. Skipping convert building.md to HTML")
876 inputs.file(buildingMD)
878 outputs.file(buildingHTML)
882 task syncDocs(type: Sync) {
883 dependsOn convertBuildingMD
884 def syncDir = "${classesDir}/${docDir}"
885 from fileTree("${jalviewDir}/${docDir}")
891 task copyHelp(type: Copy) {
892 def inputDir = helpSourceDir
893 def outputDir = "${classesDir}/${help_dir}"
898 filter(ReplaceTokens,
902 'Version-Rel': JALVIEW_VERSION,
903 'Year-Rel': getDate("yyyy")
915 outputs.files(helpFile)
916 outputs.dir(outputDir)
920 task syncLib(type: Sync) {
921 def syncDir = "${classesDir}/${libDistDir}"
922 from fileTree("${jalviewDir}/${libDistDir}")
927 task syncResources(type: Sync) {
928 dependsOn createBuildProperties
939 dependsOn syncResources
945 //testReportDirName = "test-reports" // note that test workingDir will be $jalviewDir
948 dependsOn compileJava
950 dependsOn cloverInstr
954 print("Running tests " + (use_clover?"WITH":"WITHOUT") + " clover [clover="+use_clover+"]\n")
958 includeGroups testngGroups
959 excludeGroups testngExcludedGroups
961 useDefaultListeners=true
964 maxHeapSize = "1024m"
966 workingDir = jalviewDir
967 //systemProperties 'clover.jar' System.properties.clover.jar
968 sourceCompatibility = compile_source_compatibility
969 targetCompatibility = compile_target_compatibility
970 jvmArgs += additional_compiler_args
975 task buildIndices(type: JavaExec) {
977 classpath = sourceSets.main.compileClasspath
978 main = "com.sun.java.help.search.Indexer"
979 workingDir = "${classesDir}/${help_dir}"
982 inputs.dir("${workingDir}/${argDir}")
984 outputs.dir("${classesDir}/doc")
985 outputs.dir("${classesDir}/help")
986 outputs.file("${workingDir}/JavaHelpSearch/DOCS")
987 outputs.file("${workingDir}/JavaHelpSearch/DOCS.TAB")
988 outputs.file("${workingDir}/JavaHelpSearch/OFFSETS")
989 outputs.file("${workingDir}/JavaHelpSearch/POSITIONS")
990 outputs.file("${workingDir}/JavaHelpSearch/SCHEMA")
991 outputs.file("${workingDir}/JavaHelpSearch/TMAP")
995 task compileLinkCheck(type: JavaCompile) {
997 classpath = files("${jalviewDir}/${utilsDir}")
998 destinationDir = file("${jalviewDir}/${utilsDir}")
999 source = fileTree(dir: "${jalviewDir}/${utilsDir}", include: ["HelpLinksChecker.java", "BufferedLineReader.java"])
1001 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
1002 inputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.java")
1003 outputs.file("${jalviewDir}/${utilsDir}/HelpLinksChecker.class")
1004 outputs.file("${jalviewDir}/${utilsDir}/BufferedLineReader.class")
1008 task linkCheck(type: JavaExec) {
1009 dependsOn prepare, compileLinkCheck
1011 def helpLinksCheckerOutFile = file("${jalviewDir}/${utilsDir}/HelpLinksChecker.out")
1012 classpath = files("${jalviewDir}/${utilsDir}")
1013 main = "HelpLinksChecker"
1014 workingDir = jalviewDir
1015 args = [ "${classesDir}/${help_dir}", "-nointernet" ]
1017 def outFOS = new FileOutputStream(helpLinksCheckerOutFile, false) // false == don't append
1019 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
1022 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
1026 inputs.dir("${classesDir}/${help_dir}")
1027 outputs.file(helpLinksCheckerOutFile)
1030 // import the pubhtmlhelp target
1031 ant.properties.basedir = "${jalviewDir}"
1032 ant.properties.helpBuildDir = "${jalviewDirAbsolutePath}/${classes_dir}/${help_dir}"
1033 ant.importBuild "${utilsDir}/publishHelp.xml"
1036 task cleanPackageDir(type: Delete) {
1038 delete fileTree(dir: "${jalviewDir}/${packageDir}", include: "*.jar")
1045 dependsOn buildIndices
1046 dependsOn createBuildProperties
1049 attributes "Main-Class": mainClass,
1050 "Permissions": "all-permissions",
1051 "Application-Name": "Jalview Desktop",
1052 "Codebase": application_codebase
1055 destinationDir = file("${jalviewDir}/${packageDir}")
1056 archiveName = rootProject.name+".jar"
1062 exclude "**/*.jar.*"
1064 inputs.dir(classesDir)
1065 outputs.file("${jalviewDir}/${packageDir}/${archiveName}")
1069 task copyJars(type: Copy) {
1070 from fileTree(dir: classesDir, include: "**/*.jar").files
1071 into "${jalviewDir}/${packageDir}"
1075 // doing a Sync instead of Copy as Copy doesn't deal with "outputs" very well
1076 task syncJars(type: Sync) {
1077 from fileTree(dir: "${jalviewDir}/${libDistDir}", include: "**/*.jar").files
1078 into "${jalviewDir}/${packageDir}"
1080 include jar.archiveName
1087 description = "Put all required libraries in dist"
1088 // order of "cleanPackageDir", "copyJars", "jar" important!
1089 jar.mustRunAfter cleanPackageDir
1090 syncJars.mustRunAfter cleanPackageDir
1091 dependsOn cleanPackageDir
1094 outputs.dir("${jalviewDir}/${packageDir}")
1099 dependsOn cleanPackageDir
1105 group = "distribution"
1109 from ("${jalviewDir}/${libDistDir}") {
1113 attributes 'Implementation-Version': JALVIEW_VERSION
1115 mainClassName = shadowJarMainClass
1117 classifier = "all-"+JALVIEW_VERSION+"-j"+JAVA_VERSION
1122 task getdownWebsite() {
1123 group = "distribution"
1124 description = "Create the getdown minimal app folder, and website folder for this version of jalview. Website folder also used for offline app installer"
1129 def getdownWebsiteResourceFilenames = []
1130 def getdownTextString = ""
1131 def getdownResourceDir = getdownResourceDir
1132 def getdownResourceFilenames = []
1135 // clean the getdown website and files dir before creating getdown folders
1136 delete getdownWebsiteDir
1137 delete getdownFilesDir
1140 from buildProperties
1141 rename(build_properties_file, getdown_build_properties)
1144 getdownWebsiteResourceFilenames += "${getdownAppDistDir}/${getdown_build_properties}"
1146 // go through properties looking for getdown_txt_...
1147 def props = project.properties.sort { it.key }
1148 if (getdownAltJavaMinVersion != null && getdownAltJavaMinVersion.length() > 0) {
1149 props.put("getdown_txt_java_min_version", getdownAltJavaMinVersion)
1151 if (getdownAltJavaMaxVersion != null && getdownAltJavaMaxVersion.length() > 0) {
1152 props.put("getdown_txt_java_max_version", getdownAltJavaMaxVersion)
1154 if (getdownAltMultiJavaLocation != null && getdownAltMultiJavaLocation.length() > 0) {
1155 props.put("getdown_txt_multi_java_location", getdownAltMultiJavaLocation)
1158 props.put("getdown_txt_appbase", getdownAppBase)
1159 props.each{ prop, val ->
1160 if (prop.startsWith("getdown_txt_") && val != null) {
1161 if (prop.startsWith("getdown_txt_multi_")) {
1162 def key = prop.substring(18)
1163 val.split(",").each{ v ->
1164 def line = "${key} = ${v}\n"
1165 getdownTextString += line
1168 // file values rationalised
1169 if (val.indexOf('/') > -1 || prop.startsWith("getdown_txt_resource")) {
1171 if (val.indexOf('/') == 0) {
1174 } else if (val.indexOf('/') > 0) {
1175 // relative path (relative to jalviewDir)
1176 r = file( "${jalviewDir}/${val}" )
1179 val = "${getdown_resource_dir}/" + r.getName()
1180 getdownWebsiteResourceFilenames += val
1181 getdownResourceFilenames += r.getPath()
1184 if (! prop.startsWith("getdown_txt_resource")) {
1185 def line = prop.substring(12) + " = ${val}\n"
1186 getdownTextString += line
1192 getdownWebsiteResourceFilenames.each{ filename ->
1193 getdownTextString += "resource = ${filename}\n"
1195 getdownResourceFilenames.each{ filename ->
1198 into getdownResourceDir
1203 fileTree(file(packageDir)).each{ f ->
1204 if (f.isDirectory()) {
1205 def files = fileTree(dir: f, include: ["*"]).getFiles()
1207 } else if (f.exists()) {
1211 codeFiles.sort().each{f ->
1212 def name = f.getName()
1213 def line = "code = ${getdownAppDistDir}/${name}\n"
1214 getdownTextString += line
1221 // NOT USING MODULES YET, EVERYTHING SHOULD BE IN dist
1223 if (JAVA_VERSION.equals("11")) {
1224 def j11libFiles = fileTree(dir: "${jalviewDir}/${j11libDir}", include: ["*.jar"]).getFiles()
1225 j11libFiles.sort().each{f ->
1226 def name = f.getName()
1227 def line = "code = ${getdown_j11lib_dir}/${name}\n"
1228 getdownTextString += line
1231 into getdownJ11libDir
1237 // 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.
1238 //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
1239 getdownTextString += "resource = ${getdown_launcher_new}\n"
1240 getdownTextString += "class = ${mainClass}\n"
1242 def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
1243 getdown_txt.write(getdownTextString)
1245 def getdownLaunchJvl = getdown_launch_jvl_name + ( (jvlChannelName != null && jvlChannelName.length() > 0)?"-${jvlChannelName}":"" ) + ".jvl"
1246 def launchJvl = file("${getdownWebsiteDir}/${getdownLaunchJvl}")
1247 launchJvl.write("appbase="+props.get("getdown_txt_appbase"))
1250 from getdownLauncher
1251 rename(file(getdownLauncher).getName(), getdown_launcher_new)
1252 into getdownWebsiteDir
1256 from getdownLauncher
1257 if (file(getdownLauncher).getName() != getdown_launcher) {
1258 rename(file(getdownLauncher).getName(), getdown_launcher)
1260 into getdownWebsiteDir
1263 if (! (CHANNEL.startsWith("ARCHIVE") || CHANNEL.startsWith("DEVELOP"))) {
1266 from getdownLauncher
1267 from "${getdownWebsiteDir}/${getdown_build_properties}"
1268 if (file(getdownLauncher).getName() != getdown_launcher) {
1269 rename(file(getdownLauncher).getName(), getdown_launcher)
1271 into getdownInstallDir
1275 from getdownInstallDir
1276 into getdownFilesInstallDir
1283 from getdownLauncher
1284 from "${getdownWebsiteDir}/${getdown_build_properties}"
1285 if (file(getdownLauncher).getName() != getdown_launcher) {
1286 rename(file(getdownLauncher).getName(), getdown_launcher)
1288 into getdownFilesDir
1292 from getdownResourceDir
1293 into "${getdownFilesDir}/${getdown_resource_dir}"
1298 inputs.dir("${jalviewDir}/${packageDir}")
1300 outputs.dir(getdownWebsiteDir)
1301 outputs.dir(getdownFilesDir)
1305 // a helper task to allow getdown digest of any dir: `gradle getdownDigestDir -PDIGESTDIR=/path/to/my/random/getdown/dir
1306 task getdownDigestDir(type: JavaExec) {
1307 def digestDirPropertyName = "DIGESTDIR"
1308 description = "Digest a local dir (-P${digestDirPropertyName}=...) for getdown"
1310 classpath = files(getdownLauncher)
1311 def digestDir = findProperty(digestDirPropertyName)
1312 if (digestDir == null) {
1313 throw new GradleException("Must provide a DIGESTDIR value to produce an alternative getdown digest")
1317 main = "com.threerings.getdown.tools.Digester"
1321 task getdownDigest(type: JavaExec) {
1322 group = "distribution"
1323 description = "Digest the getdown website folder"
1324 dependsOn getdownWebsite
1326 classpath = files(getdownLauncher)
1328 main = "com.threerings.getdown.tools.Digester"
1329 args getdownWebsiteDir
1330 inputs.dir(getdownWebsiteDir)
1331 outputs.file("${getdownWebsiteDir}/digest2.txt")
1336 group = "distribution"
1337 description = "Create the minimal and full getdown app folder for installers and website and create digest file"
1338 dependsOn getdownDigest
1340 if (reportRsyncCommand) {
1341 def fromDir = getdownWebsiteDir + (getdownWebsiteDir.endsWith('/')?'':'/')
1342 def toDir = "${getdown_rsync_dest}/${getdownDir}" + (getdownDir.endsWith('/')?'':'/')
1343 println "LIKELY RSYNC COMMAND:"
1344 println "mkdir -p '$toDir'\nrsync -avh --delete '$fromDir' '$toDir'"
1345 if (RUNRSYNC == "true") {
1347 commandLine "mkdir", "-p", toDir
1350 commandLine "rsync", "-avh", "--delete", fromDir, toDir
1360 delete getdownWebsiteDir
1361 delete getdownFilesDir
1367 if (file(install4jHomeDir).exists()) {
1369 } else if (file(System.getProperty("user.home")+"/buildtools/install4j").exists()) {
1370 install4jHomeDir = System.getProperty("user.home")+"/buildtools/install4j"
1371 } else if (file("/Applications/install4j.app/Contents/Resources/app").exists()) {
1372 install4jHomeDir = "/Applications/install4j.app/Contents/Resources/app"
1374 installDir(file(install4jHomeDir))
1376 mediaTypes = Arrays.asList(install4j_media_types.split(","))
1380 task copyInstall4jTemplate {
1381 def install4jTemplateFile = file("${install4jDir}/${install4j_template}")
1382 def install4jFileAssociationsFile = file("${install4jDir}/${install4j_installer_file_associations}")
1383 inputs.file(install4jTemplateFile)
1384 inputs.file(install4jFileAssociationsFile)
1385 outputs.file(install4jConfFile)
1388 def install4jConfigXml = new XmlParser().parse(install4jTemplateFile)
1390 // turn off code signing if no OSX_KEYPASS
1391 if (OSX_KEYPASS == "") {
1392 install4jConfigXml.'**'.codeSigning.each { codeSigning ->
1393 codeSigning.'@macEnabled' = "false"
1395 install4jConfigXml.'**'.windows.each { windows ->
1396 windows.'@runPostProcessor' = "false"
1400 // turn off checksum creation for LOCAL channel
1401 def e = install4jConfigXml.application[0]
1402 if (CHANNEL == "LOCAL") {
1403 e.'@createChecksums' = "false"
1405 e.'@createChecksums' = "true"
1408 // put file association actions where placeholder action is
1409 def install4jFileAssociationsText = install4jFileAssociationsFile.text
1410 def fileAssociationActions = new XmlParser().parseText("<actions>${install4jFileAssociationsText}</actions>")
1411 install4jConfigXml.'**'.action.any { a ->
1412 if (a.'@name' == 'EXTENSIONS_REPLACED_BY_GRADLE') {
1413 def parent = a.parent()
1415 fileAssociationActions.each { faa ->
1418 // don't need to continue in .any loop once replacements have been made
1423 // write install4j file
1424 install4jConfFile.text = XmlUtil.serialize(install4jConfigXml)
1431 delete install4jConfFile
1436 task installers(type: com.install4j.gradle.Install4jTask) {
1437 group = "distribution"
1438 description = "Create the install4j installers"
1439 dependsOn setGitVals
1441 dependsOn copyInstall4jTemplate
1443 projectFile = install4jConfFile
1445 // create an md5 for the input files to use as version for install4j conf file
1446 def digest = MessageDigest.getInstance("MD5")
1448 (file("${install4jDir}/${install4j_template}").text +
1449 file("${install4jDir}/${install4j_info_plist_file_associations}").text +
1450 file("${install4jDir}/${install4j_installer_file_associations}").text).bytes)
1451 def filesMd5 = new BigInteger(1, digest.digest()).toString(16)
1452 if (filesMd5.length() >= 8) {
1453 filesMd5 = filesMd5.substring(0,8)
1455 def install4jTemplateVersion = "${JALVIEW_VERSION}_F${filesMd5}_C${gitHash}"
1456 // make install4jBuildDir relative to jalviewDir
1457 def install4jBuildDir = "${install4j_build_dir}/${JAVA_VERSION}"
1460 'JALVIEW_NAME': getdown_txt_title,
1461 'JALVIEW_DIR': "../..",
1462 'OSX_KEYSTORE': OSX_KEYSTORE,
1463 'JSIGN_SH': JSIGN_SH,
1464 'JRE_DIR': getdown_app_dir_java,
1465 'INSTALLER_TEMPLATE_VERSION': install4jTemplateVersion,
1466 'JALVIEW_VERSION': JALVIEW_VERSION,
1467 'JAVA_MIN_VERSION': JAVA_MIN_VERSION,
1468 'JAVA_MAX_VERSION': JAVA_MAX_VERSION,
1469 'JAVA_VERSION': JAVA_VERSION,
1470 'JAVA_INTEGER_VERSION': JAVA_INTEGER_VERSION,
1471 'VERSION': JALVIEW_VERSION,
1472 'MACOS_JAVA_VM_DIR': macosJavaVMDir,
1473 'WINDOWS_JAVA_VM_DIR': windowsJavaVMDir,
1474 'LINUX_JAVA_VM_DIR': linuxJavaVMDir,
1475 'MACOS_JAVA_VM_TGZ': macosJavaVMTgz,
1476 'WINDOWS_JAVA_VM_TGZ': windowsJavaVMTgz,
1477 'LINUX_JAVA_VM_TGZ': linuxJavaVMTgz,
1478 'COPYRIGHT_MESSAGE': install4j_copyright_message,
1479 'MACOS_BUNDLE_ID': install4j_macOS_bundle_id,
1480 'INSTALLER_NAME': install4j_installer_name,
1481 'INSTALL4J_UTILS_DIR': install4j_utils_dir,
1482 'GETDOWN_WEBSITE_DIR': getdown_website_dir,
1483 'GETDOWN_FILES_DIR': getdown_files_dir,
1484 'GETDOWN_RESOURCE_DIR': getdown_resource_dir,
1485 'GETDOWN_DIST_DIR': getdownAppDistDir,
1486 'GETDOWN_ALT_DIR': getdown_app_dir_alt,
1487 'GETDOWN_INSTALL_DIR': getdown_install_dir,
1488 'INFO_PLIST_FILE_ASSOCIATIONS_FILE': install4j_info_plist_file_associations,
1489 'BUILD_DIR': install4jBuildDir,
1492 destination = "${jalviewDir}/${install4jBuildDir}"
1493 buildSelected = true
1495 if (install4j_faster.equals("true") || CHANNEL.startsWith("LOCAL")) {
1497 disableSigning = true
1501 macKeystorePassword = OSX_KEYPASS
1505 println("Using projectFile "+projectFile)
1508 inputs.dir(getdownWebsiteDir)
1509 inputs.file(install4jConfFile)
1510 inputs.file("${install4jDir}/${install4j_info_plist_file_associations}")
1511 inputs.dir(macosJavaVMDir)
1512 inputs.dir(windowsJavaVMDir)
1513 outputs.dir("${jalviewDir}/${install4j_build_dir}/${JAVA_VERSION}")
1517 task sourceDist(type: Tar) {
1519 def VERSION_UNDERSCORES = JALVIEW_VERSION.replaceAll("\\.", "_")
1520 def outputFileName = "${project.name}_${VERSION_UNDERSCORES}.tar.gz"
1521 // cater for buildship < 3.1 [3.0.1 is max version in eclipse 2018-09]
1523 archiveFileName = outputFileName
1524 } catch (Exception e) {
1525 archiveName = outputFileName
1528 compression Compression.GZIP
1543 "**/*.class","$j11modDir/**/*.jar","appletlib","**/*locales",
1545 "utils/InstallAnywhere",
1560 "gradle.properties",
1571 ".settings/org.eclipse.jdt.core.jalview.prefs",
1575 exclude (EXCLUDE_FILES)
1576 include (PROCESS_FILES)
1577 filter(ReplaceTokens,
1581 'Version-Rel': JALVIEW_VERSION,
1582 'Year-Rel': getDate("yyyy")
1587 exclude (EXCLUDE_FILES)
1588 exclude (PROCESS_FILES)
1589 exclude ("appletlib")
1590 exclude ("**/*locales")
1591 exclude ("*locales/**")
1592 exclude ("utils/InstallAnywhere")
1594 exclude (getdown_files_dir)
1595 exclude (getdown_website_dir)
1597 // exluding these as not using jars as modules yet
1598 exclude ("${j11modDir}/**/*.jar")
1601 include(INCLUDE_FILES)
1603 // from (jalviewDir) {
1604 // // explicit includes for stuff that seemed to not get included
1605 // include(fileTree("test/**/*."))
1606 // exclude(EXCLUDE_FILES)
1607 // exclude(PROCESS_FILES)
1614 dependsOn pubhtmlhelp
1616 inputs.dir("${classesDir}/${help_dir}")
1617 outputs.dir("${buildDir}/distributions/${help_dir}")
1621 task j2sSetHeadlessBuild {
1628 task jalviewjsSetEclipseWorkspace {
1629 def propKey = "jalviewjs_eclipse_workspace"
1631 if (project.hasProperty(propKey)) {
1632 propVal = project.getProperty(propKey)
1633 if (propVal.startsWith("~/")) {
1634 propVal = System.getProperty("user.home") + propVal.substring(1)
1637 def propsFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_workspace_location_file}"
1638 def propsFile = file(propsFileName)
1639 def eclipseWsDir = propVal
1640 def props = new Properties()
1642 def writeProps = true
1643 if (( eclipseWsDir == null || !file(eclipseWsDir).exists() ) && propsFile.exists()) {
1644 def ins = new FileInputStream(propsFileName)
1647 if (props.getProperty(propKey, null) != null) {
1648 eclipseWsDir = props.getProperty(propKey)
1653 if (eclipseWsDir == null || !file(eclipseWsDir).exists()) {
1654 def tempDir = File.createTempDir()
1655 eclipseWsDir = tempDir.getAbsolutePath()
1658 eclipseWorkspace = file(eclipseWsDir)
1661 // do not run a headless transpile when we claim to be in Eclipse
1663 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1664 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1666 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1670 props.setProperty(propKey, eclipseWsDir)
1671 propsFile.parentFile.mkdirs()
1672 def bytes = new ByteArrayOutputStream()
1673 props.store(bytes, null)
1674 def propertiesString = bytes.toString()
1675 propsFile.text = propertiesString
1681 println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath())
1684 //inputs.property(propKey, eclipseWsDir) // eclipseWsDir only gets set once this task runs, so will be out-of-date
1685 outputs.file(propsFileName)
1686 outputs.upToDateWhen { eclipseWorkspace.exists() && propsFile.exists() }
1690 task jalviewjsEclipsePaths {
1693 def eclipseRoot = jalviewjs_eclipse_root
1694 if (eclipseRoot.startsWith("~/")) {
1695 eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1)
1697 if (OperatingSystem.current().isMacOsX()) {
1698 eclipseRoot += "/Eclipse.app"
1699 eclipseBinary = "${eclipseRoot}/Contents/MacOS/eclipse"
1700 eclipseProduct = "${eclipseRoot}/Contents/Eclipse/.eclipseproduct"
1701 } else if (OperatingSystem.current().isWindows()) { // check these paths!!
1702 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1703 eclipseRoot += "/eclipse.exe"
1705 eclipseBinary = "${eclipseRoot}/eclipse"
1706 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1707 } else { // linux or unix
1708 if (file("${eclipseRoot}/eclipse").isDirectory() && file("${eclipseRoot}/eclipse/.eclipseproduct").exists()) {
1709 eclipseRoot += "/eclipse"
1711 eclipseBinary = "${eclipseRoot}/eclipse"
1712 eclipseProduct = "${eclipseRoot}/.eclipseproduct"
1715 eclipseVersion = "4.13" // default
1716 def assumedVersion = true
1717 if (file(eclipseProduct).exists()) {
1718 def fis = new FileInputStream(eclipseProduct)
1719 def props = new Properties()
1721 eclipseVersion = props.getProperty("version")
1723 assumedVersion = false
1726 def propKey = "eclipse_debug"
1727 eclipseDebug = (project.hasProperty(propKey) && project.getProperty(propKey).equals("true"))
1730 // do not run a headless transpile when we claim to be in Eclipse
1732 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1733 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1735 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1738 if (!assumedVersion) {
1739 println("ECLIPSE VERSION=${eclipseVersion}")
1745 task printProperties {
1747 description "Output to console all System.properties"
1749 System.properties.each { key, val -> System.out.println("Property: ${key}=${val}") }
1755 dependsOn eclipseProject
1756 dependsOn eclipseClasspath
1757 dependsOn eclipseJdt
1761 // this version (type: Copy) will delete anything in the eclipse dropins folder that isn't in fromDropinsDir
1762 task jalviewjsEclipseCopyDropins(type: Copy) {
1763 dependsOn jalviewjsEclipsePaths
1765 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_eclipse_dropins_dir}", include: "*.jar")
1766 inputFiles += file("${jalviewDir}/${jalviewjsJ2sPlugin}")
1767 def outputDir = "${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}"
1774 // this eclipse -clean doesn't actually work
1775 task jalviewjsCleanEclipse(type: Exec) {
1776 dependsOn eclipseSetup
1777 dependsOn jalviewjsEclipsePaths
1778 dependsOn jalviewjsEclipseCopyDropins
1780 executable(eclipseBinary)
1781 args(["-nosplash", "--launcher.suppressErrors", "-data", eclipseWorkspace.getPath(), "-clean", "-console", "-consoleLog"])
1787 def inputString = """exit
1790 def inputByteStream = new ByteArrayInputStream(inputString.getBytes())
1791 standardInput = inputByteStream
1794 /* not really working yet
1795 jalviewjsEclipseCopyDropins.finalizedBy jalviewjsCleanEclipse
1799 task jalviewjsTransferUnzipSwingJs {
1800 def file_zip = "${jalviewDir}/${jalviewjs_swingjs_zip}"
1804 from zipTree(file_zip)
1805 into "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1809 inputs.file file_zip
1810 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
1814 task jalviewjsTransferUnzipLib {
1815 def zipFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_libjs_dir}", include: "*.zip")
1818 zipFiles.each { file_zip ->
1820 from zipTree(file_zip)
1821 into "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1826 inputs.files zipFiles
1827 outputs.dir "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
1831 task jalviewjsTransferUnzipAllLibs {
1832 dependsOn jalviewjsTransferUnzipSwingJs
1833 dependsOn jalviewjsTransferUnzipLib
1837 task jalviewjsCreateJ2sSettings(type: WriteProperties) {
1839 description "Create the .j2s file from the j2s.* properties"
1841 jalviewjsJ2sProps = project.properties.findAll { it.key.startsWith("j2s.") }.sort { it.key }
1842 def siteDirProperty = "j2s.site.directory"
1843 def setSiteDir = false
1844 jalviewjsJ2sProps.each { prop, val ->
1846 if (prop == siteDirProperty) {
1847 if (!(val.startsWith('/') || val.startsWith("file://") )) {
1848 val = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${val}"
1854 if (!setSiteDir) { // default site location, don't override specifically set property
1855 property(siteDirProperty,"${jalviewDirRelativePath}/${jalviewjsTransferSiteJsDir}")
1858 outputFile = jalviewjsJ2sSettingsFileName
1861 inputs.properties(jalviewjsJ2sProps)
1862 outputs.file(jalviewjsJ2sSettingsFileName)
1867 task jalviewjsEclipseSetup {
1868 dependsOn jalviewjsEclipseCopyDropins
1869 dependsOn jalviewjsSetEclipseWorkspace
1870 dependsOn jalviewjsCreateJ2sSettings
1874 task jalviewjsSyncAllLibs (type: Sync) {
1875 dependsOn jalviewjsTransferUnzipAllLibs
1876 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteLibDir}")
1877 inputFiles += fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}")
1878 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1882 def outputFiles = []
1883 rename { filename ->
1884 outputFiles += "${outputDir}/${filename}"
1890 outputs.files outputFiles
1891 inputs.files inputFiles
1895 task jalviewjsSyncResources (type: Sync) {
1896 def inputFiles = fileTree(dir: resourceDir)
1897 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1901 def outputFiles = []
1902 rename { filename ->
1903 outputFiles += "${outputDir}/${filename}"
1909 outputs.files outputFiles
1910 inputs.files inputFiles
1914 task jalviewjsSyncSiteResources (type: Sync) {
1915 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_site_resource_dir}")
1916 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
1920 def outputFiles = []
1921 rename { filename ->
1922 outputFiles += "${outputDir}/${filename}"
1928 outputs.files outputFiles
1929 inputs.files inputFiles
1933 task jalviewjsSyncBuildProperties (type: Sync) {
1934 dependsOn createBuildProperties
1935 def inputFiles = [file(buildProperties)]
1936 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}"
1940 def outputFiles = []
1941 rename { filename ->
1942 outputFiles += "${outputDir}/${filename}"
1948 outputs.files outputFiles
1949 inputs.files inputFiles
1953 task jalviewjsProjectImport(type: Exec) {
1954 dependsOn eclipseSetup
1955 dependsOn jalviewjsEclipsePaths
1956 dependsOn jalviewjsEclipseSetup
1959 // do not run a headless import when we claim to be in Eclipse
1961 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1962 throw new StopExecutionException("Not running headless import whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1964 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1968 //def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core"
1969 def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview"
1970 executable(eclipseBinary)
1971 args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath])
1975 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
1977 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
1980 inputs.file("${jalviewDir}/.project")
1981 outputs.upToDateWhen {
1982 file(projdir).exists()
1987 task jalviewjsTranspile(type: Exec) {
1988 dependsOn jalviewjsEclipseSetup
1989 dependsOn jalviewjsProjectImport
1990 dependsOn jalviewjsEclipsePaths
1993 // do not run a headless transpile when we claim to be in Eclipse
1995 println("Skipping task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
1996 throw new StopExecutionException("Not running headless transpile whilst IN_ECLIPSE is '${IN_ECLIPSE}'")
1998 println("Running task ${name} as IN_ECLIPSE=${IN_ECLIPSE}")
2002 executable(eclipseBinary)
2003 args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-${jalviewjs_eclipse_build_arg}", eclipse_project_name ])
2007 args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ]
2009 args += [ "-D${j2sHeadlessBuildProperty}=true" ]
2015 stdout = new ByteArrayOutputStream()
2016 stderr = new ByteArrayOutputStream()
2018 def logOutFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}"
2019 def logOutFile = file(logOutFileName)
2020 logOutFile.createNewFile()
2021 logOutFile.text = """ROOT: ${jalviewjs_eclipse_root}
2022 BINARY: ${eclipseBinary}
2023 VERSION: ${eclipseVersion}
2024 WORKSPACE: ${eclipseWorkspace}
2025 DEBUG: ${eclipseDebug}
2028 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
2029 // combine stdout and stderr
2030 def logErrFOS = logOutFOS
2032 if (jalviewjs_j2s_to_console.equals("true")) {
2033 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
2034 new org.apache.tools.ant.util.TeeOutputStream(
2038 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
2039 new org.apache.tools.ant.util.TeeOutputStream(
2044 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
2047 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
2054 if (stdout.toString().contains("Error processing ")) {
2055 // j2s did not complete transpile
2056 //throw new TaskExecutionException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
2057 if (jalviewjs_ignore_transpile_errors.equals("true")) {
2058 println("IGNORING TRANSPILE ERRORS")
2059 println("See eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
2061 throw new GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'")
2066 inputs.dir("${jalviewDir}/${sourceDir}")
2067 outputs.dir("${jalviewDir}/${jalviewjsTransferSiteJsDir}")
2068 outputs.upToDateWhen( { file("${jalviewDir}/${jalviewjsTransferSiteJsDir}${jalviewjs_server_resource}").exists() } )
2072 def jalviewjsCallCore(String name, FileCollection list, String prefixFile, String suffixFile, String jsfile, String zjsfile, File logOutFile, Boolean logOutConsole) {
2074 def stdout = new ByteArrayOutputStream()
2075 def stderr = new ByteArrayOutputStream()
2077 def coreFile = file(jsfile)
2079 msg = "Creating core for ${name}...\nGenerating ${jsfile}"
2081 logOutFile.createNewFile()
2082 logOutFile.append(msg+"\n")
2084 def coreTop = file(prefixFile)
2085 def coreBottom = file(suffixFile)
2086 coreFile.getParentFile().mkdirs()
2087 coreFile.createNewFile()
2088 coreFile.write( coreTop.text )
2093 t.replaceAll("Clazz\\.([^_])","Clazz_${1}")
2094 coreFile.append( t )
2096 msg = "...file '"+f.getPath()+"' does not exist, skipping"
2098 logOutFile.append(msg+"\n")
2101 coreFile.append( coreBottom.text )
2103 msg = "Generating ${zjsfile}"
2105 logOutFile.append(msg+"\n")
2106 def logOutFOS = new FileOutputStream(logOutFile, true) // true == append
2107 def logErrFOS = logOutFOS
2110 classpath = files(["${jalviewDir}/tools/closure_compiler.jar"])
2111 args = [ "--js", jsfile, "--js_output_file", zjsfile ]
2114 msg = "\nRunning '"+commandLine.join(' ')+"'\n"
2116 logOutFile.append(msg+"\n")
2118 if (logOutConsole) {
2119 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
2120 new org.apache.tools.ant.util.TeeOutputStream(
2124 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
2125 new org.apache.tools.ant.util.TeeOutputStream(
2130 standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
2133 errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
2140 logOutFile.append(msg+"\n")
2144 task jalviewjsBuildAllCores {
2146 description "Build the core js lib closures listed in the classlists dir"
2147 dependsOn jalviewjsTranspile
2148 dependsOn jalviewjsTransferUnzipSwingJs
2150 def j2sDir = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${jalviewjs_j2s_subdir}"
2151 def swingJ2sDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${jalviewjs_j2s_subdir}"
2152 def libJ2sDir = "${jalviewDir}/${jalviewjsTransferSiteLibDir}/${jalviewjs_j2s_subdir}"
2153 def jsDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${jalviewjs_js_subdir}"
2154 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}/${jalviewjs_j2s_subdir}/core"
2155 def prefixFile = "${jsDir}/core/coretop2.js"
2156 def suffixFile = "${jsDir}/core/corebottom2.js"
2158 inputs.file prefixFile
2159 inputs.file suffixFile
2161 def classlistFiles = []
2162 // add the classlists found int the jalviewjs_classlists_dir
2163 fileTree(dir: "${jalviewDir}/${jalviewjs_classlists_dir}", include: "*.txt").each {
2165 def name = file.getName() - ".txt"
2172 // _jmol and _jalview cores. Add any other peculiar classlist.txt files here
2173 //classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jmol}"), 'name': "_jvjmol" ]
2174 classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jalview}"), 'name': jalviewjsJalviewCoreName ]
2176 jalviewjsCoreClasslists = []
2178 classlistFiles.each {
2181 def file = hash['file']
2182 if (! file.exists()) {
2183 //println("...classlist file '"+file.getPath()+"' does not exist, skipping")
2184 return false // this is a "continue" in groovy .each closure
2186 def name = hash['name']
2188 name = file.getName() - ".txt"
2196 def list = fileTree(dir: j2sDir, includes: filelist)
2198 def jsfile = "${outputDir}/core${name}.js"
2199 def zjsfile = "${outputDir}/core${name}.z.js"
2201 jalviewjsCoreClasslists += [
2210 outputs.file(jsfile)
2211 outputs.file(zjsfile)
2214 // _stevesoft core. add any cores without a classlist here (and the inputs and outputs)
2215 def stevesoftClasslistName = "_stevesoft"
2216 def stevesoftClasslist = [
2217 'jsfile': "${outputDir}/core${stevesoftClasslistName}.js",
2218 'zjsfile': "${outputDir}/core${stevesoftClasslistName}.z.js",
2219 'list': fileTree(dir: j2sDir, include: "com/stevesoft/pat/**/*.js"),
2220 'name': stevesoftClasslistName
2222 jalviewjsCoreClasslists += stevesoftClasslist
2223 inputs.files(stevesoftClasslist['list'])
2224 outputs.file(stevesoftClasslist['jsfile'])
2225 outputs.file(stevesoftClasslist['zjsfile'])
2228 def allClasslistName = "_all"
2229 def allJsFiles = fileTree(dir: j2sDir, include: "**/*.js")
2230 allJsFiles += fileTree(
2234 // these exlusions are files that the closure-compiler produces errors for. Should fix them
2235 "**/org/jmol/jvxl/readers/IsoIntersectFileReader.js",
2236 "**/org/jmol/export/JSExporter.js"
2239 allJsFiles += fileTree(
2243 // these exlusions are files that the closure-compiler produces errors for. Should fix them
2244 "**/sun/misc/Unsafe.js",
2245 "**/swingjs/jquery/jquery-editable-select.js",
2246 "**/swingjs/jquery/j2sComboBox.js",
2247 "**/sun/misc/FloatingDecimal.js"
2250 def allClasslist = [
2251 'jsfile': "${outputDir}/core${allClasslistName}.js",
2252 'zjsfile': "${outputDir}/core${allClasslistName}.z.js",
2254 'name': allClasslistName
2256 // not including this version of "all" core at the moment
2257 //jalviewjsCoreClasslists += allClasslist
2258 inputs.files(allClasslist['list'])
2259 outputs.file(allClasslist['jsfile'])
2260 outputs.file(allClasslist['zjsfile'])
2263 def logOutFile = file("${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_closure_stdout}")
2264 logOutFile.getParentFile().mkdirs()
2265 logOutFile.createNewFile()
2266 logOutFile.write(getDate("yyyy-MM-dd HH:mm:ss")+" jalviewjsBuildAllCores\n----\n")
2268 jalviewjsCoreClasslists.each {
2269 jalviewjsCallCore(it.name, it.list, prefixFile, suffixFile, it.jsfile, it.zjsfile, logOutFile, jalviewjs_j2s_to_console.equals("true"))
2276 def jalviewjsPublishCoreTemplate(String coreName, String templateName, File inputFile, String outputFile) {
2279 into file(outputFile).getParentFile()
2280 rename { filename ->
2281 if (filename.equals(inputFile.getName())) {
2282 return file(outputFile).getName()
2286 filter(ReplaceTokens,
2290 'MAIN': '"'+mainClass+'"',
2292 'NAME': jalviewjsJalviewTemplateName+" [core ${coreName}]",
2293 'COREKEY': jalviewjs_core_key,
2294 'CORENAME': coreName
2301 task jalviewjsPublishCoreTemplates {
2302 dependsOn jalviewjsBuildAllCores
2303 def inputFileName = "${jalviewDir}/${j2s_coretemplate_html}"
2304 def inputFile = file(inputFileName)
2305 def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
2307 def outputFiles = []
2308 jalviewjsCoreClasslists.each { cl ->
2309 def outputFile = "${outputDir}/${jalviewjsJalviewTemplateName}_${cl.name}.html"
2310 cl['outputfile'] = outputFile
2311 outputFiles += outputFile
2315 jalviewjsCoreClasslists.each { cl ->
2316 jalviewjsPublishCoreTemplate(cl.name, jalviewjsJalviewTemplateName, inputFile, cl.outputfile)
2319 inputs.file(inputFile)
2320 outputs.files(outputFiles)
2324 task jalviewjsSyncCore (type: Sync) {
2325 dependsOn jalviewjsBuildAllCores
2326 dependsOn jalviewjsPublishCoreTemplates
2327 def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteCoreDir}")
2328 def outputDir = "${jalviewDir}/${jalviewjsSiteDir}"
2332 def outputFiles = []
2333 rename { filename ->
2334 outputFiles += "${outputDir}/${filename}"
2340 outputs.files outputFiles
2341 inputs.files inputFiles
2345 // this Copy version of TransferSiteJs will delete anything else in the target dir
2346 task jalviewjsCopyTransferSiteJs(type: Copy) {
2347 dependsOn jalviewjsTranspile
2348 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2349 into "${jalviewDir}/${jalviewjsSiteDir}"
2353 // this Sync version of TransferSite is used by buildship to keep the website automatically up to date when a file changes
2354 task jalviewjsSyncTransferSiteJs(type: Sync) {
2355 from "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2357 into "${jalviewDir}/${jalviewjsSiteDir}"
2364 jalviewjsSyncAllLibs.mustRunAfter jalviewjsCopyTransferSiteJs
2365 jalviewjsSyncResources.mustRunAfter jalviewjsCopyTransferSiteJs
2366 jalviewjsSyncSiteResources.mustRunAfter jalviewjsCopyTransferSiteJs
2367 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsCopyTransferSiteJs
2369 jalviewjsSyncAllLibs.mustRunAfter jalviewjsSyncTransferSiteJs
2370 jalviewjsSyncResources.mustRunAfter jalviewjsSyncTransferSiteJs
2371 jalviewjsSyncSiteResources.mustRunAfter jalviewjsSyncTransferSiteJs
2372 jalviewjsSyncBuildProperties.mustRunAfter jalviewjsSyncTransferSiteJs
2375 task jalviewjsPrepareSite {
2377 description "Prepares the website folder including unzipping files and copying resources"
2378 dependsOn jalviewjsSyncAllLibs
2379 dependsOn jalviewjsSyncResources
2380 dependsOn jalviewjsSyncSiteResources
2381 dependsOn jalviewjsSyncBuildProperties
2382 dependsOn jalviewjsSyncCore
2386 task jalviewjsBuildSite {
2388 description "Builds the whole website including transpiled code"
2389 dependsOn jalviewjsCopyTransferSiteJs
2390 dependsOn jalviewjsPrepareSite
2394 task cleanJalviewjsTransferSite {
2396 delete "${jalviewDir}/${jalviewjsTransferSiteJsDir}"
2397 delete "${jalviewDir}/${jalviewjsTransferSiteLibDir}"
2398 delete "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}"
2399 delete "${jalviewDir}/${jalviewjsTransferSiteCoreDir}"
2404 task cleanJalviewjsSite {
2405 dependsOn cleanJalviewjsTransferSite
2407 delete "${jalviewDir}/${jalviewjsSiteDir}"
2412 task jalviewjsSiteTar(type: Tar) {
2414 description "Creates a tar.gz file for the website"
2415 dependsOn jalviewjsBuildSite
2416 def outputFilename = "jalviewjs-site-${JALVIEW_VERSION}.tar.gz"
2418 archiveFileName = outputFilename
2419 } catch (Exception e) {
2420 archiveName = outputFilename
2423 compression Compression.GZIP
2425 from "${jalviewDir}/${jalviewjsSiteDir}"
2426 into jalviewjs_site_dir // this is inside the tar file
2428 inputs.dir("${jalviewDir}/${jalviewjsSiteDir}")
2432 task jalviewjsServer {
2434 def filename = "jalviewjsTest.html"
2435 description "Starts a webserver on localhost to test the website. See ${filename} to access local site on most recently used port."
2436 def htmlFile = "${jalviewDirAbsolutePath}/${filename}"
2439 SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
2440 def port = Integer.valueOf(jalviewjs_server_port)
2445 while(port < start+1000 && !running) {
2447 def doc_root = new File("${jalviewDirAbsolutePath}/${jalviewjsSiteDir}")
2448 jalviewjsServer = factory.start(doc_root, port)
2450 url = jalviewjsServer.getResourceUrl(jalviewjs_server_resource)
2451 println("SERVER STARTED with document root ${doc_root}.")
2452 println("Go to "+url+" . Run gradle --stop to stop (kills all gradle daemons).")
2453 println("For debug: "+url+"?j2sdebug")
2454 println("For verbose: "+url+"?j2sverbose")
2455 } catch (Exception e) {
2460 <p><a href="${url}">JalviewJS Test. <${url}></a></p>
2461 <p><a href="${url}?j2sdebug">JalviewJS Test with debug. <${url}?j2sdebug></a></p>
2462 <p><a href="${url}?j2sverbose">JalviewJS Test with verbose. <${url}?j2sdebug></a></p>
2464 jalviewjsCoreClasslists.each { cl ->
2465 def urlcore = jalviewjsServer.getResourceUrl(file(cl.outputfile).getName())
2467 <p><a href="${urlcore}">${jalviewjsJalviewTemplateName} [core ${cl.name}]. <${urlcore}></a></p>
2469 println("For core ${cl.name}: "+urlcore)
2472 file(htmlFile).text = htmlText
2475 outputs.file(htmlFile)
2476 outputs.upToDateWhen({false})
2480 task cleanJalviewjsAll {
2482 description "Delete all configuration and build artifacts to do with JalviewJS build"
2483 dependsOn cleanJalviewjsSite
2484 dependsOn jalviewjsEclipsePaths
2487 delete "${jalviewDir}/${jalviewjsBuildDir}"
2488 delete "${jalviewDir}/${eclipse_bin_dir}"
2489 if (eclipseWorkspace != null && file(eclipseWorkspace.getAbsolutePath()+"/.metadata").exists()) {
2490 delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata")
2492 delete "${jalviewDir}/${jalviewjs_j2s_settings}"
2495 outputs.upToDateWhen( { false } )
2499 task jalviewjsIDE_checkJ2sPlugin {
2500 group "00 JalviewJS in Eclipse"
2501 description "Compare the swingjs/net.sf.j2s.core(-j11)?.jar file with the Eclipse IDE's plugin version (found in the 'dropins' dir)"
2504 def j2sPlugin = string("${jalviewDir}/${jalviewjsJ2sPlugin}")
2505 def j2sPluginFile = file(j2sPlugin)
2506 def eclipseHome = System.properties["eclipse.home.location"]
2507 if (eclipseHome == null || ! IN_ECLIPSE) {
2508 throw new StopExecutionException("Cannot find running Eclipse home from System.properties['eclipse.home.location']. Skipping J2S Plugin Check.")
2510 def eclipseJ2sPlugin = "${eclipseHome}/dropins/${j2sPluginFile.getName()}"
2511 def eclipseJ2sPluginFile = file(eclipseJ2sPlugin)
2512 if (!eclipseJ2sPluginFile.exists()) {
2513 def msg = "Eclipse J2S Plugin is not installed (could not find '${eclipseJ2sPlugin}')\nTry running task jalviewjsIDE_copyJ2sPlugin"
2514 System.err.println(msg)
2515 throw new StopExecutionException(msg)
2518 def digest = MessageDigest.getInstance("MD5")
2520 digest.update(j2sPluginFile.text.bytes)
2521 def j2sPluginMd5 = new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
2523 digest.update(eclipseJ2sPluginFile.text.bytes)
2524 def eclipseJ2sPluginMd5 = new BigInteger(1, digest.digest()).toString(16).padLeft(32, '0')
2526 if (j2sPluginMd5 != eclipseJ2sPluginMd5) {
2527 def msg = "WARNING! Eclipse J2S Plugin '${eclipseJ2sPlugin}' is different to this commit's version '${j2sPlugin}'"
2528 System.err.println(msg)
2529 throw new StopExecutionException(msg)
2531 def msg = "Eclipse J2S Plugin is the same as '${j2sPlugin}' (this is good)"
2537 task jalviewjsIDE_copyJ2sPlugin {
2538 group "00 JalviewJS in Eclipse"
2539 description "Copy the swingjs/net.sf.j2s.core(-j11)?.jar file into the Eclipse IDE's 'dropins' dir"
2542 def j2sPlugin = string("${jalviewDir}/${jalviewjsJ2sPlugin}")
2543 def j2sPluginFile = file(j2sPlugin)
2544 def eclipseHome = System.properties["eclipse.home.location"]
2545 if (eclipseHome == null || ! IN_ECLIPSE) {
2546 throw new StopExecutionException("Cannot find running Eclipse home from System.properties['eclipse.home.location']. NOT copying J2S Plugin.")
2548 def eclipseJ2sPlugin = "${eclipseHome}/dropins/${j2sPluginFile.getName()}"
2549 def eclipseJ2sPluginFile = file(eclipseJ2sPlugin)
2550 def msg = "WARNING! Copying this commit's j2s plugin '${j2sPlugin}' to Eclipse J2S Plugin '${eclipseJ2sPlugin}'\n* May require an Eclipse restart"
2551 System.err.println(msg)
2554 eclipseJ2sPluginFile.getParentFile().mkdirs()
2555 into eclipseJ2sPluginFile.getParent()
2561 task jalviewjsIDE_j2sFile {
2562 group "00 JalviewJS in Eclipse"
2563 description "Creates the .j2s file"
2564 dependsOn jalviewjsCreateJ2sSettings
2568 task jalviewjsIDE_SyncCore {
2569 group "00 JalviewJS in Eclipse"
2570 description "Build the core js lib closures listed in the classlists dir and publish core html from template"
2571 dependsOn jalviewjsSyncCore
2575 task jalviewjsIDE_SyncSiteAll {
2576 dependsOn jalviewjsSyncAllLibs
2577 dependsOn jalviewjsSyncResources
2578 dependsOn jalviewjsSyncSiteResources
2579 dependsOn jalviewjsSyncBuildProperties
2583 cleanJalviewjsTransferSite.mustRunAfter jalviewjsIDE_SyncSiteAll
2586 task jalviewjsIDE_PrepareSite {
2587 group "00 JalviewJS in Eclipse"
2588 description "Sync libs and resources to site dir, but not closure cores"
2590 dependsOn jalviewjsIDE_SyncSiteAll
2591 dependsOn cleanJalviewjsTransferSite
2595 task jalviewjsIDE_AssembleSite {
2596 group "00 JalviewJS in Eclipse"
2597 description "Assembles unzipped supporting zipfiles, resources, site resources and closure cores into the Eclipse transpiled site"
2598 dependsOn jalviewjsPrepareSite
2602 task jalviewjsIDE_SiteClean {
2603 group "00 JalviewJS in Eclipse"
2604 description "Deletes the Eclipse transpiled site"
2605 dependsOn cleanJalviewjsSite
2609 task jalviewjsIDE_Server {
2610 group "00 JalviewJS in Eclipse"
2611 description "Starts a webserver on localhost to test the website"
2612 dependsOn jalviewjsServer
2616 // buildship runs this at import or gradle refresh
2617 task eclipseSynchronizationTask {
2618 //dependsOn eclipseSetup
2619 dependsOn createBuildProperties
2621 dependsOn jalviewjsIDE_j2sFile
2622 dependsOn jalviewjsIDE_checkJ2sPlugin
2623 dependsOn jalviewjsIDE_PrepareSite
2628 // buildship runs this at build time or project refresh
2629 task eclipseAutoBuildTask {
2630 //dependsOn jalviewjsIDE_checkJ2sPlugin
2631 //dependsOn jalviewjsIDE_PrepareSite
2637 description "Build the site"
2638 dependsOn jalviewjsBuildSite