From 80fd13103d3a300f8ee9030738a783db30a10588 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Mon, 16 Aug 2021 21:26:52 +0300 Subject: [PATCH] IDEA-275516 plugin manager does not display a plugin icon and org.apache.batik.bridge.BridgeException is thrown GitOrigin-RevId: eb3f005d823586b2b59a8c905bd3ef3325c9c523 --- .../intellij/ide/plugins/newui/PluginLogo.java | 16 ++++++++++++---- .../ide/plugins/newui/PluginLogoApi.java | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java index 30a7667dc23f..25f8690f8cb3 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogo.java @@ -133,7 +133,7 @@ public final class PluginLogo { String fileName = file.getFileName().toString(); Path darkFile = file.getParent().resolve(fileName.substring(0, fileName.length() - 4) + "_dark.svg"); try (InputStream stream = Files.newInputStream(darkFile)) { - return HiDPIPluginLogoIcon.loadSVG(darkFile.toUri().toURL(), stream, width, height); + return HiDPIPluginLogoIcon.loadSVG(toURL(darkFile), stream, width, height); } catch (NoSuchFileException ignore) { } @@ -361,12 +361,20 @@ public final class PluginLogo { @Nullable private static PluginLogoIconProvider tryLoadIcon(@NotNull ZipFile zipFile, boolean light) { ZipEntry iconEntry = zipFile.getEntry(getIconFileName(light)); - return iconEntry == null ? null : loadFileIcon(toURL(new File(zipFile.getName())), () -> zipFile.getInputStream(iconEntry)); + return iconEntry == null ? null : loadFileIcon(toURL(zipFile), () -> zipFile.getInputStream(iconEntry)); } - static @Nullable URL toURL(@NotNull File file) { + static @Nullable URL toURL(@NotNull Object file) { try { - return file.toURI().toURL(); + if (file instanceof File) { + return ((File)file).toURI().toURL(); + } + if (file instanceof Path) { + return ((Path)file).toUri().toURL(); + } + if (file instanceof ZipFile) { + return new File(((ZipFile)file).getName()).toURI().toURL(); + } } catch (MalformedURLException e) { LOG.warn(e); diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogoApi.java b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogoApi.java index 45aabc8c076e..097896436a7d 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogoApi.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/newui/PluginLogoApi.java @@ -116,7 +116,7 @@ public final class PluginLogoApi { private @Nullable Icon tryLoadIcon(@NotNull Path dirFile, boolean light, int width, int height) { try { Path iconFile = dirFile.resolve(PluginLogo.getIconFileName(light)); - return Files.size(iconFile) > 0 ? loadFileIcon(iconFile.toUri().toURL(), Files.newInputStream(iconFile), width, height) : null; + return Files.size(iconFile) > 0 ? loadFileIcon(PluginLogo.toURL(iconFile), Files.newInputStream(iconFile), width, height) : null; } catch (NoSuchFileException ignore) { return null; @@ -131,7 +131,7 @@ public final class PluginLogoApi { private @Nullable static Icon tryLoadIcon(@NotNull ZipFile zipFile, boolean light, int width, int height) throws IOException { ZipEntry iconEntry = zipFile.getEntry(PluginLogo.getIconFileName(light)); - return iconEntry == null ? null : loadFileIcon(PluginLogo.toURL(new File(zipFile.getName())), zipFile.getInputStream(iconEntry), width, height); + return iconEntry == null ? null : loadFileIcon(PluginLogo.toURL(zipFile), zipFile.getInputStream(iconEntry), width, height); } private @NotNull static Icon loadFileIcon(@Nullable URL url, @NotNull InputStream stream, int width, int height) throws IOException {