Class ArtifactTree

java.lang.Object
io.jenkins.plugins.artifactexplorer.ArtifactTree

public final class ArtifactTree extends Object
Read-only view of a build's archived artifacts (or controller userContent), built on ArtifactManager.root() / VirtualFile so it works for any artifact manager (local disk, S3, ...). All paths handled here are relative to the artifact root and use / as the separator.
  • Method Details

    • sanitize

      @NonNull public static String sanitize(String raw)
      Validates and normalizes a user supplied relative path.
      Parameters:
      raw - path as received from the client, may be null
      Returns:
      the normalized path without leading or trailing slash ("" for the root)
      Throws:
      IllegalArgumentException - if the path tries to escape the artifact root
    • children

      public static ArtifactTree.Listing<ArtifactTree.Entry> children(Run<?,?> run, String path, int limit) throws IOException
      Lists the direct children of a directory, directories first, then by case-insensitive name.
      Parameters:
      limit - maximum number of entries to return
      Returns:
      the listing, or null if path is not a directory inside the artifact root
      Throws:
      IOException
    • children

      public static ArtifactTree.Listing<ArtifactTree.Entry> children(@CheckForNull VirtualFile root, String path, int limit) throws IOException
      Lists the direct children of a directory under a VirtualFile root.
      Throws:
      IOException
    • allFiles

      public static ArtifactTree.Listing<String> allFiles(Run<?,?> run, int limit) throws IOException
      Lists every file (not directory) in the build's artifacts as relative paths, for client side search.
      Parameters:
      limit - maximum number of paths to return
      Throws:
      IOException
    • allFiles

      public static ArtifactTree.Listing<String> allFiles(@CheckForNull VirtualFile root, int limit) throws IOException
      Lists every file (not directory) under a VirtualFile root as relative paths.
      Throws:
      IOException
    • preview

      @CheckForNull public static ArtifactTree.FilePreview preview(Run<?,?> run, String path, int maxBytes) throws IOException
      Reads a bounded preview of a single artifact file.
      Parameters:
      maxBytes - maximum number of bytes to read when decoding text
      Returns:
      the preview, or null if path does not refer to a readable file inside the artifact root
      Throws:
      IOException
    • preview

      @CheckForNull public static ArtifactTree.FilePreview preview(@CheckForNull VirtualFile root, String path, int maxBytes) throws IOException
      Reads a bounded preview of a single file under a VirtualFile root.
      Throws:
      IOException
    • sha256

      @CheckForNull public static String sha256(Run<?,?> run, String path, long maxBytes) throws IOException
      Computes the lowercase SHA-256 hex digest of a single artifact file.

      The digest is computed on the controller so the browser never has to fetch artifact bytes itself, which keeps the explorer working when artifacts are served from a separate Resource Root URL.

      Parameters:
      maxBytes - largest file size that will be hashed
      Returns:
      the 64-character lowercase hex digest, or null if path does not refer to a readable file inside the artifact root
      Throws:
      ArtifactTree.TooLargeException - if the file is larger than maxBytes
      IOException
    • sha256

      @CheckForNull public static String sha256(@CheckForNull VirtualFile root, String path, long maxBytes) throws IOException
      Computes the lowercase SHA-256 hex digest of a single file under a VirtualFile root.
      Throws:
      IOException