Skip to content

Commit

Permalink
OrtMain: Invoke withResolvedScopes() in readOrtResult()
Browse files Browse the repository at this point in the history
This makes sure that all commands that process ORT result files can
access fully initialized projects with scope information.

Signed-off-by: Oliver Heger <oliver.heger@bosch.io>
  • Loading branch information
oheger-bosch committed May 11, 2021
1 parent a0ffecf commit 8e38b04
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 2 deletions.
215 changes: 215 additions & 0 deletions cli/src/funTest/assets/analyzer-result-with-dependency-graph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
---
repository:
vcs:
type: "Git"
url: "https://github.com/vdurmont/semver4j.git"
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
path: ""
vcs_processed:
type: "Git"
url: "https://github.com/vdurmont/semver4j.git"
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
path: ""
config: {}
analyzer:
start_time: "2021-04-26T05:48:05.390356Z"
end_time: "2021-04-26T05:48:13.604832Z"
environment:
ort_version: "9d23fdf"
java_version: "11.0.8"
os: "Linux"
processors: 4
max_memory: 12884901888
variables:
JAVA_HOME: "/opt/java/openjdk"
ANDROID_HOME: "/opt/android-sdk"
GOPATH: "/go"
tool_versions: {}
config:
ignore_tool_versions: false
allow_dynamic_versions: false
result:
projects:
- id: "Maven:com.vdurmont:semver4j:3.1.0"
definition_file_path: "pom.xml"
authors:
- "Vincent DURMONT"
declared_licenses:
- "The MIT License"
declared_licenses_processed:
spdx_expression: "MIT"
mapped:
The MIT License: "MIT"
vcs:
type: "Git"
url: "git@github.com:vdurmont/semver4j.git"
revision: ""
path: ""
vcs_processed:
type: "Git"
url: "https://github.com/vdurmont/semver4j.git"
revision: "7653e418d610ffcd2811bcb55fd72d00d420950b"
path: ""
homepage_url: "https://github.com/vdurmont/semver4j"
scope_names:
- "test"
packages:
- package:
id: "Maven:junit:junit:4.12"
purl: "pkg:maven/junit/junit@4.12"
authors:
- "David Saff"
- "JUnit"
- "Kevin Cooney"
- "Marc Philipp"
- "Stefan Birkner"
declared_licenses:
- "Eclipse Public License 1.0"
declared_licenses_processed:
spdx_expression: "EPL-1.0"
mapped:
Eclipse Public License 1.0: "EPL-1.0"
concluded_license: "EPL-1.0"
description: "JUnit is a unit testing framework for Java, created by Erich\
\ Gamma and Kent Beck."
homepage_url: "http://junit.org"
binary_artifact:
url: "https://repo.maven.apache.org/maven2/junit/junit/4.12/junit-4.12.jar"
hash:
value: "2973d150c0dc1fefe998f834810d68f278ea58ec"
algorithm: "SHA-1"
source_artifact:
url: "https://repo.maven.apache.org/maven2/junit/junit/4.12/junit-4.12-sources.jar"
hash:
value: "a6c32b40bf3d76eca54e3c601e5d1470c86fcdfa"
algorithm: "SHA-1"
vcs:
type: "Git"
url: "https://github.com/junit-team/junit4.git"
revision: "r4.12"
path: ""
vcs_processed:
type: "Git"
url: "https://github.com/junit-team/junit4.git"
revision: "r4.12"
path: ""
curations:
- base:
vcs:
type: "Git"
url: "git://github.com/junit-team/junit.git"
revision: "r4.12"
path: ""
curation:
comment: "ScanCode claims to find some NOASSERTION and Apache-2.0 in the\
\ FAQ and the pom.xml, both are false-positives."
concluded_license: "EPL-1.0"
vcs:
type: "Git"
url: "https://github.com/junit-team/junit4.git"
revision: "r4.12"
- package:
id: "Maven:org.hamcrest:hamcrest-core:1.3"
purl: "pkg:maven/org.hamcrest/hamcrest-core@1.3"
authors:
- "Joe Walnes"
- "Nat Pryce"
- "Neil Dunn"
- "Steve Freeman"
- "Tom Denley"
declared_licenses:
- "BSD-3-Clause"
declared_licenses_processed:
spdx_expression: "BSD-3-Clause"
description: "This is the core API of hamcrest matcher framework to be used\
\ by third-party framework providers. This includes the a foundation set\
\ of matcher implementations for common operations."
homepage_url: "https://github.com/hamcrest/JavaHamcrest/hamcrest-core"
binary_artifact:
url: "https://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"
hash:
value: "42a25dc3219429f0e5d060061f71acb49bf010a0"
algorithm: "SHA-1"
source_artifact:
url: "https://repo.maven.apache.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar"
hash:
value: "1dc37250fbc78e23a65a67fbbaf71d2e9cbc3c0b"
algorithm: "SHA-1"
vcs:
type: "Git"
url: "git@github.com:hamcrest/JavaHamcrest.git"
revision: ""
path: ""
vcs_processed:
type: "Git"
url: "ssh://git@github.com/hamcrest/JavaHamcrest.git"
revision: ""
path: ""
curations:
- base:
declared_licenses:
- "New BSD License"
curation:
comment: "Provided by ClearlyDefined."
declared_licenses:
- "BSD-3-Clause"
- package:
id: "Maven:org.mockito:mockito-all:1.10.19"
purl: "pkg:maven/org.mockito/mockito-all@1.10.19"
authors:
- "Szczepan Faber"
declared_licenses:
- "MIT"
declared_licenses_processed:
spdx_expression: "MIT"
description: "Mock objects library for java"
homepage_url: "http://www.mockito.org"
binary_artifact:
url: "https://repo.maven.apache.org/maven2/org/mockito/mockito-all/1.10.19/mockito-all-1.10.19.jar"
hash:
value: "539df70269cc254a58cccc5d8e43286b4a73bf30"
algorithm: "SHA-1"
source_artifact:
url: "https://repo.maven.apache.org/maven2/org/mockito/mockito-all/1.10.19/mockito-all-1.10.19-sources.jar"
hash:
value: "8269667b73d9616600359a9b0ba1b1c7d0cf7a97"
algorithm: "SHA-1"
vcs:
type: ""
url: ""
revision: ""
path: ""
vcs_processed:
type: ""
url: ""
revision: ""
path: ""
curations:
- base:
declared_licenses:
- "The MIT License"
curation:
comment: "Provided by ClearlyDefined."
declared_licenses:
- "MIT"
dependency_graphs:
Maven:
packages:
- "Maven:junit:junit:4.12"
- "Maven:org.hamcrest:hamcrest-core:1.3"
- "Maven:org.mockito:mockito-all:1.10.19"
scope_roots:
- dependencies:
- pkg: 1
- pkg: 2
scopes:
com.vdurmont:semver4j:3.1.0:test:
- root: 0
- root: 2
has_issues: false
scanner: null
advisor: null
evaluator: null
labels:
applicationCategory: "BT05 Client application"
projectName: "Semver4jNewDependencyGraphShared"
23 changes: 23 additions & 0 deletions cli/src/funTest/kotlin/OrtMainFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,24 @@ import com.github.ajalt.clikt.core.ProgramResult
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.StringSpec
import io.kotest.core.test.TestCase
import io.kotest.matchers.collections.beEmpty
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNot

