Class FileHistoryDao

java.lang.Object
hudson.plugins.jobConfigHistory.JobConfigHistoryStrategy
hudson.plugins.jobConfigHistory.FileHistoryDao
All Implemented Interfaces:
ExtensionPoint, Describable<JobConfigHistoryStrategy>, HistoryDao, ItemListenerHistoryDao, NodeListenerHistoryDao, OverviewHistoryDao, Purgeable

@Extension public class FileHistoryDao extends JobConfigHistoryStrategy implements Purgeable
Defines some helper functions needed by JobConfigHistoryJobListener and JobConfigHistorySaveableListener.
Author:
Mirko Friedenhagen
  • Constructor Details

    • 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 Details

    • 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.
    • createNewItem

      public void createNewItem(Item item)
      Description copied from interface: ItemListenerHistoryDao
      Adds and saves the initial configuration of an item.
      Specified by:
      createNewItem in interface ItemListenerHistoryDao
      Parameters:
      item - project
    • 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
    • deleteItem

      public void deleteItem(Item item)
      Description copied from interface: ItemListenerHistoryDao
      Deletes the history of an item.
      Specified by:
      deleteItem in interface ItemListenerHistoryDao
      Parameters:
      item - project
    • changeItemLocation

      public void changeItemLocation(Item item, String oldFullName, String newFullName)
      Description copied from interface: ItemListenerHistoryDao
      Changes the item's history's location.
      Specified by:
      changeItemLocation in interface ItemListenerHistoryDao
      Parameters:
      item - project
      oldFullName - old full name
      newFullName - new full name
    • renameItem

      public void renameItem(Item item, String oldName, String newName)
      Description copied from interface: ItemListenerHistoryDao
      Save and renames the item.
      Specified by:
      renameItem in interface ItemListenerHistoryDao
      Parameters:
      item - project
      oldName - old project name
      newName - new name
    • getRevisions

      public SortedMap<String,HistoryDescr> getRevisions(XmlFile xmlFile)
      Description copied from interface: HistoryDao
      Returns a sorted map of all revisions for this xmlFile.

      The key is an identifier which may be used in HistoryDao.getOldRevision(hudson.model.AbstractItem, java.lang.String)

      Specified by:
      getRevisions in interface HistoryDao
      Parameters:
      xmlFile - file
      Returns:
      old revisions mapped to the identifier.
    • 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.
    • getSystemRevisionAmount

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

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

      public int getDeletedJobAmount()
      Specified by:
      getDeletedJobAmount in interface OverviewHistoryDao
      Returns:
      the total number of deleted Jobs.
    • 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
    • deleteRevision

      public void deleteRevision(Node node, String identifier)
      Specified by:
      deleteRevision in interface HistoryDao
    • deleteRevision

      public void deleteRevision(File historyDir, String identifier)
      Specified by:
      deleteRevision in interface HistoryDao
    • revisionEqualsCurrent

      public boolean revisionEqualsCurrent(AbstractItem project, String identifier1)
      Specified by:
      revisionEqualsCurrent in interface HistoryDao
    • revisionEqualsCurrent

      public boolean revisionEqualsCurrent(Node node, String identifier1)
      Specified by:
      revisionEqualsCurrent in interface HistoryDao
    • 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.
    • getSystemConfigsMap

      public SortedMap<String,HistoryDescr> getSystemConfigsMap()
      Specified by:
      getSystemConfigsMap in interface OverviewHistoryDao
      Returns:
      a map mapping timestamps to historydescrs. Contains all system config revision entries.
    • getJobHistory

      public SortedMap<String,HistoryDescr> getJobHistory(String jobName)
      Description copied from interface: OverviewHistoryDao
      Returns a sorted map of all HistoryDescr for a given job.
      Specified by:
      getJobHistory in interface OverviewHistoryDao
      Parameters:
      jobName - of the job
      Returns:
      sorted map.
    • getSystemHistory

      public SortedMap<String,HistoryDescr> getSystemHistory(String name)
      Description copied from interface: OverviewHistoryDao
      Returns a sorted map of all HistoryDescr for a given system configuration.
      Specified by:
      getSystemHistory in interface OverviewHistoryDao
      Parameters:
      name - of the configuration
      Returns:
      sorted map.
    • copyHistoryAndDelete

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

      public void createNewNode(Node node)
      Description copied from interface: NodeListenerHistoryDao
      Adds and saves the initial configuration of a node.
      Specified by:
      createNewNode in interface NodeListenerHistoryDao
      Parameters:
      node - node
    • deleteNode

      public void deleteNode(Node node)
      Description copied from interface: NodeListenerHistoryDao
      Deletes the history of a node.
      Specified by:
      deleteNode in interface NodeListenerHistoryDao
      Parameters:
      node - node
    • renameNode

      public void renameNode(Node node, String oldName, String newName)
      Description copied from interface: NodeListenerHistoryDao
      Save and renames the node.
      Specified by:
      renameNode in interface NodeListenerHistoryDao
      Parameters:
      node - node
      oldName - old node name
      newName - new name
    • getRevisions

      public SortedMap<String,HistoryDescr> getRevisions(Node node)
      Description copied from interface: HistoryDao
      Returns a sorted map of all revisions for this node.

      The key is an identifier which may be used in HistoryDao.getOldRevision(hudson.model.Node, java.lang.String)

      Specified by:
      getRevisions in interface HistoryDao
      Parameters:
      node - node
      Returns:
      old revisions mapped to the identifier.
    • 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.