mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-61921 Changing Gant/Gradle jars externally makes IDEA produce exceptions until restart
This commit is contained in:
@@ -31,18 +31,44 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class NonClasspathClassFinder extends PsiElementFinder {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.NonClasspathClassFinder");
|
||||
private final AtomicLong myLastStamp = new AtomicLong();
|
||||
protected final Project myProject;
|
||||
private volatile List<VirtualFile> myCache;
|
||||
|
||||
public NonClasspathClassFinder(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
protected List<VirtualFile> getClassRoots() {
|
||||
List<VirtualFile> cache = myCache;
|
||||
long stamp = PsiManager.getInstance(myProject).getModificationTracker().getModificationCount();
|
||||
if (myLastStamp.get() != stamp) {
|
||||
cache = null;
|
||||
}
|
||||
|
||||
if (cache != null && !cache.isEmpty()) {
|
||||
for (VirtualFile file : cache) {
|
||||
if (!file.isValid()) {
|
||||
cache = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cache == null) {
|
||||
myCache = cache = calcClassRoots();
|
||||
myLastStamp.set(stamp);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiClass findClass(@NotNull String qualifiedName, @NotNull GlobalSearchScope scope) {
|
||||
final List<VirtualFile> classRoots = getClassRoots();
|
||||
@@ -71,7 +97,7 @@ public abstract class NonClasspathClassFinder extends PsiElementFinder {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected abstract List<VirtualFile> getClassRoots();
|
||||
protected abstract List<VirtualFile> calcClassRoots();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,7 @@ public class GantClassFinder extends NonClasspathClassFinder {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<VirtualFile> getClassRoots() {
|
||||
protected List<VirtualFile> calcClassRoots() {
|
||||
return mySettings.getClassRoots();
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ import org.jetbrains.plugins.groovy.util.SdkHomeSettings;
|
||||
}
|
||||
)
|
||||
public class GantSettings extends SdkHomeSettings {
|
||||
public GantSettings(Project project) {
|
||||
super(project);
|
||||
}
|
||||
|
||||
public static GantSettings getInstance(Project project) {
|
||||
return ServiceManager.getService(project, GantSettings.class);
|
||||
|
||||
@@ -34,7 +34,7 @@ public class GradleClassFinder extends NonClasspathClassFinder {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<VirtualFile> getClassRoots() {
|
||||
protected List<VirtualFile> calcClassRoots() {
|
||||
return mySettings.getClassRoots();
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,9 @@ import org.jetbrains.plugins.groovy.util.SdkHomeSettings;
|
||||
}
|
||||
)
|
||||
public class GradleSettings extends SdkHomeSettings {
|
||||
public GradleSettings(Project project) {
|
||||
super(project);
|
||||
}
|
||||
|
||||
public static GradleSettings getInstance(Project project) {
|
||||
return ServiceManager.getService(project, GradleSettings.class);
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.util;
|
||||
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.components.PersistentStateComponent;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.impl.PsiModificationTrackerImpl;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -32,9 +35,12 @@ import java.util.List;
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class SdkHomeSettings implements PersistentStateComponent<SdkHomeConfigurable.SdkHomeBean> {
|
||||
private final PsiModificationTrackerImpl myTracker;
|
||||
private SdkHomeConfigurable.SdkHomeBean mySdkPath;
|
||||
private volatile VirtualFile mySdkHome;
|
||||
private volatile List<VirtualFile> myClassRoots;
|
||||
|
||||
protected SdkHomeSettings(Project project) {
|
||||
myTracker = (PsiModificationTrackerImpl)PsiManager.getInstance(project).getModificationTracker();
|
||||
}
|
||||
|
||||
public SdkHomeConfigurable.SdkHomeBean getState() {
|
||||
return mySdkPath;
|
||||
@@ -42,16 +48,7 @@ public abstract class SdkHomeSettings implements PersistentStateComponent<SdkHom
|
||||
|
||||
public void loadState(SdkHomeConfigurable.SdkHomeBean state) {
|
||||
mySdkPath = state;
|
||||
myClassRoots = null;
|
||||
mySdkHome = null;
|
||||
}
|
||||
|
||||
private synchronized void calculateRoots() {
|
||||
if (myClassRoots != null) {
|
||||
return;
|
||||
}
|
||||
mySdkHome = calcHome(mySdkPath);
|
||||
myClassRoots = calcRoots(mySdkHome);
|
||||
myTracker.incCounter();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -70,17 +67,11 @@ public abstract class SdkHomeSettings implements PersistentStateComponent<SdkHom
|
||||
|
||||
@Nullable
|
||||
public VirtualFile getSdkHome() {
|
||||
if (myClassRoots == null) {
|
||||
calculateRoots();
|
||||
}
|
||||
return mySdkHome;
|
||||
return calcHome(mySdkPath);
|
||||
}
|
||||
|
||||
public List<VirtualFile> getClassRoots() {
|
||||
if (myClassRoots == null) {
|
||||
calculateRoots();
|
||||
}
|
||||
return myClassRoots;
|
||||
return calcRoots(getSdkHome());
|
||||
}
|
||||
|
||||
private static List<VirtualFile> calcRoots(@Nullable VirtualFile home) {
|
||||
|
||||
Reference in New Issue
Block a user