com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger
Class GerritTrigger

java.lang.Object
  extended by hudson.triggers.Trigger<hudson.model.AbstractProject>
      extended by com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger
All Implemented Interfaces:
GerritEventListener, hudson.ExtensionPoint, hudson.model.Describable<hudson.triggers.Trigger<?>>

public class GerritTrigger
extends hudson.triggers.Trigger<hudson.model.AbstractProject>
implements GerritEventListener

Triggers a build based on Gerrit events.

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

Nested Class Summary
static class GerritTrigger.DescriptorImpl
          The Descriptor for the Trigger.
static class GerritTrigger.RunningJobs
          Class for maintaining and synchronizing the runningJobs info.
 
Nested classes/interfaces inherited from class hudson.triggers.Trigger
hudson.triggers.Trigger.Cron
 
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
hudson.ExtensionPoint.LegacyInstancesAreScopedToHudson
 
Field Summary
 
Fields inherited from class hudson.triggers.Trigger
job, spec, tabs, timer
 
Constructor Summary
GerritTrigger(java.util.List<GerritProject> gerritProjects, java.lang.Integer gerritBuildStartedVerifiedValue, java.lang.Integer gerritBuildStartedCodeReviewValue, java.lang.Integer gerritBuildSuccessfulVerifiedValue, java.lang.Integer gerritBuildSuccessfulCodeReviewValue, java.lang.Integer gerritBuildFailedVerifiedValue, java.lang.Integer gerritBuildFailedCodeReviewValue, java.lang.Integer gerritBuildUnstableVerifiedValue, java.lang.Integer gerritBuildUnstableCodeReviewValue, boolean silentMode, boolean escapeQuotes, java.lang.String buildStartMessage, java.lang.String buildSuccessfulMessage, java.lang.String buildUnstableMessage, java.lang.String buildFailureMessage, java.lang.String buildUnsuccessfulFilepath, java.lang.String customUrl)
          Default DataBound Constructor.
 
Method Summary
protected  hudson.model.ParametersAction createParameters(PatchsetCreated event, hudson.model.AbstractProject project)
          Creates a ParameterAction and fills it with the project's default parameters + the Standard Gerrit parameters.
 void gerritEvent(ChangeAbandoned event)
          Called when a ChangeAbandoned event arrives.
 void gerritEvent(GerritEvent event)
           
 void gerritEvent(PatchsetCreated event)
          Called when a PatchSetCreated event arrives.
 java.lang.String getBuildFailureMessage()
          The message to show users when a build finishes, if custom messages are enabled.
 int getBuildScheduleDelay()
          getBuildScheduleDelay method will return configured buildScheduledelay value.
 java.lang.String getBuildStartMessage()
          The message to show users when a build starts, if custom messages are enabled.
 java.lang.String getBuildSuccessfulMessage()
          The message to show users when a build succeeds, if custom messages are enabled.
 java.lang.String getBuildUnstableMessage()
          The message to show users when a build is unstable, if custom messages are enabled.
 java.lang.String getBuildUnsuccessfulFilepath()
          The path to a file that contains the unsuccessful Gerrit comment message.
 java.lang.String getCustomUrl()
          URL to send in comment to gerrit.
 java.lang.Integer getGerritBuildFailedCodeReviewValue()
          Job specific Gerrit code review vote when a build is failed, null means that the global value should be used.
 java.lang.Integer getGerritBuildFailedVerifiedValue()
          Job specific Gerrit verified vote when a build is failed, null means that the global value should be used.
 java.lang.Integer getGerritBuildStartedCodeReviewValue()
          Job specific Gerrit code review vote when a build is started, null means that the global value should be used.
 java.lang.Integer getGerritBuildStartedVerifiedValue()
          Job specific Gerrit verified vote when a build is started, null means that the global value should be used.
 java.lang.Integer getGerritBuildSuccessfulCodeReviewValue()
          Job specific Gerrit code review vote when a build is successful, null means that the global value should be used.
 java.lang.Integer getGerritBuildSuccessfulVerifiedValue()
          Job specific Gerrit verified vote when a build is successful, null means that the global value should be used.
 java.lang.Integer getGerritBuildUnstableCodeReviewValue()
          Job specific Gerrit code review vote when a build is unstable, null means that the global value should be used.
 java.lang.Integer getGerritBuildUnstableVerifiedValue()
          Job specific Gerrit verified vote when a build is unstable, null means that the global value should be used.
 java.util.List<GerritProject> getGerritProjects()
          The list of GerritProject triggering rules.
