com.datadog.gradle.plugin.licenses.internal.ThirdPartyDependency.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dependency-license Show documentation
Show all versions of dependency-license Show documentation
This plugin generates the OSS licenses csv file for all dependencies.
The newest version!
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/
package com.datadog.gradle.plugin.licenses.internal
internal data class ThirdPartyDependency(
val component: Component,
val origin: String,
val license: License,
val copyright: String,
val artifacts: String?,
) {
enum class Component(val csvName: String) {
IMPORT("import"),
IMPORT_TEST("import(test)"),
BUILD("build"),
UNKNOWN("__"),
;
companion object {
fun fromCSV(csvName: String): Component {
return values().firstOrNull { it.csvName == csvName } ?: UNKNOWN
}
}
}
fun toCSV(): String {
return if (copyright.isNullOrBlank()) {
"${component.csvName},$origin,$license,\"Unknown copyright for artifacts $artifacts\""
} else {
"${component.csvName},$origin,$license,$copyright"
}
}
companion object {
@Suppress("MagicNumber")
fun fromCSV(csvLine: String): ThirdPartyDependency? {
val token = csvLine.split(",", limit = 4)
if (token.size < 4) return null
return ThirdPartyDependency(
component = Component.fromCSV(token[0]),
origin = token[1],
license = License.from(token[2]),
copyright = token[3],
artifacts = "",
)
}
}
}