Merge branch 'stable-2.15'

* stable-2.15:
  Format with google-java-format 1.7

Change-Id: Id8d61153874989dcad7e0b2deeaaf191ff2e183e
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java
index 52fd08f..2648d10 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/CloneWithCommitMsgHook.java
@@ -22,6 +22,7 @@
 import com.googlesource.gerrit.plugins.download.scheme.AnonymousHttpScheme;
 import com.googlesource.gerrit.plugins.download.scheme.HttpScheme;
 import com.googlesource.gerrit.plugins.download.scheme.SshScheme;
+import java.util.Optional;
 import org.eclipse.jgit.lib.Config;
 
 public class CloneWithCommitMsgHook extends CloneCommand {
@@ -44,8 +45,8 @@
 
   @Override
   public String getCommand(DownloadScheme scheme, String project) {
-    String username = userProvider.get().getUserName();
-    if (username == null) {
+    Optional<String> username = userProvider.get().getUserName();
+    if (!username.isPresent()) {
       return null;
     }
     String projectName = getBaseName(project);
@@ -70,7 +71,7 @@
       }
 
       b.append(" ")
-          .append(username)
+          .append(username.get())
           .append("@")
           .append(sshScheme.getSshdHost())
           .append(":")
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java
index 301abeb..eb1b06f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java
@@ -14,6 +14,7 @@
 
 package com.googlesource.gerrit.plugins.download.command;
 
+import com.google.common.flogger.FluentLogger;
 import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
 import com.google.gerrit.extensions.config.DownloadCommand;
 import com.google.gerrit.extensions.config.DownloadScheme;
@@ -31,11 +32,9 @@
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.transport.URIish;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 abstract class GitDownloadCommand extends DownloadCommand {
-  private static final Logger log = LoggerFactory.getLogger(GitDownloadCommand.class);
+  private static final FluentLogger logger = FluentLogger.forEnclosingClass();
 
   private static final String DOWNLOAD = "download";
   private static final String UPLOADPACK = "uploadpack";
@@ -106,15 +105,15 @@
         if (id != null) {
           return id.name();
         }
-        log.error("Cannot resolve ref {} in project {}", ref, project);
+        logger.atSevere().log("Cannot resolve ref %s in project %s", ref, project);
         return null;
       }
       return ref;
     } catch (RepositoryNotFoundException e) {
-      log.error("Missing project: {}", project, e);
+      logger.atSevere().withCause(e).log("Missing project: %s", project);
       return null;
     } catch (IOException e) {
-      log.error("Failed to lookup project {} from cache", project, e);
+      logger.atSevere().withCause(e).log("Failed to lookup project %s from cache", project);
       return null;
     }
   }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/HttpScheme.java b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/HttpScheme.java
index 0e5bbee..3fabaa5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/HttpScheme.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/HttpScheme.java
@@ -63,8 +63,10 @@
       }
       String host = base.substring(p + 3, s);
       r.append(base.substring(0, p + 3));
-      r.append(userProvider.get().getUserName());
-      r.append("@");
+      if (userProvider.get().getUserName().isPresent()) {
+        r.append(userProvider.get().getUserName().get());
+        r.append("@");
+      }
       r.append(host);
       r.append(base.substring(s));
       r.append("a/");
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java
index ac198fb..e775d95 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SshScheme.java
@@ -16,7 +16,6 @@
 
 import static com.google.gerrit.reviewdb.client.CoreDownloadSchemes.SSH;
 
-import com.google.common.base.Strings;
 import com.google.gerrit.common.Nullable;
 import com.google.gerrit.extensions.config.DownloadScheme;
 import com.google.gerrit.server.CurrentUser;
@@ -28,6 +27,7 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.List;
+import java.util.Optional;
 
 public class SshScheme extends DownloadScheme {
   private final String sshdAddress;
@@ -84,14 +84,15 @@
     if (!isEnabled() || !userProvider.get().isIdentifiedUser()) {
       return null;
     }
-    String username = userProvider.get().getUserName();
-    if (Strings.isNullOrEmpty(username)) {
+
+    Optional<String> username = userProvider.get().getUserName();
+    if (!username.isPresent()) {
       return null;
     }
 
     StringBuilder r = new StringBuilder();
     r.append("ssh://");
-    r.append(username);
+    r.append(username.get());
     r.append("@");
     r.append(ensureSlash(sshdAddress));
     r.append(project);