Package hudson.plugins.jobConfigHistory
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 byJobConfigHistoryJobListener
andJobConfigHistorySaveableListener
.- Author:
- Mirko Friedenhagen
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Constructor Summary
Constructors Constructor Description FileHistoryDao()
FileHistoryDao(File historyRootDir, File jenkinsHome, MimickedUser currentUser, int maxHistoryEntries, boolean saveDuplicates)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
changeItemLocation(Item item, String oldFullName, String newFullName)
Changes the item's history's location.void
copyHistoryAndDelete(String oldName, String newName)
Deprecated.void
createNewItem(Item item)
Adds and saves the initial configuration of an item.void
createNewNode(Node node)
Adds and saves the initial configuration of a node.void
deleteItem(Item item)
Deletes the history of an item.void
deleteNode(Node node)
Deletes the history of a node.void
deleteRevision(AbstractItem abstractItem, String identifier)
Permanently delete the given revision.void
deleteRevision(Node node, String identifier)
void
deleteRevision(File historyDir, String identifier)
static File
getConfigFile(File historyDir)
Returns the configuration data file stored in the specified history directory.int
getDeletedJobAmount()
File[]
getDeletedJobs()
Returns a list of deleted jobs with a history, including all those contained in folders.File[]
getDeletedJobs(String folderName)
Returns a list of deleted jobs with a history.File
getHistoryDir(File configFile)
Returns the configuration history directory for the given configuration file.SortedMap<String,HistoryDescr>
getJobHistory(String jobName)
Returns a sorted map of all HistoryDescr for a given job.int
getJobRevisionAmount()
int
getJobRevisionAmount(String jobName)
File[]
getJobs()
Returns a list of jobs with a history, including all those contained in folders.File[]
getJobs(String folderName)
Returns a list of jobs with a history.XmlFile
getOldRevision(AbstractItem item, String identifier)
Returns one old configuration of item.XmlFile
getOldRevision(Node node, String identifier)
Returns one old configuration of node.XmlFile
getOldRevision(XmlFile xmlFile, String identifier)
Returns one old configuration of xmlFile.XmlFile
getOldRevision(String configFileName, String identifier)
Returns one old configuration of file.int
getRevisionAmount(XmlFile xmlFile)
SortedMap<String,HistoryDescr>
getRevisions(Node node)
Returns a sorted map of all revisions for this node.SortedMap<String,HistoryDescr>
getRevisions(XmlFile xmlFile)
Returns a sorted map of all revisions for this xmlFile.File[]
getSystemConfigs()
Returns a list of all system configuration files with a history.SortedMap<String,HistoryDescr>
getSystemConfigsMap()
SortedMap<String,HistoryDescr>
getSystemHistory(String name)
Returns a sorted map of all HistoryDescr for a given system configuration.int
getSystemRevisionAmount()
int
getSystemRevisionAmount(String sysConfigName)
int
getTotalRevisionAmount()
boolean
hasDuplicateHistory(Node node)
Determines whether the given node has already been recorded in the history.boolean
hasOldRevision(Node node, String identifier)
Returns whether the revision exists.boolean
hasOldRevision(XmlFile xmlFile, String identifier)
Returns whether the revision exists.boolean
isCreatedEntry(File historyDir)
Determines whether the specified directory should be dropped or not.void
purgeOldEntries(File itemHistoryRoot, int maxEntries)
Purges entries when there are more entries than specified by max entries.void
renameItem(Item item, String oldName, String newName)
Save and renames the item.void
renameNode(Node node, String oldName, String newName)
Save and renames the node.boolean
revisionEqualsCurrent(AbstractItem project, String identifier1)
boolean
revisionEqualsCurrent(Node node, String identifier1)
void
saveItem(XmlFile file)
Saves a copy of a xml file.void
saveNode(Node node)
Saves the current configuration of a node.-
Methods inherited from class hudson.plugins.jobConfigHistory.JobConfigHistoryStrategy
all, getDescriptor
-
-
-
-
Constructor Detail
-
FileHistoryDao
public FileHistoryDao()
-
FileHistoryDao
public FileHistoryDao(File historyRootDir, File jenkinsHome, MimickedUser currentUser, int maxHistoryEntries, boolean saveDuplicates)
- Parameters:
historyRootDir
- where to store historyjenkinsHome
- JENKINS_HOMEcurrentUser
- of operationmaxHistoryEntries
- max number of history entriessaveDuplicates
- 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 namedJobConfigHistoryConsts.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 interfaceItemListenerHistoryDao
- 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 interfaceHistoryDao
- Parameters:
file
- xmlFile
-
deleteItem
public void deleteItem(Item item)
Description copied from interface:ItemListenerHistoryDao
Deletes the history of an item.- Specified by:
deleteItem
in interfaceItemListenerHistoryDao
- 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 interfaceItemListenerHistoryDao
-
renameItem
public void renameItem(Item item, String oldName, String newName)
Description copied from interface:ItemListenerHistoryDao
Save and renames the item.- Specified by:
renameItem
in interfaceItemListenerHistoryDao
- Parameters:
item
- projectoldName
- old project namenewName
- 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 interfaceHistoryDao
- Parameters:
xmlFile
- file- Returns:
- old revisions mapped to the identifier.
-
getRevisionAmount
public int getRevisionAmount(XmlFile xmlFile)
- Specified by:
getRevisionAmount
in interfaceHistoryDao
- 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 interfaceOverviewHistoryDao
- Returns:
- the number of configuration revision entries for a certain system config.
-
getSystemRevisionAmount
public int getSystemRevisionAmount()
- Specified by:
getSystemRevisionAmount
in interfaceOverviewHistoryDao
- Returns:
- the total number of system configuration revision entries.
-
getJobRevisionAmount
public int getJobRevisionAmount()
- Specified by:
getJobRevisionAmount
in interfaceOverviewHistoryDao
- Returns:
- the total number of job configuration revision entries.
-
getDeletedJobAmount
public int getDeletedJobAmount()
- Specified by:
getDeletedJobAmount
in interfaceOverviewHistoryDao
- Returns:
- the total number of deleted Jobs.
-
getJobRevisionAmount
public int getJobRevisionAmount(String jobName)
- Specified by:
getJobRevisionAmount
in interfaceOverviewHistoryDao
- Returns:
- the number of configuration revision entries for a certain system config.
-
getTotalRevisionAmount
public int getTotalRevisionAmount()
- Specified by:
getTotalRevisionAmount
in interfaceOverviewHistoryDao
- 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 interfaceHistoryDao
- Parameters:
item
- projectidentifier
- 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 interfaceHistoryDao
- Parameters:
xmlFile
- fileidentifier
- 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 interfaceHistoryDao
- Parameters:
configFileName
- fileidentifier
- 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 interfaceHistoryDao
- Parameters:
abstractItem
- itemidentifier
- timestamp or hash
-
deleteRevision
public void deleteRevision(Node node, String identifier)
- Specified by:
deleteRevision
in interfaceHistoryDao
-
deleteRevision
public void deleteRevision(File historyDir, String identifier)
- Specified by:
deleteRevision
in interfaceHistoryDao
-
revisionEqualsCurrent
public boolean revisionEqualsCurrent(AbstractItem project, String identifier1)
- Specified by:
revisionEqualsCurrent
in interfaceHistoryDao
-
revisionEqualsCurrent
public boolean revisionEqualsCurrent(Node node, String identifier1)
- Specified by:
revisionEqualsCurrent
in interfaceHistoryDao
-
hasOldRevision
public boolean hasOldRevision(XmlFile xmlFile, String identifier)
Description copied from interface:HistoryDao
Returns whether the revision exists.- Specified by:
hasOldRevision
in interfaceHistoryDao
- Parameters:
xmlFile
- fileidentifier
- 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 interfacePurgeable
- 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 interfacePurgeable
- 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 interfaceOverviewHistoryDao
- 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 interfaceOverviewHistoryDao
- 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 interfaceOverviewHistoryDao
- 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 interfaceOverviewHistoryDao
- 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 interfaceOverviewHistoryDao
- 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 interfaceOverviewHistoryDao
- 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 interfaceOverviewHistoryDao
- 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 interfaceOverviewHistoryDao
- 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 interfaceNodeListenerHistoryDao
- Parameters:
node
- node
-
deleteNode
public void deleteNode(Node node)
Description copied from interface:NodeListenerHistoryDao
Deletes the history of a node.- Specified by:
deleteNode
in interfaceNodeListenerHistoryDao
- 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 interfaceNodeListenerHistoryDao
- Parameters:
node
- nodeoldName
- old node namenewName
- 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 interfaceHistoryDao
- 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 interfaceHistoryDao
- 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 interfaceHistoryDao
- 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 interfaceHistoryDao
- Parameters:
node
- nodeidentifier
- 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 interfaceHistoryDao
- Parameters:
node
- nodeidentifier
- timestamp or hash- Returns:
- old configuration.
-
-