Get the canonical web URL injected

The plugin now gets the server's canonical web URL injected rather
than constructing from the config.

Change-Id: I50f585cefcd084ebb1678e1f19387bde82e88d29
diff --git a/src/main/java/com/googlesource/gerrit/plugins/branchnetwork/canvas/GitGraphServlet.java b/src/main/java/com/googlesource/gerrit/plugins/branchnetwork/canvas/GitGraphServlet.java
index 50ee03a..f11d989 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/branchnetwork/canvas/GitGraphServlet.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/branchnetwork/canvas/GitGraphServlet.java
@@ -24,15 +24,12 @@
 import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jgit.errors.RepositoryNotFoundException;
-import org.eclipse.jgit.lib.Config;
 import org.eclipse.jgit.lib.Repository;
 
-import com.google.common.base.Objects;
 import com.google.gerrit.common.data.GitWebType;
-import com.google.gerrit.extensions.annotations.PluginName;
+import com.google.gerrit.extensions.annotations.PluginCanonicalWebUrl;
 import com.google.gerrit.httpd.GitWebConfig;
 import com.google.gerrit.reviewdb.client.Project;
-import com.google.gerrit.server.config.GerritServerConfig;
 import com.google.gerrit.server.git.GitRepositoryManager;
 import com.google.gerrit.server.project.NoSuchProjectException;
 import com.google.gerrit.server.project.ProjectControl;
@@ -50,21 +47,17 @@
   private Factory projectControl;
   private GitRepositoryManager repoManager;
   private GitWebConfig gitWebConfig;
-  private String canonicalWebUrl;
+  private String pluginCanonicalWebUrl;
 
   @Inject
-  public GitGraphServlet(@PluginName String pluginName,
-      @GerritServerConfig final Config gerritConfig, GitWebConfig gitWebConfig,
+  public GitGraphServlet(@PluginCanonicalWebUrl String url,
+      GitWebConfig gitWebConfig,
       final ProjectControl.Factory projectControl,
       final GitRepositoryManager repoManager)
       throws MalformedURLException {
-    this.canonicalWebUrl =
-        Objects.firstNonNull(gerritConfig.getString("gerrit", null, "canonicalWebUrl"), "/");
-    if(!canonicalWebUrl.endsWith("/")) {
-      canonicalWebUrl += "/";
-    }
-    this.canonicalPath =
-        String.format("%splugins/%s/", (new URL(canonicalWebUrl)).getPath(), pluginName);
+    this.canonicalPath = new URL(url).getPath();
+    this.pluginCanonicalWebUrl =
+        url.substring(0, url.length() - (canonicalPath.length() - 1));
     this.projectControl = projectControl;
     this.repoManager = repoManager;
     this.gitWebConfig = gitWebConfig;
@@ -133,10 +126,10 @@
                     .replaceAll("\\$\\{project\\}", repoName);
 
         commitUrlPattern =
-            (commitUrlPattern.startsWith("/") ? commitUrlPattern : canonicalWebUrl
+            (commitUrlPattern.startsWith("/") ? commitUrlPattern : pluginCanonicalWebUrl
                 + commitUrlPattern);
         projectPattern =
-            (projectPattern.startsWith("/") ? projectPattern : canonicalWebUrl
+            (projectPattern.startsWith("/") ? projectPattern : pluginCanonicalWebUrl
                 + projectPattern);
 
         String header =