Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  The MIT License
   *
   *  Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved.
   *  Copyright 2012 Sony Mobile Communications AB. 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.gerritnotifier;
 
Start position that notifies Gerrit of events.

Author(s):
Robert Sandell <robert.sandell@sonyericsson.com>
 
 public class GerritNotifier {
 
     private static final Logger logger = LoggerFactory.getLogger(GerritNotifier.class);
     private GerritCmdRunner cmdRunner;
     private ParameterExpander parameterExpander;

    
Constructor.

Parameters:
config the config.
cmdRunner the command-runner.
 
     public GerritNotifier(IGerritHudsonTriggerConfig configGerritCmdRunner cmdRunner) {
         this. = cmdRunner;
         this. = new ParameterExpander(config);
     }

    
Constructor for testing.

Parameters:
config the config.
cmdRunner the command-runner.
hudson the hudson instance.
 
     public GerritNotifier(IGerritHudsonTriggerConfig configGerritCmdRunner cmdRunnerHudson hudson) {
         this. = cmdRunner;
         this. = new ParameterExpander(confighudson);
     }

    
Generates the build-started command based on configured templates and build-values and sends it to Gerrit.

Parameters:
build the build.
taskListener the taskListener.
event the event.
stats the stats.
 
     public void buildStarted(AbstractBuild buildTaskListener taskListener,
             GerritTriggeredEvent eventBuildsStartedStats stats) {
         try {
             /* Without a change, it doesn't make sense to notify gerrit */
             if (event instanceof ChangeBasedEvent) {
                 String command =
                         .getBuildStartedCommand(buildtaskListener, (ChangeBasedEvent)eventstats);
                 if (command != null) {
                     if (!command.isEmpty()) {
                         .info("Notifying BuildStarted to gerrit: {}"command);
                         .sendCommand(command);
                     } else {
                         .info("BuildStarted command is empty.  Gerrit will not be notified of BuildStarted");
                     }
                 } else {
                     .error("Something wrong during parameter extraction. "
                             + "Gerrit will not be notified of BuildStarted");
                 }
             }
         } catch (Exception ex) {
             .error("Could not complete BuildStarted notification!"ex);
         }
     }

    
Generates the build-completed command based on configured templates and build-values and sends it to Gerrit.

Parameters:
memoryImprint the memory of all the builds for an event.
listener the taskListener.
    public void buildCompleted(MemoryImprint memoryImprintTaskListener listener) {
        try {
            /* Without a change, it doesn't make sense to notify gerrit */
            if (memoryImprint.getEvent() instanceof ChangeBasedEvent) {
                String command = .getBuildCompletedCommand(memoryImprintlistener);
                if (command != null) {
                    if (!command.isEmpty()) {
                        .info("Notifying BuildCompleted to gerrit: {}"command);
                        .sendCommand(command);
                    } else {
                        .info("BuildCompleted command is empty.  Gerrit will not be notified of BuildCompleted");
                    }
                } else {
                    .error("Something wrong during parameter extraction. "
                            + "Gerrit will not be notified of BuildCompleted");
                }
            }
        } catch (Exception ex) {
            .error("Could not complete BuildCompleted notification!"ex);
        }
    }
New to GrepCode? Check out our FAQ X