From 2e3a22dfb4f9f209d0720cc27bc8396015eb8820 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 20 Sep 2012 11:01:10 +0400 Subject: [PATCH] filter project files --- .../impl/TranslatingCompilerFilesMonitor.java | 27 ++++++------ .../compiler/server/BuildManager.java | 43 ++++++++++++++++--- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java index 7e18cd6c985b..285b867f57f9 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/TranslatingCompilerFilesMonitor.java @@ -1406,9 +1406,8 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { if (parent != null) { final String oldName = (String)event.getOldValue(); final String root = parent.getPath() + "/" + oldName; - final Set toMark; + final Set toMark = new THashSet(FileUtil.FILE_HASHING_STRATEGY); if (eventFile.isDirectory()) { - toMark = new HashSet(); VfsUtilCore.visitChildrenRecursively(eventFile, new VirtualFileVisitor() { private StringBuilder filePath = new StringBuilder(root); @@ -1421,8 +1420,10 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } else { String childPath = filePath.toString(); - if (child != eventFile) childPath += "/" + child.getName(); - toMark.add(childPath); + if (child != eventFile) { + childPath += "/" + child.getName(); + } + toMark.add(new File(childPath)); } return true; } @@ -1436,7 +1437,7 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { }); } else { - toMark = Collections.singleton(root); + toMark.add(new File(root)); } notifyFilesDeleted(toMark); } @@ -1470,14 +1471,14 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } } - final Set pathsToMark = new HashSet(); + final Set pathsToMark = new THashSet(FileUtil.FILE_HASHING_STRATEGY); processRecursively(eventFile, true, new FileProcessor() { private final TIntArrayList myAssociatedProjectIds = new TIntArrayList(); public void execute(final VirtualFile file) { final String filePath = file.getPath(); - pathsToMark.add(filePath); + pathsToMark.add(new File(filePath)); myAssociatedProjectIds.clear(); try { final OutputFileInfo outputInfo = loadOutputInfo(file); @@ -1562,10 +1563,10 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } private void markDirtyIfSource(final VirtualFile file, final boolean fromMove) { - final Set pathsToMark = new HashSet(); + final Set pathsToMark = new THashSet(FileUtil.FILE_HASHING_STRATEGY); processRecursively(file, false, new FileProcessor() { public void execute(final VirtualFile file) { - pathsToMark.add(file.getPath()); + pathsToMark.add(new File(file.getPath())); final SourceFileInfo srcInfo = file.isValid()? loadSourceInfo(file) : null; if (srcInfo != null) { for (int projectId : srcInfo.getProjectIds().toArray()) { @@ -1600,7 +1601,7 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } private void processNewFile(final VirtualFile file, final boolean notifyServer) { - final Set pathsToMark = notifyServer ? new HashSet() : Collections.emptySet(); + final Set pathsToMark = notifyServer ? new THashSet(FileUtil.FILE_HASHING_STRATEGY) : Collections.emptySet(); ApplicationManager.getApplication().runReadAction(new Runnable() { // need read action to ensure that the project was not disposed during the iteration over the project list public void run() { @@ -1616,7 +1617,7 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { processRecursively(file, false, new FileProcessor() { public void execute(final VirtualFile file) { if (notifyServer) { - pathsToMark.add(file.getPath()); + pathsToMark.add(new File(file.getPath())); } if (!projectSuspended && isCompilable(file)) { loadInfoAndAddSourceForRecompilation(projectId, file); @@ -1651,13 +1652,13 @@ public class TranslatingCompilerFilesMonitor implements ApplicationComponent { } } - private static void notifyFilesChanged(Collection paths) { + private static void notifyFilesChanged(Collection paths) { if (!paths.isEmpty()) { BuildManager.getInstance().notifyFilesChanged(paths); } } - private static void notifyFilesDeleted(Collection paths) { + private static void notifyFilesDeleted(Collection paths) { if (!paths.isEmpty()) { BuildManager.getInstance().notifyFilesDeleted(paths); } diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index 95f3e1f688d1..0f066f9bc1c5 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -61,6 +61,7 @@ import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.util.Alarm; +import com.intellij.util.Function; import com.intellij.util.concurrency.SequentialTaskExecutor; import com.intellij.util.messages.MessageBusConnection; import com.intellij.util.net.NetUtils; @@ -111,6 +112,23 @@ public class BuildManager implements ApplicationComponent{ private static final String DEFAULT_LOGGER_CONFIG = "defaultLogConfig.xml"; private static final int MAKE_TRIGGER_DELAY = 3 * 1000 /*3 seconds*/; private final boolean IS_UNIT_TEST_MODE; + private static final String IWS_EXTENSION = ".iws"; + private static final String IPR_EXTENSION = ".ipr"; + private static final String IDEA_PROJECT_DIR_PATTERN = "/.idea/"; + private static final Function PATH_FILTER = + SystemInfo.isFileSystemCaseSensitive? + new Function() { + @Override + public Boolean fun(String s) { + return !(s.contains(IDEA_PROJECT_DIR_PATTERN) || s.endsWith(IWS_EXTENSION) || s.endsWith(IPR_EXTENSION)); + } + } : + new Function() { + @Override + public Boolean fun(String s) { + return !(StringUtil.endsWithIgnoreCase(s, IWS_EXTENSION) || StringUtil.endsWithIgnoreCase(s, IPR_EXTENSION) || StringUtil.containsIgnoreCase(s, IDEA_PROJECT_DIR_PATTERN)); + } + }; private final File mySystemDirectory; private final ProjectManager myProjectManager; @@ -217,35 +235,46 @@ public class BuildManager implements ApplicationComponent{ return ApplicationManager.getApplication().getComponent(BuildManager.class); } - public void notifyFilesChanged(final Collection paths) { + public void notifyFilesChanged(final Collection paths) { doNotify(paths, false); } - public void notifyFilesDeleted(Collection paths) { + public void notifyFilesDeleted(Collection paths) { doNotify(paths, true); } - private void doNotify(final Collection paths, final boolean notifyDeletion) { + private void doNotify(final Collection paths, final boolean notifyDeletion) { // ensure events processed in the order they arrived myRequestsProcessor.submit(new Runnable() { + @Override public void run() { + final List filtered = new ArrayList(paths.size()); + for (File file : paths) { + final String path = FileUtil.toSystemIndependentName(file.getPath()); + if (PATH_FILTER.fun(path)) { + filtered.add(path); + } + } + if (filtered.isEmpty()) { + return; + } synchronized (myProjectDataMap) { if (IS_UNIT_TEST_MODE) { if (notifyDeletion) { - LOG.info("Registering deleted paths: " + paths); + LOG.info("Registering deleted paths: " + filtered); } else { - LOG.info("Registering changed paths: " + paths); + LOG.info("Registering changed paths: " + filtered); } } for (Map.Entry entry : myProjectDataMap.entrySet()) { final ProjectData data = entry.getValue(); if (notifyDeletion) { - data.addDeleted(paths); + data.addDeleted(filtered); } else { - data.addChanged(paths); + data.addChanged(filtered); } final RequestFuture future = myBuildsInProgress.get(entry.getKey()); if (future != null && !future.isCancelled() && !future.isDone()) {