Compare commits
No commits in common. "master" and "1.7" have entirely different histories.
22
build.gradle
22
build.gradle
|
|
@ -3,13 +3,10 @@ plugins {
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
id 'java-gradle-plugin'
|
id 'java-gradle-plugin'
|
||||||
id 'com.gradle.plugin-publish' version '0.12.0'
|
id 'com.gradle.plugin-publish' version '0.12.0'
|
||||||
id 'org.jetbrains.kotlin.jvm' version '1.5.10'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'kotlin'
|
|
||||||
|
|
||||||
group 'io.izzel.taboolib'
|
group 'io.izzel.taboolib'
|
||||||
version '1.27'
|
version '1.7'
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
embed
|
embed
|
||||||
|
|
@ -24,10 +21,9 @@ dependencies {
|
||||||
compile 'org.codehaus.groovy:groovy:2.5.13'
|
compile 'org.codehaus.groovy:groovy:2.5.13'
|
||||||
compile gradleApi()
|
compile gradleApi()
|
||||||
compile localGroovy()
|
compile localGroovy()
|
||||||
embed 'org.ow2.asm:asm:9.2'
|
embed 'org.ow2.asm:asm:8.0.1'
|
||||||
embed 'org.ow2.asm:asm-commons:9.2'
|
embed 'org.ow2.asm:asm-commons:8.0.1'
|
||||||
embed 'com.google.code.gson:gson:2.8.7'
|
embed 'com.google.code.gson:gson:2.8.7'
|
||||||
embed 'org.jetbrains.kotlin:kotlin-stdlib'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
|
@ -58,15 +54,3 @@ publishing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
compileKotlin {
|
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
compileTestKotlin {
|
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = "1.8"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https://skymc.oss-cn-shanghai.aliyuncs.com/files/gradle-6.5-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,240 @@
|
||||||
|
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"
|
||||||
|
|
||||||
|
static List<String> 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<String>) {
|
||||||
|
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")
|
||||||
|
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")
|
||||||
|
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")
|
||||||
|
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<String>) {
|
||||||
|
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<String>) {
|
||||||
|
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<String>) {
|
||||||
|
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<String>) {
|
||||||
|
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<String>) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
package io.izzel.taboolib.gradle
|
|
||||||
|
|
||||||
import org.gradle.api.Project
|
|
||||||
import org.objectweb.asm.AnnotationVisitor
|
|
||||||
import org.objectweb.asm.Opcodes
|
|
||||||
|
|
||||||
class KotlinAnnotationVisitor extends AnnotationVisitor {
|
|
||||||
|
|
||||||
Project project
|
|
||||||
|
|
||||||
KotlinAnnotationVisitor(AnnotationVisitor annotationVisitor, project) {
|
|
||||||
super(Opcodes.ASM7, annotationVisitor)
|
|
||||||
this.project = project
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visit(String name, Object value) {
|
|
||||||
if (value instanceof String) {
|
|
||||||
super.visit(name, value
|
|
||||||
.replace("@kotlin_version@", getKotlinVersion())
|
|
||||||
.replace("@kotlin_version_escape@", getKotlinVersionEscape())
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
super.visit(name, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitEnum(String name, String descriptor, String value) {
|
|
||||||
super.visitEnum(name, descriptor, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
AnnotationVisitor visitAnnotation(String name, String descriptor) {
|
|
||||||
return new KotlinAnnotationVisitor(super.visitAnnotation(name, descriptor), project)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
AnnotationVisitor visitArray(String name) {
|
|
||||||
return new KotlinAnnotationVisitor(super.visitArray(name), project)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitEnd() {
|
|
||||||
super.visitEnd()
|
|
||||||
}
|
|
||||||
|
|
||||||
String getKotlinVersion() {
|
|
||||||
return project.plugins.findPlugin("org.jetbrains.kotlin.jvm").kotlinPluginVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
String getKotlinVersionEscape() {
|
|
||||||
return getKotlinVersion().replaceAll("[._-]", "")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
package io.izzel.taboolib.gradle
|
|
||||||
|
|
||||||
import org.gradle.api.Project
|
|
||||||
import org.objectweb.asm.AnnotationVisitor
|
|
||||||
import org.objectweb.asm.Opcodes
|
|
||||||
|
|
||||||
class KotlinMetaAnnotationVisitor extends AnnotationVisitor {
|
|
||||||
|
|
||||||
Project project
|
|
||||||
|
|
||||||
KotlinMetaAnnotationVisitor(AnnotationVisitor annotationVisitor, project) {
|
|
||||||
super(Opcodes.ASM7, annotationVisitor)
|
|
||||||
this.project = project
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visit(String name, Object value) {
|
|
||||||
if (value instanceof String) {
|
|
||||||
super.visit(name, value.replace("taboolib", "${project.group.replace('.', '/')}/taboolib"))
|
|
||||||
} else {
|
|
||||||
super.visit(name, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
AnnotationVisitor visitArray(String name) {
|
|
||||||
return new KotlinMetaAnnotationVisitor(super.visitArray(name), project)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
package io.izzel.taboolib.gradle
|
|
||||||
|
|
||||||
import groovy.transform.EqualsAndHashCode
|
|
||||||
import groovy.transform.TupleConstructor
|
|
||||||
|
|
||||||
@TupleConstructor
|
|
||||||
@EqualsAndHashCode
|
|
||||||
class MethodVisit {
|
|
||||||
|
|
||||||
String owner
|
|
||||||
String name
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String toString() {
|
|
||||||
return owner.substring(owner.lastIndexOf("/") + 1) + "." + name + "()"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package io.izzel.taboolib.gradle
|
package io.izzel.taboolib.gradle
|
||||||
|
|
||||||
import groovy.transform.ToString
|
import groovy.transform.ToString
|
||||||
import io.izzel.taboolib.gradle.description.Platforms
|
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.tasks.Input
|
||||||
|
|
@ -18,7 +17,6 @@ import java.util.jar.JarEntry
|
||||||
import java.util.jar.JarFile
|
import java.util.jar.JarFile
|
||||||
import java.util.jar.JarOutputStream
|
import java.util.jar.JarOutputStream
|
||||||
import java.util.stream.Collectors
|
import java.util.stream.Collectors
|
||||||
import java.util.zip.ZipException
|
|
||||||
|
|
||||||
@ToString
|
@ToString
|
||||||
class RelocateJar extends DefaultTask {
|
class RelocateJar extends DefaultTask {
|
||||||
|
|
@ -41,96 +39,39 @@ class RelocateJar extends DefaultTask {
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
def relocate() {
|
def relocate() {
|
||||||
// 缓存
|
|
||||||
def optimize = []
|
|
||||||
def isolated = new TreeMap<String, List<String>>()
|
def isolated = new TreeMap<String, List<String>>()
|
||||||
def methodVisits = new TreeMap<String, Set<MethodVisit>>()
|
|
||||||
|
|
||||||
// 配置
|
|
||||||
def mapping = relocations.collectEntries { [(it.key.replace('.', '/')), it.value.replace('.', '/')] }
|
def mapping = relocations.collectEntries { [(it.key.replace('.', '/')), it.value.replace('.', '/')] }
|
||||||
def remapper = new RelocateRemapper(relocations, mapping as Map<String, String>)
|
def remapper = new RelocateRemapper(relocations, mapping as Map<String, String>)
|
||||||
|
|
||||||
// 文件
|
|
||||||
def index = inJar.name.lastIndexOf('.')
|
def index = inJar.name.lastIndexOf('.')
|
||||||
def name = inJar.name.substring(0, index) + (classifier == null ? "" : "-" + classifier) + inJar.name.substring(index)
|
def name = inJar.name.substring(0, index) + (classifier == null ? "" : "-" + classifier) + inJar.name.substring(index)
|
||||||
def outJar = new File(inJar.getParentFile(), name)
|
def outJar = new File(inJar.getParentFile(), name)
|
||||||
def tempOut1 = File.createTempFile(name, ".jar")
|
def tempOut1 = File.createTempFile(name, ".jar")
|
||||||
|
|
||||||
// 第一次工作
|
|
||||||
new JarOutputStream(new FileOutputStream(tempOut1)).withCloseable { out ->
|
new JarOutputStream(new FileOutputStream(tempOut1)).withCloseable { out ->
|
||||||
int n
|
int n
|
||||||
def buf = new byte[32768]
|
def buf = new byte[32768]
|
||||||
new JarFile(inJar).withCloseable { jarFile ->
|
new JarFile(inJar).withCloseable { jarFile ->
|
||||||
jarFile.entries().each { JarEntry jarEntry ->
|
jarFile.entries().each { def jarEntry ->
|
||||||
def path = jarEntry.name
|
|
||||||
// 忽略用户定义的文件
|
|
||||||
if (tabooExt.exclude.stream().any { String e -> path.startsWith(e) }) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 忽略模块文件
|
|
||||||
if (path.endsWith(".kotlin_module")) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 忽略优化指示文件
|
|
||||||
if (path.startsWith("META-INF/tf") && path.endsWith(".json")) {
|
|
||||||
optimize.add(Bridge.newOptimizeFileReader(project, jarFile.getInputStream(jarEntry)))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 忽略 Kotlin 依赖
|
|
||||||
def options = tabooExt.options
|
|
||||||
if (path == "taboolib/common/env/KotlinEnv.class" && options.contains("skip-kotlin")) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 忽略依赖加载部分代码
|
|
||||||
if (path.startsWith("taboolib/common/env") && options.contains("skip-env")) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 忽略 common 模块打包的第三方库
|
|
||||||
if (path.startsWith("taboolib/library/asm") || path.startsWith("taboolib/library/jarrelocator")) {
|
|
||||||
if (options.contains("skip-env") || options.contains("skip-env-relocate")) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
jarFile.getInputStream(jarEntry).withCloseable {
|
jarFile.getInputStream(jarEntry).withCloseable {
|
||||||
if (path.endsWith(".class")) {
|
if (jarEntry.name.endsWith(".class")) {
|
||||||
def reader = new ClassReader(it)
|
def reader = new ClassReader(it)
|
||||||
def writer = new ClassWriter(0)
|
def writer = new ClassWriter(0)
|
||||||
def visitor = new TabooLibClassVisitor(writer, project)
|
def visitor = new TabooLibClassVisitor(writer, project)
|
||||||
def rem = new ClassRemapper(visitor, remapper)
|
def rem = new ClassRemapper(visitor, remapper)
|
||||||
remapper.remapper = rem
|
remapper.remapper = rem
|
||||||
reader.accept(rem, 0)
|
reader.accept(rem, 0)
|
||||||
// 提取孤立类
|
|
||||||
isolated.putAll(visitor.isolated)
|
isolated.putAll(visitor.isolated)
|
||||||
// 提取方法访问记录
|
out.putNextEntry(new JarEntry(remapper.map(jarEntry.name)))
|
||||||
methodVisits.put(relocate(project, jarEntry.name), visitor.methodVisits)
|
|
||||||
// 写回文件
|
|
||||||
// 拦截报错防止文件名称重复导致编译终止
|
|
||||||
try {
|
|
||||||
out.putNextEntry(new JarEntry(remapper.map(path)))
|
|
||||||
} catch (ZipException zipException) {
|
|
||||||
println(zipException)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
out.write(writer.toByteArray())
|
out.write(writer.toByteArray())
|
||||||
} else {
|
} else {
|
||||||
try {
|
out.putNextEntry(new JarEntry(remapper.map(jarEntry.name)))
|
||||||
out.putNextEntry(new JarEntry(remapper.map(path)))
|
|
||||||
} catch (ZipException ex) {
|
|
||||||
println(ex)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
while ((n = it.read(buf)) != -1) {
|
while ((n = it.read(buf)) != -1) {
|
||||||
out.write(buf, 0, n)
|
out.write(buf, 0, n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 数据整理
|
|
||||||
// 类 -> 谁正在使用
|
|
||||||
def use = new TreeMap<String, Set<String>>()
|
def use = new TreeMap<String, Set<String>>()
|
||||||
remapper.use.each {
|
remapper.use.each {
|
||||||
it.value.each { e ->
|
it.value.each { e ->
|
||||||
|
|
@ -139,19 +80,11 @@ class RelocateJar extends DefaultTask {
|
||||||
use.computeIfAbsent(key) { new HashSet() }.add(value)
|
use.computeIfAbsent(key) { new HashSet() }.add(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
def visits = methodVisits[methodVisits.keySet().first()]
|
|
||||||
if (visits != null) {
|
|
||||||
visits.each {
|
|
||||||
println(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
def transfer = new TreeMap()
|
def transfer = new TreeMap()
|
||||||
isolated.each {
|
isolated.each {
|
||||||
transfer[relocate(project, it.key)] = it.value.stream().map { i -> relocate(project, i) }.collect(Collectors.toList())
|
transfer[relocate(project, it.key)] = it.value.stream().map { i -> relocate(project, i) }.collect(Collectors.toList())
|
||||||
}
|
}
|
||||||
isolated = transfer
|
isolated = transfer
|
||||||
|
|
||||||
// 第二次工作
|
|
||||||
def tempOut2 = File.createTempFile(name, ".jar")
|
def tempOut2 = File.createTempFile(name, ".jar")
|
||||||
new JarOutputStream(new FileOutputStream(tempOut2)).withCloseable { out ->
|
new JarOutputStream(new FileOutputStream(tempOut2)).withCloseable { out ->
|
||||||
int n
|
int n
|
||||||
|
|
@ -159,16 +92,14 @@ class RelocateJar extends DefaultTask {
|
||||||
def del = new HashSet()
|
def del = new HashSet()
|
||||||
def exclude = new HashSet()
|
def exclude = new HashSet()
|
||||||
new JarFile(tempOut1).withCloseable { jarFile ->
|
new JarFile(tempOut1).withCloseable { jarFile ->
|
||||||
jarFile.entries().each { JarEntry jarEntry ->
|
jarFile.entries().each { def jarEntry ->
|
||||||
if (optimize.any { it.exclude(jarEntry.name, use) }) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
jarFile.getInputStream(jarEntry).withCloseable {
|
jarFile.getInputStream(jarEntry).withCloseable {
|
||||||
if (jarEntry.name.endsWith(".class")) {
|
if (jarEntry.name.endsWith(".class")) {
|
||||||
def nameWithOutExtension = getNameWithOutExtension(jarEntry.name)
|
def nameWithOutExtension = getNameWithOutExtension(jarEntry.name)
|
||||||
if (use.containsKey(nameWithOutExtension.toString()) && !exclude.contains(nameWithOutExtension)) {
|
if (use.containsKey(nameWithOutExtension.toString()) && !exclude.contains(nameWithOutExtension)) {
|
||||||
exclude.add(nameWithOutExtension)
|
exclude.add(nameWithOutExtension)
|
||||||
if (isIsolated(use, use[nameWithOutExtension], isolated, nameWithOutExtension)) {
|
if (isIsolated(use, use[nameWithOutExtension], isolated, nameWithOutExtension)) {
|
||||||
|
println(" Isolated ${nameWithOutExtension}")
|
||||||
del.add(nameWithOutExtension)
|
del.add(nameWithOutExtension)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -181,11 +112,25 @@ class RelocateJar extends DefaultTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Platforms.values().each {
|
if (tabooExt.modules.contains("platform-bukkit")) {
|
||||||
if (tabooExt.modules.contains(it.module)) {
|
out.putNextEntry(new JarEntry("plugin.yml"))
|
||||||
out.putNextEntry(new JarEntry(it.file))
|
out.write(tabooExt.description.buildBukkitFile(project))
|
||||||
out.write(it.builder.build(tabooExt.des, 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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -210,27 +155,11 @@ class RelocateJar extends DefaultTask {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isIsolated(
|
static boolean isIsolated(Map<String, Set<String>> use, Set<String> refer, Map<String, List<String>> isolated, String nameWithOutExtension) {
|
||||||
Map<String, Set<String>> use,
|
if (isolated.containsKey(nameWithOutExtension)) {
|
||||||
Set<String> refer,
|
return refer.size() <= 1 || refer.stream().allMatch { nameWithOutExtension == it || isolated[nameWithOutExtension].contains(it) || isIsolated(use, use[it], isolated, it) }
|
||||||
Map<String, List<String>> isolated,
|
|
||||||
String name,
|
|
||||||
String exclude = null
|
|
||||||
) {
|
|
||||||
if (isolated.containsKey(name)) {
|
|
||||||
return refer.size() <= 1 || refer.stream()
|
|
||||||
.filter { it != exclude }
|
|
||||||
.allMatch {
|
|
||||||
name == it || isolated[name].contains(it) || isIsolated(use, use[it], isolated, it, name)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "RelocateJar{}";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,6 @@ class RelocateRemapper extends Remapper {
|
||||||
if (remapper != null) {
|
if (remapper != null) {
|
||||||
use.computeIfAbsent(remapper.className) { new HashSet() }.add(internalName)
|
use.computeIfAbsent(remapper.className) { new HashSet() }.add(internalName)
|
||||||
}
|
}
|
||||||
if (internalName.startsWith('kotlin/Metadata')) {
|
|
||||||
return internalName
|
|
||||||
}
|
|
||||||
def match = slash.find { internalName.startsWith(it.key) }
|
def match = slash.find { internalName.startsWith(it.key) }
|
||||||
if (match) {
|
if (match) {
|
||||||
return match.value + internalName.substring(match.key.length())
|
return match.value + internalName.substring(match.key.length())
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,14 @@ package io.izzel.taboolib.gradle
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.objectweb.asm.AnnotationVisitor
|
import org.objectweb.asm.AnnotationVisitor
|
||||||
import org.objectweb.asm.ClassVisitor
|
import org.objectweb.asm.ClassVisitor
|
||||||
import org.objectweb.asm.MethodVisitor
|
|
||||||
import org.objectweb.asm.Opcodes
|
import org.objectweb.asm.Opcodes
|
||||||
|
|
||||||
class TabooLibClassVisitor extends ClassVisitor {
|
class TabooLibClassVisitor extends ClassVisitor {
|
||||||
|
|
||||||
String name
|
String name
|
||||||
|
|
||||||
Project project
|
Project project
|
||||||
|
|
||||||
Map<String, List<String>> isolated = new HashMap()
|
Map<String, List<String>> isolated = new HashMap()
|
||||||
|
|
||||||
Set<MethodVisit> methodVisits = new HashSet<>()
|
|
||||||
|
|
||||||
List<String> annotations = [
|
|
||||||
"Lorg/spongepowered/api/plugin/Plugin;",
|
|
||||||
"Lorg/spongepowered/plugin/jvm/Plugin;",
|
|
||||||
"Lcom/velocitypowered/api/plugin/Plugin;"
|
|
||||||
]
|
|
||||||
|
|
||||||
TabooLibClassVisitor(ClassVisitor classVisitor, Project project) {
|
TabooLibClassVisitor(ClassVisitor classVisitor, Project project) {
|
||||||
super(Opcodes.ASM7, classVisitor);
|
super(Opcodes.ASM7, classVisitor);
|
||||||
this.project = project
|
this.project = project
|
||||||
|
|
@ -33,22 +22,11 @@ class TabooLibClassVisitor extends ClassVisitor {
|
||||||
super.visit(version, access, name, signature, superName, interfaces)
|
super.visit(version, access, name, signature, superName, interfaces)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
|
||||||
return new TabooLibMethodVisitor(super.visitMethod(access, name, descriptor, signature, exceptions), this)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||||
if (descriptor == "Lkotlin/Metadata;") {
|
if (descriptor == "L${project.group.replace('.', '/')}/taboolib/common/Isolated;") {
|
||||||
return new KotlinMetaAnnotationVisitor(super.visitAnnotation(descriptor, visible), project)
|
|
||||||
} else if (descriptor == "L${project.group.replace('.', '/')}/taboolib/common/Isolated;") {
|
|
||||||
return new IsolatedAnnotationVisitor(super.visitAnnotation(descriptor, visible), project, name, this)
|
return new IsolatedAnnotationVisitor(super.visitAnnotation(descriptor, visible), project, name, this)
|
||||||
} else if (descriptor == "L${project.group.replace('.', '/')}/taboolib/common/env/RuntimeDependency;") {
|
} else if (descriptor == "Lorg/spongepowered/api/plugin/Plugin;" || descriptor == "Lcom/velocitypowered/api/plugin/Plugin;") {
|
||||||
return new KotlinAnnotationVisitor(super.visitAnnotation(descriptor, visible), project)
|
|
||||||
} else if (descriptor == "L${project.group.replace('.', '/')}/taboolib/common/env/RuntimeDependencies;") {
|
|
||||||
return new KotlinAnnotationVisitor(super.visitAnnotation(descriptor, visible), project)
|
|
||||||
} else if (descriptor in annotations) {
|
|
||||||
return new PluginAnnotationVisitor(super.visitAnnotation(descriptor, visible), project)
|
return new PluginAnnotationVisitor(super.visitAnnotation(descriptor, visible), project)
|
||||||
} else {
|
} else {
|
||||||
return super.visitAnnotation(descriptor, visible)
|
return super.visitAnnotation(descriptor, visible)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
package io.izzel.taboolib.gradle
|
package io.izzel.taboolib.gradle
|
||||||
|
|
||||||
import groovy.transform.Canonical
|
import groovy.transform.Canonical
|
||||||
import io.izzel.taboolib.gradle.description.Description
|
import org.codehaus.groovy.runtime.DefaultGroovyMethods
|
||||||
import org.gradle.api.Action
|
|
||||||
|
|
||||||
@Canonical
|
@Canonical
|
||||||
class TabooLibExtension {
|
class TabooLibExtension {
|
||||||
|
|
@ -13,31 +12,19 @@ class TabooLibExtension {
|
||||||
|
|
||||||
List<String> modules = []
|
List<String> modules = []
|
||||||
|
|
||||||
List<String> exclude = []
|
Description description = new Description()
|
||||||
|
|
||||||
Description des = new Description()
|
|
||||||
|
|
||||||
Map<String, String> relocation = new LinkedHashMap<>()
|
Map<String, String> relocation = new LinkedHashMap<>()
|
||||||
|
|
||||||
List<String> options = []
|
|
||||||
|
|
||||||
def install(String... name) {
|
def install(String... name) {
|
||||||
name.each { modules += it }
|
name.each { modules += it }
|
||||||
}
|
}
|
||||||
|
|
||||||
def options(String... opt) {
|
|
||||||
opt.each { options += it }
|
|
||||||
}
|
|
||||||
|
|
||||||
def exclude(String match) {
|
|
||||||
exclude += match
|
|
||||||
}
|
|
||||||
|
|
||||||
def relocate(String pre, String post) {
|
def relocate(String pre, String post) {
|
||||||
relocation[pre] = post
|
relocation[pre] = post
|
||||||
}
|
}
|
||||||
|
|
||||||
def description(Action<? super Description> action) {
|
def descriptionFile(@DelegatesTo(Description.class) Closure<Description> closure) {
|
||||||
action.execute(des)
|
DefaultGroovyMethods.with(description, closure)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,183 +0,0 @@
|
||||||
package io.izzel.taboolib.gradle
|
|
||||||
|
|
||||||
|
|
||||||
import groovy.transform.EqualsAndHashCode
|
|
||||||
import groovy.transform.TupleConstructor
|
|
||||||
import org.objectweb.asm.AnnotationVisitor
|
|
||||||
import org.objectweb.asm.Attribute
|
|
||||||
import org.objectweb.asm.Handle
|
|
||||||
import org.objectweb.asm.Label
|
|
||||||
import org.objectweb.asm.MethodVisitor
|
|
||||||
import org.objectweb.asm.Opcodes
|
|
||||||
import org.objectweb.asm.TypePath
|
|
||||||
|
|
||||||
class TabooLibMethodVisitor extends MethodVisitor {
|
|
||||||
|
|
||||||
TabooLibClassVisitor classVisitor
|
|
||||||
|
|
||||||
TabooLibMethodVisitor(MethodVisitor methodVisitor, TabooLibClassVisitor classVisitor) {
|
|
||||||
super(Opcodes.ASM7, methodVisitor)
|
|
||||||
this.classVisitor = classVisitor
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitParameter(String name, int access) {
|
|
||||||
super.visitParameter(name, access)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
AnnotationVisitor visitAnnotationDefault() {
|
|
||||||
return super.visitAnnotationDefault()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
|
||||||
return super.visitAnnotation(descriptor, visible)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
|
|
||||||
return super.visitTypeAnnotation(typeRef, typePath, descriptor, visible)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitAnnotableParameterCount(int parameterCount, boolean visible) {
|
|
||||||
super.visitAnnotableParameterCount(parameterCount, visible)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
AnnotationVisitor visitParameterAnnotation(int parameter, String descriptor, boolean visible) {
|
|
||||||
return super.visitParameterAnnotation(parameter, descriptor, visible)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitAttribute(Attribute attribute) {
|
|
||||||
super.visitAttribute(attribute)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitCode() {
|
|
||||||
super.visitCode()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitFrame(int type, int numLocal, Object[] local, int numStack, Object[] stack) {
|
|
||||||
super.visitFrame(type, numLocal, local, numStack, stack)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitInsn(int opcode) {
|
|
||||||
super.visitInsn(opcode)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitIntInsn(int opcode, int operand) {
|
|
||||||
super.visitIntInsn(opcode, operand)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitVarInsn(int opcode, int i) {
|
|
||||||
super.visitVarInsn(opcode, i)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitTypeInsn(int opcode, String type) {
|
|
||||||
super.visitTypeInsn(opcode, type)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitFieldInsn(int opcode, String owner, String name, String descriptor) {
|
|
||||||
super.visitFieldInsn(opcode, owner, name, descriptor)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitMethodInsn(int opcode, String owner, String name, String descriptor) {
|
|
||||||
super.visitMethodInsn(opcode, owner, name, descriptor)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
|
|
||||||
classVisitor.methodVisits.add(new MethodVisit(owner, name))
|
|
||||||
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitInvokeDynamicInsn(String name, String descriptor, Handle bootstrapMethodHandle, Object... bootstrapMethodArguments) {
|
|
||||||
super.visitInvokeDynamicInsn(name, descriptor, bootstrapMethodHandle, bootstrapMethodArguments)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitJumpInsn(int opcode, Label label) {
|
|
||||||
super.visitJumpInsn(opcode, label)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitLabel(Label label) {
|
|
||||||
super.visitLabel(label)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitLdcInsn(Object value) {
|
|
||||||
super.visitLdcInsn(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitIincInsn(int i, int increment) {
|
|
||||||
super.visitIincInsn(i, increment)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitTableSwitchInsn(int min, int max, Label dflt, Label... labels) {
|
|
||||||
super.visitTableSwitchInsn(min, max, dflt, labels)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) {
|
|
||||||
super.visitLookupSwitchInsn(dflt, keys, labels)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitMultiANewArrayInsn(String descriptor, int numDimensions) {
|
|
||||||
super.visitMultiANewArrayInsn(descriptor, numDimensions)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
AnnotationVisitor visitInsnAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
|
|
||||||
return super.visitInsnAnnotation(typeRef, typePath, descriptor, visible)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitTryCatchBlock(Label start, Label end, Label handler, String type) {
|
|
||||||
super.visitTryCatchBlock(start, end, handler, type)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
AnnotationVisitor visitTryCatchAnnotation(int typeRef, TypePath typePath, String descriptor, boolean visible) {
|
|
||||||
return super.visitTryCatchAnnotation(typeRef, typePath, descriptor, visible)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitLocalVariable(String name, String descriptor, String signature, Label start, Label end, int index) {
|
|
||||||
super.visitLocalVariable(name, descriptor, signature, start, end, index)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String descriptor, boolean visible) {
|
|
||||||
return super.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, descriptor, visible)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitLineNumber(int line, Label start) {
|
|
||||||
super.visitLineNumber(line, start)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitMaxs(int maxStack, int maxLocals) {
|
|
||||||
super.visitMaxs(maxStack, maxLocals)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
void visitEnd() {
|
|
||||||
super.visitEnd()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -12,6 +12,7 @@ class TabooLibPlugin implements Plugin<Project> {
|
||||||
def tabooExt = project.extensions.create('taboolib', TabooLibExtension)
|
def tabooExt = project.extensions.create('taboolib', TabooLibExtension)
|
||||||
def taboo = project.configurations.maybeCreate('taboo')
|
def taboo = project.configurations.maybeCreate('taboo')
|
||||||
def tabooTask = project.tasks.create('tabooRelocateJar', RelocateJar)
|
def tabooTask = project.tasks.create('tabooRelocateJar', RelocateJar)
|
||||||
|
|
||||||
project.afterEvaluate {
|
project.afterEvaluate {
|
||||||
project.configurations.compileClasspath.extendsFrom(taboo)
|
project.configurations.compileClasspath.extendsFrom(taboo)
|
||||||
// subprojects
|
// subprojects
|
||||||
|
|
@ -22,7 +23,6 @@ class TabooLibPlugin implements Plugin<Project> {
|
||||||
project.tasks.jar.configure { Jar task ->
|
project.tasks.jar.configure { Jar task ->
|
||||||
task.from(taboo.collect { it.isDirectory() ? it : project.zipTree(it) })
|
task.from(taboo.collect { it.isDirectory() ? it : project.zipTree(it) })
|
||||||
}
|
}
|
||||||
def kv = project.plugins.findPlugin("org.jetbrains.kotlin.jvm").kotlinPluginVersion.replaceAll("[._-]", "")
|
|
||||||
def jarTask = project.tasks.jar as Jar
|
def jarTask = project.tasks.jar as Jar
|
||||||
tabooTask.configure { RelocateJar task ->
|
tabooTask.configure { RelocateJar task ->
|
||||||
task.tabooExt = tabooExt
|
task.tabooExt = tabooExt
|
||||||
|
|
@ -31,9 +31,6 @@ class TabooLibPlugin implements Plugin<Project> {
|
||||||
task.relocations = tabooExt.relocation
|
task.relocations = tabooExt.relocation
|
||||||
task.classifier = tabooExt.classifier
|
task.classifier = tabooExt.classifier
|
||||||
task.relocations['taboolib'] = project.group.toString() + '.taboolib'
|
task.relocations['taboolib'] = project.group.toString() + '.taboolib'
|
||||||
if (!tabooExt.options.contains("skip-kotlin") && !tabooExt.options.contains("skip-kotlin-relocate")) {
|
|
||||||
task.relocations['kotlin.'] = 'kotlin' + kv + '.'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
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<String> 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<String> 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<String> body, data, key) {
|
|
||||||
if (data instanceof List<String>) {
|
|
||||||
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<String>) {
|
|
||||||
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<String> 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
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 }.join(', ')
|
|
||||||
write(body, con, 'author')
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
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 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')
|
|
||||||
return bytes(info)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
package io.izzel.taboolib.gradle.description
|
|
||||||
|
|
||||||
class Contributors {
|
|
||||||
|
|
||||||
List<Contributor> 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
||||||
package io.izzel.taboolib.gradle.description
|
|
||||||
|
|
||||||
class Dependencies {
|
|
||||||
|
|
||||||
List<Dependency> 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
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(Action<? super Contributors> action) {
|
|
||||||
action.execute(con)
|
|
||||||
}
|
|
||||||
|
|
||||||
def dependencies(Action<? super Dependencies> action) {
|
|
||||||
action.execute(dep)
|
|
||||||
}
|
|
||||||
|
|
||||||
def links(Action<? super Links> action) {
|
|
||||||
action.execute(lin)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
package io.izzel.taboolib.gradle.description
|
|
||||||
|
|
||||||
class Links {
|
|
||||||
|
|
||||||
def links = new HashMap<String, Link>()
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
String toString() {
|
|
||||||
return url
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
package io.izzel.taboolib.gradle.description
|
|
||||||
|
|
||||||
enum Platforms {
|
|
||||||
|
|
||||||
BUKKIT('Bukkit', 'platform-bukkit', 'plugin.yml', new BuilderBukkit()),
|
|
||||||
|
|
||||||
NUKKIT('Nukkit', 'platform-nukkit', 'nukkit.yml', new BuilderNukkit()),
|
|
||||||
|
|
||||||
BUNGEE('Bungee', 'platform-bungee', 'bungee.yml', new BuilderBungee()),
|
|
||||||
|
|
||||||
VELOCITY('Velocity', 'platform-velocity', 'velocity-plugin.json', new BuilderVelocity()),
|
|
||||||
|
|
||||||
SPONGE7('Sponge7', 'platform-sponge-api7', 'mcmod.info', new BuilderSponge7()),
|
|
||||||
|
|
||||||
SPONGE8('Sponge8', 'platform-sponge-api8', 'META-INF/plugins.json', new BuilderSponge8());
|
|
||||||
|
|
||||||
String key
|
|
||||||
String module
|
|
||||||
String file
|
|
||||||
Builder builder
|
|
||||||
|
|
||||||
Platforms(key, module, file, builder) {
|
|
||||||
this.key = key
|
|
||||||
this.module = module
|
|
||||||
this.file = file
|
|
||||||
this.builder = builder
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
package io.izzel.taboolib.gradle;
|
|
||||||
|
|
||||||
import org.gradle.api.Project;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* taboolib-gradle-plugin
|
|
||||||
* io.izzel.taboolib.gradle.KotlinFactory
|
|
||||||
*
|
|
||||||
* @author sky
|
|
||||||
* @since 2021/8/14 1:43 下午
|
|
||||||
*/
|
|
||||||
public class Bridge {
|
|
||||||
|
|
||||||
public static OptimizeFileReader newOptimizeFileReader(Project project, InputStream inputStream) {
|
|
||||||
return new OptimizeFileReader(project, inputStream);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,134 +0,0 @@
|
||||||
package io.izzel.taboolib.gradle
|
|
||||||
|
|
||||||
import com.google.gson.JsonParser
|
|
||||||
import org.gradle.api.Project
|
|
||||||
import java.io.InputStream
|
|
||||||
import java.nio.charset.StandardCharsets
|
|
||||||
|
|
||||||
/**
|
|
||||||
* taboolib-gradle-plugin
|
|
||||||
* io.izzel.taboolib.gradle.OptimizeFileReader
|
|
||||||
*
|
|
||||||
* @author sky
|
|
||||||
* @since 2021/8/14 1:18 下午
|
|
||||||
*/
|
|
||||||
class OptimizeFileReader(project: Project, input: InputStream) {
|
|
||||||
|
|
||||||
val optimize = ArrayList<Optimize>()
|
|
||||||
val group = ArrayList<Group>()
|
|
||||||
val exclude = ArrayList<String>()
|
|
||||||
|
|
||||||
init {
|
|
||||||
try {
|
|
||||||
val jsonSource = input.readBytes().toString(StandardCharsets.UTF_8)
|
|
||||||
val json = JsonParser.parseString(jsonSource).asJsonObject
|
|
||||||
if (json.has("optimize")) {
|
|
||||||
json.getAsJsonArray("optimize").forEach { ele ->
|
|
||||||
optimize += Optimize(
|
|
||||||
relocate(project, ele.asJsonObject["class"].asString),
|
|
||||||
Optimize.Type.valueOf(ele.asJsonObject["type"].asString)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (json.has("group")) {
|
|
||||||
json.getAsJsonArray("group").forEach { ele ->
|
|
||||||
var depend: Group.Depend? = null
|
|
||||||
if (ele.asJsonObject.has("depend")) {
|
|
||||||
depend = Group.Depend(
|
|
||||||
ele.asJsonObject["depend"].asJsonObject["name"].asJsonArray.map { relocate(project, it.asString) },
|
|
||||||
ele.asJsonObject["depend"].asJsonObject["exclude"].asJsonArray.map { relocate(project, it.asString) }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
group += Group(
|
|
||||||
ele.asJsonObject["check"].asJsonArray.map { relocate(project, it.asString) },
|
|
||||||
ele.asJsonObject["member"].asJsonArray.map { relocate(project, it.asString) },
|
|
||||||
ele.asJsonObject["exclude"]?.asJsonArray?.map { relocate(project, it.asString) }?.toList() ?: emptyList(),
|
|
||||||
depend,
|
|
||||||
Group.Mode.valueOf(ele.asJsonObject["mode"].asString)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (json.has("exclude")) {
|
|
||||||
exclude += json.getAsJsonArray("exclude").map { relocate(project, it.asString) }
|
|
||||||
}
|
|
||||||
} catch (ex: Throwable) {
|
|
||||||
ex.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun relocate(project: Project, name: String): String {
|
|
||||||
return if (name.startsWith("taboolib")) {
|
|
||||||
project.group.toString().replace('.', '/') + '/' + name.replace('.', '/')
|
|
||||||
} else {
|
|
||||||
name.replace('.', '/')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun exclude(name: String, use: Map<String, Set<String>>): Boolean {
|
|
||||||
if (exclude.any { name.startsWith(it) }) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if (group.any { it.exclude(name, use) }) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
class Optimize(val path: String, val type: Type) {
|
|
||||||
|
|
||||||
enum class Type {
|
|
||||||
|
|
||||||
METHOD
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Group(check: List<String>, member: List<String>, exclude: List<String>, val depend: Depend? = null, val mode: Mode) {
|
|
||||||
|
|
||||||
val check = check.platformFlatten()
|
|
||||||
|
|
||||||
val member = member.platformFlatten()
|
|
||||||
|
|
||||||
val exclude = exclude.platformFlatten()
|
|
||||||
|
|
||||||
class Depend(name: List<String>, exclude: List<String>) {
|
|
||||||
|
|
||||||
val name = name.platformFlatten()
|
|
||||||
|
|
||||||
val exclude = exclude.platformFlatten()
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class Mode {
|
|
||||||
|
|
||||||
REMOVE
|
|
||||||
}
|
|
||||||
|
|
||||||
fun exclude(name: String, use: Map<String, Set<String>>): Boolean {
|
|
||||||
if (member.any { name.startsWith(it) }) {
|
|
||||||
if (depend != null) {
|
|
||||||
val fail = depend.name.any { n ->
|
|
||||||
val set = use[n]?.toMutableList() ?: ArrayList()
|
|
||||||
set.remove(n)
|
|
||||||
set.removeAll(depend.exclude)
|
|
||||||
set.isNotEmpty()
|
|
||||||
}
|
|
||||||
if (fail) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (s in check) {
|
|
||||||
val set = use[s]?.toMutableList() ?: ArrayList()
|
|
||||||
set.remove(s)
|
|
||||||
set.removeAll(check)
|
|
||||||
set.removeAll(member)
|
|
||||||
set.removeAll(exclude)
|
|
||||||
if (set.isNotEmpty()) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
package io.izzel.taboolib.gradle
|
|
||||||
|
|
||||||
val platforms = listOf("Bukkit", "Nukkit", "Bungee", "Sponge7", "Sponge8", "Velocity")
|
|
||||||
|
|
||||||
fun List<String>.platformFlatten(): List<String> {
|
|
||||||
return flatMap {
|
|
||||||
if (it.contains("{platform}")) {
|
|
||||||
platforms.map { p -> it.replace("{platform}", p) }
|
|
||||||
} else {
|
|
||||||
listOf(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue