Adapt injection of UrlFormatter to DynamicItem

Since I375245647 the UrlFormatter is not bound anymore
directly but through a DynamicItem.

Bug: Issue 10132
Change-Id: I621573b5246d1d2fcbc6ef03d3d1819c1525625e
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java
index aefd723..87d4291 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/HookArgs.java
@@ -21,6 +21,7 @@
 import com.google.gerrit.extensions.common.AccountInfo;
 import com.google.gerrit.extensions.common.ApprovalInfo;
 import com.google.gerrit.extensions.common.ChangeInfo;
+import com.google.gerrit.extensions.registration.DynamicItem;
 import com.google.gerrit.reviewdb.client.Account;
 import com.google.gerrit.reviewdb.client.Change;
 import com.google.gerrit.reviewdb.client.Project;
@@ -32,6 +33,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 class HookArgs {
   interface Factory {
@@ -42,14 +44,14 @@
   final HookMetrics metrics;
   final GitRepositoryManager gitManager;
   final SitePaths sitePaths;
-  final UrlFormatter urlFormatter;
+  final DynamicItem<UrlFormatter> urlFormatter;
 
   private final List<String> args;
 
   @Inject
   HookArgs(
       IdentifiedUser.GenericFactory identifiedUserFactory,
-      UrlFormatter urlFormatter,
+      DynamicItem<UrlFormatter> urlFormatter,
       HookMetrics metrics,
       GitRepositoryManager gitManager,
       SitePaths sitePaths) {
@@ -98,9 +100,12 @@
   public void addUrl(ChangeInfo change) {
     args.add("--change-url");
     if (change != null) {
+      Optional<UrlFormatter> uf = Optional.ofNullable(urlFormatter.get());
       args.add(
-          urlFormatter
-              .getChangeViewUrl(new Project.NameKey(change.project), new Change.Id(change._number))
+          uf.flatMap(
+                  f ->
+                      f.getChangeViewUrl(
+                          new Project.NameKey(change.project), new Change.Id(change._number)))
               .orElse(""));
     } else {
       args.add("");