Class ItemPathResolver

java.lang.Object
hudson.plugins.promoted_builds.util.ItemPathResolver

public class ItemPathResolver extends Object
Implements an engine, which allows to resolve Items by their paths. The engine supports both relative and absolute addressing.
Since:
2.22
Author:
Oleg Nenashev
  • Constructor Details

    • ItemPathResolver

      public ItemPathResolver()
  • Method Details

    • isEnableLegacyResolutionAgainstRoot

      public static boolean isEnableLegacyResolutionAgainstRoot()
      Check if the legacy path resolution mode is enabled. The resolution uses available ItemPathResolver.ResolverManagers and falls back to ENABLE_LEGACY_RESOLUTION_AGAINST_ROOT if there is no decision.
      Returns:
      True if the legacy resolution engine is enabled
    • getByPath

      @CheckForNull @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static <T extends Item> T getByPath(@NonNull String path, @CheckForNull Item baseItem, @NonNull Class<T> type)
      Gets an Item of the specified type by absolute or relative path.

      The implementation retains the original behavior in PromotedBuildParameterDefinition, but this method also provides a support of multi-level addressing including special markups for the relative addressing.

      Effectively, the resolution order is following:
      • Optional Legacy behavior, which can be enabled by ENABLE_LEGACY_RESOLUTION_AGAINST_ROOT. If an item for the name exists on the top Jenkins level, it will be returned
      • If the path starts with "/", a global addressing will be used
      • If the path starts with "./" or "../", a relative addressing will be used
      • If there is no prefix, a relative addressing will be tried. If it fails, the method falls back to a global one
      For the relative and absolute addressing the engine supports "." and ".." markers within the path. The first one points to the current element, the second one - to the upper element. If the search cannot get a new top element (e.g. reached the root), the method returns null.
      Type Parameters:
      T - Type of the Item to be retrieved
      Parameters:
      path - Path string to the item.
      baseItem - Base Item for the relative addressing. If null, this addressing approach will be skipped
      type - Type of the Item to be retrieved
      Returns:
      Found Item. Null if it has not been found by all addressing modes or the type differs.