Build: Remove all code from tools-jar-api leaving only declarations

Since method bodies are not required for compilation
strip them out to remove noise between different versions.
This commit is contained in:
Vyacheslav Gerasimov
2020-02-24 00:37:26 +03:00
parent ef169aa12b
commit c75ad13b66
+43 -9
View File
@@ -1,3 +1,11 @@
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
import org.jetbrains.org.objectweb.asm.ClassReader
import org.jetbrains.org.objectweb.asm.ClassReader.SKIP_CODE
import org.jetbrains.org.objectweb.asm.ClassVisitor
import org.jetbrains.org.objectweb.asm.ClassWriter
import org.jetbrains.org.objectweb.asm.Opcodes.*
import java.util.zip.ZipFile
plugins {
base
}
@@ -7,25 +15,48 @@ val toolsJarFile = toolsJarFile(jdkHome = File(JDK_18)) ?: error("Couldn't find
// tools.jar from JDK has different public api on different platforms which makes impossible to reuse caches
// for tasks which depend on it. Since we can't compile against those classes & stay cross-platform anyway,
// we may just exclude them from compile classpath. This should make tools.jar compatible at least within
// one build of JDK for different platforms
// we may just exclude them from compile classpath. Since method bodies are not required for compilation
// strip them out to remove noise between different versions.
val toolsJarStubs by tasks.registering {
inputs.file(toolsJarFile)
val outDir = buildDir.resolve(name)
outputs.dir(outDir)
doLast {
val zipFile = ZipFile(toolsJarFile)
zipFile.stream()
.filter { it.name.endsWith(".class") }
.forEach { zipEntry ->
zipFile.getInputStream(zipEntry).use { entryStream ->
val classReader = ClassReader(entryStream)
val classWriter = ClassWriter( 0)
classReader.accept(object : ClassVisitor(API_VERSION, classWriter) {
}, SKIP_CODE)
val result = File(outDir, zipEntry.name)
result.ensureParentDirsCreated()
result.writeBytes(classWriter.toByteArray())
}
}
}
}
val jar = tasks.register<Jar>("jar") {
dependsOn(toolsJarStubs)
from {
zipTree(toolsJarFile).matching {
fileTree(toolsJarStubs.get().outputs.files.singleFile).matching {
exclude("META-INF/**")
exclude("sun/tools/attach/LinuxAttachProvider.class")
exclude("sun/tools/attach/LinuxVirtualMachine${'$'}SocketInputStream.class")
exclude("sun/tools/attach/LinuxVirtualMachine.class")
exclude("sun/tools/attach/LinuxVirtualMachine*")
exclude("sun/tools/attach/BsdAttachProvider.class")
exclude("sun/tools/attach/BsdVirtualMachine${'$'}SocketInputStream.class")
exclude("sun/tools/attach/BsdVirtualMachine.class")
exclude("sun/tools/attach/BsdVirtualMachine*")
exclude("sun/tools/attach/WindowsAttachProvider.class")
exclude("sun/tools/attach/WindowsVirtualMachine${'$'}SocketInputStream.class")
exclude("sun/tools/attach/WindowsVirtualMachine.class")
exclude("sun/tools/attach/WindowsVirtualMachine*")
// Windows only classes
exclude("com/sun/tools/jdi/SharedMemoryAttachingConnector$1.class")
@@ -37,6 +68,9 @@ val jar = tasks.register<Jar>("jar") {
exclude("com/sun/tools/jdi/SharedMemoryTransportService.class")
exclude("com/sun/tools/jdi/SharedMemoryTransportServiceCapabilities.class")
exclude("com/sun/tools/jdi/SunSDK.class")
// Deprecated class which has differences in api between versions
exclude("com/sun/tools/javadoc/JavaScriptScanner.class")
}
}
}