Class RepositoryUrlFragment
Namespaces no longer serve any practical purpose in Bitbucket, but this class is still able to parse URLs with a namespace component.
Namespaces were required in the past to enable Bitbucket Mirrors to support mirroring multiple upstreams. To uniquify project/repository coordinates a namespace component was included in the Git URLs. Bitbucket provided clone URLs that included the namespace component for all users who used mirrors, regardless as to if multiple upstreams were used. In fact it was a rarely used feature.
Support for multiple upstreams was removed from Bitbucket, but so as not to break clients that used namespaced URLs the parser code continues to tolerate the namespace component, but always discards it as it no longer serves a purpose.
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.
-
Method Summary
Modifier and TypeMethodDescriptionstatic RepositoryUrlFragment
fromKeyAndSlug
(String projectKey, String repositorySlug) static RepositoryUrlFragment
fromNamespacedPathInfo
(String pathInfo) Deprecated.static RepositoryUrlFragment
fromPathInfo
(String pathInfo) Extracts the repository URL fragment from the given path info.static RepositoryUrlFragment
fromRepository
(com.atlassian.bitbucket.repository.Repository repository) Formats this fragment as a path suitable for use with aURI
, such as withURI.resolve(String)
, optionally pre-pending a provided base path.Formats this fragment as a path suitable for use with aURI
, such as withURI.resolve(String)
, optionally pre-pending a provided base path.toString()
-
Method Details
-
fromPathInfo
Extracts the repository URL fragment from the given path info.- Parameters:
pathInfo
- the path info as provided by theHttpServletRequest.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
-
fromNamespacedPathInfo
@Deprecated @Nullable public static RepositoryUrlFragment fromNamespacedPathInfo(@Nonnull String pathInfo) Deprecated.in 7.18 usefromPathInfo(String)
instead, unless when checking for namespaced URLs on mirrorsExtracts the namespaced repository URL fragment from the given path info. On Mirrors, this method must be used iffromPathInfo(String)
does not return a valid repository.- Parameters:
pathInfo
- the path info as provided by theHttpServletRequest.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- Since:
- 4.2
-
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 userepositorySlug
- the repository slug to use- Returns:
- a URL fragment for the specified projectKey and repositorySlug
- Since:
- 6.7
-
getPathSuffix
- Returns:
- the suffix after the namespace / project key / repository part of the path or null if there was none
- Since:
- 5.1
-
getProjectKey
-
getRepositorySlug
-
toPath
Formats this fragment as a path suitable for use with aURI
, such as withURI.resolve(String)
, optionally pre-pending a provided base path. Thepath suffix
nor the .git extension if present in the original path are output here.- Parameters:
basePath
- the base path to prepend, ornull
- Returns:
- a URI-suitable path
-
toPath
Formats this fragment as a path suitable for use with aURI
, such as withURI.resolve(String)
, optionally pre-pending a provided base path. Thepath suffix
is included if theincludeSuffix
parameter istrue
.- Parameters:
basePath
- the base path to prepend, ornull
includeSuffix
- whether to include the suffix- Returns:
- a URI-suitable path
- Since:
- 7.18
-
toString
-
fromPathInfo(String)
instead, unless when checking for namespaced URLs on mirrors