mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
use getResourceAsBytes
GitOrigin-RevId: 698f4792c8c7565dd0af71d4d76ff611531531a8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b272a9fb3d
commit
6260bbfd7f
@@ -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;
|
||||
|
||||
+2
-3
@@ -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;
|
||||
|
||||
@@ -2,4 +2,7 @@
|
||||
<item name='javax.xml.parsers.DocumentBuilderFactory javax.xml.parsers.DocumentBuilderFactory newInstance()'>
|
||||
<annotation name='java.lang.Deprecated'/>
|
||||
</item>
|
||||
<item name='javax.xml.parsers.SAXParserFactory javax.xml.parsers.SAXParserFactory newInstance()'>
|
||||
<annotation name='java.lang.Deprecated'/>
|
||||
</item>
|
||||
</root>
|
||||
+3
-3
@@ -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) }
|
||||
|
||||
@@ -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 <T : Any> getDefaultState(component: Any, componentName: String, stateClass: Class<T>): 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)
|
||||
}
|
||||
|
||||
@@ -118,32 +118,29 @@ class SchemeManagerImpl<T: Scheme, MUTABLE_SCHEME : T>(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 ->
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Resource, InputStream> f1 = resource -> {
|
||||
|
||||
@@ -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<ClassLoader> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
+9
-14
@@ -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<Template
|
||||
PluginInfo info) throws JDOMException {
|
||||
Element element;
|
||||
try {
|
||||
InputStream stream;
|
||||
byte[] data;
|
||||
if (defTemplate.startsWith("/")) {
|
||||
stream = loader.getResourceAsStream(appendExt(defTemplate.substring(1)));
|
||||
data = ResourceUtil.getResourceAsBytes(appendExt(defTemplate.substring(1)), loader);
|
||||
}
|
||||
else {
|
||||
stream = loader.getResourceAsStream(appendExt(defTemplate));
|
||||
data = ResourceUtil.getResourceAsBytes(appendExt(defTemplate), loader);
|
||||
}
|
||||
if (stream == null) {
|
||||
stream = loader.getResourceAsStream(appendExt("idea/" + defTemplate));
|
||||
if (stream == null) {
|
||||
LOG.error("Unable to find template resource: " + defTemplate + "; classLoader: " + loader + "; plugin: " + info);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
LOG.error("Do not rely on implicit `idea/` prefix: " + defTemplate + "; classLoader: " + loader + "; plugin: " + info);
|
||||
}
|
||||
if (data == null) {
|
||||
LOG.error("Unable to find template resource: " + defTemplate + "; classLoader: " + loader + "; plugin: " + info);
|
||||
return;
|
||||
}
|
||||
element = JDOMUtil.load(stream);
|
||||
|
||||
element = JDOMUtil.load(data);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error("Unable to read template resource: " + defTemplate + "; classLoader: " + loader + "; plugin: " + info, e);
|
||||
|
||||
@@ -107,5 +107,6 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.util.netty" />
|
||||
<orderEntry type="module" module-name="intellij.remoteDev.util" scope="RUNTIME" />
|
||||
<orderEntry type="module" module-name="intellij.platform.feedback" scope="RUNTIME" />
|
||||
<orderEntry type="library" name="aalto-xml" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -2,11 +2,11 @@
|
||||
package com.intellij.ide.gdpr;
|
||||
|
||||
import com.intellij.ide.Prefs;
|
||||
import com.intellij.idea.StartupUtil;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.util.PlatformUtils;
|
||||
import com.intellij.util.ResourceUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -153,7 +153,7 @@ public final class EndUserAgreement {
|
||||
|
||||
private static @NotNull Document loadContent(String docName, String resourcePath) {
|
||||
try {
|
||||
byte[] data = StartupUtil.getResourceAsBytes(resourcePath, EndUserAgreement.class.getClassLoader());
|
||||
byte[] data = ResourceUtil.getResourceAsBytes(resourcePath, EndUserAgreement.class.getClassLoader());
|
||||
if (data != null) {
|
||||
return new Document(docName, new String(data, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@@ -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.ide.plugins;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
@@ -166,9 +166,8 @@ public final class RepositoryHelper {
|
||||
}
|
||||
|
||||
private static boolean ideContainsUltimateModule() {
|
||||
IdeaPluginDescriptor corePlugin = PluginManagerCore.getPlugin(PluginManagerCore.CORE_ID);
|
||||
IdeaPluginDescriptorImpl corePluginImpl = (corePlugin instanceof IdeaPluginDescriptorImpl) ? (IdeaPluginDescriptorImpl)corePlugin : null;
|
||||
return corePluginImpl != null && corePluginImpl.modules.contains(PluginId.getId(ULTIMATE_MODULE));
|
||||
IdeaPluginDescriptorImpl corePlugin = PluginManagerCore.findPlugin(PluginManagerCore.CORE_ID);
|
||||
return corePlugin != null && corePlugin.modules.contains(PluginId.getId(ULTIMATE_MODULE));
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
|
||||
+25
-30
@@ -30,7 +30,6 @@ import org.xml.sax.InputSource
|
||||
import org.xml.sax.SAXException
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.io.Reader
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URLConnection
|
||||
import java.nio.file.Files
|
||||
@@ -45,25 +44,22 @@ import javax.xml.parsers.SAXParserFactory
|
||||
private val LOG = logger<MarketplaceRequests>()
|
||||
private const val FULL_PLUGINS_XML_IDS_FILENAME = "pluginsXMLIds.json"
|
||||
|
||||
private val objectMapper by lazy { ObjectMapper() }
|
||||
private val pluginManagerUrl by lazy(LazyThreadSafetyMode.PUBLICATION) { ApplicationInfoImpl.getShadowInstance().pluginManagerUrl.trimEnd('/') }
|
||||
private val compatibleUpdateUrl: String
|
||||
get() = "${pluginManagerUrl}/api/search/compatibleUpdates"
|
||||
|
||||
@ApiStatus.Internal
|
||||
class MarketplaceRequests : PluginInfoProvider {
|
||||
companion object {
|
||||
|
||||
private val objectMapper by lazy { ObjectMapper() }
|
||||
|
||||
private val PLUGIN_MANAGER_URL = ApplicationInfoImpl.getShadowInstanceImpl().pluginManagerUrl.trimEnd('/')
|
||||
|
||||
private val COMPATIBLE_UPDATE_URL = "${PLUGIN_MANAGER_URL}/api/search/compatibleUpdates"
|
||||
|
||||
@JvmStatic
|
||||
fun getInstance(): MarketplaceRequests = PluginInfoProvider.getInstance() as MarketplaceRequests
|
||||
|
||||
@JvmStatic
|
||||
fun parsePluginList(reader: Reader): List<PluginNode> {
|
||||
fun parsePluginList(input: InputStream): List<PluginNode> {
|
||||
try {
|
||||
val parser = SAXParserFactory.newInstance().newSAXParser()
|
||||
val handler = RepositoryContentHandler()
|
||||
parser.parse(InputSource(reader), handler)
|
||||
SAXParserFactory.newDefaultInstance().newSAXParser().parse(InputSource(input), handler)
|
||||
return handler.pluginsList
|
||||
}
|
||||
catch (e: Exception) {
|
||||
@@ -101,7 +97,7 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
|
||||
val data = objectMapper.writeValueAsString(CompatibleUpdateRequest(ids, buildNumber))
|
||||
return HttpRequests
|
||||
.post(Urls.newFromEncoded(COMPATIBLE_UPDATE_URL).toExternalForm(), HttpRequests.JSON_CONTENT_TYPE)
|
||||
.post(Urls.newFromEncoded(compatibleUpdateUrl).toExternalForm(), HttpRequests.JSON_CONTENT_TYPE)
|
||||
.productNameAsUserAgent()
|
||||
.throwStatusCodeException(false)
|
||||
.connect {
|
||||
@@ -128,7 +124,7 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
val updateMetadataFile = Paths.get(PathManager.getPluginTempPath(), "meta")
|
||||
return readOrUpdateFile(
|
||||
updateMetadataFile.resolve(ideCompatibleUpdate.externalUpdateId + ".json"),
|
||||
"$PLUGIN_MANAGER_URL/files/${ideCompatibleUpdate.externalPluginId}/${ideCompatibleUpdate.externalUpdateId}/meta.json",
|
||||
"$pluginManagerUrl/files/${ideCompatibleUpdate.externalPluginId}/${ideCompatibleUpdate.externalUpdateId}/meta.json",
|
||||
indicator,
|
||||
IdeBundle.message("progress.downloading.plugins.meta", xmlId)
|
||||
) {
|
||||
@@ -144,7 +140,7 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
url: String,
|
||||
indicator: ProgressIndicator?,
|
||||
@Nls indicatorMessage: String,
|
||||
parser: (Reader) -> T
|
||||
parser: (InputStream) -> T
|
||||
): T {
|
||||
val eTag = if (file == null) null else loadETagForFile(file)
|
||||
return HttpRequests
|
||||
@@ -160,7 +156,7 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
indicator?.checkCanceled()
|
||||
val connection = request.connection
|
||||
if (file != null && isNotModified(connection, file)) {
|
||||
return@connect Files.newBufferedReader(file).use(parser)
|
||||
return@connect Files.newInputStream(file).use(parser)
|
||||
}
|
||||
|
||||
if (indicator != null) {
|
||||
@@ -168,14 +164,14 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
indicator.text2 = indicatorMessage
|
||||
}
|
||||
if (file == null) {
|
||||
return@connect request.reader.use(parser)
|
||||
return@connect request.inputStream.use(parser)
|
||||
}
|
||||
|
||||
synchronized(this) {
|
||||
request.saveToFile(file, indicator)
|
||||
connection.getHeaderField("ETag")?.let { saveETagForFile(file, it) }
|
||||
}
|
||||
return@connect Files.newBufferedReader(file).use(parser)
|
||||
return@connect Files.newInputStream(file).use(parser)
|
||||
}
|
||||
catch (e: HttpRequests.HttpStatusException) {
|
||||
LOG.infoWithDebug("Cannot load data from ${url} (statusCode=${e.statusCode})", e)
|
||||
@@ -194,22 +190,22 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
|
||||
private val IDE_BUILD_FOR_REQUEST = URLUtil.encodeURIComponent(ApplicationInfoImpl.getShadowInstanceImpl().pluginsCompatibleBuild)
|
||||
|
||||
private val MARKETPLACE_ORGANIZATIONS_URL = Urls.newFromEncoded("${PLUGIN_MANAGER_URL}/api/search/aggregation/organizations")
|
||||
private val MARKETPLACE_ORGANIZATIONS_URL = Urls.newFromEncoded("${pluginManagerUrl}/api/search/aggregation/organizations")
|
||||
.addParameters(mapOf("build" to IDE_BUILD_FOR_REQUEST))
|
||||
|
||||
private val JETBRAINS_PLUGINS_URL = Urls.newFromEncoded(
|
||||
"${PLUGIN_MANAGER_URL}/api/search/plugins?organization=JetBrains&max=1000"
|
||||
"${pluginManagerUrl}/api/search/plugins?organization=JetBrains&max=1000"
|
||||
).addParameters(mapOf("build" to IDE_BUILD_FOR_REQUEST))
|
||||
|
||||
private val IDE_EXTENSIONS_URL = Urls.newFromEncoded("${PLUGIN_MANAGER_URL}/files/IDE/extensions.json")
|
||||
private val IDE_EXTENSIONS_URL = Urls.newFromEncoded("${pluginManagerUrl}/files/IDE/extensions.json")
|
||||
.addParameters(mapOf("build" to IDE_BUILD_FOR_REQUEST))
|
||||
|
||||
private fun createSearchUrl(query: String, count: Int): Url {
|
||||
return Urls.newFromEncoded("$PLUGIN_MANAGER_URL/api/search/plugins?$query&build=$IDE_BUILD_FOR_REQUEST&max=$count")
|
||||
return Urls.newFromEncoded("$pluginManagerUrl/api/search/plugins?$query&build=$IDE_BUILD_FOR_REQUEST&max=$count")
|
||||
}
|
||||
|
||||
private fun createFeatureUrl(param: Map<String, String>): Url {
|
||||
return Urls.newFromEncoded("${PLUGIN_MANAGER_URL}/feature/getImplementations").addParameters(param)
|
||||
return Urls.newFromEncoded("${pluginManagerUrl}/feature/getImplementations").addParameters(param)
|
||||
}
|
||||
|
||||
fun getFeatures(param: Map<String, String>): List<FeatureImpl> {
|
||||
@@ -252,8 +248,8 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
@Throws(IOException::class)
|
||||
fun getMarketplacePlugins(indicator: ProgressIndicator? = null): Set<PluginId> {
|
||||
return readOrUpdateFile(
|
||||
Paths.get(PathManager.getPluginTempPath(), FULL_PLUGINS_XML_IDS_FILENAME),
|
||||
"${PLUGIN_MANAGER_URL}/files/$FULL_PLUGINS_XML_IDS_FILENAME",
|
||||
Path.of(PathManager.getPluginTempPath(), FULL_PLUGINS_XML_IDS_FILENAME),
|
||||
"${pluginManagerUrl}/files/$FULL_PLUGINS_XML_IDS_FILENAME",
|
||||
indicator,
|
||||
IdeBundle.message("progress.downloading.available.plugins"),
|
||||
::parseXmlIds,
|
||||
@@ -276,7 +272,7 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
val pluginXmlIdsFile = Paths.get(PathManager.getPluginTempPath(), FULL_PLUGINS_XML_IDS_FILENAME)
|
||||
try {
|
||||
if (Files.size(pluginXmlIdsFile) > 0) {
|
||||
return Files.newBufferedReader(pluginXmlIdsFile).use(::parseXmlIds)
|
||||
return Files.newInputStream(pluginXmlIdsFile).use(::parseXmlIds)
|
||||
}
|
||||
}
|
||||
catch (ignore: IOException) {
|
||||
@@ -318,7 +314,7 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
val brokenPlugins = try {
|
||||
readOrUpdateFile(
|
||||
Paths.get(PathManager.getPluginTempPath(), "brokenPlugins.json"),
|
||||
"${PLUGIN_MANAGER_URL}/files/brokenPlugins.json",
|
||||
"${pluginManagerUrl}/files/brokenPlugins.json",
|
||||
null,
|
||||
""
|
||||
) { objectMapper.readValue(it, object : TypeReference<List<MarketplaceBrokenPlugin>>() {}) }
|
||||
@@ -354,7 +350,7 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
try {
|
||||
return HttpRequests
|
||||
.request(Urls.newFromEncoded(
|
||||
"${PLUGIN_MANAGER_URL}/api/search/aggregation/tags"
|
||||
"${pluginManagerUrl}/api/search/aggregation/tags"
|
||||
).addParameters(mapOf("build" to IDE_BUILD_FOR_REQUEST)))
|
||||
.productNameAsUserAgent()
|
||||
.throwStatusCodeException(false)
|
||||
@@ -423,7 +419,7 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
val data = objectMapper.writeValueAsString(CompatibleUpdateForModuleRequest(module))
|
||||
|
||||
return HttpRequests.post(
|
||||
Urls.newFromEncoded(COMPATIBLE_UPDATE_URL).toExternalForm(),
|
||||
Urls.newFromEncoded(compatibleUpdateUrl).toExternalForm(),
|
||||
HttpRequests.JSON_CONTENT_TYPE,
|
||||
).productNameAsUserAgent()
|
||||
.throwStatusCodeException(false)
|
||||
@@ -499,8 +495,7 @@ class MarketplaceRequests : PluginInfoProvider {
|
||||
extensionsForIdes = objectMapper.readValue(stream, object : TypeReference<Map<String, List<String>>>() {})
|
||||
}
|
||||
|
||||
private fun parseXmlIds(reader: Reader) = objectMapper.readValue(reader, object : TypeReference<Set<PluginId>>() {})
|
||||
|
||||
private fun parseXmlIds(input: InputStream) = objectMapper.readValue(input, object : TypeReference<Set<PluginId>>() {})
|
||||
}
|
||||
|
||||
private fun loadETagForFile(file: Path): String {
|
||||
|
||||
+3
-3
@@ -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.ide.plugins.marketplace;
|
||||
|
||||
import com.intellij.ide.plugins.PluginManager;
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
* Plugin repository XML parser.
|
||||
* Supports both updates.xml and plugins.jetbrains.com formats.
|
||||
*/
|
||||
class RepositoryContentHandler extends DefaultHandler {
|
||||
final class RepositoryContentHandler extends DefaultHandler {
|
||||
@NonNls private static final String CATEGORY = "category";
|
||||
@NonNls private static final String PLUGIN = "plugin";
|
||||
@NonNls private static final String IDEA_PLUGIN = "idea-plugin";
|
||||
@@ -54,7 +54,7 @@ class RepositoryContentHandler extends DefaultHandler {
|
||||
|
||||
@NotNull
|
||||
List<PluginNode> getPluginsList() {
|
||||
return plugins != null ? plugins : Collections.emptyList();
|
||||
return plugins == null ? Collections.emptyList() : plugins;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// 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.ide.ui;
|
||||
|
||||
import com.intellij.idea.StartupUtil;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.extensions.PluginAware;
|
||||
import com.intellij.openapi.extensions.PluginDescriptor;
|
||||
import com.intellij.openapi.extensions.RequiredElement;
|
||||
import com.intellij.util.ResourceUtil;
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -42,7 +42,8 @@ public final class UIThemeProvider implements PluginAware {
|
||||
|
||||
@ApiStatus.Internal
|
||||
public byte[] getThemeJson() throws IOException {
|
||||
return StartupUtil.getResourceAsBytes(path.charAt(0) == '/' ? path.substring(1) : path, myPluginDescriptor.getClassLoader());
|
||||
@NotNull String path1 = path.charAt(0) == '/' ? path.substring(1) : path;
|
||||
return ResourceUtil.getResourceAsBytes(path1, myPluginDescriptor.getClassLoader());
|
||||
}
|
||||
|
||||
public @Nullable UITheme createTheme() {
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.intellij.diagnostic.LoadingState;
|
||||
import com.intellij.ide.IdeEventQueue;
|
||||
import com.intellij.ide.ui.UITheme;
|
||||
import com.intellij.ide.ui.laf.IdeaLaf;
|
||||
import com.intellij.idea.StartupUtil;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -16,6 +15,7 @@ import com.intellij.ui.TableActions;
|
||||
import com.intellij.ui.scale.JBUIScale;
|
||||
import com.intellij.ui.scale.ScaleContext;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.ResourceUtil;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.MultiResolutionImageProvider;
|
||||
import com.intellij.util.ui.StartupUiUtil;
|
||||
@@ -148,7 +148,7 @@ public class DarculaLaf extends BasicLookAndFeel implements UserDataHolder {
|
||||
private void patchStyledEditorKit(UIDefaults defaults) {
|
||||
String relativePath = getPrefix() + (JBUIScale.isUsrHiDPI() ? "@2x.css" : ".css");
|
||||
try {
|
||||
byte[] dataBytes = StartupUtil.getResourceAsBytes(relativePath, DarculaLaf.class.getClassLoader());
|
||||
byte[] dataBytes = ResourceUtil.getResourceAsBytes(relativePath, DarculaLaf.class.getClassLoader());
|
||||
if (dataBytes == null) {
|
||||
Logger.getInstance(DarculaLaf.class).error("Cannot find " + relativePath + " file");
|
||||
return;
|
||||
@@ -251,8 +251,11 @@ public class DarculaLaf extends BasicLookAndFeel implements UserDataHolder {
|
||||
try {
|
||||
// it is important to use class loader of a current instance class (LaF in plugin)
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
byte[] data = StartupUtil.getResourceAsBytes(filename, classLoader);
|
||||
assert data != null : "Can't load " + filename;
|
||||
// macOS light theme uses theme file from core plugin
|
||||
byte[] data = ResourceUtil.getResourceAsBytes(filename, classLoader, /* checkParents */ true);
|
||||
if (data == null) {
|
||||
throw new RuntimeException("Can't load " + filename);
|
||||
}
|
||||
UITheme theme = UITheme.loadFromJson(data, "Darcula", classLoader, Function.identity());
|
||||
theme.applyProperties(defaults);
|
||||
}
|
||||
|
||||
@@ -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.ide.util
|
||||
|
||||
import com.intellij.featureStatistics.FeatureDescriptor
|
||||
@@ -8,6 +8,7 @@ import com.intellij.ide.TipsOfTheDayUsagesCollector
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.*
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.util.ResourceUtil
|
||||
import com.intellij.util.text.DateFormatUtil
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import java.awt.EventQueue
|
||||
@@ -106,7 +107,7 @@ internal class TipsUsageManager : PersistentStateComponent<TipsUsageManager.Stat
|
||||
private fun readTipsUtility() : Map<String, Double> {
|
||||
assert(!EventQueue.isDispatchThread() || ApplicationManager.getApplication().isUnitTestMode)
|
||||
val classLoader = TipsUtilityHolder::class.java.classLoader
|
||||
val lines = classLoader.getResourceAsStream(TIPS_UTILITY_FILE)?.use { it.bufferedReader().readLines() }
|
||||
val lines = ResourceUtil.getResourceAsBytes(TIPS_UTILITY_FILE, classLoader)?.decodeToString()?.reader()?.readLines()
|
||||
if (lines == null) {
|
||||
LOG.error("Can't read resource file with tips utilities: $TIPS_UTILITY_FILE")
|
||||
return emptyMap()
|
||||
|
||||
@@ -36,7 +36,6 @@ import com.intellij.ui.scale.JBUIScale;
|
||||
import com.intellij.util.EnvironmentUtil;
|
||||
import com.intellij.util.PlatformUtils;
|
||||
import com.intellij.util.lang.Java11Shim;
|
||||
import com.intellij.util.lang.UrlClassLoader;
|
||||
import com.intellij.util.lang.ZipFilePool;
|
||||
import com.intellij.util.ui.StartupUiUtil;
|
||||
import com.intellij.util.ui.accessibility.ScreenReader;
|
||||
@@ -57,7 +56,6 @@ import java.awt.dnd.DragSource;
|
||||
import java.io.File;
|
||||
import java.io.IOError;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.management.ManagementFactory;
|
||||
@@ -985,15 +983,4 @@ public final class StartupUtil {
|
||||
return List.copyOf(collection);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte @Nullable [] getResourceAsBytes(@NotNull String path, @NotNull ClassLoader classLoader) throws IOException {
|
||||
if (classLoader instanceof UrlClassLoader) {
|
||||
return ((UrlClassLoader)classLoader).getResourceAsBytes(path);
|
||||
}
|
||||
else {
|
||||
try (InputStream stream = classLoader.getResourceAsStream(path)) {
|
||||
return stream == null ? null : stream.readAllBytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-11
@@ -44,6 +44,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.serviceContainer.NonInjectable;
|
||||
import com.intellij.util.ComponentTreeEventDispatcher;
|
||||
import com.intellij.util.ResourceUtil;
|
||||
import com.intellij.util.ui.StartupUiUtil;
|
||||
import com.intellij.util.xmlb.annotations.OptionTag;
|
||||
import org.jdom.Element;
|
||||
@@ -54,7 +55,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.UIManager.LookAndFeelInfo;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
@@ -380,7 +380,7 @@ public final class EditorColorsManagerImpl extends EditorColorsManager implement
|
||||
|
||||
public TextAttributes getDefaultAttributes(@NotNull TextAttributesKey key) {
|
||||
final boolean dark = StartupUiUtil.isUnderDarcula() && getScheme("Darcula") != null;
|
||||
// It is reasonable to fetch attributes from Default color scheme. Otherwise if we launch IDE and then
|
||||
// It is reasonable to fetch attributes from Default color scheme. Otherwise, if we launch IDE and then
|
||||
// try switch from custom colors scheme (e.g. with dark background) to default one. Editor will show
|
||||
// incorrect highlighting with "traces" of color scheme which was active during IDE startup.
|
||||
return getScheme(dark ? "Darcula" : EditorColorsScheme.DEFAULT_SCHEME_NAME).getAttributes(key);
|
||||
@@ -414,16 +414,15 @@ public final class EditorColorsManagerImpl extends EditorColorsManager implement
|
||||
private static void loadAdditionalTextAttributesForScheme(@NotNull AbstractColorsScheme scheme,
|
||||
@NotNull Collection<AdditionalTextAttributesEP> attributeEps) {
|
||||
for (AdditionalTextAttributesEP attributesEP : attributeEps) {
|
||||
InputStream resourceStream = attributesEP.pluginDescriptor
|
||||
.getClassLoader()
|
||||
.getResourceAsStream(StringUtil.trimStart(attributesEP.file, "/"));
|
||||
if (resourceStream == null) {
|
||||
LOG.warn("resource not found: " + attributesEP.file);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
Element root = JDOMUtil.load(resourceStream);
|
||||
byte[] data =
|
||||
ResourceUtil.getResourceAsBytes(Strings.trimStart(attributesEP.file, "/"), attributesEP.pluginDescriptor.getClassLoader());
|
||||
if (data == null) {
|
||||
LOG.warn("resource not found: " + attributesEP.file);
|
||||
continue;
|
||||
}
|
||||
|
||||
Element root = JDOMUtil.load(data);
|
||||
scheme.readAttributes(Objects.requireNonNullElse(root.getChild("attributes"), root));
|
||||
Element colors = root.getChild("colors");
|
||||
if (colors != null) {
|
||||
|
||||
+3
-4
@@ -42,7 +42,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.jps.model.fileTypes.FileNameMatcherFactory;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -297,9 +296,9 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
|
||||
}
|
||||
|
||||
try {
|
||||
InputStream defaultFileTypeStream = FileTypeManagerImpl.class.getClassLoader().getResourceAsStream("defaultFileTypes.xml");
|
||||
if (defaultFileTypeStream != null) {
|
||||
Element defaultFileTypesElement = JDOMUtil.load(defaultFileTypeStream);
|
||||
byte[] defaultFileTypeData = ResourceUtil.getResourceAsBytes("defaultFileTypes.xml", FileTypeManagerImpl.class.getClassLoader());
|
||||
if (defaultFileTypeData != null) {
|
||||
Element defaultFileTypesElement = JDOMUtil.load(defaultFileTypeData);
|
||||
IdeaPluginDescriptor coreIdeaPluginDescriptor = coreIdeaPluginDescriptor();
|
||||
for (Element e : defaultFileTypesElement.getChildren()) {
|
||||
if ("filetypes".equals(e.getName())) {
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
// 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.
|
||||
@file:Suppress("ReplacePutWithAssignment")
|
||||
|
||||
package com.intellij.openapi.keymap.impl
|
||||
|
||||
import com.intellij.configurationStore.SchemeDataHolder
|
||||
import com.intellij.diagnostic.PluginException
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.getOrLogException
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.diagnostic.runAndLogException
|
||||
import com.intellij.openapi.extensions.PluginDescriptor
|
||||
import com.intellij.openapi.keymap.Keymap
|
||||
import com.intellij.openapi.keymap.KeymapManager
|
||||
@@ -13,6 +16,7 @@ import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.openapi.util.SystemInfo
|
||||
import com.intellij.openapi.util.SystemInfoRt
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.util.ResourceUtil
|
||||
import org.jdom.Element
|
||||
import java.util.function.BiConsumer
|
||||
|
||||
@@ -39,13 +43,10 @@ open class DefaultKeymap {
|
||||
val filteredBeans = LinkedHashMap<BundledKeymapBean, PluginDescriptor>()
|
||||
|
||||
var macosParentKeymapFound = false
|
||||
val macOsBeans = if (SystemInfoRt.isMac)
|
||||
null
|
||||
else
|
||||
LinkedHashMap<BundledKeymapBean, PluginDescriptor>()
|
||||
val macOsBeans = if (SystemInfoRt.isMac) null else LinkedHashMap<BundledKeymapBean, PluginDescriptor>()
|
||||
|
||||
BundledKeymapBean.EP_NAME.processWithPluginDescriptor(BiConsumer { bean, pluginDescriptor ->
|
||||
val keymapName = bean.keymapName
|
||||
val keymapName = getKeymapName(bean)
|
||||
// filter out bundled keymaps for other systems, but allow them via non-bundled plugins
|
||||
// on non-macOS add non-bundled known macOS keymaps if the default macOS keymap is present
|
||||
if (!filterKeymaps || !pluginDescriptor.isBundled || !isBundledKeymapHidden(keymapName)) {
|
||||
@@ -58,7 +59,7 @@ open class DefaultKeymap {
|
||||
macosParentKeymapFound = macosParentKeymapFound || keymapName == KeymapManager.MAC_OS_X_10_5_PLUS_KEYMAP
|
||||
}
|
||||
|
||||
(if (isMacOsBean) macOsBeans!! else filteredBeans)[bean] = pluginDescriptor
|
||||
(if (isMacOsBean) macOsBeans!! else filteredBeans).put(bean, pluginDescriptor)
|
||||
}
|
||||
})
|
||||
if (macosParentKeymapFound && macOsBeans != null) {
|
||||
@@ -66,15 +67,19 @@ open class DefaultKeymap {
|
||||
}
|
||||
|
||||
for ((bean, pluginDescriptor) in filteredBeans) {
|
||||
LOG.runAndLogException {
|
||||
loadKeymap(bean.keymapName, object : SchemeDataHolder<KeymapImpl> {
|
||||
runCatching {
|
||||
loadKeymap(getKeymapName(bean), object : SchemeDataHolder<KeymapImpl> {
|
||||
override fun read(): Element {
|
||||
return pluginDescriptor.classLoader
|
||||
.getResourceAsStream(bean.effectiveFile)
|
||||
.use { JDOMUtil.load(it) }
|
||||
val effectiveFile = getEffectiveFile(bean)
|
||||
// java plugin defines keymap that located in a core plugin - so, we must check parents
|
||||
val data = ResourceUtil.getResourceAsBytes(effectiveFile, pluginDescriptor.classLoader, true)
|
||||
if (data == null) {
|
||||
throw PluginException("Cannot find $effectiveFile", pluginDescriptor.pluginId)
|
||||
}
|
||||
return JDOMUtil.load(data)
|
||||
}
|
||||
}, pluginDescriptor)
|
||||
}
|
||||
}.getOrLogException(LOG)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,27 +139,31 @@ open class DefaultKeymap {
|
||||
}
|
||||
}
|
||||
|
||||
internal val BundledKeymapBean.effectiveFile: String
|
||||
get() = "keymaps/${file.replace("\$OS\$", osName())}"
|
||||
internal fun getEffectiveFile(bean: BundledKeymapBean) = "keymaps/${bean.file.replace("\$OS\$", osName())}"
|
||||
|
||||
internal val BundledKeymapBean.keymapName: String
|
||||
get() = FileUtilRt.getNameWithoutExtension(file).removePrefix("\$OS\$/")
|
||||
internal fun getKeymapName(bean: BundledKeymapBean) = FileUtilRt.getNameWithoutExtension(bean.file).removePrefix("\$OS\$/")
|
||||
|
||||
private fun osName(): String = when {
|
||||
SystemInfo.isMac -> "macos"
|
||||
SystemInfo.isWindows -> "windows"
|
||||
SystemInfo.isLinux -> "linux"
|
||||
else -> "other"
|
||||
private fun osName(): String {
|
||||
return when {
|
||||
SystemInfoRt.isMac -> "macos"
|
||||
SystemInfoRt.isWindows -> "windows"
|
||||
SystemInfoRt.isLinux -> "linux"
|
||||
else -> "other"
|
||||
}
|
||||
}
|
||||
|
||||
private fun isKnownLinuxKeymap(keymapName: String?) = when (keymapName) {
|
||||
KeymapManager.X_WINDOW_KEYMAP, KeymapManager.GNOME_KEYMAP, KeymapManager.KDE_KEYMAP -> true
|
||||
else -> false
|
||||
private fun isKnownLinuxKeymap(keymapName: String?): Boolean {
|
||||
return when (keymapName) {
|
||||
KeymapManager.X_WINDOW_KEYMAP, KeymapManager.GNOME_KEYMAP, KeymapManager.KDE_KEYMAP -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private fun isKnownMacOSKeymap(keymapName: String?) = when (keymapName) {
|
||||
KeymapManager.MAC_OS_X_KEYMAP, KeymapManager.MAC_OS_X_10_5_PLUS_KEYMAP, "macOS System Shortcuts",
|
||||
"Eclipse (Mac OS X)", "Sublime Text (Mac OS X)", "Xcode", "ReSharper OSX",
|
||||
"Visual Studio OSX", "Visual Assist OSX", "Visual Studio for Mac", "VSCode OSX", "QtCreator (Mac OS X)" -> true
|
||||
else -> false
|
||||
private fun isKnownMacOSKeymap(keymapName: String?): Boolean {
|
||||
return when (keymapName) {
|
||||
KeymapManager.MAC_OS_X_KEYMAP, KeymapManager.MAC_OS_X_10_5_PLUS_KEYMAP, "macOS System Shortcuts",
|
||||
"Eclipse (Mac OS X)", "Sublime Text (Mac OS X)", "Xcode", "ReSharper OSX",
|
||||
"Visual Studio OSX", "Visual Assist OSX", "Visual Studio for Mac", "VSCode OSX", "QtCreator (Mac OS X)" -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
// 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.
|
||||
@file:Suppress("ReplaceGetOrSet")
|
||||
|
||||
package com.intellij.openapi.keymap.impl
|
||||
|
||||
import com.intellij.configurationStore.LazySchemeProcessor
|
||||
@@ -21,6 +23,7 @@ import com.intellij.openapi.options.SchemeManagerFactory
|
||||
import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.openapi.util.text.NaturalComparator
|
||||
import com.intellij.ui.AppUIUtil
|
||||
import com.intellij.util.ResourceUtil
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jdom.Element
|
||||
import java.util.function.Function
|
||||
@@ -31,7 +34,9 @@ internal const val KEYMAPS_DIR_PATH = "keymaps"
|
||||
private const val ACTIVE_KEYMAP = "active_keymap"
|
||||
private const val NAME_ATTRIBUTE = "name"
|
||||
|
||||
@State(name = "KeymapManager", storages = [(Storage(value = "keymap.xml", roamingType = RoamingType.PER_OS))], additionalExportDirectory = KEYMAPS_DIR_PATH, category = SettingsCategory.KEYMAP)
|
||||
@State(name = "KeymapManager", storages = [(Storage(value = "keymap.xml", roamingType = RoamingType.PER_OS))],
|
||||
additionalExportDirectory = KEYMAPS_DIR_PATH,
|
||||
category = SettingsCategory.KEYMAP)
|
||||
class KeymapManagerImpl : KeymapManagerEx(), PersistentStateComponent<Element> {
|
||||
private val listeners = ContainerUtil.createLockFreeCopyOnWriteList<KeymapManagerListener>()
|
||||
private val boundShortcuts = HashMap<String, String>()
|
||||
@@ -99,16 +104,16 @@ class KeymapManagerImpl : KeymapManagerEx(), PersistentStateComponent<Element> {
|
||||
|
||||
BundledKeymapBean.EP_NAME.addExtensionPointListener(object : ExtensionPointListener<BundledKeymapBean> {
|
||||
override fun extensionAdded(ep: BundledKeymapBean, pluginDescriptor: PluginDescriptor) {
|
||||
val keymapName = ep.keymapName
|
||||
val keymapName = getKeymapName(ep)
|
||||
//if (!SystemInfo.isMac &&
|
||||
// keymapName != KeymapManager.MAC_OS_X_KEYMAP &&
|
||||
// keymapName != KeymapManager.MAC_OS_X_10_5_PLUS_KEYMAP &&
|
||||
// DefaultKeymap.isBundledKeymapHidden(keymapName) &&
|
||||
// schemeManager.findSchemeByName(KeymapManager.MAC_OS_X_10_5_PLUS_KEYMAP) == null) return
|
||||
val keymap = DefaultKeymap.getInstance().loadKeymap(keymapName, object : SchemeDataHolder<KeymapImpl> {
|
||||
override fun read() = pluginDescriptor.classLoader
|
||||
.getResourceAsStream(ep.effectiveFile)
|
||||
.use { JDOMUtil.load(it) }
|
||||
override fun read(): Element {
|
||||
return JDOMUtil.load(ResourceUtil.getResourceAsBytes(getEffectiveFile(ep), pluginDescriptor.classLoader))
|
||||
}
|
||||
}, pluginDescriptor)
|
||||
schemeManager.addScheme(keymap)
|
||||
fireKeymapAdded(keymap)
|
||||
@@ -116,7 +121,7 @@ class KeymapManagerImpl : KeymapManagerEx(), PersistentStateComponent<Element> {
|
||||
}
|
||||
|
||||
override fun extensionRemoved(ep: BundledKeymapBean, pluginDescriptor: PluginDescriptor) {
|
||||
removeKeymap(ep.keymapName)
|
||||
removeKeymap(getKeymapName(ep))
|
||||
}
|
||||
}, null)
|
||||
}
|
||||
|
||||
@@ -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.wm.impl;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -508,8 +508,7 @@ final class PaintersHelper implements Painter.Listener {
|
||||
ImageLoader.ALLOW_FLOAT_SCALING, ScaleContext.create(),
|
||||
true,
|
||||
!isSvg, 1,
|
||||
isSvg,
|
||||
new ImageLoader.Dimension2DDouble(image.getWidth(null), image.getHeight(null)));
|
||||
isSvg);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.warn(e);
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
// 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.
|
||||
// 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.ide.plugins;
|
||||
|
||||
import com.intellij.openapi.extensions.PluginId;
|
||||
import com.intellij.openapi.util.BuildNumber;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.testFramework.ApplicationRule;
|
||||
import com.intellij.testFramework.rules.TempDirectory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -21,7 +23,11 @@ import java.util.Set;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class RepositoryHelperTest {
|
||||
@Rule public TempDirectory tempDir = new TempDirectory();
|
||||
@Rule
|
||||
public TempDirectory tempDir = new TempDirectory();
|
||||
|
||||
@ClassRule
|
||||
public static final ApplicationRule appRule = new ApplicationRule();
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void testEmpty() throws IOException {
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
// 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.
|
||||
// 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.execution.testframework.sm.runner.history;
|
||||
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
@@ -63,7 +63,7 @@ public class ImportedToGeneralTestEventsConverter extends OutputToGeneralTestEve
|
||||
|
||||
public static void parseTestResults(Supplier<? extends Reader> readerSupplier, GeneralTestEventsProcessor processor) throws IOException {
|
||||
try (Reader reader = readerSupplier.get()) {
|
||||
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
|
||||
SAXParser parser = SAXParserFactory.newDefaultInstance().newSAXParser();
|
||||
parser.parse(new InputSource(reader), ImportTestOutputExtension.findHandler(readerSupplier, processor));
|
||||
}
|
||||
catch (ParserConfigurationException | SAXException e) {
|
||||
|
||||
+1
-1
@@ -153,7 +153,7 @@ public abstract class AbstractImportTestsAction extends AnAction {
|
||||
myProject = project;
|
||||
class TerminateParsingException extends SAXException { }
|
||||
try (InputStream inputStream = new BufferedInputStream(new FileInputStream(VfsUtilCore.virtualToIoFile(myFile)))) {
|
||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
SAXParserFactory factory = SAXParserFactory.newDefaultInstance();
|
||||
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
factory.newSAXParser().parse(inputStream, new DefaultHandler() {
|
||||
boolean isConfigContent = false;
|
||||
|
||||
@@ -299,7 +299,7 @@ public class UrlClassLoader extends ClassLoader implements ClassPath.ClassDataCo
|
||||
return resource != null ? resource.getURL() : null;
|
||||
}
|
||||
|
||||
public final byte @Nullable [] getResourceAsBytes(@NotNull String name) throws IOException {
|
||||
public byte @Nullable [] getResourceAsBytes(@NotNull String name, boolean checkParents) throws IOException {
|
||||
Resource resource = classPath.findResource(name);
|
||||
return resource == null ? null : resource.getBytes();
|
||||
}
|
||||
|
||||
@@ -19,5 +19,6 @@
|
||||
<orderEntry type="library" name="netty-buffer" level="project" />
|
||||
<orderEntry type="library" name="caffeine" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.base" />
|
||||
<orderEntry type="module" module-name="intellij.platform.util.classLoader" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,12 +1,13 @@
|
||||
// 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.util;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.util.text.Strings;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import com.intellij.util.lang.UrlClassLoader;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -20,6 +21,27 @@ public final class ResourceUtil {
|
||||
private ResourceUtil() {
|
||||
}
|
||||
|
||||
public static byte @Nullable [] getResourceAsBytes(@NotNull String path, @NotNull ClassLoader classLoader) throws IOException {
|
||||
return getResourceAsBytes(path, classLoader, false);
|
||||
}
|
||||
|
||||
public static byte @Nullable [] getResourceAsBytes(@NotNull String path,
|
||||
@NotNull ClassLoader classLoader,
|
||||
boolean checkParents) throws IOException {
|
||||
if (classLoader instanceof UrlClassLoader) {
|
||||
return ((UrlClassLoader)classLoader).getResourceAsBytes(path, checkParents);
|
||||
}
|
||||
|
||||
InputStream stream = classLoader.getResourceAsStream(path);
|
||||
if (stream == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try (stream) {
|
||||
return stream.readAllBytes();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #getResourceAsStream(ClassLoader, String, String)}
|
||||
*/
|
||||
@@ -39,7 +61,7 @@ public final class ResourceUtil {
|
||||
}
|
||||
|
||||
public static InputStream getResourceAsStream(@NotNull ClassLoader loader, @NonNls @NotNull String basePath, @NonNls @NotNull String fileName) {
|
||||
String fixedPath = StringUtil.trimStart(Strings.trimEnd(basePath, "/"), "/");
|
||||
String fixedPath = Strings.trimStart(Strings.trimEnd(basePath, "/"), "/");
|
||||
if (fixedPath.isEmpty()) {
|
||||
return loader.getResourceAsStream(fileName);
|
||||
}
|
||||
@@ -57,7 +79,7 @@ public final class ResourceUtil {
|
||||
}
|
||||
|
||||
public static URL getResource(@NotNull ClassLoader loader, @NonNls @NotNull String basePath, @NonNls @NotNull String fileName) {
|
||||
String fixedPath = StringUtil.trimStart(Strings.trimEnd(basePath, "/"), "/");
|
||||
String fixedPath = Strings.trimStart(Strings.trimEnd(basePath, "/"), "/");
|
||||
|
||||
List<String> bundles = calculateBundleNames(fixedPath, Locale.getDefault());
|
||||
for (String bundle : bundles) {
|
||||
|
||||
@@ -196,7 +196,7 @@ public class AbstractBundle {
|
||||
}
|
||||
|
||||
if (loader instanceof UrlClassLoader) {
|
||||
byte[] data = ((UrlClassLoader)loader).getResourceAsBytes(resourceName);
|
||||
byte[] data = ((UrlClassLoader)loader).getResourceAsBytes(resourceName, false);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -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.openapi.util;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -247,7 +247,7 @@ public final class JDOMUtil {
|
||||
/**
|
||||
* @deprecated Use {@link #load(CharSequence)}
|
||||
* <p>
|
||||
* Direct usage of element allows to get rid of {@link Document#getRootElement()} because only Element is required in mostly all cases.
|
||||
* Direct usage of element allows getting rid of {@link Document#getRootElement()} because only Element is required in mostly all cases.
|
||||
*/
|
||||
@Deprecated
|
||||
public static @NotNull Document loadDocument(@NotNull Reader reader) throws IOException, JDOMException {
|
||||
@@ -324,6 +324,21 @@ public final class JDOMUtil {
|
||||
return stream == null ? null : loadUsingStaX(stream, null);
|
||||
}
|
||||
|
||||
public static @NotNull Element load(byte @NotNull [] data) throws JDOMException, IOException {
|
||||
try {
|
||||
XMLStreamReader2 xmlStreamReader = StaxFactory.createXmlStreamReader(data);
|
||||
try {
|
||||
return SafeStAXStreamBuilder.build(xmlStreamReader, true, true, null == null ? SafeStAXStreamBuilder.FACTORY : null);
|
||||
}
|
||||
finally {
|
||||
xmlStreamReader.close();
|
||||
}
|
||||
}
|
||||
catch (XMLStreamException e) {
|
||||
throw new JDOMException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static @NotNull Element load(@NotNull InputStream stream, @Nullable SafeJdomFactory factory) throws JDOMException, IOException {
|
||||
return loadUsingStaX(stream, factory);
|
||||
|
||||
@@ -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.svg
|
||||
|
||||
import com.intellij.openapi.util.createXmlStreamReader
|
||||
@@ -9,6 +9,7 @@ import org.apache.batik.dom.GenericCDATASection
|
||||
import org.apache.batik.dom.GenericText
|
||||
import org.apache.batik.transcoder.TranscoderException
|
||||
import org.apache.batik.util.ParsedURL
|
||||
import org.codehaus.stax2.XMLStreamReader2
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Element
|
||||
@@ -19,8 +20,12 @@ import javax.xml.stream.XMLStreamException
|
||||
import javax.xml.stream.XMLStreamReader
|
||||
|
||||
@ApiStatus.Internal
|
||||
fun createSvgDocument(uri: String?, reader: InputStream): Document {
|
||||
val xmlStreamReader = createXmlStreamReader(reader)
|
||||
fun createSvgDocument(uri: String?, reader: InputStream) = createSvgDocument(uri, createXmlStreamReader(reader))
|
||||
|
||||
@ApiStatus.Internal
|
||||
fun createSvgDocument(uri: String?, data: ByteArray) = createSvgDocument(uri, createXmlStreamReader(data))
|
||||
|
||||
private fun createSvgDocument(uri: String?, xmlStreamReader: XMLStreamReader2): Document {
|
||||
val result = try {
|
||||
buildDocument(xmlStreamReader)
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@file:Suppress("UndesirableClassUsage")
|
||||
|
||||
package com.intellij.ui.svg
|
||||
@@ -170,7 +170,7 @@ class SvgTranscoder private constructor(private var width: Float, private var he
|
||||
" <line x1=\"1\" y1=\"1\" x2=\"15\" y2=\"15\" stroke=\"red\" stroke-width=\"2\"/>\n" +
|
||||
" <line x1=\"1\" y1=\"15\" x2=\"15\" y2=\"1\" stroke=\"red\" stroke-width=\"2\"/>\n" +
|
||||
"</svg>\n"
|
||||
return createSvgDocument(null, fallbackIcon.byteInputStream()) as SVGDocument
|
||||
return createSvgDocument(null, fallbackIcon.toByteArray()) as SVGDocument
|
||||
}
|
||||
|
||||
override fun getTransform() = currentTransform!!
|
||||
|
||||
@@ -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.util;
|
||||
|
||||
import com.intellij.diagnostic.StartUpMeasurer;
|
||||
@@ -31,12 +31,17 @@ import java.awt.image.BufferedImage;
|
||||
import java.awt.image.BufferedImageOp;
|
||||
import java.awt.image.FilteredImageSource;
|
||||
import java.awt.image.ImageFilter;
|
||||
import java.io.*;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -158,7 +163,7 @@ public final class ImageLoader {
|
||||
if (start != -1) {
|
||||
IconLoadMeasurer.addLoading(descriptor.isSvg, start);
|
||||
}
|
||||
return convertImage(image, filters, flags, scaleContext, isUpScaleNeeded, isHiDpiNeeded, descriptor.scale, descriptor.isSvg, originalUserSize);
|
||||
return convertImage(image, filters, flags, scaleContext, isUpScaleNeeded, isHiDpiNeeded, descriptor.scale, descriptor.isSvg);
|
||||
}
|
||||
catch (IOException e) {
|
||||
ioExceptionThrown = true;
|
||||
@@ -186,8 +191,8 @@ public final class ImageLoader {
|
||||
if (image == null) {
|
||||
continue;
|
||||
}
|
||||
return convertImage(image, Collections.emptyList(), flags, scaleContext, isUpScaleNeeded, isHiDpiNeeded, descriptor.scale, descriptor.isSvg,
|
||||
originalUserSize);
|
||||
return convertImage(image, Collections.emptyList(), flags, scaleContext, isUpScaleNeeded, isHiDpiNeeded, descriptor.scale, descriptor.isSvg
|
||||
);
|
||||
}
|
||||
catch (IOException ignore) {
|
||||
}
|
||||
@@ -285,29 +290,34 @@ public final class ImageLoader {
|
||||
return image;
|
||||
}
|
||||
|
||||
static @Nullable InputStream getResourceData(@NotNull String path, @Nullable Class<?> resourceClass, @Nullable ClassLoader classLoader) {
|
||||
static byte @Nullable [] getResourceData(@NotNull String path, @Nullable Class<?> resourceClass, @Nullable ClassLoader classLoader)
|
||||
throws IOException {
|
||||
assert resourceClass != null || classLoader != null || path.startsWith("file://");
|
||||
|
||||
if (classLoader != null) {
|
||||
InputStream stream = classLoader.getResourceAsStream(path.startsWith("/") ? path.substring(1) : path);
|
||||
if (stream != null) {
|
||||
return stream;
|
||||
boolean isAbsolute = path.startsWith("/");
|
||||
byte[] data = ResourceUtil.getResourceAsBytes(isAbsolute ? path.substring(1) : path, classLoader);
|
||||
if (data != null || isAbsolute) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
if (resourceClass != null) {
|
||||
return resourceClass.getResourceAsStream(path);
|
||||
try (InputStream stream = resourceClass.getResourceAsStream(path)) {
|
||||
return stream == null ? null : stream.readAllBytes();
|
||||
}
|
||||
}
|
||||
|
||||
if (path.startsWith("file:/")) {
|
||||
Path nioPath = Paths.get(URI.create(path));
|
||||
if (Files.exists(nioPath)) {
|
||||
try {
|
||||
return Files.newInputStream(nioPath);
|
||||
}
|
||||
catch (IOException e) {
|
||||
getLogger().warn(e);
|
||||
}
|
||||
Path nioPath = Path.of(URI.create(path));
|
||||
try {
|
||||
return Files.readAllBytes(nioPath);
|
||||
}
|
||||
catch (NoSuchFileException e) {
|
||||
return null;
|
||||
}
|
||||
catch (IOException e) {
|
||||
getLogger().warn(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -319,14 +329,11 @@ public final class ImageLoader {
|
||||
@Nullable ClassLoader classLoader,
|
||||
double scale,
|
||||
@NotNull Dimension2DDouble originalUserSize) throws IOException {
|
||||
InputStream stream = getResourceData(path, resourceClass, classLoader);
|
||||
if (stream == null) {
|
||||
byte[] data = getResourceData(path, resourceClass, classLoader);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try (stream) {
|
||||
return loadPng(stream, scale, originalUserSize);
|
||||
}
|
||||
return loadPng(new ByteArrayInputStream(data), scale, originalUserSize);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
@@ -364,7 +371,7 @@ public final class ImageLoader {
|
||||
}
|
||||
|
||||
// originalUserSize - The original user space size of the image. In case of SVG it's the size specified in the SVG doc.
|
||||
// Otherwise it's the size of the original image divided by the image's scale (defined by the extension @2x).
|
||||
// Otherwise, it's the size of the original image divided by the image's scale (defined by the extension @2x).
|
||||
public static @Nullable Image convertImage(@NotNull Image image,
|
||||
@NotNull List<? extends ImageFilter> filters,
|
||||
@MagicConstant(flagsFromClass = ImageLoader.class) int flags,
|
||||
@@ -372,8 +379,7 @@ public final class ImageLoader {
|
||||
boolean isUpScaleNeeded,
|
||||
boolean isHiDpiNeeded,
|
||||
double imageScale,
|
||||
boolean isSvg,
|
||||
@NotNull ImageLoader.Dimension2DDouble originalUserSize) {
|
||||
boolean isSvg) {
|
||||
if (isUpScaleNeeded && !isSvg) {
|
||||
double scale = adjustScaleFactor((flags & ALLOW_FLOAT_SCALING) == ALLOW_FLOAT_SCALING, (float)scaleContext.getScale(DerivedScaleType.PIX_SCALE));
|
||||
if (imageScale > 1) {
|
||||
|
||||
@@ -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.util;
|
||||
|
||||
import com.intellij.diagnostic.StartUpMeasurer;
|
||||
@@ -16,6 +16,7 @@ import com.intellij.ui.svg.SvgCacheManager;
|
||||
import com.intellij.ui.svg.SvgDocumentFactoryKt;
|
||||
import com.intellij.ui.svg.SvgPrebuiltCacheManager;
|
||||
import com.intellij.ui.svg.SvgTranscoder;
|
||||
import com.intellij.util.ui.EDT;
|
||||
import com.intellij.util.ui.ImageUtil;
|
||||
import org.apache.batik.transcoder.TranscoderException;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@@ -43,10 +44,10 @@ public final class SVGLoader {
|
||||
private static final boolean USE_CACHE = Boolean.parseBoolean(System.getProperty("idea.ui.icons.svg.disk.cache", "true"));
|
||||
|
||||
private static SvgElementColorPatcherProvider ourColorPatcher;
|
||||
private static SvgElementColorPatcherProvider ourSelectionColorPatcher;
|
||||
private static SvgElementColorPatcherProvider ourContextColorPatcher;
|
||||
private static SvgElementColorPatcherProvider selectionColorPatcher;
|
||||
private static SvgElementColorPatcherProvider contextColorPatcher;
|
||||
|
||||
private static volatile boolean ourIsColorRedefinitionContext = false;
|
||||
private static volatile boolean isColorRedefinitionContext;
|
||||
|
||||
private static final class SvgCache {
|
||||
private static final SvgCacheManager persistentCache;
|
||||
@@ -119,9 +120,8 @@ public final class SVGLoader {
|
||||
float scale,
|
||||
boolean isDark,
|
||||
@NotNull ImageLoader.Dimension2DDouble docSize /*OUT*/) throws IOException {
|
||||
byte[] svgBytes = null;
|
||||
byte[] theme ;
|
||||
InputStream stream = null;
|
||||
byte[] theme;
|
||||
byte[] data = null;
|
||||
|
||||
if (USE_CACHE && !isColorRedefinitionContext()) {
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@@ -149,23 +149,15 @@ public final class SVGLoader {
|
||||
}
|
||||
}
|
||||
|
||||
stream = ImageLoader.getResourceData(path, resourceClass, classLoader);
|
||||
if (stream == null) {
|
||||
data = ImageLoader.getResourceData(path, resourceClass, classLoader);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
svgBytes = stream.readAllBytes();
|
||||
}
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
image = SvgCache.persistentCache.loadFromCache(theme, svgBytes, scale, isDark, docSize);
|
||||
image = SvgCache.persistentCache.loadFromCache(theme, data, scale, isDark, docSize);
|
||||
if (image != null) {
|
||||
return image;
|
||||
}
|
||||
|
||||
stream = new ByteArrayInputStream(svgBytes);
|
||||
}
|
||||
|
||||
if (start != -1) {
|
||||
@@ -176,13 +168,13 @@ public final class SVGLoader {
|
||||
theme = null;
|
||||
}
|
||||
|
||||
if (stream == null) {
|
||||
stream = ImageLoader.getResourceData(path, resourceClass, classLoader);
|
||||
if (stream == null) {
|
||||
if (data == null) {
|
||||
data = ImageLoader.getResourceData(path, resourceClass, classLoader);
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return loadAndCache(path, stream, scale, docSize, theme, svgBytes);
|
||||
return loadAndCache(path, data, scale, docSize, theme);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
@@ -196,7 +188,7 @@ public final class SVGLoader {
|
||||
}
|
||||
|
||||
byte[] theme = null;
|
||||
byte[] svgBytes = null;
|
||||
byte[] data;
|
||||
Image image;
|
||||
|
||||
if (USE_CACHE && !isColorRedefinitionContext()) {
|
||||
@@ -210,32 +202,36 @@ public final class SVGLoader {
|
||||
}
|
||||
}
|
||||
|
||||
if (theme != null) {
|
||||
svgBytes = stream.readAllBytes();
|
||||
image = SvgCache.persistentCache.loadFromCache(theme, svgBytes, scale, isDark, docSize);
|
||||
if (theme == null) {
|
||||
data = null;
|
||||
}
|
||||
else {
|
||||
data = stream.readAllBytes();
|
||||
image = SvgCache.persistentCache.loadFromCache(theme, data, scale, isDark, docSize);
|
||||
if (image != null) {
|
||||
return image;
|
||||
}
|
||||
stream = new ByteArrayInputStream(svgBytes);
|
||||
}
|
||||
|
||||
if (start != -1) {
|
||||
IconLoadMeasurer.svgCacheRead.end(start);
|
||||
}
|
||||
}
|
||||
return loadAndCache(path, stream, scale, docSize, theme, svgBytes);
|
||||
else {
|
||||
data = stream.readAllBytes();
|
||||
}
|
||||
return loadAndCache(path, data, scale, docSize, theme);
|
||||
}
|
||||
|
||||
private static @NotNull BufferedImage loadAndCache(@Nullable String path,
|
||||
@NotNull InputStream stream,
|
||||
byte[] data,
|
||||
float scale,
|
||||
@NotNull ImageLoader.Dimension2DDouble docSize,
|
||||
byte[] theme,
|
||||
byte[] svgBytes) throws IOException {
|
||||
byte[] theme) throws IOException {
|
||||
long decodingStart = StartUpMeasurer.getCurrentTimeIfEnabled();
|
||||
BufferedImage bufferedImage;
|
||||
try {
|
||||
bufferedImage = SvgTranscoder.createImage(scale, createDocument(path, stream), docSize);
|
||||
bufferedImage = SvgTranscoder.createImage(scale, createDocument(path, data), docSize);
|
||||
}
|
||||
catch (TranscoderException e) {
|
||||
docSize.setSize(0, 0);
|
||||
@@ -249,7 +245,7 @@ public final class SVGLoader {
|
||||
if (theme != null) {
|
||||
try {
|
||||
long cacheWriteStart = StartUpMeasurer.getCurrentTimeIfEnabled();
|
||||
SvgCache.persistentCache.storeLoadedImage(theme, svgBytes, scale, bufferedImage, docSize);
|
||||
SvgCache.persistentCache.storeLoadedImage(theme, data, scale, bufferedImage, docSize);
|
||||
IconLoadMeasurer.svgCacheWrite.end(cacheWriteStart);
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -330,6 +326,12 @@ public final class SVGLoader {
|
||||
return document;
|
||||
}
|
||||
|
||||
private static @NotNull Document createDocument(@Nullable String url, byte[] data) {
|
||||
Document document = SvgDocumentFactoryKt.createSvgDocument(url, data);
|
||||
patchColors(url, document);
|
||||
return document;
|
||||
}
|
||||
|
||||
private static void patchColors(@Nullable String url, @NotNull Document document) {
|
||||
SvgElementColorPatcherProvider colorPatcher = ourColorPatcher;
|
||||
if (colorPatcher != null) {
|
||||
@@ -350,11 +352,11 @@ public final class SVGLoader {
|
||||
}
|
||||
|
||||
public static void setContextColorPatcher(@Nullable SvgElementColorPatcherProvider provider) {
|
||||
ourContextColorPatcher = provider;
|
||||
contextColorPatcher = provider;
|
||||
}
|
||||
|
||||
private static SvgElementColorPatcherProvider getColorPatcherProvider() {
|
||||
return ourContextColorPatcher;
|
||||
return contextColorPatcher;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -428,27 +430,28 @@ public final class SVGLoader {
|
||||
}
|
||||
|
||||
public static void setSelectionColorPatcherProvider(@Nullable SvgElementColorPatcherProvider colorPatcher) {
|
||||
ourSelectionColorPatcher = colorPatcher;
|
||||
selectionColorPatcher = colorPatcher;
|
||||
IconLoader.clearCache();
|
||||
}
|
||||
|
||||
public static void setColorRedefinitionContext(boolean isColorRedefinitionContext) {
|
||||
ourIsColorRedefinitionContext = isColorRedefinitionContext;
|
||||
SVGLoader.isColorRedefinitionContext = isColorRedefinitionContext;
|
||||
}
|
||||
|
||||
public static boolean isColorRedefinitionContext() {
|
||||
return ourContextColorPatcher != null
|
||||
&& EventQueue.isDispatchThread()
|
||||
&& ourIsColorRedefinitionContext
|
||||
return contextColorPatcher != null
|
||||
&& isColorRedefinitionContext
|
||||
&& EDT.isCurrentThreadEdt()
|
||||
&& Registry.is("ide.patch.icons.on.selection", false);
|
||||
}
|
||||
|
||||
public static void paintIconWithSelection(Icon icon, Component c, Graphics g, int x, int y) {
|
||||
if (ourSelectionColorPatcher == null) {
|
||||
if (selectionColorPatcher == null) {
|
||||
icon.paintIcon(c, g, x, y);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
try {
|
||||
setContextColorPatcher(ourSelectionColorPatcher);
|
||||
setContextColorPatcher(selectionColorPatcher);
|
||||
setColorRedefinitionContext(true);
|
||||
icon.paintIcon(c, g, x, y);
|
||||
}
|
||||
|
||||
+2
-2
@@ -4,12 +4,12 @@
|
||||
package com.intellij.completion.ml.experiment
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent
|
||||
import com.intellij.idea.StartupUtil
|
||||
import com.intellij.internal.statistic.eventLog.EventLogConfiguration
|
||||
import com.intellij.lang.Language
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import com.intellij.util.ResourceUtil
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.util.*
|
||||
|
||||
@@ -23,7 +23,7 @@ class ClientExperimentStatus : ExperimentStatus {
|
||||
return ExperimentConfig.disabledExperiment()
|
||||
}
|
||||
|
||||
val data = StartupUtil.getResourceAsBytes("experiment.json", ClientExperimentStatus::class.java.classLoader)!!
|
||||
val data = ResourceUtil.getResourceAsBytes("experiment.json", ClientExperimentStatus::class.java.classLoader)!!
|
||||
val experimentInfo = Json.Default.decodeFromString(ExperimentConfig.serializer(), data.toString(Charsets.UTF_8))
|
||||
checkExperimentGroups(experimentInfo)
|
||||
return experimentInfo
|
||||
|
||||
+2
-2
@@ -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.idea.devkit.actions.updateFromSources
|
||||
|
||||
import com.intellij.CommonBundle
|
||||
@@ -356,7 +356,7 @@ internal open class UpdateIdeFromSourcesAction
|
||||
return
|
||||
}
|
||||
val plugins = try {
|
||||
pluginsXml.inputStream().reader().use {
|
||||
pluginsXml.inputStream().use {
|
||||
MarketplaceRequests.parsePluginList(it)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-16
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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 org.jetbrains.idea.eclipse.importer;
|
||||
|
||||
import com.intellij.openapi.options.SchemeImportException;
|
||||
@@ -45,7 +31,7 @@ public class EclipseXmlProfileReader extends DefaultHandler implements EclipseXm
|
||||
* @throws SchemeImportException
|
||||
*/
|
||||
protected void readSettings(InputStream input) throws SchemeImportException {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
SAXParserFactory spf = SAXParserFactory.newDefaultInstance();
|
||||
spf.setValidating(false);
|
||||
SAXParser parser;
|
||||
try {
|
||||
|
||||
+2
-16
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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 org.jetbrains.idea.eclipse.importer.colors;
|
||||
|
||||
import com.intellij.openapi.editor.markup.EffectType;
|
||||
@@ -48,7 +34,7 @@ public class EclipseThemeReader extends DefaultHandler implements EclipseColorTh
|
||||
|
||||
|
||||
void readSettings(InputStream input) throws SchemeImportException {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
SAXParserFactory spf = SAXParserFactory.newDefaultInstance();
|
||||
spf.setValidating(false);
|
||||
try {
|
||||
SAXParser parser = spf.newSAXParser();
|
||||
|
||||
@@ -1158,7 +1158,7 @@ public class MavenUtil {
|
||||
try {
|
||||
final CRC32 crc = new CRC32();
|
||||
|
||||
SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
|
||||
SAXParser parser = SAXParserFactory.newDefaultInstance().newSAXParser();
|
||||
parser.getXMLReader().setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
parser.parse(in, new DefaultHandler() {
|
||||
|
||||
|
||||
@@ -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.jetbrains.python.debugger;
|
||||
|
||||
import com.intellij.util.io.URLUtil;
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
*/
|
||||
public final class PydevXmlUtils {
|
||||
|
||||
private static final SAXParserFactory parserFactory = SAXParserFactory.newInstance();
|
||||
private static final SAXParserFactory parserFactory = SAXParserFactory.newDefaultInstance();
|
||||
|
||||
private PydevXmlUtils() {
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
// 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.xml.util;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.util.io.UnsyncByteArrayInputStream;
|
||||
import com.intellij.util.ResourceUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@@ -33,15 +30,9 @@ public final class HTMLControls {
|
||||
private static Control[] loadControls() {
|
||||
Element element;
|
||||
try {
|
||||
// use temporary bytes stream because otherwise inputStreamSkippingBOM will fail
|
||||
// on ZipFileInputStream used in jar files
|
||||
final byte[] bytes;
|
||||
try (final InputStream stream = HTMLControls.class.getResourceAsStream("HtmlControls.xml")) {
|
||||
bytes = FileUtilRt.loadBytes(stream);
|
||||
}
|
||||
try (final UnsyncByteArrayInputStream bytesStream = new UnsyncByteArrayInputStream(bytes)) {
|
||||
element = JDOMUtil.load(CharsetToolkit.inputStreamSkippingBOM(bytesStream));
|
||||
}
|
||||
byte[] bytes = ResourceUtil.getResourceAsBytes("com/intellij/xml/util/HtmlControls.xml", HTMLControls.class.getClassLoader());
|
||||
assert bytes != null;
|
||||
element = JDOMUtil.load(bytes);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<htmlControls namespace="System.Web.UI.HtmlControls">
|
||||
<htmlControls namespace="System.Web.UI.HtmlControls">
|
||||
<control name="A" type="HtmlAnchor" startTag="required" endTag="Required" emptyAllowed="false">
|
||||
<attribute name="href" type="%URL" />
|
||||
</control>
|
||||
|
||||
Reference in New Issue
Block a user