Skip to content

Commit

Permalink
style: Add empty lines after multi-line blocks for readability
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Jun 27, 2024
1 parent f9e7f72 commit fabe6c8
Show file tree
Hide file tree
Showing 78 changed files with 189 additions and 0 deletions.
1 change: 1 addition & 0 deletions analyzer/src/main/kotlin/Analyzer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ private class AnalyzerState {
result.dependencyGraph?.let {
builder.addDependencyGraph(manager.managerName, it).addPackages(result.sharedPackages)
}

_finishedPackageManagersState.value = (_finishedPackageManagersState.value + manager.managerName)
.toSortedSet(String.CASE_INSENSITIVE_ORDER)
}
Expand Down
1 change: 1 addition & 0 deletions analyzer/src/main/kotlin/AnalyzerResultBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class AnalyzerResultBuilder {
val existingDefinitionFileUrl = existingProject.let {
"${it.vcsProcessed.url}/${it.definitionFilePath}"
}

val incomingDefinitionFileUrl = projectAnalyzerResult.project.let {
"${it.vcsProcessed.url}/${it.definitionFilePath}"
}
Expand Down
1 change: 1 addition & 0 deletions analyzer/src/testFixtures/kotlin/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ fun PackageManager.collateMultipleProjects(vararg definitionFiles: File): Analyz
managerResult.dependencyGraph?.let {
builder.addDependencyGraph(managerName, it).addPackages(managerResult.sharedPackages)
}

definitionFiles.forAll { definitionFile ->
managerResult.projectResults[definitionFile] shouldNotBeNull {
this shouldHaveAtLeastSize 1
Expand Down
8 changes: 8 additions & 0 deletions clients/fossid-webapp/src/main/kotlin/FossIdRestService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ interface FossIdRestService {
requireNotNull(boundType) {
"The PolymorphicListDeserializer needs a type to deserialize values!"
}

return when (p.currentToken) {
JsonToken.VALUE_FALSE -> PolymorphicList()
JsonToken.START_ARRAY -> {
val arrayType = JSON_MAPPER.typeFactory.constructArrayType(boundType)
val array = JSON_MAPPER.readValue<Array<Any>>(p, arrayType)
PolymorphicList(array.toList())
}

JsonToken.START_OBJECT -> {
val mapType = JSON_MAPPER.typeFactory.constructMapType(
LinkedHashMap::class.java,
Expand All @@ -116,6 +118,7 @@ interface FossIdRestService {
// present in the elements themselves, we don't lose any information by discarding the keys.
PolymorphicList(map.values.toList())
}

else -> error("FossID returned a type not handled by this deserializer!")
}
}
Expand Down Expand Up @@ -147,15 +150,18 @@ interface FossIdRestService {
val value = JSON_MAPPER.readValue(p, String::class.java)
PolymorphicInt(value.toInt())
}

JsonToken.VALUE_NUMBER_INT -> {
val value = JSON_MAPPER.readValue(p, Int::class.java)
PolymorphicInt(value)
}

JsonToken.START_ARRAY -> {
val array = JSON_MAPPER.readValue(p, IntArray::class.java)
val value = if (array.isEmpty()) null else array.first()
PolymorphicInt(value)
}

JsonToken.START_OBJECT -> {
val mapType = JSON_MAPPER.typeFactory.constructMapType(
LinkedHashMap::class.java,
Expand All @@ -166,8 +172,10 @@ interface FossIdRestService {
if (map.size != 1) {
error("A map representing a polymorphic integer should have one value!")
}

PolymorphicInt(map.values.first().toString().toInt())
}

else -> error("FossID returned a type not handled by this deserializer!")
}
}
Expand Down
3 changes: 3 additions & 0 deletions clients/scanoss/src/test/kotlin/ScanOssDetailsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,17 @@ class ScanOssDetailsTest : StringSpec({
copyrights.first() shouldNotBeNull {
source shouldBe Source.FILE_HEADER
}

vulnerabilities shouldHaveSize 1
vulnerabilities.first() shouldNotBeNull {
id shouldBe "GHSA-27p5-7cw6-m45h"
}

quality shouldHaveSize 1
quality.first() shouldNotBeNull {
score shouldBe "2/5"
}

cryptography should beEmpty()
}
}
Expand Down
1 change: 1 addition & 0 deletions detekt-rules/src/main/kotlin/OrtImportOrder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class OrtImportOrder(config: Config) : Rule(config) {
pathsWithBlankLines += it.value
pathsWithBlankLines += ""
}

pathsWithBlankLines.removeLast()

return pathsWithBlankLines
Expand Down
1 change: 1 addition & 0 deletions downloader/src/main/kotlin/Downloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ class Downloader(private val config: DownloaderConfiguration) {
throw e
}
}

val resolvedRevision = workingTree.getRevision()

logger.info {
Expand Down
1 change: 1 addition & 0 deletions downloader/src/main/kotlin/VersionControlSystem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ abstract class VersionControlSystem(
it.isAvailable() && it.isApplicableUrl(vcsUrl)
}
}

else -> forType(type)
}.also {
urlToVcsMap[vcsUrl] = it
Expand Down
1 change: 1 addition & 0 deletions downloader/src/main/kotlin/WorkingTreeCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class DefaultWorkingTreeCache : WorkingTreeCache {
workingTrees[key]?.getRootPath()?.safeDeleteRecursively(force = true)
}
}

workingTrees.clear()
workingTreeMutexes.clear()
}
Expand Down
3 changes: 3 additions & 0 deletions evaluator/src/test/kotlin/EvaluatorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class EvaluatorTest : WordSpec({
}
}
}

val script = javaClass.getResource("/rules/osadl.rules.kts").readText()

val result = Evaluator(compatibleOrtResult).run(script)
Expand Down Expand Up @@ -179,6 +180,7 @@ class EvaluatorTest : WordSpec({
}
}
}

