Class ArtifactTree
java.lang.Object
io.jenkins.plugins.artifactexplorer.ArtifactTree
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordOne file or directory directly under a directory.static final recordPreview metadata, bounded UTF-8 text content, and optional CommonMark HTML for a single artifact file.static final recordResult of a (possibly truncated) listing.static final classThrown bysha256(Run, String, long)when a file is larger than the allowed limit. -
Method Summary
Modifier and TypeMethodDescriptionstatic ArtifactTree.Listing<String> Lists every file (not directory) in the build's artifacts as relative paths, for client side search.static ArtifactTree.Listing<String> allFiles(VirtualFile root, int limit) Lists every file (not directory) under aVirtualFileroot as relative paths.Lists the direct children of a directory, directories first, then by case-insensitive name.children(VirtualFile root, String path, int limit) Lists the direct children of a directory under aVirtualFileroot.static ArtifactTree.FilePreviewReads a bounded preview of a single artifact file.static ArtifactTree.FilePreviewpreview(VirtualFile root, String path, int maxBytes) Reads a bounded preview of a single file under aVirtualFileroot.static StringValidates and normalizes a user supplied relative path.static StringComputes the lowercase SHA-256 hex digest of a single artifact file.static Stringsha256(VirtualFile root, String path, long maxBytes) Computes the lowercase SHA-256 hex digest of a single file under aVirtualFileroot.
-
Method Details
-
sanitize
Validates and normalizes a user supplied relative path.- Parameters:
raw- path as received from the client, may benull- 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 IOExceptionLists 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
nullifpathis 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 aVirtualFileroot.- Throws:
IOException
-
allFiles
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 aVirtualFileroot as relative paths.- Throws:
IOException
-
preview
@CheckForNull public static ArtifactTree.FilePreview preview(Run<?, ?> run, String path, int maxBytes) throws IOExceptionReads a bounded preview of a single artifact file.- Parameters:
maxBytes- maximum number of bytes to read when decoding text- Returns:
- the preview, or
nullifpathdoes 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 aVirtualFileroot.- Throws:
IOException
-
sha256
@CheckForNull public static String sha256(Run<?, ?> run, String path, long maxBytes) throws IOExceptionComputes 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
nullifpathdoes not refer to a readable file inside the artifact root - Throws:
ArtifactTree.TooLargeException- if the file is larger thanmaxBytesIOException
-
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 aVirtualFileroot.- Throws:
IOException
-