From: Ben Soares Date: Fri, 15 Mar 2024 12:39:49 +0000 (+0000) Subject: JAL-4320 Improve the inputs and outputs dependencies of jalviewjs build tasks X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=19aa434e7ce0085dcb4f04173df53efa506533ae;p=jalview.git JAL-4320 Improve the inputs and outputs dependencies of jalviewjs build tasks --- diff --git a/build.gradle b/build.gradle index 51c6ef2..89df34d 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ import java.util.concurrent.Executors import java.util.concurrent.Future import java.util.concurrent.ScheduledExecutorService import java.util.concurrent.TimeUnit +import java.nio.file.Path import groovy.transform.ExternalizeMethods import groovy.util.XmlParser import groovy.xml.XmlUtil @@ -559,12 +560,12 @@ ext { if (IN_ECLIPSE) { jalviewjsTransferSiteJsDir = string(jalviewjsSiteDir) } else { - jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js") + jalviewjsTransferSiteJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}/js") } - jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib") - jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_swingjs") - jalviewjsTransferSiteMergeDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_merge") - jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core") + jalviewjsTransferSiteLibDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}/lib") + jalviewjsTransferSiteSwingJsDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}/swingjs") + jalviewjsTransferSiteMergeDir = string("${jalviewjsBuildDir}/merge/${jalviewjs_site_dir}") + jalviewjsTransferSiteCoreDir = string("${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}/core") jalviewjsJalviewCoreHtmlFile = string("") jalviewjsJalviewCoreName = string(jalviewjs_core_name) jalviewjsCoreClasslists = [] @@ -3438,68 +3439,46 @@ jalviewjsEclipseCopyDropins.finalizedBy jalviewjsCleanEclipse */ -task jalviewjsTransferUnzipSwingJs { - def file_zip = "${jalviewDir}/${jalviewjs_swingjs_zip}" - - doLast { - copy { - from zipTree(file_zip) - into "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}" - } - } - - inputs.file file_zip - outputs.dir "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}" +task jalviewjsTransferUnzipSwingJs(type: Copy) { + from zipTree( "${jalviewDir}/${jalviewjs_swingjs_zip}" ) + into "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}" } -task jalviewjsTransferUnzipLib { +task jalviewjsTransferUnzipLib(type: Copy) { def zipFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_libjs_dir}", include: "*.zip").sort() - doLast { - zipFiles.each { file_zip -> - copy { - from zipTree(file_zip) - into "${jalviewDir}/${jalviewjsTransferSiteLibDir}" - - // rename files in jsmol/j2s/... to swingjs/j2s/... - if (file_zip.getName().startsWith("Jmol-j2s-site")) { - eachFile { fcd -> - // jsmol/... -> swingjs/... - def relPathSegments = fcd.relativePath.getSegments() - if (relPathSegments[0] == "jsmol") { - def newRelPathSegments = relPathSegments - newRelPathSegments[0] = "swingjs" - fcd.relativePath = new RelativePath(true, newRelPathSegments) - } - } + zipFiles.each { file_zip -> + from zipTree(file_zip) + + // rename files in jsmol/j2s/... to swingjs/j2s/... + if (file_zip.getName().startsWith("Jmol-j2s-site")) { + eachFile { fcd -> + // jsmol/... -> swingjs/... + def relPathSegments = fcd.relativePath.getSegments() + if (relPathSegments[0] == "jsmol") { + def newRelPathSegments = relPathSegments + newRelPathSegments[0] = "swingjs" + fcd.relativePath = new RelativePath(true, newRelPathSegments) } + } + } - // The following replace() is needed due to a mismatch in Jmol calls to - // colorPtToFFRGB$javajs_util_T3d when only colorPtToFFRGB$javajs_util_T3 is defined - // in the SwingJS.zip (github or the one distributed with JSmol) - if (file_zip.getName().startsWith("Jmol-SwingJS")) { - filter { line -> - def l = "" - while(!line.equals(l)) { - line = line.replace('colorPtToFFRGB$javajs_util_T3d', 'colorPtToFFRGB$javajs_util_T3') - l = line - } - return line - } + // The following replace() is needed due to a mismatch in Jmol calls to + // colorPtToFFRGB$javajs_util_T3d when only colorPtToFFRGB$javajs_util_T3 is defined + // in the SwingJS.zip (github or the one distributed with JSmol) + if (file_zip.getName().startsWith("Jmol-SwingJS")) { + filter { line -> + def l = "" + while(!line.equals(l)) { + line = line.replace('colorPtToFFRGB$javajs_util_T3d', 'colorPtToFFRGB$javajs_util_T3') + l = line } + return line } } } - - inputs.files zipFiles - outputs.dir "${jalviewDir}/${jalviewjsTransferSiteLibDir}" -} - - -task jalviewjsTransferUnzipAllLibs { - dependsOn jalviewjsTransferUnzipLib - dependsOn jalviewjsTransferUnzipSwingJs + into "${jalviewDir}/${jalviewjsTransferSiteLibDir}" } @@ -3540,47 +3519,81 @@ task jalviewjsEclipseSetup { } -task jalviewjsSyncAllLibs (type: Sync) { - dependsOn jalviewjsTransferUnzipAllLibs - def inputFiles = [] - inputFiles += fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteLibDir}") - inputFiles += fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}") +task jalviewjsSyncLibs (type: Sync) { + dependsOn jalviewjsTransferUnzipLib + dependsOn jalviewjsTransferUnzipSwingJs + + def inputDir = file("${jalviewDir}/${jalviewjsTransferSiteLibDir}") + def inputFiles = fileTree(dir: inputDir) def outputDir = "${jalviewDir}/${jalviewjsSiteDir}" from inputFiles into outputDir def outputFiles = [] - rename { filename -> - outputFiles += "${outputDir}/${filename}" - null + inputFiles.each{ file -> + def rfile = inputDir.toPath().relativize(file.toPath()) + def ofile = new File("${outputDir}/${rfile}") + outputFiles += "${ofile}" } preserve { - include "**" + include "**/*" + } + + duplicatesStrategy "EXCLUDE" + + outputs.files outputFiles + inputs.files inputFiles +} + +task jalviewjsSyncSwingJS (type: Sync) { + dependsOn jalviewjsTransferUnzipSwingJs + mustRunAfter jalviewjsSyncLibs + + def inputDir = file("${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}") + def inputFiles = fileTree(dir: inputDir) + def outputDir = "${jalviewDir}/${jalviewjsSiteDir}" + + from inputFiles + into outputDir + def outputFiles = [] + inputFiles.each{ file -> + def rfile = inputDir.toPath().relativize(file.toPath()) + def ofile = new File("${outputDir}/${rfile}") + outputFiles += "${ofile}" + } + preserve { + include "**/*" } - // should this be exclude really ? No, swingjs dir should be transferred last (and overwrite) duplicatesStrategy "INCLUDE" outputs.files outputFiles inputs.files inputFiles } +task jalviewjsSyncAllLibs { + dependsOn jalviewjsSyncLibs + dependsOn jalviewjsSyncSwingJS +} + task jalviewjsSyncResources (type: Sync) { dependsOn buildResources - def inputFiles = fileTree(dir: resourcesBuildDir) + def inputDir = file(resourcesBuildDir) + def inputFiles = fileTree(dir: inputDir) def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}" from inputFiles into outputDir def outputFiles = [] - rename { filename -> - outputFiles += "${outputDir}/${filename}" - null + inputFiles.each{ file -> + def rfile = inputDir.toPath().relativize(file.toPath()) + def ofile = new File("${outputDir}/${rfile}") + outputFiles += "${ofile}" } preserve { - include "**" + include "**/*" } outputs.files outputFiles inputs.files inputFiles @@ -3588,19 +3601,22 @@ task jalviewjsSyncResources (type: Sync) { task jalviewjsSyncSiteResources (type: Sync) { - def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjs_site_resource_dir}") + def inputDir = file("${jalviewDir}/${jalviewjs_site_resource_dir}") + def inputFiles = fileTree(dir: inputDir) def outputDir = "${jalviewDir}/${jalviewjsSiteDir}" from inputFiles into outputDir def outputFiles = [] - rename { filename -> - outputFiles += "${outputDir}/${filename}" - null + inputFiles.each{ file -> + def rfile = inputDir.toPath().relativize(file.toPath()) + def ofile = new File("${outputDir}/${rfile}") + outputFiles += "${ofile}" } preserve { - include "**" + include "**/*" } + outputs.files outputFiles inputs.files inputFiles } @@ -3608,19 +3624,24 @@ task jalviewjsSyncSiteResources (type: Sync) { task jalviewjsSyncBuildProperties (type: Sync) { dependsOn createBuildProperties - def inputFiles = [file(buildProperties)] + + def f = file(buildProperties) + def inputDir = f.getParentFile() + def inputFiles = [f] def outputDir = "${jalviewDir}/${jalviewjsSiteDir}/${jalviewjs_j2s_subdir}" from inputFiles into outputDir def outputFiles = [] - rename { filename -> - outputFiles += "${outputDir}/${filename}" - null + inputFiles.each{ file -> + def rfile = inputDir.toPath().relativize(file.toPath()) + def ofile = new File("${outputDir}/${rfile}") + outputFiles += "${ofile}" } preserve { - include "**" + include "**/*" } + outputs.files outputFiles inputs.files inputFiles } @@ -3642,7 +3663,8 @@ task jalviewjsProjectImport(type: Exec) { } //def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core" - def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview" + def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/${eclipse_project_name}" + executable(eclipseBinary) args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath]) if (eclipseDebug) { @@ -3652,19 +3674,22 @@ task jalviewjsProjectImport(type: Exec) { if (!IN_ECLIPSE) { args += [ "-D${j2sHeadlessBuildProperty}=true" ] args += [ "-D${jalviewjs_j2s_alt_file_property}=${jalviewjsJ2sAltSettingsFileName}" ] + inputs.file("${jalviewjsJ2sAltSettingsFileName}") } - inputs.file("${jalviewDir}/.project") - outputs.upToDateWhen { - file(projdir).exists() - } + outputs.upToDateWhen({ + if (IN_ECLIPSE) { + return true + } + def projDirExists = file(projdir).exists() + return projDirExists + }) } task jalviewjsTranspile(type: Exec) { - dependsOn jalviewjsEclipseSetup dependsOn jalviewjsProjectImport - dependsOn jalviewjsEclipsePaths + if (!IN_ECLIPSE) { dependsOn jalviewjsEnableAltFileProperty } @@ -3791,74 +3816,118 @@ ECLIPSE DEBUG: ${eclipseDebug} } } + if (IN_ECLIPSE) { + inputs.file(jalviewjsJ2sSettingsFileName) + } else { + inputs.file(jalviewjsJ2sAltSettingsFileName) + } inputs.dir("${jalviewDir}/${sourceDir}") - outputs.dir("${jalviewDir}/${jalviewjsTransferSiteJsDir}") - outputs.upToDateWhen( { file("${jalviewDir}/${jalviewjsTransferSiteJsDir}${jalviewjs_server_resource}").exists() } ) + + def inputJavaDir = file("${jalviewDir}/${sourceDir}") + def inputJavaFiles = fileTree(dir: inputJavaDir) + def outputJsDir = "${jalviewDir}/${jalviewjsTransferSiteJsDir}" + def outputJsFiles = [] + inputJavaFiles.each{ file -> + def rfile = inputJavaDir.toPath().relativize(file.toPath()) + def ofile = new File("${outputJsDir}/${rfile}") + def ofilenamejs = ofile.getPath() + if (ofilenamejs.endsWith(".java")) { + ofilenamejs = ofilenamejs.substring(0,ofilenamejs.length()-4)+"js" + } + outputJsFiles += "${ofilenamejs}" + } + + outputs.files outputJsFiles + outputs.file("${jalviewDir}/${jalviewjsTransferSiteJsDir}${jalviewjs_server_resource}") } -task jalviewjsTranserSiteMergeLibDirs (type: Sync) { - dependsOn jalviewjsTransferUnzipAllLibs +task jalviewjsTransferSiteMergeLibDir (type: Copy) { + dependsOn jalviewjsTransferUnzipLib + + def outputDir = "${jalviewDir}/${jalviewjsTransferSiteMergeDir}" + + // This takes the outputs of jalviewjsTransferUnzipLib + from jalviewjsTransferUnzipLib + into outputDir + + includeEmptyDirs = false + exclude "**/*.html" + exclude "**/*.htm" + + // should this be exclude really ? No, swingjs dir should be transferred last (and overwrite) + duplicatesStrategy "INCLUDE" +} + +task jalviewjsTransferSiteMergeSwingJsDir (type: Copy) { dependsOn jalviewjsTransferUnzipSwingJs - dependsOn jalviewjsTranspile - def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteLibDir}") - // merge swingjs lib last - inputFiles += fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}") + mustRunAfter jalviewjsTransferSiteMergeLibDir def outputDir = "${jalviewDir}/${jalviewjsTransferSiteMergeDir}" - from inputFiles + // This takes the outputs of jalviewjsTransferUnzipSwingJs + from jalviewjsTransferUnzipSwingJs into outputDir - def outputFiles = [] - rename { filename -> - outputFiles += "${outputDir}/${filename}" - null - } + includeEmptyDirs = false exclude "**/*.html" exclude "**/*.htm" // should this be exclude really ? No, swingjs dir should be transferred last (and overwrite) duplicatesStrategy "INCLUDE" - - outputs.files outputFiles - inputs.files inputFiles } - -task jalviewjsTranserSiteMergeSwingDir (type: Sync) { - dependsOn jalviewjsTransferUnzipAllLibs - dependsOn jalviewjsTransferUnzipSwingJs +task jalviewjsTransferSiteMergeSiteJsDir (type: Copy) { dependsOn jalviewjsTranspile - // merge jalview files very last - def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteJsDir}") + mustRunAfter jalviewjsTransferSiteMergeLibDir + mustRunAfter jalviewjsTransferSiteMergeSwingJsDir + def inputDir = file("${jalviewDir}/${jalviewjsTransferSiteJsDir}") def outputDir = "${jalviewDir}/${jalviewjsTransferSiteMergeDir}" - - from inputFiles into outputDir - def outputFiles = [] - rename { filename -> - outputFiles += "${outputDir}/${filename}" - null - } - preserve { - include "**" + from { + def inputFiles = fileTree(dir: inputDir) + return inputFiles } - // should this be exclude really ? No, jalview dir should be transferred last (and overwrite) + includeEmptyDirs = false + exclude "**/*.html" + exclude "**/*.htm" + + // should this be exclude really ? No, swingjs dir should be transferred last (and overwrite) duplicatesStrategy "INCLUDE" - outputs.files outputFiles - inputs.files inputFiles + // SiteJs files should take priority and write over existing files if different + // so we define the output files + outputs.upToDateWhen( + { + def transpiledFiles = jalviewjsTransferSiteMergeSiteJsDir.getOutputs().getFiles() + def inputFiles = fileTree(dir: inputDir) + if (inputFiles.size() < transpiledFiles.size()) { + return false + } + def retVal = ! inputFiles.any { file -> + def rfile = inputDir.toPath().relativize(file.toPath()) + def ofile = new File("${outputDir}/${rfile}") + if (!ofile.exists() || ofile.lastModified() < file.lastModified()) { + return true // this is NOTted to false + } + } + + return retVal + } + ) + + inputs.files jalviewjsTranspile } -task jalviewjsTranserSiteMergeDirs { - dependsOn jalviewjsTranserSiteMergeLibDirs - dependsOn jalviewjsTranserSiteMergeSwingDir +task jalviewjsTransferSiteMergeDirs { + dependsOn jalviewjsTransferSiteMergeLibDir + dependsOn jalviewjsTransferSiteMergeSwingJsDir + dependsOn jalviewjsTransferSiteMergeSiteJsDir } @@ -3906,7 +3975,7 @@ def jalviewjsCallCore(String name, FileCollection list, String prefixFile, Strin main = "com.google.javascript.jscomp.CommandLineRunner" jvmArgs = [ "-Dfile.encoding=UTF-8" ] args = [ "--compilation_level", jalviewjs_closure_compiler_optimization_level, "--warning_level", "QUIET", "--charset", "UTF-8", "--js", jsfile, "--js_output_file", zjsfile ] - maxHeapSize = "2g" + maxHeapSize = "4g" msg = "\nRunning '"+commandLine.join(' ')+"'\n" println(msg) @@ -3946,7 +4015,7 @@ def jalviewjsCallCore(String name, FileCollection list, String prefixFile, Strin task jalviewjsBuildAllCores { group "JalviewJS" description "Build the core js lib closures listed in the classlists dir" - dependsOn jalviewjsTranserSiteMergeDirs + dependsOn jalviewjsTransferSiteMergeDirs def j2sDir = "${jalviewDir}/${jalviewjsTransferSiteMergeDir}/${jalviewjs_j2s_subdir}" def swingJ2sDir = "${jalviewDir}/${jalviewjsTransferSiteMergeDir}/${jalviewjs_j2s_subdir}" @@ -4012,41 +4081,6 @@ task jalviewjsBuildAllCores { outputs.file(zjsfile) } - // _all core - def allClasslistName = "_all" - def allJsFiles = fileTree(dir: j2sDir, include: "**/*.js") - allJsFiles += fileTree( - dir: libJ2sDir, - include: "**/*.js", - excludes: [ - // these exlusions are files that the closure-compiler produces errors for. Should fix them - "**/org/jmol/jvxl/readers/IsoIntersectFileReader.js", - "**/org/jmol/export/JSExporter.js" - ] - ) - allJsFiles += fileTree( - dir: swingJ2sDir, - include: "**/*.js", - excludes: [ - // these exlusions are files that the closure-compiler produces errors for. Should fix them - "**/sun/misc/Unsafe.js", - "**/swingjs/jquery/jquery-editable-select.js", - "**/swingjs/jquery/j2sComboBox.js", - "**/sun/misc/FloatingDecimal.js" - ] - ) - def allClasslist = [ - 'jsfile': "${outputDir}/core${allClasslistName}.js", - 'zjsfile': "${outputDir}/core${allClasslistName}.z.js", - 'list': allJsFiles, - 'name': allClasslistName - ] - // not including this version of "all" core at the moment - //jalviewjsCoreClasslists += allClasslist - inputs.files(allClasslist['list']) - outputs.file(allClasslist['jsfile']) - outputs.file(allClasslist['zjsfile']) - doFirst { def logOutFile = file("${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_closure_stdout}") logOutFile.getParentFile().mkdirs() @@ -4114,19 +4148,22 @@ task jalviewjsSyncCore (type: Sync) { dependsOn jalviewjsBuildAllCores dependsOn jalviewjsPublishCoreTemplates - def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteCoreDir}") + def inputDir = file("${jalviewDir}/${jalviewjsTransferSiteCoreDir}") + def inputFiles = fileTree(dir: inputDir) def outputDir = "${jalviewDir}/${jalviewjsSiteDir}" from inputFiles into outputDir def outputFiles = [] - rename { filename -> - outputFiles += "${outputDir}/${filename}" - null + inputFiles.each{ file -> + def rfile = inputDir.toPath().relativize(file.toPath()) + def ofile = new File("${outputDir}/${rfile}") + outputFiles += "${ofile}" } preserve { - include "**" + include "**/*" } + outputs.files outputFiles inputs.files inputFiles } @@ -4134,7 +4171,7 @@ task jalviewjsSyncCore (type: Sync) { // this Copy version of TransferSiteJs will delete anything else in the target dir task jalviewjsCopyTransferSiteMergeDir(type: Copy) { - dependsOn jalviewjsTranserSiteMergeDirs + dependsOn jalviewjsTransferSiteMergeDirs from "${jalviewDir}/${jalviewjsTransferSiteMergeDir}" into "${jalviewDir}/${jalviewjsSiteDir}" @@ -4156,7 +4193,7 @@ task jalviewjsSyncTransferSiteJs(type: Sync) { include "**/*.*" into "${jalviewDir}/${jalviewjsSiteDir}" preserve { - include "**" + include "**/*" } } diff --git a/gradle.properties b/gradle.properties index fbc9dc5..cae63c8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -221,8 +221,8 @@ jalviewjs_site_dir = site jalviewjs_swingjs_subdir = swingjs jalviewjs_j2s_subdir = swingjs/j2s jalviewjs_js_subdir = swingjs/js -#jalviewjs_eclipseBuildArg = build -jalviewjs_eclipse_build_arg = cleanBuild +jalviewjs_eclipse_build_arg = build +#jalviewjs_eclipse_build_arg = cleanBuild jalviewjs_server_port = 9001 jalviewjs_server_wait = 30 jalviewjs_server_resource = /jalview_bin_Jalview.html