Package jenkins.scm.api
Class SCMFileSystem
java.lang.Object
jenkins.scm.api.SCMFileSystem
- All Implemented Interfaces:
Closeable,AutoCloseable
A virtual file system for a specific
SCM potentially pinned to a specific SCMRevision. In contrast
to SCMProbe, implementations should not cache results between SCMFileSystem instantiations.
While some DVCS implementations may need to perform a local checkout in order to be able to implement this API it
should be noted that in such cases the local checkout is not a cache but rather a copy of the immutable revisions
- this may look and sound like a cache but it isn't as the revision itself is immutable. When a new
SCMFileSystem if being instantiated against a null SCMRevision the DVCS system can re-use
the previous local checkout after reconfirming that the current revision for the head matches that of the local
checkout.
Where the getRevision() is null or SCMRevision.isDeterministic() a SCMFileSystem
can choose to keep the results locally (up to close()) or re-query against the remote.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classExtension point that allows different plugins to implementSCMFileSystemclasses for the sameSCMorSCMSourceand let Jenkins pick the most capable for any specificSCMimplementation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanchangesSince(SCMRevision revision, OutputStream changeLogStream) Writes the changes between the specified revision andgetRevision()in the format compatible with theSCMfrom thisof(Item, SCM)to the suppliedOutputStream.final SCMFileShort forgetRoot().child(path).voidclose()If this inspector is looking at the specific commit, returns that revision.abstract SCMFilegetRoot()Returns theSCMFileobject that represents the root directory of the repository.final booleanWhether this inspector is looking at the specific commit.abstract longReturns the time that theSCMFileSystemwas last modified.static SCMFileSystemGiven aSCMthis method will try to retrieve a correspondingSCMFileSysteminstance.static SCMFileSystemof(Item owner, SCM scm, SCMRevision rev) Given aSCMthis method will try to retrieve a correspondingSCMFileSysteminstance that reflects the content at the specifiedSCMRevision.static SCMFileSystemof(Item owner, SCM scm, SCMRevision rev, Run<?, ?> build) Given aSCMthis method will try to retrieve a correspondingSCMFileSysteminstance that reflects the content at the specifiedSCMRevision.static SCMFileSystemGiven aSCMSourceand aSCMHeadthis method will try to retrieve a correspondingSCMFileSysteminstance that reflects the content of the specifiedSCMHead.static SCMFileSystemof(SCMSource source, SCMHead head, SCMRevision rev) Given aSCMSource, aSCMHeadand aSCMRevisionthis method will try to retrieve a correspondingSCMFileSysteminstance that reflects the content of the specifiedSCMHeadat the specifiedSCMRevision.static booleanGiven aSCMthis method will check if there is at least oneSCMFileSystemprovider capable of being instantiated.static booleansupports(SCMDescriptor descriptor) Given aSCMDescriptorthis method will check if there is at least oneSCMFileSystemprovider capable of being instantiated from the descriptor'sSCMSource.static booleanGiven aSCMSourcethis method will check if there is at least oneSCMFileSystemprovider capable of being instantiated.static booleansupports(SCMSourceDescriptor descriptor) Given aSCMSourceDescriptorthis method will check if there is at least oneSCMFileSystemprovider capable of being instantiated from the descriptor'sSCMSource.
-
Constructor Details
-
SCMFileSystem
Constructor.- Parameters:
rev- the revision.
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
lastModified
Returns the time that theSCMFileSystemwas last modified. This should logically be equivalent to the maximumSCMFile.lastModified()that you would find if you were to do the horribly inefficient traversal of all theSCMFileinstances fromgetRoot(). Where implementers do not have an easy and quick way to get this information (such as by looking at the commit time of thegetRevision()HINT HINT) then just return0L.- Returns:
- A
longvalue representing the time theSCMFileSystemwas last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970) or0Lif the operation is unsupported. - Throws:
IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.
-
getRevision
If this inspector is looking at the specific commit, returns that revision. Otherwise null, indicating that the inspector is looking at just the latest state of the repository.- Returns:
- the revision of the commit the inspector is looking at, or null if none.
-
isFixedRevision
public final boolean isFixedRevision()Whether this inspector is looking at the specific commit.Short for
.getRevision()!=null.- Returns:
- true if this inspector is looking at the specific commit.
-
child
Short forgetRoot().child(path).- Parameters:
path- Path of the SCMFile to obtain from the root of the repository.- Returns:
- Child path
-
getRoot
Returns theSCMFileobject that represents the root directory of the repository.- Returns:
- the root directory of the repository.
-
changesSince
public boolean changesSince(@CheckForNull SCMRevision revision, @NonNull OutputStream changeLogStream) throws UnsupportedOperationException, IOException, InterruptedException Writes the changes between the specified revision andgetRevision()in the format compatible with theSCMfrom thisof(Item, SCM)to the suppliedOutputStream. This method allows for consumers or the SCM API to replicate theSCM.checkout(Run, Launcher, FilePath, TaskListener, File, SCMRevisionState)functionality that captures the changelog without requiring a full checkout.- Parameters:
revision- the starting revision ornullto capture the initial change set.changeLogStream- the destination to stream the changes to.- Returns:
trueif there are changes,falseif there were no changes.- Throws:
UnsupportedOperationException- if thisSCMFileSystemdoes not support changelog querying.IOException- if an error occurs while performing the operation.InterruptedException- if interrupted while performing the operation.- Since:
- 2.0
-
of
@CheckForNull public static SCMFileSystem of(@NonNull Item owner, @NonNull SCM scm) throws IOException, InterruptedException Given aSCMthis method will try to retrieve a correspondingSCMFileSysteminstance.- Parameters:
owner- the owner of theSCMscm- theSCM.- Returns:
- the corresponding
SCMFileSystemornullif there is none. - Throws:
IOException- if the attempt to create aSCMFileSystemfailed due to an IO error (such as the remote system being unavailable)InterruptedException- if the attempt to create aSCMFileSystemwas interrupted.
-
of
@CheckForNull public static SCMFileSystem of(@NonNull Item owner, @NonNull SCM scm, @CheckForNull SCMRevision rev) throws IOException, InterruptedException Given aSCMthis method will try to retrieve a correspondingSCMFileSysteminstance that reflects the content at the specifiedSCMRevision.- Parameters:
owner- the owner of theSCMscm- theSCM.rev- the specifiedSCMRevision.- Returns:
- the corresponding
SCMFileSystemornullif there is none. - Throws:
IOException- if the attempt to create aSCMFileSystemfailed due to an IO error (such as the remote system being unavailable)InterruptedException- if the attempt to create aSCMFileSystemwas interrupted.
-
of
@CheckForNull public static SCMFileSystem of(@NonNull Item owner, @NonNull SCM scm, @CheckForNull SCMRevision rev, @CheckForNull Run<?, ?> build) throws IOException, InterruptedExceptionGiven aSCMthis method will try to retrieve a correspondingSCMFileSysteminstance that reflects the content at the specifiedSCMRevision.- Parameters:
owner- the owner of theSCMscm- theSCM.rev- the specifiedSCMRevision.build- an associated build context, if any, that could be used for example to look up parameters- Returns:
- the corresponding
SCMFileSystemornullif there is none. - Throws:
IOException- if the attempt to create aSCMFileSystemfailed due to an IO error (such as the remote system being unavailable)InterruptedException- if the attempt to create aSCMFileSystemwas interrupted.
-
supports
Given aSCMthis method will check if there is at least oneSCMFileSystemprovider capable of being instantiated. Returningtruedoes not mean thatof(Item, SCM, SCMRevision, Run)will be able to instantiate aSCMFileSystemfor any specificSCMRevision, rather returningfalseindicates that there is absolutely no point in callingof(Item, SCM, SCMRevision, Run)as it will always returnnull.- Parameters:
scm- theSCMSource.- Returns:
trueifof(Item, SCM)/of(Item, SCM, SCMRevision, Run)could return aSCMFileSystemimplementation,falseifof(Item, SCM)/of(Item, SCM, SCMRevision, Run)will always returnnullfor the suppliedSCM.- Since:
- 2.0
-
of
@CheckForNull public static SCMFileSystem of(@NonNull SCMSource source, @NonNull SCMHead head) throws IOException, InterruptedException Given aSCMSourceand aSCMHeadthis method will try to retrieve a correspondingSCMFileSysteminstance that reflects the content of the specifiedSCMHead.- Parameters:
source- theSCMSource.head- the specifiedSCMHead.- Returns:
- the corresponding
SCMFileSystemornullif there is none. - Throws:
IOException- if the attempt to create aSCMFileSystemfailed due to an IO error (such as the remote system being unavailable)InterruptedException- if the attempt to create aSCMFileSystemwas interrupted.
-
of
@CheckForNull public static SCMFileSystem of(@NonNull SCMSource source, @NonNull SCMHead head, @CheckForNull SCMRevision rev) throws IOException, InterruptedException Given aSCMSource, aSCMHeadand aSCMRevisionthis method will try to retrieve a correspondingSCMFileSysteminstance that reflects the content of the specifiedSCMHeadat the specifiedSCMRevision.- Parameters:
source- theSCMSource.head- the specifiedSCMHead.rev- the specifiedSCMRevision.- Returns:
- the corresponding
SCMFileSystemornullif there is none. - Throws:
IOException- if the attempt to create aSCMFileSystemfailed due to an IO error (such as the remote system being unavailable)InterruptedException- if the attempt to create aSCMFileSystemwas interrupted.
-
supports
Given aSCMSourcethis method will check if there is at least oneSCMFileSystemprovider capable of being instantiated. Returningtruedoes not mean thatof(SCMSource, SCMHead, SCMRevision)will be able to instantiate aSCMFileSystemfor any specificSCMHeadorSCMRevision, rather returningfalseindicates that there is absolutely no point in callingof(SCMSource, SCMHead, SCMRevision)as it will always returnnull.- Parameters:
source- theSCMSource.- Returns:
trueifof(SCMSource, SCMHead)/of(SCMSource, SCMHead, SCMRevision)could return aSCMFileSystemimplementation,falseifof(SCMSource, SCMHead)/of(SCMSource, SCMHead, SCMRevision)will always returnnullfor the suppliedSCMSource.- Since:
- 2.0
-
supports
Given aSCMDescriptorthis method will check if there is at least oneSCMFileSystemprovider capable of being instantiated from the descriptor'sSCMSource. Returningtruedoes not mean thatof(Item, SCM, SCMRevision, Run)will be able to instantiate aSCMFileSystemfor any specificItemorSCMRevision, rather returningfalseindicates that there is absolutely no point in callingof(Item, SCM, SCMRevision, Run)as it will always returnnull.- Parameters:
descriptor- theSCMDescriptor.- Returns:
trueifof(Item, SCM, SCMRevision, Run)could return aSCMFileSystemimplementation,falseifof(Item, SCM, SCMRevision, Run)will always returnnullfor the suppliedSCM.- Since:
- 2.3.0
-
supports
Given aSCMSourceDescriptorthis method will check if there is at least oneSCMFileSystemprovider capable of being instantiated from the descriptor'sSCMSource. Returningtruedoes not mean thatof(SCMSource, SCMHead, SCMRevision)will be able to instantiate aSCMFileSystemfor any specificSCMHeadorSCMRevision, rather returningfalseindicates that there is absolutely no point in callingof(SCMSource, SCMHead, SCMRevision)as it will always returnnull.- Parameters:
descriptor- theSCMSourceDescriptor.- Returns:
trueifof(SCMSource, SCMHead)/of(SCMSource, SCMHead, SCMRevision)could return aSCMFileSystemimplementation,falseifof(SCMSource, SCMHead)/of(SCMSource, SCMHead, SCMRevision)will always returnnullfor the suppliedSCMSource.- Since:
- 2.3.0
-