IDEA-CR-52550: avoid closed stream usage when several DebuggerSessions are attached

GitOrigin-RevId: ab5d13ae3f33d80cb870da74a2cea2447dec1cb4
This commit is contained in:
Vladislav.Soroka
2019-09-19 07:39:18 +00:00
committed by intellij-monorepo-bot
parent b01db09ad7
commit 544ddcc12b
2 changed files with 10 additions and 10 deletions
@@ -8,6 +8,7 @@ import com.intellij.ide.actions.ActionsCollector;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.OrderEnumerator;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
@@ -19,8 +20,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class HotSwapManager {
private final Map<DebuggerSession, Long> myTimeStamps = new HashMap<>();
@@ -52,14 +51,14 @@ public class HotSwapManager {
}
public Map<String, HotSwapFile> scanForModifiedClasses(@NotNull DebuggerSession session,
@Nullable Stream<String> outputPaths,
@Nullable NotNullLazyValue<? extends List<String>> outputPaths,
@NotNull HotSwapProgress progress) {
DebuggerManagerThreadImpl.assertIsManagerThread();
final long timeStamp = getTimeStamp(session);
final Map<String, HotSwapFile> modifiedClasses = new HashMap<>();
List<String> paths = outputPaths != null ? outputPaths.collect(Collectors.toList()) :
List<String> paths = outputPaths != null ? outputPaths.getValue() :
ReadAction.compute(() -> JBIterable.of(OrderEnumerator.orderEntries(myProject).classes().getRoots())
.filterMap(o -> o.isDirectory() && !o.getFileSystem().isReadOnly() ? o.getPath() : null)
.toList()
@@ -146,7 +145,7 @@ public class HotSwapManager {
@NotNull
public static Map<DebuggerSession, Map<String, HotSwapFile>> scanForModifiedClasses(@NotNull List<? extends DebuggerSession> sessions,
@Nullable Stream<String> outputPaths,
@Nullable NotNullLazyValue<? extends List<String>> outputPaths,
@NotNull HotSwapProgress swapProgress) {
final Map<DebuggerSession, Map<String, HotSwapFile>> modifiedClasses = new THashMap<>();
final MultiProcessCommand scanClassesCommand = new MultiProcessCommand();
@@ -21,6 +21,7 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.KeyWithDefaultValue;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
@@ -38,7 +39,6 @@ import org.jetbrains.jps.util.JpsPathUtil;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class HotSwapUIImpl extends HotSwapUI {
/**
@@ -108,7 +108,7 @@ public class HotSwapUIImpl extends HotSwapUI {
private void hotSwapSessions(@NotNull final List<DebuggerSession> sessions,
@Nullable final Map<String, Collection<String>> generatedPaths,
@Nullable final Stream<String> outputPaths,
@Nullable final NotNullLazyValue<? extends List<String>> outputPaths,
@Nullable final HotSwapStatusListener callback) {
final boolean shouldAskBeforeHotswap = myAskBeforeHotswap;
myAskBeforeHotswap = true;
@@ -283,7 +283,7 @@ public class HotSwapUIImpl extends HotSwapUI {
@NotNull
private static Map<DebuggerSession, Map<String, HotSwapFile>> scanForModifiedClassesWithProgress(@NotNull List<DebuggerSession> sessions,
@Nullable Stream<String> outputPaths,
@Nullable NotNullLazyValue<? extends List<String>> outputPaths,
@NotNull HotSwapProgressImpl progress) {
return ProgressManager.getInstance().runProcess(() -> {
try {
@@ -399,8 +399,9 @@ public class HotSwapUIImpl extends HotSwapUI {
}
HotSwapStatusListener callback = context.getUserData(HOT_SWAP_CALLBACK_KEY);
Stream<String> dirtyOutputRoots = context.getDirtyOutputPaths().orElse(null);
hotSwapSessions(sessions, generatedPaths, dirtyOutputRoots, callback);
NotNullLazyValue<? extends List<String>> outputRoots = context.getDirtyOutputPaths()
.map(stream -> NotNullLazyValue.createValue(() -> stream.collect(Collectors.toCollection(SmartList::new)))).orElse(null);
hotSwapSessions(sessions, generatedPaths, outputRoots, callback);
}
}
}