From 785470975f84b18fa94db428150827a5f7252255 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 20 Nov 2012 17:55:44 +0400 Subject: [PATCH] update changed resources immediately inside IDEA process to speed up update on frame deactivation (IDEA-95060) [rev by Jeka] --- .../compiler/server/BuildManager.java | 12 ++++++ .../impl/artifacts/ArtifactUtil.java | 14 ++++--- .../impl/ui/actions/PackageFileAction.java | 38 +++-------------- .../impl/ui/actions/PackageFileWorker.java | 42 ++++++++++++++++++- 4 files changed, 65 insertions(+), 41 deletions(-) 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 c02322f40338..a87ed35a85b0 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -312,6 +312,18 @@ public class BuildManager implements ApplicationComponent{ } } + @Nullable + public List getFilesChangedSinceLastCompilation(Project project) { + String projectPath = getProjectPath(project); + synchronized (myProjectDataMap) { + ProjectData data = myProjectDataMap.get(projectPath); + if (data != null && !data.myNeedRescan) { + return new ArrayList(data.myChanged); + } + return null; + } + } + @Nullable private static String getProjectPath(final Project project) { final String url = project.getPresentableUrl(); diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java index 9cde8f07e2df..0a272e82b1ff 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactUtil.java @@ -322,11 +322,13 @@ public class ArtifactUtil { processPackagingElements(artifact, PackagingElementFactoryImpl.EXTRACTED_DIRECTORY_ELEMENT_TYPE, processor, context, processSubstitutions); } - public static Collection> findContainingArtifactsWithOutputPaths(@NotNull final VirtualFile file, @NotNull Project project) { + public static Collection> findContainingArtifactsWithOutputPaths(@NotNull final VirtualFile file, + @NotNull Project project, + final Artifact[] artifacts) { final boolean isResourceFile = CompilerConfiguration.getInstance(project).isResourceFile(file); - final List> artifacts = new ArrayList>(); + final List> result = new ArrayList>(); final PackagingElementResolvingContext context = ArtifactManager.getInstance(project).getResolvingContext(); - for (final Artifact artifact : ArtifactManager.getInstance(project).getArtifacts()) { + for (final Artifact artifact : artifacts) { processPackagingElements(artifact, null, new PackagingElementProcessor>() { @Override public boolean process(@NotNull PackagingElement element, @NotNull PackagingElementPath path) { @@ -340,14 +342,14 @@ public class ArtifactUtil { else { relativePath = VfsUtilCore.getRelativePath(file, root, '/'); } - artifacts.add(Trinity.create(artifact, path, relativePath)); + result.add(Trinity.create(artifact, path, relativePath)); return false; } } else if (isResourceFile && element instanceof ModuleOutputPackagingElement) { final String relativePath = getRelativePathInSources(file, (ModuleOutputPackagingElement)element, context); if (relativePath != null) { - artifacts.add(Trinity.create(artifact, path, relativePath)); + result.add(Trinity.create(artifact, path, relativePath)); return false; } } @@ -355,7 +357,7 @@ public class ArtifactUtil { } }, context, true); } - return artifacts; + return result; } @Nullable diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileAction.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileAction.java index 6d7d62a291c3..f72bd757eab4 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileAction.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileAction.java @@ -3,21 +3,12 @@ */ package com.intellij.packaging.impl.ui.actions; -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationType; -import com.intellij.notification.Notifications; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.PlatformDataKeys; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.application.ReadAction; -import com.intellij.openapi.application.Result; import com.intellij.openapi.compiler.CompilerBundle; import com.intellij.openapi.compiler.CompilerManager; import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; @@ -26,11 +17,11 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.WindowManager; import com.intellij.packaging.artifacts.Artifact; +import com.intellij.packaging.artifacts.ArtifactManager; import com.intellij.packaging.impl.artifacts.ArtifactBySourceFileFinder; import com.intellij.util.text.SyncDateFormat; import org.jetbrains.annotations.NotNull; -import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collection; @@ -90,29 +81,10 @@ public class PackageFileAction extends AnAction { FileDocumentManager.getInstance().saveAllDocuments(); final List files = getFilesToPackage(event, project); - ProgressManager.getInstance().run(new Task.Backgroundable(project, "Packaging Files") { - @Override - public void run(@NotNull ProgressIndicator indicator) { - for (final VirtualFile file : files) { - indicator.checkCanceled(); - new ReadAction() { - protected void run(final Result result) { - try { - PackageFileWorker.packageFile(file, project); - } - catch (IOException e) { - Notifications.Bus.notify( - new Notification("Package File", "Cannot package file", CompilerBundle.message("message.tect.package.file.io.error", e.toString()), - NotificationType.ERROR)); - } - } - }.execute(); - } - ApplicationManager.getApplication().invokeLater(new Runnable() { - public void run() { - setStatusText(project, files); - } - }); + Artifact[] allArtifacts = ArtifactManager.getInstance(project).getArtifacts(); + PackageFileWorker.startPackagingFiles(project, files, allArtifacts, new Runnable() { + public void run() { + setStatusText(project, files); } }); } diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileWorker.java b/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileWorker.java index d92c4f7a7cac..6be07f023bb7 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileWorker.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/ui/actions/PackageFileWorker.java @@ -15,8 +15,18 @@ */ package com.intellij.packaging.impl.ui.actions; +import com.intellij.notification.Notification; +import com.intellij.notification.NotificationType; +import com.intellij.notification.Notifications; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ReadAction; +import com.intellij.openapi.application.Result; +import com.intellij.openapi.compiler.CompilerBundle; import com.intellij.openapi.deployment.DeploymentUtil; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; +import com.intellij.openapi.progress.Task; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Trinity; import com.intellij.openapi.util.io.FileUtil; @@ -54,9 +64,37 @@ public class PackageFileWorker { myRelativeOutputPath = relativeOutputPath; } - public static void packageFile(@NotNull VirtualFile file, @NotNull Project project) throws IOException { + public static void startPackagingFiles(final Project project, final List files, + final Artifact[] artifacts, final Runnable onFinished) { + ProgressManager.getInstance().run(new Task.Backgroundable(project, "Packaging Files") { + @Override + public void run(@NotNull ProgressIndicator indicator) { + try { + for (final VirtualFile file : files) { + indicator.checkCanceled(); + new ReadAction() { + protected void run(final Result result) { + try { + packageFile(file, project, artifacts); + } + catch (IOException e) { + String message = CompilerBundle.message("message.tect.package.file.io.error", e.toString()); + Notifications.Bus.notify(new Notification("Package File", "Cannot package file", message, NotificationType.ERROR)); + } + } + }.execute(); + } + } + finally { + ApplicationManager.getApplication().invokeLater(onFinished); + } + } + }); + } + + public static void packageFile(@NotNull VirtualFile file, @NotNull Project project, final Artifact[] artifacts) throws IOException { LOG.debug("Start packaging file: " + file.getPath()); - final Collection> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project); + final Collection> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project, artifacts); File ioFile = VfsUtil.virtualToIoFile(file); for (Trinity item : items) { final Artifact artifact = item.getFirst();