Class FileHistoryDao

    • Constructor Detail

      • FileHistoryDao

        public FileHistoryDao()
      • FileHistoryDao

        public FileHistoryDao​(File historyRootDir,
                              File jenkinsHome,
                              MimickedUser currentUser,
                              int maxHistoryEntries,
                              boolean saveDuplicates)
        Parameters:
        historyRootDir - where to store history
        jenkinsHome - JENKINS_HOME
        currentUser - of operation
        maxHistoryEntries - max number of history entries
        saveDuplicates - should we save duplicate entries?
    • Method Detail

      • getConfigFile

        public static File getConfigFile​(File historyDir)
        Returns the configuration data file stored in the specified history directory. It looks for a file with an 'xml' extension that is not named JobConfigHistoryConsts.HISTORY_FILE.

        Relies on the assumption that random '.xml' files will not appear in the history directories.

        Checks that we are in an actual 'history directory' to prevent use for getting random xml files.

        Parameters:
        historyDir - The history directory to look under.
        Returns:
        The configuration file or null if no file is found.
      • saveItem

        public void saveItem​(XmlFile file)
        Description copied from interface: HistoryDao
        Saves a copy of a xml file.
        Specified by:
        saveItem in interface HistoryDao
        Parameters:
        file - xmlFile
      • getRevisionAmount

        public int getRevisionAmount​(XmlFile xmlFile)
        Specified by:
        getRevisionAmount in interface HistoryDao
        Parameters:
        xmlFile - the config's history xml file
        Returns:
        the amount of revision entries of a certain config.
      • getSystemRevisionAmount

        public int getSystemRevisionAmount​(String sysConfigName)
        Specified by:
        getSystemRevisionAmount in interface OverviewHistoryDao
        Returns:
        the number of configuration revision entries for a certain system config.
      • getJobRevisionAmount

        public int getJobRevisionAmount()
        Specified by:
        getJobRevisionAmount in interface OverviewHistoryDao
        Returns:
        the total number of job configuration revision entries.
      • getJobRevisionAmount

        public int getJobRevisionAmount​(String jobName)
        Specified by:
        getJobRevisionAmount in interface OverviewHistoryDao
        Returns:
        the number of configuration revision entries for a certain system config.
      • getTotalRevisionAmount

        public int getTotalRevisionAmount()
        Specified by:
        getTotalRevisionAmount in interface OverviewHistoryDao
        Returns:
        the total number of configuration revision entries, excluding agent config entries - TODO future work.
      • getOldRevision

        public XmlFile getOldRevision​(AbstractItem item,
                                      String identifier)
        Description copied from interface: HistoryDao
        Returns one old configuration of item.
        Specified by:
        getOldRevision in interface HistoryDao
        Parameters:
        item - project
        identifier - timestamp or hash
        Returns:
        old configuration.
      • getOldRevision

        public XmlFile getOldRevision​(XmlFile xmlFile,
                                      String identifier)
        Description copied from interface: HistoryDao
        Returns one old configuration of xmlFile.
        Specified by:
        getOldRevision in interface HistoryDao
        Parameters:
        xmlFile - file
        identifier - timestamp or hash
        Returns:
        old configuration.
      • getOldRevision

        public XmlFile getOldRevision​(String configFileName,
                                      String identifier)
        Description copied from interface: HistoryDao
        Returns one old configuration of file.
        Specified by:
        getOldRevision in interface HistoryDao
        Parameters:
        configFileName - file
        identifier - timestamp or hash
        Returns:
        old configuration.
      • deleteRevision

        public void deleteRevision​(AbstractItem abstractItem,
                                   String identifier)
        Description copied from interface: HistoryDao
        Permanently delete the given revision.
        Specified by:
        deleteRevision in interface HistoryDao
        Parameters:
        abstractItem - item
        identifier - timestamp or hash
      • hasOldRevision

        public boolean hasOldRevision​(XmlFile xmlFile,
                                      String identifier)
        Description copied from interface: HistoryDao
        Returns whether the revision exists.
        Specified by:
        hasOldRevision in interface HistoryDao
        Parameters:
        xmlFile - file
        identifier - timestamp or hash
        Returns:
        old configuration.
      • getHistoryDir

        public File getHistoryDir​(File configFile)
        Returns the configuration history directory for the given configuration file.
        Parameters:
        configFile - The configuration file whose content we are saving.
        Returns:
        The base directory where to store the history, or null if the file is not a valid Jenkins configuration file.
      • purgeOldEntries

        public void purgeOldEntries​(File itemHistoryRoot,
                                    int maxEntries)
        Description copied from interface: Purgeable
        Purges entries when there are more entries than specified by max entries.

        The purge will drop old entries according to:

        sort(entries, e.timestamp()); for (int i = maxEntries; i < entries.length(); i++) drop(entries[i]);

        Specified by:
        purgeOldEntries in interface Purgeable
        Parameters:
        itemHistoryRoot - the history root to drop entries from.
        maxEntries - the maximum number of entries to retain.
      • isCreatedEntry

        public boolean isCreatedEntry​(File historyDir)
        Description copied from interface: Purgeable
        Determines whether the specified directory should be dropped or not.
        Specified by:
        isCreatedEntry in interface Purgeable
        Parameters:
        historyDir - the directory to check against.
        Returns:
        true if it can be deleted, false otherwise.
      • getDeletedJobs

        public File[] getDeletedJobs()
        Description copied from interface: OverviewHistoryDao
        Returns a list of deleted jobs with a history, including all those contained in folders.
        Specified by:
        getDeletedJobs in interface OverviewHistoryDao
        Returns:
        list of deleted jobs with a history, empty when no history exists.
      • getDeletedJobs

        public File[] getDeletedJobs​(String folderName)
        Description copied from interface: OverviewHistoryDao
        Returns a list of deleted jobs with a history.
        Specified by:
        getDeletedJobs in interface OverviewHistoryDao
        Parameters:
        folderName - name of folder.
        Returns:
        list of deleted jobs with a history, empty when no history exists.
      • getJobs

        public File[] getJobs()
        Description copied from interface: OverviewHistoryDao
        Returns a list of jobs with a history, including all those contained in folders.
        Specified by:
        getJobs in interface OverviewHistoryDao
        Returns:
        list of all jobs with a history, empty when no history exists.
      • getJobs

        public File[] getJobs​(String folderName)
        Description copied from interface: OverviewHistoryDao
        Returns a list of jobs with a history.
        Specified by:
        getJobs in interface OverviewHistoryDao
        Parameters:
        folderName - name of folder
        Returns:
        list of jobs with a history, empty when no history exists.
      • getSystemConfigs

        public File[] getSystemConfigs()
        Description copied from interface: OverviewHistoryDao
        Returns a list of all system configuration files with a history.
        Specified by:
        getSystemConfigs in interface OverviewHistoryDao
        Returns:
        list of all system configuration files with a history, empty when no history exists.
      • copyHistoryAndDelete

        @Deprecated
        public void copyHistoryAndDelete​(String oldName,
                                         String newName)
        Deprecated.
      • hasDuplicateHistory

        public boolean hasDuplicateHistory​(Node node)
        Determines whether the given node has already been recorded in the history.
        Specified by:
        hasDuplicateHistory in interface HistoryDao
        Parameters:
        node - the node to check for duplicate history.
        Returns:
        true if the node is a duplicate, false otherwise.
      • saveNode

        public void saveNode​(Node node)
        Description copied from interface: HistoryDao
        Saves the current configuration of a node.
        Specified by:
        saveNode in interface HistoryDao
        Parameters:
        node - node
      • getOldRevision

        public XmlFile getOldRevision​(Node node,
                                      String identifier)
        Description copied from interface: HistoryDao
        Returns one old configuration of node.
        Specified by:
        getOldRevision in interface HistoryDao
        Parameters:
        node - node
        identifier - timestamp or hash
        Returns:
        old configuration.
      • hasOldRevision

        public boolean hasOldRevision​(Node node,
                                      String identifier)
        Description copied from interface: HistoryDao
        Returns whether the revision exists.
        Specified by:
        hasOldRevision in interface HistoryDao
        Parameters:
        node - node
        identifier - timestamp or hash
        Returns:
        old configuration.