Package jenkins.scm.api
Class SCMHead
java.lang.Object
jenkins.scm.api.SCMHead
- All Implemented Interfaces:
Serializable,Comparable<SCMHead>,SCMHeadMixin
Represents a named SCM branch, change request, tag or mainline. This class is intended to be used as a typed key
rather than passing a
String around. Each SCMSource implementation may want to have their own
subclasses in order assist to differentiating between different classes of head via the SCMHeadMixin
interfaces.
Please note the equality contract for SCMHeadMixin implementations:
Two SCMHeadMixin implementations are equal if and only if:
- They both are the same class
- They both have the same
SCMHeadMixin.getName() - For each implemented
SCMHeadMixinsub-interface, they both return the same values from all Java Bean property getters declared on the sub-interface. Thus, for exampleChangeRequestSCMHeadimplementations are only considered equal ifChangeRequestSCMHead.getId()andChangeRequestSCMHead.getTarget()are also equal
Object.hashCode() is:
Object.hashCode()for aSCMHeadMixinimplementation must be equal to theString.hashCode()ofSCMHeadMixin.getName()
equals(Object) and hashCode() methods enforce the above requirements and
are final.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classMeans of locating a head given an item.Nested classes/interfaces inherited from interface jenkins.scm.api.mixin.SCMHeadMixin
SCMHeadMixin.Equality -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AlternativeUiTextProvider.Message<SCMHead>Replaceable pronoun of that points to aSCMHead. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintfinal booleanIndicates whether some other object is "equal to" this one.<T extends Action>
TDeprecated.this was added to the API in error.Deprecated.this was added to the API in error.getName()Returns the name.Returns the origin of the head.Get the term used in the UI to represent this kind ofSCMHead.final inthashCode()toString()
-
Field Details
-
PRONOUN
Replaceable pronoun of that points to aSCMHead. Defaults tonulldepending on the context.- Since:
- 2.0
-
-
Constructor Details
-
SCMHead
Constructor.- Parameters:
name- the name.
-
-
Method Details
-
getName
Returns the name.- Specified by:
getNamein interfaceSCMHeadMixin- Returns:
- the name.
-
getOrigin
Returns the origin of the head.-
For centralized version control systems such as Subversion, CVS, etc the return value will always be
SCMHeadOrigin.DEFAULT. - For distributed version control systems such as Git, Mercurial etc the return value may have other values.
-
For centralized distributed version control systems such as GitHub, Bitbucket, etc the return values may
be restricted to
SCMHeadOrigin.DEFAULTor instances ofSCMHeadOrigin.Fork.
- Specified by:
getOriginin interfaceSCMHeadMixin- Returns:
- the origin of the head or
SCMHeadOrigin.DEFAULTif there can only ever be one origin.
-
For centralized version control systems such as Subversion, CVS, etc the return value will always be
-
getPronoun
Get the term used in the UI to represent this kind ofSCMHead. Must start with a capital letter.- Returns:
- the term or
nullto fall back to the calling context's default. - Since:
- 2.0
-
equals
Indicates whether some other object is "equal to" this one. TwoSCMHeadMixinimplementations are equal if and only if:- They both are the same class
- They both have the same
SCMHeadMixin.getName() - For each implemented
SCMHeadMixinsub-interface, they both return the same values from all Java Bean property getters declared on the sub-interface. Thus, for exampleChangeRequestSCMHeadimplementations are only considered equal ifChangeRequestSCMHead.getId()andChangeRequestSCMHead.getTarget()are also equal
By way of example, any implementation of
ChangeRequestSCMHeadwill have their equals behave like so:public static class MyChangeRequestSCMHead extends SCMHead implements ChangeRequestSCMHead { //... // this method is implemented for you, but if you had to write it this is what you would // have to write public boolean equals(Object o) { if (!super.equals(o)) { return false; } // can only be equal if they are the same class MyChangeRequestSCMHead that = (MyChangeRequestSCMHead)o; // because we implement ChangeRequestSCMHead and ChangeRequestSCMHead has a getId() method String id1 = this.getId(); String id2 = that.getId(); if (id1 == null ? id2 != null : !id1.equals(id2)) { return false; } // because we implement ChangeRequestSCMHead and ChangeRequestSCMHead has a getTarget() method SCMHead t1 = this.getTarget(); SCMHead t2 = that.getTarget(); if (t1 == null ? t2 != null : !t1.equals(t2)) { return false; } // we do not implement any other interfaces extending SCMHeadMixin, so we must be equal return true; } } -
hashCode
public final int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<SCMHead>
-
toString
-
getAllActions
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) @Deprecated @NonNull public List<? extends Action> getAllActions()Deprecated.this was added to the API in error. Retained for backwards binary compatibility only. UseSCMSource.fetchActions(SCMHead, SCMHeadEvent, TaskListener)to get the actions associated with aSCMHeadReturns an empty list.- Returns:
- an empty list
- Since:
- 1.1
-
getAction
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) @Deprecated @CheckForNull public <T extends Action> T getAction(@NonNull Class<T> type) Deprecated.this was added to the API in error. Retained for backwards binary compatibility only. UseSCMSource.fetchActions(SCMHead, SCMHeadEvent, TaskListener)to get the actions associated with aSCMHeadReturnsnull.- Type Parameters:
T- a desired action type to query, such asChangeRequestAction- Parameters:
type- type token- Returns:
null- Since:
- 1.1
-