Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    *  The MIT License
    *
    *  Copyright 2010 Sony Ericsson Mobile Communications. All rights reserved.
    *  Copyright 2012 Sony Mobile Communications AB. All rights reserved.
    *
    *  Permission is hereby granted, free of charge, to any person obtaining a copy
    *  of this software and associated documentation files (the "Software"), to deal
    *  in the Software without restriction, including without limitation the rights
   *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   *  copies of the Software, and to permit persons to whom the Software is
   *  furnished to do so, subject to the following conditions:
   *
   *  The above copyright notice and this permission notice shall be included in
   *  all copies or substantial portions of the Software.
   *
   *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   *  THE SOFTWARE.
   */
  package com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger;
  
  import hudson.Extension;
  import hudson.model.Item;
  import org.slf4j.Logger;
  
  import java.util.HashMap;
  import java.util.List;
  import java.net.URL;
  
  import static com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritDefaultValues.DEFAULT_BUILD_SCHEDULE_DELAY;
  import static com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTriggerParameters.setOrCreateParameters;

Triggers a build based on Gerrit events.

Author(s):
Robert Sandell <robert.sandell@sonyericsson.com>
 
 public class GerritTrigger extends Trigger<AbstractProjectimplements GerritEventListener {
 
     private static final Logger logger = LoggerFactory.getLogger(GerritTrigger.class);
     //! Association between patches and the jobs that we're running for them
     private transient RunningJobs runningJobs = new RunningJobs();
     private transient AbstractProject myProject;
     private List<GerritProjectgerritProjects;
     private boolean silentMode;
     private boolean escapeQuotes;
     private String buildStartMessage;
     private String buildFailureMessage;
     private String buildSuccessfulMessage;
     private String buildUnstableMessage;
     private String buildNotBuiltMessage;
     private String customUrl;
     private boolean dynamicTriggerConfiguration;
     private String triggerConfigURL;
 
 
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.
gerritBuildNotBuiltVerifiedValue Job specific Gerrit verified vote when a build is not built, null means that the global value should be used.
gerritBuildNotBuiltCodeReviewValue Job specific Gerrit code review vote when a build is not built, 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
buildNotBuiltMessage Message to write to Gerrit when all builds are not built
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
triggerOnEvents The list of event types to trigger on.
dynamicTriggerConfiguration Dynamic trigger configuration on or off
triggerConfigURL Where to fetch the configuration file from
 
     public GerritTrigger(
             List<GerritProjectgerritProjects,
             Integer gerritBuildStartedVerifiedValue,
             Integer gerritBuildStartedCodeReviewValue,
             Integer gerritBuildSuccessfulVerifiedValue,
             Integer gerritBuildSuccessfulCodeReviewValue,
             Integer gerritBuildFailedVerifiedValue,
             Integer gerritBuildFailedCodeReviewValue,
             Integer gerritBuildUnstableVerifiedValue,
             Integer gerritBuildUnstableCodeReviewValue,
             Integer gerritBuildNotBuiltVerifiedValue,
             Integer gerritBuildNotBuiltCodeReviewValue,
             boolean silentMode,
             boolean escapeQuotes,
             String buildStartMessage,
             String buildSuccessfulMessage,
             String buildUnstableMessage,
             String buildFailureMessage,
             String buildNotBuiltMessage,
             String buildUnsuccessfulFilepath,
             String customUrl,
             List<PluginGerritEventtriggerOnEvents,
             boolean dynamicTriggerConfiguration,
             String triggerConfigURL) {
         this. = gerritProjects;
         this. = gerritBuildStartedVerifiedValue;
         this. = gerritBuildStartedCodeReviewValue;
         this. = gerritBuildSuccessfulVerifiedValue;
         this. = gerritBuildSuccessfulCodeReviewValue;
         this. = gerritBuildFailedVerifiedValue;
         this. = gerritBuildFailedCodeReviewValue;
         this. = gerritBuildUnstableVerifiedValue;
         this. = gerritBuildUnstableCodeReviewValue;
         this. = gerritBuildNotBuiltVerifiedValue;
         this. = gerritBuildNotBuiltCodeReviewValue;
         this. = silentMode;
         this. = escapeQuotes;
         this. = buildStartMessage;
         this. = buildSuccessfulMessage;
         this. = buildUnstableMessage;
         this. = buildFailureMessage;
         this. = buildNotBuiltMessage;
         this. = buildUnsuccessfulFilepath;
         this. = customUrl;
         this. = triggerOnEvents;
         this. = dynamicTriggerConfiguration;
         this. = triggerConfigURL;
         this. = null;
     }

    
Converts old trigger configs when only patchset created was available as event. If no event selection is set to true, triggering on patchset created will be.

Returns:
the resolved instance.
Throws:
java.io.ObjectStreamException if something beneath goes wrong.
 
     public Object readResolve() throws ObjectStreamException {
         initializeTriggerOnEvents();
         return super.readResolve();
     }

    
Finds the GerritTrigger in a project.

Parameters:
project the project.
Returns:
the trigger if there is one, null otherwise.
 
     public static GerritTrigger getTrigger(AbstractProject project) {
         return (GerritTrigger)project.getTrigger(GerritTrigger.class);
     }

    
Cancels the timerTask, if it exists.
 
     public void cancelTimer() {
         if ( != null) {
             .trace("GerritTrigger.cancelTimer(): {0}".getName());
             .cancel();
              = null;
         }
     }
 
     @Override
     public void start(AbstractProject projectboolean newInstance) {
         .debug("Start project: {}"project);
         super.start(projectnewInstance);
         initializeTriggerOnEvents();
         this. = project;
         try {
             if (PluginImpl.getInstance() != null) {
                 PluginImpl.getInstance().addListener(this);
             } else {
                 .warn("The plugin instance could not be found! Project {} will not be triggered!",
                         project.getFullDisplayName());
             }
         } catch (IllegalStateException e) {
             .error("I am too early!"e);
         }
 
         // Create a new timer task if there is a URL
         if () {
              = new GerritTriggerTimerTask(this);
         }
     }
 
     @Override
     public void stop() {
         .debug("Stop");
         super.stop();
         try {
             if (PluginImpl.getInstance() != null) {
                 PluginImpl.getInstance().removeListener(this);
             }
         } catch (IllegalStateException e) {
             .error("I am too late!"e);
         }
 
         cancelTimer();
     }
 
     @Override
     public void gerritEvent(GerritEvent event) {
         //Default should do nothing
     }

    
Called when a PatchSetCreated event arrives.

Parameters:
event the event
 
     @Override
     public void gerritEvent(PatchsetCreated event) {
         .trace("event: {}"event);
         if (!.isBuildable()) {
             .trace("Disabled.");
             return;
         }
 
         if (isInteresting(event)) {
             .trace("The event is interesting.");
             if (!) {
                 ToGerritRunListener.getInstance().onTriggered(event);
             } else {
                 event.fireProjectTriggered();
             }
             GerritCause cause;
             if (event instanceof ManualPatchsetCreated) {
                 cause = new GerritManualCause((ManualPatchsetCreated)event);
             } else {
                 cause = new GerritCause(event);
             }
 
             schedule(causeevent);
         }
     }

    
Called when a DraftPublished event arrives.

Parameters:
event the event
 
     @Override
     public void gerritEvent(DraftPublished event) {
         .trace("event: {}"event);
         if (!.isBuildable()) {
             .trace("Disabled.");
             return;
         }
 
         if (isInteresting(event)) {
             .trace("The event is interesting.");
             if (!) {
                 ToGerritRunListener.getInstance().onTriggered(event);
             } else {
                 event.fireProjectTriggered();
             }
 
             schedule(new GerritCause(event), event);
         }
     }

    
Checks if we should trigger for the given event.

Parameters:
event the event to check for.
Returns:
true if we should trigger, false if not.
 
     private boolean shouldTriggerOnEventType(GerritTriggeredEvent event) {
         if ( == null || .isEmpty()) {
             return false;
         }
         for (PluginGerritEvent e : ) {
             if (e.getCorrespondingEventClass().isInstance(event)) {
                 return true;
             }
         }
         return false;
     }

    
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.
 
     protected void schedule(GerritCause causeGerritTriggeredEvent event) {
         schedule(causeevent);
     }

    
Schedules a build with parameters from the event.

Parameters:
cause the cause of the build.
event the event.
project the project to build.
 
     protected void schedule(GerritCause causeGerritTriggeredEvent eventAbstractProject project) {
         BadgeAction badgeAction = new BadgeAction(event);
             //during low traffic we still don't want to spam Gerrit, 3 is a nice number, isn't it?
         int projectbuildDelay = getBuildScheduleDelay();
         if (cause instanceof GerritUserCause) {
             // it's a manual trigger, no need for a quiet period
             projectbuildDelay = 0;
         } else if (project.getHasCustomQuietPeriod()
                 && project.getQuietPeriod() > projectbuildDelay) {
             projectbuildDelay = project.getQuietPeriod();
         }
         ParametersAction parameters = createParameters(eventproject);
         Future build = project.scheduleBuild2(
                 projectbuildDelay,
                 cause,
                 badgeAction,
                 new RetriggerAction(cause.getContext()),
                 new RetriggerAllAction(cause.getContext()),
                 parameters);
         //Experimental feature!
         if (event instanceof ChangeBasedEvent) {
             ChangeBasedEvent changeBasedEvent = (ChangeBasedEvent)event;
             if (PluginImpl.getInstance().getConfig().isGerritBuildCurrentPatchesOnly()) {
                 getRunningJobs().scheduled(changeBasedEventparametersproject.getName());
             }
             .info("Project {} Build Scheduled: {} By event: {}",
                     new Object[]{project.getName(), (build != null),
                             changeBasedEvent.getChange().getNumber() + "/"
                                     + changeBasedEvent.getPatchSet().getNumber(), });
         } else if (event instanceof RefUpdated) {
             RefUpdated refUpdated = (RefUpdated)event;
             .info("Project {} Build Scheduled: {} By event: {}",
                     new Object[]{project.getName(), (build != null),
                     refUpdated.getRefUpdate().getRefName() + " " + refUpdated.getRefUpdate().getNewRev(), });
         }
     }

    
Gives you runningJobs. It makes sure that the reference is not null.

Returns:
the store of running jobs.
 
     private synchronized RunningJobs getRunningJobs() {
         if ( == null) {
              = new RunningJobs();
         }
         return ;
     }

    
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:
event the event.
 
     public void notifyBuildEnded(GerritTriggeredEvent event) {
         //Experimental feature!
         if (event instanceof ChangeBasedEvent
                 && PluginImpl.getInstance().getConfig().isGerritBuildCurrentPatchesOnly()) {
             getRunningJobs().remove((ChangeBasedEvent)event);
         }
     }

    
getBuildScheduleDelay method will return configured buildScheduledelay value. If the value is missing or invalid it the method will return default schedule delay or com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritDefaultValues.DEFAULT_BUILD_SCHEDULE_DELAY.

Returns:
buildScheduleDelay.
 
     public int getBuildScheduleDelay() {
         if (PluginImpl.getInstance() == null || PluginImpl.getInstance().getConfig() == null) {
             return ;
         } else {
             int buildScheduleDelay = PluginImpl.getInstance().getConfig().getBuildScheduleDelay();
             if (buildScheduleDelay < ) {
                 return ;
             } else {
                 return buildScheduleDelay;
             }
         }
 
     }

    
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.
 
     protected ParametersAction createParameters(GerritTriggeredEvent eventAbstractProject project) {
         List<ParameterValueparameters = getDefaultParametersValues(project);
         setOrCreateParameters(eventparametersisEscapeQuotes());
         return new ParametersAction(parameters);
     }

    
Retrieves all default parameter values for a project. Copied from hudson.model.AbstractProject.getDefaultParametersValues() version 1.362. TODO: This is not a good way to solve the problem.

Parameters:
project the project.
Returns:
the default parameter values.
 
         ParametersDefinitionProperty paramDefProp =
                 (ParametersDefinitionProperty)project.getProperty(ParametersDefinitionProperty.class);
         List<ParameterValuedefValues = new ArrayList<ParameterValue>();
 
         /*
          * This check is made ONLY if someone calls this method even if isParametrized() is false.
          */
         if (paramDefProp == null) {
             return defValues;
         }
 
         /* Scan for all parameters with an associated default value */
         for (ParameterDefinition paramDefinition : paramDefProp.getParameterDefinitions()) {
             ParameterValue defaultValue = paramDefinition.getDefaultParameterValue();
 
             if (defaultValue != null) {
                 defValues.add(defaultValue);
             }
         }
 
         return defValues;
     }

    
