Class VersionControlSystem
-
- All Implemented Interfaces:
-
org.ossreviewtoolkit.utils.common.Plugin
public abstract class VersionControlSystem implements Plugin
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classVersionControlSystem.Companion
-
Field Summary
Fields Modifier and Type Field Description private final BooleanisEnabledByDefaultprivate final Stringtypepublic final static VersionControlSystem.CompanionCompanion
-
Constructor Summary
Constructors Constructor Description VersionControlSystem(CommandLineTool commandLineTool)
-
Method Summary
Modifier and Type Method Description abstract StringgetVersion()Return the VCS command's version string, or an empty string if the version cannot be determined. abstract StringgetDefaultBranchName(String url)Return the name of the default branch for the repository at url. abstract WorkingTreegetWorkingTree(File vcsDirectory)Return a working tree instance for this VCS. final BooleanisApplicableType(VcsType vcsType)Return true if this VCS can handle the given vcsType. final BooleanisApplicableUrl(String vcsUrl)Return true if this VersionControlSystem can be used to download from the provided vcsUrl. final BooleanisAvailable()Return true if this VersionControlSystem is available for use. final WorkingTreedownload(Package pkg, File targetDir, Boolean allowMovingRevisions, Boolean recursive)Download the source code as specified by the pkg information to targetDir. final Result<List<String>>getRevisionCandidates(WorkingTree workingTree, Package pkg, Boolean allowMovingRevisions)Get a list of distinct revision candidates for the package. abstract WorkingTreeinitWorkingTree(File targetDir, VcsInfo vcs)Initialize the working tree without checking out any files yet. abstract Result<String>updateWorkingTree(WorkingTree workingTree, String revision, String path, Boolean recursive)Update the working tree by checking out the given revision, optionally limited to the given path and recursively updating any nested working trees. final Result<Boolean>isFixedRevision(WorkingTree workingTree, String revision)Check whether the given revision is likely to name a fixed revision that does not move. final BooleanisAtLeastVersion(String expectedVersion)Check whether the VCS tool is at least of the specified expectedVersion, e.g. -
-
Method Detail
-
getVersion
abstract String getVersion()
Return the VCS command's version string, or an empty string if the version cannot be determined.
-
getDefaultBranchName
abstract String getDefaultBranchName(String url)
Return the name of the default branch for the repository at url. It is expected that there always is a default branch name that implementations can fall back to, and that the returned name is non-empty.
-
getWorkingTree
abstract WorkingTree getWorkingTree(File vcsDirectory)
Return a working tree instance for this VCS.
-
isApplicableType
final Boolean isApplicableType(VcsType vcsType)
Return true if this VCS can handle the given vcsType.
-
isApplicableUrl
final Boolean isApplicableUrl(String vcsUrl)
Return true if this VersionControlSystem can be used to download from the provided vcsUrl. First, try to find this out by only parsing the URL, but as a fallback implementations may actually probe the URL and make a network request.
-
isAvailable
final Boolean isAvailable()
Return true if this VersionControlSystem is available for use.
-
download
final WorkingTree download(Package pkg, File targetDir, Boolean allowMovingRevisions, Boolean recursive)
Download the source code as specified by the pkg information to targetDir. allowMovingRevisions toggles whether to allow downloads using symbolic names that point to moving revisions, like Git branches. If recursive is
true, any nested repositories (like Git submodules or Mercurial subrepositories) are downloaded, too.- Returns:
An object describing the downloaded working tree.
-
getRevisionCandidates
final Result<List<String>> getRevisionCandidates(WorkingTree workingTree, Package pkg, Boolean allowMovingRevisions)
Get a list of distinct revision candidates for the package. The iteration order of the elements in the list represents the priority of the revision candidates. If no revision candidates can be found a DownloadException is thrown.
The provided workingTree must have been created from the processed VCS information of the package for the function to return correct results.
allowMovingRevisions toggles whether candidates with symbolic names that point to moving revisions, like Git branches, are accepted or not.
Revision candidates are created from the processed VCS information of the package and from guessing revisions based on the name and version of the package. This is useful when the metadata of the package does not contain a revision or if the revision points to a non-fetchable commit, but the repository still has a tag for the package version.
-
initWorkingTree
abstract WorkingTree initWorkingTree(File targetDir, VcsInfo vcs)
Initialize the working tree without checking out any files yet.
-
updateWorkingTree
abstract Result<String> updateWorkingTree(WorkingTree workingTree, String revision, String path, Boolean recursive)
Update the working tree by checking out the given revision, optionally limited to the given path and recursively updating any nested working trees. Return a Result that encapsulates the originally requested revision on success, or the occurred exception on failure.
-
isFixedRevision
final Result<Boolean> isFixedRevision(WorkingTree workingTree, String revision)
Check whether the given revision is likely to name a fixed revision that does not move. Return a Result with a Boolean on success, or with a Throwable is there was a failure.
-
isAtLeastVersion
final Boolean isAtLeastVersion(String expectedVersion)
Check whether the VCS tool is at least of the specified expectedVersion, e.g. to check for features.
-
-
-
-