Expose GitWeb config via /config/server/info REST endpoint

In the Gerrit Client retrieve the GitWeb configuration via REST and
remove the GitWeb configuration from the config that is embedded in
the host page data.

In order to provide the GitWeb configuration from the REST endpoint
the GitWeb configuration must be bound in the sysinjector (the binding
of the GitWebModule stays in the webinjector).

Change-Id: I640e645f6c9a72d5539f33e28721f0cff93e732d
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2015-05-08 13:40:40 +02:00
committed by David Pursehouse
parent e55a72f504
commit 7023f47c4b
24 changed files with 321 additions and 206 deletions

View File

@@ -44,7 +44,6 @@ 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;
@@ -295,11 +294,6 @@ public class Gerrit implements EntryPoint {
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;

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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -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

@@ -21,6 +21,7 @@ public class ServerInfo extends JavaScriptObject {
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 boolean hasContactStore() {
return contactStore() != null;

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())) {