diff --git a/build.gradle.kts b/build.gradle.kts index 8347fed29..c4c8306f1 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,8 +16,8 @@ mikbotPlugin { pluginPublishing { repositoryUrl = "https://storage.googleapis.com/mikbot-plugins" - targetDirectory = rootProject.file("ci-repo").toPath() - currentRepository = rootProject.file("ci-repo-old").toPath() + targetDirectory = rootProject.file("ci-repo") + currentRepository = rootProject.file("ci-repo-old") projectUrl = "https://github.com/DRSchlaubi/mikbot" } diff --git a/buildSrc/src/main/kotlin/mikbot-module.gradle.kts b/buildSrc/src/main/kotlin/mikbot-module.gradle.kts index c874b9c52..078b3207d 100644 --- a/buildSrc/src/main/kotlin/mikbot-module.gradle.kts +++ b/buildSrc/src/main/kotlin/mikbot-module.gradle.kts @@ -2,7 +2,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") - org.jlleitschuh.gradle.ktlint } val experimentalAnnotations = @@ -22,13 +21,3 @@ tasks { kotlin { jvmToolchain(20) } - -ktlint { - disabledRules.add("no-wildcard-imports") - filter { - exclude { element -> - val path = element.file.absolutePath - path.contains("build") || path.contains("generated") || element.isDirectory - } - } -} diff --git a/buildSrc/src/main/kotlin/mikbot-publishing.gradle.kts b/buildSrc/src/main/kotlin/mikbot-publishing.gradle.kts index 3027bacc2..44ba99012 100644 --- a/buildSrc/src/main/kotlin/mikbot-publishing.gradle.kts +++ b/buildSrc/src/main/kotlin/mikbot-publishing.gradle.kts @@ -9,7 +9,7 @@ plugins { val sourcesJar by tasks.creating(Jar::class) { archiveClassifier = "sources" - destinationDirectory = buildDir + destinationDirectory = layout.buildDirectory from(sourceSets["main"].allSource) } diff --git a/gradle-plugin/src/main/java/dev/schlaubi/mikbot/gradle/PatchPropertiesTask.java b/gradle-plugin/src/main/java/dev/schlaubi/mikbot/gradle/PatchPropertiesTask.java index c801eaded..98925f86d 100644 --- a/gradle-plugin/src/main/java/dev/schlaubi/mikbot/gradle/PatchPropertiesTask.java +++ b/gradle-plugin/src/main/java/dev/schlaubi/mikbot/gradle/PatchPropertiesTask.java @@ -4,20 +4,19 @@ import dev.schlaubi.mikbot.gradle.extension.ExtensionsKt; import dev.schlaubi.mikbot.gradle.extension.PluginExtension; import org.gradle.api.DefaultTask; -import org.gradle.api.provider.Property; +import org.gradle.api.file.DirectoryProperty; import org.gradle.api.tasks.InputDirectory; import org.gradle.api.tasks.TaskAction; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.StandardOpenOption; import java.util.Properties; public abstract class PatchPropertiesTask extends DefaultTask { @InputDirectory - public abstract Property getPropertiesDirectory(); + public abstract DirectoryProperty getPropertiesDirectory(); @TaskAction public void runTask() throws IOException { @@ -27,7 +26,7 @@ public void runTask() throws IOException { var extension = ((PluginExtension) getProject().getExtensions() .getByName(ExtensionsKt.pluginExtensionName)); - var file = getPropertiesDirectory().get().resolve("plugin.properties"); + var file = getPropertiesDirectory().get().file("plugin.properties").getAsFile().toPath(); if (!Files.exists(file)) { throw new IllegalStateException("File %s doesn't exist".formatted(file)); } diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/AssembleBotTask.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/AssembleBotTask.kt index df18832ba..359ad011c 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/AssembleBotTask.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/AssembleBotTask.kt @@ -3,8 +3,10 @@ package dev.schlaubi.mikbot.gradle import kotlinx.coroutines.* import kotlinx.coroutines.future.await import org.gradle.api.Project +import org.gradle.api.file.Directory import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider import org.gradle.api.tasks.Input import org.gradle.api.tasks.Internal import org.gradle.api.tasks.bundling.Zip @@ -13,7 +15,6 @@ import java.net.URI import java.net.http.HttpClient import java.net.http.HttpRequest import java.net.http.HttpResponse -import java.nio.file.Path import kotlin.io.path.createDirectories import kotlin.io.path.exists @@ -45,10 +46,10 @@ abstract class AssembleBotTask : Zip() { .build() private val pluginSpecs = bundledPlugins.map { - it.map { - val split = it.split('@') + it.map { plugin -> + val split = plugin.split('@') if (split.size != 2) { - error("Invalid name $it, please specify as id@version ") + error("Invalid name $plugin, please specify as id@version ") } val (id, version) = split @@ -64,7 +65,7 @@ abstract class AssembleBotTask : Zip() { } internal fun config() { - destinationDirectory = project.buildDir.resolve("bot") + destinationDirectory = project.layout.buildDirectory.dir("bot") archiveBaseName = "bot-${project.name}" archiveExtension = "zip" @@ -72,7 +73,7 @@ abstract class AssembleBotTask : Zip() { // make this lazy, so it doesn't throw at initialization val provider = project.provider { val version = installBotTask.get().botVersionFromProject() - installBotTask.get().testBotFolder.resolve("bot-$version") + installBotTask.get().testBotFolder.get().dir("bot-$version") } from(provider) } @@ -83,7 +84,7 @@ abstract class AssembleBotTask : Zip() { } into(installedPluginsName) { pluginSpecs.get().forEach { (id, version) -> - val fullPath = project.pluginCache.resolve(id).resolve(version) + val fullPath = project.pluginCache.get().dir("$id/$version") from(fullPath) include("*.zip") } @@ -148,7 +149,7 @@ abstract class AssembleBotTask : Zip() { pluginReleases .asSequence() .mapNotNull { - val destination = it.cachePath + val destination = it.cachePath.asFile.toPath() if (!destination.exists()) { destination.parent.createDirectories() @@ -169,13 +170,13 @@ abstract class AssembleBotTask : Zip() { } } - private val PluginPair.cachePath: Path - get() = project.pluginCache.resolve(id).resolve(version).resolve("plugin-${id}-${version}.zip") + private val PluginPair.cachePath: Directory + get() = project.pluginCache.get().dir("$id/$version/plugin-${id}-${version}.zip") } data class PluginPair(val id: String, val version: String, val url: String) -private val Project.pluginCache: Path - get() = buildDir.toPath().resolve("plugin-cache") +private val Project.pluginCache: Provider + get() = layout.buildDirectory.dir("plugin-cache") diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Assembly.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Assembly.kt index f6ad37498..6407fc9e3 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Assembly.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Assembly.kt @@ -4,26 +4,22 @@ import dev.schlaubi.mikbot.gradle.extension.mikbotPluginExtension import dev.schlaubi.mikbot.gradle.extension.pluginId import org.gradle.api.Project import org.gradle.api.file.DuplicatesStrategy +import org.gradle.api.file.RegularFile +import org.gradle.api.provider.Provider import org.gradle.api.tasks.Copy import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.bundling.Jar import org.gradle.api.tasks.bundling.Zip -import org.gradle.kotlin.dsl.* +import org.gradle.kotlin.dsl.assign +import org.gradle.kotlin.dsl.register +import org.gradle.kotlin.dsl.repositories import java.net.URI -import java.nio.file.Path -import kotlin.io.path.name // There might be a better way of doing this, but for now I can't be bothered figuring it out -private val Project.pluginMainFile: Path - get() = buildDir - .resolve("generated") - .resolve("ksp") - .resolve("main") - .resolve("resources") - .resolve("META-INF") - .resolve("plugin.properties") - .toPath() +private val Project.pluginMainFile: Provider + get() = layout.buildDirectory + .file("generated/ksp/main/resources/META-INF/plugin.properties") internal data class AssemblyTask(val assembleTask: TaskProvider, val installBotTask: InstallBotTask) @@ -66,7 +62,7 @@ private fun TaskContainer.createAssembleBotTask(assemblePlugin: TaskProvider("patchPluginProperties") { group = "mikbot-plugin" dependsOn("kspKotlin") - propertiesDirectory = - project - .mikbotPluginExtension - .pluginMainFileLocation - .getOrElse(project.pluginMainFile) - .parent + propertiesDirectory = (project + .mikbotPluginExtension + .pluginMainFileLocation + .orNull ?: project.pluginMainFile.get()) + .asFile + .parentFile doFirst { @@ -103,7 +99,7 @@ private fun TaskContainer.createAssemblePluginTask(jarTask: Jar) = duplicatesStrategy = DuplicatesStrategy.EXCLUDE - destinationDirectory = buildDir.resolve("plugin") + destinationDirectory = layout.buildDirectory.dir("plugin") archiveBaseName = "plugin-${project.pluginId}" archiveExtension = "zip" @@ -139,8 +135,8 @@ private fun TaskContainer.createAssemblePluginTask(jarTask: Jar) = } into("") { // not specifying "" brakes Gradle btw - val file = project.mikbotPluginExtension.pluginMainFileLocation - .getOrElse(pluginMainFile) + val file = (project.mikbotPluginExtension.pluginMainFileLocation + .orNull ?: pluginMainFile.get()).asFile from(file.parent) include(file.name) } diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/BuildRepositoryExtension.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/BuildRepositoryExtension.kt index 981c489a4..2dad9d3b9 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/BuildRepositoryExtension.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/BuildRepositoryExtension.kt @@ -1,22 +1,22 @@ package dev.schlaubi.mikbot.gradle +import org.gradle.api.file.DirectoryProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputDirectory -import java.nio.file.Path abstract class BuildRepositoryExtension { /** * The directory to save the repository to. */ @get:InputDirectory - abstract val targetDirectory: Property + abstract val targetDirectory: DirectoryProperty /** * Directory representing the current repository content (defaults to [targetDirectory]). */ @get:InputDirectory - abstract val currentRepository: Property + abstract val currentRepository: DirectoryProperty /** * The URL were the repository is hosted (used for URLs in plugins.json). diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/GenerateDefaultTranslationBundleTask.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/GenerateDefaultTranslationBundleTask.kt index a2c487ddc..d23e70613 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/GenerateDefaultTranslationBundleTask.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/GenerateDefaultTranslationBundleTask.kt @@ -24,7 +24,7 @@ abstract class GenerateDefaultTranslationBundleTask : DefaultTask() { fun copyBundle() { val sourceSets = project.extensions.getByName("sourceSets") as SourceSetContainer val from = sourceSets.getByName("main").resources - val to = project.buildDir.resolve("generated").resolve("mikbot").resolve("main").resolve("resources") + val to = project.layout.buildDirectory.dir("generated/mikbot/main/resources") val result = project.copy { val locale = defaultLocale.orNull?.resourceBundleKey diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/InstallBotTask.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/InstallBotTask.kt index 3094f57ef..12046435d 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/InstallBotTask.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/InstallBotTask.kt @@ -1,18 +1,19 @@ package dev.schlaubi.mikbot.gradle import org.gradle.api.DefaultTask +import org.gradle.api.file.Directory import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider import org.gradle.api.tasks.Input import org.gradle.api.tasks.Optional import org.gradle.api.tasks.OutputDirectory import org.gradle.api.tasks.TaskAction import java.io.File -import java.nio.file.Path abstract class InstallBotTask : DefaultTask() { @get:OutputDirectory - internal val testBotFolder: Path - get() = project.buildDir.resolve("test-bot").resolve(botVersionFromProject()).toPath() + internal val testBotFolder: Provider + get() = project.layout.buildDirectory.dir("test-bot/${botVersionFromProject()}") @get:Input @get:Optional diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/InstallPluginsToTestBotTask.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/InstallPluginsToTestBotTask.kt index 9789f52e5..33d7701ba 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/InstallPluginsToTestBotTask.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/InstallPluginsToTestBotTask.kt @@ -24,7 +24,7 @@ abstract class InstallPluginsToTestBotTask : DefaultTask() { val result = project.copy { from(task.destinationDirectory) include(task.archiveFile.get().asFile.name) - into(project.buildDir.resolve("test-bot").resolve("plugins")) + into(project.layout.buildDirectory.dir("test-bot/plugins")) } didWork = result.didWork || deleteResult.didWork diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/MakeRepositoryIndexTask.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/MakeRepositoryIndexTask.kt index 85d1cbf9e..f4a58eb21 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/MakeRepositoryIndexTask.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/MakeRepositoryIndexTask.kt @@ -8,6 +8,7 @@ import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.bundling.Zip import java.nio.file.Files import java.util.* +import kotlin.io.path.exists abstract class MakeRepositoryIndexTask : DefaultTask() { @@ -18,8 +19,8 @@ abstract class MakeRepositoryIndexTask : DefaultTask() { @TaskAction fun upload() { val publishingExtension = project.pluginPublishingExtension - val pluginsPath = publishingExtension.targetDirectory.get().resolve("plugins.json") - val plugins = if (Files.exists(pluginsPath)) { + val pluginsPath = publishingExtension.targetDirectory.asPath().resolve("plugins.json") + val plugins = if (pluginsPath.exists()) { readPluginsJson(pluginsPath) } else { emptyList() diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/MikBotPluginGradlePlugin.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/MikBotPluginGradlePlugin.kt index 6e6dcedbd..c231f054f 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/MikBotPluginGradlePlugin.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/MikBotPluginGradlePlugin.kt @@ -26,8 +26,7 @@ class MikBotPluginGradlePlugin : Plugin { (target.extensions.getByName("sourceSets") as SourceSetContainer).getByName("main") .apply { resources.srcDir( - target.buildDir.resolve("generated").resolve("mikbot").resolve("main") - .resolve("resources") + target.layout.buildDirectory.dir("generated/mikbot/main/resources") ) } } @@ -47,7 +46,7 @@ class MikBotPluginGradlePlugin : Plugin { java { val optionalKspSourceSet = mikbotPluginExtension.enableKordexProcessor.map { if(it) { - file("$buildDir/generated/ksp/main/kotlin/") + layout.buildDirectory.dir("/generated/ksp/main/kotlin/") } else { fileTree("never_exists") { include { false } // include none diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Publishing.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Publishing.kt index 9ee8e9735..a8f26d073 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Publishing.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Publishing.kt @@ -18,12 +18,14 @@ internal fun Project.createPublishingTasks(assemblePluginTask: TaskProvider include("*.zip") // providing version manually, as of weird evaluation errors into( - pluginPublishingExtension.targetDirectory.getOrElse(project.file("ci-repo").toPath()) + pluginPublishingExtension.targetDirectory.asPathOrElse(project.file("ci-repo").toPath()) .resolve("${project.pluginId}/$version") ) eachFile { val parent = pluginPublishingExtension.currentRepository.getOrElse(pluginPublishingExtension.targetDirectory.get()) + .asPath() + val destinationPath = destinationDir.toPath() val probableExistingFile = parent.resolve( diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/RunBotTask.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/RunBotTask.kt index 074500304..3037a3693 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/RunBotTask.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/RunBotTask.kt @@ -47,14 +47,14 @@ abstract class RunBotTask : JavaExec() { private fun configureClasspath() { val installTask = installTask.get() val folder = - installTask.testBotFolder.resolve("bot-${installTask.botVersionFromProject()}") - .resolve("lib") - val jars = folder.listDirectoryEntries("*.jar") + installTask.testBotFolder.dir("bot-${installTask.botVersionFromProject()}") + .dir("lib") + val jars = folder.get().asFile.toPath().listDirectoryEntries("*.jar") classpath += objectFactory.fileCollection().from(jars) } private fun configureSystemProperties() { - systemProperties["pf4j.pluginsDir"] = project.buildDir.resolve("test-bot").resolve("plugins") + systemProperties["pf4j.pluginsDir"] = project.layout.buildDirectory.dir("test-bot/plugins") } } diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Util.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Util.kt index 9e345d6af..af1c9d31d 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Util.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/Util.kt @@ -8,12 +8,18 @@ import kotlinx.serialization.json.Json import org.gradle.api.Project import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.ProjectDependency +import org.gradle.api.file.Directory +import org.gradle.api.file.FileSystemLocation +import org.gradle.api.provider.Property +import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.assign import java.nio.file.Files import java.nio.file.Path import java.security.MessageDigest import kotlin.io.path.readBytes +import kotlin.io.path.readText -internal fun readPluginsJson(path: Path): List = Files.readString(path).run { Json.decodeFromString(this) } +internal fun readPluginsJson(path: Path): List = path.readText().run { Json.decodeFromString(this) } internal fun List.writeTo(path: Path) { Files.writeString(path, Json.encodeToString(this)) @@ -60,7 +66,7 @@ internal fun Project.buildDependenciesString(): String { } internal fun Dependency.toDependencyString(optional: Boolean = false): String { - val safeVersion = version.toString().substringBefore("-SNAPSHOT") + val safeVersion = version.toString().substringBefore("-SNAPSHOT") val name = if (this is ProjectDependency) { dependencyProject.pluginId } else { @@ -76,10 +82,8 @@ internal fun Dependency.toDependencyString(optional: Boolean = false): String { @Suppress("unused") fun Project.usePF4J() { extensions.configure(pluginExtensionName) { - ignoreDependencies.set(true) - pluginMainFileLocation.set( - buildDir.resolve("resources").resolve("main").resolve("plugin.properties").toPath() - ) + ignoreDependencies = true + pluginMainFileLocation = layout.buildDirectory.file("resources/main/plugin.properties") } } @@ -94,3 +98,8 @@ fun ByteArray.sha512Checksum(): String { internal fun pluginNotAppliedError(name: String): Nothing = error("Please make sure the $name plugin is applied before the mikbot plugin") +internal fun Provider.dir(name: String) = map { it.dir(name) } +internal fun Provider.file(name: String) = map { it.file(name) } +internal fun Property.asPath() = get().asFile.toPath() +internal fun Property.asPathOrElse(other: Path) = orNull?.asFile?.toPath() ?: other +internal fun FileSystemLocation.asPath() = asFile.toPath() diff --git a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/extension/Extension.kt b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/extension/Extension.kt index 297546f3f..a61d37ddb 100644 --- a/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/extension/Extension.kt +++ b/gradle-plugin/src/main/kotlin/dev/schlaubi/mikbot/gradle/extension/Extension.kt @@ -1,8 +1,8 @@ package dev.schlaubi.mikbot.gradle.extension import org.gradle.api.Project +import org.gradle.api.file.RegularFileProperty import org.gradle.api.provider.Property -import java.nio.file.Path /** Extension for configuring plugins for PF4J. */ abstract class PluginExtension { @@ -39,7 +39,7 @@ abstract class PluginExtension { * * If you use the KSP processor you don't need to worry about this. */ - abstract val pluginMainFileLocation: Property + abstract val pluginMainFileLocation: RegularFileProperty /** * The optional override for the projects resources bundle folder.