Skip to content

Commit

Permalink
refactor(vcs): Enable to provide VCS-specific configuration options
Browse files Browse the repository at this point in the history
 While VCS implementations are already plugins, they are not yet
 configurable. VCS implementations require common configurations
 (e.g., `revision`, `recursive`) and should support also
 VCS-specific configurations.

 This refactoring keeps the common configurations attributes as
 they are, while VCS-specific configurations are stored
 generically in an `options` attribute.

Fixes oss-review-toolkit#8556.

Signed-off-by: Wolfgang Klenk <[email protected]>
  • Loading branch information
wkl3nk committed Oct 21, 2024
1 parent 89af4ed commit 6534363
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
4 changes: 3 additions & 1 deletion downloader/src/main/kotlin/VersionControlSystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.model.config.LicenseFilePatterns
import org.ossreviewtoolkit.model.orEmpty
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.Options
import org.ossreviewtoolkit.utils.common.Plugin
import org.ossreviewtoolkit.utils.common.collectMessages
import org.ossreviewtoolkit.utils.common.uppercaseFirstChar
Expand Down Expand Up @@ -387,7 +388,8 @@ abstract class VersionControlSystem(
workingTree: WorkingTree,
revision: String,
path: String = "",
recursive: Boolean = false
recursive: Boolean = false,
options: Options = emptyMap() // VCS-specific options only
): Result<String>

/**
Expand Down
4 changes: 3 additions & 1 deletion downloader/src/test/kotlin/VersionControlSystemTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.plugins.versioncontrolsystems.git.Git
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.Options

class VersionControlSystemTest : WordSpec({
val vcsRoot = File("..").absoluteFile.normalize()
Expand Down Expand Up @@ -168,6 +169,7 @@ private class VersionControlSystemTestImpl(
workingTree: WorkingTree,
revision: String,
path: String,
recursive: Boolean
recursive: Boolean,
options: Options // VersionControlSystemTestImpl-specific configuration options only
): Result<String> = Result.failure(UnsupportedOperationException("Unexpected invocation."))
}
4 changes: 3 additions & 1 deletion plugins/version-control-systems/git/src/main/kotlin/Git.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import org.ossreviewtoolkit.downloader.WorkingTree
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.Options
import org.ossreviewtoolkit.utils.common.Os
import org.ossreviewtoolkit.utils.common.collectMessages
import org.ossreviewtoolkit.utils.common.safeMkdirs
Expand Down Expand Up @@ -170,7 +171,8 @@ class Git : VersionControlSystem(GitCommand) {
workingTree: WorkingTree,
revision: String,
path: String,
recursive: Boolean
recursive: Boolean,
options: Options // Git-specific configuration options only
): Result<String> =
(workingTree as GitWorkingTree).useRepo {
Git(this).use { git ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.model.utils.parseRepoManifestPath
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.Options
import org.ossreviewtoolkit.utils.common.Os
import org.ossreviewtoolkit.utils.common.ProcessCapture
import org.ossreviewtoolkit.utils.common.collectMessages
Expand Down Expand Up @@ -192,7 +193,8 @@ class GitRepo : VersionControlSystem(GitRepoCommand) {
workingTree: WorkingTree,
revision: String,
path: String,
recursive: Boolean
recursive: Boolean,
options: Options // GitRepo-specific configuration options only.
): Result<String> {
val manifestRevision = revision.takeUnless { it.isBlank() }
val manifestPath = workingTree.getInfo().url.parseRepoManifestPath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.ossreviewtoolkit.downloader.WorkingTree
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.utils.common.CommandLineTool
import org.ossreviewtoolkit.utils.common.Options
import org.ossreviewtoolkit.utils.common.ProcessCapture

const val MERCURIAL_LARGE_FILES_EXTENSION = "largefiles = "
Expand Down Expand Up @@ -93,7 +94,13 @@ class Mercurial : VersionControlSystem(MercurialCommand) {
return getWorkingTree(targetDir)
}

override fun updateWorkingTree(workingTree: WorkingTree, revision: String, path: String, recursive: Boolean) =
override fun updateWorkingTree(
workingTree: WorkingTree,
revision: String,
path: String,
recursive: Boolean,
options: Options // Mercurial-specific configuration options only
) =
runCatching {
// To safe network bandwidth, only pull exactly the revision we want. Do not use "-u" to update the
// working tree just yet, as Mercurial would only update if new changesets were pulled. But that might
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.ossreviewtoolkit.downloader.VersionControlSystem
import org.ossreviewtoolkit.downloader.WorkingTree
import org.ossreviewtoolkit.model.VcsInfo
import org.ossreviewtoolkit.model.VcsType
import org.ossreviewtoolkit.utils.common.Options
import org.ossreviewtoolkit.utils.common.collectMessages
import org.ossreviewtoolkit.utils.ort.OrtAuthenticator
import org.ossreviewtoolkit.utils.ort.OrtProxySelector
Expand Down Expand Up @@ -126,7 +127,13 @@ class Subversion : VersionControlSystem() {
return pathRevisions.single()
}

override fun updateWorkingTree(workingTree: WorkingTree, revision: String, path: String, recursive: Boolean) =
override fun updateWorkingTree(
workingTree: WorkingTree,
revision: String,
path: String,
recursive: Boolean,
options: Options // Subversion-specific configuration options only.
) =
runCatching {
// Note that the path should never be part of the URL as that would root the working tree at that path, but
// the path should be available in the working tree.
Expand Down

0 comments on commit 6534363

Please sign in to comment.