mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
proactively start temp dir cleanup task on project preload stage
GitOrigin-RevId: 438a3e3746b16088eab7e480a699da55706d33c0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1d50779f00
commit
6b870122e6
+1
@@ -0,0 +1 @@
|
||||
org.jetbrains.jps.incremental.CleanupTempDirectoryExtension
|
||||
@@ -0,0 +1,45 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.jps.incremental;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.builders.PreloadedDataExtension;
|
||||
import org.jetbrains.jps.cmdline.PreloadedData;
|
||||
import org.jetbrains.jps.cmdline.ProjectDescriptor;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class CleanupTempDirectoryExtension implements PreloadedDataExtension {
|
||||
private Future<Void> myTask;
|
||||
|
||||
@Override
|
||||
public void preloadData(PreloadedData data) {
|
||||
final ProjectDescriptor pd = data.getProjectDescriptor();
|
||||
if (pd != null) {
|
||||
myTask = IncProjectBuilder.startTempDirectoryCleanupTask(pd);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CleanupTempDirectoryExtension getInstance() {
|
||||
for (PreloadedDataExtension extension : JpsServiceManager.getInstance().getExtensions(PreloadedDataExtension.class)) {
|
||||
if (extension instanceof CleanupTempDirectoryExtension) {
|
||||
return (CleanupTempDirectoryExtension)extension;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Future<Void> getCleanupTask() {
|
||||
return myTask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildSessionInitialized(PreloadedData data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void discardPreloadedData(PreloadedData data) {
|
||||
}
|
||||
}
|
||||
@@ -172,7 +172,11 @@ public class IncProjectBuilder {
|
||||
myProjectDescriptor.getProjectStamps().getStampStorage().force();
|
||||
});
|
||||
|
||||
startTempDirectoryCleanupTask();
|
||||
final CleanupTempDirectoryExtension cleaner = CleanupTempDirectoryExtension.getInstance();
|
||||
final Future<Void> cleanupTask = cleaner != null && cleaner.getCleanupTask() != null? cleaner.getCleanupTask() : startTempDirectoryCleanupTask(myProjectDescriptor);
|
||||
if (cleanupTask != null) {
|
||||
myAsyncTasks.add(cleanupTask);
|
||||
}
|
||||
|
||||
CompileContextImpl context = null;
|
||||
try {
|
||||
@@ -475,16 +479,17 @@ public class IncProjectBuilder {
|
||||
.forEach(context::processMessage);
|
||||
}
|
||||
|
||||
private void startTempDirectoryCleanupTask() {
|
||||
@Nullable
|
||||
static Future<Void> startTempDirectoryCleanupTask(final ProjectDescriptor pd) {
|
||||
final String tempPath = System.getProperty("java.io.tmpdir", null);
|
||||
if (StringUtil.isEmptyOrSpaces(tempPath)) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
final File tempDir = new File(tempPath);
|
||||
final File dataRoot = myProjectDescriptor.dataManager.getDataPaths().getDataStorageRoot();
|
||||
final File dataRoot = pd.dataManager.getDataPaths().getDataStorageRoot();
|
||||
if (!FileUtil.isAncestor(dataRoot, tempDir, true)) {
|
||||
// cleanup only 'local' temp
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
final File[] files = tempDir.listFiles();
|
||||
if (files != null && files.length != 0) {
|
||||
@@ -497,8 +502,9 @@ public class IncProjectBuilder {
|
||||
thread.setPriority(Thread.MIN_PRIORITY);
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
myAsyncTasks.add(task);
|
||||
return task;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private CompileContextImpl createContext(CompileScope scope) throws ProjectBuildException {
|
||||
|
||||
Reference in New Issue
Block a user