use of org.jetbrains.jps.incremental.messages.FileDeletedEvent in project intellij-community by JetBrains.
the class BuildOperations method cleanOutputsCorrespondingToChangedFiles.
public static <R extends BuildRootDescriptor, T extends BuildTarget<R>> Map<T, Set<File>> cleanOutputsCorrespondingToChangedFiles(final CompileContext context, DirtyFilesHolder<R, T> dirtyFilesHolder) throws ProjectBuildException {
final BuildDataManager dataManager = context.getProjectDescriptor().dataManager;
try {
final Map<T, Set<File>> cleanedSources = new HashMap<>();
final THashSet<File> dirsToDelete = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
final Collection<String> deletedPaths = new ArrayList<>();
dirtyFilesHolder.processDirtyFiles(new FileProcessor<R, T>() {
// cache the mapping locally
private final Map<T, SourceToOutputMapping> mappingsCache = new HashMap<>();
private final TObjectIntHashMap<T> idsCache = new TObjectIntHashMap<>();
@Override
public boolean apply(T target, File file, R sourceRoot) throws IOException {
SourceToOutputMapping srcToOut = mappingsCache.get(target);
if (srcToOut == null) {
srcToOut = dataManager.getSourceToOutputMap(target);
mappingsCache.put(target, srcToOut);
}
final int targetId;
if (!idsCache.containsKey(target)) {
targetId = dataManager.getTargetsState().getBuildTargetId(target);
idsCache.put(target, targetId);
} else {
targetId = idsCache.get(target);
}
final String srcPath = file.getPath();
final Collection<String> outputs = srcToOut.getOutputs(srcPath);
if (outputs != null) {
final boolean shouldPruneOutputDirs = target instanceof ModuleBasedTarget;
final List<String> deletedForThisSource = new ArrayList<>(outputs.size());
for (String output : outputs) {
deleteRecursively(output, deletedForThisSource, shouldPruneOutputDirs ? dirsToDelete : null);
}
deletedPaths.addAll(deletedForThisSource);
dataManager.getOutputToTargetRegistry().removeMapping(deletedForThisSource, targetId);
Set<File> cleaned = cleanedSources.get(target);
if (cleaned == null) {
cleaned = new THashSet<>(FileUtil.FILE_HASHING_STRATEGY);
cleanedSources.put(target, cleaned);
}
cleaned.add(file);
}
return true;
}
});
if (JavaBuilderUtil.isCompileJavaIncrementally(context)) {
final ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
if (logger.isEnabled()) {
logger.logDeletedFiles(deletedPaths);
}
}
if (!deletedPaths.isEmpty()) {
context.processMessage(new FileDeletedEvent(deletedPaths));
}
// attempting to delete potentially empty directories
FSOperations.pruneEmptyDirs(context, dirsToDelete);
return cleanedSources;
} catch (Exception e) {
throw new ProjectBuildException(e);
}
}
Aggregations