From: soares Date: Wed, 6 Nov 2019 20:59:00 +0000 (+0000) Subject: JAL-3210 work in progress on closures X-Git-Tag: Release_2_11_4_0~45^2~18^2~76 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=581fcc0aab400bcdd52f5c0ec64f34a8fd5e786a;p=jalview.git JAL-3210 work in progress on closures --- diff --git a/build.gradle b/build.gradle index 535f3b9..a88c42f 100644 --- a/build.gradle +++ b/build.gradle @@ -1274,14 +1274,16 @@ task helppages { def jalviewjsBuildDir def jalviewjsSiteDir -def jalviewjsTransferSiteJSDir +def jalviewjsTransferSiteJsDir def jalviewjsTransferSiteLibDir +def jalviewjsTransferSiteCoreDir task jalviewjsSitePath { def relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath()) jalviewjsBuildDir = "${relativeBuildDir}/jalviewjs" jalviewjsSiteDir = "${jalviewjsBuildDir}/${jalviewjs_site_dir}" - jalviewjsTransferSiteJSDir = "${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js" + jalviewjsTransferSiteJsDir = "${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_js" jalviewjsTransferSiteLibDir = "${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_lib" + jalviewjsTransferSiteCoreDir = "${jalviewjsBuildDir}/tmp/${jalviewjs_site_dir}_core" } def eclipseWorkspace @@ -1494,14 +1496,14 @@ task jalviewjsCreateJ2sSettings(type: WriteProperties) { if (val != null) { if (prop == siteDirProperty) { if (!(val.startsWith('/') || val.startsWith("file://") )) { - val = "${jalviewDir}/${jalviewjsTransferSiteJSDir}/${val}" + val = "${jalviewDir}/${jalviewjsTransferSiteJsDir}/${val}" } setSiteDir = true } property(prop,val) } if (!setSiteDir) { // default site location, don't override specifically set property - property(siteDirProperty,"${jalviewDir}/${jalviewjsTransferSiteJSDir}") + property(siteDirProperty,"${jalviewDir}/${jalviewjsTransferSiteJsDir}") } } inputs.properties(j2s_props) @@ -1534,6 +1536,26 @@ task jalviewjsSyncLib (type: Sync) { inputs.files inputFiles } +task jalviewjsSyncCore (type: Sync) { + dependsOn jalviewjsSitePath + dependsOn "jalviewjsBuildAllCores" + def inputFiles = fileTree(dir: "${jalviewDir}/${jalviewjsTransferSiteCoreDir}") + def outputDir = "${jalviewDir}/${jalviewjsSiteDir}" + + from inputFiles + into outputDir + def outputFiles = [] + rename { filename -> + outputFiles += "${outputDir}/${filename}" + null + } + preserve { + include "**" + } + outputs.files outputFiles + inputs.files inputFiles +} + task jalviewjsSyncResources (type: Sync) { dependsOn jalviewjsSitePath def inputFiles = fileTree(dir: "${jalviewDir}/${resourceDir}") @@ -1674,20 +1696,20 @@ DEBUG: ${eclipseDebug} } inputs.dir("${jalviewDir}/${sourceDir}") - outputs.dir("${jalviewDir}/${jalviewjsTransferSiteJSDir}") - outputs.upToDateWhen( { file("${jalviewDir}/${jalviewjsTransferSiteJSDir}${jalviewjs_server_resource}").exists() } ) + outputs.dir("${jalviewDir}/${jalviewjsTransferSiteJsDir}") + 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) { dependsOn jalviewjsTranspile - from "${jalviewDir}/${jalviewjsTransferSiteJSDir}" + 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) { - from "${jalviewDir}/${jalviewjsTransferSiteJSDir}" + from "${jalviewDir}/${jalviewjsTransferSiteJsDir}" include "**/*.*" into "${jalviewDir}/${jalviewjsSiteDir}" preserve { @@ -1723,7 +1745,7 @@ task jalviewjsBuildSite { task cleanJalviewjsSite { doFirst { - delete "${jalviewDir}/${jalviewjsTransferSiteJSDir}" + delete "${jalviewDir}/${jalviewjsTransferSiteJsDir}" delete "${jalviewDir}/${jalviewjsSiteDir}" } } @@ -1812,7 +1834,7 @@ task jalviewjs { task jalviewjsIDE_CopyTransferSite(type: Copy) { - from "${jalviewDir}/${jalviewjsTransferSiteJSDir}" + from "${jalviewDir}/${jalviewjsTransferSiteJsDir}" into "${jalviewDir}/${jalviewjsSiteDir}" } @@ -1852,3 +1874,84 @@ task eclipseAutoBuildTask { dependsOn jalviewjsSyncTransferSite dependsOn jalviewjsPrepareSite } + + + + + + + + +// 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") + 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 { + println("...file ${line} does not exist, skipping") + } + } + coreFile.append( coreBottom.text ) + + def coreZFileName = "core${name}.z.js" + def coreZFilePath = "${outputDir}/${coreZFileName}" + def coreZFile = file(coreZFilePath) + println("...Generating ${coreZFilePath}") + + javaexec { + classpath = files(["${jalviewDir}/tools/closure_compiler.jar"]) + args = [ "--js", coreFileName, "--js_output_file", coreZFileName ] + workingDir = outputDir + } + + return [ coreFile, coreZFile ] +} + +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}") + } + */ + + return jalviewjsCallCore(name, list, jsDir, outputDir) +// publish-core-template ... here? +} + +task jalviewjsBuildAllCores { + group "JalviewJS" + description "Build the core js lib closures" + + dependsOn jalviewjsSitePath + dependsOn jalviewjsTransferUnzipLib + dependsOn jalviewjsTranspile + + 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") + } +} diff --git a/gradle.properties b/gradle.properties index fe03c9c..d602a9c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -155,13 +155,17 @@ jalviewjs_swingjs_zip = swingjs/SwingJS-site.zip jalviewjs_j2s_plugin = swingjs/net.sf.j2s.core.jar jalviewjs_libjs_dir = utils/jalviewjs/libjs jalviewjs_site_resource_dir = utils/jalviewjs/site-resources +jalviewjs_classlists_dir = utils/jalviewjs/classlists jalviewjs_j2s_settings = .j2s #jalviewjs_eclipse_workspace = ~/tmp/eclipse-workspace # these 3 files/dirs found in build/jalviewjs jalviewjs_eclipse_tmp_dropins_dir = eclipse_dropins jalviewjs_eclipse_workspace_location_file = eclipse_workspace_location jalviewjs_site_dir = site +# these dirs are subdirs of the site dir +jalviewjs_swingjs_subdir = swingjs jalviewjs_j2s_subdir = swingjs/j2s +jalviewjs_js_subdir = swingjs/js #jalviewjs_eclipseBuildArg = build jalviewjs_eclipse_build_arg = cleanBuild jalviewjs_server_port = 9001 diff --git a/classlists/jalview.txt b/utils/jalviewjs/classlists/jalview.txt similarity index 100% rename from classlists/jalview.txt rename to utils/jalviewjs/classlists/jalview.txt diff --git a/classlists/jvexamplefile.txt b/utils/jalviewjs/classlists/jvexamplefile.txt similarity index 100% rename from classlists/jvexamplefile.txt rename to utils/jalviewjs/classlists/jvexamplefile.txt