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
The scanner may use different set of scanners for scanning different packages. The same holds for projects. `ScannerRun` does not contain that information, and `ScannerRun.getScanResultsById()` just returns all scans matching the package (nested) provenance, disregarding which scanners are to be used for the particular package. Extend the data model to contain that information and use it to adjust the internals of `getScanResultsById()` to adhere to the set of scanners to be used for the particular project or package. Fixes oss-review-toolkit#7231. Signed-off-by: Nicolas Nobelis <nicolas.nobelis@bosch.io>
- Loading branch information
Showing
5 changed files
with
129 additions
and
10 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
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
97 changes: 97 additions & 0 deletions
97
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,97 @@ | ||
/* | ||
* 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.collections.containExactly | ||
import io.kotest.matchers.should | ||
|
||
import org.ossreviewtoolkit.model.AnalyzerResult | ||
import org.ossreviewtoolkit.model.AnalyzerRun | ||
import org.ossreviewtoolkit.model.Identifier | ||
import org.ossreviewtoolkit.model.OrtResult | ||
import org.ossreviewtoolkit.model.Package | ||
import org.ossreviewtoolkit.model.PackageType | ||
import org.ossreviewtoolkit.model.Project | ||
import org.ossreviewtoolkit.model.VcsInfo | ||
import org.ossreviewtoolkit.model.VcsType | ||
import org.ossreviewtoolkit.utils.test.shouldNotBeNull | ||
|
||
private val PROJECT_IDENTIFIER = Identifier("Dummy", "", "project", "1.0.0") | ||
private val PACKAGE_IDENTIFIER = Identifier("Dummy", "", "pkg1", "1.0.0") | ||
|
||
class MultipleScannersTest : WordSpec({ | ||
"Scanning a project and a package with overlapping provenance and non overlapping scanners" should { | ||
val analyzerResult = createAnalyzerResult() | ||
|
||
val dummyScanner = DummyScanner() | ||
val scannerWrappers = mapOf( | ||
PackageType.PROJECT to listOf(dummyScanner.copy(name = "Dummy2")), | ||
PackageType.PACKAGE to listOf(dummyScanner) | ||
) | ||
val ortResult = createScanner(scannerWrappers).scan(analyzerResult, skipExcluded = false, emptyMap()) | ||
|
||
"return scan results with non-overlapping scanners" { | ||
ortResult.scanner.shouldNotBeNull { | ||
val results = getScanResults(PROJECT_IDENTIFIER) | ||
results.map { it.scanner.name }.toSet() should containExactly("Dummy2") | ||
val results2 = getScanResults(PACKAGE_IDENTIFIER) | ||
results2.map { it.scanner.name }.toSet() should containExactly("Dummy") | ||
} | ||
} | ||
} | ||
}) | ||
|
||
private fun createAnalyzerResult(): OrtResult { | ||
val vcsPackage = VcsInfo( | ||
type = VcsType.GIT, | ||
url = "https://github.com/oss-review-toolkit/ort-test-data-scanner.git", | ||
revision = "97d57bb4795bc41f496e1a8e2c7751cefc7da7ec", | ||
path = "" | ||
) | ||
|
||
val pkg = Package.EMPTY.copy( | ||
id = PACKAGE_IDENTIFIER, | ||
vcs = vcsPackage, | ||
vcsProcessed = vcsPackage.normalize() | ||
) | ||
|
||
val vcsProject = VcsInfo( | ||
type = VcsType.GIT, | ||
url = "https://github.com/oss-review-toolkit/ort-test-data-scanner.git", | ||
revision = "97d57bb4795bc41f496e1a8e2c7751cefc7da7ec", | ||
path = "" | ||
) | ||
|
||
val project = Project.EMPTY.copy( | ||
id = PROJECT_IDENTIFIER, | ||
vcs = vcsProject, | ||
vcsProcessed = vcsProject.normalize() | ||
) | ||
|
||
val analyzerRun = AnalyzerRun.EMPTY.copy( | ||
result = AnalyzerResult.EMPTY.copy( | ||
projects = setOf(project), | ||
packages = setOf(pkg) | ||
) | ||
) | ||
|
||
return OrtResult.EMPTY.copy(analyzer = analyzerRun) | ||
} |
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