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
Defines some helper functions needed by
JobConfigHistoryJobListener
and JobConfigHistorySaveableListener
.- Author:
- Mirko Friedenhagen
-
Nested Class Summary
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
Constructor Summary
ConstructorDescriptionFileHistoryDao
(File historyRootDir, File jenkinsHome, MimickedUser currentUser, int maxHistoryEntries, boolean saveDuplicates) -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
File[]
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.getHistoryDir
(File configFile) Returns the configuration history directory for the given configuration file.getJobHistory
(String jobName) Returns a sorted map of all HistoryDescr for a given job.int
int
getJobRevisionAmount
(String jobName) File[]
getJobs()
Returns a list of jobs with a history, including all those contained in folders.File[]
Returns a list of jobs with a history.getOldRevision
(AbstractItem item, String identifier) Returns one old configuration of item.getOldRevision
(Node node, String identifier) Returns one old configuration of node.getOldRevision
(XmlFile xmlFile, String identifier) Returns one old configuration of xmlFile.getOldRevision
(String configFileName, String identifier) Returns one old configuration of file.int
getRevisionAmount
(XmlFile xmlFile) getRevisions
(Node node) Returns a sorted map of all revisions for this node.getRevisions
(XmlFile xmlFile) Returns a sorted map of all revisions for this xmlFile.File[]
Returns a list of all system configuration files with a history.getSystemHistory
(String name) Returns a sorted map of all HistoryDescr for a given system configuration.int
int
getSystemRevisionAmount
(String sysConfigName) int
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
Saves a copy of a xml file.void
Saves the current configuration of a node.Methods inherited from class hudson.plugins.jobConfigHistory.JobConfigHistoryStrategy
all, getDescriptor
-
Constructor Details
-
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 Details
-
getConfigFile
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
Description copied from interface:ItemListenerHistoryDao
Adds and saves the initial configuration of an item.- Specified by:
createNewItem
in interfaceItemListenerHistoryDao
- Parameters:
item
- project
-
saveItem
Description copied from interface:HistoryDao
Saves a copy of a xml file.- Specified by:
saveItem
in interfaceHistoryDao
- Parameters:
file
- xmlFile
-
deleteItem
Description copied from interface:ItemListenerHistoryDao
Deletes the history of an item.- Specified by:
deleteItem
in interfaceItemListenerHistoryDao
- Parameters:
item
- project
-
changeItemLocation
Description copied from interface:ItemListenerHistoryDao
Changes the item's history's location.- Specified by:
changeItemLocation
in interfaceItemListenerHistoryDao
- Parameters:
item
- projectoldFullName
- old full namenewFullName
- new full name
-
renameItem
Description copied from interface:ItemListenerHistoryDao
Save and renames the item.- Specified by:
renameItem
in interfaceItemListenerHistoryDao
- Parameters:
item
- projectoldName
- old project namenewName
- new name
-
getRevisions
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
- Specified by:
getRevisionAmount
in interfaceHistoryDao
- Parameters:
xmlFile
- the config's history xml file- Returns:
- the amount of revision entries of a certain config.
-
getSystemRevisionAmount
- 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
- 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
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
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
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
Description copied from interface:HistoryDao
Permanently delete the given revision.- Specified by:
deleteRevision
in interfaceHistoryDao
- Parameters:
abstractItem
- itemidentifier
- timestamp or hash
-
deleteRevision
- Specified by:
deleteRevision
in interfaceHistoryDao
-
deleteRevision
- Specified by:
deleteRevision
in interfaceHistoryDao
-
revisionEqualsCurrent
- Specified by:
revisionEqualsCurrent
in interfaceHistoryDao
-
revisionEqualsCurrent
- Specified by:
revisionEqualsCurrent
in interfaceHistoryDao
-
hasOldRevision
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
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
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
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
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
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
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
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
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
- Specified by:
getSystemConfigsMap
in interfaceOverviewHistoryDao
- Returns:
- a map mapping timestamps to historydescrs. Contains all system config revision entries.
-
getJobHistory
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
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. -
createNewNode
Description copied from interface:NodeListenerHistoryDao
Adds and saves the initial configuration of a node.- Specified by:
createNewNode
in interfaceNodeListenerHistoryDao
- Parameters:
node
- node
-
deleteNode
Description copied from interface:NodeListenerHistoryDao
Deletes the history of a node.- Specified by:
deleteNode
in interfaceNodeListenerHistoryDao
- Parameters:
node
- node
-
renameNode
Description copied from interface:NodeListenerHistoryDao
Save and renames the node.- Specified by:
renameNode
in interfaceNodeListenerHistoryDao
- Parameters:
node
- nodeoldName
- old node namenewName
- new name
-
getRevisions
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
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
Description copied from interface:HistoryDao
Saves the current configuration of a node.- Specified by:
saveNode
in interfaceHistoryDao
- Parameters:
node
- node
-
getOldRevision
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
Description copied from interface:HistoryDao
Returns whether the revision exists.- Specified by:
hasOldRevision
in interfaceHistoryDao
- Parameters:
node
- nodeidentifier
- timestamp or hash- Returns:
- old configuration.
-