Merge "init: Gracefully handle missing browser" into stable-2.6
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.pgm.init;
|
package com.google.gerrit.pgm.init;
|
||||||
|
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import com.google.gerrit.server.config.GerritServerConfig;
|
import com.google.gerrit.server.config.GerritServerConfig;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
@@ -42,7 +43,6 @@ public class Browser {
|
|||||||
if (url == null) {
|
if (url == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.startsWith("proxy-")) {
|
if (url.startsWith("proxy-")) {
|
||||||
url = url.substring("proxy-".length());
|
url = url.substring("proxy-".length());
|
||||||
}
|
}
|
||||||
@@ -54,15 +54,19 @@ public class Browser {
|
|||||||
System.err.println("error: invalid httpd.listenUrl: " + url);
|
System.err.println("error: invalid httpd.listenUrl: " + url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String hostname = uri.getHost();
|
waitForServer(uri);
|
||||||
final int port = InitUtil.portOf(uri);
|
openBrowser(uri, link);
|
||||||
|
}
|
||||||
|
|
||||||
System.err.print("Waiting for server to start ... ");
|
private void waitForServer(URI uri) throws IOException {
|
||||||
|
String host = uri.getHost();
|
||||||
|
int port = InitUtil.portOf(uri);
|
||||||
|
System.err.format("Waiting for server on %s:%d ... ", host, port);
|
||||||
System.err.flush();
|
System.err.flush();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
final Socket s;
|
Socket s;
|
||||||
try {
|
try {
|
||||||
s = new Socket(hostname, port);
|
s = new Socket(host, port);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
@@ -74,18 +78,33 @@ public class Browser {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
System.err.println("OK");
|
System.err.println("OK");
|
||||||
|
}
|
||||||
|
|
||||||
url = cfg.getString("gerrit", null, "canonicalWebUrl");
|
private String resolveUrl(URI uri, String link) {
|
||||||
if (url == null || url.isEmpty()) {
|
String url = cfg.getString("gerrit", null, "canonicalWebUrl");
|
||||||
|
if (Strings.isNullOrEmpty(url)) {
|
||||||
url = uri.toString();
|
url = uri.toString();
|
||||||
}
|
}
|
||||||
if (!url.endsWith("/")) {
|
if (!url.endsWith("/")) {
|
||||||
url += "/";
|
url += "/";
|
||||||
}
|
}
|
||||||
if (link != null && !link.isEmpty()) {
|
if (!Strings.isNullOrEmpty(link)) {
|
||||||
url += "#" + link;
|
url += "#" + link;
|
||||||
}
|
}
|
||||||
System.err.println("Opening browser ...");
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openBrowser(URI uri, String link) {
|
||||||
|
String url = resolveUrl(uri, link);
|
||||||
|
System.err.format("Opening %s ...", url);
|
||||||
|
System.err.flush();
|
||||||
|
try {
|
||||||
org.h2.tools.Server.openBrowser(url);
|
org.h2.tools.Server.openBrowser(url);
|
||||||
|
System.err.println("OK");
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("FAILED");
|
||||||
|
System.err.println("Open Gerrit with a JavaScript capable browser:");
|
||||||
|
System.err.println(" " + url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user