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().
    • 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.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws jakarta.servlet.ServletException, IOException
      Parses the incoming POST request and redirects as GET showDiffFiles.
      Parameters:
      req - incoming request
      rsp - outgoing response
      Throws:
      jakarta.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.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException
      Action when 'Prev' or 'Next' button in showDiffFiles.jelly is pressed. Forwards to the previous or next diff.
      Parameters:
      req - StaplerRequest2 created by pressing the button
      rsp - Outgoing StaplerResponse2
      Throws:
      IOException - If XML file can't be read
    • getCurrentRequest

      protected org.kohsuke.stapler.StaplerRequest2 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
    • getStringFromXmlFile

      public static String getStringFromXmlFile(XmlFile xmlFile, boolean redactSecrets) throws IOException
      Converts an XmlFile to its string representation, optionally redacting secrets. If redaction is enabled and the user lacks configure permission, sensitive information will be masked using ExtendedReadRedaction.applyAll(String). Otherwise, the raw XML content is returned.
      Parameters:
      xmlFile - the XML file to convert to string. Can be null.
      redactSecrets - whether to apply extended read redaction to the XML content
      Returns:
      the string representation of the XML file, or an empty string if xmlFile is null. If redactSecrets is true, sensitive values will be masked.
      Throws:
      IOException - if the XML file content cannot be read or converted to a string
    • getLines

      protected final List<SideBySideView.Line> getLines(XmlFile leftConfig, XmlFile rightConfig, boolean hideVersionDiffs, boolean redactSecrets) 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
      hideVersionDiffs - determines whether version diffs shall be shown or not.
      redactSecrets - determines whether secrets should be redacted in the diff or not.
      Returns:
      Differences between two config versions as list of lines.
      Throws:
      IOException - If diff doesn't work or xml files can't be read.