hudson.plugins.jobConfigHistory
Class JobConfigHistory

java.lang.Object
  extended by hudson.Plugin
      extended by hudson.plugins.jobConfigHistory.JobConfigHistory
All Implemented Interfaces:
hudson.model.Saveable

public class JobConfigHistory
extends hudson.Plugin

Class supporting global configuration settings, along with methods associated with the plugin itself.

Author:
jborghi

Nested Class Summary
 
Nested classes/interfaces inherited from class hudson.Plugin
hudson.Plugin.DummyImpl
 
Field Summary
static FileFilter HISTORY_FILTER
          A filter to return only those directories of a file listing that represent configuration history directories.
 
Fields inherited from interface hudson.model.Saveable
NOOP
 
Constructor Summary
JobConfigHistory()
           
 
Method Summary
protected  void checkForPurgeByQuantity(File itemHistoryRoot)
          Checks if we should purge old history entries under the specified root using the maxHistoryEntries value as the criteria, and if required calls the appropriate method to perform the purge.
 void configure(org.kohsuke.stapler.StaplerRequest req, net.sf.json.JSONObject formData)
           
 hudson.util.FormValidation doCheckExcludePattern(String value)
          Validates the user entry for the regular expression of system file names to exclude from saving.
 hudson.util.FormValidation doCheckMaxHistoryEntries(String value)
          Validates the user entry for the maximum number of history items to keep.
protected  File getConfigFile(File historyDir)
          Returns the configuration data file stored in the specified history directory.
protected  File getConfiguredHistoryRootDir()
          Returns the File object representing the configured root history directory.
 String getDefaultExcludePattern()
          Used by the configuration page.
 String getExcludePattern()
           
protected  Pattern getExcludeRegexpPattern()
          Used for testing to verify invalid pattern not loaded.
protected  File getHistoryDir(hudson.XmlFile xmlFile)
          Returns the configuration history directory for the given configuration file.
 String getHistoryRootDir()
           
 String getMaxHistoryEntries()
           
 boolean getSaveSystemConfiguration()
           
 boolean getSkipDuplicateHistory()
           
protected  File getSystemHistoryDir()
          Returns the directory for storing system configurations.
protected  boolean isSaveable(hudson.model.Saveable item, hudson.XmlFile xmlFile)
          Returns true if configuration for this item should be saved, based on the plugin settings, the type of item and the configuration file specified.
protected  void setMaxHistoryEntries(String maxHistoryEntries)
          This method is for convenience in testing.
 void start()
           
 
Methods inherited from class hudson.Plugin
configure, doDynamic, getConfigXml, load, postInitialize, save, setServletContext, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HISTORY_FILTER

public static final FileFilter HISTORY_FILTER
A filter to return only those directories of a file listing that represent configuration history directories.

Constructor Detail

JobConfigHistory

public JobConfigHistory()
Method Detail

start

public void start()
           throws Exception
Overrides:
start in class hudson.Plugin
Throws:
Exception

configure

public void configure(org.kohsuke.stapler.StaplerRequest req,
                      net.sf.json.JSONObject formData)
               throws IOException,
                      javax.servlet.ServletException,
                      hudson.model.Descriptor.FormException
Overrides:
configure in class hudson.Plugin
Throws:
IOException
javax.servlet.ServletException
hudson.model.Descriptor.FormException

getHistoryRootDir

public String getHistoryRootDir()
Returns:
The configured history root directory.

getMaxHistoryEntries

public String getMaxHistoryEntries()
Returns:
The maximum number of history entries to keep.

setMaxHistoryEntries

protected void setMaxHistoryEntries(String maxHistoryEntries)
This method is for convenience in testing.

Parameters:
maxHistoryEntries - The maximum number of history entries to keep

getSaveSystemConfiguration

public boolean getSaveSystemConfiguration()
Returns:
true if we should save 'system' configurations.

getSkipDuplicateHistory

public boolean getSkipDuplicateHistory()
Returns:
true if we should skip saving history that duplicates the prior saved configuration.

getExcludePattern

public String getExcludePattern()
Returns:
The regular expression for 'system' file names to exclude from saving.

getDefaultExcludePattern

public String getDefaultExcludePattern()
Used by the configuration page.

Returns:
The default regular expression for 'system' file names to exclude from saving.

getExcludeRegexpPattern

protected Pattern getExcludeRegexpPattern()
Used for testing to verify invalid pattern not loaded.

Returns:
The loaded regexp pattern, or null if pattern was invalid.

getConfiguredHistoryRootDir

protected File getConfiguredHistoryRootDir()
Returns the File object representing the configured root history directory.

Returns:
The configured root history File object, or null if this configuration has not been set.

getHistoryDir

protected File getHistoryDir(hudson.XmlFile xmlFile)
Returns the configuration history directory for the given configuration file.

Parameters:
xmlFile - 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 Hudson configuration file.

getSystemHistoryDir

protected File getSystemHistoryDir()
Returns the directory for storing system configurations.

Returns:
The directory used for storing system configurations.

getConfigFile

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

isSaveable

protected boolean isSaveable(hudson.model.Saveable item,
                             hudson.XmlFile xmlFile)
Returns true if configuration for this item should be saved, based on the plugin settings, the type of item and the configuration file specified.

If the item is an instance of AbstractProject or the configuration file is stored directly in HUDSON_ROOT, it is considered for saving. If the plugin is configured to skip saving duplicated history, we also evaluate if this configuration duplicates the previous saved history (if such history exists).

Parameters:
item - The item whose configuration is under consideration.
xmlFile - The configuration file for the above item.
Returns:
true if the item configuration should be saved.

checkForPurgeByQuantity

protected void checkForPurgeByQuantity(File itemHistoryRoot)
Checks if we should purge old history entries under the specified root using the maxHistoryEntries value as the criteria, and if required calls the appropriate method to perform the purge.

Parameters:
itemHistoryRoot - The directory to consider purging history under.

doCheckMaxHistoryEntries

public hudson.util.FormValidation doCheckMaxHistoryEntries(@QueryParameter
                                                           String value)
Validates the user entry for the maximum number of history items to keep. Must be blank or a non-negative integer.

Parameters:
value - The form input entered by the user.
Returns:
ok if the entry is blank or a non-negative integer.

doCheckExcludePattern

public hudson.util.FormValidation doCheckExcludePattern(@QueryParameter
                                                        String value)
Validates the user entry for the regular expression of system file names to exclude from saving.

Parameters:
value - The form input entered by the user.
Returns:
ok if the entry is a valid regular expression.


Copyright © 2004-2011. All Rights Reserved.