Class RepositoryUrlFragment

java.lang.Object
com.atlassian.bitbucket.scm.http.RepositoryUrlFragment

public class RepositoryUrlFragment extends Object
Utility class for parsing project keys and repository slugs from scm urls - HTTP and SSH.

This class only works with paths that begin with:

  • <baseUrl>/PROJECT_KEY/REPOSITORY_SLUG/
  • <baseUrl>/PROJECT_KEY/REPOSITORY_SLUG.git/ (the .git suffix is not captured)

This class captures any path suffix that did not describe the repository but still may be useful to identify.

  • Method Details

    • fromPathInfo

      @Nullable public static RepositoryUrlFragment fromPathInfo(@Nonnull String pathInfo)
      Extracts the repository URL fragment from the given path info.
      Parameters:
      pathInfo - the path info as provided by the HttpServletRequest.getPathInfo() method.
      Returns:
      a new repository URL fragment, or null if the path info does not contain a repository URL fragment
      Throws:
      NullPointerException - if the path info is null
    • fromRepository

      @Nonnull public static RepositoryUrlFragment fromRepository(@Nonnull com.atlassian.bitbucket.repository.Repository repository)
      Parameters:
      repository - the repository to create a fragment for
      Returns:
      a URL fragment for the specified repository
    • fromKeyAndSlug

      @Nonnull public static RepositoryUrlFragment fromKeyAndSlug(@Nonnull String projectKey, @Nonnull String repositorySlug)
      Parameters:
      projectKey - the project key to use
      repositorySlug - the repository slug to use
      Returns:
      a URL fragment for the specified projectKey and repositorySlug
      Since:
      6.7
    • getPathSuffix

      @Nullable public String getPathSuffix()
      Returns:
      the suffix after the project key / repository part of the path or null if there was none
      Since:
      5.1
    • getProjectKey

      @Nonnull public String getProjectKey()
    • getRepositorySlug

      @Nonnull public String getRepositorySlug()
    • toPath

      @Nonnull public String toPath(@Nullable String basePath)
      Formats this fragment as a path suitable for use with a URI, such as with URI.resolve(String), optionally pre-pending a provided base path. The path suffix nor the .git extension if present in the original path are output here.
      Parameters:
      basePath - the base path to prepend, or null
      Returns:
      a URI-suitable path
    • toPath

      @Nonnull public String toPath(@Nullable String basePath, boolean includeSuffix)
      Formats this fragment as a path suitable for use with a URI, such as with URI.resolve(String), optionally pre-pending a provided base path. The path suffix is included if the includeSuffix parameter is true.
      Parameters:
      basePath - the base path to prepend, or null
      includeSuffix - whether to include the suffix
      Returns:
      a URI-suitable path
      Since:
      7.18
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object
      Returns:
      KEY/slug for URLs on primary instances and mirrors