Add `Depot Tools` download scheme for download commands.

This adds a new download scheme for users to utilize `git cl patch` to
download their changes. This is useful for teams that utilize the `Depot
Tools`.

Change-Id: I078d4b71dc0b268b71fda033877b176852a36b49
Bug: 425283099
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/BranchCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/BranchCommand.java
index 7bac2c4..9dc2b68 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/BranchCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/BranchCommand.java
@@ -52,4 +52,9 @@
         + " "
         + id;
   }
+
+  @Override
+  String getDepotToolsCommand(String id) {
+    return "git cl patch -b change-" + id.replaceAll("/", "-") + " " + id;
+  }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/CherryPickCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/CherryPickCommand.java
index 02c55f8..bb6d4f2 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/CherryPickCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/CherryPickCommand.java
@@ -40,4 +40,9 @@
   String getRepoCommand(String url, String id) {
     return "repo download -c " + QuoteUtil.quote(url) + " " + id;
   }
+
+  @Override
+  String getDepotToolsCommand(String id) {
+    return "git cl patch " + id;
+  }
 }
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 908b51d..e2867c7 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
@@ -24,6 +24,7 @@
 import com.google.gerrit.server.config.DownloadConfig;
 import com.google.gerrit.server.config.GerritServerConfig;
 import com.google.gerrit.server.git.GitRepositoryManager;
+import com.googlesource.gerrit.plugins.download.scheme.DepotToolsScheme;
 import com.googlesource.gerrit.plugins.download.scheme.RepoScheme;
 import java.io.IOException;
 import java.net.URISyntaxException;
@@ -81,6 +82,9 @@
       if (scheme instanceof RepoScheme) {
         return getRepoCommand(url, id);
       }
+      if (scheme instanceof DepotToolsScheme) {
+        return getDepotToolsCommand(id);
+      }
       if (isValidUrl(url)) {
         if (checkForHiddenChangeRefs) {
           ref = resolveRef(project, ref);
@@ -158,4 +162,13 @@
     // Most commands don't support this, so default it to nothing.
     return null;
   }
+
+  /**
+   * @param id The change/PS numbers.
+   */
+  @Nullable
+  String getDepotToolsCommand(String id) {
+    // Default to nothing, override in individual command classes.
+    return null;
+  }
 }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/DepotToolsScheme.java b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/DepotToolsScheme.java
new file mode 100644
index 0000000..6fde783
--- /dev/null
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/DepotToolsScheme.java
@@ -0,0 +1,57 @@
+// Copyright (C) 2025 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.googlesource.gerrit.plugins.download.scheme;
+
+import static com.google.gerrit.entities.CoreDownloadSchemes.DEPOT_TOOLS;
+
+import com.google.gerrit.extensions.config.DownloadScheme;
+import com.google.gerrit.server.config.DownloadConfig;
+import com.google.inject.Inject;
+
+public class DepotToolsScheme extends DownloadScheme {
+  private final boolean schemeAllowed;
+  private final boolean schemeHidden;
+
+  @Inject
+  DepotToolsScheme(DownloadConfig downloadConfig) {
+    this.schemeAllowed = downloadConfig.getDownloadSchemes().contains(DEPOT_TOOLS);
+    this.schemeHidden = downloadConfig.getHiddenSchemes().contains(DEPOT_TOOLS);
+  }
+
+  @Override
+  public String getUrl(String project) {
+    return project;
+  }
+
+  @Override
+  public boolean isEnabled() {
+    return schemeAllowed;
+  }
+
+  @Override
+  public boolean isHidden() {
+    return schemeHidden;
+  }
+
+  @Override
+  public boolean isAuthRequired() {
+    return false;
+  }
+
+  @Override
+  public boolean isAuthSupported() {
+    return true;
+  }
+}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SchemeModule.java b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SchemeModule.java
index 5ff04b2..07f7d51 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SchemeModule.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/scheme/SchemeModule.java
@@ -29,6 +29,10 @@
 
     bind(DownloadScheme.class).annotatedWith(Exports.named("http")).to(HttpScheme.class);
 
+    bind(DownloadScheme.class)
+        .annotatedWith(Exports.named("depot_tools"))
+        .to(DepotToolsScheme.class);
+
     bind(DownloadScheme.class).annotatedWith(Exports.named("repo")).to(RepoScheme.class);
 
     bind(DownloadScheme.class).annotatedWith(Exports.named("ssh")).to(SshScheme.class);
diff --git a/src/main/resources/Documentation/about.md b/src/main/resources/Documentation/about.md
index 7c2288c..697487d 100644
--- a/src/main/resources/Documentation/about.md
+++ b/src/main/resources/Documentation/about.md
@@ -21,6 +21,8 @@
 
 * `REPO`: Scheme for downloading with the Repo tool.
 
+* `Depot Tools`: Scheme for downloading with the [depot_tools](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools.html).
+
 Download Commands
 -----------------
 
@@ -32,7 +34,7 @@
 
 All Git commands are for the Git command line. The Git commands are
 available for the schemes `Anonymous Git`, `Anonymous HTTP`, `HTTP` and
-`SSH`.
+`SSH`. Some Git commands are available for the `Depot Tools` scheme.
 
 * `Checkout`:
 Command to fetch and checkout a patch set.
diff --git a/src/main/resources/Documentation/config.md b/src/main/resources/Documentation/config.md
index 5580f87..9e3ffe9 100644
--- a/src/main/resources/Documentation/config.md
+++ b/src/main/resources/Documentation/config.md
@@ -21,6 +21,7 @@
   scheme = http
   scheme = anon_http
   scheme = anon_git
+  scheme = depot_tools
   scheme = repo
   hide = ssh
   recurseSubmodules = true
@@ -73,6 +74,11 @@
 	[repo multi-repository tool](https://gerrit.googlesource.com/git-repo)
 	tool.  This is not default, as not all instances will deploy repo.
 
+	* `depot_tools`: Gerrit advertises patch set downloads with the `git cl patch`
+	command, assuming that all projects managed by this instance are generally
+	worked on with the
+	[Depot Tools](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools.html).
+
 	If `download.scheme` is not specified, SSH, HTTP and Anonymous HTTP
 	downloads are allowed.