mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
clear values cached in StandardFileSystems class when application changes
This commit is contained in:
+14
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package com.intellij.openapi.application;
|
||||
|
||||
import com.intellij.openapi.util.ClearableLazyValue;
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -29,6 +30,7 @@ import java.util.List;
|
||||
public class CachedSingletonsRegistry {
|
||||
private static final Object LOCK = new CachedSingletonsRegistry();
|
||||
private static final List<Class<?>> ourRegisteredClasses = new ArrayList<Class<?>>();
|
||||
private static final List<ClearableLazyValue<?>> ourRegisteredLazyValues = new ArrayList<ClearableLazyValue<?>>();
|
||||
|
||||
private CachedSingletonsRegistry() {}
|
||||
|
||||
@@ -40,6 +42,14 @@ public class CachedSingletonsRegistry {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <T> ClearableLazyValue<T> markLazyValue(@NotNull ClearableLazyValue<T> lazyValue) {
|
||||
synchronized (LOCK) {
|
||||
ourRegisteredLazyValues.add(lazyValue);
|
||||
}
|
||||
return lazyValue;
|
||||
}
|
||||
|
||||
public static void cleanupCachedFields() {
|
||||
synchronized (LOCK) {
|
||||
for (Class<?> aClass : ourRegisteredClasses) {
|
||||
@@ -50,6 +60,9 @@ public class CachedSingletonsRegistry {
|
||||
// Ignore cleanup failed. In some cases we cannot find ourInstance field if idea.jar is scrambled and names of the private fields changed
|
||||
}
|
||||
}
|
||||
for (ClearableLazyValue<?> value : ourRegisteredLazyValues) {
|
||||
value.drop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.intellij.openapi.vfs;
|
||||
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.openapi.application.CachedSingletonsRegistry;
|
||||
import com.intellij.openapi.util.ClearableLazyValue;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -30,21 +31,25 @@ public class StandardFileSystems {
|
||||
public static final String JRT_PROTOCOL = "jrt";
|
||||
public static final String JRT_PROTOCOL_PREFIX = JRT_PROTOCOL + URLUtil.SCHEME_SEPARATOR;
|
||||
|
||||
private static final NotNullLazyValue<VirtualFileSystem> ourLocal = new NotNullLazyValue<VirtualFileSystem>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected VirtualFileSystem compute() {
|
||||
return VirtualFileManager.getInstance().getFileSystem(URLUtil.FILE_PROTOCOL);
|
||||
private static final ClearableLazyValue<VirtualFileSystem> ourLocal = CachedSingletonsRegistry.markLazyValue(
|
||||
new ClearableLazyValue<VirtualFileSystem>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected VirtualFileSystem compute() {
|
||||
return VirtualFileManager.getInstance().getFileSystem(URLUtil.FILE_PROTOCOL);
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
private static final NotNullLazyValue<VirtualFileSystem> ourJar = new NotNullLazyValue<VirtualFileSystem>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected VirtualFileSystem compute() {
|
||||
return VirtualFileManager.getInstance().getFileSystem(JAR_PROTOCOL);
|
||||
private static final ClearableLazyValue<VirtualFileSystem> ourJar = CachedSingletonsRegistry.markLazyValue(
|
||||
new ClearableLazyValue<VirtualFileSystem>() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected VirtualFileSystem compute() {
|
||||
return VirtualFileManager.getInstance().getFileSystem(JAR_PROTOCOL);
|
||||
}
|
||||
}
|
||||
};
|
||||
);
|
||||
|
||||
public static VirtualFileSystem local() {
|
||||
return ourLocal.getValue();
|
||||
|
||||
Reference in New Issue
Block a user