forked from oss-review-toolkit/ort
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(scanner): Filter scan results by scanner name
When a project scanner is configured alongside a package scanner, the scan results could be duplicated if the provenances of those packages are overlapping (e.g. in the case of repositories with Git submodules). This commit addresses the bug by constructing a map of packages with their scanners and filtering the scan results using this map. Fixes oss-review-toolkit#7231. Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.io>
- Loading branch information
Showing
5 changed files
with
205 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
scanner/src/funTest/assets/analyzer-result_for_multiple_scanners.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
--- | ||
repository: | ||
vcs: | ||
type: "Git" | ||
url: "https://github.com/nnobelis/spdx-project.git" | ||
revision: "8fae7f2b0efa8addeadfd15041e3437d92ff6b71" | ||
path: "" | ||
vcs_processed: | ||
type: "Git" | ||
url: "https://github.com/nnobelis/spdx-project.git" | ||
revision: "8fae7f2b0efa8addeadfd15041e3437d92ff6b71" | ||
path: "" | ||
nested_repositories: | ||
spdx-dependency: | ||
type: "Git" | ||
url: "https://github.com/nnobelis/spdx-dependency.git" | ||
revision: "78c8a5b12ae2d0f613fff25f2d1eb746a768ece7" | ||
path: "" | ||
config: {} | ||
analyzer: | ||
start_time: "2023-07-10T11:03:42.648265Z" | ||
end_time: "2023-07-10T11:03:43.379659Z" | ||
environment: | ||
ort_version: "9e03ee5" | ||
java_version: "11.0.19" | ||
os: "Linux" | ||
processors: 8 | ||
max_memory: 12884901888 | ||
variables: | ||
JAVA_HOME: "/opt/java/openjdk" | ||
ANDROID_HOME: "/opt/android-sdk" | ||
GOPATH: "/tmp/go" | ||
tool_versions: {} | ||
config: | ||
allow_dynamic_versions: false | ||
package_managers: | ||
NPM: | ||
options: | ||
legacyPeerDeps: "true" | ||
NuGet: | ||
options: | ||
directDependenciesOnly: "true" | ||
skip_excluded: false | ||
result: | ||
projects: | ||
- id: "SpdxDocumentFile::spdx-project:" | ||
definition_file_path: "project.spdx.yml" | ||
authors: | ||
- "Nicolas Nobelis" | ||
declared_licenses: | ||
- "LicenseRef-Bosch-Proprietary" | ||
declared_licenses_processed: | ||
spdx_expression: "LicenseRef-Bosch-Proprietary" | ||
vcs: | ||
type: "Git" | ||
url: "https://github.com/nnobelis/spdx-project.git" | ||
revision: "8fae7f2b0efa8addeadfd15041e3437d92ff6b71" | ||
path: "" | ||
vcs_processed: | ||
type: "Git" | ||
url: "https://github.com/nnobelis/spdx-project.git" | ||
revision: "8fae7f2b0efa8addeadfd15041e3437d92ff6b71" | ||
path: "" | ||
homepage_url: "" | ||
scope_names: | ||
- "default" | ||
packages: | ||
- id: "SpdxDocumentFile::spdx-dependency:" | ||
purl: "pkg:spdxdocumentfile/spdx-dependency@" | ||
authors: | ||
- "Nicolas Nobelis" | ||
declared_licenses: | ||
- "LicenseRef-Bosch-Proprietary" | ||
declared_licenses_processed: | ||
spdx_expression: "LicenseRef-Bosch-Proprietary" | ||
description: "" | ||
homepage_url: "" | ||
binary_artifact: | ||
url: "" | ||
hash: | ||
value: "" | ||
algorithm: "" | ||
source_artifact: | ||
url: "" | ||
hash: | ||
value: "" | ||
algorithm: "" | ||
vcs: | ||
type: "Git" | ||
url: "https://github.com/nnobelis/spdx-dependency.git" | ||
revision: "78c8a5b12ae2d0f613fff25f2d1eb746a768ece7" | ||
path: "" | ||
vcs_processed: | ||
type: "Git" | ||
url: "https://github.com/nnobelis/spdx-dependency.git" | ||
revision: "78c8a5b12ae2d0f613fff25f2d1eb746a768ece7" | ||
path: "" | ||
dependency_graphs: | ||
SpdxDocumentFile: | ||
packages: | ||
- "SpdxDocumentFile::spdx-dependency:" | ||
scopes: | ||
:spdx-project::default: | ||
- root: 0 | ||
nodes: | ||
- linkage: "STATIC" | ||
edges: [] | ||
scanner: null | ||
advisor: null | ||
evaluator: null | ||
resolved_configuration: | ||
package_curations: | ||
- provider: | ||
id: "RepositoryConfiguration" | ||
curations: [] | ||
- provider: | ||
id: "File" | ||
curations: [] | ||
- provider: | ||
id: "OrtConfig" | ||
curations: [] | ||
- provider: | ||
id: "ClearlyDefined" | ||
curations: [] |
54 changes: 54 additions & 0 deletions
54
scanner/src/funTest/kotlin/scanners/MultipleScannersTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2023 The ORT Project Authors (see <https://github.com/oss-review-toolkit/ort/blob/main/NOTICE>) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* License-Filename: LICENSE | ||
*/ | ||
|
||
package org.ossreviewtoolkit.scanner.scanners | ||
|
||
import io.kotest.core.spec.style.WordSpec | ||
import io.kotest.matchers.shouldBe | ||
|
||
import org.ossreviewtoolkit.model.Identifier | ||
import org.ossreviewtoolkit.model.OrtResult | ||
import org.ossreviewtoolkit.model.PackageType | ||
import org.ossreviewtoolkit.model.fromYaml | ||
import org.ossreviewtoolkit.utils.test.getAssetFile | ||
import org.ossreviewtoolkit.utils.test.shouldNotBeNull | ||
|
||
class MultipleScannersTest : WordSpec({ | ||
"Scanning a set of packages with overlapping provenance" should { | ||
val analyzerResult = | ||
getAssetFile("analyzer-result_for_multiple_scanners.yml").readText().fromYaml<OrtResult>() | ||
|
||
val dummyScanners = DummyScanner() | ||
val ortResult = createScanner().copy( | ||
scannerWrappers = mapOf( | ||
PackageType.PROJECT to listOf(dummyScanners.copy(name = "Dummy2")), | ||
PackageType.PACKAGE to listOf(dummyScanners) | ||
) | ||
).scan(analyzerResult, skipExcluded = false, emptyMap()) | ||
|
||
"return the expected ORT result" { | ||
ortResult.scanner.shouldNotBeNull { | ||
val results = getScanResults(Identifier("SpdxDocumentFile", "", "spdx-project", "")) | ||
results.map { it.scanner.name }.toSet() shouldBe setOf("Dummy2") | ||
val results2 = getScanResults(Identifier("SpdxDocumentFile", "", "spdx-dependency", "")) | ||
results2.map { it.scanner.name }.toSet() shouldBe setOf("Dummy") | ||
} | ||
} | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters