hudson.plugins.jobConfigHistory
Class JobConfigHistoryBaseAction

java.lang.Object
  extended by hudson.plugins.jobConfigHistory.JobConfigHistoryBaseAction
All Implemented Interfaces:
hudson.model.Action, hudson.model.ModelObject
Direct Known Subclasses:
JobConfigHistoryProjectAction, JobConfigHistoryRootAction

public abstract class JobConfigHistoryBaseAction
extends Object
implements hudson.model.Action

Implements some basic methods needed by the JobConfigHistoryRootAction and JobConfigHistoryProjectAction.

Author:
mfriedenhagen

Constructor Summary
JobConfigHistoryBaseAction()
          Set the Hudson instance.
 
Method Summary
protected abstract  void checkConfigurePermission()
          See whether the current user may read configurations in the object returned by getAccessControlledObject().
 void doDiffFiles(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
          Parses the incoming POST request and redirects as GET showDiffFiles.
protected abstract  hudson.security.AccessControlled getAccessControlledObject()
          Returns the object for which we want to provide access control.
protected  hudson.XmlFile getConfigXml(String diffDir)
          Returns the configuration file (default is config.xml) located in diffDir.
protected  String getDiff(File file1, File file2, String[] file1Lines, String[] file2Lines)
          Returns a unified diff between two string arrays.
 String getDiffFile()
          Returns a textual diff between two config.xml files located in histDir1 and histDir2 directories given as parameters of Stapler.getCurrentRequest().
 String getDisplayName()
           Make method final, as we always want the same display name.
 String getFile()
          Returns getConfigXml(String) as String.
protected  hudson.model.Hudson getHudson()
          Returns the hudson instance.
 String getIconFileName()
           Make method final, as we always want the same icon file.
protected  JobConfigHistory getPlugin()
          Returns the JobConfigHistory plugin instance.
protected  String getRequestParameter(String parameterName)
          Returns the parameter named parameterName from current request.
 String getUrlName()
           Do not make this method final as JobConfigHistoryRootAction overrides this method.
protected abstract  boolean hasConfigurePermission()
          Returns whether the current user may read configurations in the object returned by getAccessControlledObject().
 boolean wantRawOutput()
          Do we want 'raw' output?
 boolean wantXmlOutput()
          Do we want 'xml' output?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JobConfigHistoryBaseAction

public JobConfigHistoryBaseAction()
Set the Hudson instance.

Method Detail

getDisplayName

public final String getDisplayName()
Make method final, as we always want the same display name.

Specified by:
getDisplayName in interface hudson.model.Action
Specified by:
getDisplayName in interface hudson.model.ModelObject

getIconFileName

public final String getIconFileName()
Make method final, as we always want the same icon file. Returns null to hide the icon if the user is not allowed to configure jobs.

Specified by:
getIconFileName in interface hudson.model.Action

getUrlName

public String getUrlName()
Do not make this method final as JobConfigHistoryRootAction overrides this method.

Specified by:
getUrlName in interface hudson.model.Action

wantRawOutput

public final boolean wantRawOutput()
Do we want 'raw' output?

Returns:
true if request parameter type is 'raw'.

wantXmlOutput

public final boolean wantXmlOutput()
Do we want 'xml' output?

Returns:
true if request parameter type is 'xml'.

getFile

public final String getFile()
                     throws IOException
Returns getConfigXml(String) as String.

Returns:
content of the config.xml found in directory given by the request parameter file.
Throws:
IOException - if the config file could not be read or converted to an xml string.

getConfigXml

protected hudson.XmlFile getConfigXml(String diffDir)
Returns the configuration file (default is config.xml) located in diffDir. diffDir must either start with HUDSON_HOME and contain config-history or be located under the configured historyRootDir. It also must not contain a '..' pattern. Otherwise an IllegalArgumentException will be thrown.

This is to ensure that this plugin will not be abused to get arbitrary xml configuration files located anywhere on the system.

Parameters:
diffDir - timestamped history directory.
Returns:
xmlfile.

getRequestParameter

protected String getRequestParameter(String parameterName)
Returns the parameter named parameterName from current request.

Parameters:
parameterName - name of the parameter.
Returns:
value of the request parameter or null if it does not exist.

checkConfigurePermission

protected abstract void checkConfigurePermission()
See whether the current user may read configurations in the object returned by getAccessControlledObject().


hasConfigurePermission

protected abstract boolean hasConfigurePermission()
Returns whether the current user may read configurations in the object returned by getAccessControlledObject().

Returns:
true if the current user may read configurations.

getHudson

protected final hudson.model.Hudson getHudson()
Returns the hudson instance.

Returns:
the hudson

getPlugin

protected final JobConfigHistory getPlugin()
Returns the JobConfigHistory plugin instance.

Returns:
the JobConfigHistory plugin

getAccessControlledObject

protected abstract hudson.security.AccessControlled getAccessControlledObject()
Returns the object for which we want to provide access control.

Returns:
the access controlled object.

doDiffFiles

public final void doDiffFiles(org.kohsuke.stapler.StaplerRequest req,
                              org.kohsuke.stapler.StaplerResponse rsp)
                       throws javax.servlet.ServletException,
                              IOException
Parses the incoming POST request and redirects as GET showDiffFiles.

Parameters:
req - incoming request
rsp - outgoing response
Throws:
javax.servlet.ServletException - when parsing the request as MultipartFormDataParser does not succeed.
IOException - when the redirection does not succeed.

getDiffFile

public final String getDiffFile()
                         throws IOException
Returns a textual diff between two config.xml files located in histDir1 and histDir2 directories given as parameters of Stapler.getCurrentRequest().

Returns:
diff
Throws:
IOException - if reading one of the config files does not succeed.

getDiff

protected final String getDiff(File file1,
                               File file2,
                               String[] file1Lines,
                               String[] file2Lines)
Returns a unified diff between two string arrays.

Parameters:
file1 - first config file.
file2 - second config file.
file1Lines - the lines of the first file.
file2Lines - the lines of the second file.
Returns:
unified diff


Copyright © 2004-2011. All Rights Reserved.