commit
81f9cfdc42
|
|
@ -1,11 +1,12 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'groovy'
|
id 'groovy'
|
||||||
|
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'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'io.izzel.taboolib'
|
group 'io.izzel.taboolib'
|
||||||
version '1.3'
|
version '1.4'
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
embed
|
embed
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import org.objectweb.asm.ClassWriter
|
||||||
import org.objectweb.asm.commons.ClassRemapper
|
import org.objectweb.asm.commons.ClassRemapper
|
||||||
|
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.Paths
|
|
||||||
import java.nio.file.StandardCopyOption
|
import java.nio.file.StandardCopyOption
|
||||||
import java.util.jar.JarEntry
|
import java.util.jar.JarEntry
|
||||||
import java.util.jar.JarFile
|
import java.util.jar.JarFile
|
||||||
|
|
@ -49,7 +48,8 @@ class RelocateJar extends DefaultTask {
|
||||||
project.logger.info("Relocating " + jarEntry.name)
|
project.logger.info("Relocating " + jarEntry.name)
|
||||||
def reader = new ClassReader(it)
|
def reader = new ClassReader(it)
|
||||||
def writer = new ClassWriter(0)
|
def writer = new ClassWriter(0)
|
||||||
reader.accept(new ClassRemapper(writer, remapper), 0)
|
def visitor = new TabooLibClassVisitor(writer)
|
||||||
|
reader.accept(new ClassRemapper(visitor, remapper), 0)
|
||||||
out.putNextEntry(new JarEntry(remapper.map(jarEntry.name)))
|
out.putNextEntry(new JarEntry(remapper.map(jarEntry.name)))
|
||||||
out.write(writer.toByteArray())
|
out.write(writer.toByteArray())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
package io.izzel.taboolib.gradle
|
||||||
|
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.objectweb.asm.AnnotationVisitor
|
||||||
|
import org.objectweb.asm.Opcodes
|
||||||
|
|
||||||
|
class SpongeAnnotationVisitor extends AnnotationVisitor {
|
||||||
|
|
||||||
|
Project project
|
||||||
|
|
||||||
|
SpongeAnnotationVisitor(AnnotationVisitor annotationVisitor) {
|
||||||
|
super(Opcodes.ASM5, annotationVisitor)
|
||||||
|
}
|
||||||
|
|
||||||
|
@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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
package io.izzel.taboolib.gradle
|
||||||
|
|
||||||
|
import org.objectweb.asm.AnnotationVisitor
|
||||||
|
import org.objectweb.asm.ClassVisitor
|
||||||
|
import org.objectweb.asm.Opcodes
|
||||||
|
|
||||||
|
class TabooLibClassVisitor extends ClassVisitor {
|
||||||
|
|
||||||
|
TabooLibClassVisitor(ClassVisitor classVisitor) {
|
||||||
|
super(Opcodes.ASM5, classVisitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||||
|
if (descriptor == "Lorg/spongepowered/api/plugin/Plugin;") {
|
||||||
|
return new SpongeAnnotationVisitor(super.visitAnnotation(descriptor, visible))
|
||||||
|
} else {
|
||||||
|
return super.visitAnnotation(descriptor, visible)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,17 +5,19 @@ import groovy.transform.Canonical
|
||||||
@Canonical
|
@Canonical
|
||||||
class TabooLibExtension {
|
class TabooLibExtension {
|
||||||
|
|
||||||
String tabooLibVersion = '5.+'
|
String version = '6.0.0'
|
||||||
|
|
||||||
String loaderVersion = '2.+'
|
String classifier = "all"
|
||||||
|
|
||||||
String classifier = 'all'
|
List<String> modules = new ArrayList<>();
|
||||||
|
|
||||||
boolean builtin = true
|
|
||||||
|
|
||||||
Map<String, String> relocation = new LinkedHashMap<>()
|
Map<String, String> relocation = new LinkedHashMap<>()
|
||||||
|
|
||||||
|
def install(String... name) {
|
||||||
|
name.each { modules += it }
|
||||||
|
}
|
||||||
|
|
||||||
def relocate(String pre, String post) {
|
def relocate(String pre, String post) {
|
||||||
this.relocation[pre] = post
|
relocation[pre] = post
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,38 +8,28 @@ class TabooLibPlugin implements Plugin<Project> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void apply(Project project) {
|
void apply(Project project) {
|
||||||
project.repositories.maven { url "http://repo.ptms.ink/repository/codemc-nms/" }
|
project.repositories.maven { url URI("https://repo2s.ptms.ink/repository/maven-releases/") }
|
||||||
project.repositories.maven { url "http://repo.ptms.ink/repository/maven-releases/" }
|
|
||||||
def tabooExt = project.extensions.create('taboolib', TabooLibExtension)
|
def tabooExt = project.extensions.create('taboolib', TabooLibExtension)
|
||||||
def taboo = project.configurations.maybeCreate('taboo')
|
def taboo = project.configurations.maybeCreate('taboo')
|
||||||
def tabooTask = project.tasks.create('tabooRelocateJar', RelocateJar)
|
def tabooTask = project.tasks.create('tabooRelocateJar', RelocateJar)
|
||||||
|
tabooTask.project = project
|
||||||
|
|
||||||
project.afterEvaluate {
|
project.afterEvaluate {
|
||||||
project.configurations.compileClasspath.extendsFrom(taboo)
|
project.configurations.compileClasspath.extendsFrom(taboo)
|
||||||
project.configurations.compileClasspath.dependencies.add(project.dependencies.create("io.izzel.taboolib:TabooLib:${tabooExt.tabooLibVersion}:all"))
|
// subprojects
|
||||||
if (tabooExt.builtin) {
|
tabooExt.modules.each {
|
||||||
taboo.dependencies.add(project.dependencies.create("io.izzel.taboolib:TabooLibLoader:${tabooExt.loaderVersion}:all"))
|
project.configurations.compileClasspath.dependencies.add(project.dependencies.create("io.izzel:taboolib:${tabooExt.version}:${it}"))
|
||||||
}
|
}
|
||||||
|
project.tasks.jar.finalizedBy(tabooTask)
|
||||||
def shadowPresent = project.plugins.hasPlugin('com.github.johnrengelman.shadow')
|
project.tasks.jar.configure { Jar task ->
|
||||||
if (!shadowPresent) {
|
task.from(taboo.collect { it.isDirectory() ? it : project.zipTree(it) })
|
||||||
project.tasks.jar.finalizedBy(tabooTask)
|
}
|
||||||
project.tasks.jar.configure { Jar task ->
|
def jarTask = project.tasks.jar as Jar
|
||||||
task.from(taboo.collect { it.isDirectory() ? it : project.zipTree(it) })
|
tabooTask.configure { RelocateJar task ->
|
||||||
}
|
task.inJar = task.inJar ?: jarTask.archivePath
|
||||||
def jarTask = project.tasks.jar as Jar
|
task.relocations = tabooExt.relocation
|
||||||
tabooTask.configure { RelocateJar task ->
|
task.classifier = tabooExt.classifier
|
||||||
task.inJar = task.inJar ?: jarTask.archivePath
|
task.relocations['taboolib'] = task.relocations['taboolib'] ?: project.group.toString() + '.taboolib'
|
||||||
task.relocations = tabooExt.relocation
|
|
||||||
task.classifier = tabooExt.classifier
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue