public class

RepositoryUrlFragment

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

Class Overview

Utility class for parsing project namespaces, 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_NAMESPACE/PROJECT_KEY/REPOSITORY_SLUG/
  • <baseUrl>/PROJECT_KEY/REPOSITORY_SLUG.git/ (the .git suffix is not captured)
  • <baseUrl>/PROJECT_NAMESPACE/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.

Summary

Public Methods
@Nullable static RepositoryUrlFragment fromNamespacedPathInfo(String pathInfo)
Extracts the namespaced repository URL fragment from the given path info.
@Nullable static RepositoryUrlFragment fromPathInfo(String pathInfo)
Extracts the repository URL fragment from the given path info.
@Nonnull static RepositoryUrlFragment fromRepository(Repository repository)
@Nullable String getPathSuffix()
@Nonnull String getProjectKey()
@Nullable String getProjectNamespace()
@Nonnull String getRepositorySlug()
@Nonnull String toPath(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.
@Nonnull String toString()
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

@Nullable public static RepositoryUrlFragment fromNamespacedPathInfo (String pathInfo)

Extracts the namespaced repository URL fragment from the given path info.

Parameters
pathInfo the path info as provided by the getPathInfo() method.
Returns
  • a new repository URL fragment, or null if the path info does not contain a namespaced repository URL fragment
Throws
NullPointerException if the path info is null

@Nullable public static RepositoryUrlFragment fromPathInfo (String pathInfo)

Extracts the repository URL fragment from the given path info.

Parameters
pathInfo the path info as provided by the 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

@Nonnull public static RepositoryUrlFragment fromRepository (Repository repository)

Parameters
repository the repository to create a fragment for
Returns
  • a URL fragment for the specified repository

@Nullable public String getPathSuffix ()

Returns
  • the suffix after the namespace / project key / repository part of the path or null if there was none

@Nonnull public String getProjectKey ()

@Nullable public String getProjectNamespace ()

@Nonnull public String getRepositorySlug ()

@Nonnull public String toPath (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

@Nonnull public String toString ()

Returns