You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TagPage.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.wicket.pages;
  17. import java.text.MessageFormat;
  18. import java.util.Arrays;
  19. import java.util.Date;
  20. import java.util.List;
  21. import org.apache.wicket.PageParameters;
  22. import org.apache.wicket.markup.html.WebPage;
  23. import org.apache.wicket.markup.html.basic.Label;
  24. import org.eclipse.jgit.lib.Constants;
  25. import org.eclipse.jgit.lib.Repository;
  26. import com.gitblit.models.RefModel;
  27. import com.gitblit.utils.JGitUtils;
  28. import com.gitblit.wicket.CacheControl;
  29. import com.gitblit.wicket.CacheControl.LastModified;
  30. import com.gitblit.wicket.WicketUtils;
  31. import com.gitblit.wicket.panels.GravatarImage;
  32. import com.gitblit.wicket.panels.LinkPanel;
  33. import com.gitblit.wicket.panels.RefsPanel;
  34. @CacheControl(LastModified.BOOT)
  35. public class TagPage extends RepositoryPage {
  36. public TagPage(PageParameters params) {
  37. super(params);
  38. Repository r = getRepository();
  39. // Find tag in repository
  40. List<RefModel> tags = JGitUtils.getTags(r, true, -1);
  41. RefModel tagRef = null;
  42. for (RefModel tag : tags) {
  43. if (tag.getName().equals(objectId) || tag.getObjectId().getName().equals(objectId)) {
  44. tagRef = tag;
  45. break;
  46. }
  47. }
  48. // Failed to find tag!
  49. if (tagRef == null) {
  50. error(MessageFormat.format(getString("gb.couldNotFindTag"), objectId), true);
  51. }
  52. // Display tag.
  53. Class<? extends WebPage> linkClass;
  54. PageParameters linkParameters = newCommitParameter(tagRef.getReferencedObjectId().getName());
  55. String typeKey;
  56. switch (tagRef.getReferencedObjectType()) {
  57. case Constants.OBJ_BLOB:
  58. typeKey = "gb.blob";
  59. linkClass = BlobPage.class;
  60. break;
  61. case Constants.OBJ_TREE:
  62. typeKey = "gb.tree";
  63. linkClass = TreePage.class;
  64. break;
  65. case Constants.OBJ_COMMIT:
  66. default:
  67. typeKey = "gb.commit";
  68. linkClass = CommitPage.class;
  69. break;
  70. }
  71. add(new GravatarImage("taggerAvatar", tagRef.getAuthorIdent()));
  72. add(new RefsPanel("tagName", repositoryName, Arrays.asList(tagRef)));
  73. add(new Label("tagId", tagRef.getObjectId().getName()));
  74. add(new LinkPanel("taggedObject", "list", tagRef.getReferencedObjectId().getName(),
  75. linkClass, linkParameters));
  76. add(new Label("taggedObjectType", getString(typeKey)));
  77. add(createPersonPanel("tagger", tagRef.getAuthorIdent(), com.gitblit.Constants.SearchType.AUTHOR));
  78. Date when = new Date(0);
  79. if (tagRef.getAuthorIdent() != null) {
  80. when = tagRef.getAuthorIdent().getWhen();
  81. }
  82. add(WicketUtils.createTimestampLabel("tagDate", when, getTimeZone(), getTimeUtils()));
  83. addFullText("fullMessage", tagRef.getFullMessage(), true);
  84. }
  85. @Override
  86. protected String getPageName() {
  87. return getString("gb.tag");
  88. }
  89. @Override
  90. protected Class<? extends BasePage> getRepoNavPageClass() {
  91. return LogPage.class;
  92. }
  93. }