Class 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>
    • Field Detail

      • ORDINAL

        public static final int ORDINAL
        The ordering of this extension.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ToGerritRunListener

        public ToGerritRunListener()
    • 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
      • 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.
      • 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.
      • 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 by Run.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)
      • 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 project
        event - 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 the workspace for files matching the filepath glob.
        Parameters:
        ws - The workspace
        filepath - The filepath glob pattern
        Returns:
        List of matching FilePaths. Guaranteed to be non-null.
        Throws:
        IOException - if an error occurs while reading the workspace
        InterruptedException - if an error occurs while reading the workspace
      • getExpandedContent

        protected String getExpandedContent​(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 file
        InterruptedException - if an error occurs while checking the status of the file