Skip to content

Commit

Permalink
The JettyAppServer crashes if it can't find javascript resources
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jleyba committed May 2, 2019
1 parent 8c74517 commit ee193d8
Showing 1 changed file with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<Integer> getEnvValue(String key) {
return Optional.ofNullable(System.getenv(key)).map(Integer::parseInt);
}
Expand Down

0 comments on commit ee193d8

Please sign in to comment.