diff --git a/platform/configuration-store-impl/src/internals.kt b/platform/configuration-store-impl/src/internals.kt index d0df99ed0f34..30742cccc52c 100644 --- a/platform/configuration-store-impl/src/internals.kt +++ b/platform/configuration-store-impl/src/internals.kt @@ -22,16 +22,14 @@ internal const val VERSION_OPTION: String = "version" @JvmField internal val XML_PROLOG: ByteArray = """""".toByteArray() -internal fun isSpecialStorage(collapsedPath: String): Boolean { - return collapsedPath == StoragePathMacros.CACHE_FILE || collapsedPath == StoragePathMacros.PRODUCT_WORKSPACE_FILE -} +internal fun isSpecialStorage(collapsedPath: String): Boolean = + collapsedPath == StoragePathMacros.CACHE_FILE || collapsedPath == StoragePathMacros.PRODUCT_WORKSPACE_FILE @CalledInAny -internal suspend fun ensureFilesWritable(project: Project, files: Collection): ReadonlyStatusHandler.OperationStatus { - return withContext(Dispatchers.EDT) { +internal suspend fun ensureFilesWritable(project: Project, files: Collection): ReadonlyStatusHandler.OperationStatus = + withContext(Dispatchers.EDT) { ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files) } -} internal fun loadDataAndDetectLineSeparator(file: Path): Pair { val text = ComponentStorageUtil.loadTextContent(file) diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java b/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java index c3effcacb068..20bbe773fd9c 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java @@ -15,7 +15,6 @@ import com.intellij.openapi.util.BuildNumber; import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.util.Url; import com.intellij.util.Urls; -import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.URLUtil; import com.intellij.util.text.VersionComparatorUtil; import org.jetbrains.annotations.ApiStatus; @@ -29,31 +28,30 @@ import java.util.*; import static com.intellij.ide.plugins.BrokenPluginFileKt.isBrokenPlugin; -/** - * @author stathik - */ public final class RepositoryHelper { private static final Logger LOG = Logger.getInstance(RepositoryHelper.class); + /** Duplicates VmOptionsGenerator.CUSTOM_BUILT_IN_PLUGIN_REPOSITORY_PROPERTY */ private static final String CUSTOM_BUILT_IN_PLUGIN_REPOSITORY_PROPERTY = "intellij.plugins.custom.built.in.repository.url"; - @SuppressWarnings("SpellCheckingInspection") private static final String PLUGIN_LIST_FILE = "availables.xml"; private static final String MARKETPLACE_PLUGIN_ID = "com.intellij.marketplace"; private static final String ULTIMATE_MODULE = "com.intellij.modules.ultimate"; /** * Returns a list of configured plugin hosts. - * Note that the list always ends with {@code null} element denoting a main plugin repository. + * Note that the list always ends with {@code null} element denoting the main plugin repository (Marketplace). */ public static @NotNull List<@Nullable String> getPluginHosts() { - List hosts = new ArrayList<>(UpdateSettings.getInstance().getPluginHosts()); - String pluginsUrl = ApplicationInfoEx.getInstanceEx().getBuiltinPluginsUrl(); + var hosts = new ArrayList<>(UpdateSettings.getInstance().getPluginHosts()); + @SuppressWarnings("deprecation") var pluginsUrl = ApplicationInfoEx.getInstanceEx().getBuiltinPluginsUrl(); if (pluginsUrl != null && !"__BUILTIN_PLUGINS_URL__".equals(pluginsUrl)) { hosts.add(pluginsUrl); } - ContainerUtil.addIfNotNull(hosts, System.getProperty(CUSTOM_BUILT_IN_PLUGIN_REPOSITORY_PROPERTY)); - List repoContributors = CustomPluginRepoContributor.EP_NAME.getExtensionsIfPointIsRegistered(); - for (CustomPluginRepoContributor contributor : repoContributors) { + pluginsUrl = System.getProperty(CUSTOM_BUILT_IN_PLUGIN_REPOSITORY_PROPERTY); + if (pluginsUrl != null) { + hosts.add(pluginsUrl); + } + for (var contributor : CustomPluginRepoContributor.EP_NAME.getExtensionsIfPointIsRegistered()) { hosts.addAll(contributor.getRepoUrls()); } hosts.add(null); // main plugin repository @@ -66,25 +64,26 @@ public final class RepositoryHelper { * @deprecated Please use {@link #loadPlugins(String, BuildNumber, ProgressIndicator)} to get a list of {@link PluginNode}s. */ @Deprecated(forRemoval = true) - public static @NotNull List loadPlugins(@Nullable String repositoryUrl, - @Nullable ProgressIndicator indicator) throws IOException { + public static @NotNull List loadPlugins(@Nullable String repositoryUrl, @Nullable ProgressIndicator indicator) throws IOException { return new ArrayList<>(loadPlugins(repositoryUrl, null, indicator)); } /** * Use method only for getting plugins from custom repositories */ - public static @NotNull List loadPlugins(@Nullable String repositoryUrl, - @Nullable BuildNumber build, - @Nullable ProgressIndicator indicator) throws IOException { + public static @NotNull List loadPlugins( + @Nullable String repositoryUrl, + @Nullable BuildNumber build, + @Nullable ProgressIndicator indicator + ) throws IOException { Path pluginListFile; Url url; if (repositoryUrl == null) { if (ApplicationInfoImpl.getShadowInstance().usesJetBrainsPluginRepository()) { LOG.error("Using deprecated API for getting plugins from Marketplace"); } - String base = ApplicationInfoImpl.getShadowInstance().getPluginsListUrl(); - url = Urls.newFromEncoded(base).addParameters(Map.of("uuid", PluginDownloader.getMarketplaceDownloadsUUID())); // NON-NLS + var base = ApplicationInfoImpl.getShadowInstance().getPluginsListUrl(); + url = Urls.newFromEncoded(base).addParameters(Map.of("uuid", PluginDownloader.getMarketplaceDownloadsUUID())); pluginListFile = Paths.get(PathManager.getPluginsPath(), PLUGIN_LIST_FILE); } else { @@ -100,26 +99,18 @@ public final class RepositoryHelper { indicator.setText2(IdeBundle.message("progress.connecting.to.plugin.manager", url.getAuthority())); } - List descriptors = MarketplaceRequests.readOrUpdateFile(pluginListFile, - url.toExternalForm(), - indicator, - IdeBundle.message("progress.downloading.list.of.plugins", - url.getAuthority()), - MarketplaceRequests::parsePluginList); - return process(descriptors, - build != null ? build : PluginManagerCore.getBuildNumber(), - repositoryUrl); + var message = IdeBundle.message("progress.downloading.list.of.plugins", url.getAuthority()); + var descriptors = MarketplaceRequests.readOrUpdateFile(pluginListFile, url.toExternalForm(), indicator, message, MarketplaceRequests::parsePluginList); + return process(descriptors, build != null ? build : PluginManagerCore.getBuildNumber(), repositoryUrl); } - private static @NotNull List process(@NotNull List list, - @NotNull BuildNumber build, - @Nullable String repositoryUrl) { - Map result = new LinkedHashMap<>(list.size()); + private static List process(List pluginNodes, BuildNumber build, @Nullable String repositoryUrl) { + var result = new LinkedHashMap(pluginNodes.size()); - boolean isPaidPluginsRequireMarketplacePlugin = isPaidPluginsRequireMarketplacePlugin(); + var isPaidPluginsRequireMarketplacePlugin = isPaidPluginsRequireMarketplacePlugin(); - for (PluginNode node : list) { - PluginId pluginId = node.getPluginId(); + for (var node : pluginNodes) { + var pluginId = node.getPluginId(); if (repositoryUrl != null && node.getDownloadUrl() == null) { LOG.debug("Malformed plugin record (id:" + pluginId + " repository:" + repositoryUrl + ")"); @@ -134,12 +125,13 @@ public final class RepositoryHelper { if (repositoryUrl != null) { node.setRepositoryName(repositoryUrl); } + if (node.getName() == null) { - String url = node.getDownloadUrl(); + var url = node.getDownloadUrl(); node.setName(FileUtilRt.getNameWithoutExtension(url.substring(url.lastIndexOf('/') + 1))); } - PluginNode previous = result.get(pluginId); + var previous = result.get(pluginId); if (previous == null || VersionComparatorUtil.compare(node.getVersion(), previous.getVersion()) > 0) { result.put(pluginId, node); } @@ -151,43 +143,39 @@ public final class RepositoryHelper { } /** - * If plugin is paid (has `productCode`) and IDE is not JetBrains "ultimate" then MARKETPLACE_PLUGIN_ID is required + * If a plugin is paid (has `productCode`) and the IDE is not JetBrains "ultimate", then MARKETPLACE_PLUGIN_ID is required. */ public static void addMarketplacePluginDependencyIfRequired(@NotNull PluginNode node) { - boolean isPaidPluginsRequireMarketplacePlugin = isPaidPluginsRequireMarketplacePlugin(); + var isPaidPluginsRequireMarketplacePlugin = isPaidPluginsRequireMarketplacePlugin(); addMarketplacePluginDependencyIfRequired(node, isPaidPluginsRequireMarketplacePlugin); } private static boolean isPaidPluginsRequireMarketplacePlugin() { - boolean isCommunityIDE = !ideContainsUltimateModule(); - boolean isVendorNotJetBrains = !ApplicationInfoImpl.getShadowInstance().isVendorJetBrains(); - return isCommunityIDE || isVendorNotJetBrains; + var core = PluginManagerCore.findPlugin(PluginManagerCore.CORE_ID); + return core == null || !core.modules.contains(PluginId.getId(ULTIMATE_MODULE)) || !ApplicationInfoImpl.getShadowInstance().isVendorJetBrains(); } - private static void addMarketplacePluginDependencyIfRequired(@NotNull PluginNode node, boolean isPaidPluginsRequireMarketplacePlugin) { + private static void addMarketplacePluginDependencyIfRequired(PluginNode node, boolean isPaidPluginsRequireMarketplacePlugin) { if (isPaidPluginsRequireMarketplacePlugin && node.getProductCode() != null) { node.addDepends(MARKETPLACE_PLUGIN_ID, false); } } - private static boolean ideContainsUltimateModule() { - IdeaPluginDescriptorImpl corePlugin = PluginManagerCore.findPlugin(PluginManagerCore.CORE_ID); - return corePlugin != null && corePlugin.modules.contains(PluginId.getId(ULTIMATE_MODULE)); - } - @ApiStatus.Internal - public static @NotNull Collection mergePluginsFromRepositories(@NotNull List marketplacePlugins, - @NotNull List customPlugins, - boolean addMissing) { - Map compatiblePluginMap = new LinkedHashMap<>(marketplacePlugins.size()); + public static @NotNull Collection mergePluginsFromRepositories( + @NotNull List marketplacePlugins, + @NotNull List customPlugins, + boolean addMissing + ) { + var compatiblePluginMap = new LinkedHashMap(marketplacePlugins.size()); - for (PluginNode marketplacePlugin : marketplacePlugins) { + for (var marketplacePlugin : marketplacePlugins) { compatiblePluginMap.put(marketplacePlugin.getPluginId(), marketplacePlugin); } - for (PluginNode customPlugin : customPlugins) { - PluginId pluginId = customPlugin.getPluginId(); - IdeaPluginDescriptor plugin = compatiblePluginMap.get(pluginId); + for (var customPlugin : customPlugins) { + var pluginId = customPlugin.getPluginId(); + var plugin = compatiblePluginMap.get(pluginId); if (plugin == null && addMissing || plugin != null && PluginDownloader.compareVersionsSkipBrokenAndIncompatible(customPlugin.getVersion(), plugin) > 0) { compatiblePluginMap.put(pluginId, customPlugin); diff --git a/platform/platform-impl/src/com/intellij/openapi/command/impl/UpdatePluginsApp.java b/platform/platform-impl/src/com/intellij/ide/plugins/UpdatePluginsApp.java similarity index 92% rename from platform/platform-impl/src/com/intellij/openapi/command/impl/UpdatePluginsApp.java rename to platform/platform-impl/src/com/intellij/ide/plugins/UpdatePluginsApp.java index 855fedff1504..710fb0f74183 100644 --- a/platform/platform-impl/src/com/intellij/openapi/command/impl/UpdatePluginsApp.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/UpdatePluginsApp.java @@ -1,8 +1,7 @@ // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package com.intellij.openapi.command.impl; +package com.intellij.ide.plugins; import com.intellij.configurationStore.XmlSerializer; -import com.intellij.ide.plugins.RepositoryHelper; import com.intellij.idea.AppMode; import com.intellij.openapi.application.ApplicationStarter; import com.intellij.openapi.components.impl.stores.ComponentStorageUtil; @@ -25,8 +24,9 @@ import java.util.List; import java.util.Set; /** - * Works in two stages. On the first run, it collects available updates and writes an update script. The second run needs - * {@code idea.force.plugin.updates = "true"} system property to apply the updates. + * Works in two stages. + * On the first run, it collects available updates and writes an update script. + * The second run needs {@code idea.force.plugin.updates = "true"} system property to apply the updates. * * @see AppMode#FORCE_PLUGIN_UPDATES * @see com.intellij.idea.Main#installPluginUpdates diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index 2f61299f4c4a..29e64234161f 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -19,7 +19,7 @@ - +