static GerritTrigger getTrigger(hudson.model.AbstractProject project)
          Finds the GerritTrigger in a project.
 int hashCode()
           
 boolean isEscapeQuotes()
          if escapeQuotes is on or off.
 boolean isFileTriggerEnabled()
          Convenience method for finding it out if file triggering is enabled in the gerrit version.
 boolean isSilentMode()
          If silent mode is on or off.
 void notifyBuildEnded(PatchsetCreated patchset)
          Used to inform the plugin that the builds for a job have ended.
 void retriggerAllBuilds(TriggerContext context)
          Retriggers all builds in the given context.
 void retriggerThisBuild(TriggerContext context)
          Re-triggers the build in TriggerContext.getThisBuild() for the context's event.
protected  void schedule(GerritCause cause, PatchsetCreated event)
          Schedules a build with parameters from the event.
protected  void schedule(GerritCause cause, PatchsetCreated event, hudson.model.AbstractProject project)
          Schedules a build with parameters from the event.
 void setBuildUnsuccessfulFilepath(java.lang.String path)
          Sets the path to a file that contains the unsuccessful Gerrit comment message.
 void setCustomUrl(java.lang.String customUrl)
          Set custom URL to post back to gerrit.
 void setEscapeQuotes(boolean escapeQuotes)
          Sets escapeQuotes to on or off.
 void setGerritBuildFailedCodeReviewValue(java.lang.Integer gerritBuildFailedCodeReviewValue)
          Job specific Gerrit code review vote when a build is failed, providing null means that the global value should be used.
 void setGerritBuildFailedVerifiedValue(java.lang.Integer gerritBuildFailedVerifiedValue)
          Job specific Gerrit verified vote when a build is failed, providing null means that the global value should be used.
 void setGerritBuildStartedCodeReviewValue(java.lang.Integer gerritBuildStartedCodeReviewValue)
          Job specific Gerrit code review vote when a build is started, providing null means that the global value should be used.
 void setGerritBuildStartedVerifiedValue(java.lang.Integer gerritBuildStartedVerifiedValue)
          Job specific Gerrit verified vote when a build is started, providing null means that the global value should be used.
 void setGerritBuildSuccessfulCodeReviewValue(java.lang.Integer gerritBuildSuccessfulCodeReviewValue)
          Job specific Gerrit code review vote when a build is successful, providing null means that the global value should be used.
 void setGerritBuildSuccessfulVerifiedValue(java.lang.Integer gerritBuildSuccessfulVerifiedValue)
          Job specific Gerrit verified vote when a build is successful, providing null means that the global value should be used.
 void setGerritBuildUnstableCodeReviewValue(java.lang.Integer gerritBuildUnstableCodeReviewValue)
          Job specific Gerrit code review vote when a build is unstable, providing null means that the global value should be used.
 void setGerritBuildUnstableVerifiedValue(java.lang.Integer gerritBuildUnstableVerifiedValue)
          Job specific Gerrit verified vote when a build is unstable, providing null means that the global value should be used.
 void setGerritProjects(java.util.List<GerritProject> gerritProjects)
          The list of GerritProject triggering rules.
 void setSilentMode(boolean silentMode)
          Sets silent mode to on or off.
 void start(hudson.model.AbstractProject project, boolean newInstance)
           
 void stop()
           
 
Methods inherited from class hudson.triggers.Trigger
all, checkTriggers, for_, getDescriptor, getProjectAction, getProjectActions, getSpec, init, readResolve, run
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GerritTrigger

