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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidSee whether the current user may read configurations in the object returned bygetAccessControlledObject().protected abstract voidprotected booleancheckTimestamp(String timestamp) Checks the url parameter 'timestamp' and returns true if it is parseable as a date.voiddoDiffFiles(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) Parses the incoming POST request and redirects as GET showDiffFiles.final voiddoDiffFilesPrevNext(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) Action when 'Prev' or 'Next' button in showDiffFiles.jelly is pressed.protected abstract AccessControlledReturns the object for which we want to provide access control.protected org.kohsuke.stapler.StaplerRequest2Overridable for tests.protected final StringgetDiffAsString(File file1, File file2, String[] file1Lines, String[] file2Lines) Returns a unified diff between two string arrays.protected final StringgetDiffAsString(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 HistoryDaoFor 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.intintfinal StringReturns how the config file should be formatted in configOutput.jelly: as plain text or xml.protected JobConfigHistoryReturns the plugin for tests.getRelevantPageNums(int currentPageNum) getRelevantPageNums(int currentPageNum, int maxPageNum) protected StringgetRequestParameter(String parameterName) Returns the parameter namedparameterNamefrom current request.abstract intGet the current request's 'showVersionDiffs'-parameter.abstract booleanprotected abstract booleanReturns whether the current user may read configurations in the object returned bygetAccessControlledObject().abstract booleanMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface hudson.model.Action
getIconFileName
-
Constructor Details
-
JobConfigHistoryBaseAction
public JobConfigHistoryBaseAction()
-
-
Method Details
-
getDisplayName
- Specified by:
getDisplayNamein interfaceAction- Specified by:
getDisplayNamein interfaceModelObject
-
getUrlName
- Specified by:
getUrlNamein 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 namedparameterNamefrom 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.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws jakarta.servlet.ServletException, IOException Parses the incoming POST request and redirects as GET showDiffFiles.- Parameters:
req- incoming requestrsp- outgoing response- Throws:
jakarta.servlet.ServletException- when parsing the request asMultipartFormDataParserdoes not succeed.IOException- when the redirection does not succeed.
-
doDiffFilesPrevNext
public final void doDiffFilesPrevNext(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException Action when 'Prev' or 'Next' button in showDiffFiles.jelly is pressed. Forwards to the previous or next diff.- Parameters:
req- StaplerRequest2 created by pressing the buttonrsp- Outgoing StaplerResponse2- Throws:
IOException- If XML file can't be read
-
getCurrentRequest
protected org.kohsuke.stapler.StaplerRequest2 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.
-