import org.gradle.plugins.ide.eclipse.model.Library
import java.security.MessageDigest
import java.util.regex.Matcher
+import java.util.concurrent.Executors
+import java.util.concurrent.Future
+import java.util.concurrent.ScheduledExecutorService
+import java.util.concurrent.TimeUnit
import groovy.transform.ExternalizeMethods
import groovy.util.XmlParser
import groovy.xml.XmlUtil
eclipseBinary = string("")
eclipseVersion = string("")
eclipseDebug = false
-
+
+ jalviewjsChromiumUserDir = "${jalviewjsBuildDir}/${jalviewjs_chromium_user_dir}"
+ jalviewjsChromiumProfileDir = "${ext.jalviewjsChromiumUserDir}/${jalviewjs_chromium_profile_name}"
+
// ENDEXT
}
outputs.file jalviewjsStderrLaunchFilename
}
+task cleanJalviewjsChromiumUserDir {
+ doFirst {
+ delete jalviewjsChromiumUserDir
+ }
+ outputs.dir jalviewjsChromiumUserDir
+ // always run when depended on
+ outputs.upToDateWhen { !file(jalviewjsChromiumUserDir).exists() }
+}
+
task jalviewjsChromiumProfile {
- def userDir = "${jalviewjsBuildDir}/${jalviewjs_chromium_user_dir}"
- def profileDir = "${userDir}/${jalviewjs_chromium_profile_name}"
- def firstRun = file("${userDir}/First Run")
+ dependsOn cleanJalviewjsChromiumUserDir
+ mustRunAfter cleanJalviewjsChromiumUserDir
- doFirst {
- // clear out old profile
- delete profileDir
+ def firstRun = file("${jalviewjsChromiumUserDir}/First Run")
- mkdir profileDir
+ doFirst {
+ mkdir jalviewjsChromiumProfileDir
firstRun.text = ""
}
-
outputs.file firstRun
}
-task jalviewjsLaunchTest(type: Exec) {
+task jalviewjsLaunchTest {
group "Test"
description "Check JalviewJS opens in a browser"
// dependsOn jalviewjsBuildSite
def stdout
def stderr
doFirst {
- def binary = file(chromiumBinary)
- if (!binary.exists()) {
- throw new StopExecutionException("Could not find chromium binary '${chromiumBinary}'. Cannot run task ${name}.")
- }
-
- stdout = new ByteArrayOutputStream()
- stderr = new ByteArrayOutputStream()
- if (jalviewjs_j2s_to_console.equals("true")) {
- standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
- stdout,
- System.out)
- errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
- stderr,
- System.err)
- } else {
- standardOutput = stdout
- errorOutput = stderr
- }
- }
+ def timeoutms = Integer.valueOf(jalviewjs_chromium_timeout) * 1000
+
+ ScheduledExecutorService executor = Executors.newScheduledThreadPool(3);
+ final Future handler = executor.submit(
+ () -> {
+
+ exec {
+ def binary = file(chromiumBinary)
+ if (!binary.exists()) {
+ throw new StopExecutionException("Could not find chromium binary '${chromiumBinary}'. Cannot run task ${name}.")
+ }
+
+ stdout = new ByteArrayOutputStream()
+ stderr = new ByteArrayOutputStream()
+ if (jalviewjs_j2s_to_console.equals("true")) {
+ standardOutput = new org.apache.tools.ant.util.TeeOutputStream(
+ stdout,
+ System.out)
+ errorOutput = new org.apache.tools.ant.util.TeeOutputStream(
+ stderr,
+ System.err)
+ } else {
+ standardOutput = stdout
+ errorOutput = stderr
+ }
+
+
+ executable(chromiumBinary)
+ args([
+ "--no-sandbox", // --no-sandbox IS USED BY THE THORIUM APPIMAGE ON THE BUILDSERVER
+ "--headless=new",
+ "--disable-gpu",
+ "--timeout=${timeoutms}",
+ "--virtual-time-budget=${timeoutms}",
+ "--user-data-dir=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_chromium_user_dir}",
+ "--profile-directory=${jalviewjs_chromium_profile_name}",
+ "--allow-file-access-from-files",
+ "--enable-logging=stderr",
+ "file://${jalviewDirAbsolutePath}/${jalviewjsStderrLaunchFilename}"
+ ])
+ }
- def timeoutms = Integer.valueOf(jalviewjs_chromium_timeout) * 1000
-
- executable(chromiumBinary)
- args([
- "--no-sandbox", // --no-sandbox IS USED BY THE THORIUM APPIMAGE ON THE BUILDSERVER
- "--headless=new",
- "--disable-gpu",
- "--timeout=${timeoutms}",
- "--virtual-time-budget=${timeoutms}",
- "--user-data-dir=${jalviewDirAbsolutePath}/${jalviewjsBuildDir}/${jalviewjs_chromium_user_dir}",
- "--profile-directory=${jalviewjs_chromium_profile_name}",
- "--allow-file-access-from-files",
- "--enable-logging=stderr",
- "file://${jalviewDirAbsolutePath}/${jalviewjsStderrLaunchFilename}"
- ])
+ }
+
+ )
+
+ executor.schedule(new Runnable(){
+ public void run(){
+ executor.shutdownNow()
+ }
+ }, timeoutms, TimeUnit.MILLISECONDS);
+
+ executor.scheduleAtFixedRate(
+ () -> {
+ if (stderr.toString().contains(jalviewjs_desktop_init_string)) {
+ Thread.sleep(1000)
+ executor.shutdownNow()
+ }
+ },
+ 1, 1, TimeUnit.SECONDS)
+
+ executor.awaitTermination(timeoutms, TimeUnit.MILLISECONDS)
+
+ }
doLast {
def found = false