From de69e72bcd1fe12d3398aeee65e66b54a76cda24 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 24 Jun 2010 12:07:20 +0400 Subject: [PATCH] 'package file' action executed in a separate thread and some logging added --- .../impl/ui/actions/PackageFileAction.java | 49 ++++++++++++++----- .../impl/ui/actions/PackageFileWorker.java | 10 +++- 2 files changed, 45 insertions(+), 14 deletions(-) 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 4615cc1f191c..186485a8bcaf 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,17 +3,24 @@ */ package com.intellij.packaging.impl.ui.actions; -import com.intellij.CommonBundle; +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; -import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.WindowManager; @@ -76,23 +83,39 @@ public class PackageFileAction extends AnAction { FileDocumentManager.getInstance().saveAllDocuments(); final List files = getFilesToPackage(event, project); - try { - for (VirtualFile file : files) { - PackageFileWorker.packageFile(file, 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); + } + }); } - setStatusText(project, files); - } - catch (IOException e) { - Messages.showErrorDialog(CompilerBundle.message("message.tect.package.file.io.error", e), CommonBundle.getErrorTitle()); - } + }); } private static void setStatusText(Project project, List files) { if (!files.isEmpty()) { - String fileNames = ""; + StringBuilder fileNames = new StringBuilder(); for (VirtualFile file : files) { - if (fileNames.length() != 0) fileNames += ", "; - fileNames+="'"+file.getName()+"'"; + if (fileNames.length() != 0) fileNames.append(", "); + fileNames.append("'").append(file.getName()).append("'"); } String time = DateFormat.getTimeInstance().format(new Date()); final String statusText = CompilerBundle.message("status.text.file.has.been.packaged", files.size(), fileNames, time); 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 764b61bc7050..d92c4f7a7cac 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 @@ -16,6 +16,7 @@ package com.intellij.packaging.impl.ui.actions; import com.intellij.openapi.deployment.DeploymentUtil; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Trinity; import com.intellij.openapi.util.io.FileUtil; @@ -44,6 +45,7 @@ import java.util.List; * @author nik */ public class PackageFileWorker { + private static final Logger LOG = Logger.getInstance("#com.intellij.packaging.impl.ui.actions.PackageFileWorker"); private final File myFile; private final String myRelativeOutputPath; @@ -53,6 +55,7 @@ public class PackageFileWorker { } public static void packageFile(@NotNull VirtualFile file, @NotNull Project project) throws IOException { + LOG.debug("Start packaging file: " + file.getPath()); final Collection> items = ArtifactUtil.findContainingArtifactsWithOutputPaths(file, project); File ioFile = VfsUtil.virtualToIoFile(file); for (Trinity item : items) { @@ -60,6 +63,7 @@ public class PackageFileWorker { final String outputPath = artifact.getOutputPath(); if (!StringUtil.isEmpty(outputPath)) { PackageFileWorker worker = new PackageFileWorker(ioFile, item.getThird()); + LOG.debug(" package to " + outputPath); worker.packageFile(outputPath, item.getSecond().getParents()); } } @@ -76,7 +80,9 @@ public class PackageFileWorker { private void copyFile(String outputPath, List> parents) throws IOException { if (parents.isEmpty()) { - FileUtil.copy(myFile, new File(FileUtil.toSystemDependentName(DeploymentUtil.appendToPath(outputPath, myRelativeOutputPath)))); + final String fullOutputPath = DeploymentUtil.appendToPath(outputPath, myRelativeOutputPath); + LOG.debug(" copying to " + fullOutputPath); + FileUtil.copy(myFile, new File(FileUtil.toSystemDependentName(fullOutputPath))); return; } @@ -94,6 +100,7 @@ public class PackageFileWorker { private void packFile(String archivePath, String pathInArchive, List> parents) throws IOException { final File archiveFile = new File(FileUtil.toSystemDependentName(archivePath)); if (parents.isEmpty()) { + LOG.debug(" adding to archive " + archivePath); JBZipFile file = getOrCreateZipFile(archiveFile); try { final String fullPathInArchive = DeploymentUtil.trimForwardSlashes(DeploymentUtil.appendToPath(pathInArchive, myRelativeOutputPath)); @@ -113,6 +120,7 @@ public class PackageFileWorker { JBZipFile zipFile = getOrCreateZipFile(archiveFile); try { final JBZipEntry entry = zipFile.getOrCreateEntry(nextPathInArchive); + LOG.debug(" extracting to temp file: " + nextPathInArchive + " from " + archivePath); final File tempFile = FileUtil.createTempFile("packageFile" + FileUtil.sanitizeFileName(nextPathInArchive), FileUtil.getExtension(PathUtil.getFileName(nextPathInArchive))); if (entry.getSize() != -1) { FileUtil.writeToFile(tempFile, entry.getData());