Handle case where CanonicalWebUrl is null
Change-Id: I232e7e81bd3b3230730d93a56499ae94bfdb0fec
diff --git a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventFactory.java b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventFactory.java
index addae54..ef3547c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventFactory.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/mapping/EiffelEventFactory.java
@@ -44,6 +44,7 @@
import java.util.List;
import java.util.Optional;
import java.util.UUID;
+import org.eclipse.jgit.util.SystemReader;
public class EiffelEventFactory {
public static class Provider implements com.google.inject.Provider<EiffelEventFactory> {
@@ -112,19 +113,22 @@
purl.append("@" + pluginVersion);
}
this.packageUrl = purl.toString();
- this.host = URI.create(webUrl).getHost();
+ if (webUrl != null) {
+ this.host = URI.create(webUrl).getHost();
+ } else {
+ this.host = SystemReader.getInstance().getHostname();
+ }
this.pluginName = pluginName;
this.namespace = namespace.orElse(host);
- StringBuilder commitEndpoint = new StringBuilder();
- commitEndpoint.append(webUrl);
- if (!webUrl.endsWith("/")) {
- commitEndpoint.append("/");
+ if (webUrl != null) {
+ commitRestUrl = webUrl + (!webUrl.endsWith("/") ? "/" : "") + "a/projects/%s/commits/%s";
+ } else {
+ commitRestUrl = "/projects/%s/commits/%s";
}
- commitEndpoint.append("a/projects/%s/commits/%s");
- commitRestUrl = commitEndpoint.toString();
String sshAddress = parseSshAddress(webUrl, configuredSshAddress);
+
StringBuilder cloneUrl = new StringBuilder();
cloneUrl.append("ssh://");
cloneUrl.append(sshAddress);
@@ -138,11 +142,11 @@
private String parseSshAddress(String webUrl, String configuredSshAddress) {
- if (configuredSshAddress.startsWith("*:") || "".equals(configuredSshAddress)) {
+ if (configuredSshAddress.startsWith("*:") || configuredSshAddress.isEmpty()) {
try {
configuredSshAddress =
new URL(webUrl).getHost()
- + (configuredSshAddress.length() > 0 ? configuredSshAddress.substring(1) : "");
+ + (!configuredSshAddress.isEmpty() ? configuredSshAddress.substring(1) : "");
} catch (MalformedURLException e) {
logger.atWarning().withCause(e).log(
"Failed to construct SSH address from web URL \"%s\"", webUrl);