Compare commits

..

23 Commits
1.9 ... master

Author SHA1 Message Date
坏黑 be620a1247 1.27 Fix website 2021-09-13 23:14:19 +08:00
坏黑 b7d5a97452 1.26 2021-08-25 16:19:52 +08:00
坏黑 ce8fe9c4bf 1.26 2021-08-25 16:19:20 +08:00
坏黑 8596bcae2c 1.25 2021-08-23 16:42:16 +08:00
坏黑 9dfb9d1876 1.24 2021-08-23 14:26:01 +08:00
坏黑 9c88efae69 Merge branch 'master' of https://github.com/TabooLib/taboolib-gradle-plugin
# Conflicts:
#	build.gradle
2021-08-23 14:11:32 +08:00
坏黑 43fc609549 1.23 2021-08-23 14:10:09 +08:00
坏黑 07512c45d9
Update build.gradle 2021-08-19 17:43:03 +08:00
坏黑 2a93a9e3d5
Merge pull request #7 from Itsusinn/master
build: update asm version
2021-08-19 17:42:48 +08:00
坏黑 3360b596d5
Update build.gradle 2021-08-19 17:40:53 +08:00
坏黑 8633b8e40d 1.20 2021-08-19 17:14:08 +08:00
坏黑 49751521f8 1.19 2021-08-19 16:06:03 +08:00
itsusinn 329f659f41
build: update asm version
support java bytecode version 16,17,18
2021-08-19 09:12:24 +08:00
坏黑 b53a0d68d2 1.18 2021-08-16 22:37:07 +08:00
坏黑 ec7038c311 1.17 2021-08-15 21:17:37 +08:00
坏黑 4d2bbc8054 1.16 2021-08-15 03:57:11 +08:00
坏黑 578b820dfe 1.14 2021-08-02 15:49:38 +08:00
坏黑 943f2679f9 1.13 2021-08-02 15:15:27 +08:00
坏黑 aefa846d3c
Merge pull request #5 from Itsusinn/master
fix(RelocateJar): ZipException due to duplicate files
2021-07-29 20:51:37 +08:00
坏黑 2340a7d726 1.12 2021-07-29 20:13:29 +08:00
坏黑 651feab7e7 1.11 2021-07-29 20:04:15 +08:00
itsusinn 47fa2ddc0a
fix(RelocateJar): ZipException due to duplicate files 2021-07-29 17:59:31 +08:00
sky a3445b4482 1.10 2021-07-27 16:48:31 +08:00
19 changed files with 565 additions and 39 deletions

View File

@ -3,10 +3,13 @@ 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.9' version '1.27'
configurations { configurations {
embed embed
@ -21,9 +24,10 @@ 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:8.0.1' embed 'org.ow2.asm:asm:9.2'
embed 'org.ow2.asm:asm-commons:8.0.1' embed 'org.ow2.asm:asm-commons:9.2'
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 {
@ -53,4 +57,16 @@ publishing {
url = file("/Users/sky/Desktop/repo") url = file("/Users/sky/Desktop/repo")
} }
} }
} }
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip distributionUrl=https://skymc.oss-cn-shanghai.aliyuncs.com/files/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@ -50,6 +50,6 @@ class KotlinAnnotationVisitor extends AnnotationVisitor {
} }
String getKotlinVersionEscape() { String getKotlinVersionEscape() {
return getKotlinVersion().replaceAll("[.-]", "_") return getKotlinVersion().replaceAll("[._-]", "")
} }
} }

View File

@ -0,0 +1,29 @@
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)
}
}

View File

@ -0,0 +1,17 @@
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 + "()"
}
}

View File

@ -18,6 +18,7 @@ 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 {
@ -40,39 +41,96 @@ 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 { def jarEntry -> 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.getInputStream(jarEntry).withCloseable { jarFile.getInputStream(jarEntry).withCloseable {
if (jarEntry.name.endsWith(".class")) { if (path.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 {
out.putNextEntry(new JarEntry(remapper.map(jarEntry.name))) try {
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 ->
@ -81,11 +139,19 @@ 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
@ -93,14 +159,16 @@ 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 { def jarEntry -> jarFile.entries().each { JarEntry 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)
} }
} }
@ -142,11 +210,27 @@ class RelocateJar extends DefaultTask {
} }
} }
static boolean isIsolated(Map<String, Set<String>> use, Set<String> refer, Map<String, List<String>> isolated, String nameWithOutExtension) { static boolean isIsolated(
if (isolated.containsKey(nameWithOutExtension)) { Map<String, Set<String>> use,
return refer.size() <= 1 || refer.stream().allMatch { nameWithOutExtension == it || isolated[nameWithOutExtension].contains(it) || isIsolated(use, use[it], isolated, it) } Set<String> refer,
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{}";
}
} }

View File

@ -29,6 +29,9 @@ 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())

View File

@ -3,14 +3,19 @@ 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 = [ List<String> annotations = [
"Lorg/spongepowered/api/plugin/Plugin;", "Lorg/spongepowered/api/plugin/Plugin;",
"Lorg/spongepowered/plugin/jvm/Plugin;", "Lorg/spongepowered/plugin/jvm/Plugin;",
@ -28,9 +33,16 @@ 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 == "L${project.group.replace('.', '/')}/taboolib/common/Isolated;") { if (descriptor == "Lkotlin/Metadata;") {
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 == "L${project.group.replace('.', '/')}/taboolib/common/env/RuntimeDependency;") {
return new KotlinAnnotationVisitor(super.visitAnnotation(descriptor, visible), project) return new KotlinAnnotationVisitor(super.visitAnnotation(descriptor, visible), project)

View File

@ -13,20 +13,31 @@ class TabooLibExtension {
List<String> modules = [] List<String> modules = []
List<String> exclude = []
Description des = 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(closure) { def description(Action<? super Description> action) {
closure.delegate = des action.execute(des)
closure()
} }
} }

View File

@ -0,0 +1,183 @@
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()
}
}

View File

@ -22,7 +22,7 @@ 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 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
@ -30,8 +30,10 @@ class TabooLibPlugin implements Plugin<Project> {
task.inJar = task.inJar ?: jarTask.archivePath task.inJar = task.inJar ?: jarTask.archivePath
task.relocations = tabooExt.relocation task.relocations = tabooExt.relocation
task.classifier = tabooExt.classifier task.classifier = tabooExt.classifier
task.relocations['kotlin'] = 'taboolib.library.kotlin_' + kv
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 + '.'
}
} }
} }
} }

