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(ordinal=10003.0)
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
static int ORDINAL
          The ordering of this extension.
 
Fields inherited from class hudson.model.listeners.RunListener
LISTENERS, targetType
 
Constructor Summary
ToGerritRunListener()
          Default Constructor.
 
Method Summary
 void allBuildsCompleted(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event, GerritCause cause, hudson.model.TaskListener listener)
          Manages the end of a Gerrit Event.
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  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, String filepath)
          Searches the workspace for files matching the filepath glob.
 boolean isBuilding(hudson.model.AbstractProject project, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
          Checks the memory if the project is currently building the event.
 boolean isBuilding(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
          Checks the memory if the event is building.
 boolean isProjectTriggeredAndIncomplete(hudson.model.AbstractProject p, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
          Checks whether a project has triggered for an event but hasn't yet finished building.
 void onCompleted(hudson.model.AbstractBuild r, hudson.model.TaskListener listener)
           
 void onRetriggered(hudson.model.AbstractProject project, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event, 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, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent 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)
          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, setUpEnvironment, unregister
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORDINAL

public static final int ORDINAL
The ordering of this extension.

See Also:
Constant Field Values
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>

allBuildsCompleted

public void allBuildsCompleted(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event,
                               GerritCause cause,
                               hudson.model.TaskListener listener)
Manages the end of a Gerrit Event. Should be called after each build related to an event completes if that build should report back to Gerrit.

Parameters:
event - the Gerrit Event which may need to be completed.
cause - the Gerrit Cause which triggered the build initially.
listener - the Jenkins listener.

isProjectTriggeredAndIncomplete

public boolean isProjectTriggeredAndIncomplete(hudson.model.AbstractProject p,
                                               com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
Checks whether a project has triggered for an event but hasn't yet finished building.

Parameters:
event - the Gerrit Event which is being checked.
p - the Gerrit project being checked.
Returns:
true if so.

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)
Updates the TriggerContexts for all the GerritCauses in the build.

Parameters:
r - the build.
See Also:
BuildMemory.updateTriggerContext( 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,
                        com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent 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,
                          com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event,
                          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,
                          com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent 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(GerritTriggeredEvent, hudson.model.AbstractProject)

isBuilding

public boolean isBuilding(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
Checks the memory if the event is building.

Parameters:
event - the event.
Returns:
true if so.
See Also:
BuildMemory.isBuilding(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent)

getMatchingWorkspaceFiles

protected hudson.FilePath[] getMatchingWorkspaceFiles(hudson.FilePath ws,
                                                      String filepath)
                                               throws IOException,
                                                      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:
IOException - if an error occurs while reading the workspace
InterruptedException - if an error occurs while reading the workspace

getExpandedContent

protected String getExpandedContent(hudson.FilePath path,
                                    hudson.EnvVars envVars)
                             throws IOException,
                                    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:
IOException - if an error occurs while reading the file
InterruptedException - if an error occurs while checking the status of the file


Copyright © 2004-2014. All Rights Reserved.