Package io.jenkins.plugins.prism
Class SourceCodeViewModel
java.lang.Object
io.jenkins.plugins.prism.SourceCodeViewModel
- All Implemented Interfaces:
ModelObject
Renders a source code file with Prism syntax highlighting. Optionally, highlights an arbitrary number of markers in
the source code: each marker is either a line, some characters in a line, or a multi-line block. The details of
each marker (title, description, and icon) are shown in a box after the last line of the marker.
The model can be shown as a separate Jenkins view (see index.jelly), or it can be embedded into the view of
another model by including the fragment content.jelly, e.g.,
<st:include it="${it.sourceCode}" page="content.jelly"/>. The fragment is available for the
PermissionDeniedViewModel as well, so the result of the factory methods can be embedded directly.
A marker can be selected using the fragment of the URL: either the ID of the marker (see
Marker.MarkerBuilder.withId(String)) or a line number. A selected marker is highlighted, its description
is expanded, and the view scrolls to the marker. If there is only one marker, then this marker is selected
automatically.
- Author:
- Ullrich Hafner
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCreates the view model of a source code view with additional options. -
Constructor Summary
ConstructorsConstructorDescriptionSourceCodeViewModel(Run<?, ?> owner, String fileName, Reader sourceCodeReader, Marker marker) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionstatic ModelObjectCreates a source code view model or a permission-denied view model based on the user's permissions.static ModelObjectCreates a source code view model or a permission-denied view model based on the user's permissions.Run<?, ?> getOwner()Returns the build as the owner of this view.Returns the colorized source code.static booleanhasPermissionToViewSourceCode(Run<?, ?> owner) Checks if the current user has permission to view source code.booleanReturns whether long sections of lines without markers are collapsed in the view.static ModelObjectprotectedSourceCodeView(ModelObject view, Run<?, ?> owner, String fileName) Protects a source code view by checking permissions.
-
Constructor Details
-
SourceCodeViewModel
@Deprecated public SourceCodeViewModel(Run<?, ?> owner, String fileName, Reader sourceCodeReader, Marker marker) Deprecated.usecreate(Run, String, Reader, Marker)insteadCreates a new source code view model instance.- Parameters:
owner- the current build as the owner of this viewfileName- the file name of the shown contentsourceCodeReader- the source code file to show, provided by aReaderinstancemarker- a block of lines (or a part of a line) to mark in the source code view
-
-
Method Details
-
hasPermissionToViewSourceCode
Checks if the current user has permission to view source code.- Parameters:
owner- the current build as the owner of the view- Returns:
trueif the user has permission,falseotherwise
-
protectedSourceCodeView
public static ModelObject protectedSourceCodeView(ModelObject view, Run<?, ?> owner, String fileName) Protects a source code view by checking permissions.- Parameters:
view- the source code view to protectowner- the current build as the owner of the viewfileName- the name of the file being viewed- Returns:
- the protected view (either original view or
PermissionDeniedViewModel)
-
create
public static ModelObject create(Run<?, ?> owner, String fileName, Reader sourceCodeReader, Marker marker) Creates a source code view model or a permission-denied view model based on the user's permissions. This is the recommended way to create a view model as it checks permissions before rendering source code.- Parameters:
owner- the current build as the owner of this viewfileName- the file name of the shown contentsourceCodeReader- the source code file to show, provided by aReaderinstancemarker- a block of lines (or a part of a line) to mark in the source code view- Returns:
- a
SourceCodeViewModelif permission is granted, or aPermissionDeniedViewModelotherwise
-
create
public static ModelObject create(Run<?, ?> owner, String fileName, Reader sourceCodeReader, List<Marker> markers) Creates a source code view model or a permission-denied view model based on the user's permissions. The view model highlights all specified markers.- Parameters:
owner- the current build as the owner of this viewfileName- the file name of the shown contentsourceCodeReader- the source code file to show, provided by aReaderinstancemarkers- the blocks of lines (or parts of lines) to mark in the source code view, may be empty- Returns:
- a
SourceCodeViewModelif permission is granted, or aPermissionDeniedViewModelotherwise
-
getPrismConfiguration
-
getDisplayName
- Specified by:
getDisplayNamein interfaceModelObject
-
getOwner
Returns the build as the owner of this view.- Returns:
- the build
-
getSourceCode
Returns the colorized source code.- Returns:
- the source code
-
isCollapsible
public boolean isCollapsible()Returns whether long sections of lines without markers are collapsed in the view. The lines around the markers are still visible, and the collapsed sections can be expanded by the user.- Returns:
trueif the sections without markers are collapsed,falseif all lines are visible
-
create(Run, String, Reader, Marker)instead