Simplifying cleanup in gradle plugin after introducing ZipHandle.clearFileAccessorCache method in the platform, minor refactoring
This commit is contained in:
@@ -78,6 +78,11 @@ messages/**)
|
|||||||
public InputStream getInputStream();
|
public InputStream getInputStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# needed for jar cache cleanup in the gradle plugin and compile daemon
|
||||||
|
-keepclassmembers class com.intellij.openapi.vfs.impl.ZipHandler {
|
||||||
|
public static void clearFileAccessorCache();
|
||||||
|
}
|
||||||
|
|
||||||
-keep class jet.** {
|
-keep class jet.** {
|
||||||
public protected *;
|
public protected *;
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-20
@@ -125,32 +125,18 @@ class CompilerServicesCleanup(private var pluginClassLoader: ClassLoader?) {
|
|||||||
val shortName = classFqName.substring(classFqName.lastIndexOf('.') + 1)
|
val shortName = classFqName.substring(classFqName.lastIndexOf('.') + 1)
|
||||||
|
|
||||||
log.kotlinDebug("Looking for $shortName class")
|
log.kotlinDebug("Looking for $shortName class")
|
||||||
val lowMemoryWatcherClass = Class.forName(classFqName, false, pluginClassLoader)
|
val cls = pluginClassLoader!!.loadClass(classFqName)
|
||||||
|
|
||||||
log.kotlinDebug("Looking for $methodName() method")
|
log.kotlinDebug("Looking for $methodName() method")
|
||||||
val shutdownMethod = lowMemoryWatcherClass.getMethod(methodName)
|
val method = cls.getMethod(methodName)
|
||||||
|
|
||||||
log.kotlinDebug("Call $shortName.$methodName()")
|
log.kotlinDebug("Call $shortName.$methodName()")
|
||||||
shutdownMethod.invoke(null)
|
method.invoke(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanJarCache() {
|
private fun cleanJarCache() {
|
||||||
val zipHandlerClass = pluginClassLoader!!.loadClass("com.intellij.openapi.vfs.impl.ZipHandler")
|
log.kotlinDebug("Clean JAR cache")
|
||||||
val privateCacheField = zipHandlerClass.getDeclaredField("ourZipFileFileAccessorCache")
|
callVoidStaticMethod("com.intellij.openapi.vfs.impl.ZipHandler", "clearFileAccessorCache")
|
||||||
privateCacheField.isAccessible = true
|
log.kotlinDebug("JAR cache cleared")
|
||||||
privateCacheField.get(null)?.let {
|
|
||||||
val innerCache = privateCacheField.type.getDeclaredField("myCache")
|
|
||||||
innerCache.isAccessible = true
|
|
||||||
innerCache.get(it)?.let {
|
|
||||||
val clearMethod = innerCache.type.getMethod("clear")
|
|
||||||
if (clearMethod != null) {
|
|
||||||
clearMethod.invoke(it)
|
|
||||||
log.kotlinDebug("successfuly cleared ZipHandler.ourZipFileFileAccessorCache.myCache")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
log.kotlinDebug("unable to access ZipHandler.ourZipFileFileAccessorCache.myCache.clear")
|
|
||||||
}
|
|
||||||
} ?: log.kotlinDebug("unable to access ZipHandler.ourZipFileFileAccessorCache.myCache (${innerCache.get(it)})")
|
|
||||||
} ?: log.kotlinDebug("unable to access ZipHandler.ourZipFileFileAccessorCache (${privateCacheField.get(null)})")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user