Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  The MIT License
   *
   *  Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved.
   *
   *  Permission is hereby granted, free of charge, to any person obtaining a copy
   *  of this software and associated documentation files (the "Software"), to deal
   *  in the Software without restriction, including without limitation the rights
   *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  *  copies of the Software, and to permit persons to whom the Software is
  *  furnished to do so, subject to the following conditions:
  *
  *  The above copyright notice and this permission notice shall be included in
  *  all copies or substantial portions of the Software.
  *
  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  *  THE SOFTWARE.
  */
 package com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.actions;
 
 
 import static com.sonyericsson.hudson.plugins.gerrit.trigger.utils.StringUtil.getPluginImageUrl;

Action that retriggers one build with the same event parameters as the build this trigger is in.

Author(s):
Robert Sandell <robert.sandell@sonyericsson.com>
 
 public class RetriggerAction implements Action {
 
     private TriggerContext context;

    
Standard Constructor.

Parameters:
context the original GerritCause's context.
 
     public RetriggerAction(TriggerContext context) {
         this. = context;
     }

    
Default constructor. Only use this if you are a serializer.
 
     public RetriggerAction() {
     }
 
     @Override
     public String getIconFileName() {
         if (!hasPermission() || isBuilding()) {
             return null;
         } else {
             return getPluginImageUrl("icon_retrigger24.png");
         }
     }
 
     @Override
     public String getDisplayName() {
         if (!hasPermission() || isBuilding()) {
             return null;
         } else {
             return Messages.Retrigger();
         }
     }
 
     @Override
     public String getUrlName() {
         if (!hasPermission() || isBuilding()) {
             return null;
         } else {
             return "gerrit-trigger-retrigger-this";
         }
     }

    
Checks the current "memory" if the project is currently building this event.

Returns:
true if so.
 
     private boolean isBuilding() {
         if ( == null || .getThisBuild() == null || .getEvent() == null) {
             return false;
         } else {
             return .getThisBuild().getBuild().isBuilding()
                     || ToGerritRunListener.getInstance().isBuilding(.getThisBuild().getProject(),
                                                                 .getEvent());
        }
    }

    
checks if the current user has permission to build the project.

Returns:
true if so.
    private boolean hasPermission() {
        if ( == null || .getThisBuild() == null || .getThisBuild().getProject() == null) {
            return false;
        } else {
        }
    }

    
Handles the request to re-trigger and redirects back to the page that called.

Parameters:
request StaplerRequest the request.
response StaplerResponse the response handler.
Throws:
java.io.IOException in case of Stapler issues
    public void doIndex(StaplerRequest requestStaplerResponse responsethrows IOException {
        if ( == null || .getThisBuild() == null) {
            return;
        }
        if (!hasPermission()) {
            //TODO Access denied message to user?
            return;
        }
        if (isBuilding()) {
            //TODO show error to user?
            return;
        }
        TriggeredItemEntity entity = .getThisBuild();
        GerritTrigger trigger = (GerritTrigger)entity.getProject().getTrigger(GerritTrigger.class);
        if (trigger == null) {
            //TODO show config error to user?
            return;
        }
        trigger.retriggerThisBuild();
        response.sendRedirect2(entity.getProject().getAbsoluteUrl());
    }
New to GrepCode? Check out our FAQ X