View File

@ -13,8 +13,8 @@ class BuilderBungee extends Builder {
write(body, description.lin.links['homepage'], 'website') write(body, description.lin.links['homepage'], 'website')
writeLine(body) writeLine(body)
// authors // authors
def con = description.con.contributors.collect { it.name } def con = description.con.contributors.collect { it.name }.join(', ')
writeList(body, con, 'authors') write(body, con, 'author')
writeLine(body) writeLine(body)
// dependency // dependency
writeList(body, description.dep.dependencies writeList(body, description.dep.dependencies

View File

@ -8,7 +8,6 @@ class BuilderVelocity extends Builder {
@Override @Override
byte[] build(Description description, Project project) { byte[] build(Description description, Project project) {
def json = new JsonArray()
def info = new JsonObject() def info = new JsonObject()
info.addProperty('id', project.name.toLowerCase()) info.addProperty('id', project.name.toLowerCase())
info.addProperty('name', project.name) info.addProperty('name', project.name)
@ -21,7 +20,6 @@ class BuilderVelocity extends Builder {
writeList(info, description.dep.dependencies writeList(info, description.dep.dependencies
.findAll { it.with == null || it.with.equalsIgnoreCase('velocity') } .findAll { it.with == null || it.with.equalsIgnoreCase('velocity') }
.collect { it.name }, 'dependencies') .collect { it.name }, 'dependencies')
json.add(info) return bytes(info)
return bytes(json)
} }
} }

View File

@ -48,14 +48,12 @@ class Description {
nukkitNodes['prefix'] = prefix nukkitNodes['prefix'] = prefix
} }
def contributors(closure) { def contributors(Action<? super Contributors> action) {
closure.delegate = con action.execute(con)
closure()
} }
def dependencies(closure) { def dependencies(Action<? super Dependencies> action) {
closure.delegate = dep action.execute(dep)
closure()
} }
def links(Action<? super Links> action) { def links(Action<? super Links> action) {

View File

@ -23,5 +23,10 @@ class Links {
this.url = url this.url = url
return this return this
} }
@Override
String toString() {
return url
}
} }
} }

View File

@ -2,23 +2,25 @@ package io.izzel.taboolib.gradle.description
enum Platforms { enum Platforms {
BUKKIT('platform-bukkit', 'plugin.yml', new BuilderBukkit()), BUKKIT('Bukkit', 'platform-bukkit', 'plugin.yml', new BuilderBukkit()),
NUKKIT('platform-nukkit', 'nukkit.yml', new BuilderNukkit()), NUKKIT('Nukkit', 'platform-nukkit', 'nukkit.yml', new BuilderNukkit()),
BUNGEE('platform-bungee', 'bungee.yml', new BuilderBungee()), BUNGEE('Bungee', 'platform-bungee', 'bungee.yml', new BuilderBungee()),
VELOCITY('platform-velocity', 'velocity-plugin.json', new BuilderVelocity()), VELOCITY('Velocity', 'platform-velocity', 'velocity-plugin.json', new BuilderVelocity()),
SPONGE7('platform-sponge-api7', 'mcmod.info', new BuilderSponge7()), SPONGE7('Sponge7', 'platform-sponge-api7', 'mcmod.info', new BuilderSponge7()),
SPONGE8('platform-sponge-api8', 'META-INF/plugins.json', new BuilderSponge8()); SPONGE8('Sponge8', 'platform-sponge-api8', 'META-INF/plugins.json', new BuilderSponge8());
String key
String module String module
String file String file
Builder builder Builder builder
Platforms(module, file, builder) { Platforms(key, module, file, builder) {
this.key = key
this.module = module this.module = module
this.file = file this.file = file
this.builder = builder this.builder = builder

View File

@ -0,0 +1,19 @@
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);
}
}

View File

@ -0,0 +1,134 @@
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
}
}
}
}

View File

@ -0,0 +1,13 @@
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)
}
}
}