import java.io.File

import org.ossreviewtoolkit.commands.AdvisorCommand
import org.ossreviewtoolkit.downloader.VersionControlSystem
import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.OrtResult
import org.ossreviewtoolkit.model.readValue
import org.ossreviewtoolkit.utils.normalizeVcsUrl
import org.ossreviewtoolkit.utils.redirectStdout
import org.ossreviewtoolkit.utils.test.createTestTempDir
import org.ossreviewtoolkit.utils.test.patchActualResult
import org.ossreviewtoolkit.utils.test.patchExpectedResult
import org.ossreviewtoolkit.utils.test.shouldNotBeNull

/**
* A test for the main entry point of the application.
Expand Down Expand Up @@ -160,6 +166,23 @@ class OrtMainFunTest : StringSpec() {
)
}
}

"Commands load OrtResults with resolved scopes" {
val cmd = AdvisorCommand()
val resultFile = File("src/funTest/assets/analyzer-result-with-dependency-graph.yml")

val result = cmd.readOrtResult(resultFile)

result.analyzer?.result shouldNotBeNull {
dependencyGraphs.keys should beEmpty()
}

val project = result.getProject(Identifier("Maven:com.vdurmont:semver4j:3.1.0"))

project.shouldNotBeNull {
scopes shouldNot beEmpty()
}
}
}

private fun runMain(vararg args: String) =
Expand Down
5 changes: 3 additions & 2 deletions cli/src/main/kotlin/OrtMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,13 @@ class OrtMain : CliktCommand(name = ORT_NAME, invokeWithoutSubcommand = true) {
}

/**
* Read [ortFile] into an [OrtResult] and return it.
* Read [ortFile] into an [OrtResult] and return it. Make sure that information about project scopes is available
* (by calling [OrtResult.withResolvedScopes]), so that it can be processed.
*/
fun CliktCommand.readOrtResult(ortFile: File): OrtResult {
log.debug { "Input ORT result file has SHA-1 hash ${HashAlgorithm.SHA1.calculate(ortFile)}." }

val (ortResult, duration) = measureTimedValue { ortFile.readValue<OrtResult>() }
val (ortResult, duration) = measureTimedValue { ortFile.readValue<OrtResult>().withResolvedScopes() }

log.perf {
"Read ORT result from '${ortFile.name}' (${ortFile.formatSizeInMib}) in ${duration.inMilliseconds}ms."
Expand Down

0 comments on commit 8e38b04

Please sign in to comment.