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 in a separate Jenkins view. Optionally, highlights a marker
in the source code: either a line, some characters in a line, or a multi-line block.
- Author:
- Ullrich Hafner
-
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.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.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
-
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
-
create(Run, String, Reader, Marker)instead