Re-triggers the build in com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.TriggerContext.getThisBuild() for the context's event. Will not do any isInteresting(com.sonyericsson.hudson.plugins.gerrit.gerritevents.dto.events.GerritTriggeredEvent) 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.
 
     public void retriggerThisBuild(TriggerContext context) {
         if (context.getThisBuild().getProject().isBuildable()
                 && !ToGerritRunListener.getInstance().isBuilding(context.getThisBuild().getProject(),
                         context.getEvent())) {
 
             if (!) {
                 ToGerritRunListener.getInstance().onRetriggered(
                         context.getThisBuild().getProject(),
                         context.getEvent(),
                         context.getOtherBuilds());
             }
             final GerritUserCause cause = new GerritUserCause(context.getEvent(), );
             schedule(causecontext.getEvent(), context.getThisBuild().getProject());
         }
     }
 
     //CS IGNORE LineLength FOR NEXT 9 LINES. REASON: Javadoc see syntax.
 
    
Retriggers all builds in the given context. The builds will only be triggered if no builds for the event are building.

 
     public void retriggerAllBuilds(TriggerContext context) {
         if (!ToGerritRunListener.getInstance().isBuilding(context.getEvent())) {
             retrigger(context.getThisBuild().getProject(), context.getEvent());
             for (AbstractBuild build : context.getOtherBuilds()) {
                 GerritTrigger trigger = (GerritTrigger)build.getProject().getTrigger(GerritTrigger.class);
                 if (trigger != null) {
                     trigger.retrigger(build.getProject(), context.getEvent());
                 }
             }
         }
     }

    
