Class VManagerChartsUtil

java.lang.Object
org.jenkinsci.plugins.vmanager.charts.util.VManagerChartsUtil

public final class VManagerChartsUtil extends Object
Utility helpers for the vManager Charts plugin.

Centralises:

  • Building the conventional session-input filename (${BUILD_NUMBER}.${BUILD_ID}.sessions.input).
  • Resolving the actual file location given the user's session source choice and (optionally) custom path. The result is a FilePath so that reads work transparently on a remote agent (Linux or Windows).
  • Reading the file contents into a list of session names (one per non-blank, non-#-comment line).

The class is final with a private constructor — it is a pure collection of static helpers and is not intended to be instantiated.

  • Field Details

    • SESSIONS_INPUT_SUFFIX

      public static final String SESSIONS_INPUT_SUFFIX
      Suffix used for the conventional per-build session-input file.
      See Also:
    • SESSION_LAUNCH_OUTPUT_SUFFIX

      public static final String SESSION_LAUNCH_OUTPUT_SUFFIX
      Suffix of the per-build file dropped by the vManager Jenkins Plugin (launch mode) listing the IDs of the sessions it just kicked off. Used as a fallback when SESSIONS_INPUT_SUFFIX is missing.
      See Also:
  • Method Details

    • checkDescriptorPermission

      public static void checkDescriptorPermission(Item item)
      Enforce that the caller has permission to invoke a descriptor's doCheckXxx / doFillXxxItems method.

      For Item-scoped descriptors (the model classes in this plugin live under a job's config page), Item.CONFIGURE is the appropriate permission — the same one Jenkins requires to even open the page on which these endpoints are surfaced. When the descriptor is invoked outside an item context (e.g. the global descriptorByName URL), we fall back to Jenkins.ADMINISTER.

      This is paired with @POST on each endpoint to ensure the call is CSRF-protected. The method throws AccessDeniedException when the caller lacks the required permission.

    • defaultSessionsFileName

      public static String defaultSessionsFileName(Run<?,?> run)
      Returns:
      the conventional file name for this run, e.g. 42.42.sessions.input.
    • defaultSessionLaunchOutputFileName

      public static String defaultSessionLaunchOutputFileName(Run<?,?> run)
      Returns:
      the conventional fallback file name for this run, e.g. 42.42.session_launch.output — a list of session ids produced by the vManager Jenkins Plugin in launch mode.
    • resolveSessionLaunchOutputFile

      public static FilePath resolveSessionLaunchOutputFile(Run<?,?> run, FilePath sessionsInputFile, FilePath workspace)
      Resolves the FilePath of the fallback .session_launch.output file. We place it next to the resolved sessions-input file (so a custom user path's directory is honoured); if no input file is known we fall back to the workspace root.
      Returns:
      the FilePath that should contain the session ids (the file may or may not actually exist), or null when neither a sessions-input file nor a workspace is available.
    • getCurrentWorkspace

      public static FilePath getCurrentWorkspace(Run<?,?> run)
      Best-effort lookup of the directory where the vManager Jenkins Plugin (or a user-supplied pipeline step) is expected to drop the .sessions.input / .session_launch.output files.

      For freestyle (AbstractBuild) jobs this is the build's agent workspace.

      For Pipeline jobs there is no single workspace for the whole build, and walking the flow graph to find node { } workspaces is unreliable (the node block may have ended by the time we run, agents may be offline, etc.). Instead, for pipeline runs we return the build's controller-side directory (Run.getRootDir(), i.e. the directory that holds the build log) wrapped as a local FilePath. Pipeline users are expected to copy / archive the input files there explicitly (e.g. via archiveArtifacts or writeFile on the controller).

    • resolveSessionsInputFile

      public static FilePath resolveSessionsInputFile(Run<?,?> run, FilePath workspace, String sessionSource, String userPath)
      Resolves the FilePath of the sessions input file for this build, applying the rules described on VManagerChartsJobProperty.getSessionSource():
      • PLUGIN (default) — file is in the build workspace and is named per defaultSessionsFileName(Run).
      • FILE with empty path — same as PLUGIN.
      • FILE with a non-empty path — that path is used. Absolute paths are resolved on the same node/channel as the workspace. Relative paths are resolved against the workspace.
      Returns:
      the FilePath that should contain the session names (the file may or may not actually exist), or null if no workspace is available and no absolute path was given.
    • readSessionNames

      public static List<String> readSessionNames(FilePath file) throws IOException, InterruptedException
      Reads session names from the resolved file. Empty lines and lines starting with # are skipped.
      Returns:
      an immutable list of session names (possibly empty); never null.
      Throws:
      IOException
      InterruptedException
    • readSessionNames

      public static List<String> readSessionNames(Run<?,?> run, FilePath workspace, String sessionSource, String userPath) throws IOException, InterruptedException
      Convenience: resolve and read in one call.
      Throws:
      IOException
      InterruptedException