Package io.jenkins.plugins.prism
Class SourceCodeViewModel.Builder
java.lang.Object
io.jenkins.plugins.prism.SourceCodeViewModel.Builder
- Enclosing class:
SourceCodeViewModel
Creates the view model of a source code view with additional options. By default, the whole content is shown,
the content is colorized based on the file name, and the permission to view source code is checked.
Example: the excerpt of a console log with some markers, as plain text, without the check of the permission to view the workspace (the console log is not part of the workspace):
var view = new SourceCodeViewModel.Builder(build, "Console Output")
.withMarkers(markers)
.withPlainText()
.withExcerpt(120, 160)
.withoutPermissionCheck()
.build(consoleLines);
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates the view model for the content of the specified reader.Creates the view model for the specified lines.withExcerpt(int from, int to) Shows only an excerpt of the content.withLineAnnotations(List<LineAnnotation> annotations) Defines the annotations of the lines.withMarkers(List<Marker> markers) Defines the markers to show.Shows all lines of the content.Skips the check of the permission to view the source code of the workspace (seeSourceCodeViewModel.hasPermissionToViewSourceCode(Run)).Shows the content as plain text, without syntax highlighting.
-
Constructor Details
-
Builder
Creates a new builder.- Parameters:
owner- the current build as the owner of the viewfileName- the file name of the shown content, used to select the language of the syntax highlighting
-
-
Method Details
-
withMarkers
Defines the markers to show. The lines of the markers refer to the whole content, even if only an excerpt is shown.- Parameters:
markers- the markers- Returns:
- this builder
-
withLineAnnotations
Defines the annotations of the lines. The annotations are shown in a separate column between the line numbers and the code, e.g., to show the number of covered branches of each line. If there are several annotations for the same line, then the last one is shown. Annotations of lines outside the shown content are skipped.- Parameters:
annotations- the annotations of the lines- Returns:
- this builder
-
withPlainText
Shows the content as plain text, without syntax highlighting.- Returns:
- this builder
-
withExcerpt
Shows only an excerpt of the content. The lines keep their line numbers. Markers before the excerpt are shown before its first line, markers after the excerpt after its last line.- Parameters:
from- the first line of the excerpt (1-based)to- the last line of the excerpt (1-based, inclusive)- Returns:
- this builder
-
withoutPermissionCheck
Skips the check of the permission to view the source code of the workspace (seeSourceCodeViewModel.hasPermissionToViewSourceCode(Run)). Use this option only for content that is not part of the workspace (e.g., the console log of a build). The caller is responsible to check that the current user is allowed to see the content.- Returns:
- this builder
-
withoutCollapsing
Shows all lines of the content. By default, long sections of lines without markers are collapsed, and only the lines around the markers are visible.- Returns:
- this builder
-
build
Creates the view model for the content of the specified reader.- Parameters:
reader- the content to show- Returns:
- a
SourceCodeViewModel, or aPermissionDeniedViewModelif the permission is checked and the user is not allowed to view source code
-
build
Creates the view model for the specified lines.- Parameters:
lines- the lines of the content to show- Returns:
- a
SourceCodeViewModel, or aPermissionDeniedViewModelif the permission is checked and the user is not allowed to view source code
-