Retriggers one build in a set of many.

Parameters:
project the project to retrigger.
event the event.
See also:
retriggerAllBuilds(com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data.TriggerContext)
 
     private void retrigger(AbstractProject projectGerritTriggeredEvent event) {
         if (project.isBuildable()) {
             if (!) {
                 ToGerritRunListener.getInstance().onRetriggered(projecteventnull);
             }
             GerritUserCause cause = new GerritUserCause(event);
             schedule(causeeventproject);
         }
     }
 
     @Override
     public int hashCode() {
         if ( == null) {
             return super.hashCode();
         } else {
             return .hashCode();
         }
     }
 
     @Override
     public boolean equals(Object obj) {
         if (obj instanceof GerritTrigger) {
             GerritTrigger that = (GerritTrigger)obj;
             return this. == that.myProject;
         }
         return false;
     }

    
Should we trigger on this event?

Parameters:
event the event
Returns:
true if we should.
 
     private boolean isInteresting(GerritTriggeredEvent event) {
         if (!shouldTriggerOnEventType(event)) {
             return false;
         }
         List<GerritProjectallGerritProjects = new LinkedList<GerritProject>();
         if ( != null) {
             allGerritProjects.addAll();
         }
         if ( != null) {
             allGerritProjects.addAll();
         }
         .trace("entering isInteresting projects configured: {} the event: {}"allGerritProjects.size(), event);
         for (GerritProject p : allGerritProjects) {
             try {
                 if (event instanceof ChangeBasedEvent) {
                     ChangeBasedEvent changeBasedEvent = (ChangeBasedEvent)event;
                     if (p.isInteresting(changeBasedEvent.getChange().getProject(),
                             changeBasedEvent.getChange().getBranch())) {
                         if (isFileTriggerEnabled() && p.getFilePaths() != null
                                 && p.getFilePaths().size() > 0) {
                             if (p.isInteresting(changeBasedEvent.getChange().getProject(),
                                     changeBasedEvent.getChange().getBranch(),
                                     changeBasedEvent.getFiles(
                                             new GerritQueryHandler(PluginImpl.getInstance().getConfig())))) {
                                 .trace("According to {} the event is interesting."p);
                                 return true;
                             }
                         } else {
                             .trace("According to {} the event is interesting."p);
                             return true;
                         }
                     }
                 } else if (event instanceof RefUpdated) {
                     RefUpdated refUpdated = (RefUpdated)event;
                     if (p.isInteresting(refUpdated.getRefUpdate().getProject(),
                             refUpdated.getRefUpdate().getRefName())) {
                         .trace("According to {} the event is interesting."p);
                         return true;
                     }
                 }
             } catch (PatternSyntaxException pse) {
                 .error(MessageFormat.format("Exception caught for project {0} and pattern {1}, message: {2}",
                        new Object[]{.getName(), p.getPattern(), pse.getMessage()}));
             }
         }
         .trace("Nothing interesting here, move along folks!");
         return false;
     }

    
