Class SourceCodeViewModel

java.lang.Object
io.jenkins.plugins.prism.SourceCodeViewModel
All Implemented Interfaces:
ModelObject

public class SourceCodeViewModel extends Object implements 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 Details

    • SourceCodeViewModel

      @Deprecated public SourceCodeViewModel(Run<?,?> owner, String fileName, Reader sourceCodeReader, Marker marker)
      Deprecated.
      Creates a new source code view model instance.
      Parameters:
      owner - the current build as the owner of this view
      fileName - the file name of the shown content
      sourceCodeReader - the source code file to show, provided by a Reader instance
      marker - a block of lines (or a part of a line) to mark in the source code view
  • Method Details

    • hasPermissionToViewSourceCode

      public static boolean hasPermissionToViewSourceCode(Run<?,?> owner)
      Checks if the current user has permission to view source code.
      Parameters:
      owner - the current build as the owner of the view
      Returns:
      true if the user has permission, false otherwise
    • 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 protect
      owner - the current build as the owner of the view
      fileName - 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 view
      fileName - the file name of the shown content
      sourceCodeReader - the source code file to show, provided by a Reader instance
      marker - a block of lines (or a part of a line) to mark in the source code view
      Returns:
      a SourceCodeViewModel if permission is granted, or a PermissionDeniedViewModel otherwise
    • getPrismConfiguration

      public PrismConfiguration getPrismConfiguration()
    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in interface ModelObject
    • getOwner

      public Run<?,?> getOwner()
      Returns the build as the owner of this view.
      Returns:
      the build
    • getSourceCode

      public String getSourceCode()
      Returns the colorized source code.
      Returns:
      the source code