Fixed issues when removing kotlin license information if there is no kotlin

master
nathan 2020-08-29 09:58:27 +02:00
parent cdb6962b9d
commit 3fad1e0357
3 changed files with 27 additions and 21 deletions

View File

@ -26,7 +26,7 @@ import org.gradle.api.IllegalDependencyNotation
* "com.dorkbox:Console:2.0" -> it will return APACHE_2, AND it will return the Version project license info!! DO NOT DO THIS!
*
*/
data class L(val mavenId: String, val licenseData: LicenseData)
data class L(val mavenIdWithInfo: String, val licenseData: LicenseData)
object AppLicensing {
private const val DEBUG = false
@ -336,14 +336,14 @@ object AppLicensing {
private fun buildLicenseData(license: L) {
// assign the maven ID, so we can use this later, as necessary. This is only for internal use
license.licenseData.mavenId = license.mavenId
// will always return moduleID ("com.dorkbox") and a version ("1.4", or "0" if not defined)
val (moduleId, version) = getFromModuleName(license.mavenId)
val (mavenId, version) = getFromModuleName(license.mavenIdWithInfo)
// assign the maven ID, so we can use this later, as necessary. This is only for internal use
license.licenseData.mavenId = mavenId
val internalList = allLicenseData.getOrPut(moduleId) { mutableListOf() }
val internalList = allLicenseData.getOrPut(mavenId) { mutableListOf() }
internalList.add(Pair(version, license.licenseData))
// largest version number is first, smallest version number is last.

View File

@ -21,21 +21,6 @@ internal open class LicenseInjector @Inject constructor(@Internal val extension:
@OutputFiles val outputFiles = extension.output
init {
val doesNotUseKotlin = try {
val sourceSets = project.extensions.getByName("sourceSets") as org.gradle.api.tasks.SourceSetContainer
val mainSourceSet: SourceSet = sourceSets.getByName("main")
val kotlin = (mainSourceSet as org.gradle.api.internal.HasConvention).convention.getPlugin(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::class.java).kotlin
kotlin.files.none { it.name.endsWith(".kt") }
} catch (e: Exception) {
false
}
// we only should include the kotlin license information IF we actually use kotlin. If kotlin is not used, we should suppress the license
if (doesNotUseKotlin) {
licenses.first().extras.removeIf { it.mavenId == "org.jetbrains.kotlin" }
}
outputs.upToDateWhen {
!(checkLicenseFiles(extension.outputBuildDir, licenses) && checkLicenseFiles(extension.outputRootDir, licenses))
}

View File

@ -19,6 +19,7 @@ import License
import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.tasks.SourceSet
import java.io.File
open class Licensing(private val project: Project) {
@ -116,6 +117,26 @@ open class Licensing(private val project: Project) {
// if a license for a dependency is UNKNOWN, then we emit a warning to the user to add it as a pull request
// if a license version is not specified, then we use the default
DependencyScanner(project, this.licenses).scanForLicenseData()
// we only should include the kotlin license information IF we actually use kotlin.
//
// If kotlin is not used, we should suppress the license
val doesNotUseKotlin = try {
val sourceSets = project.extensions.getByName("sourceSets") as org.gradle.api.tasks.SourceSetContainer
val mainSourceSet: SourceSet = sourceSets.getByName("main")
val kotlin = (mainSourceSet as org.gradle.api.internal.HasConvention).convention.getPlugin(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::class.java).kotlin
kotlin.files.none { it.name.endsWith(".kt") }
} catch (e: Exception) {
false
}
if (doesNotUseKotlin) {
licenses.first().extras.removeIf {
it.mavenId == "org.jetbrains.kotlin" || it.mavenId == "org.jetbrains.kotlinx"
}
}
}
/**