Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analyzer): Remove analyzer job configuration recursiveCheckout #1904

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions api/v1/mapping/src/commonMain/kotlin/Mappings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ fun AnalyzerJobConfiguration.mapToApi() =
disabledPackageManagers,
enabledPackageManagers,
environmentConfig?.mapToApi(),
recursiveCheckout,
submoduleFetchStrategy?.mapToApi(),
packageCurationProviders.map { it.mapToApi() },
packageManagerOptions?.mapValues { it.value.mapToApi() },
Expand All @@ -210,7 +209,6 @@ fun ApiAnalyzerJobConfiguration.mapToModel() =
disabledPackageManagers,
enabledPackageManagers,
environmentConfig?.mapToModel(),
recursiveCheckout,
submoduleFetchStrategy?.mapToModel(),
packageCurationProviders?.map { it.mapToModel() }.orEmpty(),
packageManagerOptions?.mapValues { it.value.mapToModel() },
Expand Down
11 changes: 1 addition & 10 deletions api/v1/model/src/commonMain/kotlin/JobConfigurations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,10 @@ data class AnalyzerJobConfiguration(
*/
val environmentConfig: EnvironmentConfig? = null,

/**
* A flag indicating whether the submodules of the repository should be downloaded during the download process.
* If set to `true`, submodules will be downloaded; if `false`, they will be ignored.
*
* Note: This attribute is deprecated and will be removed in a future release. Use [submoduleFetchStrategy] instead.
*
*/
val recursiveCheckout: Boolean = true,

/**
* The strategy to use for fetching submodules.
*/
val submoduleFetchStrategy: SubmoduleFetchStrategy? = null,
val submoduleFetchStrategy: SubmoduleFetchStrategy? = SubmoduleFetchStrategy.FULLY_RECURSIVE,

/**
* The list of package curation providers to use.
Expand Down
1 change: 0 additions & 1 deletion core/src/main/kotlin/apiDocs/RepositoriesDocs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ internal val fullJobConfigurations = JobConfigurations(
options = mapOf("gradleVersion" to "8.1.1")
)
),
recursiveCheckout = true,
submoduleFetchStrategy = FULLY_RECURSIVE,
skipExcluded = true
),
Expand Down
10 changes: 1 addition & 9 deletions model/src/commonMain/kotlin/JobConfigurations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,12 @@ data class AnalyzerJobConfiguration(
*/
val environmentConfig: EnvironmentConfig? = null,

/**
* A flag indicating whether the submodules of the repository should be downloaded during the download process.
* If set to `true`, submodules will be downloaded; if `false`, they will be ignored.
*
* Note: This attribute is deprecated and will be removed in a future release. Use [submoduleFetchStrategy] instead.
*/
val recursiveCheckout: Boolean = true,

/**
* The strategy to use for fetching submodules.
*
* Note: Submodule fetch strategy [SubmoduleFetchStrategy.TOP_LEVEL_ONLY] is only supported for Git repositories.
*/
val submoduleFetchStrategy: SubmoduleFetchStrategy? = null,
val submoduleFetchStrategy: SubmoduleFetchStrategy? = SubmoduleFetchStrategy.FULLY_RECURSIVE,

/**
* The list of package curation providers to use.
Expand Down
23 changes: 3 additions & 20 deletions workers/analyzer/src/main/kotlin/analyzer/AnalyzerDownloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class AnalyzerDownloader {
repositoryUrl: String,
revision: String,
path: String = "",
recursiveCheckout: Boolean = true, // Deprecated: Will be removed in a future release
submoduleFetchStrategy: SubmoduleFetchStrategy? = null
submoduleFetchStrategy: SubmoduleFetchStrategy? = SubmoduleFetchStrategy.FULLY_RECURSIVE
): File {
logger.info("Downloading repository '$repositoryUrl' revision '$revision'.")

Expand All @@ -57,11 +56,9 @@ class AnalyzerDownloader {
path = path
)

// The [submoduleFetchStrategy] parameter takes precedence over the deprecated [recursiveCheckout] parameter.
val combinedRecursiveCheckout = evaluateRecursiveCheckoutParameter(recursiveCheckout, submoduleFetchStrategy)

val workingTree = vcs.initWorkingTree(outputDir, vcsInfo)
vcs.updateWorkingTree(workingTree, revision, recursive = combinedRecursiveCheckout).getOrThrow()
val recursiveCheckout = submoduleFetchStrategy != SubmoduleFetchStrategy.DISABLED
vcs.updateWorkingTree(workingTree, revision, recursive = recursiveCheckout).getOrThrow()

logger.info("Finished downloading '$repositoryUrl' revision '$revision'.")

Expand Down Expand Up @@ -89,18 +86,4 @@ class AnalyzerDownloader {
} else {
emptyMap()
}

/**
* Evaluate the [recursiveCheckout] and the [submoduleFetchStrategy] parameter to determine if the working tree
* should be checked out recursively. The [submoduleFetchStrategy] parameter takes precedence over the
* deprecated [recursiveCheckout] parameter.
*/
internal fun evaluateRecursiveCheckoutParameter(
recursiveCheckout: Boolean, submoduleFetchStrategy: SubmoduleFetchStrategy?
) =
if (submoduleFetchStrategy != null) {
submoduleFetchStrategy != SubmoduleFetchStrategy.DISABLED
} else {
recursiveCheckout
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ internal class AnalyzerWorker(
repository.url,
ortRun.revision,
ortRun.path.orEmpty(),
job.configuration.recursiveCheckout,
job.configuration.submoduleFetchStrategy
)

Expand Down
81 changes: 1 addition & 80 deletions workers/analyzer/src/test/kotlin/AnalyzerDownloaderTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import io.kotest.matchers.maps.shouldContainExactly
import io.kotest.matchers.maps.shouldNotBeEmpty
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNot

import java.io.IOException
Expand All @@ -45,23 +44,6 @@ class AnalyzerDownloaderTest : WordSpec({
val downloader = AnalyzerDownloader()

"downloadRepository" should {
"not recursively clone a Git repository if recursiveCheckout is false" {
val repositoryUrl = "https://github.com/oss-review-toolkit/ort-test-data-git-submodules.git"
val revision = "fcea94bab5835172e826afddb9f6427274c983b9"

val outputDir = downloader.downloadRepository(repositoryUrl, revision, recursiveCheckout = false)

outputDir shouldContainFile "LICENSE"
outputDir shouldContainFile "README.md"

outputDir.resolve("commons-text") should beEmptyDirectory()
outputDir.resolve("test-data-npm") should beEmptyDirectory()

val workingTree = VersionControlSystem.forDirectory(outputDir)
workingTree.shouldNotBeNull()
workingTree.getNested().shouldBeEmpty()
}

"not recursively clone a Git repository if submoduleFetchStrategy is DISABLED" {
val repositoryUrl = "https://github.com/oss-review-toolkit/ort-test-data-git-submodules.git"
val revision = "fcea94bab5835172e826afddb9f6427274c983b9"
Expand All @@ -81,48 +63,8 @@ class AnalyzerDownloaderTest : WordSpec({
workingTree.getNested().shouldBeEmpty()
}

"recursively clone a Git repository if recursiveCheckout is true" {
val repositoryUrl = "https://github.com/oss-review-toolkit/ort-test-data-git-submodules.git"
val revision = "fcea94bab5835172e826afddb9f6427274c983b9"

val outputDir = downloader.downloadRepository(repositoryUrl, revision, recursiveCheckout = true)

outputDir shouldContainFile "LICENSE"
outputDir shouldContainFile "README.md"

outputDir.resolve("commons-text") shouldNot beEmptyDirectory()
outputDir.resolve("test-data-npm") shouldNot beEmptyDirectory()

val workingTree = VersionControlSystem.forDirectory(outputDir)
workingTree.shouldNotBeNull()
workingTree.getNested() shouldContainExactly mapOf(
"commons-text" to VcsInfo(
type = VcsType.GIT,
url = "https://github.com/apache/commons-text.git",
revision = "7643b12421100d29fd2b78053e77bcb04a251b2e"
),
"test-data-npm" to VcsInfo(
type = VcsType.GIT,
url = "https://github.com/oss-review-toolkit/ort-test-data-npm.git",
revision = "ad0367b7b9920144a47b8d30cc0c84cea102b821"
),
"test-data-npm/isarray" to VcsInfo(
type = VcsType.GIT,
url = "https://github.com/juliangruber/isarray.git",
revision = "63ea4ca0a0d6b0574d6a470ebd26880c3026db4a"
),
"test-data-npm/long.js" to VcsInfo(
type = VcsType.GIT,
url = "https://github.com/dcodeIO/long.js.git",
revision = "941c5c62471168b5d18153755c2a7b38d2560e58"
)
)
}

"clone only the top level of a Git repository if submoduleFetchStrategy is TOP_LEVEL_ONLY" {
// Intentionally using https://www.github.com instead of https://github.com as a workaround
// for bug https://github.com/oss-review-toolkit/ort/issues/9795
val repositoryUrl = "https://www.github.com/oss-review-toolkit/ort-test-data-git-submodules.git"
val repositoryUrl = "https://github.com/oss-review-toolkit/ort-test-data-git-submodules.git"
val revision = "fcea94bab5835172e826afddb9f6427274c983b9"

val outputDir = downloader.downloadRepository(
Expand Down Expand Up @@ -276,25 +218,4 @@ class AnalyzerDownloaderTest : WordSpec({
}
}
}

"evaluateCombinedRecursiveCheckoutParameter" should {
val testData = listOf(
Triple(true, null, true),
Triple(false, null, false),
Triple(true, SubmoduleFetchStrategy.DISABLED, false),
Triple(false, SubmoduleFetchStrategy.DISABLED, false),
Triple(true, SubmoduleFetchStrategy.TOP_LEVEL_ONLY, true),
Triple(false, SubmoduleFetchStrategy.TOP_LEVEL_ONLY, true),
Triple(true, SubmoduleFetchStrategy.FULLY_RECURSIVE, true),
Triple(false, SubmoduleFetchStrategy.FULLY_RECURSIVE, true)
)

testData.forEach { (recursiveCheckout, submoduleFetchStrategy, expected) ->
"return $expected for recursiveCheckout $recursiveCheckout " +
"and submoduleFetchStrategy $submoduleFetchStrategy" {
val result = downloader.evaluateRecursiveCheckoutParameter(recursiveCheckout, submoduleFetchStrategy)
result shouldBe expected
}
}
}
})
Loading