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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
See whether the current user may read configurations in the object returned byJobConfigHistoryBaseAction.getAccessControlledObject()
.protected void
boolean
checkParameters
(String name, String timestamp) Checks the url parameters 'name' and 'timestamp' and returns true if they are neither null nor suspicious.checkXmlSyntax
(String name, String timestamp) final String
createLinkToFiles
(ConfigInfo config, String type) Creates links to the correct configOutput.jelly for job history vs.final void
doDeleteRevision
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) final void
doDiffFiles
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Parses the incoming POST request and redirects as GET showDiffFiles.final void
doForwardToRestoreQuestion
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Action when 'restore' button in history.jelly is pressed.final void
doRestore
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Action when 'restore' button is pressed: Restore deleted project.findNewName
(String name) Finds a name for the project to be restored.Returns the object for which we want to provide access control.getApi()
final List<ConfigInfo>
Returns the configuration history entries for eitherAbstractItem
s or system changes or deleted jobs or all of the above.final 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.final String
getFile()
ReturnsgetOldConfigXml(String, String)
as String.protected HistoryDao
For tests.final String
getJobConfigs
(String type) Returns the configuration history entries for all jobs or deleted jobs in this Jenkins instance.Retrieves the last or second to last config.xml.int
final 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.getOldConfigXml
(String name, String timestamp) Gets the version of the config.xml that was saved at a certain time.protected OverviewHistoryDao
For tests.int
final List<ConfigInfo>
getSingleConfigs
(String name) Returns the configuration history entries for one group of system files or deleted jobs.final List<ConfigInfo>
getSingleConfigs
(String name, int from, int to) Returns the configuration history entries for all system files in this Jenkins instance.final String
getTimestamp
(int timestampNumber) Used in the Difference jelly only.final String
boolean
boolean
Returns whether the current user may read configurations in the object returned byJobConfigHistoryBaseAction.getAccessControlledObject()
.boolean
boolean
Returns whether the current user may configure jobs.boolean
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
-
Constructor Details
-
JobConfigHistoryRootAction
public JobConfigHistoryRootAction()Constructor necessary for testing.
-
-
Method Details
-
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
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
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
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
Returns the configuration history entries for all system files in this Jenkins instance.- Returns:
- List of config infos.
-
getJobConfigs
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
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
- 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
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
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
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
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
-
getTimestamp
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
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
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
@POST 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
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
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
@POST public final void doDeleteRevision(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) -
getHistoryDao
For tests.- Overrides:
getHistoryDao
in classJobConfigHistoryBaseAction
- Returns:
- historyDao
-
getOverviewHistoryDao
For tests.- Returns:
- historyDao
-
getApi
-
getLeadingWhitespace
-