/hudson-core/src/main/java/hudson/model/PermalinkProjectAction.java

http://github.com/hudson/hudson · Java · 179 lines · 80 code · 24 blank · 75 comment · 0 complexity · b9800abe4d29ca952ab997cf69995d59 MD5 · raw file

  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. package hudson.model;
  25. import java.util.List;
  26. import java.util.concurrent.CopyOnWriteArrayList;
  27. /**
  28. * Optional interface for {@link Action}s that are attached
  29. * to {@link AbstractProject} (through {@link JobProperty#getJobActions(Job)}),
  30. * which allows plugins to define additional permalinks in the project.
  31. *
  32. * <p>
  33. * Permalinks are listed together in the UI for better ease of use,
  34. * plus other plugins can use this information elsewhere (for example,
  35. * a plugin to download an artifact from one of the permalinks.)
  36. *
  37. * @author Kohsuke Kawaguchi
  38. * @since 1.253
  39. * @see JobProperty
  40. */
  41. public interface PermalinkProjectAction extends Action {
  42. /**
  43. * Gets the permalinks defined for this project.
  44. *
  45. * <p>
  46. * Because {@link Permalink} is a strategy-pattern object,
  47. * this method should normally return a pre-initialzied
  48. * read-only static list object.
  49. *
  50. * @return
  51. * can be empty, but never null.
  52. */
  53. List<Permalink> getPermalinks();
  54. /**
  55. * Permalink as a strategy pattern.
  56. */
  57. public static abstract class Permalink {
  58. /**
  59. * String to be displayed in the UI, such as "Last successful build".
  60. * The convention is to upper case the first letter.
  61. */
  62. public abstract String getDisplayName();
  63. /**
  64. * ID that uniquely identifies this permalink.
  65. *
  66. * <p>
  67. * The is also used as an URL token to represent the permalink.
  68. * This becomes the part of the permanent URL.
  69. *
  70. * <p>
  71. * The expected format is the camel case,
  72. * such as "lastSuccessfulBuild".
  73. */
  74. public abstract String getId();
  75. /**
  76. * Resolves the permalink to a build.
  77. *
  78. * @return null
  79. * if the target of the permalink doesn't exist.
  80. */
  81. public abstract Run<?,?> resolve(Job<?,?> job);
  82. /**
  83. * List of {@link Permalink}s that are built into Hudson.
  84. */
  85. public static final List<Permalink> BUILTIN = new CopyOnWriteArrayList<Permalink>();
  86. static {
  87. BUILTIN.add(new Permalink() {
  88. public String getDisplayName() {
  89. return Messages.Permalink_LastBuild();
  90. }
  91. public String getId() {
  92. return "lastBuild";
  93. }
  94. public Run<?,?> resolve(Job<?,?> job) {
  95. return job.getLastBuild();
  96. }
  97. });
  98. BUILTIN.add(new Permalink() {
  99. public String getDisplayName() {
  100. return Messages.Permalink_LastStableBuild();
  101. }
  102. public String getId() {
  103. return "lastStableBuild";
  104. }
  105. public Run<?,?> resolve(Job<?,?> job) {
  106. return job.getLastStableBuild();
  107. }
  108. });
  109. BUILTIN.add(new Permalink() {
  110. public String getDisplayName() {
  111. return Messages.Permalink_LastSuccessfulBuild();
  112. }
  113. public String getId() {
  114. return "lastSuccessfulBuild";
  115. }
  116. public Run<?,?> resolve(Job<?,?> job) {
  117. return job.getLastSuccessfulBuild();
  118. }
  119. });
  120. BUILTIN.add(new Permalink() {
  121. public String getDisplayName() {
  122. return Messages.Permalink_LastFailedBuild();
  123. }
  124. public String getId() {
  125. return "lastFailedBuild";
  126. }
  127. public Run<?,?> resolve(Job<?,?> job) {
  128. return job.getLastFailedBuild();
  129. }
  130. });
  131. BUILTIN.add(new Permalink() {
  132. public String getDisplayName() {
  133. return Messages.Permalink_LastUnstableBuild();
  134. }
  135. public String getId() {
  136. return "lastUnstableBuild";
  137. }
  138. public Run<?,?> resolve(Job<?,?> job) {
  139. return job.getLastUnstableBuild();
  140. }
  141. });
  142. BUILTIN.add(new Permalink() {
  143. public String getDisplayName() {
  144. return Messages.Permalink_LastUnsuccessfulBuild();
  145. }
  146. public String getId() {
  147. return "lastUnsuccessfulBuild";
  148. }
  149. public Run<?,?> resolve(Job<?,?> job) {
  150. return job.getLastUnsuccessfulBuild();
  151. }
  152. });
  153. }
  154. }
  155. }