@DataBoundConstructor
public GerritTrigger(java.util.List<GerritProject> gerritProjects,
                                          java.lang.Integer gerritBuildStartedVerifiedValue,
                                          java.lang.Integer gerritBuildStartedCodeReviewValue,
                                          java.lang.Integer gerritBuildSuccessfulVerifiedValue,
                                          java.lang.Integer gerritBuildSuccessfulCodeReviewValue,
                                          java.lang.Integer gerritBuildFailedVerifiedValue,
                                          java.lang.Integer gerritBuildFailedCodeReviewValue,
                                          java.lang.Integer gerritBuildUnstableVerifiedValue,
                                          java.lang.Integer gerritBuildUnstableCodeReviewValue,
                                          boolean silentMode,
                                          boolean escapeQuotes,
                                          java.lang.String buildStartMessage,
                                          java.lang.String buildSuccessfulMessage,
                                          java.lang.String buildUnstableMessage,
                                          java.lang.String buildFailureMessage,
                                          java.lang.String buildUnsuccessfulFilepath,
                                          java.lang.String customUrl)
Default DataBound Constructor.

Parameters:
gerritProjects - the set of triggering rules.
gerritBuildStartedVerifiedValue - Job specific Gerrit verified vote when a build is started, null means that the global value should be used.
gerritBuildStartedCodeReviewValue - Job specific Gerrit code review vote when a build is started, null means that the global value should be used.
gerritBuildSuccessfulVerifiedValue - Job specific Gerrit verified vote when a build is successful, null means that the global value should be used.
gerritBuildSuccessfulCodeReviewValue - Job specific Gerrit code review vote when a build is successful, null means that the global value should be used.
gerritBuildFailedVerifiedValue - Job specific Gerrit verified vote when a build is failed, null means that the global value should be used.
gerritBuildFailedCodeReviewValue - Job specific Gerrit code review vote when a build is failed, null means that the global value should be used.
gerritBuildUnstableVerifiedValue - Job specific Gerrit verified vote when a build is unstable, null means that the global value should be used.
gerritBuildUnstableCodeReviewValue - Job specific Gerrit code review vote when a build is unstable, null means that the global value should be used.
silentMode - Silent Mode on or off.
escapeQuotes - EscapeQuotes on or off.
buildStartMessage - Message to write to Gerrit when a build begins
buildSuccessfulMessage - Message to write to Gerrit when a build succeeds
buildUnstableMessage - Message to write to Gerrit when a build is unstable
buildFailureMessage - Message to write to Gerrit when a build fails
buildUnsuccessfulFilepath - Filename to retrieve Gerrit comment message from, in the case of an unsuccessful build.
customUrl - Custom URL to sen to gerrit instead of build URL
Method Detail

getTrigger

public static GerritTrigger getTrigger(hudson.model.AbstractProject project)
Finds the GerritTrigger in a project.

Parameters:
project - the project.
Returns:
the trigger if there is one, null otherwise.

start

public void start(hudson.model.AbstractProject project,
                  boolean newInstance)
Overrides:
start in class hudson.triggers.Trigger<hudson.model.AbstractProject>

stop

public void stop()
Overrides:
stop in class hudson.triggers.Trigger<hudson.model.AbstractProject>

gerritEvent

public void gerritEvent(GerritEvent event)
Specified by:
gerritEvent in interface GerritEventListener

gerritEvent

public void gerritEvent(PatchsetCreated event)
Called when a PatchSetCreated event arrives.

Specified by:
gerritEvent in interface GerritEventListener
Parameters:
event - the event

schedule

protected void schedule(GerritCause cause,
                        PatchsetCreated event)
Schedules a build with parameters from the event. With myProject as the project to build.

Parameters:
cause - the cause of the build.
event - the event.

schedule

protected void schedule(GerritCause cause,
                        PatchsetCreated event,
                        hudson.model.AbstractProject project)
Schedules a build with parameters from the event.

Parameters:
cause - the cause of the build.
event - the event.
project - the project to build.

notifyBuildEnded

public void notifyBuildEnded(PatchsetCreated patchset)
Used to inform the plugin that the builds for a job have ended. This allows us to clean up our list of what jobs we're running.

Parameters:
patchset - the patchset.

getBuildScheduleDelay

public int getBuildScheduleDelay()
getBuildScheduleDelay method will return configured buildScheduledelay value. If the value is missing or invalid it the method will return default schedule delay or GerritDefaultValues.DEFAULT_BUILD_SCHEDULE_DELAY.

Returns:
buildScheduleDelay.

createParameters

protected hudson.model.ParametersAction createParameters(PatchsetCreated event,
                                                         hudson.model.AbstractProject project)
Creates a ParameterAction and fills it with the project's default parameters + the Standard Gerrit parameters.

