diff options
author | Shawn O. Pearce <sop@google.com> | 2009-12-07 15:23:16 -0800 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-12-07 15:23:16 -0800 |
commit | dbbca8bf56f667df042075a5d465f11060d4d496 (patch) | |
tree | b3ece0c2b7db73230afc7bfe0cbdf89955094e70 | |
parent | ec4495eb5a1b7a4d098c1812d104e1362f6934f6 (diff) |
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 <sop@google.com>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | gerrit-pgm/src/main/java/com/google/gerrit/pgm/http/jetty/JettyServer.java | 59 | ||||
-rw-r--r-- | tools/pgm_daemon.launch | 2 |
3 files changed, 61 insertions, 1 deletions
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 @@ <booleanAttribute key="org.eclipse.jdt.debug.ui.CONSIDER_INHERITED_MAIN" value="true"/> <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.classpathProvider"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="Main"/> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="daemon --console-log --show-stack-trace"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="daemon --console-log --show-stack-trace -d ${resource_loc:/gerrit-parent}/test_site"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="gerrit-war"/> <stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.maven.ide.eclipse.launchconfig.sourcepathProvider"/> <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx256M"/> |