val script = javaClass.getResource("/rules/osadl.rules.kts").readText()

val result = Evaluator(incompatibleOrtResult).run(script)
Expand Down Expand Up @@ -212,6 +214,7 @@ class EvaluatorTest : WordSpec({
}
}
}

val script = javaClass.getResource("/rules/osadl.rules.kts").readText()

val result = Evaluator(incompatibleOrtResult).run(script)
Expand Down
6 changes: 6 additions & 0 deletions evaluator/src/test/kotlin/ProjectSourceRuleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ProjectSourceRuleTest : WordSpec({
"module/docs/LICENSE.txt"
)
}

val rule = createRule(dir)

with(rule) {
Expand All @@ -64,6 +65,7 @@ class ProjectSourceRuleTest : WordSpec({
val dir = tempdir().apply {
addDirs("README.md")
}

val rule = createRule(dir)

rule.projectSourceHasFile("README.md").matches() shouldBe false
Expand All @@ -82,6 +84,7 @@ class ProjectSourceRuleTest : WordSpec({
val dir = tempdir().apply {
addDirs("a/b/c")
}

val rule = createRule(dir)

with(rule) {
Expand All @@ -96,6 +99,7 @@ class ProjectSourceRuleTest : WordSpec({
val dir = tempdir().apply {
addFiles("a")
}

val rule = createRule(dir)

rule.projectSourceHasDirectory("a").matches() shouldBe false
Expand All @@ -105,6 +109,7 @@ class ProjectSourceRuleTest : WordSpec({
val dir = tempdir().apply {
addDirs("b")
}

val rule = createRule(dir)

rule.projectSourceHasDirectory("a").matches() shouldBe false
Expand All @@ -123,6 +128,7 @@ class ProjectSourceRuleTest : WordSpec({
""".trimIndent()
)
}

val rule = createRule(dir)

rule.projectSourceHasFileWithContent(".*^#{1,2} License$.*", "README.md").matches() shouldBe true
Expand Down
1 change: 1 addition & 0 deletions evaluator/src/test/kotlin/RuleSetTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class RuleSetTest : WordSpec({
every { ref.id } answers { node.id.copy(name = node.id.name + "-ref") }
ref
}

spyNode
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ internal class ListLicenseCategoriesCommand : CliktCommand(
licenses.sortedBy { it.id.toString() }.forEach { license ->
appendLine(" ${license.description(category)}")
}

appendLine()
}
}
Expand Down
1 change: 1 addition & 0 deletions helper-cli/src/main/kotlin/commands/ListLicensesCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,6 @@ private fun Provenance.writeValueAsString(): String =
is RepositoryProvenance -> {
"type=${vcsInfo.type}, url=${vcsInfo.url}, path=${vcsInfo.path}, revision=$resolvedRevision"
}

else -> throw IllegalArgumentException("Provenance must have either a non-null source artifact or VCS info.")
}
1 change: 1 addition & 0 deletions helper-cli/src/main/kotlin/commands/ListPackagesCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ internal class ListPackagesCommand : CliktCommand(
appendLine(it.toCoordinates())
}
}

print(result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ internal class GenerateProjectExcludesCommand : CliktCommand(
comment = "TODO"
)
}

val existingPathExcludes = repositoryConfiguration.excludes.paths
val pathExcludes = (existingPathExcludes + generatedPathExcludes).distinctBy { it.pattern }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ internal class ImportLicenseFindingCurationsCommand : CliktCommand(
} else {
RepositoryConfiguration()
}

val vcsUrlMapping = vcsUrlMappingFile?.readValue<VcsUrlMapping>().orEmpty()

val allLicenseFindings = ortResult.getLicenseFindingsForAllProjects()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ internal class RemoveEntriesCommand : CliktCommand(
val notGloballyResolvedIssues = ortResult.getIssues().values.flatten().filterNot {
resolutionProvider.isResolved(it)
}

val issueResolutions = ortResult.getRepositoryConfigResolutions().issues.filter { resolution ->
notGloballyResolvedIssues.any { resolution.matches(it) }
}
Expand Down
1 change: 1 addition & 0 deletions model/src/main/kotlin/OrtResult.kt
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ data class OrtResult(
append(vcsPath)
append("/")
}

append(path)
}
}
Expand Down
1 change: 1 addition & 0 deletions model/src/main/kotlin/PackageReference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ data class PackageReference(
val transformedDependencies = dependencies.mapTo(mutableSetOf()) {
it.traverse(transform)
}

return transform(copy(dependencies = transformedDependencies))
}

Expand Down
2 changes: 2 additions & 0 deletions model/src/main/kotlin/Provenance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ private class ProvenanceDeserializer : StdDeserializer<Provenance>(Provenance::c
val sourceArtifact = jsonMapper.treeToValue<RemoteArtifact>(node["source_artifact"])
ArtifactProvenance(sourceArtifact)
}

node.has("vcs_info") -> {
val vcsInfo = jsonMapper.treeToValue<VcsInfo>(node["vcs_info"])
// For backward compatibility, if there is no resolved_revision use the revision from vcsInfo.
val resolvedRevision = node["resolved_revision"]?.textValue() ?: vcsInfo.revision
RepositoryProvenance(vcsInfo, resolvedRevision)
}

else -> UnknownProvenance
}
}
Expand Down
2 changes: 2 additions & 0 deletions model/src/main/kotlin/licenses/LicenseInfoResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@ class LicenseInfoResolver(
val (copyrightGarbage, copyrightFindings) = finding.copyrights.partition { copyrightFinding ->
copyrightFinding.statement in copyrightGarbage
}

copyrightGarbageFindings[finding.provenance] = copyrightGarbage.toSet()
finding.copy(copyrights = copyrightFindings.toSet())
}

return DetectedLicenseInfo(filteredFindings)
}

Expand Down
2 changes: 2 additions & 0 deletions model/src/main/kotlin/utils/SortedCollectionConverters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ private fun Provenance.getSortKey(): String =
this += vcsInfo.type.toString()
this += vcsInfo.url
}

is ArtifactProvenance -> {
this += sourceArtifact.url
}

else -> {
// Do not add anything, because unknown provenance does not have any properties.
}
Expand Down
1 change: 1 addition & 0 deletions model/src/test/kotlin/DependencyTreeNavigatorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DependencyTreeNavigatorTest : AbstractDependencyNavigatorTest() {
}
}
}

pkg("D") {
pkg("E")
}
Expand Down
1 change: 1 addition & 0 deletions model/src/test/kotlin/config/OrtConfigurationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class OrtConfigurationTest : WordSpec({
sslkey shouldBe "/defaultdir/postgresql.pk8"
sslrootcert shouldBe "/defaultdir/root.crt"
}

postgresStorage.type shouldBe StorageType.PROVENANCE_BASED

val sw360Storage = this["sw360Configuration"]
Expand Down
3 changes: 3 additions & 0 deletions model/src/test/kotlin/licenses/LicenseClassificationsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class LicenseClassificationsTest : WordSpec({
val exception = shouldThrow<IllegalArgumentException> {
LicenseClassifications(categories = listOf(cat1, cat2, cat3))
}

exception.message shouldContain "[Category 1]"
}

Expand All @@ -60,6 +61,7 @@ class LicenseClassificationsTest : WordSpec({
val exception = shouldThrow<IllegalArgumentException> {
LicenseClassifications(categorizations = listOf(lic1, lic2, lic3))
}

exception.message shouldContain "[ASL-1]"
}

Expand All @@ -79,6 +81,7 @@ class LicenseClassificationsTest : WordSpec({
val exception = shouldThrow<IllegalArgumentException> {
LicenseClassifications(categories = listOf(cat1, cat2), categorizations = listOf(lic1, lic2, lic3))
}

exception.message shouldNotContain lic1.id.toString()
exception.message shouldContain lic2.id.toString()
exception.message shouldContain lic3.id.toString()
Expand Down
1 change: 1 addition & 0 deletions plugins/advisors/osv/src/main/kotlin/Osv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class Osv(name: String, config: OsvConfiguration) : AdviceProvider(name) {
logger.error {
"Requesting vulnerabilities for IDs failed: ${it.collectMessages()}"
}

emptyList()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class VulnerableCode(name: String, config: VulnerableCodeConfiguration) : Advice
"The request of chunk ${index + 1} of ${chunks.size} failed for the following ${chunk.size} " +
"PURL(s):"
}

chunk.forEach(logger::error)
}
}
Expand Down
1 change: 1 addition & 0 deletions plugins/commands/advisor/src/main/kotlin/AdvisorCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class AdvisorCommand : OrtCommand(
val vulnerablePackageCount = count { (id, vulnerabilities) ->
id in includedPackages && vulnerabilities.isNotEmpty()
}

val vulnerabilityCount = filterKeys { it in includedPackages }.values.sumOf { it.size }

echo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,17 @@ private fun RuleViolation.format() =
append(id.toCoordinates())
append(" - ")
}

license?.let { license ->
append(license)
licenseSource?.let { source ->
append(" (")
append(source)
append(")")
}

append(" - ")
}

append(message)
}
1 change: 1 addition & 0 deletions plugins/commands/scanner/src/main/kotlin/ScannerCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class ScannerCommand : OrtCommand(
val config = ortConfig.scanner.config?.get(it.type)
it.create(config?.options.orEmpty(), config?.secrets.orEmpty())
}

val projectScannerWrappers = projectScannerWrapperFactories
.takeIf { PackageType.PROJECT in packageTypes }.orEmpty()
.map {
Expand Down
Loading

0 comments on commit fabe6c8

Please sign in to comment.