Parameters:
event - the event.
project - the project.
Returns:
the ParameterAction.

retriggerThisBuild

public void retriggerThisBuild(TriggerContext context)
Re-triggers the build in TriggerContext.getThisBuild() for the context's event. Will not do any isInteresting(com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.events.PatchsetCreated) checks. If more than one build was triggered by the event the results from those builds will be counted again, but they won't be re-triggered. If any builds for the event are still running, this new scheduled build will replace its predesessor. If the project is currently building the event, no scheduling will be done.

Parameters:
context - the previous context.

retriggerAllBuilds

public void retriggerAllBuilds(TriggerContext context)
Retriggers all builds in the given context. The builds will only be triggered if no builds for the event are building.

Parameters:
context - the context to rebuild.
See Also:
ToGerritRunListener.isBuilding(com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.events.PatchsetCreated)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

gerritEvent

public void gerritEvent(ChangeAbandoned event)
Called when a ChangeAbandoned event arrives. Should probably not be listening on this here.

Specified by:
gerritEvent in interface GerritEventListener
Parameters:
event - the event.

getGerritProjects

public java.util.List<GerritProject> getGerritProjects()
The list of GerritProject triggering rules.

Returns:
the rule-set.

setGerritProjects

public void setGerritProjects(java.util.List<GerritProject> gerritProjects)
The list of GerritProject triggering rules.

Parameters:
gerritProjects - the rule-set

getGerritBuildFailedCodeReviewValue

public java.lang.Integer getGerritBuildFailedCodeReviewValue()
Job specific Gerrit code review vote when a build is failed, null means that the global value should be used.

Returns:
the vote value.

setGerritBuildFailedCodeReviewValue

public void setGerritBuildFailedCodeReviewValue(java.lang.Integer gerritBuildFailedCodeReviewValue)
Job specific Gerrit code review vote when a build is failed, providing null means that the global value should be used.

Parameters:
gerritBuildFailedCodeReviewValue - the vote value.

getGerritBuildFailedVerifiedValue

public java.lang.Integer getGerritBuildFailedVerifiedValue()
Job specific Gerrit verified vote when a build is failed, null means that the global value should be used.

Returns:
the vote value.

setGerritBuildFailedVerifiedValue

public void setGerritBuildFailedVerifiedValue(java.lang.Integer gerritBuildFailedVerifiedValue)
Job specific Gerrit verified vote when a build is failed, providing null means that the global value should be used.

Parameters:
gerritBuildFailedVerifiedValue - the vote value.

getGerritBuildStartedCodeReviewValue

public java.lang.Integer getGerritBuildStartedCodeReviewValue()
Job specific Gerrit code review vote when a build is started, null means that the global value should be used.

Returns:
the vote value.

setGerritBuildStartedCodeReviewValue

public void setGerritBuildStartedCodeReviewValue(java.lang.Integer gerritBuildStartedCodeReviewValue)
Job specific Gerrit code review vote when a build is started, providing null means that the global value should be used.

Parameters:
gerritBuildStartedCodeReviewValue - the vote value.

getGerritBuildStartedVerifiedValue

public java.lang.Integer getGerritBuildStartedVerifiedValue()
Job specific Gerrit verified vote when a build is started, null means that the global value should be used.

Returns:
the vote value.

setGerritBuildStartedVerifiedValue

public void setGerritBuildStartedVerifiedValue(java.lang.Integer gerritBuildStartedVerifiedValue)
Job specific Gerrit verified vote when a build is started, providing null means that the global value should be used.

Parameters:
gerritBuildStartedVerifiedValue - the vote value.

getGerritBuildSuccessfulCodeReviewValue

public java.lang.Integer getGerritBuildSuccessfulCodeReviewValue()
Job specific Gerrit code review vote when a build is successful, null means that the global value should be used.

Returns:
the vote value.

setGerritBuildSuccessfulCodeReviewValue

public void setGerritBuildSuccessfulCodeReviewValue(java.lang.Integer gerritBuildSuccessfulCodeReviewValue)
Job specific Gerrit code review vote when a build is successful, providing null means that the global value should be used.

Parameters:
gerritBuildSuccessfulCodeReviewValue - the vote value.

getGerritBuildSuccessfulVerifiedValue

