From: soares Date: Sat, 9 Nov 2019 16:35:26 +0000 (+0000) Subject: JAL-3210 working on dependencies for publishcoretemplate. tidying X-Git-Tag: Release_2_11_4_0~45^2~18^2~69 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6aec2dea780d21b874707b429964afa91558a6ff;p=jalview.git JAL-3210 working on dependencies for publishcoretemplate. tidying --- diff --git a/build.gradle b/build.gradle index bbba335..76c1c44 100644 --- a/build.gradle +++ b/build.gradle @@ -1697,10 +1697,6 @@ DEBUG: ${eclipseDebug} ---- """ def logOutFOS = new FileOutputStream(logOutFile, true) // true == append - //def logErrFileName = "${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}" - //def logErrFile = file(logFileName) - //logErrFile.createNewFile() - //def logErrFOS = new FileErrputStream(logErrFile, false) // combine stdout and stderr def logErrFOS = logOutFOS @@ -1739,9 +1735,215 @@ DEBUG: ${eclipseDebug} } +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 ) + list.each { + f -> + if (f.exists()) { + def t = f.text + t.replaceAll("Clazz\\.","Clazz_") + t.replaceAll("Class__","Clazz._") + coreFile.append( t ) + } else { + msg = "...file '"+f.getPath()+"' does not exist, skipping" + println(msg) + logOutFile.append(msg+"\n") + } + } + coreFile.append( coreBottom.text ) + + 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", jsfile, "--js_output_file", zjsfile ] + + msg = "\nRunning '"+commandLine.join(' ')+"'\n" + println(msg) + logOutFile.append(msg+"\n") + + 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) + } + } + msg = "--" + println(msg) + logOutFile.append(msg+"\n") +} + + +task jalviewjsNoTranspileBuildAllCores { + dependsOn jalviewjsSitePath + dependsOn jalviewjsTransferUnzipSwingJs + + def j2sDir = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${jalviewjs_j2s_subdir}" + def jsDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${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 classlistFiles = [] + // add the classlists found int the jalviewjs_classlists_dir + fileTree(dir: "${jalviewDir}/${jalviewjs_classlists_dir}", include: "*.txt").each { + file -> + def name = file.getName() - ".txt" + classlistFiles += [ + 'file': file, + 'name': name + ] + } + + // _jmol and _jalview cores. Add any other peculiar classlist.txt files here + classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jmol}"), 'name': "_jvjmol" ] + classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jalview}"), 'name': "_jalview" ] + + def classlists = [] + + classlistFiles.each { + hash -> + + def file = hash['file'] + if (! file.exists()) { + println("...classlist file '"+file.getPath()+"' does not exist, skipping") + return false // this is a "continue" in groovy .each closure + } + def name = hash['name'] + if (name == null) { + name = file.getName() - ".txt" + } + + def filelist = [] + file.eachLine { + line -> + filelist += line + } + def list = fileTree(dir: j2sDir, includes: filelist) + + def jsfile = "${outputDir}/core${name}.js" + def zjsfile = "${outputDir}/core${name}.z.js" + + classlists += [ + 'jsfile': jsfile, + 'zjsfile': zjsfile, + 'list': list + ] + + inputs.file(file) + inputs.files(list) + outputs.file(jsfile) + outputs.file(zjsfile) + } + + // _stevesoft core. add any cores without a classlist here (and the inputs and outputs) + def stevesoftClasslist = [ + 'jsfile': "${outputDir}/core_stevesoft.js", + 'zjsfile': "${outputDir}/core_stevesoft.z.js", + 'list': fileTree(dir: j2sDir, include: "com/stevesoft/pat/**/*.js") + ] + classlists += stevesoftClasslist + inputs.files(stevesoftClasslist['list']) + outputs.file(stevesoftClasslist['jsfile']) + outputs.file(stevesoftClasslist['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")+" jalviewjsNoTranspileBuildAllCores\n----\n") + + classlists.each { + jalviewjsCallCore(it.list, prefixFile, suffixFile, it.jsfile, it.zjsfile, logOutFile, jalviewjs_j2s_to_console.equals("true")) + } + } + +} + + +jalviewjsNoTranspileBuildAllCores.mustRunAfter jalviewjsTranspile + + +task jalviewjsBuildAllCores { + group "JalviewJS" + description "Build the core js lib closures listed in the classlists dir" + dependsOn jalviewjsTranspile + dependsOn jalviewjsNoTranspileBuildAllCores +} + + +task jalviewjsPublishCoreTemplate(type: Sync) { + dependsOn jalviewjsSitePath + dependsOn jalviewjsBuildAllCores + +// clean this up + def inputFile = file("${jalviewDir}/${j2s_template_html}") + def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}" + +// clean this up + def jalviewTemplateName = "JalviewJS" + def jalviewCoreName = "_jalview" + + from inputFile + into outputDir + def outputFiles = [] + rename { filename -> + outputFiles += "${outputDir}/${filename}" + if (filename.equals(inputFile.getName())) { + return "${jalviewTemplateName}_${jalviewCoreName}.html" + } + return null + } + filter(ReplaceTokens, beginToken: '_', endToken: '_', tokens: ['MAIN': mainClass, 'CODE': "null", 'NAME': jalviewTemplateName]) + filter(ReplaceTokens, beginToken: '', endToken: '', tokens: ['NONE': jalviewCoreName]) + preserve { + include "**" + } + outputs.files outputFiles + inputs.files inputFile +} + + task jalviewjsNoTranspileSyncCore (type: Sync) { dependsOn jalviewjsSitePath - dependsOn "jalviewjsNoTranspileBuildAllCores" + dependsOn jalviewjsNoTranspileBuildAllCores + dependsOn jalviewjsPublishCoreTemplate def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteCoreDir}") def outputDir = "${jalviewDir}/${jalviewjsSiteDir}" @@ -1914,13 +2116,6 @@ task cleanJalviewjsAll { } -task jalviewjs { - group "JalviewJS" - description "Build the site" - dependsOn jalviewjsBuildSite -} - - task jalviewjsIDE_CopyTransferSiteJs(type: Copy) { from "${jalviewDir}/${jalviewjsTransferSiteJsDir}" @@ -1935,6 +2130,13 @@ task jalviewjsIDE_j2sFile { } +task jalviewjsIDE_BuildAllCores { + group "00 JalviewJS in Eclipse" + description "Build the core js lib closures listed in the classlists dir" + dependsOn jalviewjsNoTranspileBuildAllCores +} + + task jalviewjsIDE_AssembleSite { group "00 JalviewJS in Eclipse" description "Assembles the Eclipse transpiled site and unzips supporting zipfiles" @@ -1977,214 +2179,8 @@ task eclipseAutoBuildTask { -// closure - -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 ) - list.each { - f -> - if (f.exists()) { - def t = f.text - t.replaceAll("Clazz\\.","Clazz_") - t.replaceAll("Class__","Clazz._") - coreFile.append( t ) - } else { - msg = "...file '"+f.getPath()+"' does not exist, skipping" - println(msg) - logOutFile.append(msg+"\n") - } - } - coreFile.append( coreBottom.text ) - - 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", jsfile, "--js_output_file", zjsfile ] - - msg = "\nRunning '"+commandLine.join(' ')+"'\n" - println(msg) - logOutFile.append(msg+"\n") - - 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) - } - } - msg = "--" - println(msg) - logOutFile.append(msg+"\n") -} - - -task jalviewjsNoTranspileBuildAllCores { - dependsOn jalviewjsSitePath - dependsOn jalviewjsTransferUnzipSwingJs - - def j2sDir = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${jalviewjs_j2s_subdir}" - def jsDir = "${jalviewDir}/${jalviewjsTransferSiteSwingJsDir}/${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 classlistFiles = [] - // add the classlists found int the jalviewjs_classlists_dir - fileTree(dir: "${jalviewDir}/${jalviewjs_classlists_dir}", include: "*.txt").each { - file -> - def name = file.getName() - ".txt" - classlistFiles += [ - 'file': file, - 'name': name - ] - } - - // _jmol and _jalview cores. Add any other peculiar classlist.txt files here - classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jmol}"), 'name': "_jvjmol" ] - classlistFiles += [ 'file': file("${jalviewDir}/${jalviewjs_classlist_jalview}"), 'name': "_jalview" ] - - def classlists = [] - - classlistFiles.each { - hash -> - - def file = hash['file'] - if (! file.exists()) { - println("...classlist file '"+file.getPath()+"' does not exist, skipping") - return false // this is a "continue" in groovy .each closure - } - def name = hash['name'] - if (name == null) { - name = file.getName() - ".txt" - } - - def filelist = [] - file.eachLine { - line -> - filelist += line - } - def list = fileTree(dir: j2sDir, includes: filelist) - - def jsfile = "${outputDir}/core${name}.js" - def zjsfile = "${outputDir}/core${name}.z.js" - - classlists += [ - 'jsfile': jsfile, - 'zjsfile': zjsfile, - 'list': list - ] - - inputs.file(file) - inputs.files(list) - outputs.file(jsfile) - outputs.file(zjsfile) - } - - // _stevesoft core. add any cores without a classlist here (and the inputs and outputs) - def stevesoftClasslist = [ - 'jsfile': "${outputDir}/core_stevesoft.js", - 'zjsfile': "${outputDir}/core_stevesoft.z.js", - 'list': fileTree(dir: j2sDir, include: "com/stevesoft/pat/**/*.js") - ] - classlists += stevesoftClasslist - inputs.files(stevesoftClasslist['list']) - outputs.file(stevesoftClasslist['jsfile']) - outputs.file(stevesoftClasslist['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")+" jalviewjsNoTranspileBuildAllCores\n----\n") - - classlists.each { - jalviewjsCallCore(it.list, prefixFile, suffixFile, it.jsfile, it.zjsfile, logOutFile, jalviewjs_j2s_to_console.equals("true")) - } - } - -} - - -jalviewjsNoTranspileBuildAllCores.mustRunAfter jalviewjsTranspile - - -task jalviewjsBuildAllCores { +task jalviewjs { group "JalviewJS" - description "Build the core js lib closures listed in the classlists dir" - dependsOn jalviewjsTranspile - dependsOn jalviewjsNoTranspileBuildAllCores -} - - -task jalviewjsIDE_BuildAllCores { - group "00 JalviewJS in Eclipse" - description "Build the core js lib closures listed in the classlists dir" - dependsOn jalviewjsNoTranspileBuildAllCores -} - - -task jalviewjsPublishCoreTemplate(type: Sync) { - dependsOn jalviewjsSitePath - dependsOn jalviewjsBuildAllCores - -// clean this up - def inputFile = file("${jalviewDir}/${j2s_template_html}") - def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}" - -// clean this up - def jalviewTemplateName = "JalviewJS" - def jalviewCoreName = "_jalview" - - from inputFile - into outputDir - def outputFiles = [] - rename { filename -> - outputFiles += "${outputDir}/${filename}" - if (filename.equals(inputFile.getName())) { - return "${jalviewTemplateName}_${jalviewCoreName}.html" - } - return null - } - filter(ReplaceTokens, beginToken: '', endToken: '', tokens: ['NONE': jalviewCoreName]) - preserve { - include "**" - } - outputs.files outputFiles - inputs.files inputFile + description "Build the site" + dependsOn jalviewjsBuildSite }