Merge "Plugin support for project weblinks"
This commit is contained in:
		@@ -1740,6 +1740,9 @@ public class MyWeblinkPlugin implements PatchSetWebLink {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
----
 | 
					----
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ProjectWebLinks will appear in the project list in the
 | 
				
			||||||
 | 
					`Repository Browser` column.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[documentation]]
 | 
					[[documentation]]
 | 
				
			||||||
== Documentation
 | 
					== Documentation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1485,6 +1485,9 @@ is increased for each non-visible project).
 | 
				
			|||||||
|`description` |optional|The description of the project.
 | 
					|`description` |optional|The description of the project.
 | 
				
			||||||
|`state`       |optional|`ACTIVE`, `READ_ONLY` or `HIDDEN`.
 | 
					|`state`       |optional|`ACTIVE`, `READ_ONLY` or `HIDDEN`.
 | 
				
			||||||
|`branches`    |optional|Map of branch names to HEAD revisions.
 | 
					|`branches`    |optional|Map of branch names to HEAD revisions.
 | 
				
			||||||
 | 
					|'web_links'   |optional|
 | 
				
			||||||
 | 
					Links to the project in external sites as a list of
 | 
				
			||||||
 | 
					link:rest-api-changes.html#web-link-info[WebLinkInfo] entries.
 | 
				
			||||||
