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

helper-cli: Add a command to generate a flat analyzer result #7305

Merged
merged 2 commits into from
Sep 12, 2023
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
@@ -0,0 +1,113 @@
---
mnonnenmacher marked this conversation as resolved.
Show resolved Hide resolved
repository:
vcs:
type: "Git"
url: "https://github.com/example/project.git"
revision: "2222222222222222222222222222222222222222"
path: "vcs-path/project"
vcs_processed:
type: "Git"
url: "https://github.com/example/project.git"
revision: "2222222222222222222222222222222222222222"
path: "vcs-path/project"
config:
excludes:
scopes:
- pattern: "excluded"
reason: "DEV_DEPENDENCY_OF"
analyzer:
start_time: "1970-01-01T00:00:00Z"
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "1.1.0-SNAPSHOT"
java_version: "17.0.8.1"
os: "Linux"
processors: 8
max_memory: 536870912
variables: {}
tool_versions: {}
config:
allow_dynamic_versions: false
skip_excluded: false
result:
projects:
- id: "Unmanaged::Example project name:"
definition_file_path: ""
declared_licenses: []
declared_licenses_processed: {}
vcs:
type: "Git"
url: "https://github.com/example/project.git"
revision: "2222222222222222222222222222222222222222"
path: "vcs-path/project"
vcs_processed:
type: "Git"
url: "https://github.com/example/project.git"
revision: "2222222222222222222222222222222222222222"
path: "vcs-path/project"
homepage_url: ""
scopes:
- name: "excluded"
dependencies:
- id: "NPM::example-dependency-one:1.0.0"
- name: "main"
dependencies:
- id: "NPM::example-dependency-two:2.0.0"
linkage: "STATIC"
packages:
- id: "NPM::example-dependency-one:1.0.0"
purl: ""
declared_licenses: []
declared_licenses_processed: {}
description: ""
homepage_url: ""
binary_artifact:
url: ""
hash:
value: ""
algorithm: ""
source_artifact:
url: "https://example.org/example-dependency-one.zip"
hash:
value: ""
algorithm: ""
vcs:
type: "Git"
url: "https://github.com/example/depedency-one.git"
revision: "0000000000000000000000000000000000000000"
path: "vcs-path/dependency-one"
vcs_processed:
type: "Git"
url: "https://github.com/example/depedency-one.git"
revision: "0000000000000000000000000000000000000000"
path: "vcs-path/dependency-one"
- id: "NPM::example-dependency-two:2.0.0"
purl: ""
declared_licenses: []
declared_licenses_processed: {}
description: ""
homepage_url: ""
binary_artifact:
url: ""
hash:
value: ""
algorithm: ""
source_artifact:
url: "https://example.org/example-dependency-two.zip"
hash:
value: ""
algorithm: ""
vcs:
type: "Git"
url: "https://github.com/example/depedency-1.git"
revision: "1111111111111111111111111111111111111111"
path: "vcs-path/dependency-two"
vcs_processed:
type: "Git"
url: "https://github.com/example/depedency-1.git"
revision: "1111111111111111111111111111111111111111"
path: "vcs-path/dependency-two"
scanner: null
advisor: null
evaluator: null
resolved_configuration: {}
28 changes: 28 additions & 0 deletions helper-cli/src/funTest/assets/package-list.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
projectName: "Example project name"
projectVcs:
type: "Git"
url: "https://github.com/example/project.git"
revision: "2222222222222222222222222222222222222222"
path: "vcs-path/project"
dependencies:
- id: "NPM::example-dependency-one:1.0.0"
vcs:
type: "Git"
url: "https://github.com/example/depedency-one.git"
revision: "0000000000000000000000000000000000000000"
path: "vcs-path/dependency-one"
sourceArtifact:
url: "https://example.org/example-dependency-one.zip"
isExcluded: true
isDynamicallyLinked: true
- id: "NPM::example-dependency-two:2.0.0"
vcs:
type: "Git"
url: "https://github.com/example/depedency-1.git"
revision: "1111111111111111111111111111111111111111"
path: "vcs-path/dependency-two"
sourceArtifact:
url: "https://example.org/example-dependency-two.zip"
isExcluded: false
isDynamicallyLinked: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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.helper.commands

import com.github.ajalt.clikt.core.ProgramResult

import io.kotest.core.spec.style.WordSpec
import io.kotest.matchers.shouldBe

import org.ossreviewtoolkit.helper.HelperMain
import org.ossreviewtoolkit.model.OrtResult
import org.ossreviewtoolkit.model.ResolvedConfiguration
import org.ossreviewtoolkit.model.readValue
import org.ossreviewtoolkit.utils.ort.Environment
import org.ossreviewtoolkit.utils.ort.createOrtTempDir
import org.ossreviewtoolkit.utils.test.getAssetFile

class CreateAnalyzerResultFromPackageListCommandFunTest : WordSpec({
"The command" should {
"generate the expected analyzer result file" {
val inputFile = getAssetFile("package-list.yml")
val outputFile = createOrtTempDir().resolve("analyzer-result.yml")
val expectedOutputFile = getAssetFile("create-analyzer-result-from-pkg-list-expected-output.yml")

runMain(
"create-analyzer-result-from-package-list",
"--package-list-file",
inputFile.absolutePath,
"--ort-file",
outputFile.absolutePath
)
Fixed Show fixed Hide fixed

outputFile.readValue<OrtResult>().patchAnalyzerResult() shouldBe
expectedOutputFile.readValue<OrtResult>().patchAnalyzerResult()
}
}
})

private fun runMain(vararg args: String) {
@Suppress("SwallowedException")
try {
HelperMain().parse(args.asList())
} catch (e: ProgramResult) {
// Ignore exceptions that just propagate the program result.
}
}
sschuberth marked this conversation as resolved.
Show resolved Hide resolved

private fun OrtResult.patchAnalyzerResult(): OrtResult =
copy(
analyzer = analyzer?.copy(environment = Environment()),
resolvedConfiguration = ResolvedConfiguration()
)
1 change: 1 addition & 0 deletions helper-cli/src/main/kotlin/HelperMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ internal class HelperMain : CliktCommand(
subcommands(
ConvertOrtFileCommand(),
CreateAnalyzerResultCommand(),
CreateAnalyzerResultFromPackageListCommand(),
DevCommand(),
ExtractRepositoryConfigurationCommand(),
GenerateTimeoutErrorResolutionsCommand(),
Expand Down
Loading