cleanup - extract LoadingContext

GitOrigin-RevId: bb813c7845ce9108182e4e7f5debb849b5043480
This commit is contained in:
Vladimir Krivosheev
2019-11-07 02:40:58 +00:00
committed by intellij-monorepo-bot
parent 67d4101210
commit 143ad7ecf9
2 changed files with 58 additions and 45 deletions
@@ -0,0 +1,57 @@
// 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 com.intellij.ide.plugins;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.SafeJdomFactory;
import gnu.trove.THashMap;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipFile;
final class LoadingContext implements AutoCloseable {
final Map<File, ZipFile> openedFiles = new THashMap<>();
final LoadDescriptorsContext parentContext;
final boolean isBundled;
final boolean isEssential;
final boolean ignoreDisabled;
final List<Pair<String, IdeaPluginDescriptorImpl>> visitedFiles = new ArrayList<>(3);
File lastZipWithDescriptor;
/**
* parentContext is null only for CoreApplicationEnvironment - it is not valid otherwise because in this case XML is not interned.
*/
LoadingContext(@Nullable LoadDescriptorsContext parentContext, boolean isBundled, boolean isEssential, boolean ignoreDisabled) {
this.parentContext = parentContext;
this.isBundled = isBundled;
this.isEssential = isEssential;
this.ignoreDisabled = ignoreDisabled;
}
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
ZipFile open(File file) throws IOException {
ZipFile zipFile = openedFiles.get(file);
if (zipFile == null) {
openedFiles.put(file, zipFile = new ZipFile(file));
}
return zipFile;
}
@Nullable
SafeJdomFactory getXmlFactory() {
return parentContext != null ? parentContext.getXmlFactory() : null;
}
@Override
public void close() {
for (ZipFile file : openedFiles.values()) {
try { file.close(); }
catch (IOException ignore) { }
}
}
}
@@ -32,7 +32,6 @@ import com.intellij.util.io.URLUtil;
import com.intellij.util.lang.UrlClassLoader;
import com.intellij.util.text.VersionComparatorUtil;
import com.intellij.util.xmlb.JDOMXIncluder;
import gnu.trove.THashMap;
import gnu.trove.THashSet;
import gnu.trove.TObjectIntHashMap;
import org.jdom.JDOMException;
@@ -761,49 +760,6 @@ public class PluginManagerCore {
}
}
static class LoadingContext implements AutoCloseable {
final Map<File, ZipFile> openedFiles = new THashMap<>();
final LoadDescriptorsContext parentContext;
final boolean isBundled;
final boolean isEssential;
final boolean ignoreDisabled;
final List<Pair<String, IdeaPluginDescriptorImpl>> visitedFiles = new ArrayList<>(3);
File lastZipWithDescriptor;
/**
* parentContext is null only for CoreApplicationEnvironment - it is not valid otherwise because in this case XML is not interned.
*/
LoadingContext(@Nullable LoadDescriptorsContext parentContext, boolean isBundled, boolean isEssential, boolean ignoreDisabled) {
this.parentContext = parentContext;
this.isBundled = isBundled;
this.isEssential = isEssential;
this.ignoreDisabled = ignoreDisabled;
}
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
ZipFile open(File file) throws IOException {
ZipFile zipFile = openedFiles.get(file);
if (zipFile == null) {
openedFiles.put(file, zipFile = new ZipFile(file));
}
return zipFile;
}
@Nullable
SafeJdomFactory getXmlFactory() {
return parentContext != null ? parentContext.getXmlFactory() : null;
}
@Override
public void close() {
for (ZipFile file : openedFiles.values()) {
try { file.close(); }
catch (IOException ignore) { }
}
}
}
@Nullable
private static IdeaPluginDescriptorImpl loadDescriptor(@NotNull File file, @NotNull String pathName, @NotNull LoadingContext context) {
IdeaPluginDescriptorImpl descriptor = null;
@@ -1698,7 +1654,7 @@ public class PluginManagerCore {
.skip(1);
}
private static class PluginTraverser extends JBTreeTraverser<PluginId> {
private static final class PluginTraverser extends JBTreeTraverser<PluginId> {
final Map<PluginId, IdeaPluginDescriptorImpl> idMap;
PluginTraverser(@NotNull Map<PluginId, IdeaPluginDescriptorImpl> idMap,