Called when a ChangeAbandoned event arrives. Should probably not be listening on this here.

Parameters:
event the event.
 
     @Override
     public void gerritEvent(ChangeAbandoned event) {
         //TODO Implement
     }

    
Called when a ChangeMerged event arrives.

Parameters:
event the event.
 
     @Override
     public void gerritEvent(ChangeMerged event) {
         .trace("event: {}"event);
         if (!.isBuildable()) {
             .trace("Disabled.");
             return;
         }
         if (isInteresting(event)) {
             .trace("The event is interesting.");
             if (!) {
                 ToGerritRunListener.getInstance().onTriggered(event);
             }
             GerritCause cause = new GerritCause(event);
             schedule(causeevent);
         }
     }

    
Checks if the approvals associated with this comment-added event match what this trigger is configured to look for.

Parameters:
event the event.
Returns:
true if the event matches the approval category and value configured.
 
     private boolean matchesApproval(CommentAdded event) {
         PluginCommentAddedEvent commentAdded = null;
         for (PluginGerritEvent e : ) {
             if (e instanceof PluginCommentAddedEvent) {
                 commentAdded = (PluginCommentAddedEvent)e;
                 break;
             }
         }
         if (commentAdded == null) {
             return false;
         }
         for (Approval approval : event.getApprovals()) {
             if (approval.getType().equals(commentAdded.getVerdictCategory())
                     && (approval.getValue().equals(commentAdded.getCommentAddedTriggerApprovalValue())
                     || ("+" + approval.getValue()).equals(commentAdded.getCommentAddedTriggerApprovalValue()))) {
                 return true;
             }
         }
         return false;
     }

    
