From cdeea3566608cbd170d98cdf5b2b7124c190feaa Mon Sep 17 00:00:00 2001 From: Robinson Date: Wed, 22 Sep 2021 02:57:26 +0200 Subject: [PATCH] Updated to gradle 7.2 --- src/License.kt | 4 +-- src/dorkbox/license/LicenseData.kt | 3 +- src/dorkbox/license/Licensing.kt | 49 ++++++++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/License.kt b/src/License.kt index ad692fe..fa6ccbb 100644 --- a/src/License.kt +++ b/src/License.kt @@ -445,10 +445,10 @@ enum class License constructor(internal val names: Collection, internal return UNKNOWN } - val normalizedLicenseName = licenseName.toLowerCase(Locale.US) + val normalizedLicenseName = licenseName.lowercase(Locale.US) values().forEach { license -> - val found = license.names.firstOrNull { it.toLowerCase(Locale.US) == normalizedLicenseName } + val found = license.names.firstOrNull { it.lowercase(Locale.US) == normalizedLicenseName } if (found != null) { return license } diff --git a/src/dorkbox/license/LicenseData.kt b/src/dorkbox/license/LicenseData.kt index 1c2b0a0..3fa912e 100644 --- a/src/dorkbox/license/LicenseData.kt +++ b/src/dorkbox/license/LicenseData.kt @@ -20,6 +20,7 @@ import java.io.IOException import java.io.ObjectInputStream import java.io.ObjectOutputStream import java.time.LocalDate +import java.util.* open class LicenseData(var name: String, var license: License) : java.io.Serializable, Comparable { @@ -122,7 +123,7 @@ open class LicenseData(var name: String, var license: License) : java.io.Seriali * ignore case when sorting these */ override operator fun compareTo(other: LicenseData): Int { - return this.name.toLowerCase().compareTo(other.name.toLowerCase()) + return this.name.lowercase(Locale.US).compareTo(other.name.lowercase(Locale.US)) } override fun toString(): String { diff --git a/src/dorkbox/license/Licensing.kt b/src/dorkbox/license/Licensing.kt index cd129d9..00d20f6 100644 --- a/src/dorkbox/license/Licensing.kt +++ b/src/dorkbox/license/Licensing.kt @@ -16,10 +16,10 @@ package dorkbox.license 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 org.gradle.api.tasks.SourceSetContainer +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.io.File open class Licensing(private val project: Project) { @@ -32,6 +32,51 @@ open class Licensing(private val project: Project) { } internal const val NAME = "licensing" + + /** + * If the kotlin plugin is applied, and there is a compileKotlin task.. Then kotlin is enabled + * NOTE: This can ONLY be called from a task, it cannot be called globally! + */ + fun hasKotlin(project: Project, debug: Boolean = false): Boolean { + try { + // check if plugin is available + project.plugins.findPlugin("org.jetbrains.kotlin.jvm") ?: return false + + if (debug) println("\tHas kotlin plugin") + + // this will check if the task exists, and throw an exception if it does not or return false + project.tasks.named("compileKotlin", KotlinCompile::class.java).orNull ?: return false + + if (debug) println("\tHas compile kotlin task") + + // check to see if we have any kotlin file + val sourceSets = project.extensions.getByName("sourceSets") as SourceSetContainer + val main = sourceSets.getByName("main") + val kotlin = project.extensions.getByType(org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension::class.java).sourceSets.getByName("main").kotlin + + if (debug) { + println("\tmain dirs: ${main.java.srcDirs}") + println("\tkotlin dirs: ${kotlin.srcDirs}") + + project.buildFile.parentFile.walkTopDown().filter { it.extension == "kt" }.forEach { + println("\t\t$it") + } + } + + val files = main.java.srcDirs + kotlin.srcDirs + files.forEach { srcDir -> + val kotlinFile = srcDir.walkTopDown().find { it.extension == "kt" } + if (kotlinFile?.exists() == true) { + if (debug) println("\t Has kotlin file: $kotlinFile") + return true + } + } + } catch (e: Exception) { + if (debug) e.printStackTrace() + } + + return false + } } private val projectName = project.name