mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
project reloading synchronization + additional logging
This commit is contained in:
+36
-15
@@ -95,7 +95,7 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
|
||||
|
||||
private final Map<VirtualFile, byte[]> mySavedCopies = new HashMap<VirtualFile, byte[]>();
|
||||
private final TObjectLongHashMap<VirtualFile> mySavedTimestamps = new TObjectLongHashMap<VirtualFile>();
|
||||
private final HashMap<Project, List<Pair<VirtualFile, StateStorage>>> myChangedProjectFiles = new HashMap<Project, List<Pair<VirtualFile, StateStorage>>>();
|
||||
private final Map<Project, List<Pair<VirtualFile, StateStorage>>> myChangedProjectFiles = new HashMap<Project, List<Pair<VirtualFile, StateStorage>>>();
|
||||
private final Alarm myChangedFilesAlarm = new Alarm();
|
||||
private final List<Pair<VirtualFile, StateStorage>> myChangedApplicationFiles = new ArrayList<Pair<VirtualFile, StateStorage>>();
|
||||
private volatile int myReloadBlockCount = 0;
|
||||
@@ -574,8 +574,17 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
|
||||
}
|
||||
|
||||
private void askToReloadProjectIfConfigFilesChangedExternally() {
|
||||
if (!myChangedProjectFiles.isEmpty() && myReloadBlockCount == 0) {
|
||||
Set<Project> projects = myChangedProjectFiles.keySet();
|
||||
LOG.info("[STORAGE] trying to reload project while myReloadBlockCount = " + myReloadBlockCount);
|
||||
if (myReloadBlockCount == 0) {
|
||||
Set<Project> projects;
|
||||
|
||||
synchronized (myChangedProjectFiles) {
|
||||
if (myChangedProjectFiles.isEmpty()) return;
|
||||
projects = new HashSet<Project>(myChangedProjectFiles.keySet());
|
||||
}
|
||||
|
||||
LOG.info("[STORAGE] iterate over opened project & reload");
|
||||
|
||||
List<Project> projectsToReload = new ArrayList<Project>();
|
||||
|
||||
for (Project project : projects) {
|
||||
@@ -587,8 +596,6 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
|
||||
for (final Project projectToReload : projectsToReload) {
|
||||
reloadProjectImpl(projectToReload, false, false);
|
||||
}
|
||||
|
||||
myChangedProjectFiles.clear();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -651,7 +658,18 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
|
||||
|
||||
private boolean shouldReloadProject(final Project project) {
|
||||
if (project.isDisposed()) return false;
|
||||
final HashSet<Pair<VirtualFile, StateStorage>> causes = new HashSet<Pair<VirtualFile, StateStorage>>(myChangedProjectFiles.get(project));
|
||||
final HashSet<Pair<VirtualFile, StateStorage>> causes = new HashSet<Pair<VirtualFile, StateStorage>>();
|
||||
|
||||
LOG.info("[STORAGE] Should reload project now");
|
||||
|
||||
synchronized (myChangedProjectFiles) {
|
||||
final List<Pair<VirtualFile, StateStorage>> changes = myChangedProjectFiles.remove(project);
|
||||
if (changes != null) {
|
||||
causes.addAll(changes);
|
||||
}
|
||||
|
||||
if (causes.isEmpty()) return false;
|
||||
}
|
||||
|
||||
final boolean[] reloadOk = {false};
|
||||
|
||||
@@ -707,14 +725,17 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
|
||||
}
|
||||
|
||||
public void unblockReloadingProjectOnExternalChanges() {
|
||||
myReloadBlockCount--;
|
||||
scheduleReloadApplicationAndProject();
|
||||
if (--myReloadBlockCount == 0) scheduleReloadApplicationAndProject();
|
||||
}
|
||||
|
||||
private void scheduleReloadApplicationAndProject() {
|
||||
LOG.info("[STORAGE] Scheduling reload with myReloadBlockCount = " + myReloadBlockCount);
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
LOG.info("[STORAGE] trying reloading application and should reload project");
|
||||
if (!tryToReloadApplication()) return;
|
||||
LOG.info("[STORAGE] reloading project");
|
||||
askToReloadProjectIfConfigFilesChangedExternally();
|
||||
}
|
||||
|
||||
@@ -747,17 +768,17 @@ public class ProjectManagerImpl extends ProjectManagerEx implements NamedJDOMExt
|
||||
registerProjectToReload(project, file, storage);
|
||||
}
|
||||
|
||||
|
||||
private void registerProjectToReload(final Project project, final VirtualFile cause, final StateStorage storage) {
|
||||
if (project != null) {
|
||||
List<Pair<VirtualFile, StateStorage>> changedProjectFiles = myChangedProjectFiles.get(project);
|
||||
synchronized (myChangedProjectFiles) {
|
||||
List<Pair<VirtualFile, StateStorage>> changedProjectFiles = myChangedProjectFiles.get(project);
|
||||
if (changedProjectFiles == null) {
|
||||
changedProjectFiles = new ArrayList<Pair<VirtualFile, StateStorage>>();
|
||||
myChangedProjectFiles.put(project, changedProjectFiles);
|
||||
}
|
||||
|
||||
if (changedProjectFiles == null) {
|
||||
changedProjectFiles = new ArrayList<Pair<VirtualFile, StateStorage>>();
|
||||
myChangedProjectFiles.put(project, changedProjectFiles);
|
||||
changedProjectFiles.add(new Pair<VirtualFile, StateStorage>(cause, storage));
|
||||
}
|
||||
|
||||
changedProjectFiles.add(new Pair<VirtualFile, StateStorage>(cause, storage));
|
||||
}
|
||||
else {
|
||||
myChangedApplicationFiles.add(new Pair<VirtualFile, StateStorage>(cause, storage));
|
||||
|
||||
Reference in New Issue
Block a user