Skip to content

Commit

Permalink
Drop usage of deprecated buildDir property
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Nov 1, 2023
1 parent 3f2f68b commit 19f6a3a
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 78 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
11 changes: 0 additions & 11 deletions buildSrc/src/main/kotlin/mikbot-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
org.jlleitschuh.gradle.ktlint
}

val experimentalAnnotations =
Expand All @@ -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
}
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/mikbot-publishing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {

val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier = "sources"
destinationDirectory = buildDir
destinationDirectory = layout.buildDirectory
from(sourceSets["main"].allSource)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path> getPropertiesDirectory();
public abstract DirectoryProperty getPropertiesDirectory();

@TaskAction
public void runTask() throws IOException {
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -64,15 +65,15 @@ abstract class AssembleBotTask : Zip() {
}

internal fun config() {
destinationDirectory = project.buildDir.resolve("bot")
destinationDirectory = project.layout.buildDirectory.dir("bot")
archiveBaseName = "bot-${project.name}"
archiveExtension = "zip"

into("") {
// 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)
}
Expand All @@ -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")
}
Expand Down Expand Up @@ -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()

Expand All @@ -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<Directory>
get() = layout.buildDirectory.dir("plugin-cache")


Original file line number Diff line number Diff line change
Expand Up @@ -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<RegularFile>
get() = layout.buildDirectory
.file("generated/ksp/main/resources/META-INF/plugin.properties")

internal data class AssemblyTask(val assembleTask: TaskProvider<Zip>, val installBotTask: InstallBotTask)

Expand Down Expand Up @@ -66,7 +62,7 @@ private fun TaskContainer.createAssembleBotTask(assemblePlugin: TaskProvider<Zip
dependsOn(assembleBot)

from(zipTree(assembleBot.get().archiveFile))
into(buildDir.resolve("installBot"))
into(layout.buildDirectory.dir("installBot"))
}
}

Expand All @@ -75,12 +71,12 @@ private fun TaskContainer.createPatchPropertiesTask() =
register<PatchPropertiesTask>("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 {
Expand All @@ -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"

Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Path>
abstract val targetDirectory: DirectoryProperty

/**
* Directory representing the current repository content (defaults to [targetDirectory]).
*/
@get:InputDirectory
abstract val currentRepository: Property<Path>
abstract val currentRepository: DirectoryProperty

/**
* The URL were the repository is hosted (used for URLs in plugins.json).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Directory>
get() = project.layout.buildDirectory.dir("test-bot/${botVersionFromProject()}")

@get:Input
@get:Optional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class MikBotPluginGradlePlugin : Plugin<Project> {
(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")
)
}
}
Expand All @@ -47,7 +46,7 @@ class MikBotPluginGradlePlugin : Plugin<Project> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ internal fun Project.createPublishingTasks(assemblePluginTask: TaskProvider<Zip>
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Loading

0 comments on commit 19f6a3a

Please sign in to comment.