Called when a CommentAdded event arrives.

Parameters:
event the event.
 
     @Override
     public void gerritEvent(CommentAdded event) {
         .trace("event: {}"event);
         if (!.isBuildable()) {
             .trace("Disabled.");
             return;
         }
         if (ToGerritRunListener.getInstance().isBuilding(event)) {
             .trace("Already building.");
             return;
         }
         if (isInteresting(event) && matchesApproval(event)) {
             .trace("The event is interesting.");
             if (!) {
                 ToGerritRunListener.getInstance().onTriggered(event);
             }
             GerritCause cause = new GerritCause(event);
             schedule(causeevent);
         }
     }

    
Called when a RefUpdated event arrives.

Parameters:
event the event.
 
     @Override
     public void gerritEvent(RefUpdated event) {
         .trace("event: {}"event);
         if (!.isBuildable()) {
             .trace("Disabled.");
             return;
         }
         if (isInteresting(event)) {
             .trace("The event is interesting.");
             if (!) {
                 ToGerritRunListener.getInstance().onTriggered(event);
             }
             GerritCause cause = new GerritCause(event);
             schedule(causeevent);
         }
     }

    
The list of GerritProject triggering rules.

Returns:
the rule-set.
 
     public List<GerritProjectgetGerritProjects() {
         return ;
     }

    
The list of dynamically configured triggering rules.

Returns:
the rule-set.
 
         return ;
     }

    
The list of GerritProject triggering rules.

Parameters:
gerritProjects the rule-set
 
     public void setGerritProjects(List<GerritProjectgerritProjects) {
         this. = gerritProjects;
     }

    
Job specific Gerrit code review vote when a build is failed, null means that the global value should be used.

Returns:
the vote value.
 
         return ;
     }

    
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.
 
     public void setGerritBuildFailedCodeReviewValue(Integer gerritBuildFailedCodeReviewValue) {
         this. = gerritBuildFailedCodeReviewValue;
     }

    
Job specific Gerrit verified vote when a build is failed, null means that the global value should be used.

Returns:
the vote value.
 
         return ;
     }

    
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.
 
     public void setGerritBuildFailedVerifiedValue(Integer gerritBuildFailedVerifiedValue) {
         this. = gerritBuildFailedVerifiedValue;
     }

    
