From 3ba8b399b3f6e8163b748e208465dbb7bf4efbd5 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 8 Jun 2023 20:58:49 +0100 Subject: [PATCH] JAL-3599 gradle tasks to test JalviewJS launches in a chrome or chromium browser --- build.gradle | 72 ++++++++++++++++++++ gradle.properties | 6 ++ src/jalview/gui/Desktop.java | 19 ++++-- .../chromium_test/jalview_bin_Jalview-stderr.html | 36 ++++++++++ 4 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 utils/jalviewjs/chromium_test/jalview_bin_Jalview-stderr.html diff --git a/build.gradle b/build.gradle index ca599a8..8a7e0d7 100644 --- a/build.gradle +++ b/build.gradle @@ -568,11 +568,13 @@ ext { jalviewjsJ2sAltSettingsFileName = string("${jalviewDir}/${jalviewjs_j2s_alt_settings}") jalviewjsJ2sProps = null jalviewjsJ2sPlugin = jalviewjs_j2s_plugin + jalviewjsStderrLaunchFilename = "${jalviewjsSiteDir}/"+(file(jalviewjs_stderr_launch).getName()) eclipseWorkspace = null eclipseBinary = string("") eclipseVersion = string("") eclipseDebug = false + // ENDEXT } @@ -4207,3 +4209,73 @@ task jalviewjs { dependsOn jalviewjsBuildSite } + +task jalviewjsCopyStderrLaunchFile(type: Copy) { + from file(jalviewjs_stderr_launch) + into jalviewjsSiteDir + + inputs.file jalviewjs_stderr_launch + outputs.file jalviewjsStderrLaunchFilename +} + +task jalviewjsChromiumProfile { + def profileDir = "${jalviewjsBuildDir}/${jalviewjs_chromium_user_dir}/${jalviewjs_chromium_profile_name}" + def firstRun = file("${profileDir}/First Run") + + doFirst { + mkdir profileDir + firstRun.text = "" + } + + outputs.file firstRun +} + +task jalviewjsLaunchTest(type: Exec) { + group "Test" + description "Check JalviewJS opens in a browser" + dependsOn jalviewjsBuildSite + dependsOn jalviewjsCopyStderrLaunchFile + dependsOn jalviewjsChromiumProfile + + def chromiumBinary = jalviewjs_chromium_binary + if (chromiumBinary.startsWith("~/")) { + chromiumBinary = System.getProperty("user.home") + chromiumBinary.substring(1) + } + + doFirst { + def exec = file(chromiumBinary) + if (!exec.exists()) { + throw new GradleException("Could not find chromium binary '${chromiumBinary}'. Cannot run task ${name}.") + } + } + + executable(chromiumBinary) + args([ + "--headless=new", + "--timeout=15000", + "--virtual-time-budget=15000", + "--user-data-dir=${jalviewjsBuildDir}/${jalviewjs_chromium_user_dir}", + "--profile-directory=${jalviewjs_chromium_profile_name}", + "--allow-file-access-from-files", + "--enable-logging=stderr", + jalviewjsStderrLaunchFilename + ]) + + standardOutput = new ByteArrayOutputStream() + errorOutput = new ByteArrayOutputStream() + + doLast { + def found = false + def stderr = errorOutput.toString() + stderr.eachLine { line -> + if (line.contains(jalviewjs_desktop_init_string)) { + println("Found line '"+line+"'") + found = true + return + } + } + if (!found) { + throw new GradleException("Could not find evidence of Desktop launch in JalviewJS.") + } + } +} diff --git a/gradle.properties b/gradle.properties index 7b3a031..93bf118 100644 --- a/gradle.properties +++ b/gradle.properties @@ -260,5 +260,11 @@ jalviewjs_j2s_to_console = true jalviewjs_closure_compiler = tools/closure_compiler.jar jalviewjs_j2s_closure_stdout = j2s-closure.out +# for checking jalviewjs launches okay +jalviewjs_chromium_binary = ~/buildtools/chromium/chrome +jalviewjs_chromium_user_dir = chromium +jalviewjs_chromium_profile_name = BUILD +jalviewjs_stderr_launch = utils/jalviewjs/chromium_test/jalview_bin_Jalview-stderr.html +jalviewjs_desktop_init_string = JALVIEWJS: CREATED DESKTOP testp=gradle.properties diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index bfd700f..2dfe820 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -623,6 +623,12 @@ public class Desktop extends jalview.jbgui.GDesktop } }); desktop.addMouseListener(ma); + + if (Platform.isJS()) + { + // used for jalviewjsTest + jalview.bin.Console.info("JALVIEWJS: CREATED DESKTOP"); + } } /** @@ -3132,10 +3138,14 @@ public class Desktop extends jalview.jbgui.GDesktop String title = "View of desktop"; ImageExporter exporter = new ImageExporter(writer, null, TYPE.EPS, title); - try { + try + { exporter.doExport(of, this, width, height, title); - } catch (ImageOutputException ioex) { - jalview.bin.Console.error("Unexpected error whilst writing Jalview desktop snapshot as EPS",ioex); + } catch (ImageOutputException ioex) + { + jalview.bin.Console.error( + "Unexpected error whilst writing Jalview desktop snapshot as EPS", + ioex); } } @@ -3582,7 +3592,8 @@ public class Desktop extends jalview.jbgui.GDesktop */ public static void closeDesktop() { - if (Desktop.instance != null) { + if (Desktop.instance != null) + { Desktop.instance.closeAll_actionPerformed(null); Desktop.instance.setVisible(false); Desktop.instance.dispose(); diff --git a/utils/jalviewjs/chromium_test/jalview_bin_Jalview-stderr.html b/utils/jalviewjs/chromium_test/jalview_bin_Jalview-stderr.html new file mode 100644 index 0000000..bf7a678 --- /dev/null +++ b/utils/jalviewjs/chromium_test/jalview_bin_Jalview-stderr.html @@ -0,0 +1,36 @@ + + + +SwingJS test Jalview + + + + + +
+
+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 +
+ + -- 1.7.10.2