Package hudson.plugins.jobConfigHistory
Class JobConfigHistoryBaseAction
java.lang.Object
hudson.plugins.jobConfigHistory.JobConfigHistoryBaseAction
- All Implemented Interfaces:
Action
,ModelObject
- Direct Known Subclasses:
ComputerConfigHistoryAction
,JobConfigHistoryProjectAction
,JobConfigHistoryRootAction
Implements some basic methods needed by the
JobConfigHistoryRootAction
and JobConfigHistoryProjectAction
.- Author:
- Mirko Friedenhagen
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
See whether the current user may read configurations in the object returned bygetAccessControlledObject()
.protected abstract void
protected boolean
checkTimestamp
(String timestamp) Checks the url parameter 'timestamp' and returns true if it is parseable as a date.void
doDiffFiles
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Parses the incoming POST request and redirects as GET showDiffFiles.final void
doDiffFilesPrevNext
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Action when 'Prev' or 'Next' button in showDiffFiles.jelly is pressed.protected abstract AccessControlled
Returns the object for which we want to provide access control.protected org.kohsuke.stapler.StaplerRequest
Overridable for tests.protected final String
getDiffAsString
(File file1, File file2, String[] file1Lines, String[] file2Lines) Returns a unified diff between two string arrays.protected final String
getDiffAsString
(File file1, File file2, String[] file1Lines, String[] file2Lines, boolean hideVersionDiffs) Returns a unified diff between two string arrays representing an xml file.final List<SideBySideView.Line>
getDiffLines
(List<String> diffLines) Returns side-by-side (i.e.protected HistoryDao
For tests.final List<SideBySideView.Line>
getLines()
Returns the diff between two config files as a list of single lines.abstract List<SideBySideView.Line>
getLines
(boolean useRegex) protected final List<SideBySideView.Line>
Takes the two config files and returns the diff between them as a list of single lines.int
int
final String
Returns how the config file should be formatted in configOutput.jelly: as plain text or xml.protected JobConfigHistory
Returns the plugin for tests.getRelevantPageNums
(int currentPageNum) getRelevantPageNums
(int currentPageNum, int maxPageNum) protected String
getRequestParameter
(String parameterName) Returns the parameter namedparameterName
from current request.abstract int
Get the current request's 'showVersionDiffs'-parameter.abstract boolean
protected abstract boolean
Returns whether the current user may read configurations in the object returned bygetAccessControlledObject()
.abstract boolean
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
getIconFileName
-
Constructor Details
-
JobConfigHistoryBaseAction
public JobConfigHistoryBaseAction()
-
-
Method Details
-
getDisplayName
- Specified by:
getDisplayName
in interfaceAction
- Specified by:
getDisplayName
in interfaceModelObject
-
getUrlName
- Specified by:
getUrlName
in interfaceAction
-
getOutputType
Returns how the config file should be formatted in configOutput.jelly: as plain text or xml.- Returns:
- "plain" or "xml"
-
checkTimestamp
Checks the url parameter 'timestamp' and returns true if it is parseable as a date.- Parameters:
timestamp
- Timestamp of config change.- Returns:
- True if timestamp is okay.
-
getRequestParameter
Returns the parameter namedparameterName
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 bygetAccessControlledObject()
. -
hasAdminPermission
public abstract boolean hasAdminPermission() -
hasDeleteEntryPermission
public abstract boolean hasDeleteEntryPermission() -
checkDeleteEntryPermission
protected abstract void checkDeleteEntryPermission() -
hasConfigurePermission
protected abstract boolean hasConfigurePermission()Returns whether the current user may read configurations in the object returned bygetAccessControlledObject()
.- Returns:
- true if the current user may read configurations.
-
getRevisionAmount
public abstract int getRevisionAmount()- Returns:
- the amount of revisions existing for the given request (not page-dependant).
-
getAccessControlledObject
Returns the object for which we want to provide access control.- Returns:
- the access controlled object.
-
getDiffLines
Returns side-by-side (i.e. human-readable) diff view lines.- Parameters:
diffLines
- Unified diff as list of Strings.- Returns:
- Nice and clean diff as list of single Lines. if reading one of the config files does not succeed.
-
getDiffAsString
protected final String getDiffAsString(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
-
getShowVersionDiffs
Get the current request's 'showVersionDiffs'-parameter. If there is none, "True" is returned.- Returns:
- true if the current request has set this parameter to true or not at all.
false else
-
getLines
Returns the diff between two config files as a list of single lines. Takes the two timestamps and the name of the system property or the deleted job from the url parameters.- Returns:
- Differences between two config versions as list of lines.
- Throws:
IOException
- If diff doesn't work or xml files can't be read.
-
getLines
- Throws:
IOException
-
getDiffAsString
protected final String getDiffAsString(File file1, File file2, String[] file1Lines, String[] file2Lines, boolean hideVersionDiffs) Returns a unified diff between two string arrays representing an xml file. The order of elements in the xml file is NOT ignored.- Parameters:
file1
- first config file.file2
- second config file.file1Lines
- the lines of the first file.file2Lines
- the lines of the second file.hideVersionDiffs
- determines whether version diffs shall be shown or not.- Returns:
- unified diff
-
getRelevantPageNums
- Parameters:
currentPageNum
- the current page number- Returns:
- the same as
getRelevantPageNums(int, int)
, usinggetMaxPageNum()
as second parameter.
-
getRelevantPageNums
- Parameters:
currentPageNum
- the current page numbermaxPageNum
- the highest page number- Returns:
- a list representing all page navigation entries which are displayed. These include:
- 0
- maxPageNum
- all integers in {k in [currentPageNum - PAGING_EPSILON, currentPageNum + PAGING_EPSILON] | k > 0 && k < maxPageNum}.
-
getMaxEntriesPerPage
public int getMaxEntriesPerPage()- Returns:
- the configured maximum entries per page.
-
getMaxPageNum
public int getMaxPageNum()- Returns:
- the maximum page number given this request's number of entries per page and the revision amount.
-
doDiffFiles
public 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 requestrsp
- outgoing response- Throws:
javax.servlet.ServletException
- when parsing the request asMultipartFormDataParser
does not succeed.IOException
- when the redirection does not succeed.
-
doDiffFilesPrevNext
public final void doDiffFilesPrevNext(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException Action when 'Prev' or 'Next' button in showDiffFiles.jelly is pressed. Forwards to the previous or next diff.- Parameters:
req
- StaplerRequest created by pressing the buttonrsp
- Outgoing StaplerResponse- Throws:
IOException
- If XML file can't be read
-
getCurrentRequest
protected org.kohsuke.stapler.StaplerRequest getCurrentRequest()Overridable for tests.- Returns:
- current request
-
getPlugin
Returns the plugin for tests.- Returns:
- plugin
-
getHistoryDao
For tests.- Returns:
- historyDao
-
getLines
protected final List<SideBySideView.Line> getLines(XmlFile leftConfig, XmlFile rightConfig, boolean hideVersionDiffs) throws IOException Takes the two config files and returns the diff between them as a list of single lines.- Parameters:
leftConfig
- first config filerightConfig
- second config file- Returns:
- Differences between two config versions as list of lines.
- Throws:
IOException
- If diff doesn't work or xml files can't be read.
-