gitiles-dev: inject source path through a System property. This makes gitiles-dev independent of the build system. It assumes that nobody relies on .buckconfig being shipped into the gitiles jar. Change-Id: Id3c5313061516aba835f0bc62160133913c7772e
diff --git a/gitiles-dev/src/main/java/com/google/gitiles/dev/DevServer.java b/gitiles-dev/src/main/java/com/google/gitiles/dev/DevServer.java index faa6ee5..ccdbd6c 100644 --- a/gitiles-dev/src/main/java/com/google/gitiles/dev/DevServer.java +++ b/gitiles-dev/src/main/java/com/google/gitiles/dev/DevServer.java
@@ -96,45 +96,13 @@ } private static Path findSourceRoot() throws IOException { - URI u; - try { - u = DevServer.class.getResource(DevServer.class.getSimpleName() + ".class").toURI(); - } catch (URISyntaxException e) { - u = null; + String prop = "com.google.gitiles.sourcePath"; + String sourceRoot = System.getProperty(prop); + if (sourceRoot == null) { + throw new NoSuchFileException( + String.format("Must set system property %s to top of source directory", prop)); } - if (u == null) { - throw new NoSuchFileException("Cannot find Gitiles source directory"); - } - if ("jar".equals(u.getScheme())) { - String path = u.getSchemeSpecificPart(); - int jarEntry = path.indexOf("!/"); - if (jarEntry < 0) { - throw badSourceRoot(u); - } - try { - return findSourceRoot(new URI(path.substring(0, jarEntry))); - } catch (URISyntaxException e) { - throw badSourceRoot(u, e); - } - } else { - return findSourceRoot(u); - } - } - - private static Path findSourceRoot(URI targetUri) throws IOException { - if (!"file".equals(targetUri.getScheme())) { - throw badSourceRoot(targetUri); - } - - Path dir = Paths.get(targetUri.getPath()); - while (!Files.isRegularFile(dir.resolve(".buckconfig"))) { - Path parent = dir.getParent(); - if (parent == null) { - throw badSourceRoot(targetUri); - } - dir = parent; - } - return dir; + return Paths.get(sourceRoot); } private final Path sourceRoot; @@ -142,7 +110,8 @@ private final Server httpd; DevServer(File cfgFile) throws IOException, ConfigInvalidException { - sourceRoot = findSourceRoot(); + // Jetty doesn't doesn't allow symlinks, so canonicalize. + sourceRoot = findSourceRoot().toRealPath(); Config cfg = defaultConfig(); if (cfgFile.exists() && cfgFile.isFile()) {
diff --git a/tools/run_dev.sh b/tools/run_dev.sh index 14620d1..58493a6 100755 --- a/tools/run_dev.sh +++ b/tools/run_dev.sh
@@ -16,12 +16,14 @@ set -e -ROOT="$(dirname "$0")/.." +ROOT="$(cd $(dirname "$0")/..; pwd)" PROPERTIES= if [ "x$1" != "x" ]; then PROPERTIES="-Dcom.google.gitiles.configPath=$1" fi +PROPERTIES="$PROPERTIES -Dcom.google.gitiles.sourcePath=$ROOT" + ( cd "$ROOT" buck build gitiles-dev:dev