From dbbca8bf56f667df042075a5d465f11060d4d496 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 7 Dec 2009 15:23:16 -0800 Subject: [PATCH] daemon: Run correctly under Eclipse debugger We now can launch the daemon correctly from within the Eclipse debugger without having to switch to using the WAR in our CLASSPATH. This works by allowing Eclipse to supply all of the CLASSPATH, but we have to go find our WAR resource content in gerrit-gwtui/target. Bug: 340 Change-Id: I7dfbc0654cdc10099fb3de3041e615a9fda5fdb4 Signed-off-by: Shawn O. Pearce --- .gitignore | 1 + .../gerrit/pgm/http/jetty/JettyServer.java | 59 +++++++++++++++++++ tools/pgm_daemon.launch | 2 +- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index fdd9fa12a3..9f3c4e125a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.project /.settings/org.maven.ide.eclipse.prefs /GerritServer.properties +/test_site diff --git a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java index 0c8e02819a..bf07dda358 100644 --- a/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java +++ b/gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java @@ -53,6 +53,7 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashSet; @@ -322,7 +323,11 @@ public class JettyServer { try { baseResource = unpackWar(); } catch (FileNotFoundException err) { + if (err.getMessage() == GerritLauncher.NOT_ARCHIVED) { + baseResource = useDeveloperBuild(); + } else { throw err; + } } } return baseResource; @@ -396,4 +401,58 @@ public class JettyServer { dir.deleteOnExit(); } } + + private Resource useDeveloperBuild() throws IOException { + // Find ourselves in the CLASSPATH. We should be a loose class file. + // + URL u = getClass().getResource(getClass().getSimpleName() + ".class"); + if (u == null) { + throw new FileNotFoundException("Cannot find web application root"); + } + if (!"file".equals(u.getProtocol())) { + throw new FileNotFoundException("Cannot find web root from " + u); + } + + // Pop up to the top level classes folder that contains us. + // + File dir = new File(u.getPath()); + String myName = getClass().getName(); + for (;;) { + int dot = myName.lastIndexOf('.'); + if (dot < 0) { + dir = dir.getParentFile(); + break; + } + myName = myName.substring(0, dot); + dir = dir.getParentFile(); + } + + // We should be in a Maven style output, that is $jar/target/classes. + // + if (!dir.getName().equals("classes")) { + throw new FileNotFoundException("Cannot find web root from " + u); + } + dir = dir.getParentFile(); // pop classes + if (!dir.getName().equals("target")) { + throw new FileNotFoundException("Cannot find web root from " + u); + } + dir = dir.getParentFile(); // pop target + dir = dir.getParentFile(); // pop the module we are in + + // Drop down into gerrit-gwtui to find the WAR assets we need. + // + dir = new File(new File(dir, "gerrit-gwtui"), "target"); + final File[] entries = dir.listFiles(); + if (entries == null) { + throw new FileNotFoundException("No " + dir); + } + for (File e : entries) { + if (e.isDirectory() /* must be a directory */ + && e.getName().startsWith("gerrit-gwtui-") + && new File(e, "gerrit/gerrit.nocache.js").isFile()) { + return Resource.newResource(e.toURI()); + } + } + throw new FileNotFoundException("No " + dir + "/gerrit-gwtui-*"); + } } diff --git a/tools/pgm_daemon.launch b/tools/pgm_daemon.launch index 9dca1f8b5a..7aeca89805 100644 --- a/tools/pgm_daemon.launch +++ b/tools/pgm_daemon.launch @@ -13,7 +13,7 @@ - +