Job specific Gerrit code review vote when a build is started, null means that the global value should be used.

Returns:
the vote value.
 
         return ;
     }

    
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.
 
     public void setGerritBuildStartedCodeReviewValue(Integer gerritBuildStartedCodeReviewValue) {
         this. = gerritBuildStartedCodeReviewValue;
     }

    
Job specific Gerrit verified vote when a build is started, null means that the global value should be used.

Returns:
the vote value.
 
         return ;
     }

    
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.
 
     public void setGerritBuildStartedVerifiedValue(Integer gerritBuildStartedVerifiedValue) {
         this. = gerritBuildStartedVerifiedValue;
     }

    
Job specific Gerrit code review vote when a build is successful, null means that the global value should be used.

Returns:
the vote value.
 
         return ;
     }

    
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.
 
     public void setGerritBuildSuccessfulCodeReviewValue(Integer gerritBuildSuccessfulCodeReviewValue) {
         this. = gerritBuildSuccessfulCodeReviewValue;
     }

    
Job specific Gerrit verified vote when a build is successful, null means that the global value should be used.

Returns:
the vote value.
 
         return ;
     }

    
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.
 
     public void setGerritBuildSuccessfulVerifiedValue(Integer gerritBuildSuccessfulVerifiedValue) {
         this. = gerritBuildSuccessfulVerifiedValue;
     }

    
Job specific Gerrit code review vote when a build is unstable, null means that the global value should be used.

Returns:
the vote value.
 
         return ;
     }

    
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.
 
     public void setGerritBuildUnstableCodeReviewValue(Integer gerritBuildUnstableCodeReviewValue) {
         this. = gerritBuildUnstableCodeReviewValue;
     }

    
Job specific Gerrit verified vote when a build is unstable, null means that the global value should be used.

Returns:
the vote value.
 
         return ;
     }

    
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.
 
     public void setGerritBuildUnstableVerifiedValue(Integer gerritBuildUnstableVerifiedValue) {
         this. = gerritBuildUnstableVerifiedValue;
     }

    
Job specific Gerrit code review vote when a build is not built, null means that the global value should be used.

Returns:
the vote value.
 
         return ;
     }

    
Job specific Gerrit code review vote when a build is not built, providing null means that the global value should be used.

Parameters:
gerritBuildNotBuiltCodeReviewValue the vote value.
 
     public void setGerritBuildNotBuiltCodeReviewValue(Integer gerritBuildNotBuiltCodeReviewValue) {
         this. = gerritBuildNotBuiltCodeReviewValue;
     }

    
Job specific Gerrit verified vote when a build is not built, null means that the global value should be used.

Returns:
the vote value.
 
         return ;
     }

    
Job specific Gerrit verified vote when a build is not built, providing null means that the global value should be used.

Parameters:
gerritBuildNotBuiltVerifiedValue the vote value.
 
     public void setGerritBuildNotBuiltVerifiedValue(Integer gerritBuildNotBuiltVerifiedValue) {
         this. = gerritBuildNotBuiltVerifiedValue;
    }

    
Sets the path to a file that contains the unsuccessful Gerrit comment message.

Parameters:
path The unsuccessful message comment file path
    public void setBuildUnsuccessfulFilepath(String path) {
         = path;
    }

    
Getter for the triggerOnEvents list.

Returns:
the list.
        return ;
    }

    
Initializes the triggerOnEvents list. If it is empty or null, adds patch set created and draft published events (the latter only if supported by the current Gerrit version).
    private void initializeTriggerOnEvents() {
        if ( == null) {
             = new LinkedList<PluginGerritEvent>();
        }
        if (.isEmpty()) {
            .add(new PluginPatchsetCreatedEvent());
            if (isTriggerOnDraftPublishedEnabled()) {
                .add(new PluginDraftPublishedEvent());
            }
        }
    }

    
If trigger configuration should be fetched from a URL or not.

Returns:
true if trigger configuration should be fetched from a URL.
    public boolean isDynamicTriggerConfiguration() {
        return ;
    }

    
Set if dynamic trigger configuration should be enabled or not.

Parameters:
dynamicTriggerConfiguration true if dynamic trigger configuration should be enabled.
    public void setDynamicTriggerConfiguration(boolean dynamicTriggerConfiguration) {
        this. = dynamicTriggerConfiguration;
    }

    