public java.lang.Integer getGerritBuildSuccessfulVerifiedValue()
Job specific Gerrit verified vote when a build is successful, null means that the global value should be used.

Returns:
the vote value.

setGerritBuildSuccessfulVerifiedValue

public void setGerritBuildSuccessfulVerifiedValue(java.lang.Integer gerritBuildSuccessfulVerifiedValue)
Job specific Gerrit verified vote when a build is successful, providing null means that the global value should be used.

Parameters:
gerritBuildSuccessfulVerifiedValue - the vote value.

getGerritBuildUnstableCodeReviewValue

public java.lang.Integer getGerritBuildUnstableCodeReviewValue()
Job specific Gerrit code review vote when a build is unstable, null means that the global value should be used.

Returns:
the vote value.

setGerritBuildUnstableCodeReviewValue

public void setGerritBuildUnstableCodeReviewValue(java.lang.Integer gerritBuildUnstableCodeReviewValue)
Job specific Gerrit code review vote when a build is unstable, providing null means that the global value should be used.

Parameters:
gerritBuildUnstableCodeReviewValue - the vote value.

getGerritBuildUnstableVerifiedValue

public java.lang.Integer getGerritBuildUnstableVerifiedValue()
Job specific Gerrit verified vote when a build is unstable, null means that the global value should be used.

Returns:
the vote value.

setGerritBuildUnstableVerifiedValue

public void setGerritBuildUnstableVerifiedValue(java.lang.Integer gerritBuildUnstableVerifiedValue)
Job specific Gerrit verified vote when a build is unstable, providing null means that the global value should be used.

Parameters:
gerritBuildUnstableVerifiedValue - the vote value.

setBuildUnsuccessfulFilepath

public void setBuildUnsuccessfulFilepath(java.lang.String path)
Sets the path to a file that contains the unsuccessful Gerrit comment message.

Parameters:
path - The unsuccessful message comment file path

isSilentMode

public boolean isSilentMode()
If silent mode is on or off. When silent mode is on there will be no communication back to Gerrit, i.e. no build started/failed/successful approve messages etc. Default is false.

Returns:
true if silent mode is on.

isEscapeQuotes

public boolean isEscapeQuotes()
if escapeQuotes is on or off. When escapeQuotes is on this plugin will escape quotes in Gerrit event parameter string Default is true

Returns:
true if escapeQuotes is on.

setEscapeQuotes

public void setEscapeQuotes(boolean escapeQuotes)
Sets escapeQuotes to on or off. When escapeQuotes is on plugin will escape quotes in Gerrit event parameter string. Default is false.

Parameters:
escapeQuotes - is true if escapeQuotes should be on.

getBuildStartMessage

public java.lang.String getBuildStartMessage()
The message to show users when a build starts, if custom messages are enabled.

Returns:
The build start message

getBuildSuccessfulMessage

public java.lang.String getBuildSuccessfulMessage()
The message to show users when a build succeeds, if custom messages are enabled.

Returns:
The build successful message

getBuildUnstableMessage

public java.lang.String getBuildUnstableMessage()
The message to show users when a build is unstable, if custom messages are enabled.

Returns:
The build unstable message

getBuildFailureMessage

public java.lang.String getBuildFailureMessage()
The message to show users when a build finishes, if custom messages are enabled.

Returns:
The build failure message

getBuildUnsuccessfulFilepath

public java.lang.String getBuildUnsuccessfulFilepath()
The path to a file that contains the unsuccessful Gerrit comment message.

Returns:
The unsuccessful message comment file path

setSilentMode

public void setSilentMode(boolean silentMode)
Sets silent mode to on or off. When silent mode is on there will be no communication back to Gerrit, i.e. no build started/failed/successful approve messages etc. Default is false.

Parameters:
silentMode - true if silent mode should be on.

getCustomUrl

public java.lang.String getCustomUrl()
URL to send in comment to gerrit.

Returns:
custom URL to post back to gerrit

setCustomUrl

public void setCustomUrl(java.lang.String customUrl)
Set custom URL to post back to gerrit.

Parameters:
customUrl - url to set

isFileTriggerEnabled

public boolean isFileTriggerEnabled()
Convenience method for finding it out if file triggering is enabled in the gerrit version.

Returns:
true if file triggering is enabled in the gerrit version.


Copyright © 2004-2012. All Rights Reserved.