Package jenkins.scm.api
Class SCMCategory<T>
java.lang.Object
jenkins.scm.api.SCMCategory<T>
- Type Parameters:
T
- the type of thing.
- Direct Known Subclasses:
SCMHeadCategory
,SCMSourceCategory
Base class for categories of SCM things.
A rose by any other name would smell as sweet?Naming things is hard. Naming things related to a source control system is even harder. It would be really nice if all the source control systems could agree on a standard set or terminologies for how to name things to do with source control systems. You are reading this and thinking "but how bad can it be?":
- Git - Git uses the following terminology:
- Each versioned tree of source files in Git is called a "Commit"
- The collection of semi-related commits in Git is called a "Repository"
- Each commit has a history of previous commits. Each Git repository has a collection of references to commits. Mutable references are called "Branches". Immutable references are called "Tags"
- The remote place where all the Git repositories are kept is called a "Server"
- AccuRev - AccuRev uses the following terminology:
- Accurev tracks a tree of files, each file has a "Version"
- Each tree of files starts from a single initiation point and that tree's multiple evolutions are all tracked in a single "Depot"
- Each depot has a collection of references to version states of the tree at different points in time. Mutable references are called "Streams". Immutable references are called "Snapshots"
- The remote place where all the Accurev depots are kept is called a "Repository"
- Subversion - Subversion is really a versioned filesystem and people use conventions to do
source control with the versioned
file system.
There are two common conventions:
- Keep one project per repository
- Keep multiple projects per repository, each with their own sub-tree
trunk
/branches/___
/tags/___
structure for each project.So, if following conventions you might have "commits"; "trunk", "branches" and "tags"; "projects" or "repositories"; and "repositories" or "servers"
For example:
- A GitHub implementation of the SCM API might return "Branches", "Pull Requests", and "Tags" as the different
types of
SCMHead
discovered by itsSCMSource
. It might return "Repositories" and "Forks" as the different types of project discovered by itsSCMNavigator
.
SCMHeadCategory
is used to categorizeSCMHead
instances returned by aSCMSource
SCMSourceCategory
is used to categorizeSCMSource
instances returned by aSCMNavigator
- Since:
- 2.0
-
Constructor Summary
ConstructorDescriptionSCMCategory
(String name, org.jvnet.localizer.Localizable displayName) Constructs a named category with the specified display name.SCMCategory
(org.jvnet.localizer.Localizable displayName) Constructs an uncategorized category with the specified display name. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract org.jvnet.localizer.Localizable
The default display name.org.jvnet.localizer.Localizable
Get the term used in the UI to represent a collection of things in this kind ofSCMCategory
.final String
getName()
Gets the url path component to use when building URLs from categories.static <T,
C extends SCMCategory<T>>
Map<String,List<C>> group
(C... categories) Partitions a list ofSCMCategory
instances bygetName()
.static <T,
C extends SCMCategory<T>>
Map<String,List<C>> Partitions a collection ofSCMCategory
instances bygetName()
.abstract boolean
Checks if the supplied instance is a match for thisSCMCategory
.boolean
isMatch
(T instance, Iterable<? extends SCMCategory<T>> categories) Checks if the supplied instance is a match for thisSCMCategory
.final boolean
Checks if this is the uncategorized category.static <C extends SCMCategory<?>>
org.jvnet.localizer.LocalizabletoDisplayName
(C... categories) Gets the composite display name for a collection ofSCMCategory
instances.static <C extends SCMCategory<?>>
org.jvnet.localizer.LocalizabletoDisplayName
(List<C> categories) Gets the composite display name for a collection ofSCMCategory
instances.static <C extends SCMCategory<?>>
StringtoShortUrl
(C... categories) Gets the composite short url name for a collection ofSCMCategory
instances.static <C extends SCMCategory<?>>
StringtoShortUrl
(List<C> categories) Gets the composite short url name for a collection ofSCMCategory
instances.
-
Constructor Details
-
SCMCategory
public SCMCategory(@CheckForNull org.jvnet.localizer.Localizable displayName) Constructs an uncategorized category with the specified display name.- Parameters:
displayName
- the display name.
-
SCMCategory
Constructs a named category with the specified display name.- Parameters:
name
- the name of the category. This will likely be used as a path component in building URLsdisplayName
- the display name.- Throws:
IllegalArgumentException
- if the supplied name isdefault
-
-
Method Details
-
toDisplayName
@NonNull public static <C extends SCMCategory<?>> org.jvnet.localizer.Localizable toDisplayName(C... categories) Gets the composite display name for a collection ofSCMCategory
instances.- Type Parameters:
C
- the type of categories.- Parameters:
categories
- the categories.- Returns:
- the composite display name for the categories
-
toDisplayName
@NonNull public static <C extends SCMCategory<?>> org.jvnet.localizer.Localizable toDisplayName(@NonNull List<C> categories) Gets the composite display name for a collection ofSCMCategory
instances.- Type Parameters:
C
- the type of categories.- Parameters:
categories
- the categories.- Returns:
- the composite display name for the categories
-
toShortUrl
Gets the composite short url name for a collection ofSCMCategory
instances.- Type Parameters:
C
- the type of categories.- Parameters:
categories
- the categories.- Returns:
- the composite short url name for the categories
-
toShortUrl
Gets the composite short url name for a collection ofSCMCategory
instances.- Type Parameters:
C
- the type of categories.- Parameters:
categories
- the categories.- Returns:
- the composite short url name for the categories
-
group
Partitions a list ofSCMCategory
instances bygetName()
.- Type Parameters:
T
- the base type of thing.C
- the base type of category.- Parameters:
categories
- the categories to group.- Returns:
- the map of sorted
SCMCategory
instances keyed bygetName()
.
-
group
@NonNull public static <T,C extends SCMCategory<T>> Map<String,List<C>> group(@NonNull Iterable<C> categories) Partitions a collection ofSCMCategory
instances bygetName()
.- Type Parameters:
T
- the base type of thing.C
- the base type of category.- Parameters:
categories
- the categories to group.- Returns:
- the map of sorted
SCMCategory
instances keyed bygetName()
.
-
getName
Gets the url path component to use when building URLs from categories.- Returns:
- the url path component;
-
getDisplayName
@NonNull public org.jvnet.localizer.Localizable getDisplayName()Get the term used in the UI to represent a collection of things in this kind ofSCMCategory
. Must be a plural and start with a capital letter.- Returns:
- the term for a collection of things in this kind of
SCMCategory
.
-
defaultDisplayName
@NonNull protected abstract org.jvnet.localizer.Localizable defaultDisplayName()The default display name.- Returns:
- The generic term of a collection of things in this kind of
SCMCategory
.
-
isUncategorized
public final boolean isUncategorized()Checks if this is the uncategorized category. The uncategorized category is special asisMatch(Object)
will not be applied, rather the uncategorized category will pick up everything that has not been captured by another category.- Returns:
true
if this is a catch-all category.
-
isMatch
Checks if the supplied instance is a match for thisSCMCategory
.- Parameters:
instance
- the instance to test.- Returns:
true
if the instance belongs to thisSCMCategory
.
-
isMatch
public boolean isMatch(@NonNull T instance, @Nullable Iterable<? extends SCMCategory<T>> categories) Checks if the supplied instance is a match for thisSCMCategory
.- Parameters:
instance
- the instance to test.categories
- ignored unlessisUncategorized()
in which case it should be the list of categories.- Returns:
true
if the instance belongs to thisSCMCategory
.
-