diff --git a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/Utils.java b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/Utils.java index 4cb241cde467..4e6422867ce6 100644 --- a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/Utils.java +++ b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/Utils.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.uiDesigner.compiler; import com.intellij.compiler.instrumentation.InstrumentationClassFinder; diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java index 5e4e3bee32e0..64a3cd2bb39f 100644 --- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java +++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/JpsLoaderBase.java @@ -1,4 +1,4 @@ -// Copyright 2000-2021 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. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. 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.model.serialization; import com.intellij.openapi.diagnostic.Logger; @@ -13,7 +13,6 @@ import org.jetbrains.jps.TimingLog; import org.jetbrains.jps.model.JpsElement; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; @@ -73,7 +72,7 @@ public abstract class JpsLoaderBase { int i = 0; while (true) { try { - return JDOMUtil.load(Files.newInputStream(file)); + return JDOMUtil.load(file); } catch (NoSuchFileException e) { return null; diff --git a/lib/annotations/jdk/javax/xml/parsers/annotations.xml b/lib/annotations/jdk/javax/xml/parsers/annotations.xml index aff102e2f335..6a2f2abc33f5 100644 --- a/lib/annotations/jdk/javax/xml/parsers/annotations.xml +++ b/lib/annotations/jdk/javax/xml/parsers/annotations.xml @@ -2,4 +2,7 @@ + + + \ No newline at end of file diff --git a/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/IconsClassGenerator.kt b/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/IconsClassGenerator.kt index 6f05e27d2729..97230f1c8ddd 100644 --- a/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/IconsClassGenerator.kt +++ b/platform/build-scripts/icons/src/org/jetbrains/intellij/build/images/IconsClassGenerator.kt @@ -443,9 +443,9 @@ internal open class IconsClassGenerator(private val projectHome: Path, val loadedImage: BufferedImage if (file.toString().endsWith(".svg")) { // don't mask any exception for svg file - val data = loadAndNormalizeSvgFile(imageFile) - loadedImage = SvgTranscoder.createImage(1f, createSvgDocument(null, data.byteInputStream()), null) - key = getImageKey(data.toByteArray(), file.fileName.toString()) + val data = loadAndNormalizeSvgFile(imageFile).toByteArray() + loadedImage = SvgTranscoder.createImage(1f, createSvgDocument(null, data), null) + key = getImageKey(data, file.fileName.toString()) } else { loadedImage = Files.newInputStream(file).buffered().use { ImageIO.read(it) } diff --git a/platform/configuration-store-impl/src/ComponentStoreImpl.kt b/platform/configuration-store-impl/src/ComponentStoreImpl.kt index c0c5a5890226..2b68f4194e79 100644 --- a/platform/configuration-store-impl/src/ComponentStoreImpl.kt +++ b/platform/configuration-store-impl/src/ComponentStoreImpl.kt @@ -14,17 +14,13 @@ import com.intellij.openapi.components.impl.stores.IComponentStore import com.intellij.openapi.components.impl.stores.UnknownMacroNotification import com.intellij.openapi.diagnostic.* import com.intellij.openapi.extensions.PluginId -import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.JDOMUtil import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.util.use import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess -import com.intellij.util.ArrayUtilRt -import com.intellij.util.SmartList -import com.intellij.util.SystemProperties -import com.intellij.util.ThreeState +import com.intellij.util.* import com.intellij.util.concurrency.annotations.RequiresEdt import com.intellij.util.containers.toArray import com.intellij.util.messages.MessageBus @@ -493,9 +489,9 @@ abstract class ComponentStoreImpl : IComponentStore { private fun getDefaultState(component: Any, componentName: String, stateClass: Class): T? { val classLoader = component.javaClass.classLoader - val stream = classLoader.getResourceAsStream("$componentName.xml") ?: return null + val data = ResourceUtil.getResourceAsBytes("$componentName.xml", classLoader) ?: return null try { - val element = JDOMUtil.load(stream) + val element = JDOMUtil.load(data) getPathMacroManagerForDefaults()?.expandPaths(element) return deserializeState(element, stateClass, null) } diff --git a/platform/configuration-store-impl/src/schemeManager/SchemeManagerImpl.kt b/platform/configuration-store-impl/src/schemeManager/SchemeManagerImpl.kt index add3d4fa737f..22c595c484a3 100644 --- a/platform/configuration-store-impl/src/schemeManager/SchemeManagerImpl.kt +++ b/platform/configuration-store-impl/src/schemeManager/SchemeManagerImpl.kt @@ -118,32 +118,29 @@ class SchemeManagerImpl(val fileSpec: String, bytes = Files.readAllBytes(Path.of(resourceName)) } is UITheme -> { - val stream = requestor.providerClassLoader.getResourceAsStream(resourceName.removePrefix("/")) - if (stream == null) { + bytes = ResourceUtil.getResourceAsBytes(resourceName.removePrefix("/"), requestor.providerClassLoader) + if (bytes == null) { LOG.error("Cannot find $resourceName in ${requestor.providerClassLoader}") return } - bytes = stream.use { it.readAllBytes() } } else -> { - val stream = (if (requestor is ClassLoader) requestor else requestor!!.javaClass.classLoader) - .getResourceAsStream(resourceName.removePrefix("/")) - if (stream == null) { + bytes = ResourceUtil.getResourceAsBytes(resourceName.removePrefix("/"), + (if (requestor is ClassLoader) requestor else requestor!!.javaClass.classLoader)) + if (bytes == null) { LOG.error("Cannot read scheme from $resourceName") return } - bytes = stream.use { it.readAllBytes() } } } } else { val classLoader = pluginDescriptor.classLoader - val stream = classLoader.getResourceAsStream(resourceName.removePrefix("/")) - if (stream == null) { + bytes = ResourceUtil.getResourceAsBytes(resourceName.removePrefix("/"), classLoader) + if (bytes == null) { LOG.error("Cannot found scheme $resourceName in $classLoader") return } - bytes = stream.use { it.readAllBytes() } } lazyPreloadScheme(bytes, isOldSchemeNaming) { name, parser -> diff --git a/platform/core-impl/src/com/intellij/ide/plugins/ClassPathXmlPathResolver.kt b/platform/core-impl/src/com/intellij/ide/plugins/ClassPathXmlPathResolver.kt index 0d48c320b8c3..5458dff11c05 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/ClassPathXmlPathResolver.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/ClassPathXmlPathResolver.kt @@ -20,7 +20,7 @@ internal class ClassPathXmlPathResolver(private val classLoader: ClassLoader, va val path = PluginXmlPathResolver.toLoadPath(relativePath, base) val reader: XMLStreamReader2 if (classLoader is UrlClassLoader) { - reader = createNonCoalescingXmlStreamReader(classLoader.getResourceAsBytes(path) ?: return false, dataLoader.toString()) + reader = createNonCoalescingXmlStreamReader(classLoader.getResourceAsBytes(path, true) ?: return false, dataLoader.toString()) } else { reader = createNonCoalescingXmlStreamReader(classLoader.getResourceAsStream(path) ?: return false, dataLoader.toString()) @@ -40,7 +40,7 @@ internal class ClassPathXmlPathResolver(private val classLoader: ClassLoader, va readInto: RawPluginDescriptor?): RawPluginDescriptor { var resource: ByteArray? if (classLoader is UrlClassLoader) { - resource = classLoader.getResourceAsBytes(path) + resource = classLoader.getResourceAsBytes(path, true) } else { classLoader.getResourceAsStream(path)?.let { @@ -101,7 +101,7 @@ internal class ClassPathXmlPathResolver(private val classLoader: ClassLoader, va private fun getXmlReader(classLoader: ClassLoader, path: String, dataLoader: DataLoader): XMLStreamReader2? { if (classLoader is UrlClassLoader) { - return createNonCoalescingXmlStreamReader(classLoader.getResourceAsBytes(path) ?: return null, dataLoader.toString()) + return createNonCoalescingXmlStreamReader(classLoader.getResourceAsBytes(path, true) ?: return null, dataLoader.toString()) } else { return createNonCoalescingXmlStreamReader(classLoader.getResourceAsStream(path) ?: return null, dataLoader.toString()) diff --git a/platform/core-impl/src/com/intellij/ide/plugins/PluginDescriptorLoader.kt b/platform/core-impl/src/com/intellij/ide/plugins/PluginDescriptorLoader.kt index 68825c21c66f..e2a36e53f4b9 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/PluginDescriptorLoader.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/PluginDescriptorLoader.kt @@ -416,7 +416,7 @@ private fun loadBundledDescriptorsAndDescriptorsFromDir(context: DescriptorListL else { val fileName = "${platformPrefix}Plugin.xml" if (classLoader is UrlClassLoader) { - classLoader.getResourceAsBytes("${PluginManagerCore.META_INF}$fileName")?.let { + classLoader.getResourceAsBytes("${PluginManagerCore.META_INF}$fileName", false)?.let { loadCoreProductPlugin(data = ByteArrayInputStream(it), context, pathResolver, useCoreClassLoader) } } diff --git a/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java b/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java index b94595fde94c..bf52466d625e 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java +++ b/platform/core-impl/src/com/intellij/ide/plugins/cl/PluginClassLoader.java @@ -16,10 +16,7 @@ import com.intellij.util.lang.UrlClassLoader; import com.intellij.util.ui.EDT; import org.jetbrains.annotations.*; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.Writer; +import java.io.*; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; @@ -437,6 +434,45 @@ public final class PluginClassLoader extends UrlClassLoader implements PluginAwa return doFindResource(name, Resource::getURL, ClassLoader::getResource); } + @Override + public byte @Nullable [] getResourceAsBytes(@NotNull String name, boolean checkParents) throws IOException { + byte[] result = super.getResourceAsBytes(name, checkParents); + if (result != null) { + return result; + } + + if (!checkParents) { + return null; + } + + for (ClassLoader classloader : getAllParents()) { + if (classloader instanceof UrlClassLoader) { + Resource resource = ((UrlClassLoader)classloader).getClassPath().findResource(name); + if (resource != null) { + return resource.getBytes(); + } + } + else { + InputStream input = classloader.getResourceAsStream(name); + if (input != null) { + try { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + int read; + byte[] data = new byte[16384]; + while ((read = input.read(data, 0, data.length)) != -1) { + buffer.write(data, 0, read); + } + return buffer.toByteArray(); + } + finally { + input.close(); + } + } + } + } + return result; + } + @Override public @Nullable InputStream getResourceAsStream(@NotNull String name) { Function f1 = resource -> { diff --git a/platform/core-ui/src/ui/RasterizedImageDataLoader.java b/platform/core-ui/src/ui/RasterizedImageDataLoader.java index 9c3a42fb28fa..808aa6a55742 100644 --- a/platform/core-ui/src/ui/RasterizedImageDataLoader.java +++ b/platform/core-ui/src/ui/RasterizedImageDataLoader.java @@ -1,4 +1,4 @@ -// Copyright 2000-2021 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. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui; import com.intellij.diagnostic.StartUpMeasurer; @@ -16,7 +16,6 @@ import com.intellij.util.ImageLoader.Dimension2DDouble; import com.intellij.util.SVGLoader; import com.intellij.util.ui.StartupUiUtil; import org.intellij.lang.annotations.MagicConstant; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,7 +26,6 @@ import java.lang.ref.WeakReference; import java.net.URL; import java.util.List; -@ApiStatus.Internal final class RasterizedImageDataLoader implements ImageDataLoader { private final WeakReference classLoaderRef; private final long cacheKey; @@ -134,8 +132,8 @@ final class RasterizedImageDataLoader implements ImageDataLoader { long start = StartUpMeasurer.getCurrentTimeIfEnabled(); Image image; if (isSvg) { - image = SVGLoader - .loadFromClassResource(null, classLoader, effectivePath, rasterizedCacheKey, imageScale, isEffectiveDark, originalUserSize); + image = SVGLoader.loadFromClassResource(null, classLoader, effectivePath, rasterizedCacheKey, imageScale, isEffectiveDark, + originalUserSize); } else { image = ImageLoader.loadPngFromClassResource(effectivePath, null, classLoader, imageScale, originalUserSize); @@ -151,11 +149,11 @@ final class RasterizedImageDataLoader implements ImageDataLoader { if (image == null) { return null; } - return ImageLoader.convertImage(image, filters, flags, scaleContext, isUpScaleNeeded, StartupUiUtil.isJreHiDPI(scaleContext), imageScale, isSvg, - originalUserSize); + return ImageLoader.convertImage(image, filters, flags, scaleContext, isUpScaleNeeded, StartupUiUtil.isJreHiDPI(scaleContext), + imageScale, isSvg); } catch (IOException e) { - Logger.getInstance(ImageLoader.class).debug(e); + Logger.getInstance(RasterizedImageDataLoader.class).debug(e); return null; } } diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/ex/DefaultColorSchemesManager.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/ex/DefaultColorSchemesManager.java index 887294251219..330c4a884f55 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/ex/DefaultColorSchemesManager.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/ex/DefaultColorSchemesManager.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 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. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.editor.colors.ex; import com.intellij.openapi.application.ApplicationManager; @@ -9,6 +9,7 @@ import com.intellij.openapi.editor.colors.impl.EmptyColorScheme; import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.ExceptionUtil; +import com.intellij.util.ResourceUtil; import org.jdom.Attribute; import org.jdom.Element; import org.jdom.JDOMException; @@ -47,7 +48,8 @@ public final class DefaultColorSchemesManager { public void reload() { try { - loadState(JDOMUtil.load(DefaultColorSchemesManager.class, "/DefaultColorSchemesManager.xml")); + loadState(JDOMUtil.load(ResourceUtil.getResourceAsBytes("DefaultColorSchemesManager.xml", + DefaultColorSchemesManager.class.getClassLoader()))); } catch (JDOMException | IOException e) { ExceptionUtil.rethrow(e); diff --git a/platform/inspect/src/com/intellij/codeInspection/InspectionDiff.java b/platform/inspect/src/com/intellij/codeInspection/InspectionDiff.java index 764107b07aff..588c226b03a9 100644 --- a/platform/inspect/src/com/intellij/codeInspection/InspectionDiff.java +++ b/platform/inspect/src/com/intellij/codeInspection/InspectionDiff.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 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. +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInspection; @@ -9,7 +9,11 @@ import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.Nullable; -import java.io.*; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStream; +import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -65,13 +69,10 @@ public final class InspectionDiff { } } - private static void writeInspectionDiff(final String oldPath, final String newPath, final String outPath) { + private static void writeInspectionDiff(String oldPath, String newPath, final String outPath) { try { - InputStream oldStream = oldPath != null ? new BufferedInputStream(new FileInputStream(oldPath)) : null; - InputStream newStream = new BufferedInputStream(new FileInputStream(newPath)); - - Element oldDoc = oldStream != null ? JDOMUtil.load(oldStream) : null; - Element newDoc = JDOMUtil.load(newStream); + Element oldDoc = oldPath == null ? null : JDOMUtil.load(Path.of(oldPath)); + Element newDoc = JDOMUtil.load(Path.of(newPath)); OutputStream outStream = System.out; if (outPath != null) { @@ -83,7 +84,8 @@ public final class InspectionDiff { if (outStream != System.out) { outStream.close(); } - } catch (Exception e) { + } + catch (Exception e) { e.printStackTrace(); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java index bc4841ee49aa..2a74aa09db6d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/template/impl/TemplateSettings.java @@ -27,6 +27,7 @@ import com.intellij.openapi.util.NlsSafe; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.Strings; import com.intellij.serviceContainer.NonInjectable; +import com.intellij.util.ResourceUtil; import com.intellij.util.SmartList; import com.intellij.util.containers.MultiMap; import com.intellij.util.xmlb.Converter; @@ -39,7 +40,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.IOException; -import java.io.InputStream; import java.util.*; @State( @@ -541,24 +541,19 @@ public final class TemplateSettings implements PersistentStateComponent