This commit is contained in:
坏黑 2021-08-02 15:15:27 +08:00
parent aefa846d3c
commit 943f2679f9
3 changed files with 35 additions and 26 deletions

View File

@ -6,7 +6,7 @@ plugins {
}
group 'io.izzel.taboolib'
version '1.12'
version '1.13'
configurations {
embed

View File

@ -53,32 +53,35 @@ class RelocateJar extends DefaultTask {
def buf = new byte[32768]
new JarFile(inJar).withCloseable { jarFile ->
jarFile.entries().each { def jarEntry ->
jarFile.getInputStream(jarEntry).withCloseable {
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)
try {
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(jarEntry.name)))
} catch(ZipException zipException) {
println(zipException)
return true
}
while ((n = it.read(buf)) != -1) {
out.write(buf, 0, n)
if (tabooExt.exclude.none { String e -> jarEntry.name.matches(e) }) {
jarFile.getInputStream(jarEntry).withCloseable {
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)
try {
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(jarEntry.name)))
} catch(ZipException ex) {
println(ex)
return true
}
while ((n = it.read(buf)) != -1) {
out.write(buf, 0, n)
}
}
null
}
}
}

View File

@ -13,6 +13,8 @@ class TabooLibExtension {
List<String> modules = []
List<String> exclude = []
Description des = new Description()
Map<String, String> relocation = new LinkedHashMap<>()
@ -21,6 +23,10 @@ class TabooLibExtension {
name.each { modules += it }
}
def exclude(String match) {
exclude += match
}
def relocate(String pre, String post) {
relocation[pre] = post
}