diff --git a/src/main/kotlin/lgbt/mystic/foundation/concrete/SetupPaperServer.kt b/src/main/kotlin/lgbt/mystic/foundation/concrete/SetupPaperServer.kt index b04157a..b0742fa 100644 --- a/src/main/kotlin/lgbt/mystic/foundation/concrete/SetupPaperServer.kt +++ b/src/main/kotlin/lgbt/mystic/foundation/concrete/SetupPaperServer.kt @@ -16,7 +16,7 @@ open class SetupPaperServer : DefaultTask() { @get:Input @set:Option(option = "update", description = "Update Paper Server") - var shouldUpdatePaperServer = false + var shouldUpdatePaperServer = true private val paperVersionClient = PaperVersionClient() @@ -58,6 +58,14 @@ open class SetupPaperServer : DefaultTask() { } private fun downloadLatestBuild(paperVersionGroup: String, paperJarFile: File) { + if (project.gradle.startParameter.isOffline) { + if (!paperJarFile.exists()) { + throw RuntimeException("Offline mode is enabled and Paper has not been downloaded.") + } else { + logger.lifecycle("Offline mode is enabled, skipping Paper update.") + return + } + } val builds = paperVersionClient.getVersionBuilds(paperVersionGroup) val build = builds.last() val download = build.downloads["application"]!! diff --git a/src/main/kotlin/lgbt/mystic/foundation/concrete/extensions.kt b/src/main/kotlin/lgbt/mystic/foundation/concrete/extensions.kt index 33b2e25..4f260c8 100644 --- a/src/main/kotlin/lgbt/mystic/foundation/concrete/extensions.kt +++ b/src/main/kotlin/lgbt/mystic/foundation/concrete/extensions.kt @@ -2,6 +2,7 @@ package lgbt.mystic.foundation.concrete import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import org.gradle.api.Project +import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.TaskOutputs import java.nio.file.FileSystems import java.nio.file.Path @@ -9,43 +10,41 @@ import java.nio.file.Path internal fun Project.isPluginProject() = plugins.hasPlugin(ConcretePluginPlugin::class.java) internal fun Project.findPluginProjects() = allprojects.filter { project -> project.isPluginProject() } +internal inline fun TaskContainer.find(name: String) = + findByName(name) as T? + internal val Project.shadowJarTask: ShadowJar? - get() = - if (project.tasks.names.contains("shadowJar")) - project.tasks.getByName("shadowJar") as ShadowJar - else null + get() = project.tasks.find("shadowJar") internal val Project.shadowJarOutputs: TaskOutputs? get() = shadowJarTask?.outputs internal val Project.concreteRootExtension: ConcreteExtension - get() { - val direct = extensions.findByType(ConcreteExtension::class.java) - if (direct != null) { - return direct - } - - if (parent != null) { - return parent!!.concreteRootExtension - } - - throw RuntimeException("Failed to find concrete extension. Did you apply the concrete root plugin?") - } + get() = findTargetParent( + valid = { extensions.findByType(ConcreteExtension::class.java) != null }, + extract = { extensions.findByType(ConcreteExtension::class.java)!! }, + error = { "Failed to find concrete root. Did you apply the concrete root plugin?" } + ) internal val Project.concreteRootProject: Project - get() { - val direct = extensions.findByType(ConcreteExtension::class.java) - if (direct != null) { - return this - } + get() = findTargetParent( + valid = { extensions.findByType(ConcreteExtension::class.java) != null }, + extract = { this }, + error = { "Failed to find concrete root. Did you apply the concrete root plugin?" } + ) - if (parent != null) { - return parent!!.concreteRootProject - } - - throw RuntimeException("Failed to find concrete root. Did you apply the concrete root plugin?") +internal fun Project.findTargetParent(valid: Project.() -> Boolean, extract: Project.() -> T, error: () -> String): T { + if (valid(this)) { + return extract(this) } + if (parent != null) { + return parent!!.findTargetParent(valid, extract, error) + } + + throw RuntimeException(error()) +} + internal fun TaskOutputs.allFilesRelativeToPath(root: Path): List = files.map { root.relativize(it.toPath()) } internal fun Path.toUnixString() = toString().replace(FileSystems.getDefault().separator, "/")