From 82877ddfda2240e452835e28e912f81f1b548695 Mon Sep 17 00:00:00 2001 From: Frontrider Date: Sun, 20 Nov 2022 15:05:24 +0100 Subject: [PATCH] Dedicated download task included, running the game/editor now depends on running the build task if it exists. Assetstore url is no longer hardcoded, the configuration is used. --- build.gradle.kts | 8 ++-- src/integrationTest/README.MD | 3 ++ .../resources/downloadURLSet/build.gradle | 3 +- .../resources/downloadURLSet/build.gradle.kts | 3 +- src/main/kotlin/Godle.kt | 48 ++++++++----------- src/main/kotlin/dsl/GodleExtension.kt | 18 ++++++- src/main/kotlin/dsl/GodotDownloadConfig.kt | 7 +-- .../dsl/addon/sources/AssetStoreAddon.kt | 8 +++- src/main/kotlin/tasks/GodotDownload.kt | 42 ++++++++++++++++ 9 files changed, 101 insertions(+), 39 deletions(-) create mode 100644 src/integrationTest/README.MD create mode 100644 src/main/kotlin/tasks/GodotDownload.kt diff --git a/build.gradle.kts b/build.gradle.kts index 4a21088..1862173 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "io.github.frontrider.godle" -version = "1.0-SNAPSHOT" +version = "0.2.0" repositories { mavenCentral() @@ -50,8 +50,9 @@ dependencies { testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.0") } pluginBundle{ - vcsUrl= "" + vcsUrl= "https://github.com/Frontrider/Godle" website = vcsUrl + tags = listOf("game development","godot") } @@ -61,6 +62,7 @@ gradlePlugin { plugins { create("godle") { id = group.toString() + displayName = "Godle" implementationClass = "io.github.frontrider.godle.Godle" description = "Plugin to manage small tasks around plugins, like addons and the godot binary itself." } @@ -71,7 +73,7 @@ gradlePlugin { publishing { publications { - create("maven"){ + create("pluginMaven"){ groupId = project.group.toString() artifactId = project.name version = project.version.toString() diff --git a/src/integrationTest/README.MD b/src/integrationTest/README.MD new file mode 100644 index 0000000..34986b0 --- /dev/null +++ b/src/integrationTest/README.MD @@ -0,0 +1,3 @@ +The test suit must be down to as many individual classes as it is reasonable, to take advantage of multi threading! + +Every test should be done with both dsl-s, to verify that every user can handle the plugin. \ No newline at end of file diff --git a/src/integrationTest/resources/downloadURLSet/build.gradle b/src/integrationTest/resources/downloadURLSet/build.gradle index bef9f8b..ac0f011 100644 --- a/src/integrationTest/resources/downloadURLSet/build.gradle +++ b/src/integrationTest/resources/downloadURLSet/build.gradle @@ -5,6 +5,7 @@ plugins { godle{ downloadConfig{ - downloadURL = "https://downloads.tuxfamily.org/godotengine/3.5/Godot_v3.5-stable_win32.exe.zip" + windowsDownloadURL = "https://downloads.tuxfamily.org/godotengine/3.5/Godot_v3.5-stable_win32.exe.zip" + linuxDownloadURL = "https://downloads.tuxfamily.org/godotengine/3.5/Godot_v3.5-stable_win32.exe.zip" } } \ No newline at end of file diff --git a/src/integrationTest/resources/downloadURLSet/build.gradle.kts b/src/integrationTest/resources/downloadURLSet/build.gradle.kts index 2c14dcc..1495a61 100644 --- a/src/integrationTest/resources/downloadURLSet/build.gradle.kts +++ b/src/integrationTest/resources/downloadURLSet/build.gradle.kts @@ -6,6 +6,7 @@ plugins { godle { downloadConfig { - downloadURL.set("https://downloads.tuxfamily.org/godotengine/3.5/Godot_v3.5-stable_win32.exe.zip") + windowsDownloadURL.set("https://downloads.tuxfamily.org/godotengine/3.5/Godot_v3.5-stable_win32.exe.zip") + linuxDownloadURL.set( "https://downloads.tuxfamily.org/godotengine/3.5/Godot_v3.5-stable_win32.exe.zip") } } \ No newline at end of file diff --git a/src/main/kotlin/Godle.kt b/src/main/kotlin/Godle.kt index 0a51fce..af33083 100644 --- a/src/main/kotlin/Godle.kt +++ b/src/main/kotlin/Godle.kt @@ -1,8 +1,8 @@ package io.github.frontrider.godle -import fi.linuxbox.gradle.download.Download import fi.linuxbox.gradle.download.DownloadPlugin import io.github.frontrider.godle.dsl.GodleExtension +import io.github.frontrider.godle.tasks.GodotDownload import io.github.frontrider.godle.tasks.GodotExec import org.gradle.api.Plugin import org.gradle.api.Project @@ -10,6 +10,7 @@ import org.gradle.api.tasks.Copy import org.gradle.api.tasks.Delete import java.io.File +@Suppress("Unused") class Godle : Plugin { override fun apply(project: Project) { project.extensions.create("godle", GodleExtension::class.java) @@ -30,11 +31,7 @@ class Godle : Plugin { println("Current version: ${extension.getDownloadConfig().godotVersion.get()}") val downloadConfig = extension.getDownloadConfig() - val hasMono = downloadConfig.mono.get() - val version = downloadConfig.godotVersion.get() - val classifier = downloadConfig.classifier.get() val compressed = downloadConfig.isCompressed.get() - val downloadPath = "${project.buildDir.absolutePath}/$GodotCacheFolder/" val storePath = "${project.buildDir.absolutePath}/$GodotFolder/" project.tasks.create("cleanGodotAddons", Delete::class.java) { @@ -44,31 +41,10 @@ class Godle : Plugin { group = "godle" } } - val godotDownloadTask = it.tasks.create("godotDownload", Download::class.java) { download -> + val godotDownloadTask = it.tasks.create("godotDownload", GodotDownload::class.java) { download -> with(download) { description = "Downloads the configured godot version." group = "godle" - from.set(extension.getDownloadURL()) - to.set( - File( - if (hasMono) { - "${downloadPath}/Godot_mono_V${version}_$classifier" - } else { - "${downloadPath}/Godot_V${version}_$classifier" - } + if (compressed) { - ".zip" - } else { - "" - } - ) - ) - doFirst { - println("downloading godot from ${from.get()}") - } - //IF we already downloaded then this is up-to-date. - outputs.upToDateWhen { - to.get().asFile.exists() - } } } val godotExtractTask = it.tasks.create("godotExtract", Copy::class.java) { copy -> @@ -87,14 +63,28 @@ class Godle : Plugin { if (compressed) { from(it.zipTree(godotDownloadTask.to.get())) } else { + fileMode = 754 from(godotDownloadTask.to.get()) } destinationDir = File(storePath) } } + //IF a build task exists, then we depend on it. + //The primary use of this is with Godot Kotlin/JVM, so the binaries are built and provided. + //THIS WILL BE TREATED AS A CONVENTION! IF the build task exists, then it will run! + val build = project.tasks.findByPath("build") + it.tasks.create("godotEditor", GodotExec::class.java) { exec -> + with(exec) { + //IF a build task exists, then depend on it. + //The primary use of this is with Godot Kotlin/JVM, so the binaries are built and provided to godot. + //THIS WILL BE TREATED AS A CONVENTION! Anything running together with the build task, will be used! + if(build != null){ + this.dependsOn(build) + } + description = "Launch the godot editor" group = "godle" args("--editor") @@ -107,6 +97,10 @@ class Godle : Plugin { it.tasks.create("godotRunGame", GodotExec::class.java) { exec -> with(exec) { + if(build != null){ + this.dependsOn(build) + } + description = "Launch the game in the current project" group = "application" dependsOn(godotExtractTask) diff --git a/src/main/kotlin/dsl/GodleExtension.kt b/src/main/kotlin/dsl/GodleExtension.kt index b816743..9bf2470 100644 --- a/src/main/kotlin/dsl/GodleExtension.kt +++ b/src/main/kotlin/dsl/GodleExtension.kt @@ -3,13 +3,13 @@ package io.github.frontrider.godle.dsl import io.github.frontrider.godle.* import io.github.frontrider.godle.dsl.addon.GodotAddonDependencyContainer import io.github.frontrider.godle.dsl.execution.ExecutionConfig +import org.apache.commons.lang3.SystemUtils import org.gradle.api.Action import org.gradle.api.Project import org.gradle.api.file.RegularFileProperty import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Property import org.gradle.api.tasks.Nested -import java.io.File import javax.inject.Inject /** @@ -69,7 +69,21 @@ abstract class GodleExtension @Inject constructor(objectFactory: ObjectFactory,v if (classifier == ClassifierLinux32 && hasMono) { classifier = ClassifierLinux32Mono } - val downloadURL = downloadConfig.downloadURL.get() + + val downloadURL = + when { + SystemUtils.IS_OS_MAC -> { + downloadConfig.macDownloadURL.get() + } + SystemUtils.IS_OS_WINDOWS -> { + downloadConfig.windowsDownloadURL.get() + } + //we default to linux if we had no idea what the system is. + else -> { + downloadConfig.linuxDownloadURL.get() + } + } + if (downloadURL.isNotEmpty()) { println("Download url set, getting godot from $downloadURL") return downloadURL diff --git a/src/main/kotlin/dsl/GodotDownloadConfig.kt b/src/main/kotlin/dsl/GodotDownloadConfig.kt index 2be4b77..614f395 100644 --- a/src/main/kotlin/dsl/GodotDownloadConfig.kt +++ b/src/main/kotlin/dsl/GodotDownloadConfig.kt @@ -2,7 +2,6 @@ package io.github.frontrider.godle.dsl import io.github.frontrider.godle.* import org.apache.commons.lang3.SystemUtils -import org.gradle.api.internal.model.DefaultObjectFactory import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.Property import javax.inject.Inject @@ -40,7 +39,9 @@ abstract class GodotDownloadConfig @Inject constructor(objectFactory: ObjectFact } } ) - //If the full url needs to be overridden. IF set everything else is ignored. - val downloadURL: Property = objectFactory.property(String::class.java).convention("") + //If the full url needs to be overridden. IF set for the current platform, then the other configs are ignored. + val linuxDownloadURL: Property = objectFactory.property(String::class.java).convention("") + val windowsDownloadURL: Property = objectFactory.property(String::class.java).convention("") + val macDownloadURL: Property = objectFactory.property(String::class.java).convention("") val isCompressed: Property = objectFactory.property(Boolean::class.java).convention(true) } \ No newline at end of file diff --git a/src/main/kotlin/dsl/addon/sources/AssetStoreAddon.kt b/src/main/kotlin/dsl/addon/sources/AssetStoreAddon.kt index ce89299..650c8de 100644 --- a/src/main/kotlin/dsl/addon/sources/AssetStoreAddon.kt +++ b/src/main/kotlin/dsl/addon/sources/AssetStoreAddon.kt @@ -8,18 +8,22 @@ import java.io.File import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.registerKotlinModule +import io.github.frontrider.godle.dsl.GodleExtension import io.github.frontrider.godle.dsl.configureAsGodleInternal import kong.unirest.Unirest import kong.unirest.UnirestException import org.gradle.api.tasks.Copy -import java.net.UnknownHostException class AssetStoreAddon(val id: String, addonConfig: AddonConfig, project: Project) : GodotAddon(addonConfig, project) { override fun init() { val internalName = getAddonInternalName() try { - val response = Unirest.get("https://godotengine.org/asset-library/api/asset/$id").asString() + val extension = project.extensions.getByName("godle") as GodleExtension + val downloadConfig = extension.getDownloadConfig() + val assetStoreURL = downloadConfig.godotAssetStoreBaseURL.get() + + val response = Unirest.get("$assetStoreURL/asset/$id").asString() val objectMapper = ObjectMapper().registerKotlinModule() //being gitlike is the default behavior, as most addons come from git repositories. diff --git a/src/main/kotlin/tasks/GodotDownload.kt b/src/main/kotlin/tasks/GodotDownload.kt new file mode 100644 index 0000000..d6c5dbc --- /dev/null +++ b/src/main/kotlin/tasks/GodotDownload.kt @@ -0,0 +1,42 @@ +package io.github.frontrider.godle.tasks + +import fi.linuxbox.gradle.download.Download +import io.github.frontrider.godle.GodotCacheFolder +import io.github.frontrider.godle.dsl.GodleExtension +import org.gradle.workers.WorkerExecutor +import java.io.File +import javax.inject.Inject + +abstract class GodotDownload @Inject constructor(workerExecutor: WorkerExecutor?) :Download(workerExecutor) { + + init { + val extension = project.extensions.getByName("godle") as GodleExtension + val downloadConfig = extension.getDownloadConfig() + + val hasMono = downloadConfig.mono.get() + val version = downloadConfig.godotVersion.get() + val classifier = downloadConfig.classifier.get() + val compressed = downloadConfig.isCompressed.get() + val downloadPath = "${project.buildDir.absolutePath}/$GodotCacheFolder/" + + from.set(extension.getDownloadURL()) + to.set( + File( + if (hasMono) { + "${downloadPath}/Godot_mono_V${version}_$classifier" + } else { + "${downloadPath}/Godot_V${version}_$classifier" + } + if (compressed) { + ".zip" + } else { + "" + } + ) + ) + //IF we already downloaded then this is up-to-date. + outputs.upToDateWhen { + to.get().asFile.exists() + } + + } +} \ No newline at end of file