Class JobConfigHistoryRootAction

java.lang.Object
hudson.plugins.jobConfigHistory.JobConfigHistoryBaseAction
hudson.plugins.jobConfigHistory.JobConfigHistoryRootAction
All Implemented Interfaces:
ExtensionPoint, Action, ModelObject, RootAction

@ExportedBean(defaultVisibility=-1) @Extension public class JobConfigHistoryRootAction extends JobConfigHistoryBaseAction implements RootAction
Author:
Stefan Brausch, Mirko Friedenhagen
  • Constructor Details

    • JobConfigHistoryRootAction

      public JobConfigHistoryRootAction()
      Constructor necessary for testing.
  • Method Details

    • getUrlName

      public final String getUrlName()

      This actions always starts from the context directly, so prefix JobConfigHistoryConsts.URLNAME with a slash.

      Specified by:
      getUrlName in interface Action
      Overrides:
      getUrlName in class JobConfigHistoryBaseAction
    • getIconFileName

      public final String getIconFileName()

      Make method final, as we always want the same icon file. Returns null to hide the icon if the user is not allowed to configure jobs.

      Specified by:
      getIconFileName in interface Action
    • getConfigs

      @Exported(visibility=1) public final List<ConfigInfo> getConfigs() throws IOException
      Returns the configuration history entries for either AbstractItem s or system changes or deleted jobs or all of the above.
      Returns:
      list of configuration histories (as ConfigInfo)
      Throws:
      IOException - if one of the history entries might not be read.
    • getConfigs

      public final List<ConfigInfo> getConfigs(int from, int to) throws IOException
      Calculates a list containing the .subList(from, to) of the newest-first list of job config revision entries. Does not read the history.xmls unless it is inevitable. Since filter=created requires to read the history.xml of each revision which makes paging pointless from a performance and usability perspective, all configs are returned in that case.
      Parameters:
      from - the first revision to display
      to - the first revision not to display anymore
      Returns:
      a list equivalent to getJobConfigs().subList(from, to) (except for filter=created), but more efficiently calculated.
      Throws:
      IOException
    • getSystemConfigs

      public List<ConfigInfo> getSystemConfigs()
      Returns the configuration history entries for all system files in this Jenkins instance.
      Returns:
      List of config infos.
    • getJobConfigs

      public List<ConfigInfo> getJobConfigs(String type) throws IOException
      Returns the configuration history entries for all jobs or deleted jobs in this Jenkins instance.
      Parameters:
      type - Whether we want to see all jobs or just the deleted jobs.
      Returns:
      List of config infos.
      Throws:
      IOException - if one of the history entries might not be read.
    • getSingleConfigs

      public final List<ConfigInfo> getSingleConfigs(String name) throws IOException
      Returns the configuration history entries for one group of system files or deleted jobs.
      Parameters:
      name - of the item.
      Returns:
      Configs list for one group of system configuration files.
      Throws:
      IOException - if one of the history entries might not be read.
    • getSingleConfigs

      public final List<ConfigInfo> getSingleConfigs(String name, int from, int to)
      Parameters:
      name - of the item
      from - the first revision to display
      to - the first revision not to display anymore
      Returns:
      the same as getSingleConfigs(String), but cut for paging.
    • getRevisionAmount

      public int getRevisionAmount()
      Specified by:
      getRevisionAmount in class JobConfigHistoryBaseAction
      Returns:
      the amount of revisions existing for the given request (not page-dependant).
    • getFile

      public final String getFile() throws IOException
      Returns:
      content of the config.xml found in directory given by the request parameter file.
      Throws:
      IOException - if the config file could not be read or converted to an xml string.
    • createLinkToFiles

      public final String createLinkToFiles(ConfigInfo config, String type)
      Creates links to the correct configOutput.jelly for job history vs. system history and for xml vs. plain text.
      Parameters:
      config - ConfigInfo.
      type - Output type ('xml' or 'plain').
      Returns:
      The link as String.
    • getAccessControlledObject

      public AccessControlled getAccessControlledObject()
      Description copied from class: JobConfigHistoryBaseAction
      Returns the object for which we want to provide access control.
      Specified by:
      getAccessControlledObject in class JobConfigHistoryBaseAction
      Returns:
      the access controlled object.
    • checkConfigurePermission

      public void checkConfigurePermission()
      Description copied from class: JobConfigHistoryBaseAction
      See whether the current user may read configurations in the object returned by JobConfigHistoryBaseAction.getAccessControlledObject().
      Specified by:
      checkConfigurePermission in class JobConfigHistoryBaseAction
    • checkDeleteEntryPermission

      protected void checkDeleteEntryPermission()
      Specified by:
      checkDeleteEntryPermission in class JobConfigHistoryBaseAction
    • hasAdminPermission

      public boolean hasAdminPermission()
      Specified by:
      hasAdminPermission in class JobConfigHistoryBaseAction
    • hasDeleteEntryPermission

      public boolean hasDeleteEntryPermission()
      Specified by:
      hasDeleteEntryPermission in class JobConfigHistoryBaseAction
    • hasConfigurePermission

      public boolean hasConfigurePermission()
      Description copied from class: JobConfigHistoryBaseAction
      Returns whether the current user may read configurations in the object returned by JobConfigHistoryBaseAction.getAccessControlledObject().
      Specified by:
      hasConfigurePermission in class JobConfigHistoryBaseAction
      Returns:
      true if the current user may read configurations.
    • hasJobConfigurePermission

      public boolean hasJobConfigurePermission()
      Returns whether the current user may configure jobs.
      Returns:
      true if the current user may configure jobs.
    • hasReadExtensionPermission

      public boolean hasReadExtensionPermission()
      Returns whether the current user may read configure jobs.
      Returns:
      true if the current user may read configure jobs.
    • doDiffFiles

      public final 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.
      Overrides:
      doDiffFiles in class JobConfigHistoryBaseAction
      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.
    • getLines

      public final List<SideBySideView.Line> getLines(boolean hideVersionDiffs) throws IOException
      Takes the two timestamp request parameters and returns the diff between the corresponding config files of this project as a list of single lines. Filters lines that contain plugin version information.
      Specified by:
      getLines in class JobConfigHistoryBaseAction
      Parameters:
      hideVersionDiffs - determines whether lines that match the ignoredLinesPattern shall be hidden 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.
    • checkXmlSyntax

      public XmlSyntaxChecker.Answer checkXmlSyntax(String name, String timestamp)
    • getTimestamp

      public final String getTimestamp(int timestampNumber)
      Used in the Difference jelly only. Returns one of the two timestamps that have been passed to the Difference page as parameter. timestampNumber must be 1 or 2.
      Parameters:
      timestampNumber - 1 for timestamp1 and 2 for timestamp2
      Returns:
      the timestamp as String.
    • getOldConfigXml

      public XmlFile getOldConfigXml(String name, String timestamp)
      Gets the version of the config.xml that was saved at a certain time.
      Parameters:
      name - The name of the system property or deleted job.
      timestamp - The timestamp as String.
      Returns:
      The config file as XmlFile.
    • checkParameters

      public boolean checkParameters(String name, String timestamp)
      Checks the url parameters 'name' and 'timestamp' and returns true if they are neither null nor suspicious.
      Parameters:
      name - Name of deleted job or system property.
      timestamp - Timestamp of config change.
      Returns:
      True if parameters are okay.
    • doRestore

      @POST public final void doRestore(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException
      Action when 'restore' button is pressed: Restore deleted project.
      Parameters:
      req - Incoming StaplerRequest
      rsp - Outgoing StaplerResponse
      Throws:
      IOException - If something goes wrong
    • getLastAvailableConfigXml

      public XmlFile getLastAvailableConfigXml(String name)
      Retrieves the last or second to last config.xml. The latter is necessary when the last config.xml is missing although the history entry exists, which happens when a project is deleted while being disabled.
      Parameters:
      name - The name of the deleted project.
      Returns:
      The last or second to last config as XmlFile or null.
    • findNewName

      public String findNewName(String name)
      Finds a name for the project to be restored. If the old name is already in use by another project, "_" plus a number is appended to the name until an unused name is found.
      Parameters:
      name - The old name as String.
      Returns:
      the new name as String.
    • doForwardToRestoreQuestion

      public final void doForwardToRestoreQuestion(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException
      Action when 'restore' button in history.jelly is pressed. Gets required parameter and forwards to restoreQuestion.jelly.
      Parameters:
      req - StaplerRequest created by pressing the button
      rsp - Outgoing StaplerResponse
      Throws:
      IOException - If redirect goes wrong
    • doDeleteRevision

      @POST public final void doDeleteRevision(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
    • getHistoryDao

      protected HistoryDao getHistoryDao()
      For tests.
      Overrides:
      getHistoryDao in class JobConfigHistoryBaseAction
      Returns:
      historyDao
    • getOverviewHistoryDao

      protected OverviewHistoryDao getOverviewHistoryDao()
      For tests.
      Returns:
      historyDao
    • getApi

      public Api getApi()
    • getLeadingWhitespace

      public int getLeadingWhitespace(String str)