From 9fe5286cbcbbfdca0e9548e6ab1b6543871a8073 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 7 Nov 2019 15:36:48 +0000 Subject: [PATCH] JAL-3210 Added jalviewjsBuildAllClosures. Improved incrementality of jalviewjsSetEclipseWorkspace and jalviewjsProjectImport and hence jalviewjsTranspile :) --- build.gradle | 182 ++++++++++++++++++++++++++++++++++++----------------- gradle.properties | 3 +- 2 files changed, 127 insertions(+), 58 deletions(-) diff --git a/build.gradle b/build.gradle index a88c42f..52c0385 100644 --- a/build.gradle +++ b/build.gradle @@ -1331,8 +1331,9 @@ task jalviewjsSetEclipseWorkspace { println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath()) } - inputs.property(propKey, eclipseWsDir) + //inputs.property(propKey, eclipseWsDir) // eclipseWsDir only gets set once this task runs, so will be out-of-date outputs.file(propsFileName) + outputs.upToDateWhen { eclipseWorkspace.exists() } } @@ -1619,7 +1620,8 @@ task jalviewjsProjectImport(type: Exec) { dependsOn jalviewjsEclipsePaths dependsOn jalviewjsEclipseSetup - 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/org.eclipse.jdt.core" + def projdir = eclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview" executable(eclipseBinary) args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath]) if (eclipseDebug) { @@ -1628,7 +1630,9 @@ task jalviewjsProjectImport(type: Exec) { args += [ "--launcher.appendVmargs", "-vmargs", "-Dorg.eclipse.equinox.p2.reconciler.dropins.directory=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_eclipse_tmp_dropins_dir}" ] inputs.file("${jalviewDir}/.project") - outputs.upToDateWhen { file(projdir).exists() } + outputs.upToDateWhen { + file(projdir).exists() + } } task jalviewjsTranspile(type: Exec) { @@ -1649,7 +1653,7 @@ task jalviewjsTranspile(type: Exec) { stdout = new ByteArrayOutputStream() stderr = new ByteArrayOutputStream() - def logOutFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}" + def logOutFileName = "${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}" def logOutFile = file(logOutFileName) logOutFile.createNewFile() logOutFile.text = """ROOT: ${jalviewjs_eclipse_root} @@ -1691,7 +1695,7 @@ DEBUG: ${eclipseDebug} doLast { if (stdout.toString().contains("Error processing ")) { // j2s did not complete transpile - throw new GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}'") + throw new GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'") } } @@ -1700,15 +1704,15 @@ DEBUG: ${eclipseDebug} outputs.upToDateWhen( { file("${jalviewDir}/${jalviewjsTransferSiteJsDir}${jalviewjs_server_resource}").exists() } ) } -// this Copy version of TransferSite will delete anything else in the target dir -task jalviewjsCopyTransferSite(type: Copy) { +// this Copy version of TransferSiteJs will delete anything else in the target dir +task jalviewjsCopyTransferSiteJs(type: Copy) { dependsOn jalviewjsTranspile from "${jalviewDir}/${jalviewjsTransferSiteJsDir}" into "${jalviewDir}/${jalviewjsSiteDir}" } // this Sync version of TransferSite is used by buildship to keep the website automatically up to date when a file changes -task jalviewjsSyncTransferSite(type: Sync) { +task jalviewjsSyncTransferSiteJs(type: Sync) { from "${jalviewDir}/${jalviewjsTransferSiteJsDir}" include "**/*.*" into "${jalviewDir}/${jalviewjsSiteDir}" @@ -1717,15 +1721,15 @@ task jalviewjsSyncTransferSite(type: Sync) { } } -jalviewjsSyncLib.mustRunAfter jalviewjsCopyTransferSite -jalviewjsSyncResources.mustRunAfter jalviewjsCopyTransferSite -jalviewjsSyncSiteResources.mustRunAfter jalviewjsCopyTransferSite -jalviewjsSyncBuildProperties.mustRunAfter jalviewjsCopyTransferSite +jalviewjsSyncLib.mustRunAfter jalviewjsCopyTransferSiteJs +jalviewjsSyncResources.mustRunAfter jalviewjsCopyTransferSiteJs +jalviewjsSyncSiteResources.mustRunAfter jalviewjsCopyTransferSiteJs +jalviewjsSyncBuildProperties.mustRunAfter jalviewjsCopyTransferSiteJs -jalviewjsSyncLib.mustRunAfter jalviewjsSyncTransferSite -jalviewjsSyncResources.mustRunAfter jalviewjsSyncTransferSite -jalviewjsSyncSiteResources.mustRunAfter jalviewjsSyncTransferSite -jalviewjsSyncBuildProperties.mustRunAfter jalviewjsSyncTransferSite +jalviewjsSyncLib.mustRunAfter jalviewjsSyncTransferSiteJs +jalviewjsSyncResources.mustRunAfter jalviewjsSyncTransferSiteJs +jalviewjsSyncSiteResources.mustRunAfter jalviewjsSyncTransferSiteJs +jalviewjsSyncBuildProperties.mustRunAfter jalviewjsSyncTransferSiteJs task jalviewjsPrepareSite { group "JalviewJS" @@ -1734,18 +1738,21 @@ task jalviewjsPrepareSite { dependsOn jalviewjsSyncResources dependsOn jalviewjsSyncSiteResources dependsOn jalviewjsSyncBuildProperties + dependsOn jalviewjsSyncCore } task jalviewjsBuildSite { group "JalviewJS" description "Builds the whole website including transpiled code" - dependsOn jalviewjsCopyTransferSite + dependsOn jalviewjsCopyTransferSiteJs dependsOn jalviewjsPrepareSite } task cleanJalviewjsSite { doFirst { delete "${jalviewDir}/${jalviewjsTransferSiteJsDir}" + delete "${jalviewDir}/${jalviewjsTransferSiteLibDir}" + delete "${jalviewDir}/${jalviewjsTransferSiteCoreDir}" delete "${jalviewDir}/${jalviewjsSiteDir}" } } @@ -1833,12 +1840,12 @@ task jalviewjs { } -task jalviewjsIDE_CopyTransferSite(type: Copy) { +task jalviewjsIDE_CopyTransferSiteJs(type: Copy) { from "${jalviewDir}/${jalviewjsTransferSiteJsDir}" into "${jalviewDir}/${jalviewjsSiteDir}" } -task jalviewjsIDE_j2s { +task jalviewjsIDE_j2sFile { group "00 JalviewJS in Eclipse" description "Creates the .j2s file" dependsOn jalviewjsCreateJ2sSettings @@ -1847,7 +1854,7 @@ task jalviewjsIDE_j2s { task jalviewjsIDE_AssembleSite { group "00 JalviewJS in Eclipse" description "Assembles the Eclipse transpiled site and unzips supporting zipfiles" - dependsOn jalviewjsIDE_CopyTransferSite + dependsOn jalviewjsIDE_CopyTransferSiteJs dependsOn jalviewjsPrepareSite } @@ -1866,12 +1873,12 @@ task jalviewjsIDE_Server { // buildship runs this at import task eclipseSynchronizationTask { dependsOn eclipseSetup - dependsOn jalviewjsIDE_j2s + dependsOn jalviewjsIDE_j2sFile } // buildship runs this at build time task eclipseAutoBuildTask { - dependsOn jalviewjsSyncTransferSite + dependsOn jalviewjsSyncTransferSiteJs dependsOn jalviewjsPrepareSite } @@ -1883,14 +1890,21 @@ task eclipseAutoBuildTask { // closure -def jalviewjsCallCore(String name, FileCollection list, String jsDir, String outputDir) { - def coreFileName = "core${name}.js" - def coreFilePath = "${outputDir}/${coreFileName}" - def coreFile = file(coreFilePath) - println("...Generating ${coreFilePath}") - - def coreTop = file("${jsDir}/core/coretop2.js") - def coreBottom = file("${jsDir}/core/corebottom2.js") + +def jalviewjsCallCore(FileCollection list, String prefixFile, String suffixFile, String jsfile, String zjsfile, File logOutFile, Boolean logOutConsole) { + + def stdout = new ByteArrayOutputStream() + def stderr = new ByteArrayOutputStream() + + def coreFile = file(jsfile) + def msg = "" + msg = "Generating ${jsfile}" + println(msg) + logOutFile.createNewFile() + logOutFile.append(msg+"\n") + + def coreTop = file(prefixFile) + def coreBottom = file(suffixFile) coreFile.getParentFile().mkdirs() coreFile.createNewFile() coreFile.write( coreTop.text ) @@ -1902,44 +1916,54 @@ def jalviewjsCallCore(String name, FileCollection list, String jsDir, String out t.replaceAll("Class__","Clazz._") coreFile.append( t ) } else { - println("...file ${line} does not exist, skipping") + msg = "...file "+f.getPath()+" does not exist, skipping" + println(msg) + logOutFile.append(msg+"\n") } } coreFile.append( coreBottom.text ) - def coreZFileName = "core${name}.z.js" - def coreZFilePath = "${outputDir}/${coreZFileName}" - def coreZFile = file(coreZFilePath) - println("...Generating ${coreZFilePath}") + msg = "Generating ${zjsfile}" + println(msg) + logOutFile.append(msg+"\n") + def logOutFOS = new FileOutputStream(logOutFile, true) // true == append + def logErrFOS = logOutFOS javaexec { classpath = files(["${jalviewDir}/tools/closure_compiler.jar"]) - args = [ "--js", coreFileName, "--js_output_file", coreZFileName ] - workingDir = outputDir - } + args = [ "--js", jsfile, "--js_output_file", zjsfile ] - return [ coreFile, coreZFile ] -} + msg = "\nRunning '"+commandLine.join(' ')+"'\n" + println(msg) + logOutFile.append(msg+"\n") -def jalviewjsToJs(String name, String classlist, String jsDir, String j2sDir, String outputDir) { - def filelist = [] - file(classlist).eachLine { - line -> - filelist += line - } - def list = fileTree(dir: j2sDir, includes: filelist) - /* - def list = files() - file(classlist).eachLine { - line -> - list += file("${j2sDir}/${line}") + if (logOutConsole) { + standardOutput = new org.apache.tools.ant.util.TeeOutputStream( + new org.apache.tools.ant.util.TeeOutputStream( + logOutFOS, + stdout), + standardOutput) + errorOutput = new org.apache.tools.ant.util.TeeOutputStream( + new org.apache.tools.ant.util.TeeOutputStream( + logErrFOS, + stderr), + errorOutput) + } else { + standardOutput = new org.apache.tools.ant.util.TeeOutputStream( + logOutFOS, + stdout) + errorOutput = new org.apache.tools.ant.util.TeeOutputStream( + logErrFOS, + stderr) + } } - */ - - return jalviewjsCallCore(name, list, jsDir, outputDir) -// publish-core-template ... here? + msg = "--" + println(msg) + logOutFile.append(msg+"\n") } + + task jalviewjsBuildAllCores { group "JalviewJS" description "Build the core js lib closures" @@ -1948,10 +1972,54 @@ task jalviewjsBuildAllCores { dependsOn jalviewjsTransferUnzipLib dependsOn jalviewjsTranspile + def j2sDir = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${jalviewjs_j2s_subdir}" + def jsDir = "${jalviewDir}/${jalviewjsTransferSiteLibDir}/${jalviewjs_js_subdir}" + def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}/${jalviewjs_j2s_subdir}/core" + def prefixFile = "${jsDir}/core/coretop2.js" + def suffixFile = "${jsDir}/core/corebottom2.js" + + inputs.file prefixFile + inputs.file suffixFile + + def classlists = [] fileTree(dir: "${jalviewDir}/${jalviewjs_classlists_dir}", include: "*.txt").each { file -> def name = file.getName() - ".txt" - jalviewjsToJs(name, file.getAbsolutePath(), "${jalviewDir}/${jalviewjsTransferSiteLibDir}/${jalviewjs_js_subdir}", "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${jalviewjs_j2s_subdir}", "${jalviewDir}/${jalviewjsTransferSiteCoreDir}/${jalviewjs_j2s_subdir}/core") + def filelist = [] + file.eachLine { + line -> + filelist += line + } + def list = fileTree(dir: j2sDir, includes: filelist) + + def coreFileName = "core${name}.js" + def jsfile = "${outputDir}/${coreFileName}" + def coreZFileName = "core${name}.z.js" + def zjsfile = "${outputDir}/${coreZFileName}" + + classlists += [ + 'jsfile': jsfile, + 'zjsfile': zjsfile, + 'list': list + ] + + inputs.file(file) + inputs.files(list) + outputs.file(jsfile) + outputs.file(zjsfile) + } + + + doFirst { + def logOutFile = file("${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_j2s_closure_stdout}") + logOutFile.getParentFile().mkdirs() + logOutFile.createNewFile() + logOutFile.write(getDate("yyyy-MM-dd HH:mm:ss")+" jalviewjsBuildAllCores\n----\n") + + classlists.each { + jalviewjsCallCore(it.list, prefixFile, suffixFile, it.jsfile, it.zjsfile, logOutFile, jalviewjs_j2s_to_console.equals("true")) + } } + } diff --git a/gradle.properties b/gradle.properties index d602a9c..444d333 100644 --- a/gradle.properties +++ b/gradle.properties @@ -195,9 +195,10 @@ j2s.template.html = utils/jalviewjs/template.html #output will be comma-separated: called method,caller class #j2s.prop.j2s.log.all.calls=true -jalviewjs_j2s_stdout = j2s-transpile.out +jalviewjs_j2s_transpile_stdout = j2s-transpile.out #jalviewjs_j2s_stderr = j2s-transpile.err # all going into out jalviewjs_j2s_to_console = true +jalviewjs_j2s_closure_stdout = j2s-closure.out testp=gradle.properties -- 1.7.10.2