Package hudson.plugins.jobConfigHistory
Class JobConfigHistoryProjectAction
- java.lang.Object
-
- hudson.plugins.jobConfigHistory.JobConfigHistoryBaseAction
-
- hudson.plugins.jobConfigHistory.JobConfigHistoryProjectAction
-
- All Implemented Interfaces:
Action
,ModelObject
@ExportedBean(defaultVisibility=-1) public class JobConfigHistoryProjectAction extends JobConfigHistoryBaseAction
- Author:
- Stefan Brausch
-
-
Constructor Summary
Constructors Constructor Description JobConfigHistoryProjectAction(AbstractItem project)
-
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()
XmlSyntaxChecker.Answer
checkXmlSyntax(String timestamp)
void
doDeleteRevision(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
void
doForwardToRestoreQuestion(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Action when 'restore' button in showDiffFiles.jelly is pressed.void
doRestore(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
Action when 'restore' button is pressed: Replace current config file by older version.AccessControlled
getAccessControlledObject()
Returns the object for which we want to provide access control.Api
getApi()
String
getChangeReasonComment(int timestamp)
String
getFile()
ReturnsgetOldConfigXml(String)
as String.protected HistoryDao
getHistoryDao()
For tests.String
getIconFileName()
List<ConfigInfo>
getJobConfigs()
Returns the configuration history entries for oneAbstractItem
.List<ConfigInfo>
getJobConfigs(int from, int to)
Calculates a list containing the .subList(from, to) of the newest-first list of job config revision entries.List<ConfigInfo>
getJobConfigsREST()
Returns the configuration history entries for oneAbstractItem
for the REST API.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.String
getNextTimestamp(int timestampNumber)
Used in the Difference jelly only.String
getOperation(int timestampNumber)
Used in the Difference jelly only.String
getPrevTimestamp(int timestampNumber)
Used in the Difference jelly only.AbstractItem
getProject()
Returns the project for which we want to see the config history, the config files or the diff.int
getRevisionAmount()
String
getTimestamp(int timestampNumber)
Used in the Difference jelly only.String
getUser(int timestampNumber)
Used in the Difference jelly only.String
getUserID(int timestamp)
boolean
hasAdminPermission()
boolean
hasChangeReasonComment(int timestamp)
boolean
hasConfigurePermission()
Returns whether the current user may read configurations in the object returned byJobConfigHistoryBaseAction.getAccessControlledObject()
.boolean
hasDeleteEntryPermission()
boolean
hasReadExtensionPermission()
boolean
revisionEqualsCurrent(String timestamp)
-
Methods inherited from class hudson.plugins.jobConfigHistory.JobConfigHistoryBaseAction
checkTimestamp, doDiffFiles, doDiffFilesPrevNext, getCurrentRequest, getDiffAsString, getDiffAsString, getDiffLines, getDisplayName, getLines, getLines, getMaxEntriesPerPage, getMaxPageNum, getOutputType, getPlugin, getRelevantPageNums, getRelevantPageNums, getRequestParameter, getShowVersionDiffs, getUrlName
-
-
-
-
Constructor Detail
-
JobConfigHistoryProjectAction
public JobConfigHistoryProjectAction(AbstractItem project)
- Parameters:
project
- for which configurations should be returned.
-
-
Method Detail
-
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.
-
getJobConfigs
public final List<ConfigInfo> getJobConfigs()
Returns the configuration history entries for oneAbstractItem
.- Returns:
- history list for one
AbstractItem
.
-
getJobConfigs
public final List<ConfigInfo> getJobConfigs(int from, int to)
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.- Parameters:
from
- the first revision to displayto
- the first revision not to display anymore- Returns:
- a list equivalent to getJobConfigs().subList(from, to), but more efficiently calculated.
-
getRevisionAmount
public int getRevisionAmount()
- Specified by:
getRevisionAmount
in classJobConfigHistoryBaseAction
- Returns:
- the amount of revisions existing for the given request (not page-dependant).
-
getJobConfigsREST
@Exported(name="jobConfigHistory", visibility=1) public final List<ConfigInfo> getJobConfigsREST() throws IOException
Returns the configuration history entries for oneAbstractItem
for the REST API.- Returns:
- history list for one
AbstractItem
, or an empty list if not authorized. - Throws:
IOException
- ifJobConfigHistoryConsts.HISTORY_FILE
might not be read or the path might not be urlencoded.
-
getFile
public final String getFile() throws IOException
ReturnsgetOldConfigXml(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.
-
getProject
public final AbstractItem getProject()
Returns the project for which we want to see the config history, the config files or the diff.- Returns:
- project
-
getAccessControlledObject
public AccessControlled getAccessControlledObject()
Returns the object for which we want to provide access control. Returns the project.- 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.
-
hasReadExtensionPermission
public boolean hasReadExtensionPermission()
-
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.
-
getUser
public final String getUser(int timestampNumber)
Used in the Difference jelly only. Returns the user that made the change in one of the Files shown in the Difference view(A or B). timestampNumber decides between File A and File B.- Parameters:
timestampNumber
- 1 for File A and 2 for File B- Returns:
- the user as String.
-
getUserID
public final String getUserID(int timestamp)
-
getChangeReasonComment
public final String getChangeReasonComment(int timestamp)
-
hasChangeReasonComment
public final boolean hasChangeReasonComment(int timestamp)
-
getOperation
public final String getOperation(int timestampNumber)
Used in the Difference jelly only. Returns the operation made on one of the two Files A and B. timestampNumber decides which file exactly.- Parameters:
timestampNumber
- 1 for File A, 2 for File B- Returns:
- the operation as String.
-
getNextTimestamp
public final String getNextTimestamp(int timestampNumber)
Used in the Difference jelly only. Returns the next timestamp of the next entry of the two Files A and B. timestampNumber decides which file exactly.- Parameters:
timestampNumber
- 1 for File A, 2 for File B- Returns:
- the timestamp of the next entry as String.
-
getPrevTimestamp
public final String getPrevTimestamp(int timestampNumber)
Used in the Difference jelly only. Returns the previous timestamp of the next entry of the two Files A and B. timestampNumber decides which file exactly.- Parameters:
timestampNumber
- 1 for File A, 2 for File B- Returns:
- the timestamp of the previous entry as String.
-
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 match the ignoredLinesPattern if wanted.- Specified by:
getLines
in classJobConfigHistoryBaseAction
- Parameters:
hideVersionDiffs
- determines whether version diffs shall be shown 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 timestamp)
-
doRestore
public final void doRestore(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException
Action when 'restore' button is pressed: Replace current config file by older version.- Parameters:
req
- Incoming StaplerRequestrsp
- Outgoing StaplerResponse- Throws:
IOException
- If something goes wrong
-
doForwardToRestoreQuestion
public final void doForwardToRestoreQuestion(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException
Action when 'restore' button in showDiffFiles.jelly is pressed. Gets required parameter and forwards to restoreQuestion.jelly.- Parameters:
req
- StaplerRequest created by pressing the buttonrsp
- Outgoing StaplerResponse- Throws:
IOException
- If XML file can't be read
-
doDeleteRevision
public final void doDeleteRevision(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp)
-
revisionEqualsCurrent
public boolean revisionEqualsCurrent(String timestamp)
-
getHistoryDao
protected HistoryDao getHistoryDao()
For tests.- Overrides:
getHistoryDao
in classJobConfigHistoryBaseAction
- Returns:
- historyDao
-
getApi
public Api getApi()
-
getLeadingWhitespace
public int getLeadingWhitespace(String str)
-
-