Skip to content

Commit 4df7b90

Browse files
wkl3nksschuberth
authored andcommitted
feat(downloader): Support plugin configs when creating working tree cache
Add ability to pass VCS plugin configurations when creating a VersionControlSystem instance for a working tree cache. This enables customizing VCS behavior during repository checkout. For example, Git submodule handling can be configured to fetch only top-level submodules. Signed-off-by: Wolfgang Klenk <[email protected]>
1 parent 7d2e86a commit 4df7b90

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

downloader/src/main/kotlin/WorkingTreeCache.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import kotlinx.coroutines.sync.withLock
2727
import org.apache.logging.log4j.kotlin.logger
2828

2929
import org.ossreviewtoolkit.model.VcsInfo
30+
import org.ossreviewtoolkit.plugins.api.PluginConfig
3031
import org.ossreviewtoolkit.utils.common.safeDeleteRecursively
3132
import org.ossreviewtoolkit.utils.ort.createOrtTempDir
3233

@@ -55,11 +56,23 @@ interface WorkingTreeCache {
5556

5657
class DefaultWorkingTreeCache : WorkingTreeCache {
5758
private val mutex = Mutex()
59+
private val vcsPluginConfigs = mutableMapOf<String, PluginConfig>()
5860
private val workingTreeMutexes = mutableMapOf<String, Mutex>()
5961
private val workingTrees = mutableMapOf<String, WorkingTree>()
6062

6163
private var terminated = false
6264

65+
/**
66+
* Add [VCS plugin configurations][configs] that are applied when creating a [VersionControlSystem] instance
67+
* for this working tree. Calling this function is optional.
68+
*/
69+
@Suppress("unused") // Intended for use when this class is consumed externally as a library.
70+
fun addVcsPluginConfigs(configs: Map<String, PluginConfig>): DefaultWorkingTreeCache {
71+
logger.debug { "Using VCS plugin configs: $configs" }
72+
vcsPluginConfigs += configs
73+
return this
74+
}
75+
6376
override suspend fun <T> use(vcsInfo: VcsInfo, block: (VersionControlSystem, WorkingTree) -> T): T {
6477
val vcs = getVcs(vcsInfo)
6578
return getWorkingTreeMutex(vcsInfo).withLock { block(vcs, getWorkingTree(vcsInfo, vcs)) }
@@ -75,8 +88,8 @@ class DefaultWorkingTreeCache : WorkingTreeCache {
7588
}
7689

7790
private fun getVcs(vcsInfo: VcsInfo) =
78-
VersionControlSystem.forType(vcsInfo.type)
79-
?: VersionControlSystem.forUrl(vcsInfo.url)
91+
VersionControlSystem.forType(vcsInfo.type, vcsPluginConfigs)
92+
?: VersionControlSystem.forUrl(vcsInfo.url, vcsPluginConfigs)
8093
?: throw IOException("Could not determine VCS for type '${vcsInfo.type}' and URL ${vcsInfo.url}.")
8194

8295
private fun getWorkingTree(vcsInfo: VcsInfo, vcs: VersionControlSystem) =

0 commit comments

Comments
 (0)