Add config option to select supported archive formats
Change-Id: I076e0a6cf038b72c6403e03fe9b9187ba2aa63fc
This commit is contained in:
		@@ -1317,6 +1317,21 @@ not default, as not all instances will deploy repo.
 | 
				
			|||||||
If `download.scheme` is not specified, SSH, HTTP and Anonymous HTTP
 | 
					If `download.scheme` is not specified, SSH, HTTP and Anonymous HTTP
 | 
				
			||||||
downloads are allowed.
 | 
					downloads are allowed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[download.archive]]download.archive::
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					Specifies which archive formats, if any, should be offered on the change
 | 
				
			||||||
 | 
					screen:
 | 
				
			||||||
 | 
					+
 | 
				
			||||||
 | 
					----
 | 
				
			||||||
 | 
					[download]
 | 
				
			||||||
 | 
					  archive = tar
 | 
				
			||||||
 | 
					  archive = tbz2
 | 
				
			||||||
 | 
					  archive = tgz
 | 
				
			||||||
 | 
					  archive = txz
 | 
				
			||||||
 | 
					----
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Defaults to no archive commands.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[gerrit]]
 | 
					[[gerrit]]
 | 
				
			||||||
=== Section gerrit
 | 
					=== Section gerrit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@ import com.google.gerrit.reviewdb.client.Account.FieldName;
 | 
				
			|||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
 | 
					import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
 | 
					import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadCommand;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
 | 
					import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
 | 
				
			||||||
 | 
					import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.ArchiveFormat;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.AuthType;
 | 
					import com.google.gerrit.reviewdb.client.AuthType;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.Project;
 | 
					import com.google.gerrit.reviewdb.client.Project;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -53,6 +54,7 @@ public class GerritConfig implements Cloneable {
 | 
				
			|||||||
  protected int suggestFrom;
 | 
					  protected int suggestFrom;
 | 
				
			||||||
  protected int changeUpdateDelay;
 | 
					  protected int changeUpdateDelay;
 | 
				
			||||||
  protected AccountGeneralPreferences.ChangeScreen changeScreen;
 | 
					  protected AccountGeneralPreferences.ChangeScreen changeScreen;
 | 
				
			||||||
 | 
					  protected Set<ArchiveFormat> archiveFormats;
 | 
				
			||||||
  protected int largeChangeSize;
 | 
					  protected int largeChangeSize;
 | 
				
			||||||
  protected boolean newFeatures;
 | 
					  protected boolean newFeatures;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -291,6 +293,14 @@ public class GerritConfig implements Cloneable {
 | 
				
			|||||||
    this.largeChangeSize = largeChangeSize;
 | 
					    this.largeChangeSize = largeChangeSize;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public Set<ArchiveFormat> getArchiveFormats() {
 | 
				
			||||||
 | 
					    return archiveFormats;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public void setArchiveFormats(Set<ArchiveFormat> formats) {
 | 
				
			||||||
 | 
					    archiveFormats = formats;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public boolean getNewFeatures() {
 | 
					  public boolean getNewFeatures() {
 | 
				
			||||||
    return newFeatures;
 | 
					    return newFeatures;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,6 +25,7 @@ import com.google.gerrit.client.rpc.Natives;
 | 
				
			|||||||
import com.google.gerrit.client.rpc.RestApi;
 | 
					import com.google.gerrit.client.rpc.RestApi;
 | 
				
			||||||
import com.google.gerrit.extensions.common.ListChangesOption;
 | 
					import com.google.gerrit.extensions.common.ListChangesOption;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
 | 
					import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
 | 
				
			||||||
 | 
					import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.ArchiveFormat;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
 | 
					import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.PatchSet;
 | 
					import com.google.gerrit.reviewdb.client.PatchSet;
 | 
				
			||||||
import com.google.gwt.core.client.JavaScriptObject;
 | 
					import com.google.gwt.core.client.JavaScriptObject;
 | 
				
			||||||
@@ -44,6 +45,7 @@ import java.util.ArrayList;
 | 
				
			|||||||
import java.util.EnumSet;
 | 
					import java.util.EnumSet;
 | 
				
			||||||
import java.util.Iterator;
 | 
					import java.util.Iterator;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DownloadBox extends VerticalPanel {
 | 
					class DownloadBox extends VerticalPanel {
 | 
				
			||||||
  private final static String ARCHIVE[] = {"tar", "tbz2", "tgz", "txz"};
 | 
					  private final static String ARCHIVE[] = {"tar", "tbz2", "tgz", "txz"};
 | 
				
			||||||
@@ -147,8 +149,13 @@ class DownloadBox extends VerticalPanel {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private void insertArchive() {
 | 
					  private void insertArchive() {
 | 
				
			||||||
    List<Anchor> formats = new ArrayList<>(ARCHIVE.length);
 | 
					    Set<ArchiveFormat> activated = Gerrit.getConfig().getArchiveFormats();
 | 
				
			||||||
 | 
					    if (activated.contains(ArchiveFormat.OFF)) {
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    List<Anchor> anchors = new ArrayList<>(activated.size());
 | 
				
			||||||
    for (String f : ARCHIVE) {
 | 
					    for (String f : ARCHIVE) {
 | 
				
			||||||
 | 
					      if (activated.contains(ArchiveFormat.valueOf(f.toUpperCase()))) {
 | 
				
			||||||
        Anchor archive = new Anchor(f);
 | 
					        Anchor archive = new Anchor(f);
 | 
				
			||||||
        archive.setHref(new RestApi("/changes/")
 | 
					        archive.setHref(new RestApi("/changes/")
 | 
				
			||||||
            .id(psId.getParentKey().get())
 | 
					            .id(psId.getParentKey().get())
 | 
				
			||||||
@@ -157,11 +164,12 @@ class DownloadBox extends VerticalPanel {
 | 
				
			|||||||
            .view("archive")
 | 
					            .view("archive")
 | 
				
			||||||
            .addParameter("format", f)
 | 
					            .addParameter("format", f)
 | 
				
			||||||
            .url());
 | 
					            .url());
 | 
				
			||||||
      formats.add(archive);
 | 
					        anchors.add(archive);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    HorizontalPanel p = new HorizontalPanel();
 | 
					    HorizontalPanel p = new HorizontalPanel();
 | 
				
			||||||
    Iterator<Anchor> it = formats.iterator();
 | 
					    Iterator<Anchor> it = anchors.iterator();
 | 
				
			||||||
    while (it.hasNext()) {
 | 
					    while (it.hasNext()) {
 | 
				
			||||||
      Anchor a = it.next();
 | 
					      Anchor a = it.next();
 | 
				
			||||||
      p.add(a);
 | 
					      p.add(a);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -18,6 +18,7 @@ import com.google.gerrit.common.data.GerritConfig;
 | 
				
			|||||||
import com.google.gerrit.common.data.GitwebConfig;
 | 
					import com.google.gerrit.common.data.GitwebConfig;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.Account;
 | 
					import com.google.gerrit.reviewdb.client.Account;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
 | 
					import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
 | 
				
			||||||
 | 
					import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.ArchiveFormat;
 | 
				
			||||||
import com.google.gerrit.server.account.Realm;
 | 
					import com.google.gerrit.server.account.Realm;
 | 
				
			||||||
import com.google.gerrit.server.config.AllProjectsName;
 | 
					import com.google.gerrit.server.config.AllProjectsName;
 | 
				
			||||||
import com.google.gerrit.server.config.AnonymousCowardName;
 | 
					import com.google.gerrit.server.config.AnonymousCowardName;
 | 
				
			||||||
@@ -36,6 +37,7 @@ import org.eclipse.jgit.lib.Config;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.net.MalformedURLException;
 | 
					import java.net.MalformedURLException;
 | 
				
			||||||
import java.util.HashSet;
 | 
					import java.util.HashSet;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Set;
 | 
					import java.util.Set;
 | 
				
			||||||
import java.util.concurrent.TimeUnit;
 | 
					import java.util.concurrent.TimeUnit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -128,6 +130,12 @@ class GerritConfigProvider implements Provider<GerritConfig> {
 | 
				
			|||||||
        "gerrit", null, "changeScreen",
 | 
					        "gerrit", null, "changeScreen",
 | 
				
			||||||
        AccountGeneralPreferences.ChangeScreen.CHANGE_SCREEN2));
 | 
					        AccountGeneralPreferences.ChangeScreen.CHANGE_SCREEN2));
 | 
				
			||||||
    config.setLargeChangeSize(cfg.getInt("change", "largeChange", 500));
 | 
					    config.setLargeChangeSize(cfg.getInt("change", "largeChange", 500));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    List<ArchiveFormat> allArchiveFormats =
 | 
				
			||||||
 | 
					        ConfigUtil.getEnumList(cfg, "download", null, "archive",
 | 
				
			||||||
 | 
					            ArchiveFormat.OFF);
 | 
				
			||||||
 | 
					    config.setArchiveFormats(new HashSet<>(allArchiveFormats));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    config.setNewFeatures(cfg.getBoolean("gerrit", "enableNewFeatures", true));
 | 
					    config.setNewFeatures(cfg.getBoolean("gerrit", "enableNewFeatures", true));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    final String reportBugUrl = cfg.getString("gerrit", null, "reportBugUrl");
 | 
					    final String reportBugUrl = cfg.getString("gerrit", null, "reportBugUrl");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,6 +35,10 @@ public final class AccountGeneralPreferences {
 | 
				
			|||||||
    REPO_DOWNLOAD, PULL, CHECKOUT, CHERRY_PICK, FORMAT_PATCH, DEFAULT_DOWNLOADS
 | 
					    REPO_DOWNLOAD, PULL, CHECKOUT, CHERRY_PICK, FORMAT_PATCH, DEFAULT_DOWNLOADS
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public static enum ArchiveFormat {
 | 
				
			||||||
 | 
					    OFF, TAR, TBZ2, TGZ, TXZ
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public static enum DateFormat {
 | 
					  public static enum DateFormat {
 | 
				
			||||||
    /** US style dates: Apr 27, Feb 14, 2010 */
 | 
					    /** US style dates: Apr 27, Feb 14, 2010 */
 | 
				
			||||||
    STD("MMM d", "MMM d, yyyy"),
 | 
					    STD("MMM d", "MMM d, yyyy"),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user