Class JobConfigHistoryRootAction

  • All Implemented Interfaces:
    hudson.ExtensionPoint, hudson.model.Action, hudson.model.ModelObject, hudson.model.RootAction

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

      • JobConfigHistoryRootAction

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

      • 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 hudson.model.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()
                                          throws IOException
        Returns the configuration history entries for all system files in this Jenkins instance.
        Returns:
        List of config infos.
        Throws:
        IOException - if one of the history entries might not be read.
      • 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.
      • 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.
      • 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.
      • 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 hudson.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

        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 hudson.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

        public final void doDeleteRevision​(org.kohsuke.stapler.StaplerRequest req,
                                           org.kohsuke.stapler.StaplerResponse rsp)
      • getOverviewHistoryDao

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

        public hudson.model.Api getApi()
      • getLeadingWhitespace

        public int getLeadingWhitespace​(String str)