From 7ed003ebbddfbb8f17a9c0d25813737ec07407a6 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Wed, 18 Jan 2012 21:42:37 +0100 Subject: [PATCH] compile-server: use async delete when cleaning output dirs --- .../jps/incremental/IncProjectBuilder.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java index 23ec5ee1e5c3..adf1c6b1cf9c 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java @@ -161,17 +161,17 @@ public class IncProjectBuilder { myProjectDescriptor.fsState.onRebuild(); final Collection modulesToClean = context.getProject().getModules().values(); - final Set toDelete = new HashSet(); + final Set rootsToDelete = new HashSet(); final Set allSourceRoots = new HashSet(); for (Module module : modulesToClean) { final File out = context.getProjectPaths().getModuleOutputDir(module, false); if (out != null) { - toDelete.add(out); + rootsToDelete.add(out); } final File testOut = context.getProjectPaths().getModuleOutputDir(module, true); if (testOut != null) { - toDelete.add(testOut); + rootsToDelete.add(testOut); } final List moduleRoots = context.getModuleRoots(module); for (RootDescriptor d : moduleRoots) { @@ -180,7 +180,11 @@ public class IncProjectBuilder { } // check that output and source roots are not overlapping - for (File outputRoot : toDelete) { + final List filesToDelete = new ArrayList(); + for (File outputRoot : rootsToDelete) { + if (myCancelStatus.isCanceled()) { + throw new ProjectBuildException(CANCELED_MESSAGE); + } boolean okToDelete = true; if (PathUtil.isUnder(allSourceRoots, outputRoot)) { okToDelete = false; @@ -195,22 +199,19 @@ public class IncProjectBuilder { } } if (okToDelete) { - context.processMessage(new ProgressMessage("Cleaning " + outputRoot.getPath())); // do not delete output root itself to avoid lots of unnecessary "roots_changed" events in IDEA final File[] children = outputRoot.listFiles(); if (children != null) { - for (File child : children) { - if (myCancelStatus.isCanceled()) { - throw new ProjectBuildException(CANCELED_MESSAGE); - } - FileUtil.delete(child); - } + filesToDelete.addAll(Arrays.asList(children)); } } else { context.processMessage(new CompilerMessage(JPS_SERVER_NAME, BuildMessage.Kind.WARNING, "Output path " + outputRoot.getPath() + " intersects with a source root. The output cannot be cleaned.")); } } + + context.processMessage(new ProgressMessage("Cleaning output directories...")); + FileUtil.asyncDelete(filesToDelete); } private static void runTasks(CompileContext context, final List tasks) throws ProjectBuildException {