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 {
|
public class GerritOptions {
|
||||||
private final boolean headless;
|
private final boolean headless;
|
||||||
private final boolean slave;
|
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.headless = headless;
|
||||||
this.slave = slave;
|
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() {
|
public boolean enableDefaultUi() {
|
||||||
return !headless && !polyGerrit;
|
return !headless && !enablePolyGerrit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean enableMasterFeatures() {
|
public boolean enableMasterFeatures() {
|
||||||
@@ -36,6 +40,10 @@ public class GerritOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean enablePolyGerrit() {
|
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;
|
package com.google.gerrit.httpd.raw;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import com.google.common.cache.Cache;
|
||||||
import com.google.gerrit.httpd.GerritOptions;
|
import com.google.gerrit.httpd.GerritOptions;
|
||||||
import com.google.gerrit.httpd.raw.ResourceServlet.Resource;
|
import com.google.gerrit.httpd.raw.ResourceServlet.Resource;
|
||||||
@@ -146,9 +148,14 @@ public class StaticModule extends ServletModule {
|
|||||||
|
|
||||||
private Path polyGerritBasePath() {
|
private Path polyGerritBasePath() {
|
||||||
Paths p = getPaths();
|
Paths p = getPaths();
|
||||||
return p.warFs != null
|
boolean forceDev = options.forcePolyGerritDev();
|
||||||
? p.warFs.getPath("/polygerrit_ui")
|
if (forceDev) {
|
||||||
: p.buckOut.getParent().resolve("polygerrit-ui").resolve("app");
|
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");
|
URL u = self.getResource(self.getSimpleName() + ".class");
|
||||||
if (u == null) {
|
if (u == null) {
|
||||||
throw new FileNotFoundException("Cannot find class " + self.getName());
|
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);
|
throw new FileNotFoundException("Cannot find extract path from " + u);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pop up to the top level classes folder that contains us.
|
// Pop up to the top level classes folder that contains us.
|
||||||
Path dir = Paths.get(u.getPath());
|
Path dir = Paths.get(u.getPath());
|
||||||
String myName = self.getName();
|
while (!name(dir).equals("buck-out")) {
|
||||||
for (;;) {
|
Path parent = dir.getParent();
|
||||||
int dot = myName.lastIndexOf('.');
|
if (parent == null || parent.equals(dir)) {
|
||||||
if (dot < 0) {
|
throw new FileNotFoundException("Cannot find buck-out from " + u);
|
||||||
dir = dir.getParent();
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
myName = myName.substring(0, dot);
|
dir = parent;
|
||||||
dir = dir.getParent();
|
|
||||||
}
|
}
|
||||||
|
return dir;
|
||||||
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) {
|
private static String name(Path dir) {
|
||||||
return dir.getName(dir.getNameCount() - 1).toString();
|
return dir.getFileName().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 ClassLoader useDevClasspath()
|
private static ClassLoader useDevClasspath()
|
||||||
|
@@ -142,6 +142,9 @@ public class Daemon extends SiteProgram {
|
|||||||
@Option(name = "--headless", usage = "Don't start the UI frontend")
|
@Option(name = "--headless", usage = "Don't start the UI frontend")
|
||||||
private boolean headless;
|
private boolean headless;
|
||||||
|
|
||||||
|
@Option(name = "--polygerrit-dev", usage = "Force PolyGerrit UI for development")
|
||||||
|
private boolean polyGerritDev;
|
||||||
|
|
||||||
@Option(name = "--init", aliases = {"-i"},
|
@Option(name = "--init", aliases = {"-i"},
|
||||||
usage = "Init site before starting the daemon")
|
usage = "Init site before starting the daemon")
|
||||||
private boolean doInit;
|
private boolean doInit;
|
||||||
@@ -370,8 +373,8 @@ public class Daemon extends SiteProgram {
|
|||||||
modules.add(new AbstractModule() {
|
modules.add(new AbstractModule() {
|
||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(GerritOptions.class)
|
bind(GerritOptions.class).toInstance(
|
||||||
.toInstance(new GerritOptions(config, headless, slave));
|
new GerritOptions(config, headless, slave, polyGerritDev));
|
||||||
if (test) {
|
if (test) {
|
||||||
bind(String.class).annotatedWith(SecureStoreClassName.class)
|
bind(String.class).annotatedWith(SecureStoreClassName.class)
|
||||||
.toInstance(DefaultSecureStore.class.getName());
|
.toInstance(DefaultSecureStore.class.getName());
|
||||||
|
@@ -324,7 +324,7 @@ public class WebAppInitializer extends GuiceServletContextListener
|
|||||||
@Override
|
@Override
|
||||||
protected void configure() {
|
protected void configure() {
|
||||||
bind(GerritOptions.class)
|
bind(GerritOptions.class)
|
||||||
.toInstance(new GerritOptions(config, false, false));
|
.toInstance(new GerritOptions(config, false, false, false));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
modules.add(new GarbageCollectionModule());
|
modules.add(new GarbageCollectionModule());
|
||||||
|
Reference in New Issue
Block a user