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

fix(compose): Ignore definition files from vendor directories #8981

Merged
merged 1 commit into from
Aug 15, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ package org.ossreviewtoolkit.plugins.packagemanagers.composer

import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.collections.beEmpty
import io.kotest.matchers.collections.containExactly
import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.haveSubstring

import java.io.File

import org.ossreviewtoolkit.analyzer.create
import org.ossreviewtoolkit.analyzer.resolveSingleProject
import org.ossreviewtoolkit.model.Identifier
Expand All @@ -34,6 +37,22 @@ import org.ossreviewtoolkit.utils.test.getAssetFile
import org.ossreviewtoolkit.utils.test.matchExpectedResult

class ComposerFunTest : StringSpec({
"Project files from vendor directories are ignored" {
val projectFiles = create("Composer").mapDefinitionFiles(
listOf(
"projectA/composer.json",
"projectA/vendor/dependency1/composer.json",
"projectB/composer.json",
"projectB/vendor/dependency2/composer.json"
).map { File(it) }
)

projectFiles.map { it.path } should containExactly(
"projectA/composer.json",
"projectB/composer.json"
)
mnonnenmacher marked this conversation as resolved.
Show resolved Hide resolved
}

"Project dependencies are detected correctly" {
val definitionFile = getAssetFile("projects/synthetic/lockfile/composer.json")
val expectedResultFile = getAssetFile("projects/synthetic/composer-expected-output.yml")
Expand Down
13 changes: 13 additions & 0 deletions plugins/package-managers/composer/src/main/kotlin/Composer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ class Composer(
checkVersion()
}

override fun mapDefinitionFiles(definitionFiles: List<File>): List<File> {
val projectFiles = definitionFiles.toMutableList()

var index = 0
while (index < projectFiles.size - 1) {
val projectFile = projectFiles[index++]
val vendorDir = projectFile.resolveSibling("vendor")
projectFiles.subList(index, projectFiles.size).removeAll { it.startsWith(vendorDir) }
}

return projectFiles
}

override fun resolveDependencies(definitionFile: File, labels: Map<String, String>): List<ProjectAnalyzerResult> {
val workingDir = definitionFile.parentFile

Expand Down
Loading