From 12e5d4e25b06dd1772636ffa438544cb6191e223 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Wed, 5 Dec 2018 18:16:05 +0300 Subject: [PATCH] IDEA-203656 Up-to-date build script can be wrongly treated as changed --- .../ExternalSystemProjectsWatcherImpl.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/autoimport/ExternalSystemProjectsWatcherImpl.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/autoimport/ExternalSystemProjectsWatcherImpl.java index b26772c1d5d7..a93e70665373 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/autoimport/ExternalSystemProjectsWatcherImpl.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/autoimport/ExternalSystemProjectsWatcherImpl.java @@ -163,7 +163,7 @@ public class ExternalSystemProjectsWatcherImpl extends ExternalSystemTaskNotific myRefreshRequestsQueue.activate(); DocumentListener myDocumentListener = new DocumentListener() { - private final Map myChangedDocuments = new THashMap<>(); + private final Map> 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 copy; + final Map> 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); } } })