Compare commits

..

No commits in common. "master" and "1.0" have entirely different histories.
master ... 1.0

30 changed files with 51 additions and 1407 deletions

3
.gitignore vendored
View File

@ -1,3 +0,0 @@
.gradle
.idea
build

View File

@ -1,15 +1,11 @@
plugins {
id 'groovy'
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.0'
configurations {
embed
@ -17,6 +13,7 @@ configurations {
}
repositories {
maven { url "http://ptms.ink:8081/repository/maven-releases/" }
mavenCentral()
}
@ -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 'com.google.code.gson:gson:2.8.7'
embed 'org.jetbrains.kotlin:kotlin-stdlib'
embed 'org.ow2.asm:asm:8.0.1'
embed 'org.ow2.asm:asm-commons:8.0.1'
embed 'io.izzel.taboolib:TabooLibLoader:2.+:all'
}
jar {
@ -50,23 +46,3 @@ gradlePlugin {
}
}
}
publishing {
repositories {
maven {
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
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

0
gradlew vendored Executable file → Normal file
View File

View File

@ -1,42 +0,0 @@
package io.izzel.taboolib.gradle
import org.gradle.api.Project
import org.objectweb.asm.AnnotationVisitor
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
class IsolatedAnnotationVisitor extends AnnotationVisitor {
String name
Project project
TabooLibClassVisitor parent
IsolatedAnnotationVisitor(AnnotationVisitor annotationVisitor, project, name, parent) {
super(Opcodes.ASM7, annotationVisitor)
this.name = name
this.project = project
this.parent = parent
this.parent.isolated[name] = new ArrayList<>()
}
@Override
AnnotationVisitor visitArray(String name) {
return new IsolatedExcludeAnnotationVisitor(super.visitArray(name), this)
}
class IsolatedExcludeAnnotationVisitor extends AnnotationVisitor {
IsolatedAnnotationVisitor parent
IsolatedExcludeAnnotationVisitor(AnnotationVisitor annotationVisitor, parent) {
super(Opcodes.ASM7, annotationVisitor)
this.parent = parent
}
@Override
void visit(String name, Object value) {
parent.parent.isolated[parent.name] += (value as Type).className
super.visit(name, value)
}
}
}

View File

@ -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("[._-]", "")
}
}

View File

@ -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)
}
}

View File

@ -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 + "()"
}
}

View File

@ -1,48 +0,0 @@
package io.izzel.taboolib.gradle
import org.gradle.api.Project
import org.objectweb.asm.AnnotationVisitor
import org.objectweb.asm.Opcodes
class PluginAnnotationVisitor extends AnnotationVisitor {
Project project
PluginAnnotationVisitor(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("@plugin_id@", project.name.toLowerCase())
.replace("@plugin_name@", project.name)
.replace("@plugin_version@", project.version.toString())
)
} 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 super.visitAnnotation(name, descriptor)
}
@Override
AnnotationVisitor visitArray(String name) {
return super.visitArray(name)
}
@Override
void visitEnd() {
super.visitEnd()
}
}

View File

@ -1,9 +1,7 @@
package io.izzel.taboolib.gradle
import groovy.transform.ToString
import io.izzel.taboolib.gradle.description.Platforms
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Optional
@ -13,12 +11,11 @@ import org.objectweb.asm.ClassWriter
import org.objectweb.asm.commons.ClassRemapper
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.util.jar.JarEntry
import java.util.jar.JarFile
import java.util.jar.JarOutputStream
import java.util.stream.Collectors
import java.util.zip.ZipException
@ToString
class RelocateJar extends DefaultTask {
@ -33,204 +30,38 @@ class RelocateJar extends DefaultTask {
@Input
String classifier
@Input
Project project
@Input
TabooLibExtension tabooExt
@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 ->
def tmpOut = File.createTempFile(name, ".jar")
new JarOutputStream(new FileOutputStream(tmpOut)).withCloseable { out ->
project.logger.info(outJar.getAbsolutePath())
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.getInputStream(jarEntry).withCloseable {
if (path.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) {
println(zipException)
return true
}
out.write(writer.toByteArray())
} else {
try {
out.putNextEntry(new JarEntry(remapper.map(path)))
} catch (ZipException ex) {
println(ex)
return true
}
while ((n = it.read(buf)) != -1) {
out.write(buf, 0, n)
}
}
null
}
}
}
}
//
// -> 使
def use = new TreeMap<String, Set<String>>()
remapper.use.each {
it.value.each { e ->
def key = relocate(project, getNameWithOutExtension(e))
def value = relocate(project, getNameWithOutExtension(it.key))
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
def buf = new byte[32768]
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
}
for (def jarEntry : jarFile.entries()) {
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)) {
del.add(nameWithOutExtension)
}
}
}
if (!del.contains(getNameWithOutExtension(jarEntry.name))) {
out.putNextEntry(new JarEntry(jarEntry.name))
project.logger.info("Relocating " + jarEntry.name)
def reader = new ClassReader(it)
def writer = new ClassWriter(0)
reader.accept(new ClassRemapper(writer, remapper), 0)
out.putNextEntry(new JarEntry(remapper.map(jarEntry.name)))
out.write(writer.toByteArray())
} else {
out.putNextEntry(new JarEntry(remapper.map(jarEntry.name)))
while ((n = it.read(buf)) != -1) {
out.write(buf, 0, n)
}
}
}
}
Platforms.values().each {
if (tabooExt.modules.contains(it.module)) {
out.putNextEntry(new JarEntry(it.file))
out.write(it.builder.build(tabooExt.des, project))
}
}
}
}
Files.copy(tempOut2.toPath(), outJar.toPath(), StandardCopyOption.REPLACE_EXISTING)
}
static String getNameWithOutExtension(name) {
if (name.contains('$')) {
return name.substring(0, name.indexOf('$')).replace('.', '/')
} else if (name.contains('.')) {
return name.substring(0, name.lastIndexOf('.')).replace('.', '/')
} else {
return name.replace('.', '/')
}
}
static String relocate(Project project, String name) {
if (name.startsWith("taboolib")) {
return project.group.toString().replace('.', '/') + '/' + name.replace('.', '/')
} else {
return name.replace('.', '/')
}
}
static boolean isIsolated(
Map<String, Set<String>> use,
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 {
return false
}
}
@Override
public String toString() {
return "RelocateJar{}";
Files.copy(tmpOut.toPath(), outJar.toPath(), StandardCopyOption.REPLACE_EXISTING)
}
}

