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.
 
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(List<GerritProject> gerritProjects, Integer gerritBuildStartedVerifiedValue, Integer gerritBuildStartedCodeReviewValue, Integer gerritBuildSuccessfulVerifiedValue, Integer gerritBuildSuccessfulCodeReviewValue, Integer gerritBuildFailedVerifiedValue, Integer gerritBuildFailedCodeReviewValue, Integer gerritBuildUnstableVerifiedValue, Integer gerritBuildUnstableCodeReviewValue, boolean silentMode, boolean escapeQuotes, String buildStartMessage, String buildSuccessfulMessage, String buildUnstableMessage, String buildFailureMessage)
          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.
 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.
 String getBuildStartMessage()
          The message to show users when a build starts, if custom messages are enabled.
 String getBuildSuccessfulMessage()
          The message to show users when a build succeeds, if custom messages are enabled.
 String getBuildUnstableMessage()
          The message to show users when a build is unstable, if custom messages are enabled.
 Integer getGerritBuildFailedCodeReviewValue()
          Job specific Gerrit code review vote when a build is failed, null means that the global value should be used.
 Integer getGerritBuildFailedVerifiedValue()
          Job specific Gerrit verified vote when a build is failed, null means that the global value should be used.
 Integer getGerritBuildStartedCodeReviewValue()
          Job specific Gerrit code review vote when a build is started, null means that the global value should be used.
 Integer getGerritBuildStartedVerifiedValue()
          Job specific Gerrit verified vote when a build is started, null means that the global value should be used.
 Integer getGerritBuildSuccessfulCodeReviewValue()
          Job specific Gerrit code review vote when a build is successful, null means that the global value should be used.
 Integer getGerritBuildSuccessfulVerifiedValue()
          Job specific Gerrit verified vote when a build is successful, null means that the global value should be used.
 Integer getGerritBuildUnstableCodeReviewValue()
          Job specific Gerrit code review vote when a build is unstable, null means that the global value should be used.
 Integer getGerritBuildUnstableVerifiedValue()
          Job specific Gerrit verified vote when a build is unstable, null means that the global value should be used.
 List<GerritProject> getGerritProjects()
          The list of GerritProject triggering rules.
 int hashCode()
           
 boolean isEscapeQuotes()
          if escapeQuotes is on or off.
 boolean isSilentMode()
          If silent mode is on or off.
 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 setEscapeQuotes(boolean escapeQuotes)
          Sets escapeQuotes to on or off.
 void setGerritBuildFailedCodeReviewValue(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(Integer gerritBuildFailedVerifiedValue)
          Job specific Gerrit verified vote when a build is failed, providing null means that the global value should be used.
 void setGerritBuildStartedCodeReviewValue(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(Integer gerritBuildStartedVerifiedValue)
          Job specific Gerrit verified vote when a build is started, providing null means that the global value should be used.
 void setGerritBuildSuccessfulCodeReviewValue(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(Integer gerritBuildSuccessfulVerifiedValue)
          Job specific Gerrit verified vote when a build is successful, providing null means that the global value should be used.
 void setGerritBuildUnstableCodeReviewValue(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(Integer gerritBuildUnstableVerifiedValue)
          Job specific Gerrit verified vote when a build is unstable, providing null means that the global value should be used.
 void setGerritProjects(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(List<GerritProject> gerritProjects,
                                          Integer gerritBuildStartedVerifiedValue,
                                          Integer gerritBuildStartedCodeReviewValue,
                                          Integer gerritBuildSuccessfulVerifiedValue,
                                          Integer gerritBuildSuccessfulCodeReviewValue,
                                          Integer gerritBuildFailedVerifiedValue,
                                          Integer gerritBuildFailedCodeReviewValue,
                                          Integer gerritBuildUnstableVerifiedValue,
                                          Integer gerritBuildUnstableCodeReviewValue,
                                          boolean silentMode,
                                          boolean escapeQuotes,
                                          String buildStartMessage,
                                          String buildSuccessfulMessage,
                                          String buildUnstableMessage,
                                          String buildFailureMessage)
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
Method Detail

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.

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 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 List<GerritProject> getGerritProjects()
The list of GerritProject triggering rules.

Returns:
the rule-set.

setGerritProjects

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

Parameters:
gerritProjects - the rule-set

getGerritBuildFailedCodeReviewValue

public 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(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 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(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 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(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 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(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 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(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 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(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 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(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 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(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.

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 String getBuildStartMessage()
The message to show users when a build starts, if custom messages are enabled.

Returns:
The build start message

getBuildSuccessfulMessage

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

Returns:
The build successful message

getBuildUnstableMessage

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

Returns:
The build unstable message

getBuildFailureMessage

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

Returns:
The build failure message

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.


Copyright © 2004-2011. All Rights Reserved.