The URL where the trigger configuration should be fetched from.

Returns:
the URL, or null if this feature is not used.
    public String getTriggerConfigURL() {
        return ;
    }

    
Set the URL where the trigger configuration should be fetched from.

Parameters:
triggerConfigURL the URL where the trigger configuration should be fetched from.
    public void setTriggerConfigURL(String triggerConfigURL) {
        this. = triggerConfigURL;
    }

    
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.
    public boolean isSilentMode() {
        return ;
    }

    
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.
    public boolean isEscapeQuotes() {
        return ;
    }

    
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.
    public void setEscapeQuotes(boolean escapeQuotes) {
        this. = escapeQuotes;
    }

    
The message to show users when a build starts, if custom messages are enabled.

Returns:
The build start message
    public String getBuildStartMessage() {
        return ;
    }

    
The message to show users when a build succeeds, if custom messages are enabled.

Returns:
The build successful message
        return ;
    }

    
The message to show users when a build is unstable, if custom messages are enabled.

Returns:
The build unstable message
    public String getBuildUnstableMessage() {
        return ;
    }

    
The message to show users when a build finishes, if custom messages are enabled.

Returns:
The build failure message
    public String getBuildFailureMessage() {
        return ;
    }

    
The message to show users when all builds are not built, if custom messages are enabled.

Returns:
The build not built message
    public String getBuildNotBuiltMessage() {
        return ;
    }

    
The path to a file that contains the unsuccessful Gerrit comment message.

Returns:
The unsuccessful message comment file path
        return ;
    }

    
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.
    public void setSilentMode(boolean silentMode) {
        this. = silentMode;
    }

    
URL to send in comment to gerrit.

Returns:
custom URL to post back to gerrit
    public String getCustomUrl() {
        return ;
    }

    
Set custom URL to post back to gerrit.

Parameters:
customUrl url to set
    public void setCustomUrl(String customUrl) {
        this. = customUrl;
    }

    
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.
    public boolean isFileTriggerEnabled() {
        return GerritVersionChecker.isCorrectVersion(..);
    }

    
This method is called by the timer thread at regular intervals. It fetches the URL, determines if the result is different than from the last fetch, and if so, replaces the current URL trigger configuration with the fetched one.
    public void updateTriggerConfigURL() {
        if ( == null) {
        }
        try {
             = GerritDynamicUrlProcessor.fetch();
        } catch (ParseException pe) {
            String logErrorMessage = MessageFormat.format(
                    "ParseException for project: {0} and URL: {1} Message: {2}",
                    new Object[]{.getName(), pe.getMessage()});
            .error(logErrorMessagepe);
            String triggerInformationMessage = MessageFormat.format(
                    "ParseException when fetching dynamic trigger url: {0}"pe.getMessage());
            .setErrorMessage(triggerInformationMessage);
        } catch (MalformedURLException mue) {
            String logErrorMessage = MessageFormat.format(
                    "MalformedURLException for project: {0} and URL: {1} Message: {2}",
                    new Object[]{.getName(), mue.getMessage()});
            .error(logErrorMessagemue);
            String triggerInformationMessage = MessageFormat.format(
                    "MalformedURLException when fetching dynamic trigger url: {0}"mue.getMessage());
            .setErrorMessage(triggerInformationMessage);
        } catch (IOException ioe) {
            String logErrorMessage = MessageFormat.format(
                    "IOException for project: {0} and URL: {1} Message: {2}",
                    new Object[]{.getName(), ioe.getMessage()});
            .error(logErrorMessageioe);
            String triggerInformationMessage = MessageFormat.format(
                    "IOException when fetching dynamic trigger url: {0}"ioe.getMessage());
            .setErrorMessage(triggerInformationMessage);
        }
    }

    
Convenience method for finding it out if triggering on draft published is enabled in the Gerrit version.

Returns:
true if triggering on draft published is enabled in the Gerrit version.
    public boolean isTriggerOnDraftPublishedEnabled() {
        return GerritVersionChecker.isCorrectVersion(..);
    }
    @Override
    public List<ActiongetProjectActions() {
        List<Actionlist = new LinkedList<Action>();
        list.add();
        return list;
    }

    
