Class ToGerritRunListener
- java.lang.Object
-
- hudson.model.listeners.RunListener<Run>
-
- com.sonyericsson.hudson.plugins.gerrit.trigger.gerritnotifier.ToGerritRunListener
-
- All Implemented Interfaces:
ExtensionPoint
@Extension(ordinal=10003.0) public final class ToGerritRunListener extends RunListener<Run>
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
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Field Summary
Fields Modifier and Type Field Description static int
ORDINAL
The ordering of this extension.-
Fields inherited from class hudson.model.listeners.RunListener
LISTENERS, targetType
-
-
Constructor Summary
Constructors Constructor Description ToGerritRunListener()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
allBuildsCompleted(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event, GerritCause cause, TaskListener listener)
Manages the end of a Gerrit Event.protected void
cleanUpGerritCauses(GerritCause firstFound, Run build)
Workaround for builds that are triggered by the same Gerrit cause but multiple times in the same quiet period.protected String
getExpandedContent(FilePath path, 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 FilePath[]
getMatchingWorkspaceFiles(FilePath ws, String filepath)
Searches theworkspace
for files matching thefilepath
glob.List<Run>
getRuns(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
Get runs triggered for event.boolean
isBuilding(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
Checks the memory if the event is building.boolean
isBuilding(Job project, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
Checks the memory if the project is currently building the event.boolean
isProjectTriggeredAndIncomplete(Job 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.boolean
isTriggered(Job project, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
Checks the memory if the project is triggered by the event.void
notifyProjectRemoved(Job project)
Cleans the project from run listener related data structures.void
onCompleted(Run r, TaskListener listener)
void
onRetriggered(Job project, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event, List<Run> otherBuilds)
Called just before a build is scheduled by the user to retrigger.void
onStarted(Run r, TaskListener listener)
void
onTriggered(Job project, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
Called just before a build is scheduled by the trigger.BuildMemoryReport
report()
Creates a snapshot report of the current contents of theBuildMemory
.void
setBuildCustomUrl(Run r, String customUrl)
Records a custom URL for the given build.void
setBuildUnsuccessfulMessage(Run r, String unsuccessfulMessage)
Records the unsuccessful message for the given build.void
setQueueCancelled(Job project, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
Sets the memory of the project to buildCompleted.protected void
setThisBuild(Run r)
Updates allGerritCause
sTriggerContext.thisBuild
in the build.protected void
updateTriggerContexts(Run r)
Updates theTriggerContext
s for all theGerritCause
s in the build.-
Methods inherited from class hudson.model.listeners.RunListener
all, fireCompleted, fireDeleted, fireFinalized, fireInitialize, fireStarted, onDeleted, onFinalized, onInitialize, register, setUpEnvironment, unregister
-
-
-
-
Field Detail
-
ORDINAL
public static final int ORDINAL
The ordering of this extension.- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
@CheckForNull public static ToGerritRunListener getInstance()
Returns the registered instance of this class from the list of all listeners.- Returns:
- the instance.
-
setBuildCustomUrl
public void setBuildCustomUrl(@NonNull Run r, @NonNull String customUrl)
Records a custom URL for the given build.- Parameters:
r
- the build.customUrl
- the URL.
-
setBuildUnsuccessfulMessage
public void setBuildUnsuccessfulMessage(@NonNull Run r, @NonNull String unsuccessfulMessage)
Records the unsuccessful message for the given build.- Parameters:
r
- the build that caused the failure.unsuccessfulMessage
- the unsuccessful message
-
onCompleted
public void onCompleted(@NonNull Run r, @NonNull TaskListener listener)
- Overrides:
onCompleted
in classRunListener<Run>
-
report
@NonNull public BuildMemoryReport report()
Creates a snapshot report of the current contents of theBuildMemory
.- Returns:
- the report.
- See Also:
Diagnostics
-
allBuildsCompleted
public void allBuildsCompleted(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event, GerritCause cause, 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(Job 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(Run r, TaskListener listener)
- Overrides:
onStarted
in classRunListener<Run>
-
getRuns
@Nullable public List<Run> getRuns(com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
Get runs triggered for event.- Parameters:
event
- the Gerrit Event which is being checked.- Returns:
- the list of triggered runs for the event.
-
updateTriggerContexts
protected void updateTriggerContexts(Run r)
Updates theTriggerContext
s for all theGerritCause
s in the build.- Parameters:
r
- the build.- See Also:
BuildMemory.updateTriggerContext( com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritCause, hudson.model.Run)
-
setThisBuild
protected void setThisBuild(Run r)
Updates allGerritCause
sTriggerContext.thisBuild
in the build.- Parameters:
r
- the build to update.
-
cleanUpGerritCauses
protected void cleanUpGerritCauses(GerritCause firstFound, Run 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 byRun.getCause(Class)
.build
- the build to clean up.
-
onTriggered
public void onTriggered(Job 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(Job project, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event, List<Run> 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(Job 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.Job)
-
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)
-
isTriggered
public boolean isTriggered(Job project, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
Checks the memory if the project is triggered by the event.- Parameters:
project
- the project.event
- the event.- Returns:
- true if so.
-
setQueueCancelled
public void setQueueCancelled(Job project, com.sonymobile.tools.gerrit.gerritevents.dto.events.GerritTriggeredEvent event)
Sets the memory of the project to buildCompleted. Used when the entry is canceled in the Queue.- Parameters:
project
- the projectevent
- the event
-
notifyProjectRemoved
public void notifyProjectRemoved(Job project)
Cleans the project from run listener related data structures.- Parameters:
project
- the project to be removed.
-
getMatchingWorkspaceFiles
@NonNull protected FilePath[] getMatchingWorkspaceFiles(@Nullable FilePath ws, @NonNull String filepath) throws IOException, InterruptedException
Searches theworkspace
for files matching thefilepath
glob.- Parameters:
ws
- The workspacefilepath
- The filepath glob pattern- Returns:
- List of matching
FilePath
s. Guaranteed to be non-null. - Throws:
IOException
- if an error occurs while reading the workspaceInterruptedException
- if an error occurs while reading the workspace
-
getExpandedContent
protected String getExpandedContent(FilePath path, 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 fileInterruptedException
- if an error occurs while checking the status of the file
-
-