Replace gitweb glue with WebLink extensions

Keep the gitweb configuration section, but bind the URLs through the
WebLink extension points instead of specific support in the web UI.
This simplifies the server and UI implementations a bit by using
only code paths that other plugins like the gitiles plugin use.

Change-Id: I8508dcaf3a4405b3ce3a47f2f717472a46e5a8ca
This commit is contained in:
Shawn Pearce
2016-06-08 21:29:53 -07:00
parent e7d7282284
commit c4a90512d5
17 changed files with 180 additions and 504 deletions

View File

@@ -1,168 +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.info;
import com.google.gerrit.client.info.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 String encode(String segment) {
if (type().urlEncode()) {
return URL.encodeQueryString(type().replacePathSeparator(segment));
}
return segment;
}
protected GitwebInfo() {
}
}

View File

@@ -1,48 +0,0 @@
// 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.info;
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

@@ -28,7 +28,6 @@ public class ServerInfo extends JavaScriptObject {
public final native ChangeConfigInfo change() /*-{ return this.change; }-*/;
public final native DownloadInfo download() /*-{ return this.download; }-*/;
public final native GerritInfo gerrit() /*-{ return this.gerrit; }-*/;
public final native GitwebInfo gitweb() /*-{ return this.gitweb; }-*/;
public final native PluginConfigInfo plugin() /*-{ return this.plugin; }-*/;
public final native SshdInfo sshd() /*-{ return this.sshd; }-*/;
public final native SuggestInfo suggest() /*-{ return this.suggest; }-*/;