IDEA-203656 Up-to-date build script can be wrongly treated as changed

This commit is contained in:
Vladislav.Soroka
2018-12-05 18:16:19 +03:00
parent 33c0300ace
commit 12e5d4e25b
@@ -163,7 +163,7 @@ public class ExternalSystemProjectsWatcherImpl extends ExternalSystemTaskNotific
myRefreshRequestsQueue.activate();
DocumentListener myDocumentListener = new DocumentListener() {
private final Map<Document, String> myChangedDocuments = new THashMap<>();
private final Map<Document, Pair<String, VirtualFile>> myChangedDocuments = new THashMap<>();
@Override
public void documentChanged(@NotNull DocumentEvent event) {
@@ -174,12 +174,12 @@ public class ExternalSystemProjectsWatcherImpl extends ExternalSystemTaskNotific
if (externalProjectPath == null) return;
synchronized (myChangedDocuments) {
myChangedDocuments.put(doc, externalProjectPath);
myChangedDocuments.put(doc, Pair.create(externalProjectPath, file));
}
myChangedDocumentsQueue.queue(new Update(ExternalSystemProjectsWatcherImpl.this) {
@Override
public void run() {
final Map<Document, String> copy;
final Map<Document, Pair<String, VirtualFile>> copy;
synchronized (myChangedDocuments) {
copy = new THashMap<>(myChangedDocuments);
@@ -187,20 +187,17 @@ public class ExternalSystemProjectsWatcherImpl extends ExternalSystemTaskNotific
}
ExternalSystemUtil.invokeLater(myProject, () -> WriteAction.run(
() -> copy.forEach((document, projectPath) -> {
() -> copy.forEach((document, pair) -> {
PsiDocumentManager.getInstance(myProject).commitDocument(document);
FileDocumentManagerImpl fileDocumentManager = (FileDocumentManagerImpl)FileDocumentManager.getInstance();
fileDocumentManager.saveDocumentAsIs(document);
Long beforeImport = file.getUserData(CRC_WITHOUT_SPACES_BEFORE_LAST_IMPORT);
Long current = file.getUserData(CRC_WITHOUT_SPACES_CURRENT);
Long beforeImport = pair.second.getUserData(CRC_WITHOUT_SPACES_BEFORE_LAST_IMPORT);
Long current = pair.second.getUserData(CRC_WITHOUT_SPACES_CURRENT);
if (current != null && current.equals(beforeImport)) {
VirtualFile virtualFile = fileDocumentManager.getFile(document);
if (virtualFile != null) {
Long newCrc = calculateCrc(virtualFile);
virtualFile.putUserData(CRC_WITHOUT_SPACES_CURRENT, newCrc);
if (!current.equals(newCrc)) {
scheduleUpdate(externalProjectPath, false);
}
Long newCrc = calculateCrc(pair.second);
pair.second.putUserData(CRC_WITHOUT_SPACES_CURRENT, newCrc);
if (!current.equals(newCrc)) {
scheduleUpdate(pair.first, false);
}
}
})