Daemon: Add flag to force PolyGerrit development mode
Frontend developers shouldn't even have to open Eclipse in order to get started developing PolyGerrit: Eclipse is far from the most popular frontend development environment, and setting it up for the first time is an unnecessary barrier. Add a flag --polygerrit-dev to the daemon command that does two things: 1. Act as if gerrit.enablePolyGerrit is set to true, enabling the PolyGerrit UI. 2. Serve PolyGerrit from the local buck-out directory, as if it were launched from Eclipse, ignoring the version compiled into the war. Change-Id: Ibfe92d3d53637c5c8424e3200791f28260c0c9fa
This commit is contained in:
@@ -19,16 +19,20 @@ import org.eclipse.jgit.lib.Config;
|
||||
public class GerritOptions {
|
||||
private final boolean headless;
|
||||
private final boolean slave;
|
||||
private final boolean polyGerrit;
|
||||
private final boolean enablePolyGerrit;
|
||||
private final boolean forcePolyGerritDev;
|
||||
|
||||
public GerritOptions(Config cfg, boolean headless, boolean slave) {
|
||||
public GerritOptions(Config cfg, boolean headless, boolean slave,
|
||||
boolean forcePolyGerritDev) {
|
||||
this.headless = headless;
|
||||
this.slave = slave;
|
||||
this.polyGerrit = cfg.getBoolean("gerrit", null, "enablePolyGerrit", false);
|
||||
this.enablePolyGerrit = forcePolyGerritDev
|
||||
|| cfg.getBoolean("gerrit", null, "enablePolyGerrit", false);
|
||||
this.forcePolyGerritDev = forcePolyGerritDev;
|
||||
}
|
||||
|
||||
public boolean enableDefaultUi() {
|
||||
return !headless && !polyGerrit;
|
||||
return !headless && !enablePolyGerrit;
|
||||
}
|
||||
|
||||
public boolean enableMasterFeatures() {
|
||||
@@ -36,6 +40,10 @@ public class GerritOptions {
|
||||
}
|
||||
|
||||
public boolean enablePolyGerrit() {
|
||||
return !headless && polyGerrit;
|
||||
return !headless && enablePolyGerrit;
|
||||
}
|
||||
|
||||
public boolean forcePolyGerritDev() {
|
||||
return !headless && forcePolyGerritDev;
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,8 @@
|
||||
|
||||
package com.google.gerrit.httpd.raw;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.gerrit.httpd.GerritOptions;
|
||||
import com.google.gerrit.httpd.raw.ResourceServlet.Resource;
|
||||
@@ -146,9 +148,14 @@ public class StaticModule extends ServletModule {
|
||||
|
||||
private Path polyGerritBasePath() {
|
||||
Paths p = getPaths();
|
||||
return p.warFs != null
|
||||
? p.warFs.getPath("/polygerrit_ui")
|
||||
: p.buckOut.getParent().resolve("polygerrit-ui").resolve("app");
|
||||
boolean forceDev = options.forcePolyGerritDev();
|
||||
if (forceDev) {
|
||||
checkArgument(p.buckOut != null,
|
||||
"no buck-out directory found for PolyGerrit developer mode");
|
||||
}
|
||||
return forceDev || p.warFs == null
|
||||
? p.buckOut.getParent().resolve("polygerrit-ui").resolve("app")
|
||||
: p.warFs.getPath("/polygerrit_ui");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -580,41 +580,35 @@ public final class GerritLauncher {
|
||||
URL u = self.getResource(self.getSimpleName() + ".class");
|
||||
if (u == null) {
|
||||
throw new FileNotFoundException("Cannot find class " + self.getName());
|
||||
} else if (!"file".equals(u.getProtocol())) {
|
||||
} else if ("jar".equals(u.getProtocol())) {
|
||||
String p = u.getPath();
|
||||
try {
|
||||
u = new URL(p.substring(0, p.indexOf('!')));
|
||||
} catch (MalformedURLException e) {
|
||||
FileNotFoundException fnfe =
|
||||
new FileNotFoundException("Not a valid jar file: " + u);
|
||||
fnfe.initCause(e);
|
||||
throw fnfe;
|
||||
}
|
||||
}
|
||||
if (!"file".equals(u.getProtocol())) {
|
||||
throw new FileNotFoundException("Cannot find extract path from " + u);
|
||||
}
|
||||
|
||||
// Pop up to the top level classes folder that contains us.
|
||||
Path dir = Paths.get(u.getPath());
|
||||
String myName = self.getName();
|
||||
for (;;) {
|
||||
int dot = myName.lastIndexOf('.');
|
||||
if (dot < 0) {
|
||||
dir = dir.getParent();
|
||||
break;
|
||||
while (!name(dir).equals("buck-out")) {
|
||||
Path parent = dir.getParent();
|
||||
if (parent == null || parent.equals(dir)) {
|
||||
throw new FileNotFoundException("Cannot find buck-out from " + u);
|
||||
}
|
||||
myName = myName.substring(0, dot);
|
||||
dir = dir.getParent();
|
||||
dir = parent;
|
||||
}
|
||||
|
||||
dir = popdir(u, dir, "classes");
|
||||
dir = popdir(u, dir, "eclipse");
|
||||
if (last(dir).equals("buck-out")) {
|
||||
return dir;
|
||||
}
|
||||
throw new FileNotFoundException("Cannot find buck-out from " + u);
|
||||
}
|
||||
|
||||
private static String last(Path dir) {
|
||||
return dir.getName(dir.getNameCount() - 1).toString();
|
||||
}
|
||||
|
||||
private static Path popdir(URL u, Path dir, String name)
|
||||
throws FileNotFoundException {
|
||||
if (last(dir).equals(name)) {
|
||||
return dir.getParent();
|
||||
}
|
||||
throw new FileNotFoundException("Cannot find buck-out from " + u);
|
||||
private static String name(Path dir) {
|
||||
return dir.getFileName().toString();
|
||||
}
|
||||
|
||||
private static ClassLoader useDevClasspath()
|
||||
|
@@ -142,6 +142,9 @@ public class Daemon extends SiteProgram {
|
||||
@Option(name = "--headless", usage = "Don't start the UI frontend")
|
||||
private boolean headless;
|
||||
|
||||
@Option(name = "--polygerrit-dev", usage = "Force PolyGerrit UI for development")
|
||||
private boolean polyGerritDev;
|
||||
|
||||
@Option(name = "--init", aliases = {"-i"},
|
||||
usage = "Init site before starting the daemon")
|
||||
private boolean doInit;
|
||||
@@ -370,8 +373,8 @@ public class Daemon extends SiteProgram {
|
||||
modules.add(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GerritOptions.class)
|
||||
.toInstance(new GerritOptions(config, headless, slave));
|
||||
bind(GerritOptions.class).toInstance(
|
||||
new GerritOptions(config, headless, slave, polyGerritDev));
|
||||
if (test) {
|
||||
bind(String.class).annotatedWith(SecureStoreClassName.class)
|
||||
.toInstance(DefaultSecureStore.class.getName());
|
||||
|
@@ -324,7 +324,7 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GerritOptions.class)
|
||||
.toInstance(new GerritOptions(config, false, false));
|
||||
.toInstance(new GerritOptions(config, false, false, false));
|
||||
}
|
||||
});
|
||||
modules.add(new GarbageCollectionModule());
|
||||
|
Reference in New Issue
Block a user