/hudson-core/src/main/java/hudson/scm/AbstractScmTagAction.java

http://github.com/hudson/hudson · Java · 96 lines · 40 code · 13 blank · 43 comment · 1 complexity · 889281f1db7886c7487fbab81fedfb0d 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.scm;
  25. import hudson.model.AbstractBuild;
  26. import hudson.model.TaskAction;
  27. import hudson.model.BuildBadgeAction;
  28. import hudson.security.Permission;
  29. import hudson.security.ACL;
  30. import org.kohsuke.stapler.StaplerRequest;
  31. import org.kohsuke.stapler.StaplerResponse;
  32. import javax.servlet.ServletException;
  33. import java.io.IOException;
  34. /**
  35. * Common part of {@link CVSSCM.TagAction} and {@link SubversionTagAction}.
  36. *
  37. * <p>
  38. * This class implements the action that tags the modules. Derived classes
  39. * need to provide <tt>tagForm.jelly</tt> view that displays a form for
  40. * letting user start tagging.
  41. *
  42. * @author Kohsuke Kawaguchi
  43. */
  44. public abstract class AbstractScmTagAction extends TaskAction implements BuildBadgeAction {
  45. protected final AbstractBuild build;
  46. protected AbstractScmTagAction(AbstractBuild build) {
  47. this.build = build;
  48. }
  49. public final String getUrlName() {
  50. // to make this consistent with CVSSCM, even though the name is bit off
  51. return "tagBuild";
  52. }
  53. /**
  54. * Defaults to {@link SCM#TAG}.
  55. */
  56. protected Permission getPermission() {
  57. return SCM.TAG;
  58. }
  59. public AbstractBuild getBuild() {
  60. return build;
  61. }
  62. /**
  63. * This message is shown as the tool tip of the build badge icon.
  64. */
  65. public String getTooltip() {
  66. return null;
  67. }
  68. /**
  69. * Returns true if the build is tagged already.
  70. */
  71. public abstract boolean isTagged();
  72. protected ACL getACL() {
  73. return build.getACL();
  74. }
  75. public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
  76. req.getView(this,chooseAction()).forward(req,rsp);
  77. }
  78. protected synchronized String chooseAction() {
  79. if(workerThread!=null)
  80. return "inProgress.jelly";
  81. return "tagForm.jelly";
  82. }
  83. }