View File

@ -1,7 +1,6 @@
package io.izzel.taboolib.gradle
import groovy.transform.Canonical
import org.objectweb.asm.commons.ClassRemapper
import org.objectweb.asm.commons.Remapper
@Canonical
@ -9,8 +8,6 @@ class RelocateRemapper extends Remapper {
Map<String, String> dot
Map<String, String> slash
Map<String, Set<String>> use = new TreeMap()
ClassRemapper remapper
@Override
Object mapValue(Object value) {
@ -23,15 +20,8 @@ class RelocateRemapper extends Remapper {
return super.mapValue(value)
}
@SuppressWarnings('GroovyAccessibility')
@Override
String map(String internalName) {
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())

View File

@ -1,62 +0,0 @@
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;",
"Lcom/velocitypowered/api/plugin/Plugin;"
]
TabooLibClassVisitor(ClassVisitor classVisitor, Project project) {
super(Opcodes.ASM7, classVisitor);
this.project = project
}
@Override
void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
this.name = name
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;") {
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)
} 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)
} else {
return super.visitAnnotation(descriptor, visible)
}
}
@Override
void visitEnd() {
super.visitEnd()
}
}

View File

@ -1,43 +1,19 @@
package io.izzel.taboolib.gradle
import groovy.transform.Canonical
import io.izzel.taboolib.gradle.description.Description
import org.gradle.api.Action
@Canonical
class TabooLibExtension {
String version = '6.0.0'
String tabooLibVersion = '5.+'
String classifier = "all"
String loaderVersion = '2.+'
List<String> modules = []
List<String> exclude = []
Description des = new Description()
String classifier = 'all'
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
}
def relocate(String pre, String post) {
relocation[pre] = post
}
def description(Action<? super Description> action) {
action.execute(des)
this.relocation[pre] = post
}
}

View File

@ -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()
}
}

View File

@ -8,31 +8,36 @@ class TabooLibPlugin implements Plugin<Project> {
@Override
void apply(Project project) {
project.repositories.maven { url project.uri("https://repo2s.ptms.ink/repository/maven-releases/") }
project.repositories.maven { url "http://repo.ptms.ink/repository/codemc-nms/" }
project.repositories.maven { url "http://repo.ptms.ink/repository/maven-releases/" }
def tabooExt = project.extensions.create('taboolib', TabooLibExtension)
def taboo = project.configurations.maybeCreate('taboo')
def tabooTask = project.tasks.create('tabooRelocateJar', RelocateJar)
project.afterEvaluate {
project.configurations.compileClasspath.extendsFrom(taboo)
// subprojects
tabooExt.modules.each {
project.configurations.taboo.dependencies.add(project.dependencies.create("io.izzel:taboolib:${tabooExt.version}:${it}"))
}
def tabooTask = project.tasks.create('tabooRelocateJar', RelocateJar)
project.afterEvaluate {
println(project.group.toString())
project.configurations.compileClasspath.dependencies.add(project.dependencies.create("io.izzel.taboolib:TabooLib:${tabooExt.tabooLibVersion}:all"))
taboo.dependencies.add(project.dependencies.create("io.izzel.taboolib:TabooLibLoader:${tabooExt.loaderVersion}:all"))
def shadowPresent = project.plugins.hasPlugin('com.github.johnrengelman.shadow')
if (!shadowPresent) {
project.tasks.jar.finalizedBy(tabooTask)
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 jarTask = project.tasks.jar as Jar
tabooTask.configure { RelocateJar task ->
task.tabooExt = tabooExt
task.project = project
task.inJar = task.inJar ?: jarTask.archivePath
task.relocations = tabooExt.relocation
task.classifier = tabooExt.classifier
task.relocations['taboolib'] = project.group.toString() + '.taboolib'
if (!tabooExt.options.contains("skip-kotlin") && !tabooExt.options.contains("skip-kotlin-relocate")) {
task.relocations['kotlin.'] = 'kotlin' + kv + '.'
task.relocations['io.izzel.taboolib.loader'] = task.relocations['io.izzel.taboolib.loader'] ?: project.group.toString() + '.boot'
task.relocations['org.bstats.bukkit'] = task.relocations['org.bstats.bukkit'] ?: project.group.toString() + '.metrics'
}
} else {
def shadowJar = project.tasks.getByName('shadowJar')
if (shadowJar) {
shadowJar.configurations.add(taboo)
}
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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
}
}
}

View File

@ -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
}
}
}

View File

@ -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)
}
}

View File

@ -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
}
}
}

View File

@ -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
}
}

View File

@ -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);
}
}

View File

@ -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
}
}
}
}

View File

@ -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)
}
}
}