X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=build.gradle;h=97980622f03e81fa045abb2443893c28615cac8b;hb=d74c7a4abda9d65eec1b2e1b2a8012dce4967210;hp=a333e7dee958158cd30298958e4ed1887b969598;hpb=7d736363504249a051fa237946a953595861b899;p=jalview.git diff --git a/build.gradle b/build.gradle index a333e7d..9798062 100644 --- a/build.gradle +++ b/build.gradle @@ -73,7 +73,6 @@ def libDistDir def compile_source_compatibility def compile_target_compatibility - ext { getdownWebsiteDir = "${jalviewDir}/${getdown_website_dir}/${JAVA_VERSION}" getdownDir = "" @@ -1639,6 +1638,13 @@ task jalviewjsProjectImport(type: Exec) { dependsOn jalviewjsEclipsePaths dependsOn jalviewjsEclipseSetup + doFirst { + // do not run a headless import when we claim to be in Eclipse + if (ECLIPSE_IDE_DEVELOPER.equals("true")) { + throw new StopExecutionException("Not running headless import whilst ECLIPSE_IDE_DEVELOPER is '"+ECLIPSE_IDE_DEVELOPER+"'") + } + } + //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) @@ -1660,6 +1666,13 @@ task jalviewjsTranspile(type: Exec) { dependsOn jalviewjsProjectImport dependsOn jalviewjsEclipsePaths + doFirst { + // do not run a headless transpile when we claim to be in Eclipse + if (ECLIPSE_IDE_DEVELOPER.equals("true")) { + throw new StopExecutionException("Not running headless transpile whilst ECLIPSE_IDE_DEVELOPER is '"+ECLIPSE_IDE_DEVELOPER+"'") + } + } + executable(eclipseBinary) args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-${jalviewjs_eclipse_build_arg}", eclipse_project_name ]) if (eclipseDebug) { @@ -1684,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 @@ -1715,6 +1724,7 @@ DEBUG: ${eclipseDebug} doLast { if (stdout.toString().contains("Error processing ")) { // j2s did not complete transpile + //throw new TaskExecutionException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'") throw new GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log file '${jalviewDir}/${jalviewjsBuildDir}/${jalviewjs_j2s_transpile_stdout}'") } } @@ -1725,9 +1735,214 @@ 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") +} + + +def jalviewjsJalviewTemplateName = "JalviewJS" +def jalviewjsJalviewCoreName = "_jalview" +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': jalviewjsJalviewCoreName ] + + 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 +} + + +def jalviewjsJalviewCoreHtmlFile +task jalviewjsPublishCoreTemplate(type: Sync) { + dependsOn jalviewjsSitePath + dependsOn jalviewjsBuildAllCores + + def inputFile = file("${jalviewDir}/${j2s_template_html}") + def outputDir = "${jalviewDir}/${jalviewjsTransferSiteCoreDir}" + + from inputFile + into outputDir + def outputFiles = [] + jalviewjsJalviewCoreHtmlFile = "${jalviewjsJalviewTemplateName}_${jalviewjsJalviewCoreName}.html" + rename { filename -> + outputFiles += "${outputDir}/${filename}" + if (filename.equals(inputFile.getName())) { + return jalviewjsJalviewCoreHtmlFile + } + return null + } + filter(ReplaceTokens, beginToken: '_', endToken: '_', tokens: ['MAIN': '"'+mainClass+'"', 'CODE': "null", 'NAME': jalviewjsJalviewTemplateName]) + filter(ReplaceTokens, beginToken: '', endToken: '', tokens: ['NONE': jalviewjsJalviewCoreName]) + 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}" @@ -1854,19 +2069,23 @@ task jalviewjsServer { def start = port def running = false def url + def urlcore while(port < start+1000 && !running) { try { def doc_root = new File("${jalviewDirAbsolutePath}/${jalviewjsSiteDir}") def jalviewjsServer = factory.start(doc_root, port) running = true url = jalviewjsServer.getResourceUrl(jalviewjs_server_resource) + urlcore = jalviewjsServer.getResourceUrl(jalviewjsJalviewCoreHtmlFile) println("SERVER STARTED with document root ${doc_root}.") println("Go to "+url+" . Run gradle --stop to stop (kills all gradle daemons).") println("For debug: "+url+"?j2sdebug") + println("For core: "+urlcore) file(htmlFile).text = """ -

Jalview JS Test. <${url}>

-

Jalview JS Test with debug. <${url}?j2sdebug<

+

JalviewJS Test. <${url}>

+

JalviewJS Test with debug. <${url}?j2sdebug<

+

${jalviewjsJalviewTemplateName} Core Test. <${urlcore}>

""" } catch (Exception e) { @@ -1900,13 +2119,6 @@ task cleanJalviewjsAll { } -task jalviewjs { - group "JalviewJS" - description "Build the site" - dependsOn jalviewjsBuildSite -} - - task jalviewjsIDE_CopyTransferSiteJs(type: Copy) { from "${jalviewDir}/${jalviewjsTransferSiteJsDir}" @@ -1921,6 +2133,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" @@ -1963,188 +2182,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 { - dependsOn jalviewjsBuildAllCores + description "Build the site" + dependsOn jalviewjsBuildSite }