From ee193d8e943cc026ad52f1174c77cf9622ac6c0e Mon Sep 17 00:00:00 2001 From: jleyba Date: Thu, 2 May 2019 16:48:10 -0700 Subject: [PATCH] The JettyAppServer crashes if it can't find javascript resources on startup. This is not ideal with bazel since we're still sorting out build rules and the data dependencies haven't been nailed down. As a quick fix to move forward, introduce a system property to ignore the missing JS roots: -Dorg.openqa.selenium.environment.webserver.ignoreMissingJsRoots=true The server will still crash if it cannot find common/src/web, as those dependencies are critical for the selenium test suite. --- .../environment/webserver/JettyAppServer.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/java/client/test/org/openqa/selenium/environment/webserver/JettyAppServer.java b/java/client/test/org/openqa/selenium/environment/webserver/JettyAppServer.java index 42ea763b582f2..4d943e35e6564 100644 --- a/java/client/test/org/openqa/selenium/environment/webserver/JettyAppServer.java +++ b/java/client/test/org/openqa/selenium/environment/webserver/JettyAppServer.java @@ -56,6 +56,7 @@ import org.seleniumhq.jetty9.util.ssl.SslContextFactory; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.net.URL; import java.nio.file.Files; @@ -115,10 +116,10 @@ public JettyAppServer(String hostName, int httpPort, int httpsPort) { Path webSrc = locate("common/src/web"); ServletContextHandler defaultContext = addResourceHandler( DEFAULT_CONTEXT_PATH, webSrc); - ServletContextHandler jsContext = addResourceHandler( - JS_SRC_CONTEXT_PATH, locate("javascript")); - addResourceHandler(CLOSURE_CONTEXT_PATH, locate("third_party/closure/goog")); - addResourceHandler(THIRD_PARTY_JS_CONTEXT_PATH, locate("third_party/js")); + + addJsResourceHandler(JS_SRC_CONTEXT_PATH, "javascript"); + addJsResourceHandler(CLOSURE_CONTEXT_PATH, "third_party/closure/goog"); + addJsResourceHandler(THIRD_PARTY_JS_CONTEXT_PATH, "third_party/js"); TemporaryFilesystem tempFs = TemporaryFilesystem.getDefaultTmpFS(); tempPageDir = tempFs.createTempDir("pages", "test"); @@ -148,6 +149,22 @@ public JettyAppServer(String hostName, int httpPort, int httpsPort) { addServlet(defaultContext, "/createPage", CreatePageServlet.class); } + private void addJsResourceHandler(String handlerPath, String dirPath) { + Path path; + try { + path = locate(dirPath); + } catch (WebDriverException e) { + // Ugly hack to get us started with bazel while sorting out missing data dependencies. + if (Boolean.getBoolean(getClass().getPackage().getName() + ".ignoreMissingJsRoots") + && e.getCause() instanceof FileNotFoundException) { + System.err.println("WARNING: failed to add resource handler " + handlerPath + ": " + e.getCause()); + return; + } + throw e; + } + addResourceHandler(handlerPath, path); + } + private static Optional getEnvValue(String key) { return Optional.ofNullable(System.getenv(key)).map(Integer::parseInt); }