use of com.intellij.openapi.externalSystem.ExternalSystemAutoImportAware in project intellij-community by JetBrains.
the class ExternalSystemProjectsWatcher method updateWatchedRoots.
private void updateWatchedRoots(boolean isProjectOpen) {
List<String> pathsToWatch = new SmartList<>();
myFilesPointers.clear();
LocalFileSystem.getInstance().removeWatchedRoots(myWatchedRoots);
Map<String, VirtualFilePointer> pointerMap = ContainerUtil.newHashMap();
for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
if (!(manager instanceof ExternalSystemAutoImportAware))
continue;
ExternalSystemAutoImportAware importAware = (ExternalSystemAutoImportAware) manager;
for (ExternalProjectSettings settings : manager.getSettingsProvider().fun(myProject).getLinkedProjectsSettings()) {
List<File> files = importAware.getAffectedExternalProjectFiles(settings.getExternalProjectPath(), myProject);
long timeStamp = 0;
for (File file : files) {
timeStamp += file.lastModified();
}
Map<String, Long> modificationStamps = manager.getLocalSettingsProvider().fun(myProject).getExternalConfigModificationStamps();
if (isProjectOpen && myProject.getUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT) != Boolean.TRUE) {
Long affectedFilesTimestamp = modificationStamps.get(settings.getExternalProjectPath());
affectedFilesTimestamp = affectedFilesTimestamp == null ? -1L : affectedFilesTimestamp;
if (timeStamp != affectedFilesTimestamp.longValue()) {
scheduleUpdate(settings.getExternalProjectPath());
}
} else {
modificationStamps.put(settings.getExternalProjectPath(), timeStamp);
}
for (File file : files) {
if (file == null)
continue;
String path = getNormalizedPath(file);
if (path == null)
continue;
pathsToWatch.add(path);
String url = VfsUtilCore.pathToUrl(path);
VirtualFilePointer pointer = pointerMap.get(url);
if (pointer == null) {
pointer = VirtualFilePointerManager.getInstance().create(url, myChangedDocumentsQueue, null);
pointerMap.put(url, pointer);
// update timestamps based on file crc and local settings
final VirtualFile virtualFile = pointer.getFile();
if (virtualFile != null) {
Long crc = virtualFile.getUserData(CRC_WITHOUT_SPACES_BEFORE_LAST_IMPORT);
if (crc != null) {
modificationStamps.put(path, crc);
}
}
}
myFilesPointers.putValue(pointer, settings.getExternalProjectPath());
}
}
}
myWatchedRoots.addAll(LocalFileSystem.getInstance().addRootsToWatch(pathsToWatch, false));
}
Aggregations