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:
parent
e55a72f504
commit
7023f47c4b
Documentation
gerrit-common/src/main/java/com/google/gerrit/common/data
gerrit-gwtui/src/main/java/com/google/gerrit/client
gerrit-httpd/src/main/java/com/google/gerrit/httpd
gerrit-server/src
main/java/com/google/gerrit/server/config
test/java/com/google/gerrit/server/config
@ -1095,6 +1095,54 @@ Name of the link:config-gerrit.html#gerrit.allUsers[project in which
|
||||
meta data of all users is stored].
|
||||
|================================
|
||||
|
||||
[[git-web-info]]
|
||||
=== GitWebInfo
|
||||
The `GitWebInfo` entity contains information about the
|
||||
link:config-gerrit.html#gitweb[GitWeb] configuration.
|
||||
|
||||
[options="header",cols="1,6"]
|
||||
|=======================
|
||||
|Field Name |Description
|
||||
|`url` |
|
||||
The link:config-gerrit.html#gitweb.url[GitWeb base URL].
|
||||
|`type` |
|
||||
The link:config-gerrit.html#gitweb.type[GitWeb type] as
|
||||
link:#git-web-type-info[GitWebTypeInfo] entity.
|
||||
|=======================
|
||||
|
||||
[[git-web-type-info]]
|
||||
=== GitWebTypeInfo
|
||||
The `GitWebTypeInfo` entity contains information about the
|
||||
link:config-gerrit.html#gitweb[GitWeb] configuration.
|
||||
|
||||
[options="header",cols="1,^1,5"]
|
||||
|=============================
|
||||
|Field Name ||Description
|
||||
|`name` ||
|
||||
The link:config-gerrit.html#gitweb.linkname[GitWeb link name].
|
||||
|`revision` |optional|
|
||||
The link:config-gerrit.html#gitweb.revision[GitWeb revision pattern].
|
||||
|`project` |optional|
|
||||
The link:config-gerrit.html#gitweb.project[GitWeb project pattern].
|
||||
|`branch` |optional|
|
||||
The link:config-gerrit.html#gitweb.branch[GitWeb branch pattern].
|
||||
|`root_tree` |optional|
|
||||
The link:config-gerrit.html#gitweb.roottree[GitWeb root tree pattern].
|
||||
|`file` |optional|
|
||||
The link:config-gerrit.html#gitweb.file[GitWeb file pattern].
|
||||
|`file_history` |optional|
|
||||
The link:config-gerrit.html#gitweb.filehistory[GitWeb file history
|
||||
pattern].
|
||||
|`path_separator`||
|
||||
The link:config-gerrit.html#gitweb.pathSeparator[GitWeb path separator].
|
||||
|`link_drafts` |optional|
|
||||
link:config-gerrit.html#gitweb.linkDrafts[Whether Gerrit should provide
|
||||
links to GitWeb on draft patch set.]
|
||||
|`url_encode` |optional|
|
||||
link:config-gerrit.html#gitweb.urlEncode[Whether Gerrit should encode
|
||||
the generated viewer URL.]
|
||||
|=============================
|
||||
|
||||
[[hit-ration-info]]
|
||||
=== HitRatioInfo
|
||||
The `HitRatioInfo` entity contains information about the hit ratio of a
|
||||
@ -1179,6 +1227,9 @@ information about Gerrit
|
||||
Information about the configuration from the
|
||||
link:config-gerrit.html#gerrit[gerrit] section as link:#gerrit-info[
|
||||
GerritInfo] entity.
|
||||
|`git_web` |optional|
|
||||
Information about the link:config-gerrit.html#gitweb[GitWeb]
|
||||
configuration as link:#git-web-info[GitWebInfo] entity.
|
||||
|=======================================
|
||||
|
||||
[[summary-info]]
|
||||
|
@ -19,7 +19,6 @@ public class GerritConfig implements Cloneable {
|
||||
protected String reportBugUrl;
|
||||
protected String reportBugText;
|
||||
|
||||
protected GitwebConfig gitweb;
|
||||
protected String gitDaemonUrl;
|
||||
protected String sshdAddress;
|
||||
protected boolean documentationAvailable;
|
||||
@ -47,14 +46,6 @@ public class GerritConfig implements Cloneable {
|
||||
reportBugText = t;
|
||||
}
|
||||
|
||||
public GitwebConfig getGitwebLink() {
|
||||
return gitweb;
|
||||
}
|
||||
|
||||
public void setGitwebLink(final GitwebConfig w) {
|
||||
gitweb = w;
|
||||
}
|
||||
|
||||
public String getGitDaemonUrl() {
|
||||
return gitDaemonUrl;
|
||||
}
|
||||
|
@ -1,29 +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.common.data;
|
||||
|
||||
/** Link to an external gitweb server. */
|
||||
public class GitwebConfig {
|
||||
public String baseUrl;
|
||||
public GitWebType type;
|
||||
|
||||
protected GitwebConfig() {
|
||||
}
|
||||
|
||||
public GitwebConfig(final String base, final GitWebType gitWebType) {
|
||||
baseUrl = base;
|
||||
type = gitWebType;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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());
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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()));
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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() {
|
||||
}
|
||||
}
|
@ -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() {
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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())) {
|
||||
|
@ -16,7 +16,6 @@ package com.google.gerrit.httpd;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.gerrit.common.data.GerritConfig;
|
||||
import com.google.gerrit.common.data.GitwebConfig;
|
||||
import com.google.gerrit.server.config.AnonymousCowardName;
|
||||
import com.google.gerrit.server.config.ConfigUtil;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
@ -34,7 +33,6 @@ import javax.servlet.ServletContext;
|
||||
|
||||
class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
private final Config cfg;
|
||||
private final GitWebConfig gitWebConfig;
|
||||
private final SshInfo sshInfo;
|
||||
|
||||
private final ServletContext servletContext;
|
||||
@ -43,12 +41,10 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
@Inject
|
||||
GerritConfigProvider(
|
||||
@GerritServerConfig Config gsc,
|
||||
GitWebConfig gwc,
|
||||
SshInfo si,
|
||||
ServletContext sc,
|
||||
@AnonymousCowardName String acn) {
|
||||
cfg = gsc;
|
||||
gitWebConfig = gwc;
|
||||
sshInfo = si;
|
||||
servletContext = sc;
|
||||
anonymousCowardName = acn;
|
||||
@ -68,11 +64,6 @@ class GerritConfigProvider implements Provider<GerritConfig> {
|
||||
config.setReportBugUrl(cfg.getString("gerrit", null, "reportBugUrl"));
|
||||
config.setReportBugText(cfg.getString("gerrit", null, "reportBugText"));
|
||||
|
||||
if (gitWebConfig.getUrl() != null) {
|
||||
config.setGitwebLink(new GitwebConfig(gitWebConfig.getUrl(), gitWebConfig
|
||||
.getGitWebType()));
|
||||
}
|
||||
|
||||
if (sshInfo != null && !sshInfo.getHostKeys().isEmpty()) {
|
||||
config.setSshdAddress(sshInfo.getHostKeys().get(0).getHost());
|
||||
}
|
||||
|
@ -31,12 +31,11 @@ import com.google.gerrit.server.RemotePeer;
|
||||
import com.google.gerrit.server.config.AuthConfig;
|
||||
import com.google.gerrit.server.config.CanonicalWebUrl;
|
||||
import com.google.gerrit.server.config.GerritRequestModule;
|
||||
import com.google.gerrit.server.config.GitWebConfig;
|
||||
import com.google.gerrit.server.git.AsyncReceiveCommits;
|
||||
import com.google.gerrit.server.util.GuiceRequestScopePropagator;
|
||||
import com.google.gerrit.server.util.RequestScopePropagator;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.ProvisionException;
|
||||
import com.google.inject.servlet.RequestScoped;
|
||||
|
||||
@ -49,21 +48,14 @@ public class WebModule extends LifecycleModule {
|
||||
private final GerritOptions options;
|
||||
|
||||
@Inject
|
||||
WebModule(final AuthConfig authConfig,
|
||||
@CanonicalWebUrl @Nullable final String canonicalUrl,
|
||||
WebModule(AuthConfig authConfig,
|
||||
@CanonicalWebUrl @Nullable String canonicalUrl,
|
||||
GerritOptions options,
|
||||
final Injector creatingInjector) {
|
||||
GitWebConfig gitWebConfig) {
|
||||
this.authConfig = authConfig;
|
||||
this.wantSSL = canonicalUrl != null && canonicalUrl.startsWith("https:");
|
||||
this.options = options;
|
||||
|
||||
this.gitWebConfig =
|
||||
creatingInjector.createChildInjector(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GitWebConfig.class);
|
||||
}
|
||||
}).getInstance(GitWebConfig.class);
|
||||
this.gitWebConfig = gitWebConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -84,7 +76,6 @@ public class WebModule extends LifecycleModule {
|
||||
install(new GerritRequestModule());
|
||||
install(new GitOverHttpServlet.Module(options.enableMasterFeatures()));
|
||||
|
||||
bind(GitWebConfig.class).toInstance(gitWebConfig);
|
||||
if (gitWebConfig.getGitwebCGI() != null) {
|
||||
install(new GitWebModule());
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ package com.google.gerrit.httpd.gitweb;
|
||||
import static com.google.gerrit.common.FileUtil.lastModified;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gerrit.httpd.GitWebConfig;
|
||||
import com.google.gerrit.server.config.GitWebConfig;
|
||||
import com.google.gwtexpui.server.CacheHeaders;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
@ -16,8 +16,8 @@ package com.google.gerrit.httpd.gitweb;
|
||||
|
||||
import static com.google.gerrit.common.FileUtil.lastModified;
|
||||
|
||||
import com.google.gerrit.httpd.GitWebConfig;
|
||||
import com.google.gerrit.httpd.HtmlDomUtil;
|
||||
import com.google.gerrit.server.config.GitWebConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gwtexpui.server.CacheHeaders;
|
||||
import com.google.gwtjsonrpc.server.RPCServletUtils;
|
||||
|
@ -17,7 +17,7 @@ package com.google.gerrit.httpd.gitweb;
|
||||
import static com.google.gerrit.common.FileUtil.lastModified;
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.gerrit.httpd.GitWebConfig;
|
||||
import com.google.gerrit.server.config.GitWebConfig;
|
||||
import com.google.gwtexpui.server.CacheHeaders;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
@ -34,11 +34,11 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import com.google.gerrit.common.PageLinks;
|
||||
import com.google.gerrit.common.data.GerritConfig;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
import com.google.gerrit.httpd.GitWebConfig;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.AnonymousUser;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.config.GitWebConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.gerrit.server.git.LocalDiskRepositoryManager;
|
||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||
|
@ -215,6 +215,7 @@ public class GerritGlobalModule extends FactoryModule {
|
||||
bind(ToolsCatalog.class);
|
||||
bind(EventFactory.class);
|
||||
bind(TransferConfig.class);
|
||||
bind(GitWebConfig.class);
|
||||
|
||||
bind(GcConfig.class);
|
||||
|
||||
|
@ -17,6 +17,7 @@ package com.google.gerrit.server.config;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.common.data.GitWebType;
|
||||
import com.google.gerrit.extensions.config.DownloadCommand;
|
||||
import com.google.gerrit.extensions.config.DownloadScheme;
|
||||
import com.google.gerrit.extensions.registration.DynamicMap;
|
||||
@ -45,6 +46,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
private final GetArchive.AllowedFormats archiveFormats;
|
||||
private final AllProjectsName allProjectsName;
|
||||
private final AllUsersName allUsersName;
|
||||
private final GitWebConfig gitWebConfig;
|
||||
|
||||
@Inject
|
||||
public GetServerInfo(
|
||||
@ -55,7 +57,8 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
DynamicMap<DownloadCommand> downloadCommands,
|
||||
GetArchive.AllowedFormats archiveFormats,
|
||||
AllProjectsName allProjectsName,
|
||||
AllUsersName allUsersName) {
|
||||
AllUsersName allUsersName,
|
||||
GitWebConfig gitWebConfig) {
|
||||
this.config = config;
|
||||
this.authConfig = authConfig;
|
||||
this.realm = realm;
|
||||
@ -64,6 +67,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
this.archiveFormats = archiveFormats;
|
||||
this.allProjectsName = allProjectsName;
|
||||
this.allUsersName = allUsersName;
|
||||
this.gitWebConfig = gitWebConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -74,6 +78,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
info.download =
|
||||
new DownloadInfo(downloadSchemes, downloadCommands, archiveFormats);
|
||||
info.gerrit = new GerritInfo(allProjectsName, allUsersName);
|
||||
info.gitWeb = getGitWebInfo(gitWebConfig);
|
||||
return info;
|
||||
}
|
||||
|
||||
@ -88,6 +93,11 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
return contactStore;
|
||||
}
|
||||
|
||||
private GitWebInfo getGitWebInfo(GitWebConfig cfg) {
|
||||
return cfg.getUrl() != null && cfg.getGitWebType() != null
|
||||
? new GitWebInfo(cfg) : null;
|
||||
}
|
||||
|
||||
private static Boolean toBoolean(boolean v) {
|
||||
return v ? v : null;
|
||||
}
|
||||
@ -97,6 +107,7 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
public ContactStoreInfo contactStore;
|
||||
public DownloadInfo download;
|
||||
public GerritInfo gerrit;
|
||||
public GitWebInfo gitWeb;
|
||||
}
|
||||
|
||||
public static class AuthInfo {
|
||||
@ -213,4 +224,14 @@ public class GetServerInfo implements RestReadView<ConfigResource> {
|
||||
allUsers = allUsersName.get();
|
||||
}
|
||||
}
|
||||
|
||||
public static class GitWebInfo {
|
||||
public String url;
|
||||
public GitWebType type;
|
||||
|
||||
public GitWebInfo(GitWebConfig cfg) {
|
||||
url = cfg.getUrl();
|
||||
type = cfg.getGitWebType();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,14 +12,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.httpd;
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import static java.nio.file.Files.isExecutable;
|
||||
import static java.nio.file.Files.isRegularFile;
|
||||
|
||||
import com.google.gerrit.common.data.GitWebType;
|
||||
import com.google.gerrit.server.config.GerritServerConfig;
|
||||
import com.google.gerrit.server.config.SitePaths;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
@ -12,7 +12,9 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.httpd;
|
||||
package com.google.gerrit.server.config;
|
||||
|
||||
import com.google.gerrit.server.config.GitWebConfig;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
Loading…
x
Reference in New Issue
Block a user