From 438eff19da8d50d90df4465095f128a10aa70ab0 Mon Sep 17 00:00:00 2001 From: sky Date: Sun, 11 Jul 2021 00:54:35 +0800 Subject: [PATCH] + update description file generator --- .../izzel/taboolib/gradle/Description.groovy | 266 ------------------ .../izzel/taboolib/gradle/RelocateJar.groovy | 25 +- .../taboolib/gradle/TabooLibExtension.groovy | 10 +- .../gradle/description/Builder.groovy | 75 +++++ .../gradle/description/BuilderBukkit.groovy | 43 +++ .../gradle/description/BuilderBungee.groovy | 39 +++ .../gradle/description/BuilderNukkit.groovy | 43 +++ .../gradle/description/BuilderSponge7.groovy | 33 +++ .../gradle/description/BuilderSponge8.groovy | 56 ++++ .../gradle/description/BuilderVelocity.groovy | 27 ++ .../gradle/description/Contributors.groovy | 27 ++ .../gradle/description/Dependencies.groovy | 66 +++++ .../gradle/description/Description.groovy | 64 +++++ .../taboolib/gradle/description/Links.groovy | 27 ++ .../gradle/description/Platforms.groovy | 26 ++ 15 files changed, 538 insertions(+), 289 deletions(-) delete mode 100644 src/main/groovy/io/izzel/taboolib/gradle/Description.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/Builder.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/BuilderBukkit.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/BuilderBungee.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/BuilderNukkit.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/BuilderSponge7.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/BuilderSponge8.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/BuilderVelocity.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/Contributors.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/Dependencies.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/Description.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/Links.groovy create mode 100644 src/main/groovy/io/izzel/taboolib/gradle/description/Platforms.groovy diff --git a/src/main/groovy/io/izzel/taboolib/gradle/Description.groovy b/src/main/groovy/io/izzel/taboolib/gradle/Description.groovy deleted file mode 100644 index aa4ae47..0000000 --- a/src/main/groovy/io/izzel/taboolib/gradle/Description.groovy +++ /dev/null @@ -1,266 +0,0 @@ -package io.izzel.taboolib.gradle - -import com.google.gson.GsonBuilder -import org.gradle.api.Project -import com.google.gson.JsonArray -import com.google.gson.JsonObject - -import java.nio.charset.StandardCharsets - -class Description { - - def authors - def contributors - def depend - def softdepend - def loadbefore - def website - def prefix - def load - def api = "1.0.0" - def apiVersion = '1.13' - def libraries - def dependencies - def requiredMods = "spongeapi@7.2.0" - def custom = new HashMap() - - static List buildFile() { - def str = [] - str += "" - str += "" - str += "# Powered by TabooLib 6.0 #" - str += "" - str += "" - return str - } - - static def appendName(str, any, key) { - if (any != null) { - str.add("$key: $any") - } - } - - static def appendNameList(str, any, key) { - if (any instanceof List) { - str.add("$key:") - for (i in any) { - str.add(" - '${i}'") - } - } else if (any != null) { - str.add("$key:") - str.add(" - '${any}'") - } - } - - byte[] buildBukkitFile(Project project) { - def str = buildFile() - str += "name: ${project.name}" - str += "main: ${project.group}.taboolib.platform.BukkitPlugin" - appendName(str, load, "load") - str += "version: ${project.version}" - if (apiVersion != null) { - str += "api-version: ${apiVersion}" - } - appendName(str, prefix, "prefix") - appendName(str, website, "website") - appendNameList(str, authors, "authors") - appendNameList(str, contributors, "contributors") - appendNameList(str, depend, "depend") - appendNameList(str, softdepend, "softdepend") - appendNameList(str, loadbefore, "loadbefore") - appendNameList(str, libraries, "libraries") - custom.entrySet().each { - if (it.value instanceof List) { - appendNameList(str, it.value, it.key) - } else { - appendName(str, it.value, it.key) - } - } - return str.join("\n").getBytes(StandardCharsets.UTF_8) - } - - byte[] buildBungeeFile(Project project) { - def str = buildFile() - str += "name: ${project.name}" - str += "main: ${project.group}.taboolib.platform.BungeePlugin" - str += "version: ${project.version}" - appendName(str, authors, "author") - appendNameList(str, depend, "depends") - appendNameList(str, softdepend, "softDepends") - appendNameList(str, libraries, "libraries") - custom.entrySet().each { - if (it.value instanceof List) { - appendNameList(str, it.value, it.key) - } else { - appendName(str, it.value, it.key) - } - } - return str.join("\n").getBytes(StandardCharsets.UTF_8) - } - - byte[] buildNukkitFile(Project project) { - def str = buildFile() - str += "name: ${project.name}" - str += "main: ${project.group}.taboolib.platform.NukkitPlugin" - appendName(str, load, "load") - str += "version: ${project.version}" - if (api != null) { - str += "api: ${api}" - } - appendName(str, prefix, "prefix") - appendName(str, website, "website") - appendNameList(str, authors, "authors") - appendNameList(str, depend, "depend") - appendNameList(str, softdepend, "softdepend") - appendNameList(str, loadbefore, "loadbefore") - appendNameList(str, libraries, "libraries") - custom.entrySet().each { - if (it.value instanceof List) { - appendNameList(str, it.value, it.key) - } else { - appendName(str, it.value, it.key) - } - } - return str.join("\n").getBytes(StandardCharsets.UTF_8) - } - - byte[] buildSpongeFile(Project project) { - def base = new JsonArray() - def info = new JsonObject() - info.addProperty("modid", project.name.toLowerCase()) - info.addProperty("name", project.name) - info.addProperty("version", project.version.toString()) - if (website != null) { - info.addProperty("url", website.toString()) - } - if (authors instanceof List) { - def arr = new JsonArray() - authors.each { arr.add(it) } - info.add("authorList", arr) - } else if (authors != null) { - def arr = new JsonArray() - arr.add(authors.toString()) - info.add("authorList", arr) - } - if (dependencies instanceof List) { - def arr = new JsonArray() - if (dependencies.none { "spongeapi" in it }) { - arr.add("spongeapi@7.2.0") - } - dependencies.each { arr.add(it) } - info.add("dependencies", arr) - } else if (dependencies != null) { - def arr = new JsonArray() - arr.add(dependencies.toString()) - info.add("dependencies", arr) - } else { - def arr = new JsonArray() - arr.add("spongeapi@7.2.0") - info.add("dependencies", arr) - } - if (requiredMods instanceof List) { - def arr = new JsonArray() - requiredMods.each { arr.add(it) } - info.add("requiredMods", arr) - } else if (requiredMods != null) { - def arr = new JsonArray() - arr.add(requiredMods.toString()) - info.add("requiredMods", arr) - } - base.add(info) - return new GsonBuilder().setPrettyPrinting().create().toJson(base).getBytes(StandardCharsets.UTF_8) - } - - byte[] buildVelocityFile(Project project) { - def base = new JsonArray() - def info = new JsonObject() - info.addProperty("id", project.name.toLowerCase()) - info.addProperty("name", project.name) - info.addProperty("main", "${project.group}.taboolib.platform.VelocityPlugin") - info.addProperty("version", project.version.toString()) - if (authors instanceof List) { - def arr = new JsonArray() - authors.each { arr.add(it) } - info.add("authors", arr) - } else if (authors != null) { - def arr = new JsonArray() - arr.add(authors.toString()) - info.add("authors", arr) - } - if (dependencies instanceof List) { - def arr = new JsonArray() - dependencies.each { arr.add(it) } - info.add("dependencies", arr) - } else if (dependencies != null) { - def arr = new JsonArray() - arr.add(dependencies.toString()) - info.add("dependencies", arr) - } - base.add(info) - return new GsonBuilder().setPrettyPrinting().create().toJson(base).getBytes(StandardCharsets.UTF_8) - } - - def author(author) { - this.authors = author - } - - def contributor(contributor) { - this.contributors = contributor - } - - def authors(author) { - this.authors = author - } - - def contributors(contributor) { - this.contributors = contributor - } - - def depend(depend) { - this.depend = depend - } - - def softdepend(softdepend) { - this.softdepend = softdepend - } - - def loadbefore(loadbefore) { - this.loadbefore = loadbefore - } - - def website(website) { - this.website = website - } - - def prefix(prefix) { - this.prefix = prefix - } - - def load(load) { - this.load = load - } - - def api(api) { - this.api = api - } - - def apiVersion(apiVersion) { - this.apiVersion = apiVersion - } - - def libraries(libraries) { - this.libraries = libraries - } - - def dependencies(dependencies) { - this.dependencies = dependencies - } - - def requiredMods(requiredMods) { - this.requiredMods = requiredMods - } - - def custom(String key, value) { - this.custom[key] = value - } -} diff --git a/src/main/groovy/io/izzel/taboolib/gradle/RelocateJar.groovy b/src/main/groovy/io/izzel/taboolib/gradle/RelocateJar.groovy index 2213e54..e809526 100644 --- a/src/main/groovy/io/izzel/taboolib/gradle/RelocateJar.groovy +++ b/src/main/groovy/io/izzel/taboolib/gradle/RelocateJar.groovy @@ -1,6 +1,7 @@ package io.izzel.taboolib.gradle import groovy.transform.ToString +import io.izzel.taboolib.gradle.description.Platforms import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.tasks.Input @@ -112,25 +113,11 @@ class RelocateJar extends DefaultTask { } } } - if (tabooExt.modules.contains("platform-bukkit")) { - out.putNextEntry(new JarEntry("plugin.yml")) - out.write(tabooExt.description.buildBukkitFile(project)) - } - if (tabooExt.modules.contains("platform-nukkit")) { - out.putNextEntry(new JarEntry("nukkit.yml")) - out.write(tabooExt.description.buildNukkitFile(project)) - } - if (tabooExt.modules.contains("platform-bungee")) { - out.putNextEntry(new JarEntry("bungee.yml")) - out.write(tabooExt.description.buildBungeeFile(project)) - } - if (tabooExt.modules.contains("platform-sponge")) { - out.putNextEntry(new JarEntry("mcmod.info")) - out.write(tabooExt.description.buildSpongeFile(project)) - } - if (tabooExt.modules.contains("platform-velocity")) { - out.putNextEntry(new JarEntry("velocity-plugin.json")) - out.write(tabooExt.description.buildVelocityFile(project)) + Platforms.values().each { + if (tabooExt.modules.contains(it.module)) { + out.putNextEntry(new JarEntry(it.file)) + out.write(it.builder.build(tabooExt.des, project)) + } } } } diff --git a/src/main/groovy/io/izzel/taboolib/gradle/TabooLibExtension.groovy b/src/main/groovy/io/izzel/taboolib/gradle/TabooLibExtension.groovy index 2afcb3c..6613a81 100644 --- a/src/main/groovy/io/izzel/taboolib/gradle/TabooLibExtension.groovy +++ b/src/main/groovy/io/izzel/taboolib/gradle/TabooLibExtension.groovy @@ -1,7 +1,8 @@ package io.izzel.taboolib.gradle import groovy.transform.Canonical -import org.codehaus.groovy.runtime.DefaultGroovyMethods +import io.izzel.taboolib.gradle.description.Description +import org.gradle.api.Action @Canonical class TabooLibExtension { @@ -12,7 +13,7 @@ class TabooLibExtension { List modules = [] - Description description = new Description() + Description des = new Description() Map relocation = new LinkedHashMap<>() @@ -24,7 +25,8 @@ class TabooLibExtension { relocation[pre] = post } - def descriptionFile(@DelegatesTo(Description.class) Closure closure) { - DefaultGroovyMethods.with(description, closure) + def description(closure) { + closure.delegate = des + closure() } } diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/Builder.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/Builder.groovy new file mode 100644 index 0000000..6e5bb8f --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/Builder.groovy @@ -0,0 +1,75 @@ +package io.izzel.taboolib.gradle.description + +import com.google.gson.GsonBuilder +import com.google.gson.JsonArray +import com.google.gson.JsonElement +import com.google.gson.JsonObject +import org.gradle.api.Project + +import java.nio.charset.StandardCharsets + +abstract class Builder { + + abstract byte[] build(Description description, Project project) + + static List startBukkitFile() { + def str = [] + str += '' + str += '' + str += '# Powered by TabooLib 6.0 #' + str += '' + str += '' + return str + } + + static def writeLine(body) { + body.add("") + } + + static def write(List body, data, key) { + if (data != null) { + body.add("$key: $data") + } + } + + static def write(JsonObject body, data, key) { + if (data != null) { + body.addProperty("$key", "$data") + } + } + + static def writeList(List body, data, key) { + if (data instanceof List) { + if (data.size() > 0) { + body.add("$key:") + for (i in data) { + body.add(" - '${i}'") + } + } + } else if (data != null) { + body.add("$key:") + body.add(" - '${data}'") + } + } + + static def writeList(JsonObject body, data, key) { + def arr = new JsonArray() + if (data instanceof List) { + if (data.size() > 0) { + data.each { arr.add(it) } + body.add(key, arr) + } + } else if (data != null) { + arr.add(data.toString()) + body.add(key, arr) + } + } + + static byte[] bytes(List body) { + return body.join('\n').getBytes(StandardCharsets.UTF_8) + } + + static byte[] bytes(JsonElement body) { + return new GsonBuilder().setPrettyPrinting().create().toJson(body).getBytes(StandardCharsets.UTF_8) + } +} \ No newline at end of file diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderBukkit.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderBukkit.groovy new file mode 100644 index 0000000..9cbbc7d --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderBukkit.groovy @@ -0,0 +1,43 @@ +package io.izzel.taboolib.gradle.description + +import org.gradle.api.Project + +class BuilderBukkit extends Builder { + + @Override + byte[] build(Description description, Project project) { + def body = startBukkitFile() + body += "name: ${project.name}" + body += "main: ${project.group}.taboolib.platform.BukkitPlugin" + body += "version: ${project.version}" + write(body, description.lin.links['homepage'], 'website') + writeLine(body) + // authors + def con = description.con.contributors.collect { it.name } + writeList(body, con, 'authors') + writeLine(body) + // dependency + writeList(body, description.dep.dependencies + .findAll { it.with == null || it.with.equalsIgnoreCase('bukkit') } + .findAll { it.forceDepend() } + .collect { it.name }, 'depend') + writeList(body, description.dep.dependencies + .findAll { it.with == null || it.with.equalsIgnoreCase('bukkit') } + .findAll { it.optional } + .collect { it.name }, 'softdepend') + writeList(body, description.dep.dependencies + .findAll { it.with == null || it.with.equalsIgnoreCase('bukkit') } + .findAll { it.loadbefore } + .collect { it.name }, 'loadbefore') + writeLine(body) + // custom nodes + description.bukkitNodes.each { + if (it.value instanceof List) { + writeList(body, it.value, it.key) + } else { + write(body, it.value, it.key) + } + } + return bytes(body) + } +} diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderBungee.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderBungee.groovy new file mode 100644 index 0000000..f056e72 --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderBungee.groovy @@ -0,0 +1,39 @@ +package io.izzel.taboolib.gradle.description + +import org.gradle.api.Project + +class BuilderBungee extends Builder { + + @Override + byte[] build(Description description, Project project) { + def body = startBukkitFile() + body += "name: ${project.name}" + body += "main: ${project.group}.taboolib.platform.BungeePlugin" + body += "version: ${project.version}" + write(body, description.lin.links['homepage'], 'website') + writeLine(body) + // authors + def con = description.con.contributors.collect { it.name } + writeList(body, con, 'authors') + writeLine(body) + // dependency + writeList(body, description.dep.dependencies + .findAll { it.with == null || it.with.equalsIgnoreCase('bungee') } + .findAll { it.forceDepend() } + .collect { it.name }, 'depends') + writeList(body, description.dep.dependencies + .findAll { it.with == null || it.with.equalsIgnoreCase('bungee') } + .findAll { it.optional } + .collect { it.name }, 'softDepends') + writeLine(body) + // custom nodes + description.bungeeNodes.each { + if (it.value instanceof List) { + writeList(body, it.value, it.key) + } else { + write(body, it.value, it.key) + } + } + return bytes(body) + } +} diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderNukkit.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderNukkit.groovy new file mode 100644 index 0000000..99e6242 --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderNukkit.groovy @@ -0,0 +1,43 @@ +package io.izzel.taboolib.gradle.description + +import org.gradle.api.Project + +class BuilderNukkit extends Builder { + + @Override + byte[] build(Description description, Project project) { + def body = startBukkitFile() + body += "name: ${project.name}" + body += "main: ${project.group}.taboolib.platform.NukkitPlugin" + body += "version: ${project.version}" + write(body, description.lin.links['homepage'], 'website') + writeLine(body) + // authors + def con = description.con.contributors.collect { it.name } + writeList(body, con, 'authors') + writeLine(body) + // dependency + writeList(body, description.dep.dependencies + .findAll { it.with == null || it.with.equalsIgnoreCase('nukkit') } + .findAll { it.forceDepend() } + .collect { it.name }, 'depend') + writeList(body, description.dep.dependencies + .findAll { it.with == null || it.with.equalsIgnoreCase('nukkit') } + .findAll { it.optional } + .collect { it.name }, 'softdepend') + writeList(body, description.dep.dependencies + .findAll { it.with == null || it.with.equalsIgnoreCase('nukkit') } + .findAll { it.loadbefore } + .collect { it.name }, 'loadbefore') + writeLine(body) + // custom nodes + description.nukkitNodes.each { + if (it.value instanceof List) { + writeList(body, it.value, it.key) + } else { + write(body, it.value, it.key) + } + } + return bytes(body) + } +} diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderSponge7.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderSponge7.groovy new file mode 100644 index 0000000..9f00c50 --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderSponge7.groovy @@ -0,0 +1,33 @@ +package io.izzel.taboolib.gradle.description + +import com.google.gson.JsonArray +import com.google.gson.JsonObject +import org.gradle.api.Project + +class BuilderSponge7 extends Builder { + + @Override + byte[] build(Description description, Project project) { + def json = new JsonArray() + def info = new JsonObject() + info.addProperty('modid', project.name.toLowerCase()) + info.addProperty('name', project.name) + info.addProperty('version', project.version.toString()) + write(info, description.spongeDesc, 'description') + write(info, description.lin.links['homepage'], 'url') + // authors + def con = description.con.contributors.collect { it.name } + writeList(info, con, 'authorList') + // dependencies + writeList(info, description.dep.dependencies + .findAll { it.with == null || it.with.equalsIgnoreCase('sponge7') } + .findAll { !it.mod } + .collect { it.fullyName() }, 'dependencies') + writeList(info, description.dep.dependencies + .findAll { it.with == null || it.with.equalsIgnoreCase('sponge7') } + .findAll { it.mod } + .collect { it.fullyName() }, 'requiredMods') + json.add(info) + return bytes(json) + } +} diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderSponge8.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderSponge8.groovy new file mode 100644 index 0000000..630b805 --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderSponge8.groovy @@ -0,0 +1,56 @@ +package io.izzel.taboolib.gradle.description + +import com.google.gson.JsonArray +import com.google.gson.JsonObject +import org.gradle.api.Project + +class BuilderSponge8 extends Builder { + + @Override + byte[] build(Description description, Project project) { + def json = new JsonObject() + def plugins = new JsonArray() + def info = new JsonObject() + info.addProperty('loader', 'java_plain') + info.addProperty('id', project.name.toLowerCase()) + info.addProperty('name', project.name) + info.addProperty('version', project.version.toString()) + info.addProperty('main-class', "${project.group}.taboolib.platform.Sponge8Plugin") + write(info, description.spongeDesc, 'description') + // links + if (description.lin.links.size() > 0) { + def links = new JsonObject() + description.lin.links.each { + links.addProperty(it.key, it.value.url) + } + info.add('links', links) + } + // contributors + if (description.con.contributors.size() > 0) { + def contributors = new JsonArray() + description.con.contributors.each { + def con = new JsonObject() + write(con, it.name, 'name') + write(con, it.description, 'description') + contributors.add(con) + } + info.add('contributors', contributors) + } + // dependencies + if (description.dep.dependencies.size() > 0) { + def dependencies = new JsonArray() + description.dep.dependencies.findAll { it.with == null || it.with.equalsIgnoreCase('sponge8') }.each { + def dep = new JsonObject() + write(dep, it.name, 'id') + write(dep, it.version, 'version') + dep.addProperty('load-order', it.loadafter ? 'AFTER' : 'UNDEFINED') + dep.addProperty('optional', it.optional) + dependencies.add(dep) + } + info.add('dependencies', dependencies) + } + plugins.add(info) + json.add('plugins', plugins) + return bytes(json) + } +} diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderVelocity.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderVelocity.groovy new file mode 100644 index 0000000..e38fb6f --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/BuilderVelocity.groovy @@ -0,0 +1,27 @@ +package io.izzel.taboolib.gradle.description + +import com.google.gson.JsonArray +import com.google.gson.JsonObject +import org.gradle.api.Project + +class BuilderVelocity extends Builder { + + @Override + byte[] build(Description description, Project project) { + def json = new JsonArray() + def info = new JsonObject() + info.addProperty('id', project.name.toLowerCase()) + info.addProperty('name', project.name) + info.addProperty('main', "${project.group}.taboolib.platform.VelocityPlugin") + info.addProperty('version', project.version.toString()) + // authors + def con = description.con.contributors.collect { it.name } + writeList(info, con, 'authors') + // dependencies + writeList(info, description.dep.dependencies + .findAll { it.with == null || it.with.equalsIgnoreCase('velocity') } + .collect { it.name }, 'dependencies') + json.add(info) + return bytes(json) + } +} diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/Contributors.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/Contributors.groovy new file mode 100644 index 0000000..3cc9264 --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/Contributors.groovy @@ -0,0 +1,27 @@ +package io.izzel.taboolib.gradle.description + +class Contributors { + + List contributors = [] + + Contributor name(name) { + def con = new Contributor(name) + contributors += con + return con + } + + class Contributor { + + def name + def description + + Contributor(name) { + this.name = name + } + + Contributor description(description) { + this.description = description + return this + } + } +} \ No newline at end of file diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/Dependencies.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/Dependencies.groovy new file mode 100644 index 0000000..fe097f5 --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/Dependencies.groovy @@ -0,0 +1,66 @@ +package io.izzel.taboolib.gradle.description + +class Dependencies { + + List dependencies = [] + + Dependency name(name) { + def dep = new Dependency(name) + dependencies += dep + return dep + } + + class Dependency { + + String name + String with + String version + + def loadafter = false + def loadbefore = false + def optional = false + def mod = false + + Dependency(name) { + this.name = name + } + + def fullyName(spec = '@') { + return version == null ? name : name + spec + version + } + + def forceDepend() { + return !loadafter && !loadbefore && !optional + } + + Dependency with(description) { + this.with = description + return this + } + + Dependency version(version) { + this.version = version + return this + } + + Dependency loadafter(loadafter) { + this.loadafter = loadafter + return this + } + + Dependency loadbefore(loadbefore) { + this.loadbefore = loadbefore + return this + } + + Dependency optional(optional) { + this.optional = optional + return this + } + + Dependency mod(mod) { + this.mod = mod + return this + } + } +} \ No newline at end of file diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/Description.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/Description.groovy new file mode 100644 index 0000000..0b0fa51 --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/Description.groovy @@ -0,0 +1,64 @@ +package io.izzel.taboolib.gradle.description + +import org.gradle.api.Action + +class Description { + + Contributors con = new Contributors() + + Dependencies dep = new Dependencies() + + Links lin = new Links() + + def bukkitNodes = new HashMap() + + def nukkitNodes = new HashMap() + + def bungeeNodes = new HashMap() + + String spongeDesc + + Description() { + bukkitApi('1.13') + nukkitApi('1.0.0') + } + + def desc(desc) { + bukkitNodes['description'] = desc + nukkitNodes['description'] = desc + bungeeNodes['description'] = desc + spongeDesc = desc + } + + def load(order) { + bukkitNodes['load'] = order + nukkitNodes['load'] = order + } + + def bukkitApi(api) { + bukkitNodes['api-version'] = api + } + + def nukkitApi(api) { + nukkitNodes['api'] = api + } + + def prefix(prefix) { + bukkitNodes['prefix'] = prefix + nukkitNodes['prefix'] = prefix + } + + def contributors(closure) { + closure.delegate = con + closure() + } + + def dependencies(closure) { + closure.delegate = dep + closure() + } + + def links(Action action) { + action.execute(lin) + } +} diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/Links.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/Links.groovy new file mode 100644 index 0000000..1d94656 --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/Links.groovy @@ -0,0 +1,27 @@ +package io.izzel.taboolib.gradle.description + +class Links { + + def links = new HashMap() + + Link name(name) { + def link = new Link(name) + links[link.name] = link + return link + } + + class Link { + + String name + String url + + Link(name) { + this.name = name + } + + Link url(url) { + this.url = url + return this + } + } +} \ No newline at end of file diff --git a/src/main/groovy/io/izzel/taboolib/gradle/description/Platforms.groovy b/src/main/groovy/io/izzel/taboolib/gradle/description/Platforms.groovy new file mode 100644 index 0000000..1531e46 --- /dev/null +++ b/src/main/groovy/io/izzel/taboolib/gradle/description/Platforms.groovy @@ -0,0 +1,26 @@ +package io.izzel.taboolib.gradle.description + +enum Platforms { + + BUKKIT('platform-bukkit', 'plugin.yml', new BuilderBukkit()), + + NUKKIT('platform-nukkit', 'nukkit.yml', new BuilderNukkit()), + + BUNGEE('platform-bungee', 'bungee.yml', new BuilderBungee()), + + VELOCITY('platform-velocity', 'velocity-plugin.json', new BuilderVelocity()), + + SPONGE7('platform-sponge-api7', 'mcmod.info', new BuilderSponge7()), + + SPONGE8('platform-sponge-api8', 'META-INF/plugins.json', new BuilderSponge8()); + + String module + String file + Builder builder + + Platforms(module, file, builder) { + this.module = module + this.file = file + this.builder = builder + } +} \ No newline at end of file