From 458edd5fcbe3d1f08d430032dd29d7d03e8d28a6 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 15 Sep 2023 10:59:39 +0200 Subject: [PATCH] Cleanup (dead code; formatting) GitOrigin-RevId: 457ab07cbe5fa9e8d389d036205ef8d9ba272a30 --- .../ide/plugins/IdeaPluginDescriptorImpl.kt | 43 ++---- .../intellij/ide/plugins/PluginManagerCore.kt | 77 +++++----- .../intellij/ide/plugins/PluginSetBuilder.kt | 58 ++------ .../ide/plugins/PluginManagerTest.java | 139 +++++++----------- 4 files changed, 114 insertions(+), 203 deletions(-) diff --git a/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt b/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt index 6c1cc2bde0ef..867c1eb52b02 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/IdeaPluginDescriptorImpl.kt @@ -125,9 +125,8 @@ class IdeaPluginDescriptorImpl(raw: RawPluginDescriptor, override fun getDescriptorPath(): String? = descriptorPath - override fun getDependencies(): List { - return if (pluginDependencies.isEmpty()) Collections.emptyList() else Collections.unmodifiableList(pluginDependencies) - } + override fun getDependencies(): List = + if (pluginDependencies.isEmpty()) Collections.emptyList() else Collections.unmodifiableList(pluginDependencies) override fun getPluginPath(): Path = path @@ -516,38 +515,22 @@ class IdeaPluginDescriptorImpl(raw: RawPluginDescriptor, override fun isRequireRestart(): Boolean = isRestartRequired - override fun equals(other: Any?): Boolean { - if (this === other) { - return true - } - if (other !is IdeaPluginDescriptorImpl) { - return false - } - return id == other.id && descriptorPath == other.descriptorPath - } + override fun equals(other: Any?): Boolean = + this === other || other is IdeaPluginDescriptorImpl && id == other.id && descriptorPath == other.descriptorPath - override fun hashCode(): Int { - return 31 * id.hashCode() + (descriptorPath?.hashCode() ?: 0) - } + override fun hashCode(): Int = + 31 * id.hashCode() + (descriptorPath?.hashCode() ?: 0) - override fun toString(): String { - return "PluginDescriptor(" + - "name=$name, " + - "id=$id, " + - (if (moduleName == null) "" else "moduleName=$moduleName, ") + - "descriptorPath=${descriptorPath ?: "plugin.xml"}, " + - "path=${pluginPathToUserString(path)}, " + - "version=$version, " + - "package=$packagePrefix, " + - "isBundled=$isBundled" + - ")" - } + override fun toString(): String = + "PluginDescriptor(name=$name, id=$id, " + + (if (moduleName == null) "" else "moduleName=$moduleName, ") + + "descriptorPath=${descriptorPath ?: "plugin.xml"}, " + + "path=${pluginPathToUserString(path)}, version=$version, package=$packagePrefix, isBundled=$isBundled)" } // don't expose user home in error messages -internal fun pluginPathToUserString(file: Path): String { - return file.toString().replace("${System.getProperty("user.home")}${File.separatorChar}", "~${File.separatorChar}") -} +internal fun pluginPathToUserString(file: Path): String = + file.toString().replace("${System.getProperty("user.home")}${File.separatorChar}", "~${File.separatorChar}") private fun checkCycle(descriptor: IdeaPluginDescriptorImpl, configFile: String, visitedFiles: List) { var i = 0 diff --git a/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.kt b/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.kt index 1cee8e4a8fe8..b7ce546d2fc7 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/PluginManagerCore.kt @@ -200,9 +200,7 @@ object PluginManagerCore { @ApiStatus.ScheduledForRemoval @Deprecated("Use {@link PluginManager#getPluginByClass}.") @JvmStatic - fun getPluginOrPlatformByClassName(className: String): PluginId? { - return getPluginDescriptorOrPlatformByClassName(className)?.getPluginId() - } + fun getPluginOrPlatformByClassName(className: String): PluginId? = getPluginDescriptorOrPlatformByClassName(className)?.getPluginId() @Internal @JvmStatic @@ -386,9 +384,8 @@ object PluginManagerCore { * Think twice before use and get an approval from the core team. Returns enabled plugins only. */ @Internal - fun getEnabledPluginRawList(): CompletableFuture> { - return initFuture!!.asCompletableFuture().thenApply { it.enabledPlugins } - } + fun getEnabledPluginRawList(): CompletableFuture> = + initFuture!!.asCompletableFuture().thenApply { it.enabledPlugins } @get:Internal val initPluginFuture: Deferred @@ -453,7 +450,6 @@ object PluginManagerCore { if (descriptor === coreDescriptor) { continue } - if (explicitlyEnabled != null) { if (!explicitlyEnabled.contains(descriptor)) { descriptor.isEnabled = false @@ -463,8 +459,7 @@ object PluginManagerCore { else if (!shouldLoadPlugins) { descriptor.isEnabled = false errors.put(descriptor.getPluginId(), PluginLoadingError(descriptor, - message("plugin.loading.error.long.plugin.loading.disabled", - descriptor.getName()), + message("plugin.loading.error.long.plugin.loading.disabled", descriptor.getName()), message("plugin.loading.error.short.plugin.loading.disabled"))) } } @@ -486,23 +481,20 @@ object PluginManagerCore { @JvmStatic fun isCompatible(descriptor: IdeaPluginDescriptor): Boolean = isCompatible(descriptor = descriptor, buildNumber = null) - fun isCompatible(descriptor: IdeaPluginDescriptor, buildNumber: BuildNumber?): Boolean { - return !isIncompatible(descriptor = descriptor, buildNumber = buildNumber) - } + fun isCompatible(descriptor: IdeaPluginDescriptor, buildNumber: BuildNumber?): Boolean = + !isIncompatible(descriptor = descriptor, buildNumber = buildNumber) @JvmStatic fun isIncompatible(descriptor: IdeaPluginDescriptor): Boolean = isIncompatible(descriptor = descriptor, buildNumber = null) @JvmStatic - fun isIncompatible(descriptor: IdeaPluginDescriptor, buildNumber: BuildNumber?): Boolean { - return checkBuildNumberCompatibility(descriptor, buildNumber ?: PluginManagerCore.buildNumber) != null - } + fun isIncompatible(descriptor: IdeaPluginDescriptor, buildNumber: BuildNumber?): Boolean = + checkBuildNumberCompatibility(descriptor, buildNumber ?: PluginManagerCore.buildNumber) != null - fun getIncompatiblePlatform(descriptor: IdeaPluginDescriptor): IdeaPluginPlatform? { - return descriptor.getDependencies().asSequence() + fun getIncompatiblePlatform(descriptor: IdeaPluginDescriptor): IdeaPluginPlatform? = + descriptor.getDependencies().asSequence() .map { fromModuleId(it.pluginId) } .firstOrNull { p -> p != null && !p.isHostPlatform() } - } @JvmStatic fun checkBuildNumberCompatibility(descriptor: IdeaPluginDescriptor, ideBuildNumber: BuildNumber): PluginLoadingError? { @@ -596,18 +588,8 @@ object PluginManagerCore { throw EssentialPluginMissingException(listOf("$CORE_ID (platform prefix: ${System.getProperty(PlatformUtils.PLATFORM_PREFIX_KEY)})")) } - val activity = parentActivity?.startChild("3rd-party plugins consent") - val aliens = ArrayList() - for (id in get3rdPartyPluginIds()) { - val pluginDescriptor = idMap.get(id) ?: continue - aliens.add(pluginDescriptor) - } + check3rdPartyPluginsPrivacyConsent(parentActivity, idMap) - if (!aliens.isEmpty()) { - check3rdPartyPluginsPrivacyConsent(aliens) - } - - activity?.end() val pluginSetBuilder = PluginSetBuilder(loadingResult.enabledPluginsById.values) disableIncompatiblePlugins(descriptors = pluginSetBuilder.unsortedPlugins, idMap = idMap, errors = pluginErrorsById) pluginSetBuilder.checkPluginCycles(globalErrors) @@ -654,6 +636,21 @@ object PluginManagerCore { return PluginManagerState(pluginSet = pluginSet, pluginIdsToDisable = pluginsToDisable.keys, pluginIdsToEnable = pluginsToEnable.keys) } + private fun check3rdPartyPluginsPrivacyConsent(parentActivity: Activity?, idMap: Map) { + val activity = parentActivity?.startChild("3rd-party plugins consent") + + val aliens = ArrayList() + for (id in get3rdPartyPluginIds()) { + val pluginDescriptor = idMap.get(id) ?: continue + aliens.add(pluginDescriptor) + } + if (!aliens.isEmpty()) { + check3rdPartyPluginsPrivacyConsent(aliens) + } + + activity?.end() + } + private fun check3rdPartyPluginsPrivacyConsent(aliens: List) { if (GraphicsEnvironment.isHeadless()) { if (QODANA_PLUGINS_THIRD_PARTY_ACCEPT || FLEET_BACKEND_PLUGINS_THIRD_PARTY_ACCEPT) { @@ -839,9 +836,7 @@ object PluginManagerCore { @Contract("null -> null") @JvmStatic - fun getPlugin(id: PluginId?): IdeaPluginDescriptor? { - return if (id == null) null else findPlugin(id) - } + fun getPlugin(id: PluginId?): IdeaPluginDescriptor? = if (id == null) null else findPlugin(id) @Internal @JvmStatic @@ -851,9 +846,8 @@ object PluginManagerCore { } @Internal - fun findPluginByModuleDependency(id: PluginId): IdeaPluginDescriptorImpl? { - return getPluginSet().allPlugins.firstOrNull { it.modules.contains(id) } - } + fun findPluginByModuleDependency(id: PluginId): IdeaPluginDescriptorImpl? = + getPluginSet().allPlugins.firstOrNull { it.modules.contains(id) } @JvmStatic fun isPluginInstalled(id: PluginId): Boolean { @@ -950,16 +944,12 @@ object PluginManagerCore { // @Deprecated("Use {@link #disablePlugin(PluginId)} ") @JvmStatic - fun disablePlugin(id: String): Boolean { - return disablePlugin(PluginId.getId(id)) - } + fun disablePlugin(id: String): Boolean = disablePlugin(PluginId.getId(id)) @ApiStatus.ScheduledForRemoval @Deprecated("Use {@link #enablePlugin(PluginId)} ") @JvmStatic - fun enablePlugin(id: String): Boolean { - return enablePlugin(PluginId.getId(id)) - } + fun enablePlugin(id: String): Boolean = enablePlugin(PluginId.getId(id)) @ApiStatus.ScheduledForRemoval @Deprecated("Use {@link DisabledPluginsState#addDisablePluginListener} directly") @@ -974,9 +964,8 @@ object PluginManagerCore { class EssentialPluginMissingException internal constructor(@JvmField val pluginIds: List) : RuntimeException("Missing essential plugins: ${pluginIds.joinToString(", ")}") -private fun message(key: @PropertyKey(resourceBundle = CoreBundle.BUNDLE) String?, vararg params: Any?): @Nls Supplier { - return Supplier { CoreBundle.message(key!!, *params) } -} +private fun message(key: @PropertyKey(resourceBundle = CoreBundle.BUNDLE) String?, vararg params: Any?): @Nls Supplier = + Supplier { CoreBundle.message(key!!, *params) } @Synchronized internal fun tryReadPluginIdsFromFile(path: Path, log: Logger): Set { diff --git a/platform/core-impl/src/com/intellij/ide/plugins/PluginSetBuilder.kt b/platform/core-impl/src/com/intellij/ide/plugins/PluginSetBuilder.kt index 4b6051d4f8ec..3a8f5303b045 100644 --- a/platform/core-impl/src/com/intellij/ide/plugins/PluginSetBuilder.kt +++ b/platform/core-impl/src/com/intellij/ide/plugins/PluginSetBuilder.kt @@ -4,7 +4,6 @@ package com.intellij.ide.plugins import com.intellij.core.CoreBundle -import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.extensions.PluginId import com.intellij.util.Java11Shim import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap @@ -15,10 +14,7 @@ import java.util.* import java.util.function.Supplier @ApiStatus.Internal -class PluginSetBuilder( - val unsortedPlugins: Set, -) { - +class PluginSetBuilder(val unsortedPlugins: Set) { private val _moduleGraph = createModuleGraph(unsortedPlugins) private val builder = _moduleGraph.builder() val moduleGraph: SortedModuleGraph = _moduleGraph.sorted(builder) @@ -139,9 +135,7 @@ class PluginSetBuilder( return this } - fun createPluginSetWithEnabledModulesMap(): PluginSet { - return computeEnabledModuleMap().createPluginSet() - } + fun createPluginSetWithEnabledModulesMap(): PluginSet = computeEnabledModuleMap().createPluginSet() fun createPluginSet(incompletePlugins: Collection = Collections.emptyList()): PluginSet { val sortedPlugins = getSortedPlugins() @@ -162,28 +156,6 @@ class PluginSetBuilder( ) } - internal fun checkModules(descriptor: IdeaPluginDescriptorImpl, isDebugLogEnabled: Boolean, log: Logger) { - m@ for (item in descriptor.content.modules) { - for (ref in item.requireDescriptor().dependencies.modules) { - if (!enabledModuleV2Ids.containsKey(ref.name)) { - if (isDebugLogEnabled) { - log.info("Module ${item.name} is not enabled because dependency ${ref.name} is not available") - } - continue@m - } - } - for (ref in item.requireDescriptor().dependencies.plugins) { - if (!enabledPluginIds.containsKey(ref.id)) { - if (isDebugLogEnabled) { - log.info("Module ${item.name} is not enabled because dependency ${ref.id} is not available") - } - continue@m - } - } - enabledModuleV2Ids.put(item.name, descriptor) - } - } - // use only for init plugins internal fun initEnableState( descriptor: IdeaPluginDescriptorImpl, @@ -276,23 +248,17 @@ private fun createTransitivelyDisabledError( ) } -private fun message(key: @PropertyKey(resourceBundle = CoreBundle.BUNDLE) String, vararg params: Any): @Nls Supplier { - return Supplier { CoreBundle.message(key, *params) } -} +private fun message(key: @PropertyKey(resourceBundle = CoreBundle.BUNDLE) String, vararg params: Any): @Nls Supplier = + Supplier { CoreBundle.message(key, *params) } private val IdeaPluginDescriptorImpl.allPluginDependencies - get(): Sequence { - return pluginDependencies.asSequence() - .filterNot { it.isOptional } - .map { it.pluginId } + - dependencies - .plugins.asSequence() - .map { it.id } - } + get(): Sequence = + pluginDependencies.asSequence() + .filterNot { it.isOptional } + .map { it.pluginId } + + dependencies + .plugins.asSequence() + .map { it.id } private val IdeaPluginDescriptorImpl.moduleDependencies - get(): Sequence { - return dependencies - .modules.asSequence() - .map { it.name } - } \ No newline at end of file + get(): Sequence = dependencies.modules.asSequence().map { it.name } diff --git a/platform/platform-tests/testSrc/com/intellij/ide/plugins/PluginManagerTest.java b/platform/platform-tests/testSrc/com/intellij/ide/plugins/PluginManagerTest.java index c6b1b58d7f92..fc65219a80cb 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/plugins/PluginManagerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ide/plugins/PluginManagerTest.java @@ -5,7 +5,6 @@ import com.intellij.openapi.extensions.PluginId; import com.intellij.openapi.util.BuildNumber; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.SystemInfo; -import com.intellij.openapi.util.text.HtmlChunk; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.text.Strings; import com.intellij.testFramework.PlatformTestUtil; @@ -162,25 +161,21 @@ public class PluginManagerTest { doPluginSortTest("simplePluginSort", false); } - /** - + /* Actual result: - HTTP Client (main) Endpoints (main) HTTP Client (intellij.restClient.microservicesUI, depends on Endpoints) Expected: - Endpoints (main) HTTP Client (main) HTTP Client (intellij.restClient.microservicesUI, depends on Endpoints) But graph is correct - HTTP Client (main) it is node that doesn't depend on Endpoints (main), - so, no reason for DFSTBuilder to put it after. - - See CachingSemiGraph.getSortedPlugins for solution - */ + so no reason for DFSTBuilder to put it after. + See CachingSemiGraph.getSortedPlugins for a solution. + */ @Test public void moduleSort() throws Exception { doPluginSortTest("moduleSort", true); @@ -193,22 +188,21 @@ public class PluginManagerTest { @Test public void testModulePluginIdContract() { - Path pluginsPath = Path.of(PlatformTestUtil.getPlatformTestDataPath(), "plugins", "withModules"); - IdeaPluginDescriptorImpl descriptorBundled = loadDescriptorInTest(pluginsPath, true); - PluginSet pluginSet = new PluginSetBuilder(Set.of(descriptorBundled)) - .createPluginSetWithEnabledModulesMap(); + var pluginsPath = Path.of(PlatformTestUtil.getPlatformTestDataPath(), "plugins", "withModules"); + var descriptorBundled = loadDescriptorInTest(pluginsPath, true); + var pluginSet = new PluginSetBuilder(Set.of(descriptorBundled)).createPluginSetWithEnabledModulesMap(); - PluginId moduleId = PluginId.getId("foo.bar"); - PluginId corePlugin = PluginId.getId("my.plugin"); + var moduleId = PluginId.getId("foo.bar"); + var corePlugin = PluginId.getId("my.plugin"); assertThat(pluginSet.findEnabledPlugin(moduleId).getPluginId()).isEqualTo(corePlugin); } @Test public void testIdentifyPreInstalledPlugins() { - Path pluginsPath = Path.of(PlatformTestUtil.getPlatformTestDataPath(), "plugins", "updatedBundled"); - IdeaPluginDescriptorImpl bundled = loadDescriptorInTest(pluginsPath.resolve("bundled"), true); - IdeaPluginDescriptorImpl updated = loadDescriptorInTest(pluginsPath.resolve("updated")); - PluginId expectedPluginId = updated.getPluginId(); + var pluginsPath = Path.of(PlatformTestUtil.getPlatformTestDataPath(), "plugins", "updatedBundled"); + var bundled = loadDescriptorInTest(pluginsPath.resolve("bundled"), true); + var updated = loadDescriptorInTest(pluginsPath.resolve("updated")); + var expectedPluginId = updated.getPluginId(); assertEquals(expectedPluginId, bundled.getPluginId()); assertPluginPreInstalled(expectedPluginId, bundled, updated); @@ -219,25 +213,24 @@ public class PluginManagerTest { public void testSymlinkInConfigPath() throws IOException { assumeSymLinkCreationIsSupported(); - Path configPath = tempDir.getRoot().toPath().resolve("config-link"); - @NotNull Path target = tempDir.newDirectory("config-target").toPath(); + var configPath = tempDir.getRoot().toPath().resolve("config-link"); + var target = tempDir.newDirectory("config-target").toPath(); Files.createSymbolicLink(configPath, target); DisabledPluginsState.Companion.saveDisabledPluginsAndInvalidate(configPath, List.of("a")); assertThat(configPath.resolve(DisabledPluginsState.DISABLED_PLUGINS_FILENAME)).hasContent("a" + System.lineSeparator()); } - private static void assertPluginPreInstalled(@NotNull PluginId expectedPluginId, - IdeaPluginDescriptorImpl... descriptors) { - PluginLoadingResult loadingResult = createPluginLoadingResult(); + private static void assertPluginPreInstalled(PluginId expectedPluginId, IdeaPluginDescriptorImpl... descriptors) { + var loadingResult = createPluginLoadingResult(); loadingResult.addAll(List.of(descriptors)); assertTrue("Plugin should be pre installed", loadingResult.shadowedBundledIds.contains(expectedPluginId)); } private static void doPluginSortTest(String testDataName, boolean isBundled) throws IOException, XMLStreamException { PluginManagerCore.INSTANCE.getAndClearPluginLoadingErrors(); - PluginManagerState loadPluginResult = loadAndInitializeDescriptors(testDataName + ".xml", isBundled); - StringBuilder text = new StringBuilder(); - for (IdeaPluginDescriptorImpl descriptor : loadPluginResult.pluginSet.getEnabledModules()) { + var loadPluginResult = loadAndInitializeDescriptors(testDataName + ".xml", isBundled); + var text = new StringBuilder(); + for (var descriptor : loadPluginResult.pluginSet.getEnabledModules()) { text.append(descriptor.isEnabled() ? "+ " : " ").append(descriptor.getPluginId().getIdString()); if (descriptor.moduleName != null) { text.append(" | ").append(descriptor.moduleName); @@ -245,7 +238,7 @@ public class PluginManagerTest { text.append('\n'); } text.append("\n\n"); - for (HtmlChunk html : PluginManagerCore.INSTANCE.getAndClearPluginLoadingErrors()) { + for (var html : PluginManagerCore.INSTANCE.getAndClearPluginLoadingErrors()) { text.append(html.toString().replace("
", "\n").replace("'", "")).append('\n'); } UsefulTestCase.assertSameLinesWithFile(new File(getTestDataPath(), testDataName + ".txt").getPath(), text.toString()); @@ -255,15 +248,11 @@ public class PluginManagerTest { assertEquals(result, PluginManager.convertExplicitBigNumberInUntilBuildToStar(untilBuild)); } - private static void assertIncompatible(@NotNull String ideVersion, - @Nullable String sinceBuild, - @Nullable String untilBuild) { + private static void assertIncompatible(String ideVersion, @Nullable String sinceBuild, @Nullable String untilBuild) { assertNotNull(checkCompatibility(ideVersion, sinceBuild, untilBuild)); } - private static @Nullable PluginLoadingError checkCompatibility(@NotNull String ideVersion, - @Nullable String sinceBuild, - @Nullable String untilBuild) { + private static @Nullable PluginLoadingError checkCompatibility(String ideVersion, @Nullable String sinceBuild, @Nullable String untilBuild) { IdeaPluginDescriptor mock = EasyMock.niceMock(IdeaPluginDescriptor.class); expect(mock.getSinceBuild()).andReturn(sinceBuild).anyTimes(); expect(mock.getUntilBuild()).andReturn(untilBuild).anyTimes(); @@ -273,7 +262,7 @@ public class PluginManagerTest { return PluginManagerCore.checkBuildNumberCompatibility(mock, Objects.requireNonNull(BuildNumber.fromString(ideVersion))); } - private static boolean checkCompatibility(@NotNull String platformId) { + private static boolean checkCompatibility(String platformId) { IdeaPluginDependency platformDependencyMock = EasyMock.niceMock(IdeaPluginDependency.class); expect(platformDependencyMock.getPluginId()).andReturn(PluginId.getId(platformId)); replay(platformDependencyMock); @@ -287,29 +276,19 @@ public class PluginManagerTest { return PluginManagerCore.checkBuildNumberCompatibility(mock, BuildNumber.fromString("145")) == null; } - private static void assertCompatible(@NotNull String ideVersion, - @Nullable String sinceBuild, - @Nullable String untilBuild) { + private static void assertCompatible(String ideVersion, @Nullable String sinceBuild, @Nullable String untilBuild) { assertNull(checkCompatibility(ideVersion, sinceBuild, untilBuild)); } - private static PluginManagerState loadAndInitializeDescriptors(String testDataName, boolean isBundled) - throws IOException, XMLStreamException { - Path file = Path.of(getTestDataPath(), testDataName); - BuildNumber buildNumber = BuildNumber.fromString("2042.42"); - DescriptorListLoadingContext parentContext = new DescriptorListLoadingContext(Set.of(), - Set.of(), - Map.of(), - () -> buildNumber, - false, - false, - false, - false); + private static PluginManagerState loadAndInitializeDescriptors(String testDataName, boolean isBundled) throws IOException, XMLStreamException { + var file = Path.of(getTestDataPath(), testDataName); + var buildNumber = BuildNumber.fromString("2042.42"); + var parentContext = new DescriptorListLoadingContext(Set.of(), Set.of(), Map.of(), () -> buildNumber, false, false, false, false); - XmlElement root = XmlDomReader.readXmlAsModel(Files.newInputStream(file)); - Ref autoGenerateModuleDescriptor = new Ref<>(false); - Map moduleMap = new HashMap<>(); - PathResolver pathResolver = new PathResolver() { + var root = XmlDomReader.readXmlAsModel(Files.newInputStream(file)); + var autoGenerateModuleDescriptor = new Ref<>(false); + var moduleMap = new HashMap(); + var pathResolver = new PathResolver() { @Override public boolean isFlat() { return false; @@ -329,9 +308,9 @@ public class PluginManagerTest { @NotNull DataLoader dataLoader, @NotNull String relativePath, @Nullable RawPluginDescriptor readInto) { - for (XmlElement child : root.children) { + for (var child : root.children) { if (child.name.equals("config-file-idea-plugin")) { - String url = Objects.requireNonNull(child.getAttributeValue("url")); + var url = Objects.requireNonNull(child.getAttributeValue("url")); if (url.endsWith("/" + relativePath)) { try { return XmlReader.readModuleDescriptor(elementAsBytes(child), readContext, this, dataLoader, null, readInto, null); @@ -351,7 +330,7 @@ public class PluginManagerTest { @NotNull String path, @Nullable RawPluginDescriptor readInto) { if (autoGenerateModuleDescriptor.get() && path.startsWith("intellij.")) { - XmlElement element = moduleMap.get(path); + var element = moduleMap.get(path); if (element != null) { try { return XmlReader.readModuleDescriptorForTest(elementAsBytes(element)); @@ -363,27 +342,26 @@ public class PluginManagerTest { assert readInto == null; // auto-generate empty descriptor - return XmlReader.readModuleDescriptorForTest(("") - .getBytes(StandardCharsets.UTF_8)); + return XmlReader.readModuleDescriptorForTest(("").getBytes(StandardCharsets.UTF_8)); } return resolvePath(readContext, dataLoader, path, readInto); } }; - for (XmlElement element : root.children) { - String moduleFile = element.attributes.get("moduleFile"); + for (var element : root.children) { + var moduleFile = element.attributes.get("moduleFile"); if (moduleFile != null) { moduleMap.put(moduleFile, element); } } - List list = new ArrayList<>(); - for (XmlElement element : root.children) { + var list = new ArrayList(); + for (var element : root.children) { if (!element.name.equals("idea-plugin")) { continue; } - String url = element.getAttributeValue("url"); + var url = element.getAttributeValue("url"); Path pluginPath; if (url == null) { XmlElement id = element.getChild("id"); @@ -398,62 +376,57 @@ public class PluginManagerTest { else { pluginPath = Path.of(Strings.trimStart(Objects.requireNonNull(url), "file://")); } - IdeaPluginDescriptorImpl descriptor = PluginDescriptorTestKt.createFromDescriptor(pluginPath, - isBundled, - elementAsBytes(element), - parentContext, - pathResolver, - new LocalFsDataLoader(pluginPath)); + var descriptor = PluginDescriptorTestKt.createFromDescriptor( + pluginPath, isBundled, elementAsBytes(element), parentContext, pathResolver, new LocalFsDataLoader(pluginPath)); list.add(descriptor); descriptor.jarFiles = List.of(); } parentContext.close(); - PluginLoadingResult result = new PluginLoadingResult(false); + var result = new PluginLoadingResult(false); result.addAll(list); - return PluginManagerCore.INSTANCE.initializePlugins(parentContext, result, PluginManagerTest.class.getClassLoader(), /* checkEssentialPlugins = */ false, null); + return PluginManagerCore.INSTANCE.initializePlugins(parentContext, result, PluginManagerTest.class.getClassLoader(), false, null); } - private static byte @NotNull [] elementAsBytes(XmlElement child) throws XMLStreamException { - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - XMLStreamWriter writer = XMLOutputFactory.newDefaultFactory().createXMLStreamWriter(byteOut, "utf-8"); - writeXmlElement(child, writer); + private static byte[] elementAsBytes(XmlElement child) throws XMLStreamException { + var byteOut = new ByteArrayOutputStream(); + writeXmlElement(child, XMLOutputFactory.newDefaultFactory().createXMLStreamWriter(byteOut, "utf-8")); return byteOut.toByteArray(); } private static void writeXmlElement(XmlElement element, XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement(element.name); - for (Map.Entry entry : element.attributes.entrySet()) { + for (var entry : element.attributes.entrySet()) { writer.writeAttribute(entry.getKey(), entry.getValue()); } if (element.content != null) { writer.writeCharacters(element.content); } - for (XmlElement child : element.children) { + for (var child : element.children) { writeXmlElement(child, writer); } writer.writeEndElement(); } - /** @noinspection unused */ + @SuppressWarnings("unused") private static String dumpDescriptors(IdeaPluginDescriptorImpl @NotNull [] descriptors) { // place breakpoint in PluginManagerCore#loadDescriptors before sorting - StringBuilder sb = new StringBuilder(""); + var sb = new StringBuilder(""); Function escape = s -> { return s.equals("com.intellij") || s.startsWith("com.intellij.modules.") ? s : "-" + s.replace(".", "-") + "-"; }; - for (IdeaPluginDescriptorImpl d : descriptors) { + for (var d : descriptors) { sb.append("\n "); sb.append("\n ").append(escape.apply(d.getPluginId().getIdString())).append(""); sb.append("\n ").append(StringUtil.escapeXmlEntities(d.getName())).append(""); for (PluginId module : d.modules) { sb.append("\n "); } - for (PluginDependency dependency : d.pluginDependencies) { + for (var dependency : d.pluginDependencies) { if (!dependency.isOptional()) { sb.append("\n ").append(escape.apply(dependency.getPluginId().getIdString())).append(""); } else { - IdeaPluginDescriptorImpl optionalConfigPerId = dependency.subDescriptor; + var optionalConfigPerId = dependency.subDescriptor; if (optionalConfigPerId == null) { sb.append("\n ") .append(escape.apply(dependency.getPluginId().getIdString()))