The Descriptor for the Trigger.
    @Extension
    public static final class DescriptorImpl extends TriggerDescriptor {

        
Checks that the provided parameter is an empty string or an integer.

        public FormValidation doEmptyOrIntegerCheck(
                @QueryParameter("value")
                final String value) {
            if (value == null || value.length() <= 0) {
                return FormValidation.ok();
            } else {
                try {
                    Integer.parseInt(value);
                    return FormValidation.ok();
                } catch (NumberFormatException e) {
                    return FormValidation.error(hudson.model.Messages.Hudson_NotANumber());
                }
            }
        }

        
Checks that the provided parameter is nonempty and a valid URL.

Parameters:
value the value.
Returns:
hudson.util.FormValidation.ok()
        public FormValidation doUrlCheck(
                @QueryParameter("value")
                final String value) {
            if (value == null || value.isEmpty()) {
                return FormValidation.error(Messages.EmptyError());
            }
            try {
                URL url = new URL(value); // Check for protocol errors
                url.toURI(); // Perform some extra checking
                return FormValidation.ok();
            } catch (java.net.MalformedURLException e) {
                return FormValidation.error(Messages.BadUrlError());
            } catch (java.net.URISyntaxException e) {
                return FormValidation.error(Messages.BadUrlError());
            }
        }

        
Default Constructor.
        public DescriptorImpl() {
            super(GerritTrigger.class);
        }
        @Override
        public boolean isApplicable(Item item) {
            return true;
        }
        @Override
        public String getDisplayName() {
            return Messages.TriggerDisplayName();
        }
        @Override
        public String getHelpFile() {
            return "/plugin/gerrit-trigger/help-whatIsGerritTrigger.html";
        }

        
Fills the verdict category drop-down list.

Returns:
a ListBoxModel for the drop-down list.
        public ListBoxModel doFillVerdictCategoryItems() {
            ListBoxModel m = new ListBoxModel();
            List<VerdictCategorylist = PluginImpl.getInstance().getConfig().getCategories();
            if (list != null && !list.isEmpty()) {
                for (VerdictCategory v : list) {
                    m.add(v.getVerdictDescription(), v.getVerdictValue());
                }
            }
            return m;
        }

        
A list of CompareTypes for the UI.

Returns:
A list of CompareTypes
        public CompareType[] getCompareTypes() {
            return CompareType.values();
        }
        
Convenience method for the jelly file, accessing the instance proved to be hard.

Returns:
true if file triggering is enabled in the gerrit version.
        public boolean isFileTriggerEnabled() {
            return GerritVersionChecker.isCorrectVersion(..);
        }

        
Getter for the list of PluginGerritEventDescriptors.

Returns:
the list.
            ExtensionList<PluginGerritEvent.PluginGerritEventDescriptorextensionList =
                    Hudson.getInstance().getExtensionList(PluginGerritEvent.PluginGerritEventDescriptor.class);
            return extensionList;
        }
    }

    
Class for maintaining and synchronizing the runningJobs info. Association between patches and the jobs that we're running for them.
    public class RunningJobs {
        private final HashMap<GerritTriggeredEventParametersActionrunningJobs =
                new HashMap<GerritTriggeredEventParametersAction>();

        
Does the needful after a build has been scheduled. I.e. cancelling the old build if configured to do so and removing and storing any references.

Parameters:
event the event triggering a new build.
parameters the parameters for the new build, used to find it later.
projectName the name of the current project for better logging.
        public synchronized void scheduled(ChangeBasedEvent eventParametersAction parametersString projectName) {
            if (!PluginImpl.getInstance().getConfig().isGerritBuildCurrentPatchesOnly()) {
                return;
            }
            while (it.hasNext()) {
                Entry<GerritTriggeredEventParametersActionpairs = it.next();
                // Find all entries in runningJobs with the same Change #.
                if (pairs.getKey() instanceof ChangeBasedEvent) {
                    if (((ChangeBasedEvent)pairs.getKey()).getChange().equals(event.getChange())) {
                        .debug("Cancelling build for " + pairs.getKey());
                        try {
                            cancelJob(pairs.getValue());
                        } catch (Exception e) {
                            // Ignore any problems with canceling the job.
                            .error("Error canceling job"e);
                        }
                        it.remove();
                    }
                }
            }
            // add our new job
            .