From 164f00da2cf73ebd3811df895e41a44ffdeae056 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Fri, 11 Oct 2019 17:23:25 +0100 Subject: [PATCH] JAL-3210 Just about working transpilation. Some work needed for new Java 11 classes --- build.gradle | 462 ++++++++++++++++++++++++----- gradle.properties | 55 +++- src/org/json/simple/JSONValue.java | 2 + utils/jalviewjs/template.html | 32 ++ utils/{ => testlibs}/classgraph-4.1.6.jar | Bin 346926 -> 346926 bytes 5 files changed, 474 insertions(+), 77 deletions(-) create mode 100644 utils/jalviewjs/template.html rename utils/{ => testlibs}/classgraph-4.1.6.jar (100%) diff --git a/build.gradle b/build.gradle index f02d8ad..07c744f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,13 @@ import org.apache.tools.ant.filters.ReplaceTokens -//import org.apache.tools.ant.filters.ReplaceRegexp import org.gradle.internal.os.OperatingSystem -import org.gradle.plugins.ide.eclipse.model.* - +import org.gradle.plugins.ide.eclipse.model.Output +import org.gradle.plugins.ide.eclipse.model.Library import groovy.transform.ExternalizeMethods buildscript { dependencies { classpath 'org.openclover:clover:4.3.1' - classpath 'org.apache.commons:commons-compress:1.18' } } @@ -30,6 +28,10 @@ repositories { } } +dependencies { + compile 'org.apache.commons:commons-compress:1.18' +} + mainClassName = launcherClass def cloverInstrDir = file("$buildDir/$cloverSourcesInstrDir") def classes = "$jalviewDir/$classesDir" @@ -164,6 +166,8 @@ ext { */ gitHash = "" gitBranch = "" + + jalviewjsServer = "" } def JAVA_INTEGER_VERSION @@ -241,6 +245,7 @@ sourceSets { runtimeClasspath = compileClasspath } + clover { java { srcDirs = [ cloverInstrDir ] @@ -277,8 +282,9 @@ sourceSets { compileClasspath += files(sourceSets.main.java.outputDir) } - compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"]) compileClasspath += fileTree(dir: "$jalviewDir/$libDir", include: ["*.jar"]) + compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir/testnglibs", include: ["**/*.jar"]) + compileClasspath += fileTree(dir: "$jalviewDir/$utilsDir/testlibs", include: ["**/*.jar"]) runtimeClasspath = compileClasspath } @@ -312,83 +318,88 @@ eclipse { classpath { //defaultOutputDir = sourceSets.main.java.outputDir def removeThese = [] - configurations.each{ if (it.isCanBeResolved()) { - removeThese += it + configurations.each{ + if (it.isCanBeResolved()) { + removeThese += it + } } - } - minusConfigurations += removeThese - plusConfigurations = [ ] - file { - - whenMerged { cp -> - def removeTheseToo = [] - HashMap addedSrcPath = new HashMap<>(); - cp.entries.each { entry -> - if (entry.kind == 'src') { - if (addedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) { - removeTheseToo += entry - } else { - addedSrcPath.putAt(entry.path, true) + minusConfigurations += removeThese + plusConfigurations = [ ] + file { + + whenMerged { cp -> + def removeTheseToo = [] + HashMap alreadyAddedSrcPath = new HashMap<>(); + cp.entries.each { entry -> + if (entry.kind == 'src') { + if (alreadyAddedSrcPath.getAt(entry.path) || !(entry.path == "src" || entry.path == "test")) { + removeTheseToo += entry + } else { + alreadyAddedSrcPath.putAt(entry.path, true) + } } } - } - cp.entries.removeAll(removeTheseToo) - - print ("CP="+cp.inspect()) - - cp.entries += new Output("bin/main") - cp.entries += new Library(fileReference(helpParentDir)) - cp.entries += new Library(fileReference(resourceDir)) - - HashMap addedLibPath = new HashMap<>(); + cp.entries.removeAll(removeTheseToo) - // changing from sourcesets.main.classpath to specific Java version lib - //sourceSets.main.compileClasspath.each{ - fileTree("$jalviewDir/$libDistDir").include("**/*.jar").include("*.jar").each { - //don't want to add outputDir as eclipse is using its own output dir in bin/main - if (it.isDirectory() || ! it.exists()) { - // don't add dirs to classpath - return + if (file(eclipse_bin_dir+"/main").isDirectory()) { + cp.entries += new Output(eclipse_bin_dir+"/main") } - def itPath = it.toString() - if (itPath.startsWith(jalviewDirAbsolutePath+"/")) { - itPath = itPath.substring(jalviewDirAbsolutePath.length()+1) + if (file(helpParentDir).isDirectory()) { + cp.entries += new Library(fileReference(helpParentDir)) } - if (addedLibPath.get(itPath)) { - //println("Not adding duplicate entry "+itPath) - } else { - //println("Adding entry "+itPath) - cp.entries += new Library(fileReference(itPath)) - addedLibPath.put(itPath, true) + if (file(resourceDir).isDirectory()) { + cp.entries += new Library(fileReference(resourceDir)) } - } - // changing from sourcesets.main.classpath to specific Java version lib - //sourceSets.test.compileClasspath.each{ - fileTree(dir: "$jalviewDir/$utilsDir", include: ["**/*.jar"]).each { - //if ((it.isDirectory() || ! it.exists()) && ! (it.equals(sourceSets.main.java.outputDir))) { - //no longer want to add outputDir as eclipse is using its own output dir in bin/main - if (it.isDirectory() || ! it.exists()) { - // don't add dirs to classpath - return false // groovy "break" in .each loop - } - def itPath = it.toString() - if (itPath.startsWith(jalviewDirAbsolutePath+"/")) { - itPath = itPath.substring(jalviewDirAbsolutePath.length()+1) - } - if (addedLibPath.get(itPath)) { - // don't duplicate - } else { - def lib = new Library(fileReference(itPath)) - // this doesn't work... yet. Adding test=true attribute using withXml below - //def attrs = new Node(null, 'attributes', ["test":"true"]) - //lib.appendNode(attrs) // - cp.entries += lib - addedLibPath.put(itPath, true) + HashMap alreadyAddedLibPath = new HashMap<>(); + + sourceSets.main.compileClasspath.findAll { it.name.endsWith(".jar") }.each { + //don't want to add outputDir as eclipse is using its own output dir in bin/main + if (it.isDirectory() || ! it.exists()) { + // don't add dirs to classpath + return + } + def itPath = it.toString() + if (itPath.startsWith(jalviewDirAbsolutePath+"/")) { + // make relative path + itPath = itPath.substring(jalviewDirAbsolutePath.length()+1) + } + if (alreadyAddedLibPath.get(itPath)) { + //println("Not adding duplicate entry "+itPath) + } else { + //println("Adding entry "+itPath) + cp.entries += new Library(fileReference(itPath)) + alreadyAddedLibPath.put(itPath, true) + } } + + //fileTree(dir: "$jalviewDir/$utilsDir", include: ["test*/*.jar"]).each { + sourceSets.test.compileClasspath.findAll { it.name.endsWith(".jar") }.each { + //no longer want to add outputDir as eclipse is using its own output dir in bin/main + if (it.isDirectory() || ! it.exists()) { + // don't add dirs to classpath + return false // groovy "break" in .each closure + } + def itPath = it.toString() + if (itPath.startsWith(jalviewDirAbsolutePath+"/")) { + itPath = itPath.substring(jalviewDirAbsolutePath.length()+1) + } + if (alreadyAddedLibPath.get(itPath)) { + // don't duplicate + } else { + def lib = new Library(fileReference(itPath)) + /* this doesn't work... yet. Adding test=true attribute using withXml below + def attrs = new Node(null, 'attributes') + attrs.appendNode('attribute', ["name":"test","value":"true"]) + lib.appendNode(attrs) + /**/ + cp.entries += lib + alreadyAddedLibPath.put(itPath, true) + } } - } + + } // whenMerged // withXml changes ignored by buildship, these add the "test=true" attribute withXml { @@ -420,9 +431,12 @@ eclipse { } } } // withXML + + } // file containers 'org.eclipse.buildship.core.gradleclasspathcontainer' + } // classpath jdt { @@ -431,6 +445,7 @@ eclipse { targetCompatibility = compile_target_compatibility javaRuntimeName = eclipse_java_runtime_name + // add in jalview project specific properties/preferences into eclipse core preferences file { withProperties { props -> def jalview_prefs = new Properties() @@ -444,10 +459,9 @@ eclipse { } } } - } - //synchronizationTasks eclipseClasspath - //autoBuildTasks eclipseClasspath + } // jdt + } task cloverInstr() { @@ -1247,3 +1261,303 @@ task helppages { inputs.dir("$classes/$helpDir") outputs.dir("$helpOutputDir") } + +def eclipseWorkspace +task jalviewjsSetEclipseWorkspace { + def eclipseWsDir = jalviewjs_eclipse_workspace + eclipseWorkspace = file(eclipseWsDir) + if (!eclipseWorkspace.exists()) { + eclipseWorkspace = file("${buildDir}/../tmp/eclipse-workspace") + //eclipseWorkspace.deleteOnExit() + } + println("ECLIPSE WORKSPACE: "+eclipseWorkspace.getPath()) +} + +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 + } +} + + + +task jalviewjsUnzipFiles { + dependsOn jalviewjsSitePath + + def zipFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_libjs_dir).include("*.zip") + zipFiles += jalviewjs_utils_dir+"/"+jalviewjs_swingjs_zip + + doLast { + zipFiles.each { file_zip -> + copy { + from zipTree(file_zip) + into jalviewjsSiteDir + } + } + } + + inputs.files zipFiles + outputs.dir jalviewjsSiteDir +} + +def eclipseDropinsDir +def eclipseBinary +task jalviewjsEclipsePaths { + def eclipseRoot + eclipseRoot = jalviewjs_eclipse_root + if (eclipseRoot.startsWith("~")) { + eclipseRoot = System.getProperty("user.home") + eclipseRoot.substring(1) + } + if (OperatingSystem.current().isMacOsX()) { + eclipseRoot += "/Eclipse.app" + eclipseDropinsDir = eclipseRoot+"/Contents/Eclipse/dropins" + eclipseBinary = eclipseRoot+"/Contents/MacOS/eclipse" + } else if (OperatingSystem.current().isWindows()) { // check these paths!! + eclipseDropinsDir = eclipseRoot+"/dropins" + eclipseBinary = eclipseRoot+"/eclipse" + } else { // linux or unix + eclipseDropinsDir = eclipseRoot+"/dropins" + eclipseBinary = eclipseRoot+"/eclipse" + } +} + +task jalviewjsEclipseCopyDropins { + dependsOn jalviewjsEclipsePaths + def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_eclipse_dropins_dir, include: "*.jar") + def outputDir = eclipseDropinsDir + + inputs.files inputFiles + inputFiles.each { file -> + outputs.file(outputDir+"/"+file.name) + } + + doLast { + def outputFiles = [] + inputFiles.each { file -> + copy { + from file + into outputDir + } + } + } +} + +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 jalviewjsEclipseSetup { + dependsOn jalviewjsEclipseCopyDropins + dependsOn jalviewjsSetEclipseWorkspace + dependsOn jalviewjsCreateJ2sSettings +} + +task jalviewjsCopyResources (type: Copy) { + dependsOn jalviewjsSitePath + def inputFiles = fileTree(dir: jalviewjs_resource_dir) + def outputDir = jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir + + from inputFiles + into outputDir + def outputFiles = [] + rename { filename -> + outputFiles += outputDir+"/"+filename + null + } + outputs.files outputFiles + inputs.files inputFiles +} + +task jalviewjsCopySiteResources (type: Copy) { + dependsOn jalviewjsSitePath + def inputFiles = fileTree(dir: jalviewjs_utils_dir+"/"+jalviewjs_site_resource_dir) + def outputDir = jalviewjsSiteDir + + from inputFiles + into outputDir + def outputFiles = [] + rename { filename -> + outputFiles += outputDir+"/"+filename + null + } + outputs.files outputFiles + inputs.files inputFiles +} + +task cleanJalviewjs { + //delete jalviewjsBuildDir + //delete jalviewDir+"/"+eclipse_bin_dir + //delete file(eclipseWorkspace.getAbsolutePath()+"/.metadata") + //delete jalviewDir+"/"+jalviewjs_j2s_settings +} + +task jalviewjsProjectImport(type: Exec) { + // work out how to do this! + dependsOn eclipseProject + dependsOn eclipseClasspath + dependsOn eclipseJdt + dependsOn jalviewjsEclipsePaths + dependsOn jalviewjsEclipseSetup + executable(eclipseBinary) + args(["-nosplash", "--launcher.suppressErrors", "-application", "com.seeq.eclipse.importprojects.headlessimport", "-data", eclipseWorkspace.getPath(), "-import", jalviewDirAbsolutePath]) + + def projdir = eclipseWorkspace.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 jalviewjsEclipseSetup + dependsOn jalviewjsProjectImport + dependsOn jalviewjsEclipsePaths + executable(eclipseBinary) + args(["-nosplash", "--launcher.suppressErrors", "-application", "org.eclipse.jdt.apt.core.aptBuild", "-data", eclipseWorkspace, "-"+jalviewjs_eclipseBuildArg, eclipse_project_name ]) + + def stdout + def stderr + doFirst { + stdout = new ByteArrayOutputStream() + stderr = new ByteArrayOutputStream() + + if (jalviewjs_j2s_to_console.equals("true")) { + standardOutput = new org.apache.tools.ant.util.TeeOutputStream( + new org.apache.tools.ant.util.TeeOutputStream( + new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}"), + stdout), + standardOutput) + errorOutput = new org.apache.tools.ant.util.TeeOutputStream( + new org.apache.tools.ant.util.TeeOutputStream( + new FileOutputStream("${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}"), + stderr), + errorOutput) + } else { + 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 GradleException("Error during transpilation:\n${stderr}\nSee eclipse transpile log files '${jalviewjsBuildDir}/${jalviewjs_j2s_stdout}' and '${jalviewjsBuildDir}/${jalviewjs_j2s_stderr}'\n") + } + } + + inputs.dir(sourceDir) + outputs.dir(eclipse_bin_dir+"/main") + outputs.files( + fileTree( + dir: jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir, + includes: [ "**/*.js" ], + excludes: [ + //jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir+"/intervalstore/**", + //jalviewjsSiteDir+"/"+jalviewjs_j2s_subdir+"/org/json/**", + "intervalstore/**", + "org/json/**", + ] + ).files + ) + outputs.file(jalviewjsSiteDir+jalviewjs_server_resource) + +} + +jalviewjsUnzipFiles.mustRunAfter jalviewjsTranspile +jalviewjsTranspile.mustRunAfter jalviewjsCopyResources +jalviewjsTranspile.mustRunAfter jalviewjsCopySiteResources + +task jalviewjsPrepareSite { + group "JalviewJS" + description "Prepares the website folder including unzipping files and copying resources" + dependsOn jalviewjsSitePath + dependsOn jalviewjsUnzipFiles + dependsOn jalviewjsCopyResources + dependsOn jalviewjsCopySiteResources +} + +task jalviewjsBuildSite { + group "JalviewJS" + description "Builds the whole website including transpiled code" + dependsOn jalviewjsPrepareSite + dependsOn jalviewjsTranspile +} + +task jalviewjsSiteTar(type: Tar) { + group "JalviewJS" + description "Creates a tar.gz file for the website" + dependsOn jalviewjsBuildSite + def outputFilename = "jalviewjs-site-${JALVIEW_VERSION}.tar.gz" + try { + archiveFileName = outputFilename + } catch (Exception e) { + archiveName = outputFilename + } + + compression Compression.GZIP + + from jalviewjsSiteDir + into jalviewjs_site_dir // this is inside the tar file + + inputs.dir(jalviewjsSiteDir) +} + +task jalviewjsServer { + group "JalviewJS" + description "Starts a webserver on localhost to test the website" + dependsOn jalviewjsSitePath + doLast { + + SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory() + def port = Integer.valueOf(jalviewjs_server_port) + def start = port + def running = false + while(port < start+1000 && !running) { + try { + def doc_root = new File(jalviewDirAbsolutePath +"/"+ jalviewjsSiteDir) + jalviewjsServer = factory.start(doc_root, port) + running = true + println("SERVER STARTED with document root ${doc_root}.") + println("Go to "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+" . Run gradle --stop to stop (kills all gradle daemons).") + println("For debug: "+jalviewjsServer.getResourceUrl(jalviewjs_server_resource)+"?j2sdebug") + } catch (Exception e) { + port++; + } + } + + } + +} + +task jalviewjs { + dependsOn jalviewjsBuildSite +} + + diff --git a/gradle.properties b/gradle.properties index 2dbdad3..85929f8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -121,8 +121,6 @@ OSX_KEYSTORE = OSX_KEYPASS = JSIGN_SH = echo -eclipse_extra_jdt_prefs_file = .settings/org.eclipse.jdt.core.jalview.prefs - pandoc_exec = /usr/local/bin/pandoc,/usr/bin/pandoc dev = false @@ -139,4 +137,55 @@ RUNRSYNC=false bamboo_channelbase = https://builds.jalview.org/browse bamboo_planKey = bamboo_getdown_channel_suffix = /latest/artifact/shared/getdown-channel - \ No newline at end of file + +eclipse_extra_jdt_prefs_file = .settings/org.eclipse.jdt.core.jalview.prefs +eclipse_project_name = jalview +eclipse_bin_dir = bin + +jalviewjs_eclipse_root = ~/buildtools/eclipse/eclipse-jee-2019-06 + +jalviewjs_utils_dir = utils/jalviewjs +jalviewjs_eclipse_dropins_dir = eclipse/dropins +jalviewjs_swingjs_zip = SwingJS-site.zip +jalviewjs_libjs_dir = libjs +jalviewjs_resource_dir = resources +jalviewjs_site_resource_dir = site-resources +jalviewjs_site_dir = site +jalviewjs_j2s_subdir = swingjs/j2s +jalviewjs_j2s_settings_file = dot_j2s +jalviewjs_j2s_settings = .j2s +jalviewjs_eclipse_workspace = ../tmp/eclipse-workspace +#jalviewjs_eclipseBuildArg = build +jalviewjs_eclipseBuildArg = cleanBuild +jalviewjs_server_port = 9001 +jalviewjs_server_wait = 30 +jalviewjs_server_resource = /jalview_bin_Jalview.html + +j2s.compiler.status = enable +#j2s.site.directory = null +#j2s.log.methods.declared = null +#j2s.log.methods.called = null +#a semicolon-separated list of package-level file paths to be excluded +j2s.excluded.paths = test;testng;util +#j2s.testing = null +#j2s.compiler.nonqualified.packages = null +#j2s.compiler.nonqualified.classes = 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 = utils/jalviewjs/template.html +#output file name for logging methods declared - delete the file to regenerate a listing +#j2s.prop.j2s.log.methods.declared=swingjs/methodsDeclared_csv +#output file name for logging methods called - delete the file to regenerate a listing +#j2s.prop.j2s.log.methods_called=swingjs/methodsCalled_csv +#if set, every instance of methods called will be logged +#otherwise, only the first call to a method will be logged +#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 +jalviewjs_j2s_to_console = true + + + diff --git a/src/org/json/simple/JSONValue.java b/src/org/json/simple/JSONValue.java index 5da3cd0..d6b2185 100644 --- a/src/org/json/simple/JSONValue.java +++ b/src/org/json/simple/JSONValue.java @@ -41,6 +41,7 @@ public class JSONValue { * {@code null}; please use {@link JSONValue#parseWithException(Reader)} * instead */ + @Deprecated public static Object parse(Reader in){ try{ JSONParser parser=new JSONParser(); @@ -71,6 +72,7 @@ public class JSONValue { * {@code null}; please use {@link JSONValue#parseWithException(String)} * instead */ + @Deprecated public static Object parse(String s){ StringReader in=new StringReader(s); return parse(in); diff --git a/utils/jalviewjs/template.html b/utils/jalviewjs/template.html new file mode 100644 index 0000000..7c20d44 --- /dev/null +++ b/utils/jalviewjs/template.html @@ -0,0 +1,32 @@ + + + +SwingJS test _NAME_ + + + + + +
+
+This is System.out. clear it
Add ?j2snocore to URL to see full class list; ?j2sdebug to use uncompressed j2s/core files
get _j2sClassList.txt +
+ + diff --git a/utils/classgraph-4.1.6.jar b/utils/testlibs/classgraph-4.1.6.jar similarity index 100% rename from utils/classgraph-4.1.6.jar rename to utils/testlibs/classgraph-4.1.6.jar -- 1.7.10.2