diff --git a/helper-cli/src/main/kotlin/commands/ListLicensesCommand.kt b/helper-cli/src/main/kotlin/commands/ListLicensesCommand.kt index 300581996bdab..2409cccc4bff2 100644 --- a/helper-cli/src/main/kotlin/commands/ListLicensesCommand.kt +++ b/helper-cli/src/main/kotlin/commands/ListLicensesCommand.kt @@ -33,8 +33,10 @@ import com.github.ajalt.clikt.parameters.types.file import java.io.File import java.lang.IllegalArgumentException -import org.ossreviewtoolkit.helper.utils.fetchScannedSources +import org.ossreviewtoolkit.helper.utils.downloadSources import org.ossreviewtoolkit.helper.utils.getLicenseFindingsById +import org.ossreviewtoolkit.helper.utils.getScannedProvenance +import org.ossreviewtoolkit.helper.utils.getSourceCodeOrigin import org.ossreviewtoolkit.helper.utils.getViolatedRulesByLicense import org.ossreviewtoolkit.helper.utils.readOrtResult import org.ossreviewtoolkit.helper.utils.replaceConfig @@ -146,9 +148,14 @@ internal class ListLicensesCommand : CliktCommand( throw UsageError("Could not find the package for the given id '${packageId.toCoordinates()}'.") } + val sourceCodeOrigin = ortResult.getScannedProvenance(packageId).getSourceCodeOrigin() ?: run { + println("No scan results available.") + return + } + val sourcesDir = sourceCodeDir ?: run { println("Downloading sources for package '${packageId.toCoordinates()}'...") - ortResult.fetchScannedSources(packageId) + ortResult.downloadSources(packageId, sourceCodeOrigin) } val packageConfigurationProvider = DirPackageConfigurationProvider(packageConfigurationsDir) @@ -190,11 +197,6 @@ internal class ListLicensesCommand : CliktCommand( } } - if (findingsByProvenance.isEmpty()) { - println("No scan results available.") - return - } - buildString { appendLine(" scan results:") findingsByProvenance.keys.forEachIndexed { i, provenance -> diff --git a/helper-cli/src/main/kotlin/utils/Extensions.kt b/helper-cli/src/main/kotlin/utils/Extensions.kt index 4be7311b30c0a..ba965d858e533 100644 --- a/helper-cli/src/main/kotlin/utils/Extensions.kt +++ b/helper-cli/src/main/kotlin/utils/Extensions.kt @@ -34,7 +34,6 @@ import org.jetbrains.exposed.sql.transactions.TransactionManager import org.ossreviewtoolkit.analyzer.PackageManagerFactory import org.ossreviewtoolkit.downloader.Downloader -import org.ossreviewtoolkit.model.ArtifactProvenance import org.ossreviewtoolkit.model.Identifier import org.ossreviewtoolkit.model.Issue import org.ossreviewtoolkit.model.KnownProvenance @@ -43,13 +42,13 @@ import org.ossreviewtoolkit.model.Package import org.ossreviewtoolkit.model.PackageCuration import org.ossreviewtoolkit.model.Project import org.ossreviewtoolkit.model.Provenance -import org.ossreviewtoolkit.model.RemoteArtifact import org.ossreviewtoolkit.model.Repository +import org.ossreviewtoolkit.model.RepositoryProvenance import org.ossreviewtoolkit.model.RuleViolation import org.ossreviewtoolkit.model.ScanResult import org.ossreviewtoolkit.model.Severity +import org.ossreviewtoolkit.model.SourceCodeOrigin import org.ossreviewtoolkit.model.TextLocation -import org.ossreviewtoolkit.model.VcsInfo import org.ossreviewtoolkit.model.config.CopyrightGarbage import org.ossreviewtoolkit.model.config.Curations import org.ossreviewtoolkit.model.config.DownloaderConfiguration @@ -88,21 +87,14 @@ internal fun List.minimize(projectScopes: List): List null + this is RepositoryProvenance -> SourceCodeOrigin.VCS + else -> SourceCodeOrigin.ARTIFACT + } + /** * Return all issues from scan results. Issues for excludes [Project]s or [Package]s are not returned if and only if * the given [omitExcluded] is true.