|===========================
 | 
					|===========================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[project-input]]
 | 
					[[project-input]]
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,6 +16,7 @@ package com.google.gerrit.extensions.common;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.google.gerrit.extensions.api.projects.ProjectState;
 | 
					import com.google.gerrit.extensions.api.projects.ProjectState;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Map;
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ProjectInfo {
 | 
					public class ProjectInfo {
 | 
				
			||||||
@@ -25,4 +26,5 @@ public class ProjectInfo {
 | 
				
			|||||||
  public String description;
 | 
					  public String description;
 | 
				
			||||||
  public ProjectState state;
 | 
					  public ProjectState state;
 | 
				
			||||||
  public Map<String, String> branches;
 | 
					  public Map<String, String> branches;
 | 
				
			||||||
 | 
					  public List<WebLinkInfo> webLinks;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -27,14 +27,4 @@ public class RevisionInfo {
 | 
				
			|||||||
  public Map<String, FileInfo> files;
 | 
					  public Map<String, FileInfo> files;
 | 
				
			||||||
  public Map<String, ActionInfo> actions;
 | 
					  public Map<String, ActionInfo> actions;
 | 
				
			||||||
  public List<WebLinkInfo> webLinks;
 | 
					  public List<WebLinkInfo> webLinks;
 | 
				
			||||||
 | 
					 | 
				
			||||||
  public static class WebLinkInfo {
 | 
					 | 
				
			||||||
    public String name;
 | 
					 | 
				
			||||||
    public String url;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public WebLinkInfo(String name, String url) {
 | 
					 | 
				
			||||||
      this.name = name;
 | 
					 | 
				
			||||||
      this.url = url;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					// 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.common;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class WebLinkInfo {
 | 
				
			||||||
 | 
					  public String name;
 | 
				
			||||||
 | 
					  public String url;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public WebLinkInfo(String name, String url) {
 | 
				
			||||||
 | 
					    this.name = name;
 | 
				
			||||||
 | 
					    this.url = url;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					// 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;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.gerrit.extensions.annotations.ExtensionPoint;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@ExtensionPoint
 | 
				
			||||||
 | 
					public interface ProjectWebLink extends WebLink {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  /**
 | 
				
			||||||
 | 
					   * URL to project in external service.
 | 
				
			||||||
 | 
					   *
 | 
				
			||||||
 | 
					   * @param projectName Name of the project
 | 
				
			||||||
 | 
					   * @return url to project in external service.
 | 
				
			||||||
 | 
					   */
 | 
				
			||||||
 | 
					  String getProjectUrl(String projectName);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					// 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.client;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.gwt.core.client.JavaScriptObject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class WebLinkInfo extends JavaScriptObject {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public final native String name() /*-{ return this.name; }-*/;
 | 
				
			||||||
 | 
					  public final native String url() /*-{ return this.url; }-*/;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  protected WebLinkInfo() {
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -19,9 +19,11 @@ import static com.google.gerrit.common.PageLinks.ADMIN_PROJECTS;
 | 
				
			|||||||
import com.google.gerrit.client.Dispatcher;
 | 
					import com.google.gerrit.client.Dispatcher;
 | 
				
			||||||
import com.google.gerrit.client.Gerrit;
 | 
					import com.google.gerrit.client.Gerrit;
 | 
				
			||||||
import com.google.gerrit.client.GitwebLink;
 | 
					import com.google.gerrit.client.GitwebLink;
 | 
				
			||||||
 | 
					import com.google.gerrit.client.WebLinkInfo;
 | 
				
			||||||
import com.google.gerrit.client.projects.ProjectInfo;
 | 
					import com.google.gerrit.client.projects.ProjectInfo;
 | 
				
			||||||
import com.google.gerrit.client.projects.ProjectMap;
 | 
					import com.google.gerrit.client.projects.ProjectMap;
 | 
				
			||||||
import com.google.gerrit.client.rpc.GerritCallback;
 | 
					import com.google.gerrit.client.rpc.GerritCallback;
 | 
				
			||||||
 | 
					import com.google.gerrit.client.rpc.Natives;
 | 
				
			||||||
import com.google.gerrit.client.ui.FilteredUserInterface;
 | 
					import com.google.gerrit.client.ui.FilteredUserInterface;
 | 
				
			||||||
import com.google.gerrit.client.ui.HighlightingInlineHyperlink;
 | 
					import com.google.gerrit.client.ui.HighlightingInlineHyperlink;
 | 
				
			||||||
import com.google.gerrit.client.ui.Hyperlink;
 | 
					import com.google.gerrit.client.ui.Hyperlink;
 | 
				
			||||||
@@ -43,6 +45,8 @@ import com.google.gwt.user.client.ui.Image;
 | 
				
			|||||||
import com.google.gwt.user.client.ui.Label;
 | 
					import com.google.gwt.user.client.ui.Label;
 | 
				
			||||||
import com.google.gwtexpui.globalkey.client.NpTextBox;
 | 
					import com.google.gwtexpui.globalkey.client.NpTextBox;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ProjectListScreen extends Screen implements FilteredUserInterface {
 | 
					public class ProjectListScreen extends Screen implements FilteredUserInterface {
 | 
				
			||||||
  private Hyperlink prev;
 | 
					  private Hyperlink prev;
 | 
				
			||||||
  private Hyperlink next;
 | 
					  private Hyperlink next;
 | 
				
			||||||
@@ -167,13 +171,11 @@ public class ProjectListScreen extends Screen implements FilteredUserInterface {
 | 
				
			|||||||
      @Override
 | 
					      @Override
 | 
				
			||||||
      protected void initColumnHeaders() {
 | 
					      protected void initColumnHeaders() {
 | 
				
			||||||
        super.initColumnHeaders();
 | 
					        super.initColumnHeaders();
 | 
				
			||||||
        if (Gerrit.getGitwebLink() != null) {
 | 
					        table.setText(0, ProjectsTable.C_REPO_BROWSER,
 | 
				
			||||||
          table.setText(0, ProjectsTable.C_REPO_BROWSER,
 | 
					            Util.C.projectRepoBrowser());
 | 
				
			||||||
              Util.C.projectRepoBrowser());
 | 
					        table.getFlexCellFormatter().
 | 
				
			||||||
          table.getFlexCellFormatter().
 | 
					          addStyleName(0, ProjectsTable.C_REPO_BROWSER,
 | 
				
			||||||
            addStyleName(0, ProjectsTable.C_REPO_BROWSER,
 | 
					              Gerrit.RESOURCES.css().dataHeader());
 | 
				
			||||||
                Gerrit.RESOURCES.css().dataHeader());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      @Override
 | 
					      @Override
 | 
				
			||||||
@@ -188,11 +190,8 @@ public class ProjectListScreen extends Screen implements FilteredUserInterface {
 | 
				
			|||||||
      @Override
 | 
					      @Override
 | 
				
			||||||
      protected void insert(int row, ProjectInfo k) {
 | 
					      protected void insert(int row, ProjectInfo k) {
 | 
				
			||||||
        super.insert(row, k);
 | 
					        super.insert(row, k);
 | 
				
			||||||
        if (Gerrit.getGitwebLink() != null) {
 | 
					        table.getFlexCellFormatter().addStyleName(row,
 | 
				
			||||||
          table.getFlexCellFormatter().
 | 
					            ProjectsTable.C_REPO_BROWSER, Gerrit.RESOURCES.css().dataCell());
 | 
				
			||||||
            addStyleName(row, ProjectsTable.C_REPO_BROWSER,
 | 
					 | 
				
			||||||
                Gerrit.RESOURCES.css().dataCell());
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      @Override
 | 
					      @Override
 | 
				
			||||||
@@ -219,15 +218,33 @@ public class ProjectListScreen extends Screen implements FilteredUserInterface {
 | 
				
			|||||||
        fp.add(new HighlightingInlineHyperlink(k.name(), link(k), subname));
 | 
					        fp.add(new HighlightingInlineHyperlink(k.name(), link(k), subname));
 | 
				
			||||||
        table.setWidget(row, ProjectsTable.C_NAME, fp);
 | 
					        table.setWidget(row, ProjectsTable.C_NAME, fp);
 | 
				
			||||||
        table.setText(row, ProjectsTable.C_DESCRIPTION, k.description());
 | 
					        table.setText(row, ProjectsTable.C_DESCRIPTION, k.description());
 | 
				
			||||||
        GitwebLink l = Gerrit.getGitwebLink();
 | 
					        addWebLinks(row, k);
 | 
				
			||||||
        if (l != null) {
 | 
					 | 
				
			||||||
          table.setWidget(row, ProjectsTable.C_REPO_BROWSER,
 | 
					 | 
				
			||||||
              new Anchor(l.getLinkName(), false, l.toProject(k
 | 
					 | 
				
			||||||
              .name_key())));
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        setRowItem(row, k);
 | 
					        setRowItem(row, k);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      private void addWebLinks(int row, ProjectInfo k) {
 | 
				
			||||||
 | 
					        GitwebLink gitWebLink = Gerrit.getGitwebLink();
 | 
				
			||||||
 | 
					        List<WebLinkInfo> webLinks = Natives.asList(k.web_links());
 | 
				
			||||||
 | 
					        if (gitWebLink != null || (webLinks != null && !webLinks.isEmpty())) {
 | 
				
			||||||
 | 
					          FlowPanel p = new FlowPanel();
 | 
				
			||||||
 | 
					          table.setWidget(row, ProjectsTable.C_REPO_BROWSER, p);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          if (gitWebLink != null) {
 | 
				
			||||||
 | 
					            Anchor a = new Anchor();
 | 
				
			||||||
 | 
					            a.setText(gitWebLink.getLinkName());
 | 
				
			||||||
 | 
					            a.setHref(gitWebLink.toProject(k.name_key()));
 | 
				
			||||||
 | 
					            p.add(a);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          for (WebLinkInfo weblink : webLinks) {
 | 
				
			||||||
 | 
					            Anchor a = new Anchor();
 | 
				
			||||||
 | 
					            a.setText("(" + weblink.name() + ")");
 | 
				
			||||||
 | 
					            a.setHref(weblink.url());
 | 
				
			||||||
 | 
					            p.add(a);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    projects.setSavePointerId(PageLinks.ADMIN_PROJECTS);
 | 
					    projects.setSavePointerId(PageLinks.ADMIN_PROJECTS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,11 +17,11 @@ package com.google.gerrit.client.change;
 | 
				
			|||||||
import com.google.gerrit.client.FormatUtil;
 | 
					import com.google.gerrit.client.FormatUtil;
 | 
				
			||||||
import com.google.gerrit.client.Gerrit;
 | 
					import com.google.gerrit.client.Gerrit;
 | 
				
			||||||
import com.google.gerrit.client.GitwebLink;
 | 
					import com.google.gerrit.client.GitwebLink;
 | 
				
			||||||
 | 
					import com.google.gerrit.client.WebLinkInfo;
 | 
				
			||||||
import com.google.gerrit.client.changes.ChangeInfo;
 | 
					import com.google.gerrit.client.changes.ChangeInfo;
 | 
				
			||||||
import com.google.gerrit.client.changes.ChangeInfo.CommitInfo;
 | 
					import com.google.gerrit.client.changes.ChangeInfo.CommitInfo;
 | 
				
			||||||
import com.google.gerrit.client.changes.ChangeInfo.GitPerson;
 | 
					import com.google.gerrit.client.changes.ChangeInfo.GitPerson;
 | 
				
			||||||
import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
 | 
					import com.google.gerrit.client.changes.ChangeInfo.RevisionInfo;
 | 
				
			||||||
import com.google.gerrit.client.changes.ChangeInfo.WebLinkInfo;
 | 
					 | 
				
			||||||
import com.google.gerrit.client.rpc.Natives;
 | 
					import com.google.gerrit.client.rpc.Natives;
 | 
				
			||||||
import com.google.gerrit.client.ui.CommentLinkProcessor;
 | 
					import com.google.gerrit.client.ui.CommentLinkProcessor;
 | 
				
			||||||
import com.google.gerrit.client.ui.InlineHyperlink;
 | 
					import com.google.gerrit.client.ui.InlineHyperlink;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.google.gerrit.client.changes;
 | 
					package com.google.gerrit.client.changes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.gerrit.client.WebLinkInfo;
 | 
				
			||||||
import com.google.gerrit.client.account.AccountInfo;
 | 
					import com.google.gerrit.client.account.AccountInfo;
 | 
				
			||||||
import com.google.gerrit.client.actions.ActionInfo;
 | 
					import com.google.gerrit.client.actions.ActionInfo;
 | 
				
			||||||
import com.google.gerrit.client.diff.FileInfo;
 | 
					import com.google.gerrit.client.diff.FileInfo;
 | 
				
			||||||
@@ -298,11 +299,4 @@ public class ChangeInfo extends JavaScriptObject {
 | 
				
			|||||||
    protected IncludedInInfo() {
 | 
					    protected IncludedInInfo() {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					 | 
				
			||||||
  public static class WebLinkInfo extends JavaScriptObject {
 | 
					 | 
				
			||||||
    public final native String name() /*-{ return this.name; }-*/;
 | 
					 | 
				
			||||||
    public final native String url() /*-{ return this.url; }-*/;
 | 
					 | 
				
			||||||
    protected WebLinkInfo() {
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,9 +14,11 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
package com.google.gerrit.client.projects;
 | 
					package com.google.gerrit.client.projects;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.google.gerrit.client.WebLinkInfo;
 | 
				
			||||||
import com.google.gerrit.extensions.api.projects.ProjectState;
 | 
					import com.google.gerrit.extensions.api.projects.ProjectState;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.Project;
 | 
					import com.google.gerrit.reviewdb.client.Project;
 | 
				
			||||||
import com.google.gwt.core.client.JavaScriptObject;
 | 
					import com.google.gwt.core.client.JavaScriptObject;
 | 
				
			||||||
 | 
					import com.google.gwt.core.client.JsArray;
 | 
				
			||||||
import com.google.gwt.user.client.ui.SuggestOracle;
 | 
					import com.google.gwt.user.client.ui.SuggestOracle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ProjectInfo
 | 
					public class ProjectInfo
 | 
				
			||||||
@@ -28,6 +30,7 @@ public class ProjectInfo
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  public final native String name() /*-{ return this.name; }-*/;
 | 
					  public final native String name() /*-{ return this.name; }-*/;
 | 
				
			||||||
  public final native String description() /*-{ return this.description; }-*/;
 | 
					  public final native String description() /*-{ return this.description; }-*/;
 | 
				
			||||||
 | 
					  public final native JsArray<WebLinkInfo> web_links() /*-{ return this.web_links; }-*/;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public final ProjectState state() {
 | 
					  public final ProjectState state() {
 | 
				
			||||||
    return ProjectState.valueOf(getStringState());
 | 
					    return ProjectState.valueOf(getStringState());
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,26 +11,30 @@
 | 
				
			|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
				
			||||||
// See the License for the specific language governing permissions and
 | 
					// See the License for the specific language governing permissions and
 | 
				
			||||||
// limitations under the License.
 | 
					// limitations under the License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package com.google.gerrit.server;
 | 
					package com.google.gerrit.server;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.common.collect.Lists;
 | 
					import com.google.common.collect.Lists;
 | 
				
			||||||
import com.google.gerrit.extensions.registration.DynamicSet;
 | 
					import com.google.gerrit.extensions.registration.DynamicSet;
 | 
				
			||||||
import com.google.gerrit.extensions.webui.PatchSetWebLink;
 | 
					import com.google.gerrit.extensions.webui.PatchSetWebLink;
 | 
				
			||||||
 | 
					import com.google.gerrit.extensions.webui.ProjectWebLink;
 | 
				
			||||||
import com.google.inject.Inject;
 | 
					import com.google.inject.Inject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class WebLinks {
 | 
					public class WebLinks {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private DynamicSet<PatchSetWebLink> patchSetLinks;
 | 
					  private final DynamicSet<PatchSetWebLink> patchSetLinks;
 | 
				
			||||||
 | 
					  private final DynamicSet<ProjectWebLink> projectLinks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Inject
 | 
					  @Inject
 | 
				
			||||||
  public WebLinks(final DynamicSet<PatchSetWebLink> patchSetLinks) {
 | 
					  public WebLinks(DynamicSet<PatchSetWebLink> patchSetLinks,
 | 
				
			||||||
 | 
					      DynamicSet<ProjectWebLink> projectLinks) {
 | 
				
			||||||
    this.patchSetLinks = patchSetLinks;
 | 
					    this.patchSetLinks = patchSetLinks;
 | 
				
			||||||
 | 
					    this.projectLinks = projectLinks;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public Iterable<Link> getPatchSetLinks(final String project,
 | 
					  public Iterable<Link> getPatchSetLinks(String project, String commit) {
 | 
				
			||||||
      final String commit) {
 | 
					 | 
				
			||||||
    List<Link> links = Lists.newArrayList();
 | 
					    List<Link> links = Lists.newArrayList();
 | 
				
			||||||
    for (PatchSetWebLink webLink : patchSetLinks) {
 | 
					    for (PatchSetWebLink webLink : patchSetLinks) {
 | 
				
			||||||
      links.add(new Link(webLink.getLinkName(),
 | 
					      links.add(new Link(webLink.getLinkName(),
 | 
				
			||||||
@@ -39,6 +43,15 @@ public class WebLinks {
 | 
				
			|||||||
    return links;
 | 
					    return links;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  public Iterable<Link> getProjectLinks(String project) {
 | 
				
			||||||
 | 
					    List<Link> links = Lists.newArrayList();
 | 
				
			||||||
 | 
					    for (ProjectWebLink webLink : projectLinks) {
 | 
				
			||||||
 | 
					      links.add(new Link(webLink.getLinkName(),
 | 
				
			||||||
 | 
					          webLink.getProjectUrl(project)));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return links;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public class Link {
 | 
					  public class Link {
 | 
				
			||||||
    public String name;
 | 
					    public String name;
 | 
				
			||||||
    public String url;
 | 
					    public String url;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,25 +11,30 @@
 | 
				
			|||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
					// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
				
			||||||
// See the License for the specific language governing permissions and
 | 
					// See the License for the specific language governing permissions and
 | 
				
			||||||
// limitations under the License.
 | 
					// limitations under the License.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
package com.google.gerrit.server;
 | 
					package com.google.gerrit.server;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.gerrit.extensions.registration.DynamicSet;
 | 
					import com.google.gerrit.extensions.registration.DynamicSet;
 | 
				
			||||||
import com.google.gerrit.extensions.webui.PatchSetWebLink;
 | 
					import com.google.gerrit.extensions.webui.PatchSetWebLink;
 | 
				
			||||||
 | 
					import com.google.gerrit.extensions.webui.ProjectWebLink;
 | 
				
			||||||
import com.google.inject.Inject;
 | 
					import com.google.inject.Inject;
 | 
				
			||||||
import com.google.inject.Provider;
 | 
					import com.google.inject.Provider;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class WebLinksProvider implements Provider<WebLinks> {
 | 
					public class WebLinksProvider implements Provider<WebLinks> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private DynamicSet<PatchSetWebLink> patchSetLinks;
 | 
					  private final DynamicSet<PatchSetWebLink> patchSetLinks;
 | 
				
			||||||
 | 
					  private final DynamicSet<ProjectWebLink> projectLinks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Inject
 | 
					  @Inject
 | 
				
			||||||
  public WebLinksProvider(DynamicSet<PatchSetWebLink> patchSetLinks) {
 | 
					  public WebLinksProvider(DynamicSet<PatchSetWebLink> patchSetLinks,
 | 
				
			||||||
 | 
					      DynamicSet<ProjectWebLink> projectLinks) {
 | 
				
			||||||
    this.patchSetLinks = patchSetLinks;
 | 
					    this.patchSetLinks = patchSetLinks;
 | 
				
			||||||
 | 
					    this.projectLinks = projectLinks;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Override
 | 
					  @Override
 | 
				
			||||||
  public WebLinks get() {
 | 
					  public WebLinks get() {
 | 
				
			||||||
    WebLinks webLinks = new WebLinks(patchSetLinks);
 | 
					    WebLinks webLinks = new WebLinks(patchSetLinks, projectLinks);
 | 
				
			||||||
    return webLinks;
 | 
					    return webLinks;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,6 +59,7 @@ import com.google.gerrit.extensions.common.FetchInfo;
 | 
				
			|||||||
import com.google.gerrit.extensions.common.GitPerson;
 | 
					import com.google.gerrit.extensions.common.GitPerson;
 | 
				
			||||||
import com.google.gerrit.extensions.common.ListChangesOption;
 | 
					import com.google.gerrit.extensions.common.ListChangesOption;
 | 
				
			||||||
import com.google.gerrit.extensions.common.RevisionInfo;
 | 
					import com.google.gerrit.extensions.common.RevisionInfo;
 | 
				
			||||||
 | 
					import com.google.gerrit.extensions.common.WebLinkInfo;
 | 
				
			||||||
import com.google.gerrit.extensions.config.DownloadCommand;
 | 
					import com.google.gerrit.extensions.config.DownloadCommand;
 | 
				
			||||||
import com.google.gerrit.extensions.config.DownloadScheme;
 | 
					import com.google.gerrit.extensions.config.DownloadScheme;
 | 
				
			||||||
import com.google.gerrit.extensions.registration.DynamicMap;
 | 
					import com.google.gerrit.extensions.registration.DynamicMap;
 | 
				
			||||||
@@ -875,7 +876,7 @@ public class ChangeJson {
 | 
				
			|||||||
      out.webLinks = Lists.newArrayList();
 | 
					      out.webLinks = Lists.newArrayList();
 | 
				
			||||||
      for (WebLinks.Link link : webLinks.get().getPatchSetLinks(
 | 
					      for (WebLinks.Link link : webLinks.get().getPatchSetLinks(
 | 
				
			||||||
          project, in.getRevision().get())) {
 | 
					          project, in.getRevision().get())) {
 | 
				
			||||||
        out.webLinks.add(new RevisionInfo.WebLinkInfo(link.name, link.url));
 | 
					        out.webLinks.add(new WebLinkInfo(link.name, link.url));
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return out;
 | 
					    return out;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,6 +32,7 @@ import com.google.gerrit.extensions.registration.DynamicMap;
 | 
				
			|||||||
import com.google.gerrit.extensions.registration.DynamicSet;
 | 
					import com.google.gerrit.extensions.registration.DynamicSet;
 | 
				
			||||||
import com.google.gerrit.extensions.systemstatus.MessageOfTheDay;
 | 
					import com.google.gerrit.extensions.systemstatus.MessageOfTheDay;
 | 
				
			||||||
import com.google.gerrit.extensions.webui.PatchSetWebLink;
 | 
					import com.google.gerrit.extensions.webui.PatchSetWebLink;
 | 
				
			||||||
 | 
					import com.google.gerrit.extensions.webui.ProjectWebLink;
 | 
				
			||||||
import com.google.gerrit.extensions.webui.TopMenu;
 | 
					import com.google.gerrit.extensions.webui.TopMenu;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.AccountGroup;
 | 
					import com.google.gerrit.reviewdb.client.AccountGroup;
 | 
				
			||||||
import com.google.gerrit.rules.PrologModule;
 | 
					import com.google.gerrit.rules.PrologModule;
 | 
				
			||||||
@@ -271,6 +272,7 @@ public class GerritGlobalModule extends FactoryModule {
 | 
				
			|||||||
    DynamicMap.mapOf(binder(), DownloadCommand.class);
 | 
					    DynamicMap.mapOf(binder(), DownloadCommand.class);
 | 
				
			||||||
    DynamicMap.mapOf(binder(), ProjectConfigEntry.class);
 | 
					    DynamicMap.mapOf(binder(), ProjectConfigEntry.class);
 | 
				
			||||||
    DynamicSet.setOf(binder(), PatchSetWebLink.class);
 | 
					    DynamicSet.setOf(binder(), PatchSetWebLink.class);
 | 
				
			||||||
 | 
					    DynamicSet.setOf(binder(), ProjectWebLink.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bind(AnonymousUser.class);
 | 
					    bind(AnonymousUser.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,6 +22,7 @@ import com.google.common.collect.Maps;
 | 
				
			|||||||
import com.google.gerrit.common.data.GroupReference;
 | 
					import com.google.gerrit.common.data.GroupReference;
 | 
				
			||||||
import com.google.gerrit.common.errors.NoSuchGroupException;
 | 
					import com.google.gerrit.common.errors.NoSuchGroupException;
 | 
				
			||||||
import com.google.gerrit.extensions.common.ProjectInfo;
 | 
					import com.google.gerrit.extensions.common.ProjectInfo;
 | 
				
			||||||
 | 
					import com.google.gerrit.extensions.common.WebLinkInfo;
 | 
				
			||||||
import com.google.gerrit.extensions.restapi.BinaryResult;
 | 
					import com.google.gerrit.extensions.restapi.BinaryResult;
 | 
				
			||||||
import com.google.gerrit.extensions.restapi.RestReadView;
 | 
					import com.google.gerrit.extensions.restapi.RestReadView;
 | 
				
			||||||
import com.google.gerrit.extensions.restapi.TopLevelResource;
 | 
					import com.google.gerrit.extensions.restapi.TopLevelResource;
 | 
				
			||||||
@@ -32,12 +33,14 @@ import com.google.gerrit.reviewdb.client.RefNames;
 | 
				
			|||||||
import com.google.gerrit.server.CurrentUser;
 | 
					import com.google.gerrit.server.CurrentUser;
 | 
				
			||||||
import com.google.gerrit.server.OutputFormat;
 | 
					import com.google.gerrit.server.OutputFormat;
 | 
				
			||||||
import com.google.gerrit.server.StringUtil;
 | 
					import com.google.gerrit.server.StringUtil;
 | 
				
			||||||
 | 
					import com.google.gerrit.server.WebLinks;
 | 
				
			||||||
import com.google.gerrit.server.account.GroupCache;
 | 
					import com.google.gerrit.server.account.GroupCache;
 | 
				
			||||||
import com.google.gerrit.server.account.GroupControl;
 | 
					import com.google.gerrit.server.account.GroupControl;
 | 
				
			||||||
import com.google.gerrit.server.git.GitRepositoryManager;
 | 
					import com.google.gerrit.server.git.GitRepositoryManager;
 | 
				
			||||||
import com.google.gerrit.server.util.TreeFormatter;
 | 
					import com.google.gerrit.server.util.TreeFormatter;
 | 
				
			||||||
import com.google.gson.reflect.TypeToken;
 | 
					import com.google.gson.reflect.TypeToken;
 | 
				
			||||||
import com.google.inject.Inject;
 | 
					import com.google.inject.Inject;
 | 
				
			||||||
 | 
					import com.google.inject.Provider;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
 | 
					import org.eclipse.jgit.errors.RepositoryNotFoundException;
 | 
				
			||||||
import org.eclipse.jgit.lib.Constants;
 | 
					import org.eclipse.jgit.lib.Constants;
 | 
				
			||||||
@@ -106,6 +109,7 @@ public class ListProjects implements RestReadView<TopLevelResource> {
 | 
				
			|||||||
  private final GroupControl.Factory groupControlFactory;
 | 
					  private final GroupControl.Factory groupControlFactory;
 | 
				
			||||||
  private final GitRepositoryManager repoManager;
 | 
					  private final GitRepositoryManager repoManager;
 | 
				
			||||||
  private final ProjectNode.Factory projectNodeFactory;
 | 
					  private final ProjectNode.Factory projectNodeFactory;
 | 
				
			||||||
 | 
					  private final Provider<WebLinks> webLinks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Deprecated
 | 
					  @Deprecated
 | 
				
			||||||
  @Option(name = "--format", usage = "(deprecated) output format")
 | 
					  @Option(name = "--format", usage = "(deprecated) output format")
 | 
				
			||||||
@@ -179,13 +183,15 @@ public class ListProjects implements RestReadView<TopLevelResource> {
 | 
				
			|||||||
  @Inject
 | 
					  @Inject
 | 
				
			||||||
  protected ListProjects(CurrentUser currentUser, ProjectCache projectCache,
 | 
					  protected ListProjects(CurrentUser currentUser, ProjectCache projectCache,
 | 
				
			||||||
      GroupCache groupCache, GroupControl.Factory groupControlFactory,
 | 
					      GroupCache groupCache, GroupControl.Factory groupControlFactory,
 | 
				
			||||||
      GitRepositoryManager repoManager, ProjectNode.Factory projectNodeFactory) {
 | 
					      GitRepositoryManager repoManager, ProjectNode.Factory projectNodeFactory,
 | 
				
			||||||
 | 
					      Provider<WebLinks> webLinks) {
 | 
				
			||||||
    this.currentUser = currentUser;
 | 
					    this.currentUser = currentUser;
 | 
				
			||||||
    this.projectCache = projectCache;
 | 
					    this.projectCache = projectCache;
 | 
				
			||||||
    this.groupCache = groupCache;
 | 
					    this.groupCache = groupCache;
 | 
				
			||||||
    this.groupControlFactory = groupControlFactory;
 | 
					    this.groupControlFactory = groupControlFactory;
 | 
				
			||||||
    this.repoManager = repoManager;
 | 
					    this.repoManager = repoManager;
 | 
				
			||||||
    this.projectNodeFactory = projectNodeFactory;
 | 
					    this.projectNodeFactory = projectNodeFactory;
 | 
				
			||||||
 | 
					    this.webLinks = webLinks;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public List<String> getShowBranch() {
 | 
					  public List<String> getShowBranch() {
 | 
				
			||||||
@@ -367,6 +373,13 @@ public class ListProjects implements RestReadView<TopLevelResource> {
 | 
				
			|||||||
            log.warn("Unexpected error reading " + projectName, err);
 | 
					            log.warn("Unexpected error reading " + projectName, err);
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          info.webLinks = Lists.newArrayList();
 | 
				
			||||||
 | 
					          for (WebLinks.Link link : webLinks.get().getProjectLinks(projectName.get())) {
 | 
				
			||||||
 | 
					            if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) {
 | 
				
			||||||
 | 
					              info.webLinks.add(new WebLinkInfo(link.name, link.url));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (foundIndex++ < start) {
 | 
					        if (foundIndex++ < start) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,19 +15,25 @@
 | 
				
			|||||||
package com.google.gerrit.server.project;
 | 
					package com.google.gerrit.server.project;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.common.base.Strings;
 | 
					import com.google.common.base.Strings;
 | 
				
			||||||
 | 
					import com.google.common.collect.Lists;
 | 
				
			||||||
import com.google.gerrit.extensions.common.ProjectInfo;
 | 
					import com.google.gerrit.extensions.common.ProjectInfo;
 | 
				
			||||||
 | 
					import com.google.gerrit.extensions.common.WebLinkInfo;
 | 
				
			||||||
import com.google.gerrit.extensions.restapi.Url;
 | 
					import com.google.gerrit.extensions.restapi.Url;
 | 
				
			||||||
import com.google.gerrit.reviewdb.client.Project;
 | 
					import com.google.gerrit.reviewdb.client.Project;
 | 
				
			||||||
 | 
					import com.google.gerrit.server.WebLinks;
 | 
				
			||||||
import com.google.gerrit.server.config.AllProjectsName;
 | 
					import com.google.gerrit.server.config.AllProjectsName;
 | 
				
			||||||
import com.google.inject.Inject;
 | 
					import com.google.inject.Inject;
 | 
				
			||||||
 | 
					import com.google.inject.Provider;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class ProjectJson {
 | 
					public class ProjectJson {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  private final AllProjectsName allProjects;
 | 
					  private final AllProjectsName allProjects;
 | 
				
			||||||
 | 
					  private final Provider<WebLinks> webLinks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @Inject
 | 
					  @Inject
 | 
				
			||||||
  ProjectJson(AllProjectsName allProjects) {
 | 
					  ProjectJson(AllProjectsName allProjects, Provider<WebLinks> webLinks) {
 | 
				
			||||||
    this.allProjects = allProjects;
 | 
					    this.allProjects = allProjects;
 | 
				
			||||||
 | 
					    this.webLinks = webLinks;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public ProjectInfo format(ProjectResource rsrc) {
 | 
					  public ProjectInfo format(ProjectResource rsrc) {
 | 
				
			||||||
@@ -42,6 +48,14 @@ public class ProjectJson {
 | 
				
			|||||||
    info.description = Strings.emptyToNull(p.getDescription());
 | 
					    info.description = Strings.emptyToNull(p.getDescription());
 | 
				
			||||||
    info.state = p.getState();
 | 
					    info.state = p.getState();
 | 
				
			||||||
    info.id = Url.encode(info.name);
 | 
					    info.id = Url.encode(info.name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    info.webLinks = Lists.newArrayList();
 | 
				
			||||||
 | 
					    for (WebLinks.Link link : webLinks.get().getProjectLinks(p.getName())) {
 | 
				
			||||||
 | 
					      if (!Strings.isNullOrEmpty(link.name) && !Strings.isNullOrEmpty(link.url)) {
 | 
				
			||||||
 | 
					        info.webLinks.add(new WebLinkInfo(link.name, link.url));
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return info;
 | 
					    return info;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user