Package hudson.plugins.jobConfigHistory
Class JobConfigHistoryRootAction
- java.lang.Object
-
- hudson.plugins.jobConfigHistory.JobConfigHistoryBaseAction
-
- hudson.plugins.jobConfigHistory.JobConfigHistoryRootAction
-
- All Implemented Interfaces:
ExtensionPoint
,Action
,ModelObject
,RootAction
@ExportedBean(defaultVisibility=-1) @Extension public class JobConfigHistoryRootAction extends JobConfigHistoryBaseAction implements RootAction
- Author:
- Stefan Brausch, Mirko Friedenhagen
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
-
Constructor Summary
Constructors Constructor Description JobConfigHistoryRootAction()
Constructor necessary for testing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkConfigurePermission()
See whether the current user may read configurations in the object returned byJobConfigHistoryBaseAction.getAccessControlledObject()
.protected void
checkDeleteEntryPermission()
boolean
checkParameters(String name, String timestamp)
Checks the url parameters 'name' and 'timestamp' and returns true if they are neither null nor suspicious.XmlSyntaxChecker.Answer
checkXmlSyntax(String name, String timestamp)
String
createLinkToFiles(ConfigInfo config, String type)
Creates links to the correct configOutput.jelly for job history vs.void
doDeleteRevision(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
void
doDiffFiles(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Parses the incoming POST request and redirects as GET showDiffFiles.void
doForwardToRestoreQuestion(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Action when 'restore' button in history.jelly is pressed.void
doRestore(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Action when 'restore' button is pressed: Restore deleted project.String
findNewName(String name)
Finds a name for the project to be restored.AccessControlled
getAccessControlledObject()
Returns the object for which we want to provide access control.Api
getApi()
List<ConfigInfo>
getConfigs()
Returns the configuration history entries for eitherAbstractItem
s or system changes or deleted jobs or all of the above.List<ConfigInfo>
getConfigs(int from, int to)
Calculates a list containing the .subList(from, to) of the newest-first list of job config revision entries.String
getFile()
ReturnsgetOldConfigXml(String, String)
as String.protected HistoryDao
getHistoryDao()
For tests.String
getIconFileName()
List<ConfigInfo>
getJobConfigs(String type)
Returns the configuration history entries for all jobs or deleted jobs in this Jenkins instance.XmlFile
getLastAvailableConfigXml(String name)
Retrieves the last or second to last config.xml.int
getLeadingWhitespace(String str)
List<SideBySideView.Line>
getLines(boolean hideVersionDiffs)
Takes the two timestamp request parameters and returns the diff between the corresponding config files of this project as a list of single lines.XmlFile
getOldConfigXml(String name, String timestamp)
Gets the version of the config.xml that was saved at a certain time.protected OverviewHistoryDao
getOverviewHistoryDao()
For tests.int
getRevisionAmount()
List<ConfigInfo>
getSingleConfigs(String name)
Returns the configuration history entries for one group of system files or deleted jobs.List<ConfigInfo>
getSingleConfigs(String name, int from, int to)
List<ConfigInfo>
getSystemConfigs()
Returns the configuration history entries for all system files in this Jenkins instance.String
getTimestamp(int timestampNumber)
Used in the Difference jelly only.String
getUrlName()
boolean
hasAdminPermission()
boolean
hasConfigurePermission()
Returns whether the current user may read configurations in the object returned byJobConfigHistoryBaseAction.getAccessControlledObject()
.boolean
hasDeleteEntryPermission()
boolean
hasJobConfigurePermission()
Returns whether the current user may configure jobs.boolean
hasReadExtensionPermission()
Returns whether the current user may read configure jobs.-
Methods inherited from class hudson.plugins.jobConfigHistory.JobConfigHistoryBaseAction
checkTimestamp, doDiffFilesPrevNext, getCurrentRequest, getDiffAsString, getDiffAsString, getDiffLines, getDisplayName, getLines, getLines, getMaxEntriesPerPage, getMaxPageNum, getOutputType, getPlugin, getRelevantPageNums, getRelevantPageNums, getRequestParameter, getShowVersionDiffs
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface hudson.model.Action
getDisplayName
-
-
-
-
Method Detail
-
getUrlName
public final String getUrlName()
This actions always starts from the context directly, so prefix
JobConfigHistoryConsts.URLNAME
with a slash.- Specified by:
getUrlName
in interfaceAction
- Overrides:
getUrlName
in classJobConfigHistoryBaseAction
-
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 interfaceAction
-
getConfigs
@Exported(visibility=1) public final List<ConfigInfo> getConfigs() throws IOException
Returns the configuration history entries for eitherAbstractItem
s or system changes or deleted jobs or all of the above.- Returns:
- list of configuration histories (as ConfigInfo)
- Throws:
IOException
- if one of the history entries might not be read.
-
getConfigs
public final List<ConfigInfo> getConfigs(int from, int to) throws IOException
Calculates a list containing the .subList(from, to) of the newest-first list of job config revision entries. Does not read the history.xmls unless it is inevitable. Since filter=created requires to read the history.xml of each revision which makes paging pointless from a performance and usability perspective, all configs are returned in that case.- Parameters:
from
- the first revision to displayto
- the first revision not to display anymore- Returns:
- a list equivalent to getJobConfigs().subList(from, to) (except for filter=created), but more efficiently calculated.
- Throws:
IOException
-
getSystemConfigs
public List<ConfigInfo> getSystemConfigs()
Returns the configuration history entries for all system files in this Jenkins instance.- Returns:
- List of config infos.
-
getJobConfigs
public List<ConfigInfo> getJobConfigs(String type) throws IOException
Returns the configuration history entries for all jobs or deleted jobs in this Jenkins instance.- Parameters:
type
- Whether we want to see all jobs or just the deleted jobs.- Returns:
- List of config infos.
- Throws:
IOException
- if one of the history entries might not be read.
-
getSingleConfigs
public final List<ConfigInfo> getSingleConfigs(String name) throws IOException
Returns the configuration history entries for one group of system files or deleted jobs.- Parameters:
name
- of the item.- Returns:
- Configs list for one group of system configuration files.
- Throws:
IOException
- if one of the history entries might not be read.
-
getSingleConfigs
public final List<ConfigInfo> getSingleConfigs(String name, int from, int to)
- Parameters:
name
- of the itemfrom
- the first revision to displayto
- the first revision not to display anymore- Returns:
- the same as
getSingleConfigs(String)
, but cut for paging.
-
getRevisionAmount
public int getRevisionAmount()
- Specified by:
getRevisionAmount
in classJobConfigHistoryBaseAction
- Returns:
- the amount of revisions existing for the given request (not page-dependant).
-
getFile
public final String getFile() throws IOException
ReturnsgetOldConfigXml(String, 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.
-
createLinkToFiles
public final String createLinkToFiles(ConfigInfo config, String type)
Creates links to the correct configOutput.jelly for job history vs. system history and for xml vs. plain text.- Parameters:
config
- ConfigInfo.type
- Output type ('xml' or 'plain').- Returns:
- The link as String.
-
getAccessControlledObject
public AccessControlled getAccessControlledObject()
Description copied from class:JobConfigHistoryBaseAction
Returns the object for which we want to provide access control.- Specified by:
getAccessControlledObject
in classJobConfigHistoryBaseAction
- Returns:
- the access controlled object.
-
checkConfigurePermission
public void checkConfigurePermission()
Description copied from class:JobConfigHistoryBaseAction
See whether the current user may read configurations in the object returned byJobConfigHistoryBaseAction.getAccessControlledObject()
.- Specified by:
checkConfigurePermission
in classJobConfigHistoryBaseAction
-
checkDeleteEntryPermission
protected void checkDeleteEntryPermission()
- Specified by:
checkDeleteEntryPermission
in classJobConfigHistoryBaseAction
-
hasAdminPermission
public boolean hasAdminPermission()
- Specified by:
hasAdminPermission
in classJobConfigHistoryBaseAction
-
hasDeleteEntryPermission
public boolean hasDeleteEntryPermission()
- Specified by:
hasDeleteEntryPermission
in classJobConfigHistoryBaseAction
-
hasConfigurePermission
public boolean hasConfigurePermission()
Description copied from class:JobConfigHistoryBaseAction
Returns whether the current user may read configurations in the object returned byJobConfigHistoryBaseAction.getAccessControlledObject()
.- Specified by:
hasConfigurePermission
in classJobConfigHistoryBaseAction
- Returns:
- true if the current user may read configurations.
-
hasJobConfigurePermission
public boolean hasJobConfigurePermission()
Returns whether the current user may configure jobs.- Returns:
- true if the current user may configure jobs.
-
hasReadExtensionPermission
public boolean hasReadExtensionPermission()
Returns whether the current user may read configure jobs.- Returns:
- true if the current user may read configure jobs.
-
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.- Overrides:
doDiffFiles
in classJobConfigHistoryBaseAction
- Parameters:
req
- incoming requestrsp
- outgoing response- Throws:
javax.servlet.ServletException
- when parsing the request asMultipartFormDataParser
does not succeed.IOException
- when the redirection does not succeed.
-
getLines
public final List<SideBySideView.Line> getLines(boolean hideVersionDiffs) throws IOException
Takes the two timestamp request parameters and returns the diff between the corresponding config files of this project as a list of single lines. Filters lines that contain plugin version information.- Specified by:
getLines
in classJobConfigHistoryBaseAction
- Parameters:
hideVersionDiffs
- determines whether lines that match the ignoredLinesPattern shall be hidden or not.- Returns:
- Differences between two config versions as list of lines.
- Throws:
IOException
- If diff doesn't work or xml files can't be read.
-
checkXmlSyntax
public XmlSyntaxChecker.Answer checkXmlSyntax(String name, String timestamp)
-
getTimestamp
public final String getTimestamp(int timestampNumber)
Used in the Difference jelly only. Returns one of the two timestamps that have been passed to the Difference page as parameter. timestampNumber must be 1 or 2.- Parameters:
timestampNumber
- 1 for timestamp1 and 2 for timestamp2- Returns:
- the timestamp as String.
-
getOldConfigXml
public XmlFile getOldConfigXml(String name, String timestamp)
Gets the version of the config.xml that was saved at a certain time.- Parameters:
name
- The name of the system property or deleted job.timestamp
- The timestamp as String.- Returns:
- The config file as XmlFile.
-
checkParameters
public boolean checkParameters(String name, String timestamp)
Checks the url parameters 'name' and 'timestamp' and returns true if they are neither null nor suspicious.- Parameters:
name
- Name of deleted job or system property.timestamp
- Timestamp of config change.- Returns:
- True if parameters are okay.
-
doRestore
public final void doRestore(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException
Action when 'restore' button is pressed: Restore deleted project.- Parameters:
req
- Incoming StaplerRequestrsp
- Outgoing StaplerResponse- Throws:
IOException
- If something goes wrong
-
getLastAvailableConfigXml
public XmlFile getLastAvailableConfigXml(String name)
Retrieves the last or second to last config.xml. The latter is necessary when the last config.xml is missing although the history entry exists, which happens when a project is deleted while being disabled.- Parameters:
name
- The name of the deleted project.- Returns:
- The last or second to last config as XmlFile or null.
-
findNewName
public String findNewName(String name)
Finds a name for the project to be restored. If the old name is already in use by another project, "_" plus a number is appended to the name until an unused name is found.- Parameters:
name
- The old name as String.- Returns:
- the new name as String.
-
doForwardToRestoreQuestion
public final void doForwardToRestoreQuestion(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException
Action when 'restore' button in history.jelly is pressed. Gets required parameter and forwards to restoreQuestion.jelly.- Parameters:
req
- StaplerRequest created by pressing the buttonrsp
- Outgoing StaplerResponse- Throws:
IOException
- If redirect goes wrong
-
doDeleteRevision
public final void doDeleteRevision(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
-
getHistoryDao
protected HistoryDao getHistoryDao()
For tests.- Overrides:
getHistoryDao
in classJobConfigHistoryBaseAction
- Returns:
- historyDao
-
getOverviewHistoryDao
protected OverviewHistoryDao getOverviewHistoryDao()
For tests.- Returns:
- historyDao
-
getApi
public Api getApi()
-
getLeadingWhitespace
public int getLeadingWhitespace(String str)
-
-