From 143ad7ecf9c2bf524029b8ea2a014bfd15ef429e Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 29 Oct 2019 18:01:27 +0100 Subject: [PATCH] cleanup - extract LoadingContext GitOrigin-RevId: bb813c7845ce9108182e4e7f5debb849b5043480 --- .../intellij/ide/plugins/LoadingContext.java | 57 +++++++++++++++++++ .../ide/plugins/PluginManagerCore.java | 46 +-------------- 2 files changed, 58 insertions(+), 45 deletions(-) create mode 100644 platform/core-impl/src/com/intellij/ide/plugins/LoadingContext.java diff --git a/platform/core-impl/src/com/intellij/ide/plugins/LoadingContext.java b/platform/core-impl/src/com/intellij/ide/plugins/LoadingContext.java new file mode 100644 index 000000000000..277387e58f7a --- /dev/null +++ b/platform/core-impl/src/com/intellij/ide/plugins/LoadingContext.java @@ -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 openedFiles = new THashMap<>(); + final LoadDescriptorsContext parentContext; + final boolean isBundled; + final boolean isEssential; + final boolean ignoreDisabled; + final List> 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) { } + } + } +} diff --git a/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.java b/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.java index ed94fc8eb679..de08a4ff0e91 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.java +++ b/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.java @@ -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 openedFiles = new THashMap<>(); - final LoadDescriptorsContext parentContext; - final boolean isBundled; - final boolean isEssential; - final boolean ignoreDisabled; - final List> 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 { + private static final class PluginTraverser extends JBTreeTraverser { final Map idMap; PluginTraverser(@NotNull Map idMap,