com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier
Class ToGerritRunListener

java.lang.Object
  extended by hudson.model.listeners.RunListener<hudson.model.AbstractBuild>
      extended by com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.ToGerritRunListener
All Implemented Interfaces:
hudson.ExtensionPoint

@Extension
public class ToGerritRunListener
extends hudson.model.listeners.RunListener<hudson.model.AbstractBuild>

The Big RunListener in charge of coordinating build results and reporting back to Gerrit.

Author:
Robert Sandell <robert.sandell@sonyericsson.com>

Nested Class Summary
 
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
hudson.ExtensionPoint.LegacyInstancesAreScopedToHudson
 
Field Summary
 
Fields inherited from class hudson.model.listeners.RunListener
LISTENERS, targetType
 
Constructor Summary
ToGerritRunListener()
          Default Constructor.
 
Method Summary
protected  void cleanUpGerritCauses(GerritCause firstFound, hudson.model.AbstractBuild build)
          Workaround for builds that are triggered by the same Gerrit cause but multiple times in the same quiet period.
protected  java.lang.String getExpandedContent(hudson.FilePath path, hudson.EnvVars envVars)
          Returns the expanded file contents using the provided environment variables.
static ToGerritRunListener getInstance()
          Returns the registered instance of this class from the list of all listeners.
protected  hudson.FilePath[] getMatchingWorkspaceFiles(hudson.FilePath ws, java.lang.String filepath)
          Searches the workspace for files matching the filepath glob.
 boolean isBuilding(hudson.model.AbstractProject project, PatchsetCreated event)
          Checks the memory if the project is currently building the event.
 boolean isBuilding(PatchsetCreated event)
          Checks the memory if the event is building.
 void onCompleted(hudson.model.AbstractBuild r, hudson.model.TaskListener listener)
           
 void onRetriggered(hudson.model.AbstractProject project, PatchsetCreated event, java.util.List<hudson.model.AbstractBuild> otherBuilds)
          Called just before a build is scheduled by the user to retrigger.
 void onStarted(hudson.model.AbstractBuild r, hudson.model.TaskListener listener)
           
 void onTriggered(hudson.model.AbstractProject project, PatchsetCreated event)
          Called just before a build is scheduled by the trigger.
protected  void setThisBuild(hudson.model.AbstractBuild r)
          Updates all GerritCauses TriggerContext.thisBuild in the build.
protected  void updateTriggerContexts(hudson.model.AbstractBuild r, BuildMemory.PatchSetKey key)
          Updates the TriggerContexts for all the GerritCauses in the build.
 
Methods inherited from class hudson.model.listeners.RunListener
all, fireCompleted, fireDeleted, fireFinalized, fireStarted, onDeleted, onFinalized, register, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ToGerritRunListener

public ToGerritRunListener()
Default Constructor.

Method Detail

getInstance

public static ToGerritRunListener getInstance()
Returns the registered instance of this class from the list of all listeners.

Returns:
the instance.

onCompleted

public void onCompleted(hudson.model.AbstractBuild r,
                        hudson.model.TaskListener listener)
Overrides:
onCompleted in class hudson.model.listeners.RunListener<hudson.model.AbstractBuild>

onStarted

public void onStarted(hudson.model.AbstractBuild r,
                      hudson.model.TaskListener listener)
Overrides:
onStarted in class hudson.model.listeners.RunListener<hudson.model.AbstractBuild>

updateTriggerContexts

protected void updateTriggerContexts(hudson.model.AbstractBuild r,
                                     BuildMemory.PatchSetKey key)
Updates the TriggerContexts for all the GerritCauses in the build.

Parameters:
r - the build.
key - the memory key to update.
See Also:
BuildMemory.updateTriggerContext( com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.model.BuildMemory.PatchSetKey, com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritCause, hudson.model.AbstractBuild)

setThisBuild

protected void setThisBuild(hudson.model.AbstractBuild r)
Updates all GerritCauses TriggerContext.thisBuild in the build.

Parameters:
r - the build to update.

cleanUpGerritCauses

protected void cleanUpGerritCauses(GerritCause firstFound,
                                   hudson.model.AbstractBuild build)
Workaround for builds that are triggered by the same Gerrit cause but multiple times in the same quiet period.

Parameters:
firstFound - the cause first returned by Run.getCause(Class).
build - the build to clean up.

onTriggered

public void onTriggered(hudson.model.AbstractProject project,
                        PatchsetCreated event)
Called just before a build is scheduled by the trigger.

Parameters:
project - the project that will be built.
event - the event that caused the build to be scheduled.

onRetriggered

public void onRetriggered(hudson.model.AbstractProject project,
                          PatchsetCreated event,
                          java.util.List<hudson.model.AbstractBuild> otherBuilds)
Called just before a build is scheduled by the user to retrigger.

Parameters:
project - the project.
event - the event.
otherBuilds - the list of other builds in the previous context.

isBuilding

public boolean isBuilding(hudson.model.AbstractProject project,
                          PatchsetCreated event)
Checks the memory if the project is currently building the event.

Parameters:
project - the project.
event - the event.
Returns:
true if so.
See Also:
BuildMemory.isBuilding(PatchsetCreated, hudson.model.AbstractProject)

isBuilding

public boolean isBuilding(PatchsetCreated event)
Checks the memory if the event is building.

Parameters:
event - the event.
Returns:
true if so.
See Also:
BuildMemory.isBuilding(com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.events.PatchsetCreated)

getMatchingWorkspaceFiles

protected hudson.FilePath[] getMatchingWorkspaceFiles(hudson.FilePath ws,
                                                      java.lang.String filepath)
                                               throws java.io.IOException,
                                                      java.lang.InterruptedException
Searches the workspace for files matching the filepath glob.

Parameters:
ws - The workspace
filepath - The filepath glob pattern
Returns:
List of matching FilePaths. Guaranteed to be non-null.
Throws:
java.io.IOException - if an error occurs while reading the workspace
java.lang.InterruptedException - if an error occurs while reading the workspace

getExpandedContent

protected java.lang.String getExpandedContent(hudson.FilePath path,
                                              hudson.EnvVars envVars)
                                       throws java.io.IOException,
                                              java.lang.InterruptedException
Returns the expanded file contents using the provided environment variables. null will be returned if the path does not exist.

Parameters:
path - The file path being read.
envVars - The environment variables to use during expansion.
Returns:
The string file contents, or null if it does not exist.
Throws:
java.io.IOException - if an error occurs while reading the file
java.lang.InterruptedException - if an error occurs while checking the status of the file


Copyright © 2004-2012. All Rights Reserved.