From: Ben Soares Date: Fri, 27 Sep 2019 15:47:18 +0000 (+0100) Subject: JAL-3210 Improvements to how incremental build and gradle artefacts play with j2s X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7837ecd37305f0fd7c220c43d63561fbca691f31;p=jalview.git JAL-3210 Improvements to how incremental build and gradle artefacts play with j2s --- diff --git a/build.gradle b/build.gradle index dec0765..9aef0ff 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,8 @@ import org.apache.tools.ant.filters.ReplaceTokens import org.gradle.internal.os.OperatingSystem import org.gradle.plugins.ide.eclipse.model.* import groovy.transform.ExternalizeMethods -import org.eclipse.osgi.* +//import org.eclipse.osgi.* +import com.diffplug.gradle.GoomphCacheLocations /* buildscript { @@ -293,6 +294,20 @@ clean { + + + + + + + + + + + + + +GoomphCacheLocations.override_workspaces = file(jalviewDirAbsolutePath+"/"+goomph_workspace) oomphIde { repoEclipse goomph_eclipse_version jdt { @@ -358,18 +373,32 @@ ideJalviewjsBuild.dependsOn ideCopyDropins -def tempEclipseWorkspace = "" +def jalviewjsBuildDir +def jalviewjsSiteDir +task jalviewjsSitePath { + if (jalviewjs_site_dir.startsWith("/")) { + jalviewjsSiteDir = jalviewjs_site_dir + } else { + def relativeBuildDir = file(jalviewDirAbsolutePath).toPath().relativize(buildDir.toPath()) + jalviewjsBuildDir = "${relativeBuildDir}/jalviewjs" + jalviewjsSiteDir = jalviewjsBuildDir + "/" + jalviewjs_site_dir + } +} + +def tempEclipseWorkspace task jalviewjsSetTempEclipseWorkspace { tempEclipseWorkspace = file(jalviewjs_eclipse_workspace) if (!tempEclipseWorkspace.exists()) { - tempEclipseWorkspace = File.createTempDir() - tempEclipseWorkspace.deleteOnExit() + tempEclipseWorkspace = file("${buildDir}/tmp/eclipse-workspace") + //tempEclipseWorkspace.deleteOnExit() } println("ECLIPSE WORKSPACE: "+tempEclipseWorkspace.getPath()) } task jalviewjsUnzipFiles { + dependsOn jalviewjsSitePath + def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip") zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip @@ -377,18 +406,17 @@ task jalviewjsUnzipFiles { zipFiles.each { file_zip -> copy { from zipTree(file_zip) - into jalviewjs_site_dir + into jalviewjsSiteDir } } } inputs.files zipFiles - outputs.dir jalviewjs_site_dir + outputs.dir jalviewjsSiteDir } -def eclipseBinary def eclipseDropinsDir -def eclipsePluginsDir +def eclipseBinary task jalviewjsEclipsePaths { def eclipseRoot = jalviewjs_eclipse_root if (eclipseRoot.startsWith("~")) { @@ -397,18 +425,14 @@ task jalviewjsEclipsePaths { if (OperatingSystem.current().isMacOsX()) { eclipseRoot += "/Eclipse.app" eclipseDropinsDir = eclipseRoot+"/Contents/Eclipse/dropins" - eclipsePluginsDir = eclipseRoot+"/Contents/Eclipse/plugins" eclipseBinary = eclipseRoot+"/Contents/MacOS/eclipse" } else if (OperatingSystem.current().isWindows()) { // check these paths!! eclipseDropinsDir = eclipseRoot+"/dropins" - eclipsePluginsDir = eclipseRoot+"/plugins" eclipseBinary = eclipseRoot+"/eclipse" } else { // linux or unix eclipseDropinsDir = eclipseRoot+"/dropins" - eclipsePluginsDir = eclipseRoot+"/plugins" eclipseBinary = eclipseRoot+"/eclipse" } - println("ECLIPSE ROOT: "+eclipseRoot) } task jalviewjsEclipseCopyDropins (type: Copy) { @@ -427,43 +451,39 @@ task jalviewjsEclipseCopyDropins (type: Copy) { inputs.files inputFiles } -task jalviewjsEclipseCopyPlugins (type: Copy) { - dependsOn jalviewjsEclipsePaths - def inputFiles = fileTree(jalviewjs_utils_dir+"/"+jalviewjs_eclipse_plugins_dir) - def outputDir = eclipsePluginsDir - - from inputFiles - into outputDir - def outputFiles = [] - rename { filename -> - outputFiles += outputDir+"/"+filename - null - } - outputs.files outputFiles - inputs.files inputFiles -} - task jalviewjsEclipseSetup { dependsOn jalviewjsEclipseCopyDropins - dependsOn jalviewjsEclipseCopyPlugins dependsOn jalviewjsSetTempEclipseWorkspace } task jalviewjsCreateJ2sSettings(type: WriteProperties) { + dependsOn jalviewjsSitePath outputFile (jalviewDir+"/"+jalviewjs_j2s_settings) def props = project.properties.sort { it.key } + def siteDirProperty = "j2s.site.directory" + def setSiteDir = false props.each { prop, val -> if (prop.startsWith("j2s.") && val != null) { + if (prop == siteDirProperty) { + if (!(val.startsWith("/") || val.startsWith("file://") )) { + val = jalviewjsSiteDir+"/"+val + } + setSiteDir = true + } property(prop,val) } + if (!setSiteDir) { + property(siteDirProperty,"${jalviewjsSiteDir}") + } } outputs.file(outputFile) } task jalviewjsCopyResources (type: Copy) { + dependsOn jalviewjsSitePath def inputFiles = fileTree(dir: jalviewjs_resource_dir) - def outputDir = jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir + def outputDir = jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir from inputFiles into outputDir @@ -477,8 +497,9 @@ task jalviewjsCopyResources (type: Copy) { } task jalviewjsCopySiteResources (type: Copy) { + dependsOn jalviewjsSitePath def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir) - def outputDir = jalviewjs_site_dir + def outputDir = jalviewjsSiteDir from inputFiles into outputDir @@ -492,8 +513,9 @@ task jalviewjsCopySiteResources (type: Copy) { } task cleanJalviewjs { + dependsOn jalviewjsSitePath /* - delete jalviewDir+"/"+jalviewjs_site_dir + delete jalviewDir+"/"+jalviewjsSiteDir delete jalviewDir+"/"+eclipse_bin_dir delete file(tempEclipseWorkspace.getAbsolutePath()+"/.metadata") delete jalviewDir+"/"+jalviewjs_j2s_settings @@ -510,24 +532,58 @@ task jalviewjsProjectImport(type: Exec) { executable(eclipseBinary) args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", tempEclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath]) - def projdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core/" + def projdir = tempEclipseWorkspace.getPath()+"/.metadata/.plugins/org.eclipse.core.resources/.projects/jalview/org.eclipse.jdt.core" inputs.file(jalviewDir+"/.project") outputs.dir(projdir) + outputs.upToDateWhen { file(projdir).exists() } } + + + + + + + task jalviewjsTranspile(type: Exec) { dependsOn jalviewjsCreateJ2sSettings dependsOn jalviewjsProjectImport dependsOn jalviewjsEclipsePaths executable(eclipseBinary) args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", tempEclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]) + + def stdout + def stderr + doFirst { + stdout = new ByteArrayOutputStream() + stderr = new ByteArrayOutputStream() + standardOutput = new org.apache.tools.ant.util.TeeOutputStream(new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}"), stdout); + errorOutput = new org.apache.tools.ant.util.TeeOutputStream(new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}"), stderr); + } + doLast { + if (stdout.toString().contains("Error processing ")) { + // j2s did not complete transpile + throw new TaskExecutionException("Error during transpilation:\n${stderr}\n") + } + } + inputs.dir(sourceDir) outputs.dir(eclipse_bin_dir+"/main") - outputs.file(eclipse_bin_dir+"/main/jalview/bin/Jalview.class") - outputs.dir(jalviewjs_site_dir+"/"+jalviewjs_j2s_subdir) + outputs.dir(jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir) + outputs.file(jalviewjsSiteDir+jalviewjs_server_resource) + outputs.upToDateWhen { file(jalviewjsSiteDir+jalviewjs_server_resource).exists() } + } + + + + + + + task jalviewjsBuildSite { + dependsOn jalviewjsSitePath dependsOn jalviewjsUnzipFiles dependsOn jalviewjsCopyResources dependsOn jalviewjsCopySiteResources @@ -545,10 +601,10 @@ task jalviewjsSiteTar(type: Tar) { compression Compression.GZIP - from jalviewjs_site_dir + from jalviewjsSiteDir into jalviewjs_site_dir // this is inside the tar file - inputs.dir(jalviewjs_site_dir) + inputs.dir(jalviewjsSiteDir) } task jalviewjs { @@ -557,6 +613,7 @@ task jalviewjs { def jalviewjsServer = null task jalviewjsServerStart { + dependsOn jalviewjsSitePath doLast { if (jalviewjsServer != null) { @@ -569,9 +626,10 @@ task jalviewjsServerStart { def running = false while(port < start+1000 && !running) { try { - jalviewjsServer = factory.start(new File(jalviewDirAbsolutePath+"/"+jalviewjs_site_dir), port) + def doc_root = new File(jalviewDirAbsolutePath +"/"+ jalviewjsSiteDir) + jalviewjsServer = factory.start(doc_root, port) running = true - println("SERVER STARTED. Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.") + println("SERVER STARTED with document root ${doc_root}.\nGo to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle jalviewjsServerStop to stop.") //println("Ctrl-c to stop.");java.lang.Thread.sleep(Integer.valueOf(jalviewjs_server_wait)*1000); } catch (Exception e) { port++; diff --git a/gradle.properties b/gradle.properties index d2c5394..bab2570 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ jalviewDir = . -JAVA_VERSION = 1.8 -#JAVA_VERSION = 11 +#JAVA_VERSION = 1.8 +JAVA_VERSION = 11 JALVIEW_VERSION = DEVELOPMENT INSTALLATION = Source @@ -40,7 +40,6 @@ dev = false jalviewjs_eclipse_root = ~/buildtools/eclipse/eclipse-jee-2019-06 jalviewjs_utils_dir = utils/jalviewjs -jalviewjs_eclipse_plugins_dir = eclipse/plugins jalviewjs_eclipse_dropins_dir = eclipse/dropins jalviewjs_swingjs_zip = SwingJS-site.zip jalviewjs_libjs_dir = libjs @@ -66,7 +65,7 @@ j2s.excluded.paths = test;testng;util #j2s.testing = null #j2s.compiler.nonqualified.packages = null #j2s.compiler.nonqualified.classes = null -#j2s.compiler.mode = null +j2s.compiler.mode = debug #a semicolon-separated list of package (foo.) or class (foo.bar) replacements to be made j2s.class.replacements = org.apache.log4j.->jalview.javascript.log4j. #j2s.template.html = null @@ -79,7 +78,11 @@ j2s.class.replacements = org.apache.log4j.->jalview.javascript.log4j. #output will be comma-separated: called method,caller class #j2s.prop.j2s.log.all.calls=true +jalviewjs_j2s_stdout = j2s-transpile.out +jalviewjs_j2s_stderr = j2s-transpile.err + spotless_eclipse_version = 4.12.0 -goomph_eclipse_version = 4.13 +goomph_eclipse_version = 4.12 goomph_repo_buildship = https://download.eclipse.org/buildship/updates/e47/releases/3.x/ goomph_feature_buildship = org.eclipse.buildship +goomph_workspace = ../tmp/goomph-workspace diff --git a/utils/jalviewjs/SwingJS-site.zip b/utils/jalviewjs/SwingJS-site.zip index c8c7341..40feffa 100644 Binary files a/utils/jalviewjs/SwingJS-site.zip and b/utils/jalviewjs/SwingJS-site.zip differ diff --git a/utils/jalviewjs/eclipse/plugins/com.seeq.eclipse.importprojects_1.4.0.jar b/utils/jalviewjs/eclipse/dropins/com.seeq.eclipse.importprojects_1.4.0.jar similarity index 100% rename from utils/jalviewjs/eclipse/plugins/com.seeq.eclipse.importprojects_1.4.0.jar rename to utils/jalviewjs/eclipse/dropins/com.seeq.eclipse.importprojects_1.4.0.jar diff --git a/utils/jalviewjs/eclipse/dropins/net.sf.j2s.core.jar b/utils/jalviewjs/eclipse/dropins/net.sf.j2s.core.jar index 87df1d9..e8288a9 100644 Binary files a/utils/jalviewjs/eclipse/dropins/net.sf.j2s.core.jar and b/utils/jalviewjs/eclipse/dropins/net.sf.j2s.core.jar differ