Merge changes from topic 'remove-gerrit-config-from-client'

* changes:
  Check with HEAD request if docs are available and remove GerritConfig
  Remove usage of GerritConfig from GitWebServlet
  Add acceptance test for /config/server/info REST endpoint
  Return info about SSHD with /config/server/info REST endpoint
  Retrieve clone commands from /config/server/info REST endpoint
  Add new extension point for clone commands
  Make *Info classes in GetServerInfo movable to extension package
  Expose more config parameters via REST
  Expose GitWeb config via /config/server/info REST endpoint
  Gerrit Client: Retrieve archives formats via REST
  Expose all auth config params that are needed by client over REST
  For clone commands rely on scheme URLs from the server
This commit is contained in:
David Pursehouse
2015-06-10 00:14:15 +00:00
committed by Gerrit Code Review
60 changed files with 1255 additions and 1045 deletions

View File

@@ -138,7 +138,7 @@ public class FormatUtil {
public static String nameEmail(AccountInfo info) {
String name = info.name();
if (name == null || name.trim().isEmpty()) {
name = Gerrit.getConfig().getAnonymousCowardName();
name = Gerrit.info().user().anonymousCowardName();
}
StringBuilder b = new StringBuilder().append(name);

View File

@@ -27,8 +27,10 @@ import com.google.gerrit.client.api.ApiGlue;
import com.google.gerrit.client.api.PluginLoader;
import com.google.gerrit.client.changes.ChangeConstants;
import com.google.gerrit.client.changes.ChangeListScreen;
import com.google.gerrit.client.config.AuthInfo;
import com.google.gerrit.client.config.ConfigServerApi;
import com.google.gerrit.client.config.ServerInfo;
import com.google.gerrit.client.documentation.DocInfo;
import com.google.gerrit.client.extensions.TopMenu;
import com.google.gerrit.client.extensions.TopMenuItem;
import com.google.gerrit.client.extensions.TopMenuList;
@@ -42,8 +44,6 @@ import com.google.gerrit.client.ui.MorphingTabPanel;
import com.google.gerrit.client.ui.ProjectLinkMenuItem;
import com.google.gerrit.client.ui.Screen;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.common.data.GerritConfig;
import com.google.gerrit.common.data.GitwebConfig;
import com.google.gerrit.common.data.HostPageData;
import com.google.gerrit.common.data.SystemInfoService;
import com.google.gerrit.extensions.client.GerritTopMenu;
@@ -65,6 +65,11 @@ import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.http.client.URL;
import com.google.gwt.http.client.UrlBuilder;
import com.google.gwt.user.client.Command;
@@ -103,10 +108,11 @@ public class Gerrit implements EntryPoint {
public static final EventBus EVENT_BUS = GWT.create(SimpleEventBus.class);
public static final Themer THEMER = GWT.create(Themer.class);
public static final String PROJECT_NAME_MENU_VAR = "${projectName}";
public static final String INDEX = "Documentation/index.html";
private static String myHost;
private static GerritConfig myConfig;
private static ServerInfo myServerInfo;
private static boolean hasDocumentation;
private static HostPageData.Theme myTheme;
private static Account myAccount;
private static String defaultScreenToken;
@@ -284,21 +290,11 @@ public class Gerrit implements EntryPoint {
return bottomMenu;
}
/** Get the public configuration data used by this Gerrit instance. */
public static GerritConfig getConfig() {
return myConfig;
}
/** Get the public configuration data used by this Gerrit instance. */
public static ServerInfo info() {
return myServerInfo;
}
public static GitwebLink getGitwebLink() {
GitwebConfig gw = getConfig().getGitwebLink();
return gw != null && gw.type != null ? new GitwebLink(gw) : null;
}
/** Site theme information (site specific colors)/ */
public static HostPageData.Theme getTheme() {
return myTheme;
@@ -434,6 +430,12 @@ public class Gerrit implements EntryPoint {
RpcStatus.INSTANCE = new RpcStatus();
CallbackGroup cbg = new CallbackGroup();
getDocIndex(cbg.add(new GerritCallback<DocInfo>() {
@Override
public void onSuccess(DocInfo indexInfo) {
hasDocumentation = indexInfo != null;
}
}));
ConfigServerApi.serverInfo(cbg.add(new GerritCallback<ServerInfo>() {
@Override
public void onSuccess(ServerInfo info) {
@@ -445,7 +447,6 @@ public class Gerrit implements EntryPoint {
@Override
public void onSuccess(final HostPageData result) {
Document.get().getElementById("gerrit_hostpagedata").removeFromParent();
myConfig = result.config;
myTheme = result.theme;
isNoteDbEnabled = result.isNoteDbEnabled;
if (result.account != null) {
@@ -485,9 +486,9 @@ public class Gerrit implements EntryPoint {
btmmenu.add(new InlineHTML(M.poweredBy(vs)));
String reportBugUrl = getConfig().getReportBugUrl();
String reportBugUrl = info().gerrit().reportBugUrl();
if (reportBugUrl != null) {
String reportBugText = getConfig().getReportBugText();
String reportBugText = info().gerrit().reportBugText();
Anchor a = new Anchor(
reportBugText == null ? C.reportBug() : reportBugText,
reportBugUrl);
@@ -623,8 +624,8 @@ public class Gerrit implements EntryPoint {
menuBars = new HashMap<>();
final boolean signedIn = isSignedIn();
final GerritConfig cfg = getConfig();
boolean signedIn = isSignedIn();
AuthInfo authInfo = info().auth();
LinkMenuBar m;
m = new LinkMenuBar();
@@ -705,7 +706,7 @@ public class Gerrit implements EntryPoint {
}, CREATE_PROJECT, CREATE_GROUP, VIEW_PLUGINS);
}
if (getConfig().isDocumentationAvailable()) {
if (hasDocumentation) {
m = new LinkMenuBar();
menuBars.put(GerritTopMenu.DOCUMENTATION.menuName, m);
addDocLink(m, C.menuDocumentationTOC(), "index.html");
@@ -718,9 +719,9 @@ public class Gerrit implements EntryPoint {
}
if (signedIn) {
whoAmI(!info().auth().isClientSslCertLdap());
whoAmI(!authInfo.isClientSslCertLdap());
} else {
switch (info().auth().authType()) {
switch (authInfo.authType()) {
case CLIENT_SSL_CERT_LDAP:
break;
@@ -763,18 +764,22 @@ public class Gerrit implements EntryPoint {
case HTTP:
case HTTP_LDAP:
if (cfg.getLoginUrl() != null) {
final String signinText = cfg.getLoginText() == null ? C.menuSignIn() : cfg.getLoginText();
menuRight.add(anchor(signinText, cfg.getLoginUrl()));
if (authInfo.loginUrl() != null) {
String signinText = authInfo.loginText() == null
? C.menuSignIn()
: authInfo.loginText();
menuRight.add(anchor(signinText, authInfo.loginUrl()));
}
break;
case LDAP:
case LDAP_BIND:
case CUSTOM_EXTENSION:
if (cfg.getRegisterUrl() != null) {
final String registerText = cfg.getRegisterText() == null ? C.menuRegister() : cfg.getRegisterText();
menuRight.add(anchor(registerText, cfg.getRegisterUrl()));
if (authInfo.registerUrl() != null) {
String registerText = authInfo.registerText() == null
? C.menuRegister()
: authInfo.registerText();
menuRight.add(anchor(registerText, authInfo.registerUrl()));
}
menuRight.addItem(C.menuSignIn(), new Command() {
@Override
@@ -810,6 +815,32 @@ public class Gerrit implements EntryPoint {
});
}
private static void getDocIndex(final AsyncCallback<DocInfo> cb) {
RequestBuilder req =
new RequestBuilder(RequestBuilder.HEAD, GWT.getHostPageBaseURL()
+ INDEX);
req.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request req, Response resp) {
if (resp.getStatusCode() == Response.SC_OK) {
cb.onSuccess(DocInfo.create());
} else {
cb.onSuccess(null);
}
}
@Override
public void onError(Request request, Throwable e) {
cb.onFailure(e);
}
});
try {
req.send();
} catch (RequestException e) {
cb.onFailure(e);
}
}
private static AsyncCallback<Preferences> createMyMenuBarCallback() {
return new GerritCallback<Preferences>() {
@Override

View File

@@ -1,115 +0,0 @@
// Copyright (C) 2008 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.google.gerrit.client;
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.common.data.GitWebType;
import com.google.gerrit.common.data.ParameterizedString;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gwt.http.client.URL;
import java.util.HashMap;
import java.util.Map;
/** Link to an external gitweb server. */
public class GitwebLink {
protected String baseUrl;
protected GitWebType type;
public GitwebLink(com.google.gerrit.common.data.GitwebConfig link) {
baseUrl = link.baseUrl;
type = link.type;
}
/**
* Can we link to a patch set if it's a draft
*
* @param ps Patch set to check draft status
* @return true if it's not a draft, or we can link to drafts
*/
public boolean canLink(final PatchSet ps) {
return !ps.isDraft() || type.getLinkDrafts();
}
public boolean canLink(RevisionInfo revision) {
return revision.draft() || type.getLinkDrafts();
}
public String getLinkName() {
return "(" + type.getLinkName() + ")";
}
public String toRevision(String project, String commit) {
ParameterizedString pattern = new ParameterizedString(type.getRevision());
Map<String, String> p = new HashMap<>();
p.put("project", encode(project));
p.put("commit", encode(commit));
return baseUrl + pattern.replace(p);
}
public String toRevision(final Project.NameKey project, final PatchSet ps) {
return toRevision(project.get(), ps.getRevision().get());
}
public String toProject(final Project.NameKey project) {
ParameterizedString pattern = new ParameterizedString(type.getProject());
final Map<String, String> p = new HashMap<>();
p.put("project", encode(project.get()));
return baseUrl + pattern.replace(p);
}
public String toBranch(final Branch.NameKey branch) {
ParameterizedString pattern = new ParameterizedString(type.getBranch());
final Map<String, String> p = new HashMap<>();
p.put("project", encode(branch.getParentKey().get()));
p.put("branch", encode(branch.get()));
return baseUrl + pattern.replace(p);
}
public String toFile(String project, String commit, String file) {
Map<String, String> p = new HashMap<>();
p.put("project", encode(project));
p.put("commit", encode(commit));
p.put("file", encode(file));
ParameterizedString pattern = (file == null || file.isEmpty())
? new ParameterizedString(type.getRootTree())
: new ParameterizedString(type.getFile());
return baseUrl + pattern.replace(p);
}
public String toFileHistory(final Branch.NameKey branch, final String file) {
ParameterizedString pattern = new ParameterizedString(type.getFileHistory());
final Map<String, String> p = new HashMap<>();
p.put("project", encode(branch.getParentKey().get()));
p.put("branch", encode(branch.get()));
p.put("file", encode(file));
return baseUrl + pattern.replace(p);
}
private String encode(String segment) {
if (type.isUrlEncode()) {
return URL.encodeQueryString(type.replacePathSeparator(segment));
} else {
return segment;
}
}
}

View File

@@ -50,8 +50,8 @@ public class UserPopupPanel extends PluginSafePopupPanel {
userEmail.setText(account.email());
}
if (showSettingsLink) {
if (Gerrit.getConfig().getSwitchAccountUrl() != null) {
switchAccount.setHref(Gerrit.getConfig().getSwitchAccountUrl());
if (Gerrit.info().auth().switchAccountUrl() != null) {
switchAccount.setHref(Gerrit.info().auth().switchAccountUrl());
} else if (Gerrit.info().auth().isDev()
|| Gerrit.info().auth().isOpenId()) {
switchAccount.setHref(Gerrit.selfRedirect("/login/"));

View File

@@ -101,7 +101,7 @@ class ContactPanelShort extends Composite {
int row = 0;
if (!Gerrit.info().auth().canEdit(FieldName.USER_NAME)
&& Gerrit.getConfig().siteHasUsernames()) {
&& Gerrit.info().auth().siteHasUsernames()) {
infoPlainText.resizeRows(infoPlainText.getRowCount() + 1);
row(infoPlainText, row++, Util.C.userName(), new UsernameField());
}
@@ -109,12 +109,12 @@ class ContactPanelShort extends Composite {
if (!canEditFullName()) {
FlowPanel nameLine = new FlowPanel();
nameLine.add(nameTxt);
if (Gerrit.getConfig().getEditFullNameUrl() != null) {
if (Gerrit.info().auth().editFullNameUrl() != null) {
Button edit = new Button(Util.C.linkEditFullName());
edit.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.open(Gerrit.getConfig().getEditFullNameUrl(), "_blank", null);
Window.open(Gerrit.info().auth().editFullNameUrl(), "_blank", null);
}
});
nameLine.add(edit);

View File

@@ -40,7 +40,7 @@ public class MyPasswordScreen extends SettingsScreen {
protected void onInitUI() {
super.onInitUI();
String url = Gerrit.getConfig().getHttpPasswordUrl();
String url = Gerrit.info().auth().httpPasswordUrl();
if (url != null) {
Anchor link = new Anchor();
link.setText(Util.C.linkObtainPassword());

View File

@@ -61,13 +61,13 @@ public class MyProfileScreen extends SettingsScreen {
fieldIdx = 1;
}
info = new Grid((Gerrit.getConfig().siteHasUsernames() ? 1 : 0) + 4, 2);
info = new Grid((Gerrit.info().auth().siteHasUsernames() ? 1 : 0) + 4, 2);
info.setStyleName(Gerrit.RESOURCES.css().infoBlock());
info.addStyleName(Gerrit.RESOURCES.css().accountInfoBlock());
h.add(info);
int row = 0;
if (Gerrit.getConfig().siteHasUsernames()) {
if (Gerrit.info().auth().siteHasUsernames()) {
infoRow(row++, Util.C.userName());
}
infoRow(row++, Util.C.fullName());
@@ -110,7 +110,7 @@ public class MyProfileScreen extends SettingsScreen {
});
int row = 0;
if (Gerrit.getConfig().siteHasUsernames()) {
if (Gerrit.info().auth().siteHasUsernames()) {
info.setWidget(row++, fieldIdx, new UsernameField());
}
info.setText(row++, fieldIdx, account.getFullName());

View File

@@ -99,7 +99,7 @@ public class RegisterScreen extends AccountScreen {
formBody.add(fp);
}
if (Gerrit.getConfig().getSshdAddress() != null) {
if (Gerrit.info().hasSshd()) {
final FlowPanel sshKeyGroup = new FlowPanel();
sshKeyGroup.setStyleName(Gerrit.RESOURCES.css().registerScreenSection());
sshKeyGroup.add(new SmallHeading(Util.C.welcomeSshKeyHeading()));

View File

@@ -26,10 +26,10 @@ public abstract class SettingsScreen extends MenuScreen {
link(Util.C.tabPreferences(), PageLinks.SETTINGS_PREFERENCES);
link(Util.C.tabWatchedProjects(), PageLinks.SETTINGS_PROJECTS);
link(Util.C.tabContactInformation(), PageLinks.SETTINGS_CONTACT);
if (Gerrit.getConfig().getSshdAddress() != null) {
if (Gerrit.info().hasSshd()) {
link(Util.C.tabSshKeys(), PageLinks.SETTINGS_SSHKEYS);
}
if (Gerrit.getConfig().isHttpPasswordSettingsEnabled()) {
if (Gerrit.info().auth().isHttpPasswordSettingsEnabled()) {
link(Util.C.tabHttpAccess(), PageLinks.SETTINGS_HTTP_PASSWORD);
}
link(Util.C.tabWebIdentities(), PageLinks.SETTINGS_WEBIDENT);

View File

@@ -16,7 +16,7 @@ package com.google.gerrit.client.admin;
import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.GitwebLink;
import com.google.gerrit.client.config.GitWebInfo;
import com.google.gerrit.client.ui.Hyperlink;
import com.google.gerrit.client.ui.ParentProjectBox;
import com.google.gerrit.common.data.AccessSection;
@@ -121,7 +121,7 @@ public class ProjectAccessEditor extends Composite implements
inheritsFrom.getStyle().setDisplay(Display.NONE);
}
final GitwebLink c = Gerrit.getGitwebLink();
GitWebInfo c = Gerrit.info().gitWeb();
if (value.isConfigVisible() && c != null) {
history.getStyle().setDisplay(Display.BLOCK);
gitweb.setText(c.getLinkName());

View File

@@ -20,13 +20,13 @@ import com.google.gerrit.client.ConfirmationCallback;
import com.google.gerrit.client.ConfirmationDialog;
import com.google.gerrit.client.ErrorDialog;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.GitwebLink;
import com.google.gerrit.client.VoidResult;
import com.google.gerrit.client.WebLinkInfo;
import com.google.gerrit.client.access.AccessMap;
import com.google.gerrit.client.access.ProjectAccessInfo;
import com.google.gerrit.client.actions.ActionButton;
import com.google.gerrit.client.actions.ActionInfo;
import com.google.gerrit.client.config.GitWebInfo;
import com.google.gerrit.client.projects.BranchInfo;
import com.google.gerrit.client.projects.ProjectApi;
import com.google.gerrit.client.rpc.GerritCallback;
@@ -457,7 +457,7 @@ public class ProjectBranchesScreen extends ProjectScreen {
}
void populate(int row, BranchInfo k) {
final GitwebLink c = Gerrit.getGitwebLink();
GitWebInfo c = Gerrit.info().gitWeb();
if (k.canDelete()) {
CheckBox sel = new CheckBox();

View File

@@ -21,6 +21,8 @@ import com.google.gerrit.client.access.ProjectAccessInfo;
import com.google.gerrit.client.actions.ActionButton;
import com.google.gerrit.client.actions.ActionInfo;
import com.google.gerrit.client.change.Resources;
import com.google.gerrit.client.config.DownloadInfo.DownloadCommandInfo;
import com.google.gerrit.client.config.DownloadInfo.DownloadSchemeInfo;
import com.google.gerrit.client.download.DownloadPanel;
import com.google.gerrit.client.projects.ConfigInfo;
import com.google.gerrit.client.projects.ConfigInfo.ConfigParameterInfo;
@@ -65,6 +67,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class ProjectInfoScreen extends ProjectScreen {
private boolean isOwner;
@@ -677,23 +680,11 @@ public class ProjectInfoScreen extends ProjectScreen {
}
@Override
public void populateDownloadCommandLinks() {
if (!urls.isEmpty()) {
commands.add(cmdLinkfactory.new CloneCommandLink());
if (Gerrit.getConfig().getSshdAddress() != null && hasUserName()) {
commands.add(
cmdLinkfactory.new CloneWithCommitMsgHookCommandLink(getProjectKey()));
}
}
protected Set<DownloadCommandInfo> getCommands(DownloadSchemeInfo schemeInfo) {
return schemeInfo.cloneCommands(project);
}
}
private static boolean hasUserName() {
return Gerrit.isSignedIn()
&& Gerrit.getUserAccount().getUserName() != null
&& Gerrit.getUserAccount().getUserName().length() > 0;
}
private static class LabeledWidgetsGrid extends FlexTable {
private String labelSuffix;

View File

@@ -18,8 +18,8 @@ import static com.google.gerrit.common.PageLinks.ADMIN_PROJECTS;
import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.GitwebLink;
import com.google.gerrit.client.WebLinkInfo;
import com.google.gerrit.client.config.GitWebInfo;
import com.google.gerrit.client.projects.ProjectInfo;
import com.google.gerrit.client.projects.ProjectMap;
import com.google.gerrit.client.rpc.GerritCallback;
@@ -185,7 +185,7 @@ public class ProjectListScreen extends Screen {
}
private void addWebLinks(int row, ProjectInfo k) {
GitwebLink gitWebLink = Gerrit.getGitwebLink();
GitWebInfo gitWebLink = Gerrit.info().gitWeb();
List<WebLinkInfo> webLinks = Natives.asList(k.webLinks());
if (gitWebLink != null || (webLinks != null && !webLinks.isEmpty())) {
FlowPanel p = new FlowPanel();

View File

@@ -310,10 +310,10 @@ public class ChangeScreen extends Screen {
private void initReplyButton(ChangeInfo info, String revision) {
if (!info.revision(revision).isEdit()) {
reply.setTitle(Gerrit.getConfig().getReplyTitle());
reply.setTitle(Gerrit.info().change().replyLabel());
reply.setHTML(new SafeHtmlBuilder()
.openDiv()
.append(Gerrit.getConfig().getReplyLabel())
.append(Gerrit.info().change().replyLabel())
.closeDiv());
if (hasDraftComments) {
reply.setStyleName(style.highlight());
@@ -1201,7 +1201,7 @@ public class ChangeScreen extends Screen {
// TODO info card hover
String name = info.owner().name() != null
? info.owner().name()
: Gerrit.getConfig().getAnonymousCowardName();
: Gerrit.info().user().anonymousCowardName();
if (info.owner().avatar(AvatarInfo.DEFAULT_SIZE) != null) {
ownerPanel.insert(new AvatarImage(info.owner()), 0);
@@ -1303,7 +1303,7 @@ public class ChangeScreen extends Screen {
}
private void startPoller() {
if (Gerrit.isSignedIn() && 0 < Gerrit.getConfig().getChangeUpdateDelay()) {
if (Gerrit.isSignedIn() && 0 < Gerrit.info().change().updateDelay()) {
updateCheck = new UpdateCheckTimer(this);
updateCheck.schedule();
handlers.add(UserActivityMonitor.addValueChangeHandler(updateCheck));

View File

@@ -17,13 +17,13 @@ package com.google.gerrit.client.change;
import com.google.gerrit.client.AvatarImage;
import com.google.gerrit.client.FormatUtil;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.GitwebLink;
import com.google.gerrit.client.WebLinkInfo;
import com.google.gerrit.client.account.AccountInfo;
import com.google.gerrit.client.changes.ChangeInfo;
import com.google.gerrit.client.changes.ChangeInfo.CommitInfo;
import com.google.gerrit.client.changes.ChangeInfo.GitPerson;
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.client.config.GitWebInfo;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.client.ui.CommentLinkProcessor;
import com.google.gerrit.client.ui.InlineHyperlink;
@@ -135,7 +135,7 @@ class CommitBox extends Composite {
private void setWebLinks(ChangeInfo change, String revision,
RevisionInfo revInfo) {
GitwebLink gw = Gerrit.getGitwebLink();
GitWebInfo gw = Gerrit.info().gitWeb();
if (gw != null && gw.canLink(revInfo)) {
toAnchor(gw.toRevision(change.project(), revision),
gw.getLinkName());
@@ -184,7 +184,7 @@ class CommitBox extends Composite {
}
private void addLinks(String project, CommitInfo c, FlowPanel panel) {
GitwebLink gw = Gerrit.getGitwebLink();
GitWebInfo gw = Gerrit.info().gitWeb();
if (gw != null) {
Anchor a =
new Anchor(gw.getLinkName(), gw.toRevision(project, c.commit()));

View File

@@ -164,7 +164,7 @@ class DownloadBox extends VerticalPanel {
}
private void insertArchive() {
List<String> activated = Gerrit.getConfig().getArchiveFormats();
List<String> activated = Gerrit.info().download().archives();
if (activated.isEmpty()) {
return;
}

View File

@@ -204,7 +204,7 @@ class Message extends Composite {
if (info.author().name() != null) {
return info.author().name();
}
return Gerrit.getConfig().getAnonymousCowardName();
return Gerrit.info().user().anonymousCowardName();
}
return Util.C.messageNoAuthor();
}

View File

@@ -15,10 +15,10 @@
package com.google.gerrit.client.change;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.GitwebLink;
import com.google.gerrit.client.change.RelatedChanges.ChangeAndCommit;
import com.google.gerrit.client.changes.ChangeInfo.CommitInfo;
import com.google.gerrit.client.changes.Util;
import com.google.gerrit.client.config.GitWebInfo;
import com.google.gerrit.common.PageLinks;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gwt.core.client.GWT;
@@ -301,7 +301,7 @@ class RelatedChangesTab implements IsWidget {
sb.closeSpan();
sb.openSpan();
GitwebLink gw = Gerrit.getGitwebLink();
GitWebInfo gw = Gerrit.info().gitWeb();
if (gw != null && (!info.hasChangeNumber() || !info.hasRevisionNumber())) {
sb.setStyleName(RelatedChanges.R.css().gitweb());
sb.setAttribute("title", gw.getLinkName());
@@ -335,7 +335,7 @@ class RelatedChangesTab implements IsWidget {
id.getId());
}
GitwebLink gw = Gerrit.getGitwebLink();
GitWebInfo gw = Gerrit.info().gitWeb();
if (gw != null && project != null) {
return gw.toRevision(project, info.commit().commit());
}

View File

@@ -26,7 +26,7 @@ class UpdateCheckTimer extends Timer implements ValueChangeHandler<Boolean> {
private static final int MAX_PERIOD = 3 * 60 * 1000;
private static final int IDLE_PERIOD = 2 * 3600 * 1000;
private static final int POLL_PERIOD =
Gerrit.getConfig().getChangeUpdateDelay() * 1000;
Gerrit.info().change().updateDelay() * 1000;
private final ChangeScreen screen;
private int delay;

View File

@@ -53,7 +53,7 @@ public class ChangeApi {
input.subject(emptyToNull(subject));
input.baseChange(emptyToNull(base));
if (Gerrit.getConfig().isAllowDraftChanges()) {
if (Gerrit.info().change().allowDrafts()) {
input.status(Change.Status.DRAFT.toString());
}

View File

@@ -373,7 +373,7 @@ public class ChangeTable extends NavigationTable<ChangeInfo> {
}
private static Widget getSizeWidget(ChangeInfo c) {
int largeChangeSize = Gerrit.getConfig().getLargeChangeSize();
int largeChangeSize = Gerrit.info().change().largeChange();
int changedLines = c.insertions() + c.deletions();
int p = 100;
if (changedLines < largeChangeSize) {

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.client.config;
import com.google.gerrit.client.rpc.Natives;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.AuthType;
import com.google.gerrit.reviewdb.client.Account.FieldName;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;
@@ -28,6 +29,9 @@ public class AuthInfo extends JavaScriptObject {
return AuthType.valueOf(authTypeRaw());
}
public final boolean isLdap() {
return authType() == AuthType.LDAP || authType() == AuthType.LDAP_BIND;
}
public final boolean isOpenId() {
return authType() == AuthType.OPENID;
}
@@ -60,8 +64,32 @@ public class AuthInfo extends JavaScriptObject {
return fields;
}
public final boolean siteHasUsernames() {
if (isCustomExtension()
&& httpPasswordUrl() != null
&& !canEdit(FieldName.USER_NAME)) {
return false;
}
return true;
}
public final boolean isHttpPasswordSettingsEnabled() {
if (isLdap() && isGitBasicAuth()) {
return false;
}
return true;
}
public final native boolean useContributorAgreements()
/*-{ return this.use_contributor_agreements || false; }-*/;
public final native String loginUrl() /*-{ return this.login_url; }-*/;
public final native String loginText() /*-{ return this.login_text; }-*/;
public final native String switchAccountUrl() /*-{ return this.switch_account_url; }-*/;
public final native String registerUrl() /*-{ return this.register_url; }-*/;
public final native String registerText() /*-{ return this.register_text; }-*/;
public final native String editFullNameUrl() /*-{ return this.edit_full_name_url; }-*/;
public final native String httpPasswordUrl() /*-{ return this.http_password_url; }-*/;
public final native boolean isGitBasicAuth() /*-{ return this.is_git_basic_auth || false; }-*/;
private final native String authTypeRaw() /*-{ return this.auth_type; }-*/;
private final native JsArrayString _editableAccountFields()
/*-{ return this.editable_account_fields; }-*/;

View File

@@ -18,16 +18,29 @@ import com.google.gerrit.client.rpc.NativeMap;
import com.google.gerrit.client.rpc.NativeString;
import com.google.gerrit.client.rpc.Natives;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArrayString;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class DownloadInfo extends JavaScriptObject {
public final Set<String> schemes() {
return Natives.keys(_schemes());
}
public final List<String> archives() {
List<String> archives = new ArrayList<>();
for (String f : Natives.asList(_archives())) {
archives.add(f);
}
return archives;
}
public final native DownloadSchemeInfo scheme(String n) /*-{ return this.schemes[n]; }-*/;
private final native NativeMap<DownloadSchemeInfo> _schemes() /*-{ return this.schemes; }-*/;
private final native JsArrayString _archives() /*-{ return this.archives; }-*/;
protected DownloadInfo() {
}
@@ -50,6 +63,23 @@ public class DownloadInfo extends JavaScriptObject {
return command(commandName).replaceAll("\\$\\{project\\}", project);
}
public final Set<String> cloneCommandNames() {
return Natives.keys(_cloneCommands());
}
public final Set<DownloadCommandInfo> cloneCommands(String project) {
Set<DownloadCommandInfo> commands = new HashSet<>();
for (String commandName : cloneCommandNames()) {
commands.add(new DownloadCommandInfo(commandName, cloneCommand(
commandName, project)));
}
return commands;
}
public final String cloneCommand(String commandName, String project) {
return cloneCommand(commandName).replaceAll("\\$\\{project\\}", project);
}
public final String getUrl(String project) {
return url().replaceAll("\\$\\{project\\}", project);
}
@@ -59,7 +89,9 @@ public class DownloadInfo extends JavaScriptObject {
public final native boolean isAuthRequired() /*-{ return this.is_auth_required || false; }-*/;
public final native boolean isAuthSupported() /*-{ return this.is_auth_supported || false; }-*/;
public final native String command(String n) /*-{ return this.commands[n]; }-*/;
public final native String cloneCommand(String n) /*-{ return this.clone_commands[n]; }-*/;
private final native NativeMap<NativeString> _commands() /*-{ return this.commands; }-*/;
private final native NativeMap<NativeString> _cloneCommands() /*-{ return this.clone_commands; }-*/;
protected DownloadSchemeInfo() {
}

View File

@@ -36,6 +36,8 @@ public class GerritInfo extends JavaScriptObject {
public final native String allProjects() /*-{ return this.all_projects; }-*/;
public final native String allUsers() /*-{ return this.all_users; }-*/;
public final native String reportBugUrl() /*-{ return this.report_bug_url; }-*/;
public final native String reportBugText() /*-{ return this.report_bug_text; }-*/;
protected GerritInfo() {
}

View File

@@ -0,0 +1,169 @@
// Copyright (C) 2008 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.google.gerrit.client.config;
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.common.data.ParameterizedString;
import com.google.gerrit.reviewdb.client.Branch;
import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.http.client.URL;
import java.util.HashMap;
import java.util.Map;
public class GitWebInfo extends JavaScriptObject {
public final native String url() /*-{ return this.url; }-*/;
public final native GitWebTypeInfo type() /*-{ return this.type; }-*/;
/**
* Checks whether the given patch set can be linked.
*
* Draft patch sets can only be linked if linking of drafts was enabled by
* configuration.
*
* @param ps patch set to check whether it can be linked
* @return true if the patch set can be linked, otherwise false
*/
public final boolean canLink(PatchSet ps) {
return !ps.isDraft() || type().linkDrafts();
}
/**
* Checks whether the given revision can be linked.
*
* Draft revisions can only be linked if linking of drafts was enabled by
* configuration.
*
* @param revision revision to check whether it can be linked
* @return true if the revision can be linked, otherwise false
*/
public final boolean canLink(RevisionInfo revision) {
return revision.draft() || type().linkDrafts();
}
/**
* Returns the name for GitWeb links.
*
* @return the name for GitWeb links
*/
public final String getLinkName() {
return "(" + type().name() + ")";
}
/**
* Returns the GitWeb link to a revision.
*
* @param project the name of the project
* @param commit the commit ID
* @return GitWeb link to a revision
*/
public final String toRevision(String project, String commit) {
ParameterizedString pattern = new ParameterizedString(type().revision());
Map<String, String> p = new HashMap<>();
p.put("project", encode(project));
p.put("commit", encode(commit));
return url() + pattern.replace(p);
}
/**
* Returns the GitWeb link to a revision.
*
* @param project the name of the project
* @param ps the patch set
* @return GitWeb link to a revision
*/
public final String toRevision(Project.NameKey project, PatchSet ps) {
return toRevision(project.get(), ps.getRevision().get());
}
/**
* Returns the GitWeb link to a project.
*
* @param project the project name key
* @return GitWeb link to a project
*/
public final String toProject(Project.NameKey project) {
ParameterizedString pattern = new ParameterizedString(type().project());
Map<String, String> p = new HashMap<>();
p.put("project", encode(project.get()));
return url() + pattern.replace(p);
}
/**
* Returns the GitWeb link to a branch.
*
* @param branch the branch name key
* @return GitWeb link to a branch
*/
public final String toBranch(Branch.NameKey branch) {
ParameterizedString pattern = new ParameterizedString(type().branch());
Map<String, String> p = new HashMap<>();
p.put("project", encode(branch.getParentKey().get()));
p.put("branch", encode(branch.get()));
return url() + pattern.replace(p);
}
/**
* Returns the GitWeb link to a file.
*
* @param project the branch name key
* @param commit the commit ID
* @param file the path of the file
* @return GitWeb link to a file
*/
public final String toFile(String project, String commit, String file) {
Map<String, String> p = new HashMap<>();
p.put("project", encode(project));
p.put("commit", encode(commit));
p.put("file", encode(file));
ParameterizedString pattern = (file == null || file.isEmpty())
? new ParameterizedString(type().rootTree())
: new ParameterizedString(type().file());
return url() + pattern.replace(p);
}
/**
* Returns the GitWeb link to a file history.
*
* @param branch the branch name key
* @param file the path of the file
* @return GitWeb link to a file history
*/
public final String toFileHistory(Branch.NameKey branch, String file) {
ParameterizedString pattern = new ParameterizedString(type().fileHistory());
Map<String, String> p = new HashMap<>();
p.put("project", encode(branch.getParentKey().get()));
p.put("branch", encode(branch.get()));
p.put("file", encode(file));
return url() + pattern.replace(p);
}
private final String encode(String segment) {
if (type().urlEncode()) {
return URL.encodeQueryString(type().replacePathSeparator(segment));
} else {
return segment;
}
}
protected GitWebInfo() {
}
}

View File

@@ -0,0 +1,48 @@
// Copyright (C) 2015 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.google.gerrit.client.config;
import com.google.gwt.core.client.JavaScriptObject;
public class GitWebTypeInfo extends JavaScriptObject {
/**
* Replace the standard path separator ('/') in a branch name or project
* name with a custom path separator configured by the property
* gitweb.pathSeparator.
* @param urlSegment The branch or project to replace the path separator in
* @return the urlSegment with the standard path separator replaced by the
* custom path separator
*/
public final String replacePathSeparator(String urlSegment) {
if (!"/".equals(pathSeparator())) {
return urlSegment.replace("/", pathSeparator());
}
return urlSegment;
}
public final native String name() /*-{ return this.name; }-*/;
public final native String revision() /*-{ return this.revision; }-*/;
public final native String project() /*-{ return this.project; }-*/;
public final native String branch() /*-{ return this.branch; }-*/;
public final native String rootTree() /*-{ return this.root_tree; }-*/;
public final native String file() /*-{ return this.file; }-*/;
public final native String fileHistory() /*-{ return this.file_history; }-*/;
public final native String pathSeparator() /*-{ return this.path_separator; }-*/;
public final native boolean linkDrafts() /*-{ return this.link_drafts || false; }-*/;
public final native boolean urlEncode() /*-{ return this.url_encode || false; }-*/;
protected GitWebTypeInfo() {
}
}

View File

@@ -18,21 +18,60 @@ import com.google.gwt.core.client.JavaScriptObject;
public class ServerInfo extends JavaScriptObject {
public final native AuthInfo auth() /*-{ return this.auth; }-*/;
public final native ChangeConfigInfo change() /*-{ return this.change; }-*/;
public final native ContactStoreInfo contactStore() /*-{ return this.contact_store; }-*/;
public final native DownloadInfo download() /*-{ return this.download; }-*/;
public final native GerritInfo gerrit() /*-{ return this.gerrit; }-*/;
public final native GitWebInfo gitWeb() /*-{ return this.git_web; }-*/;
public final native SshdInfo sshd() /*-{ return this.sshd; }-*/;
public final native SuggestInfo suggest() /*-{ return this.suggest; }-*/;
public final native UserConfigInfo user() /*-{ return this.user; }-*/;
public final boolean hasContactStore() {
return contactStore() != null;
}
public final boolean hasSshd() {
return sshd() != null;
}
protected ServerInfo() {
}
public static class ChangeConfigInfo extends JavaScriptObject {
public final native boolean allowDrafts() /*-{ return this.allow_drafts || false; }-*/;
public final native int largeChange() /*-{ return this.large_change || 0; }-*/;
public final native String replyLabel() /*-{ return this.reply_label; }-*/;
public final native String replyTooltip() /*-{ return this.reply_tooltip; }-*/;
public final native int updateDelay() /*-{ return this.update_delay || 0; }-*/;
protected ChangeConfigInfo() {
}
}
public static class ContactStoreInfo extends JavaScriptObject {
public final native String url() /*-{ return this.url; }-*/;
protected ContactStoreInfo() {
}
}
public static class SshdInfo extends JavaScriptObject {
protected SshdInfo() {
}
}
public static class SuggestInfo extends JavaScriptObject {
public final native int from() /*-{ return this.from || 0; }-*/;
protected SuggestInfo() {
}
}
public static class UserConfigInfo extends JavaScriptObject {
public final native String anonymousCowardName() /*-{ return this.anonymous_coward_name; }-*/;
protected UserConfigInfo() {
}
}
}

View File

@@ -16,13 +16,13 @@ package com.google.gerrit.client.diff;
import com.google.gerrit.client.Dispatcher;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.GitwebLink;
import com.google.gerrit.client.WebLinkInfo;
import com.google.gerrit.client.changes.ChangeApi;
import com.google.gerrit.client.changes.ChangeInfo;
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
import com.google.gerrit.client.changes.ReviewInfo;
import com.google.gerrit.client.changes.Util;
import com.google.gerrit.client.config.GitWebInfo;
import com.google.gerrit.client.diff.DiffInfo.Region;
import com.google.gerrit.client.patches.PatchUtil;
import com.google.gerrit.client.rpc.CallbackGroup;
@@ -115,7 +115,8 @@ public class Header extends Composite {
return b.append(Util.C.commitMessage());
}
GitwebLink gw = (project != null && commit != null) ? Gerrit.getGitwebLink() : null;
GitWebInfo gw = (project != null && commit != null)
? Gerrit.info().gitWeb() : null;
int s = path.lastIndexOf('/') + 1;
if (gw != null && s > 0) {
String base = path.substring(0, s - 1);
@@ -192,7 +193,7 @@ public class Header extends Composite {
}
void setChangeInfo(ChangeInfo info) {
GitwebLink gw = Gerrit.getGitwebLink();
GitWebInfo gw = Gerrit.info().gitWeb();
if (gw != null) {
for (RevisionInfo rev : Natives.asList(info.revisions().values())) {
if (patchSetId.getId().equals(rev.id())) {

View File

@@ -205,7 +205,7 @@ class PublishedBox extends CommentBox {
if (info.author().name() != null) {
return info.author().name();
}
return Gerrit.getConfig().getAnonymousCowardName();
return Gerrit.info().user().anonymousCowardName();
}
return Util.C.messageNoAuthor();
}

View File

@@ -22,6 +22,10 @@ public class DocInfo extends JavaScriptObject {
public final native String title() /*-{ return this.title; }-*/;
public final native String url() /*-{ return this.url; }-*/;
public static DocInfo create() {
return (DocInfo) createObject();
}
protected DocInfo() {
}

View File

@@ -15,92 +15,24 @@
package com.google.gerrit.client.download;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.client.config.DownloadInfo.DownloadCommandInfo;
import com.google.gwt.aria.client.Roles;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwtexpui.clippy.client.CopyableLabel;
public abstract class DownloadCommandLink extends Anchor implements ClickHandler {
public static class CopyableCommandLinkFactory {
protected CopyableLabel copyLabel = null;
protected Widget widget;
public class DownloadCommandLink extends Anchor implements ClickHandler {
private final CopyableLabel copyLabel;
private final String command;
public class CloneCommandLink extends DownloadCommandLink {
public CloneCommandLink() {
super("clone");
}
public DownloadCommandLink(CopyableLabel copyLabel,
DownloadCommandInfo commandInfo) {
super(commandInfo.name());
this.copyLabel = copyLabel;
this.command = commandInfo.command();
@Override
protected void setCurrentUrl(DownloadUrlLink link) {
widget.setVisible(true);
copyLabel.setText("git clone " + link.getUrlData());
}
}
public class CloneWithCommitMsgHookCommandLink extends DownloadCommandLink {
private final Project.NameKey project;
public CloneWithCommitMsgHookCommandLink(Project.NameKey project) {
super("clone with commit-msg hook");
this.project = project;
}
@Override
protected void setCurrentUrl(DownloadUrlLink link) {
widget.setVisible(true);
String sshPort = null;
String sshAddr = Gerrit.getConfig().getSshdAddress();
int p = sshAddr.lastIndexOf(':');
if (p != -1 && !sshAddr.endsWith(":")) {
sshPort = sshAddr.substring(p + 1);
}
StringBuilder cmd = new StringBuilder();
cmd.append("git clone ");
cmd.append(link.getUrlData());
cmd.append(" && scp -p ");
if (sshPort != null) {
cmd.append("-P ");
cmd.append(sshPort);
cmd.append(" ");
}
cmd.append(Gerrit.getUserAccount().getUserName());
cmd.append("@");
if (sshAddr.startsWith("*:") || p == -1) {
cmd.append(Window.Location.getHostName());
} else {
cmd.append(sshAddr.substring(0, p));
}
cmd.append(":hooks/commit-msg ");
p = project.get().lastIndexOf('/');
if (p != -1) {
cmd.append(project.get().substring(p + 1));
} else {
cmd.append(project.get());
}
cmd.append("/.git/hooks/");
copyLabel.setText(cmd.toString());
}
}
public CopyableCommandLinkFactory(CopyableLabel label, Widget widget) {
copyLabel = label;
this.widget = widget;
}
}
public DownloadCommandLink(String text) {
super(text);
setStyleName(Gerrit.RESOURCES.css().downloadLink());
Roles.getTabRole().set(getElement());
addClickHandler(this);
@@ -115,6 +47,8 @@ public abstract class DownloadCommandLink extends Anchor implements ClickHandler
}
void select() {
copyLabel.setText(command);
DownloadCommandPanel parent = (DownloadCommandPanel) getParent();
for (Widget w : parent) {
if (w != this && w instanceof DownloadCommandLink) {
@@ -124,6 +58,4 @@ public abstract class DownloadCommandLink extends Anchor implements ClickHandler
parent.setCurrentCommand(this);
addStyleName(Gerrit.RESOURCES.css().downloadLink_Active());
}
protected abstract void setCurrentUrl(DownloadUrlLink link);
}

View File

@@ -21,7 +21,6 @@ import com.google.gwt.user.client.ui.Widget;
public class DownloadCommandPanel extends FlowPanel {
private DownloadCommandLink currentCommand;
private DownloadUrlLink currentUrl;
public DownloadCommandPanel() {
setStyleName(Gerrit.RESOURCES.css().downloadLinkList());
@@ -37,7 +36,12 @@ public class DownloadCommandPanel extends FlowPanel {
for (Widget w : this) {
if (w instanceof DownloadCommandLink) {
final DownloadCommandLink d = (DownloadCommandLink) w;
DownloadCommandLink d = (DownloadCommandLink) w;
if (currentCommand != null
&& d.getText().equals(currentCommand.getText())) {
d.select();
return;
}
if (first == null) {
first = d;
}
@@ -51,19 +55,7 @@ public class DownloadCommandPanel extends FlowPanel {
}
}
void setCurrentUrl(DownloadUrlLink link) {
currentUrl = link;
update();
}
void setCurrentCommand(DownloadCommandLink cmd) {
currentCommand = cmd;
update();
}
private void update() {
if (currentCommand != null && currentUrl != null) {
currentCommand.setCurrentUrl(currentUrl);
}
}
}

View File

@@ -15,34 +15,32 @@
package com.google.gerrit.client.download;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.config.DownloadInfo.DownloadCommandInfo;
import com.google.gerrit.client.config.DownloadInfo.DownloadSchemeInfo;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwtexpui.clippy.client.CopyableLabel;
import java.util.Set;
public abstract class DownloadPanel extends FlowPanel {
protected String projectName;
protected final String project;
protected DownloadCommandLink.CopyableCommandLinkFactory cmdLinkfactory;
protected DownloadCommandPanel commands = new DownloadCommandPanel();
protected DownloadUrlPanel urls = new DownloadUrlPanel(commands);
protected CopyableLabel copyLabel = new CopyableLabel("");
private final DownloadCommandPanel commands = new DownloadCommandPanel();
private final DownloadUrlPanel urls = new DownloadUrlPanel();
private final CopyableLabel copyLabel = new CopyableLabel("");
public DownloadPanel(String project, boolean allowAnonymous) {
this.projectName = project;
this.project = project;
copyLabel.setStyleName(Gerrit.RESOURCES.css().downloadLinkCopyLabel());
urls.add(DownloadUrlLink.createDownloadUrlLinks(project, allowAnonymous));
cmdLinkfactory = new DownloadCommandLink.CopyableCommandLinkFactory(
copyLabel, urls);
urls.add(DownloadUrlLink.createDownloadUrlLinks(allowAnonymous, this));
populateDownloadCommandLinks();
setupWidgets();
}
protected void setupWidgets() {
if (!commands.isEmpty()) {
private void setupWidgets() {
if (!urls.isEmpty()) {
final AccountGeneralPreferences pref;
if (Gerrit.isSignedIn()) {
pref = Gerrit.getUserAccount().getGeneralPreferences();
@@ -50,7 +48,6 @@ public abstract class DownloadPanel extends FlowPanel {
pref = new AccountGeneralPreferences();
pref.resetToDefaults();
}
commands.select();
urls.select(pref.getDownloadUrl());
FlowPanel p = new FlowPanel();
@@ -66,5 +63,14 @@ public abstract class DownloadPanel extends FlowPanel {
}
}
protected abstract void populateDownloadCommandLinks();
void populateDownloadCommandLinks(DownloadSchemeInfo schemeInfo) {
commands.clear();
for (DownloadCommandInfo cmd : getCommands(schemeInfo)) {
commands.add(new DownloadCommandLink(copyLabel, cmd));
}
commands.select();
}
protected abstract Set<DownloadCommandInfo> getCommands(
DownloadSchemeInfo schemeInfo);
}

View File

@@ -15,13 +15,12 @@
package com.google.gerrit.client.download;
import com.google.gerrit.client.Gerrit;
import com.google.gerrit.client.config.DownloadInfo.DownloadSchemeInfo;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences;
import com.google.gerrit.reviewdb.client.AccountGeneralPreferences.DownloadScheme;
import com.google.gwt.aria.client.Roles;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwtjsonrpc.common.AsyncCallback;
@@ -29,164 +28,77 @@ import com.google.gwtjsonrpc.common.VoidResult;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class DownloadUrlLink extends Anchor implements ClickHandler {
public static class AnonGitLink extends DownloadUrlLink {
public AnonGitLink(String project) {
super(DownloadScheme.ANON_GIT, Util.M.anonymousDownload("Git"), project);
private enum KnownScheme {
ANON_GIT(DownloadScheme.ANON_GIT, "git", Util.M.anonymousDownload("Git")),
ANON_HTTP(DownloadScheme.ANON_HTTP, "anonymous http", Util.M.anonymousDownload("HTTP")),
SSH(DownloadScheme.SSH, "ssh", "SSH"),
HTTP(DownloadScheme.HTTP, "http", "HTTP");
public final DownloadScheme downloadScheme;
public final String name;
public final String text;
private KnownScheme(DownloadScheme downloadScheme, String name, String text) {
this.downloadScheme = downloadScheme;
this.name = name;
this.text = text;
}
@Override
public String getUrlData() {
StringBuilder r = new StringBuilder();
r.append(Gerrit.getConfig().getGitDaemonUrl());
r.append(projectName);
return r.toString();
}
}
public static class AnonHttpLink extends DownloadUrlLink {
public AnonHttpLink(String project) {
super(DownloadScheme.ANON_HTTP, Util.M.anonymousDownload("HTTP"), project);
}
@Override
public String getUrlData() {
StringBuilder r = new StringBuilder();
if (Gerrit.getConfig().getGitHttpUrl() != null) {
r.append(Gerrit.getConfig().getGitHttpUrl());
} else {
r.append(hostPageUrl);
}
r.append(projectName);
return r.toString();
}
}
public static class SshLink extends DownloadUrlLink {
public SshLink(String project) {
super(DownloadScheme.SSH, "SSH", project);
}
@Override
public String getUrlData() {
String sshAddr = Gerrit.getConfig().getSshdAddress();
final StringBuilder r = new StringBuilder();
r.append("ssh://");
r.append(Gerrit.getUserAccount().getUserName());
r.append("@");
if (sshAddr.startsWith("*:") || "".equals(sshAddr)) {
r.append(Window.Location.getHostName());
}
if (sshAddr.startsWith("*")) {
sshAddr = sshAddr.substring(1);
}
r.append(sshAddr);
r.append("/");
r.append(projectName);
return r.toString();
}
}
public static class HttpLink extends DownloadUrlLink {
protected boolean anonymous;
public HttpLink(String project, boolean anonymous) {
super(DownloadScheme.HTTP, "HTTP", project);
this.anonymous = anonymous;
}
@Override
public String getUrlData() {
final StringBuilder r = new StringBuilder();
if (Gerrit.getConfig().getGitHttpUrl() != null
&& (anonymous || siteReliesOnHttp())) {
r.append(Gerrit.getConfig().getGitHttpUrl());
} else {
String base = hostPageUrl;
int p = base.indexOf("://");
int s = base.indexOf('/', p + 3);
if (s < 0) {
s = base.length();
static KnownScheme get(String name) {
for (KnownScheme s : values()) {
if (s.name.equals(name)) {
return s;
}
String host = base.substring(p + 3, s);
if (host.contains("@")) {
host = host.substring(host.indexOf('@') + 1);
}
r.append(base.substring(0, p + 3));
r.append(Gerrit.getUserAccount().getUserName());
r.append('@');
r.append(host);
r.append(base.substring(s));
}
r.append(projectName);
return r.toString();
return null;
}
}
public static boolean siteReliesOnHttp() {
return Gerrit.getConfig().getGitHttpUrl() != null
&& Gerrit.info().auth().isCustomExtension()
&& !Gerrit.getConfig().siteHasUsernames();
}
public static List<DownloadUrlLink> createDownloadUrlLinks(String project,
boolean allowAnonymous) {
public static List<DownloadUrlLink> createDownloadUrlLinks(
boolean allowAnonymous, DownloadPanel downloadPanel) {
List<DownloadUrlLink> urls = new ArrayList<>();
Set<String> allowedSchemes = Gerrit.info().download().schemes();
for (String s : Gerrit.info().download().schemes()) {
DownloadSchemeInfo scheme = Gerrit.info().download().scheme(s);
if (scheme.isAuthRequired() && !allowAnonymous) {
continue;
}
if (allowAnonymous
&& Gerrit.getConfig().getGitDaemonUrl() != null
&& allowedSchemes.contains("git")) {
urls.add(new DownloadUrlLink.AnonGitLink(project));
}
if (allowAnonymous
&& allowedSchemes.contains("anonymous http")) {
urls.add(new DownloadUrlLink.AnonHttpLink(project));
}
if (Gerrit.getConfig().getSshdAddress() != null
&& hasUserName()
&& allowedSchemes.contains("ssh")) {
urls.add(new DownloadUrlLink.SshLink(project));
}
if ((hasUserName() || siteReliesOnHttp())
&& allowedSchemes.contains("http")) {
urls.add(new DownloadUrlLink.HttpLink(project, allowAnonymous));
KnownScheme knownScheme = KnownScheme.get(s);
if (knownScheme != null) {
urls.add(new DownloadUrlLink(downloadPanel, scheme,
knownScheme.downloadScheme, knownScheme.text));
} else {
urls.add(new DownloadUrlLink(downloadPanel, scheme, s));
}
}
return urls;
}
private static boolean hasUserName() {
return Gerrit.isSignedIn()
&& Gerrit.getUserAccount().getUserName() != null
&& Gerrit.getUserAccount().getUserName().length() > 0;
private final DownloadPanel downloadPanel;
private final DownloadSchemeInfo schemeInfo;
private final DownloadScheme urlType;
public DownloadUrlLink(DownloadPanel downloadPanel,
DownloadSchemeInfo schemeInfo, String text) {
this(downloadPanel, schemeInfo, null, text);
}
protected DownloadScheme urlType;
protected String projectName;
protected String urlData;
protected String hostPageUrl = GWT.getHostPageBaseURL();
public DownloadUrlLink(DownloadScheme urlType, String text, String project) {
public DownloadUrlLink(DownloadPanel downloadPanel,
DownloadSchemeInfo schemeInfo, DownloadScheme urlType, String text) {
super(text);
setStyleName(Gerrit.RESOURCES.css().downloadLink());
Roles.getTabRole().set(getElement());
addClickHandler(this);
if (!hostPageUrl.endsWith("/")) {
hostPageUrl += "/";
}
this.downloadPanel = downloadPanel;
this.schemeInfo = schemeInfo;
this.urlType = urlType;
this.projectName = project;
}
public String getUrlData() {
return urlData;
public DownloadScheme getUrlType() {
return urlType;
}
@Override
@@ -196,7 +108,7 @@ public class DownloadUrlLink extends Anchor implements ClickHandler {
select();
if (Gerrit.isSignedIn()) {
if (Gerrit.isSignedIn() && urlType != null) {
// If the user is signed-in, remember this choice for future panels.
//
AccountGeneralPreferences pref =
@@ -216,13 +128,14 @@ public class DownloadUrlLink extends Anchor implements ClickHandler {
}
void select() {
downloadPanel.populateDownloadCommandLinks(schemeInfo);
DownloadUrlPanel parent = (DownloadUrlPanel) getParent();
for (Widget w : parent) {
if (w != this && w instanceof DownloadUrlLink) {
w.removeStyleName(Gerrit.RESOURCES.css().downloadLink_Active());
}
}
parent.setCurrentUrl(this);
addStyleName(Gerrit.RESOURCES.css().downloadLink_Active());
}
}

View File

@@ -23,10 +23,8 @@ import com.google.gwt.user.client.ui.Widget;
import java.util.Collection;
public class DownloadUrlPanel extends FlowPanel {
private final DownloadCommandPanel commandPanel;
public DownloadUrlPanel(final DownloadCommandPanel commandPanel) {
this.commandPanel = commandPanel;
public DownloadUrlPanel() {
setStyleName(Gerrit.RESOURCES.css().downloadLinkList());
Roles.getTablistRole().set(getElement());
}
@@ -44,7 +42,7 @@ public class DownloadUrlPanel extends FlowPanel {
if (first == null) {
first = d;
}
if (d.urlType == urlType) {
if (d.getUrlType() == urlType) {
d.select();
return;
}
@@ -58,10 +56,6 @@ public class DownloadUrlPanel extends FlowPanel {
}
}
void setCurrentUrl(DownloadUrlLink link) {
commandPanel.setCurrentUrl(link);
}
public void add(Collection<DownloadUrlLink> links) {
for (Widget link: links) {
add(link);

View File

@@ -29,7 +29,7 @@ public abstract class SuggestAfterTypingNCharsOracle extends HighlightSuggestOra
@Override
protected void onRequestSuggestions(Request req, Callback cb) {
if (req.getQuery().length() >= Gerrit.getConfig().getSuggestFrom()) {
if (req.getQuery().length() >= Gerrit.info().suggest().from()) {
_onRequestSuggestions(req, cb);
} else {
List<Suggestion> none = Collections.emptyList();