Skip to content

Commit

Permalink
Dedicated download task included, running the game/editor now depends…
Browse files Browse the repository at this point in the history
… on running the build task if it exists.

Assetstore url is no longer hardcoded, the configuration is used.
  • Loading branch information
Frontrider committed Nov 20, 2022
1 parent 520e0a7 commit 82877dd
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 39 deletions.
8 changes: 5 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "io.github.frontrider.godle"
version = "1.0-SNAPSHOT"
version = "0.2.0"

repositories {
mavenCentral()
Expand Down Expand Up @@ -50,8 +50,9 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.0")
}
pluginBundle{
vcsUrl= "<uri to project source repository>"
vcsUrl= "https://github.com/Frontrider/Godle"
website = vcsUrl

tags = listOf("game development","godot")
}

Expand All @@ -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."
}
Expand All @@ -71,7 +73,7 @@ gradlePlugin {

publishing {
publications {
create<MavenPublication>("maven"){
create<MavenPublication>("pluginMaven"){
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
Expand Down
3 changes: 3 additions & 0 deletions src/integrationTest/README.MD
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion src/integrationTest/resources/downloadURLSet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
48 changes: 21 additions & 27 deletions src/main/kotlin/Godle.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
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
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Delete
import java.io.File

@Suppress("Unused")
class Godle : Plugin<Project> {
override fun apply(project: Project) {
project.extensions.create("godle", GodleExtension::class.java)
Expand All @@ -30,11 +31,7 @@ class Godle : Plugin<Project> {
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) {
Expand All @@ -44,31 +41,10 @@ class Godle : Plugin<Project> {
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 ->
Expand All @@ -87,14 +63,28 @@ class Godle : Plugin<Project> {
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")
Expand All @@ -107,6 +97,10 @@ class Godle : Plugin<Project> {

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)
Expand Down
18 changes: 16 additions & 2 deletions src/main/kotlin/dsl/GodleExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/dsl/GodotDownloadConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<String> = 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<String> = objectFactory.property(String::class.java).convention("")
val windowsDownloadURL: Property<String> = objectFactory.property(String::class.java).convention("")
val macDownloadURL: Property<String> = objectFactory.property(String::class.java).convention("")
val isCompressed: Property<Boolean> = objectFactory.property(Boolean::class.java).convention(true)
}
8 changes: 6 additions & 2 deletions src/main/kotlin/dsl/addon/sources/AssetStoreAddon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
42 changes: 42 additions & 0 deletions src/main/kotlin/tasks/GodotDownload.kt
Original file line number Diff line number Diff line change
@@ -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()
}

}
}

0 comments on commit 82877dd

Please sign in to comment.