Class JobConfigHistoryBaseAction

java.lang.Object
hudson.plugins.jobConfigHistory.JobConfigHistoryBaseAction
All Implemented Interfaces:
Action, ModelObject
Direct Known Subclasses:
ComputerConfigHistoryAction, JobConfigHistoryProjectAction, JobConfigHistoryRootAction

public abstract class JobConfigHistoryBaseAction extends Object implements Action
Implements some basic methods needed by the JobConfigHistoryRootAction and JobConfigHistoryProjectAction.
Author:
Mirko Friedenhagen
  • Constructor Details

    • JobConfigHistoryBaseAction

      public JobConfigHistoryBaseAction()
  • Method Details

    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in interface Action
      Specified by:
      getDisplayName in interface ModelObject
    • getUrlName

      public String getUrlName()
      Specified by:
      getUrlName in interface Action
    • getOutputType

      public final String getOutputType()
      Returns how the config file should be formatted in configOutput.jelly: as plain text or xml.
      Returns:
      "plain" or "xml"
    • checkTimestamp

      protected boolean checkTimestamp(String timestamp)
      Checks the url parameter 'timestamp' and returns true if it is parseable as a date.
      Parameters:
      timestamp - Timestamp of config change.
      Returns:
      True if timestamp is okay.
    • getRequestParameter

      protected String getRequestParameter(String parameterName)
      Returns the parameter named parameterName from current request.
      Parameters:
      parameterName - name of the parameter.
      Returns:
      value of the request parameter or null if it does not exist.
    • checkConfigurePermission

      protected abstract void checkConfigurePermission()
      See whether the current user may read configurations in the object returned by getAccessControlledObject().
    • hasAdminPermission

      public abstract boolean hasAdminPermission()
    • hasDeleteEntryPermission

      public abstract boolean hasDeleteEntryPermission()
    • checkDeleteEntryPermission

      protected abstract void checkDeleteEntryPermission()
    • hasConfigurePermission

      protected abstract boolean hasConfigurePermission()
      Returns whether the current user may read configurations in the object returned by getAccessControlledObject().
      Returns:
      true if the current user may read configurations.
    • getRevisionAmount

      public abstract int getRevisionAmount()
      Returns:
      the amount of revisions existing for the given request (not page-dependant).
    • getAccessControlledObject

      protected abstract AccessControlled getAccessControlledObject()
      Returns the object for which we want to provide access control.
      Returns:
      the access controlled object.
    • getDiffLines

      public final List<SideBySideView.Line> getDiffLines(List<String> diffLines)
      Returns side-by-side (i.e. human-readable) diff view lines.
      Parameters:
      diffLines - Unified diff as list of Strings.
      Returns:
      Nice and clean diff as list of single Lines. if reading one of the config files does not succeed.
    • getDiffAsString

      protected final String getDiffAsString(File file1, File file2, String[] file1Lines, String[] file2Lines)
      Returns a unified diff between two string arrays.
      Parameters:
      file1 - first config file.
      file2 - second config file.
      file1Lines - the lines of the first file.
      file2Lines - the lines of the second file.
      Returns:
      unified diff
    • getShowVersionDiffs

      public String getShowVersionDiffs()
      Get the current request's 'showVersionDiffs'-parameter. If there is none, "True" is returned.
      Returns:
      true if the current request has set this parameter to true or not at all.
      false else
    • getLines

      public final List<SideBySideView.Line> getLines() throws IOException
      Returns the diff between two config files as a list of single lines. Takes the two timestamps and the name of the system property or the deleted job from the url parameters.
      Returns:
      Differences between two config versions as list of lines.
      Throws:
      IOException - If diff doesn't work or xml files can't be read.
    • getLines

      public abstract List<SideBySideView.Line> getLines(boolean useRegex) throws IOException
      Throws:
      IOException
    • getDiffAsString

      protected final String getDiffAsString(File file1, File file2, String[] file1Lines, String[] file2Lines, boolean hideVersionDiffs)
      Returns a unified diff between two string arrays representing an xml file. The order of elements in the xml file is NOT ignored.
      Parameters:
      file1 - first config file.
      file2 - second config file.
      file1Lines - the lines of the first file.
      file2Lines - the lines of the second file.
      hideVersionDiffs - determines whether version diffs shall be shown or not.
      Returns:
      unified diff
    • getRelevantPageNums

      public List<Integer> getRelevantPageNums(int currentPageNum)
      Parameters:
      currentPageNum - the current page number
      Returns:
      the same as getRelevantPageNums(int, int), using getMaxPageNum() as second parameter.
    • getRelevantPageNums

      public List<Integer> getRelevantPageNums(int currentPageNum, int maxPageNum)
      Parameters:
      currentPageNum - the current page number
      maxPageNum - the highest page number
      Returns:
      a list representing all page navigation entries which are displayed. These include:
      • 0
      • maxPageNum
      • all integers in {k in [currentPageNum - PAGING_EPSILON, currentPageNum + PAGING_EPSILON] | k > 0 && k < maxPageNum}.
    • getMaxEntriesPerPage

      public int getMaxEntriesPerPage()
      Returns:
      the configured maximum entries per page.
    • getMaxPageNum

      public int getMaxPageNum()
      Returns:
      the maximum page number given this request's number of entries per page and the revision amount.
    • doDiffFiles

      public void doDiffFiles(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws javax.servlet.ServletException, IOException
      Parses the incoming POST request and redirects as GET showDiffFiles.
      Parameters:
      req - incoming request
      rsp - outgoing response
      Throws:
      javax.servlet.ServletException - when parsing the request as MultipartFormDataParser does not succeed.
      IOException - when the redirection does not succeed.
    • doDiffFilesPrevNext

      public final void doDiffFilesPrevNext(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException
      Action when 'Prev' or 'Next' button in showDiffFiles.jelly is pressed. Forwards to the previous or next diff.
      Parameters:
      req - StaplerRequest created by pressing the button
      rsp - Outgoing StaplerResponse
      Throws:
      IOException - If XML file can't be read
    • getCurrentRequest

      protected org.kohsuke.stapler.StaplerRequest getCurrentRequest()
      Overridable for tests.
      Returns:
      current request
    • getPlugin

      protected JobConfigHistory getPlugin()
      Returns the plugin for tests.
      Returns:
      plugin
    • getHistoryDao

      protected HistoryDao getHistoryDao()
      For tests.
      Returns:
      historyDao
    • getLines

      protected final List<SideBySideView.Line> getLines(XmlFile leftConfig, XmlFile rightConfig, boolean hideVersionDiffs) throws IOException
      Takes the two config files and returns the diff between them as a list of single lines.
      Parameters:
      leftConfig - first config file
      rightConfig - second config file
      Returns:
      Differences between two config versions as list of lines.
      Throws:
      IOException - If diff doesn't work or xml files can't be read.