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>
diff --git a/.gitignore b/.gitignore
index fdd9fa1..9f3c4e1 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 0c8e028..bf07dda 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.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 @@
try {
baseResource = unpackWar();
} catch (FileNotFoundException err) {
+ if (err.getMessage() == GerritLauncher.NOT_ARCHIVED) {
+ baseResource = useDeveloperBuild();
+ } else {
throw err;
+ }
}
}
return baseResource;
@@ -396,4 +401,58 @@
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 9dca1f8..7aeca89 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"/>