Compare commits
No commits in common. "master" and "1.13" have entirely different histories.
22
build.gradle
22
build.gradle
|
|
@ -3,13 +3,10 @@ plugins {
|
|||
id 'maven-publish'
|
||||
id 'java-gradle-plugin'
|
||||
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'
|
||||
version '1.27'
|
||||
version '1.13'
|
||||
|
||||
configurations {
|
||||
embed
|
||||
|
|
@ -24,10 +21,9 @@ dependencies {
|
|||
compile 'org.codehaus.groovy:groovy:2.5.13'
|
||||
compile gradleApi()
|
||||
compile localGroovy()
|
||||
embed 'org.ow2.asm:asm:9.2'
|
||||
embed 'org.ow2.asm:asm-commons:9.2'
|
||||
embed 'org.ow2.asm:asm:8.0.1'
|
||||
embed 'org.ow2.asm:asm-commons:8.0.1'
|
||||
embed 'com.google.code.gson:gson:2.8.7'
|
||||
embed 'org.jetbrains.kotlin:kotlin-stdlib'
|
||||
}
|
||||
|
||||
jar {
|
||||
|
|
@ -58,15 +54,3 @@ publishing {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
compileTestKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
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
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
|||
|
|
@ -50,6 +50,6 @@ class KotlinAnnotationVisitor extends AnnotationVisitor {
|
|||
}
|
||||
|
||||
String getKotlinVersionEscape() {
|
||||
return getKotlinVersion().replaceAll("[._-]", "")
|
||||
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 + "()"
|
||||
}
|
||||
}
|
||||
|
|
@ -41,81 +41,39 @@ class RelocateJar extends DefaultTask {
|
|||
|
||||
@TaskAction
|
||||
def relocate() {
|
||||
// 缓存
|
||||
def optimize = []
|
||||
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 remapper = new RelocateRemapper(relocations, mapping as Map<String, String>)
|
||||
|
||||
// 文件
|
||||
def index = inJar.name.lastIndexOf('.')
|
||||
def name = inJar.name.substring(0, index) + (classifier == null ? "" : "-" + classifier) + inJar.name.substring(index)
|
||||
def outJar = new File(inJar.getParentFile(), name)
|
||||
def tempOut1 = File.createTempFile(name, ".jar")
|
||||
|
||||
// 第一次工作
|
||||
new JarOutputStream(new FileOutputStream(tempOut1)).withCloseable { out ->
|
||||
int n
|
||||
def buf = new byte[32768]
|
||||
new JarFile(inJar).withCloseable { jarFile ->
|
||||
jarFile.entries().each { JarEntry 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.entries().each { def jarEntry ->
|
||||
if (tabooExt.exclude.none { String e -> jarEntry.name.matches(e) }) {
|
||||
jarFile.getInputStream(jarEntry).withCloseable {
|
||||
if (path.endsWith(".class")) {
|
||||
if (jarEntry.name.endsWith(".class")) {
|
||||
def reader = new ClassReader(it)
|
||||
def writer = new ClassWriter(0)
|
||||
def visitor = new TabooLibClassVisitor(writer, project)
|
||||
def rem = new ClassRemapper(visitor, remapper)
|
||||
remapper.remapper = rem
|
||||
reader.accept(rem, 0)
|
||||
// 提取孤立类
|
||||
isolated.putAll(visitor.isolated)
|
||||
// 提取方法访问记录
|
||||
methodVisits.put(relocate(project, jarEntry.name), visitor.methodVisits)
|
||||
// 写回文件
|
||||
// 拦截报错防止文件名称重复导致编译终止
|
||||
try {
|
||||
out.putNextEntry(new JarEntry(remapper.map(path)))
|
||||
} catch (ZipException zipException) {
|
||||
out.putNextEntry(new JarEntry(remapper.map(jarEntry.name)))
|
||||
} catch(ZipException zipException) {
|
||||
println(zipException)
|
||||
return true
|
||||
}
|
||||
out.write(writer.toByteArray())
|
||||
} else {
|
||||
try {
|
||||
out.putNextEntry(new JarEntry(remapper.map(path)))
|
||||
} catch (ZipException ex) {
|
||||
out.putNextEntry(new JarEntry(remapper.map(jarEntry.name)))
|
||||
} catch(ZipException ex) {
|
||||
println(ex)
|
||||
return true
|
||||
}
|
||||
|
|
@ -128,9 +86,7 @@ class RelocateJar extends DefaultTask {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 数据整理
|
||||
// 类 -> 谁正在使用
|
||||
}
|
||||
def use = new TreeMap<String, Set<String>>()
|
||||
remapper.use.each {
|
||||
it.value.each { e ->
|
||||
|
|
@ -139,19 +95,11 @@ class RelocateJar extends DefaultTask {
|
|||
use.computeIfAbsent(key) { new HashSet() }.add(value)
|
||||
}
|
||||
}
|
||||
def visits = methodVisits[methodVisits.keySet().first()]
|
||||
if (visits != null) {
|
||||
visits.each {
|
||||
println(it)
|
||||
}
|
||||
}
|
||||
def transfer = new TreeMap()
|
||||
isolated.each {
|
||||
transfer[relocate(project, it.key)] = it.value.stream().map { i -> relocate(project, i) }.collect(Collectors.toList())
|
||||
}
|
||||
isolated = transfer
|
||||
|
||||
// 第二次工作
|
||||
def tempOut2 = File.createTempFile(name, ".jar")
|
||||
new JarOutputStream(new FileOutputStream(tempOut2)).withCloseable { out ->
|
||||
int n
|
||||
|
|
@ -159,16 +107,14 @@ class RelocateJar extends DefaultTask {
|
|||
def del = new HashSet()
|
||||
def exclude = new HashSet()
|
||||
new JarFile(tempOut1).withCloseable { jarFile ->
|
||||
jarFile.entries().each { JarEntry jarEntry ->
|
||||
if (optimize.any { it.exclude(jarEntry.name, use) }) {
|
||||
return
|
||||
}
|
||||
jarFile.entries().each { def jarEntry ->
|
||||
jarFile.getInputStream(jarEntry).withCloseable {
|
||||
if (jarEntry.name.endsWith(".class")) {
|
||||
def nameWithOutExtension = getNameWithOutExtension(jarEntry.name)
|
||||
if (use.containsKey(nameWithOutExtension.toString()) && !exclude.contains(nameWithOutExtension)) {
|
||||
exclude.add(nameWithOutExtension)
|
||||
if (isIsolated(use, use[nameWithOutExtension], isolated, nameWithOutExtension)) {
|
||||
println(" Isolated ${nameWithOutExtension}")
|
||||
del.add(nameWithOutExtension)
|
||||
}
|
||||
}
|
||||
|
|
@ -227,10 +173,4 @@ class RelocateJar extends DefaultTask {
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RelocateJar{}";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,9 +29,6 @@ class RelocateRemapper extends Remapper {
|
|||
if (remapper != null) {
|
||||
use.computeIfAbsent(remapper.className) { new HashSet() }.add(internalName)
|
||||
}
|
||||
if (internalName.startsWith('kotlin/Metadata')) {
|
||||
return internalName
|
||||
}
|
||||
def match = slash.find { internalName.startsWith(it.key) }
|
||||
if (match) {
|
||||
return match.value + internalName.substring(match.key.length())
|
||||
|
|
|
|||
|
|
@ -3,19 +3,14 @@ package io.izzel.taboolib.gradle
|
|||
import org.gradle.api.Project
|
||||
import org.objectweb.asm.AnnotationVisitor
|
||||
import org.objectweb.asm.ClassVisitor
|
||||
import org.objectweb.asm.MethodVisitor
|
||||
import org.objectweb.asm.Opcodes
|
||||
|
||||
class TabooLibClassVisitor extends ClassVisitor {
|
||||
|
||||
String name
|
||||
|
||||
Project project
|
||||
|
||||
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;",
|
||||
|
|
@ -33,16 +28,9 @@ class TabooLibClassVisitor extends ClassVisitor {
|
|||
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
|
||||
AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||
if (descriptor == "Lkotlin/Metadata;") {
|
||||
return new KotlinMetaAnnotationVisitor(super.visitAnnotation(descriptor, visible), project)
|
||||
} else if (descriptor == "L${project.group.replace('.', '/')}/taboolib/common/Isolated;") {
|
||||
if (descriptor == "L${project.group.replace('.', '/')}/taboolib/common/Isolated;") {
|
||||
return new IsolatedAnnotationVisitor(super.visitAnnotation(descriptor, visible), project, name, this)
|
||||
} else if (descriptor == "L${project.group.replace('.', '/')}/taboolib/common/env/RuntimeDependency;") {
|
||||
return new KotlinAnnotationVisitor(super.visitAnnotation(descriptor, visible), project)
|
||||
|
|
|
|||
|
|
@ -19,16 +19,10 @@ class TabooLibExtension {
|
|||
|
||||
Map<String, String> relocation = new LinkedHashMap<>()
|
||||
|
||||
List<String> options = []
|
||||
|
||||
def install(String... name) {
|
||||
name.each { modules += it }
|
||||
}
|
||||
|
||||
def options(String... opt) {
|
||||
opt.each { options += it }
|
||||
}
|
||||
|
||||
def exclude(String match) {
|
||||
exclude += match
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ class TabooLibPlugin implements Plugin<Project> {
|
|||
project.tasks.jar.configure { Jar task ->
|
||||
task.from(taboo.collect { it.isDirectory() ? it : project.zipTree(it) })
|
||||
}
|
||||
def kv = project.plugins.findPlugin("org.jetbrains.kotlin.jvm").kotlinPluginVersion.replaceAll("[._-]", "")
|
||||
def kv = project.plugins.findPlugin("org.jetbrains.kotlin.jvm").kotlinPluginVersion.replaceAll("[.-]", "_")
|
||||
def jarTask = project.tasks.jar as Jar
|
||||
tabooTask.configure { RelocateJar task ->
|
||||
task.tabooExt = tabooExt
|
||||
|
|
@ -30,10 +30,8 @@ class TabooLibPlugin implements Plugin<Project> {
|
|||
task.inJar = task.inJar ?: jarTask.archivePath
|
||||
task.relocations = tabooExt.relocation
|
||||
task.classifier = tabooExt.classifier
|
||||
task.relocations['kotlin'] = 'taboolib.library.kotlin_' + kv
|
||||
task.relocations['taboolib'] = project.group.toString() + '.taboolib'
|
||||
if (!tabooExt.options.contains("skip-kotlin") && !tabooExt.options.contains("skip-kotlin-relocate")) {
|
||||
task.relocations['kotlin.'] = 'kotlin' + kv + '.'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ class BuilderBungee extends Builder {
|
|||
write(body, description.lin.links['homepage'], 'website')
|
||||
writeLine(body)
|
||||
// authors
|
||||
def con = description.con.contributors.collect { it.name }.join(', ')
|
||||
write(body, con, 'author')
|
||||
def con = description.con.contributors.collect { it.name }
|
||||
writeList(body, con, 'authors')
|
||||
writeLine(body)
|
||||
// dependency
|
||||
writeList(body, description.dep.dependencies
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ 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)
|
||||
|
|
@ -20,6 +21,7 @@ class BuilderVelocity extends Builder {
|
|||
writeList(info, description.dep.dependencies
|
||||
.findAll { it.with == null || it.with.equalsIgnoreCase('velocity') }
|
||||
.collect { it.name }, 'dependencies')
|
||||
return bytes(info)
|
||||
json.add(info)
|
||||
return bytes(json)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,10 +23,5 @@ class Links {
|
|||
this.url = url
|
||||
return this
|
||||
}
|
||||
|
||||
@Override
|
||||
String toString() {
|
||||
return url
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,25 +2,23 @@ package io.izzel.taboolib.gradle.description
|
|||
|
||||
enum Platforms {
|
||||
|
||||
BUKKIT('Bukkit', 'platform-bukkit', 'plugin.yml', new BuilderBukkit()),
|
||||
BUKKIT('platform-bukkit', 'plugin.yml', new BuilderBukkit()),
|
||||
|
||||
NUKKIT('Nukkit', 'platform-nukkit', 'nukkit.yml', new BuilderNukkit()),
|
||||
NUKKIT('platform-nukkit', 'nukkit.yml', new BuilderNukkit()),
|
||||
|
||||
BUNGEE('Bungee', 'platform-bungee', 'bungee.yml', new BuilderBungee()),
|
||||
BUNGEE('platform-bungee', 'bungee.yml', new BuilderBungee()),
|
||||
|
||||
VELOCITY('Velocity', 'platform-velocity', 'velocity-plugin.json', new BuilderVelocity()),
|
||||
VELOCITY('platform-velocity', 'velocity-plugin.json', new BuilderVelocity()),
|
||||
|
||||
SPONGE7('Sponge7', 'platform-sponge-api7', 'mcmod.info', new BuilderSponge7()),
|
||||
SPONGE7('platform-sponge-api7', 'mcmod.info', new BuilderSponge7()),
|
||||
|
||||
SPONGE8('Sponge8', 'platform-sponge-api8', 'META-INF/plugins.json', new BuilderSponge8());
|
||||
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
|
||||
Platforms(module, file, builder) {
|
||||
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