diff --git a/Documentation/dev-plugins.txt b/Documentation/dev-plugins.txt index a14aebcfc8..3e76edc12d 100644 --- a/Documentation/dev-plugins.txt +++ b/Documentation/dev-plugins.txt @@ -1753,6 +1753,7 @@ PatchSetWebLinks will appear to the right of the commit-SHA1 in the UI. ---- import com.google.gerrit.extensions.annotations.Listen; import com.google.gerrit.extensions.webui.PatchSetWebLink;; +import com.google.gerrit.extensions.webui.WebLinkTarget; @Listen public class MyWeblinkPlugin implements PatchSetWebLink { @@ -1762,23 +1763,11 @@ public class MyWeblinkPlugin implements PatchSetWebLink { private String imageUrl = "http://placehold.it/16x16.gif"; @Override - public String getLinkName() { - return name; - } - - @Override - public String getPatchSetUrl(String project, String commit) { - return String.format(placeHolderUrlProjectCommit, project, commit); - } - - @Override - public String getImageUrl() { - return imageUrl; - } - - @Override - public String getTarget() { - return "_blank"; + public WebLinkInfo getPathSetWebLink(String projectName, String commit) { + return new WebLinkInfo(name, + imageUrl, + String.format(placeHolderUrlProjectCommit, project, commit), + WebLinkTarget.BLANK); } } ---- diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/BranchWebLink.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/BranchWebLink.java index bc7a1e5b10..65a45dc7f0 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/BranchWebLink.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/BranchWebLink.java @@ -15,16 +15,17 @@ package com.google.gerrit.extensions.webui; import com.google.gerrit.extensions.annotations.ExtensionPoint; +import com.google.gerrit.extensions.common.WebLinkInfo; @ExtensionPoint -public interface BranchWebLink extends WebLink { +public interface BranchWebLink { /** * URL to branch in external service. * * @param projectName Name of the project * @param branchName Name of the branch - * @return url to branch in external service. + * @return WebLinkInfo that links to branch in external service. */ - String getBranchUrl(String projectName, String branchName); + WebLinkInfo getBranchWebLink(String projectName, String branchName); } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/FileWebLink.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/FileWebLink.java index ee3c62fe22..1bfbd99a2a 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/FileWebLink.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/FileWebLink.java @@ -15,9 +15,10 @@ package com.google.gerrit.extensions.webui; import com.google.gerrit.extensions.annotations.ExtensionPoint; +import com.google.gerrit.extensions.common.WebLinkInfo; @ExtensionPoint -public interface FileWebLink extends WebLink { +public interface FileWebLink { /** * URL to file in external service. @@ -25,7 +26,7 @@ public interface FileWebLink extends WebLink { * @param projectName Name of the project * @param revision Name of the revision (e.g. branch or commit ID) * @param fileName Name of the file - * @return url to project in external service. + * @return WebLinkInfo that links to project in external service. */ - String getFileUrl(String projectName, String revision, String fileName); + WebLinkInfo getFileWebLink(String projectName, String revision, String fileName); } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/PatchSetWebLink.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/PatchSetWebLink.java index b6086f2cb6..8aaedaff26 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/PatchSetWebLink.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/PatchSetWebLink.java @@ -14,16 +14,17 @@ package com.google.gerrit.extensions.webui; import com.google.gerrit.extensions.annotations.ExtensionPoint; +import com.google.gerrit.extensions.common.WebLinkInfo; @ExtensionPoint -public interface PatchSetWebLink extends WebLink { +public interface PatchSetWebLink { /** * URL to patch set in external service. * * @param projectName Name of the project * @param commit Commit of the patch set - * @return url to patch set in external service. + * @return WebLinkInfo that links to patch set in external service. */ - String getPatchSetUrl(final String projectName, final String commit); + WebLinkInfo getPathSetWebLink(final String projectName, final String commit); } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/ProjectWebLink.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/ProjectWebLink.java index 61e9982011..204c51d946 100644 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/ProjectWebLink.java +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/ProjectWebLink.java @@ -15,15 +15,16 @@ package com.google.gerrit.extensions.webui; import com.google.gerrit.extensions.annotations.ExtensionPoint; +import com.google.gerrit.extensions.common.WebLinkInfo; @ExtensionPoint -public interface ProjectWebLink extends WebLink { +public interface ProjectWebLink { /** * URL to project in external service. * * @param projectName Name of the project - * @return url to project in external service. + * @return WebLinkInfo that links to project in external service. */ - String getProjectUrl(String projectName); + WebLinkInfo getProjectWeblink(String projectName); } diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/WebLink.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/WebLink.java deleted file mode 100644 index 4065c68148..0000000000 --- a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/WebLink.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2014 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.extensions.webui; - -public interface WebLink { - - public static class Target { - public final static String BLANK = "_blank"; - public final static String SELF = "_self"; - public final static String PARENT = "_parent"; - public final static String TOP = "_top"; - } - /** - * The link-name displayed in UI. - * - * @return name of link or title of the link if image URL is available. - */ - String getLinkName(); - - /** - * URL of image to be displayed - * - * @return URL to image for link or null for using a text-only link. - * Recommended image size is 16x16. - */ - String getImageUrl(); - - /** - * Target window in which the link should be opened (e.g. "_blank", "_self".). - * - * @return link target, if null the link is opened in the current window - */ - String getTarget(); -} diff --git a/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/WebLinkTarget.java b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/WebLinkTarget.java new file mode 100644 index 0000000000..fc27c250a1 --- /dev/null +++ b/gerrit-extension-api/src/main/java/com/google/gerrit/extensions/webui/WebLinkTarget.java @@ -0,0 +1,36 @@ +// Copyright (C) 2014 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.extensions.webui; + +/** + * Class that holds target defaults for WebLink anchors. + */ +public class WebLinkTarget { + /** + * Opens the link in a new window or tab + */ + public final static String BLANK = "_blank"; + /** + * Opens the link in the frame it was clicked. + */ + public final static String SELF = "_self"; + /** + * Opens link in parent frame. + */ + public final static String PARENT = "_parent"; + /** + * Opens link in the full body of the window. + */ + public final static String TOP = "_top"; +} diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/WebLinks.java b/gerrit-server/src/main/java/com/google/gerrit/server/WebLinks.java index 67cb45e696..ddd59ec8a6 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/WebLinks.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/WebLinks.java @@ -50,10 +50,7 @@ public class WebLinks { public List getPatchSetLinks(String project, String commit) { List links = new ArrayList<>(4); for (PatchSetWebLink webLink : patchSetLinks) { - links.add(new WebLinkInfo(webLink.getLinkName(), - webLink.getImageUrl(), - webLink.getPatchSetUrl(project, commit), - webLink.getTarget())); + links.add(webLink.getPathSetWebLink(project, commit)); } return links; } @@ -62,13 +59,9 @@ public class WebLinks { String file) { List links = new ArrayList<>(4); for (FileWebLink webLink : fileLinks) { - String name = webLink.getLinkName(); - String url = webLink.getFileUrl(project, revision, file); - if (!Strings.isNullOrEmpty(name) && !Strings.isNullOrEmpty(url)) { - links.add(new WebLinkInfo(name, - webLink.getImageUrl(), - url, - webLink.getTarget())); + WebLinkInfo info = webLink.getFileWebLink(project, revision, file); + if (!Strings.isNullOrEmpty(info.name) && !Strings.isNullOrEmpty(info.url)) { + links.add(info); } } return links; @@ -77,10 +70,7 @@ public class WebLinks { public Iterable getProjectLinks(String project) { List links = Lists.newArrayList(); for (ProjectWebLink webLink : projectLinks) { - links.add(new WebLinkInfo(webLink.getLinkName(), - webLink.getImageUrl(), - webLink.getProjectUrl(project), - webLink.getTarget())); + links.add(webLink.getProjectWeblink(project)); } return links; } @@ -88,10 +78,7 @@ public class WebLinks { public Iterable getBranchLinks(String project, String branch) { List links = Lists.newArrayList(); for (BranchWebLink webLink : branchLinks) { - links.add(new WebLinkInfo(webLink.getLinkName(), - webLink.getImageUrl(), - webLink.getBranchUrl(project, branch), - webLink.getTarget())); + links.add(webLink.getBranchWebLink(project, branch)); } return links; } diff --git a/plugins/cookbook-plugin b/plugins/cookbook-plugin index a2e56f0f76..15efdb1f7e 160000 --- a/plugins/cookbook-plugin +++ b/plugins/cookbook-plugin @@ -1 +1 @@ -Subproject commit a2e56f0f76dac45a5084c28a27e24ba039b57e09 +Subproject commit 15efdb1f7e6e5f6e4db2791b8753cd57e6d5c790