Class SCMSource
- All Implemented Interfaces:
ExtensionPoint
,Describable<SCMSource>
- Direct Known Subclasses:
NullSCMSource
,SingleSCMSource
SCMSource
is responsible for fetching SCMHead
and corresponding SCMRevision
instances from
which it can build SCM
instances that are configured to check out the specific SCMHead
at the
specified SCMRevision
.
Each SCMSource
is owned by a SCMSourceOwner
, if you need to find all the owners use
SCMSourceOwners.all()
to iterate through them, e.g. to notify SCMSource
instances of push
notification from the server they source SCMHead
s from.
NOTE: This layer does not cache remote calls but can cache intermediary results. For example,
with Subversion it is acceptable to cache the last revisions of various directory entries to minimize network
round trips, but any of the calls to fetch(TaskListener)
,
fetch(SCMHeadObserver, hudson.model.TaskListener)
or
fetch(SCMHead, hudson.model.TaskListener)
must
involve at least one network round trip to validate any cached information.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Means of locating a head given an item.Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
Field Summary
Modifier and TypeFieldDescriptionstatic final AlternativeUiTextProvider.Message<SCMSource>
Replaceable pronoun of that points to aSCMSource
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Callback from theSCMSourceOwner
after theSCMSourceOwner
has been saved.final SCM
Builds aSCM
instance for the specified head.abstract SCM
build
(SCMHead head, SCMRevision revision) Builds aSCM
instance for the specified head and revision, no validation of the head is performed, a revision for a different head or source will be treated as equivalent to anull
revision.boolean
canProbe()
Tests if thisSCMSource
can instantiate aSCMSourceCriteria.Probe
protected final void
Checks theThread.interrupted()
and throws anInterruptedException
if it was set.protected SCMProbe
createProbe
(SCMHead head, SCMRevision revision) protected final TaskListener
defaultListener
(TaskListener listener) Turns a possiblynull
TaskListener
reference into a guaranteed non-null reference.final boolean
fetch
(TaskListener listener) Fetches the current list of heads.final SCMRevision
fetch
(String thingName, TaskListener listener) Deprecated.final SCMRevision
fetch
(String thingName, TaskListener listener, Item context) Looks up a specific thingName based on some SCM-specific set of permissible syntaxes.final SCMRevision
fetch
(SCMHead head, TaskListener listener) Gets the current head revision of the specified head.final <O extends SCMHeadObserver>
Ofetch
(SCMSourceCriteria criteria, O observer, TaskListener listener) Fetches the latest heads and corresponding revisions.final <O extends SCMHeadObserver>
Ofetch
(SCMSourceCriteria criteria, O observer, SCMHeadEvent<?> event, TaskListener listener) Fetches the latest heads and corresponding revisions scoped against a specific event.final <O extends SCMHeadObserver>
Ofetch
(O observer, TaskListener listener) Fetches the latest heads and corresponding revisions.final <O extends SCMHeadObserver>
Ofetch
(O observer, SCMHeadEvent<?> event, TaskListener listener) Fetches the latest heads and corresponding revisions scoped against a specific event.fetchActions
(SCMHead head, SCMHeadEvent event, TaskListener listener) Fetches any actions that should be persisted for objects related to the specified head.fetchActions
(SCMRevision revision, SCMHeadEvent event, TaskListener listener) Fetches any actions that should be persisted for objects related to the specified revision.fetchActions
(SCMSourceEvent event, TaskListener listener) Fetches any actions that should be persisted for objects related to the specified source.fetchRevisions
(TaskListener listener) Deprecated.rather callfetchRevisions(TaskListener, Item)
fetchRevisions
(TaskListener listener, Item context) Looks up suggested revisions that could be passed tofetch(String, TaskListener)
.protected final SCMProbe
fromSCMFileSystem
(SCMHead head, SCMRevision revision) Helper method for subclasses that have implemented aSCMFileSystem.Builder
and want to use a simple non-cachingSCMProbe
based off of theSCMFileSystem
.final Set<? extends SCMHeadCategory>
Returns the set ofSCMHeadCategory
that thisSCMSource
supports.protected final SCMSourceCriteria
Returns the branch criteria.final String
getId()
The ID of this source.final SCMSourceOwner
getOwner()
Gets the owner.Get the term used in the UI to represent this kind ofSCMSource
.Gets the traits for this source.getTrustedRevision
(SCMRevision revision, TaskListener listener) Enables a source to request that an alternative revision be used to obtain security-sensitive build instructions.final int
hashCode()
final boolean
hasId()
Returnstrue
if and only if thisSCMSource
has been assigned an ID.protected boolean
isCategoryEnabled
(SCMHeadCategory category) Sub-classes can override this method to filter the categories that are available from a specific source.final SCMProbe
newProbe
(SCMHead head, SCMRevision revision) parentHeads
(SCMHead head, TaskListener listener) Looks up the immediate parent heads of the specified head within the specified source.parentRevisions
(SCMHead head, SCMRevision revision, TaskListener listener) Looks up the immediate parent revision(s) of the specified revision within the specified head.retrieve
(TaskListener listener) SPI: Fetches the current list of heads.protected SCMRevision
retrieve
(String thingName, TaskListener listener) Deprecated.rather overrideretrieve(String, TaskListener, Item)
protected SCMRevision
retrieve
(String thingName, TaskListener listener, Item context) SPI: Looks up a specific revision based on some SCM-specific set of permissible syntaxes.protected void
retrieve
(SCMHeadObserver observer, TaskListener listener) Deprecated.prefer implementingretrieve(SCMSourceCriteria, SCMHeadObserver, SCMHeadEvent, TaskListener)
protected SCMRevision
retrieve
(SCMHead head, TaskListener listener) SPI: Gets the current head revision of the specified head.retrieve
(SCMSourceCriteria criteria, TaskListener listener) SPI: Fetches the current list of heads.protected void
retrieve
(SCMSourceCriteria criteria, SCMHeadObserver observer, TaskListener listener) Deprecated.prefer implementingretrieve(SCMSourceCriteria, SCMHeadObserver, SCMHeadEvent, TaskListener)
protected abstract void
retrieve
(SCMSourceCriteria criteria, SCMHeadObserver observer, SCMHeadEvent<?> event, TaskListener listener) SPI: Fetches the latest heads and corresponding revisions that are originating from the supplied event.retrieveActions
(SCMHead head, SCMHeadEvent event, TaskListener listener) retrieveActions
(SCMRevision revision, SCMHeadEvent event, TaskListener listener) retrieveActions
(SCMSourceEvent event, TaskListener listener) retrieveRevisions
(TaskListener listener) Deprecated.rather overrideretrieveRevisions(TaskListener, Item)
retrieveRevisions
(TaskListener listener, Item context) SPI: Looks up suggested revisions that could be passed tofetch(String, TaskListener)
.final void
Sets the ID that is used to ensure thisSCMSource
can be retrieved from itsSCMSourceOwner
provided that thisSCMSource
does not alreadyhasId()
.final void
setOwner
(SCMSourceOwner owner) Sets the owner.void
setTraits
(List<SCMSourceTrait> traits) Sets the traits for this source.toString()
final SCMSource
Variant ofsetId(String)
that can be useful for method chaining.
-
Field Details
-
PRONOUN
Replaceable pronoun of that points to aSCMSource
. Defaults tonull
depending on the context.- Since:
- 2.0
-
-
Constructor Details
-
SCMSource
Deprecated.Constructor.- Parameters:
id
- the id ornull
.
-
SCMSource
protected SCMSource()Constructor.
-
-
Method Details
-
setId
Sets the ID that is used to ensure thisSCMSource
can be retrieved from itsSCMSourceOwner
provided that thisSCMSource
does not alreadyhasId()
.Note this is a one-shot setter. If
getId()
is called first, then its value will stick, otherwise the first call tosetId(String)
will stick.- Parameters:
id
- the ID, this is an opaque token expected to be unique within any oneSCMSourceOwner
.- Since:
- 2.2.0
- See Also:
-
withId
Variant ofsetId(String)
that can be useful for method chaining.- Parameters:
id
- the ID- Returns:
this
for method chaining
-
hasId
public final boolean hasId()Returnstrue
if and only if thisSCMSource
has been assigned an ID. Once an ID has been assigned it should be preserved.- Returns:
true
if and only if thisSCMSource
has been assigned an ID.- Since:
- 2.2.0
- See Also:
-
getId
The ID of this source. The ID is not related to anything at all. If thisSCMSource
does not have an ID then one will be generated.- Returns:
- the ID of this source.
- See Also:
-
setTraits
Sets the traits for this source. No-op by default.- Parameters:
traits
- the list of traits
-
getTraits
Gets the traits for this source.- Returns:
- traits the list of traits, empty by default.
-
setOwner
Sets the owner.- Parameters:
owner
- the owner.
-
getOwner
Gets the owner.- Returns:
- the owner.
-
getCriteria
Returns the branch criteria.- Returns:
- the branch criteria.
-
fetch
@NonNull public final <O extends SCMHeadObserver> O fetch(@NonNull O observer, @CheckForNull TaskListener listener) throws IOException, InterruptedException Fetches the latest heads and corresponding revisions. Implementers are free to cache intermediary results but the call must always check the validity of any intermediary caches.- Type Parameters:
O
- Observer type.- Parameters:
observer
- an optional observer of interim results.listener
- the task listener- Returns:
- the provided observer.
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.
-
fetch
@NonNull public final <O extends SCMHeadObserver> O fetch(@CheckForNull SCMSourceCriteria criteria, @NonNull O observer, @CheckForNull TaskListener listener) throws IOException, InterruptedException Fetches the latest heads and corresponding revisions. Implementers are free to cache intermediary results but the call must always check the validity of any intermediary caches.- Type Parameters:
O
- Observer type.- Parameters:
criteria
- the criteria to use.observer
- an optional observer of interim results.listener
- the task listener- Returns:
- the provided observer.
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.
-
fetch
@NonNull public final <O extends SCMHeadObserver> O fetch(@CheckForNull SCMSourceCriteria criteria, @NonNull O observer, @CheckForNull SCMHeadEvent<?> event, @CheckForNull TaskListener listener) throws IOException, InterruptedException Fetches the latest heads and corresponding revisions scoped against a specific event. Implementers are free to cache intermediary results but the call must always check the validity of any intermediary caches.- Type Parameters:
O
- Observer type.- Parameters:
criteria
- the criteria to use.observer
- an observer of interim results.event
- the (optional) event from which the fetch should be scoped.listener
- the task listener- Returns:
- the provided observer.
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.0
-
fetch
@NonNull public final <O extends SCMHeadObserver> O fetch(@NonNull O observer, @CheckForNull SCMHeadEvent<?> event, @CheckForNull TaskListener listener) throws IOException, InterruptedException Fetches the latest heads and corresponding revisions scoped against a specific event. Implementers are free to cache intermediary results but the call must always check the validity of any intermediary caches.- Type Parameters:
O
- Observer type.- Parameters:
observer
- an observer of interim results.event
- the (optional) event from which the fetch should be scoped.listener
- the task listener- Returns:
- the provided observer.
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.0
-
retrieve
@Deprecated protected void retrieve(@NonNull SCMHeadObserver observer, @NonNull TaskListener listener) throws IOException, InterruptedException Deprecated.prefer implementingretrieve(SCMSourceCriteria, SCMHeadObserver, SCMHeadEvent, TaskListener)
SPI: Fetches the latest heads and corresponding revisions. Implementers are free to cache intermediary results but the call must always check the validity of any intermediary caches.- Parameters:
observer
- an optional observer of interim results.listener
- the task listener.- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.
-
retrieve
@Deprecated protected void retrieve(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHeadObserver observer, @NonNull TaskListener listener) throws IOException, InterruptedException Deprecated.prefer implementingretrieve(SCMSourceCriteria, SCMHeadObserver, SCMHeadEvent, TaskListener)
SPI: Fetches the latest heads and corresponding revisions. Implementers are free to cache intermediary results but the call must always check the validity of any intermediary caches. It is vitally important that implementations must periodically callcheckInterrupt()
otherwise it will be impossible for users to interrupt the operation.- Parameters:
criteria
- the criteria to use, if non-null
them implementations mustfilter allSCMHead
instances against theSCMSourceCriteria.isHead(SCMSourceCriteria.Probe, TaskListener)
before passing through to theSCMHeadObserver
.observer
- an optional observer of interim results.listener
- the task listener.- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.
-
retrieve
protected abstract void retrieve(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHeadObserver observer, @CheckForNull SCMHeadEvent<?> event, @NonNull TaskListener listener) throws IOException, InterruptedException SPI: Fetches the latest heads and corresponding revisions that are originating from the supplied event. If the supplied event is one that the implementer trusts, then the implementer may be able to optimize retrieval to minimize round trips. Implementers are free to cache intermediary results but the call must always check the validity of any intermediary caches.It is vitally important that implementations must periodically call
checkInterrupt()
otherwise it will be impossible for users to interrupt the operation.The default implementation wraps the
SCMHeadObserver
usingSCMHeadEvent.filter(SCMSource, SCMHeadObserver)
and delegates toretrieve(SCMSourceCriteria, SCMHeadObserver, TaskListener)
- Parameters:
criteria
- the criteria to use, if non-null
them implementations mustfilter allSCMHead
instances against theSCMSourceCriteria.isHead(SCMSourceCriteria.Probe, TaskListener)
before passing through to theSCMHeadObserver
.observer
- an observer of interim results, if the event is non-null
then the observer will already have been filtered withSCMHeadEvent.filter(SCMSource, SCMHeadObserver)
.event
- the (optional) event from which the operation should be scoped.listener
- the task listener.- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.0
-
fetch
@NonNull public final Set<SCMHead> fetch(@CheckForNull TaskListener listener) throws IOException, InterruptedException Fetches the current list of heads. Implementers are free to cache intermediary results but the call must always check the validity of any intermediary caches.- Parameters:
listener
- the task listener- Returns:
- the current list of heads.
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.
-
parentRevisions
@NonNull public Set<SCMRevision> parentRevisions(@NonNull SCMHead head, @NonNull SCMRevision revision, @CheckForNull TaskListener listener) throws IOException, InterruptedException Looks up the immediate parent revision(s) of the specified revision within the specified head.- Parameters:
head
- the head to look up the parent revision(s) within.revision
- the revision to lookup the immediate parent(s) of.listener
- the task listener.- Returns:
- a set of immediate parent revisions of the specified revision. An empty set indicates either that the parents are unknown or that the revision is a root revision. Where the backing SCM supports merge tracking there is the potential for multiple parent revisions reflecting that the specified revision was a merge of more than one revision and thus has more than one parent.
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 0.3
-
parentHeads
@NonNull public Map<SCMHead,SCMRevision> parentHeads(@NonNull SCMHead head, @CheckForNull TaskListener listener) throws IOException, InterruptedException Looks up the immediate parent heads of the specified head within the specified source.- Parameters:
head
- the head to look up the parent head(s) within.listener
- the task listener.- Returns:
- a map of immediate parent heads of the specified head where the heads are the keys and the revisions at which the parent relationship was established are the values. An empty map indicates either that the parents are unknown or that the head is a root head. Where the backing SCM supports merge tracking there is the potential for multiple parent heads reflecting that the specified head was a merge of more than one head and thus has more than one parent.
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 0.3
-
retrieve
@NonNull protected Set<SCMHead> retrieve(@NonNull TaskListener listener) throws IOException, InterruptedException SPI: Fetches the current list of heads. Implementers are free to cache intermediary results but the call must always check the validity of any intermediary caches.- Parameters:
listener
- the task listener- Returns:
- the current list of heads.
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.
-
retrieve
@NonNull protected Set<SCMHead> retrieve(@CheckForNull SCMSourceCriteria criteria, @NonNull TaskListener listener) throws IOException, InterruptedException SPI: Fetches the current list of heads. Implementers are free to cache intermediary results but the call must always check the validity of any intermediary caches.- Parameters:
criteria
- the criteria to use for identifying heads.listener
- the task listener- Returns:
- the current list of heads.
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.
-
fetch
@CheckForNull public final SCMRevision fetch(@NonNull SCMHead head, @CheckForNull TaskListener listener) throws IOException, InterruptedException Gets the current head revision of the specified head. Does not check this against anySCMSourceCriteria
.- Parameters:
head
- the head.listener
- the task listener- Returns:
- the revision hash (may be non-deterministic) or
null
if the head no longer exists. - Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.
-
retrieve
@CheckForNull protected SCMRevision retrieve(@NonNull SCMHead head, @NonNull TaskListener listener) throws IOException, InterruptedException SPI: Gets the current head revision of the specified head. Does not check this against anySCMSourceCriteria
.- Parameters:
head
- the head.listener
- the task listener- Returns:
- the revision hash (may be non-deterministic) or
null
if the head no longer exists. - Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.
-
fetch
@Deprecated @CheckForNull public final SCMRevision fetch(@NonNull String thingName, @CheckForNull TaskListener listener) throws IOException, InterruptedException Deprecated.rather callfetch(String, TaskListener, Item)
Looks up a specific thingName based on some SCM-specific set of permissible syntaxes. Delegates toretrieve(String, TaskListener)
.- Parameters:
thingName
- might be a branch name, a tag name, a cryptographic hash, a change request number, etc.listener
- the task listener (optional)- Returns:
- a valid
SCMRevision
corresponding to the argument, with a usable corresponding head, ornull
if malformed or not found - Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 1.3
-
fetch
@CheckForNull public final SCMRevision fetch(@NonNull String thingName, @CheckForNull TaskListener listener, @CheckForNull Item context) throws IOException, InterruptedException Looks up a specific thingName based on some SCM-specific set of permissible syntaxes. Delegates toretrieve(String, TaskListener)
.- Parameters:
thingName
- might be a branch name, a tag name, a cryptographic hash, a change request number, etc.listener
- the task listener (optional)context
- an associated context to supersedegetOwner()
, such as a job in which this is running- Returns:
- a valid
SCMRevision
corresponding to the argument, with a usable corresponding head, ornull
if malformed or not found - Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.6.0
-
retrieve
@Deprecated @CheckForNull protected SCMRevision retrieve(@NonNull String thingName, @NonNull TaskListener listener) throws IOException, InterruptedException Deprecated.rather overrideretrieve(String, TaskListener, Item)
SPI: Looks up a specific revision based on some SCM-specific set of permissible syntaxes. The default implementation usesretrieve(SCMSourceCriteria, SCMHeadObserver, TaskListener)
and looks forSCMHead.getName()
matching the argument (so typically only supporting branch names).- Parameters:
thingName
- might be a branch name, a tag name, a cryptographic hash, a revision number, etc.listener
- the task listener- Returns:
- a valid revision object corresponding to the argument, with a usable corresponding head, or null if malformed or not found
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 1.3
-
retrieve
@CheckForNull protected SCMRevision retrieve(@NonNull String thingName, @NonNull TaskListener listener, @CheckForNull Item context) throws IOException, InterruptedException SPI: Looks up a specific revision based on some SCM-specific set of permissible syntaxes. The default implementation usesretrieve(SCMSourceCriteria, SCMHeadObserver, TaskListener)
and looks forSCMHead.getName()
matching the argument (so typically only supporting branch names).- Parameters:
thingName
- might be a branch name, a tag name, a cryptographic hash, a revision number, etc.listener
- the task listenercontext
- an associated context to supersedegetOwner()
, such as a job in which this is running- Returns:
- a valid revision object corresponding to the argument, with a usable corresponding head, or null if malformed or not found
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.6.0
-
fetchRevisions
@Deprecated @NonNull public final Set<String> fetchRevisions(@CheckForNull TaskListener listener) throws IOException, InterruptedException Deprecated.rather callfetchRevisions(TaskListener, Item)
Looks up suggested revisions that could be passed tofetch(String, TaskListener)
. There is no guarantee that all returned revisions are in fact valid, nor that all valid revisions are returned. Delegates toretrieveRevisions(hudson.model.TaskListener)
.- Parameters:
listener
- the task listener- Returns:
- a possibly empty set of revision names suggested by the implementation
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 1.3
-
fetchRevisions
@NonNull public final Set<String> fetchRevisions(@CheckForNull TaskListener listener, @CheckForNull Item context) throws IOException, InterruptedException Looks up suggested revisions that could be passed tofetch(String, TaskListener)
. There is no guarantee that all returned revisions are in fact valid, nor that all valid revisions are returned. Delegates toretrieveRevisions(hudson.model.TaskListener)
.- Parameters:
listener
- the task listenercontext
- an associated context to supersedegetOwner()
, such as a job in which this is running- Returns:
- a possibly empty set of revision names suggested by the implementation
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.6.0
-
retrieveRevisions
@Deprecated @NonNull protected Set<String> retrieveRevisions(@NonNull TaskListener listener) throws IOException, InterruptedException Deprecated.rather overrideretrieveRevisions(TaskListener, Item)
SPI: Looks up suggested revisions that could be passed tofetch(String, TaskListener)
. There is no guarantee that all returned revisions are in fact valid, nor that all valid revisions are returned. By default, callsretrieve(TaskListener)
, thus typically returning only branch names.- Parameters:
listener
- the task listener- Returns:
- a possibly empty set of revision names suggested by the implementation
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 1.3
-
retrieveRevisions
@NonNull protected Set<String> retrieveRevisions(@NonNull TaskListener listener, @CheckForNull Item context) throws IOException, InterruptedException SPI: Looks up suggested revisions that could be passed tofetch(String, TaskListener)
. There is no guarantee that all returned revisions are in fact valid, nor that all valid revisions are returned. By default, callsretrieve(TaskListener)
, thus typically returning only branch names.- Parameters:
listener
- the task listenercontext
- an associated context to supersedegetOwner()
, such as a job in which this is running- Returns:
- a possibly empty set of revision names suggested by the implementation
- Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.6.0
-
fetchActions
@NonNull public final List<Action> fetchActions(@NonNull SCMRevision revision, @CheckForNull SCMHeadEvent event, @CheckForNull TaskListener listener) throws IOException, InterruptedException Fetches any actions that should be persisted for objects related to the specified revision. For example, if aRun
is building a specificSCMRevision
, then this method would be called to populate anyAction
instances for thatRun
. NOTE: unlikefetchActions(SCMHead, SCMHeadEvent, TaskListener)
,fetchActions(SCMSourceEvent, TaskListener)
orSCMNavigator.fetchActions(SCMNavigatorOwner, SCMNavigatorEvent, TaskListener)
there is no guarantee that this method will ever be called more than once for anyRun
.fetchActions(SCMHead, SCMHeadEvent, TaskListener)
must have been called at least once before calling this method.- Parameters:
revision
- theSCMRevision
event
- the (optional) event to use when fetching the actions. Where the implementation is able to trust the event, it may use the event payload to reduce the number of network calls required to obtain the actions.listener
- the listener to report progress on.- Returns:
- the list of
Action
instances to persist. - Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.0
-
fetchActions
@NonNull public final List<Action> fetchActions(@NonNull SCMHead head, @CheckForNull SCMHeadEvent event, @CheckForNull TaskListener listener) throws IOException, InterruptedException Fetches any actions that should be persisted for objects related to the specified head. For example, if aJob
is associated with a specificSCMHead
, then this method would be called to refresh anyAction
instances of thatJob
.fetchActions(SCMSourceEvent,TaskListener)
must have been called at least once before calling this method.Where a
SCMHead
is associated with aItem
orJob
, it is the responsibility of the caller to ensure that theseAction
instances are exposed on theItem
/Job
for example by providing aTransientActionFactory
implementation that reports these persisted actions separately (for exampleAbstractProject.getActions()
returns an immutable list, so there is no way to persist the actions from this method against those sub-classes, instead the actions need to be persisted by some side mechanism and then injected into theActionable.getAllActions()
through aTransientActionFactory
ignoring the cognitive dissonance triggered by adding non-transient actions through a transient action factory... think of it instead as aTemporalActionFactory
that adds actions that can change over time)- Parameters:
head
- theSCMHead
event
- the (optional) event to use when fetching the actions. Where the implementation is able to trust the event, it may use the event payload to reduce the number of network calls required to obtain the actions.listener
- the listener to report progress on.- Returns:
- the list of
Action
instances to persist. - Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.0
-
fetchActions
@NonNull public final List<Action> fetchActions(@CheckForNull SCMSourceEvent event, @CheckForNull TaskListener listener) throws IOException, InterruptedException Fetches any actions that should be persisted for objects related to the specified source. For example, if aItem
is associated with a specificSCMSource
, then this method would be called to refresh anyAction
instances of thatItem
. If thisSCMSource
belongs to aSCMNavigator
thenSCMNavigator.fetchActions(SCMNavigatorOwner, SCMNavigatorEvent, TaskListener)
must have been called at least once before calling this method.Where a
SCMSource
is associated with a specificItem
, it is the responsibility of the caller to ensure that theseAction
instances are exposed on theItem
for example by providing aTransientActionFactory
implementation that reports these persisted actions separately (for exampleAbstractProject.getActions()
returns an immutable list, so there is no way to persist the actions from this method against those sub-classes, instead the actions need to be persisted by some side mechanism and then injected into theActionable.getAllActions()
through aTransientActionFactory
ignoring the cognitive dissonance triggered by adding non-transient actions through a transient action factory... think of it instead as aTemporalActionFactory
that adds actions that can change over time)- Parameters:
event
- the (optional) event to use when fetching the actions. Where the implementation is able to trust the event, it may use the event payload to reduce the number of network calls required to obtain the actions.listener
- the listener to report progress on.- Returns:
- the list of
Action
instances to persist. - Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.0
-
retrieveActions
@NonNull protected List<Action> retrieveActions(@NonNull SCMRevision revision, @CheckForNull SCMHeadEvent event, @NonNull TaskListener listener) throws IOException, InterruptedException SPI forfetchActions(SCMRevision, SCMHeadEvent, TaskListener)
. Fetches any actions that should be persisted for objects related to the specified revision.- Parameters:
revision
- theSCMRevision
event
- the (optional) event to use when fetching the actions. Where the implementation is able to trust the event, it may use the event payload to reduce the number of network calls required to obtain the actions.listener
- the listener to report progress on.- Returns:
- the list of
Action
instances to persist. - Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.0
-
retrieveActions
@NonNull protected List<Action> retrieveActions(@NonNull SCMHead head, @CheckForNull SCMHeadEvent event, @NonNull TaskListener listener) throws IOException, InterruptedException SPI forfetchActions(SCMHead, SCMHeadEvent, TaskListener)
. Fetches any actions that should be persisted for objects related to the specified head.- Parameters:
head
- theSCMHead
event
- the (optional) event to use when fetching the actions. Where the implementation is able to trust the event, it may use the event payload to reduce the number of network calls required to obtain the actions.listener
- the listener to report progress on.- Returns:
- the list of
Action
instances to persist. - Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.0
-
retrieveActions
@NonNull protected List<Action> retrieveActions(@CheckForNull SCMSourceEvent event, @NonNull TaskListener listener) throws IOException, InterruptedException SPI forfetchActions(SCMSourceEvent,TaskListener)
. Fetches any actions that should be persisted for objects related to the specified source.- Parameters:
event
- the (optional) event to use when fetching the actions. Where the implementation is able to trust the event, it may use the event payload to reduce the number of network calls required to obtain the actions.listener
- the listener to report progress on.- Returns:
- the list of
Action
instances to persist. - Throws:
IOException
- if an error occurs while performing the operation.InterruptedException
- if any thread has interrupted the current thread.- Since:
- 2.0
-
build
Builds aSCM
instance for the specified head and revision, no validation of the head is performed, a revision for a different head or source will be treated as equivalent to anull
revision.- Parameters:
head
- the head.revision
- the revision ornull
.- Returns:
- the
SCM
instance.
-
build
Builds aSCM
instance for the specified head.- Parameters:
head
- the head.- Returns:
- the
SCM
instance
-
getTrustedRevision
@NonNull public SCMRevision getTrustedRevision(@NonNull SCMRevision revision, @NonNull TaskListener listener) throws IOException, InterruptedException Enables a source to request that an alternative revision be used to obtain security-sensitive build instructions.Normally it is assumed that revisions in the SCM represented by this source come from principals operating with the same authorization as the principal creating the job, or at least with authorization to create a similar job.
A source may however collect revisions from untrusted third parties and submit them for builds. If the project type performing the build loads instructions from the same revision, this might allow the job to be subverted to perform unauthorized build steps or steal credentials.
By replacing the supplied revision with a trusted variant, a source can defend against such attacks. It is up to the project type to determine which files should come from a trusted replacement. Regular project sources should come from the original; Jenkins-specific scripting commands or configuration should come from the replacement, unless easily sandboxed; scripts for external build tools should come from the original if possible.
- Parameters:
revision
- a revision (produced by one of theretrieve
overloads) which may or may not come from a trustworthy sourcelistener
- a way to explain possible substitutions- Returns:
- by default,
revision
; may be overridden to provide an alternate revision from the same or a different head - Throws:
IOException
- in case the implementation must callfetch(SCMHead, TaskListener)
or similarInterruptedException
- in case the implementation must callfetch(SCMHead, TaskListener)
or similar- Since:
- 1.1
-
defaultListener
Turns a possiblynull
TaskListener
reference into a guaranteed non-null reference.- Parameters:
listener
- a possiblynull
TaskListener
reference.- Returns:
- guaranteed non-null
TaskListener
.
-
canProbe
public boolean canProbe()Tests if thisSCMSource
can instantiate aSCMSourceCriteria.Probe
- Returns:
true
if and only ifcreateProbe(SCMHead, SCMRevision)
has been implemented.- Since:
- 2.0
-
newProbe
@NonNull public final SCMProbe newProbe(@NonNull SCMHead head, @CheckForNull SCMRevision revision) throws IOException Creates aSCMProbe
for the specifiedSCMHead
andSCMRevision
.Public exposed API for
createProbe(SCMHead, SCMRevision)
.- Parameters:
head
- theSCMHead
.revision
- theSCMRevision
.- Returns:
- the
SCMSourceCriteria.Probe
. - Throws:
IllegalArgumentException
- if theSCMRevision.getHead()
is not equal to the suppliedSCMHead
IOException
- if the probe creation failed due to an IO exception.- Since:
- 2.0
- See Also:
-
createProbe
@NonNull protected SCMProbe createProbe(@NonNull SCMHead head, @CheckForNull SCMRevision revision) throws IOException - Parameters:
head
- theSCMHead
.revision
- theSCMRevision
.- Returns:
- the
SCMSourceCriteria.Probe
. - Throws:
IOException
- if the probe creation failed due to an IO exception.- Since:
- 2.0
- See Also:
-
fromSCMFileSystem
@CheckForNull protected final SCMProbe fromSCMFileSystem(@NonNull SCMHead head, @CheckForNull SCMRevision revision) throws IOException, InterruptedException Helper method for subclasses that have implemented aSCMFileSystem.Builder
and want to use a simple non-cachingSCMProbe
based off of theSCMFileSystem
.- Parameters:
head
- theSCMHead
.revision
- theSCMRevision
.- Returns:
- the
SCMSourceCriteria.Probe
ornull
if this source cannot be probed. - Throws:
IOException
- if the attempt to create aSCMFileSystem
failed due to an IO error (such as the remote system being unavailable)InterruptedException
- if the attempt to create aSCMFileSystem
was interrupted.- Since:
- 2.0
-
equals
-
hashCode
public final int hashCode() -
toString
-
getDescriptor
- Specified by:
getDescriptor
in interfaceDescribable<SCMSource>
- Overrides:
getDescriptor
in classAbstractDescribableImpl<SCMSource>
-
getPronoun
Get the term used in the UI to represent this kind ofSCMSource
. Must start with a capital letter.- Returns:
- the term or
null
to fall back to the calling context's default. - Since:
- 2.0
-
getCategories
Returns the set ofSCMHeadCategory
that thisSCMSource
supports. There will always be exactly oneSCMCategory.isUncategorized()
instance in the returned set.- Returns:
- the set of
SCMHeadCategory
that thisSCMSource
supports. - Since:
- 2.0
-
isCategoryEnabled
Sub-classes can override this method to filter the categories that are available from a specific source. For example a source type might be capable of having mainline branches, user branches, merge requests and release tags while a specific instance of the source may be configured to only have mainline branches and release tags.- Parameters:
category
- the category.- Returns:
true
if the supplied category is enabled for thisSCMSource
instance.- Since:
- 2.0
-
checkInterrupt
Checks theThread.interrupted()
and throws anInterruptedException
if it was set.- Throws:
InterruptedException
- if interrupted.- Since:
- 2.0
-
afterSave
public void afterSave()Callback from theSCMSourceOwner
after theSCMSourceOwner
has been saved. Can be used to register theSCMSourceOwner
for a call-back hook from the backing SCM that this source is for. Implementations are responsible for ensuring that they do not create duplicate registrations and that orphaned registrations are removed eventually.- Since:
- 2.0
-
fetch(String, TaskListener, Item)