1.4
This commit is contained in:
parent
33349bcb71
commit
7e76f33f13
|
|
@ -1,11 +1,12 @@
|
|||
plugins {
|
||||
id 'groovy'
|
||||
id 'maven-publish'
|
||||
id 'java-gradle-plugin'
|
||||
id 'com.gradle.plugin-publish' version '0.12.0'
|
||||
}
|
||||
|
||||
group 'io.izzel.taboolib'
|
||||
version '1.3'
|
||||
version '1.4'
|
||||
|
||||
configurations {
|
||||
embed
|
||||
|
|
@ -43,4 +44,4 @@ gradlePlugin {
|
|||
implementationClass = 'io.izzel.taboolib.gradle.TabooLibPlugin'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,6 @@ 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
|
||||
|
|
@ -49,7 +48,8 @@ class RelocateJar extends DefaultTask {
|
|||
project.logger.info("Relocating " + jarEntry.name)
|
||||
def reader = new ClassReader(it)
|
||||
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.write(writer.toByteArray())
|
||||
} 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
|
||||
class TabooLibExtension {
|
||||
|
||||
String tabooLibVersion = '5.+'
|
||||
String version = '6.0.0'
|
||||
|
||||
String loaderVersion = '2.+'
|
||||
String classifier = "all"
|
||||
|
||||
String classifier = 'all'
|
||||
|
||||
boolean builtin = true
|
||||
List<String> modules = new ArrayList<>();
|
||||
|
||||
Map<String, String> relocation = new LinkedHashMap<>()
|
||||
|
||||
def install(String... name) {
|
||||
name.each { modules += it }
|
||||
}
|
||||
|
||||
def relocate(String pre, String post) {
|
||||
this.relocation[pre] = post
|
||||
relocation[pre] = post
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,38 +8,28 @@ class TabooLibPlugin implements Plugin<Project> {
|
|||
|
||||
@Override
|
||||
void apply(Project project) {
|
||||
project.repositories.maven { url "http://repo.ptms.ink/repository/codemc-nms/" }
|
||||
project.repositories.maven { url "http://repo.ptms.ink/repository/maven-releases/" }
|
||||
project.repositories.maven { url URI("https://repo2s.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)
|
||||
tabooTask.project = project
|
||||
|
||||
project.afterEvaluate {
|
||||
project.configurations.compileClasspath.extendsFrom(taboo)
|
||||
project.configurations.compileClasspath.dependencies.add(project.dependencies.create("io.izzel.taboolib:TabooLib:${tabooExt.tabooLibVersion}:all"))
|
||||
if (tabooExt.builtin) {
|
||||
taboo.dependencies.add(project.dependencies.create("io.izzel.taboolib:TabooLibLoader:${tabooExt.loaderVersion}:all"))
|
||||
// subprojects
|
||||
tabooExt.modules.each {
|
||||
project.configurations.compileClasspath.dependencies.add(project.dependencies.create("io.izzel:taboolib:${tabooExt.version}:${it}"))
|
||||
}
|
||||
|
||||
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 jarTask = project.tasks.jar as Jar
|
||||
tabooTask.configure { RelocateJar task ->
|
||||
task.inJar = task.inJar ?: jarTask.archivePath
|
||||
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)
|
||||
}
|
||||
project.tasks.jar.finalizedBy(tabooTask)
|
||||
project.tasks.jar.configure { Jar task ->
|
||||
task.from(taboo.collect { it.isDirectory() ? it : project.zipTree(it) })
|
||||
}
|
||||
def jarTask = project.tasks.jar as Jar
|
||||
tabooTask.configure { RelocateJar task ->
|
||||
task.inJar = task.inJar ?: jarTask.archivePath
|
||||
task.relocations = tabooExt.relocation
|
||||
task.classifier = tabooExt.classifier
|
||||
task.relocations['taboolib'] = task.relocations['taboolib'] ?: project.group.toString() + '.taboolib'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue