Cleanup (moving UpdatePluginsApp to more appropriate location; typos; formatting)

GitOrigin-RevId: 9883e2f5342953dde126f3aa97b9dac73cb79c2d
This commit is contained in:
Roman Shevchenko
2024-02-19 12:54:47 +01:00
committed by intellij-monorepo-bot
parent da7500caa0
commit 0b5363a00e
4 changed files with 52 additions and 66 deletions

View File

@@ -22,16 +22,14 @@ internal const val VERSION_OPTION: String = "version"
@JvmField @JvmField
internal val XML_PROLOG: ByteArray = """<?xml version="1.0" encoding="UTF-8"?>""".toByteArray() internal val XML_PROLOG: ByteArray = """<?xml version="1.0" encoding="UTF-8"?>""".toByteArray()
internal fun isSpecialStorage(collapsedPath: String): Boolean { internal fun isSpecialStorage(collapsedPath: String): Boolean =
return collapsedPath == StoragePathMacros.CACHE_FILE || collapsedPath == StoragePathMacros.PRODUCT_WORKSPACE_FILE collapsedPath == StoragePathMacros.CACHE_FILE || collapsedPath == StoragePathMacros.PRODUCT_WORKSPACE_FILE
}
@CalledInAny @CalledInAny
internal suspend fun ensureFilesWritable(project: Project, files: Collection<VirtualFile>): ReadonlyStatusHandler.OperationStatus { internal suspend fun ensureFilesWritable(project: Project, files: Collection<VirtualFile>): ReadonlyStatusHandler.OperationStatus =
return withContext(Dispatchers.EDT) { withContext(Dispatchers.EDT) {
ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files) ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files)
} }
}
internal fun loadDataAndDetectLineSeparator(file: Path): Pair<Element, LineSeparator?> { internal fun loadDataAndDetectLineSeparator(file: Path): Pair<Element, LineSeparator?> {
val text = ComponentStorageUtil.loadTextContent(file) val text = ComponentStorageUtil.loadTextContent(file)

View File

@@ -15,7 +15,6 @@ import com.intellij.openapi.util.BuildNumber;
import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.util.Url; import com.intellij.util.Url;
import com.intellij.util.Urls; import com.intellij.util.Urls;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.io.URLUtil; import com.intellij.util.io.URLUtil;
import com.intellij.util.text.VersionComparatorUtil; import com.intellij.util.text.VersionComparatorUtil;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
@@ -29,31 +28,30 @@ import java.util.*;
import static com.intellij.ide.plugins.BrokenPluginFileKt.isBrokenPlugin; import static com.intellij.ide.plugins.BrokenPluginFileKt.isBrokenPlugin;
/**
* @author stathik
*/
public final class RepositoryHelper { public final class RepositoryHelper {
private static final Logger LOG = Logger.getInstance(RepositoryHelper.class); private static final Logger LOG = Logger.getInstance(RepositoryHelper.class);
/** Duplicates VmOptionsGenerator.CUSTOM_BUILT_IN_PLUGIN_REPOSITORY_PROPERTY */ /** 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"; 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"; @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 MARKETPLACE_PLUGIN_ID = "com.intellij.marketplace";
private static final String ULTIMATE_MODULE = "com.intellij.modules.ultimate"; private static final String ULTIMATE_MODULE = "com.intellij.modules.ultimate";
/** /**
* Returns a list of configured plugin hosts. * 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() { public static @NotNull List<@Nullable String> getPluginHosts() {
List<String> hosts = new ArrayList<>(UpdateSettings.getInstance().getPluginHosts()); var hosts = new ArrayList<>(UpdateSettings.getInstance().getPluginHosts());
String pluginsUrl = ApplicationInfoEx.getInstanceEx().getBuiltinPluginsUrl(); @SuppressWarnings("deprecation") var pluginsUrl = ApplicationInfoEx.getInstanceEx().getBuiltinPluginsUrl();
if (pluginsUrl != null && !"__BUILTIN_PLUGINS_URL__".equals(pluginsUrl)) { if (pluginsUrl != null && !"__BUILTIN_PLUGINS_URL__".equals(pluginsUrl)) {
hosts.add(pluginsUrl); hosts.add(pluginsUrl);
} }
ContainerUtil.addIfNotNull(hosts, System.getProperty(CUSTOM_BUILT_IN_PLUGIN_REPOSITORY_PROPERTY)); pluginsUrl = System.getProperty(CUSTOM_BUILT_IN_PLUGIN_REPOSITORY_PROPERTY);
List<CustomPluginRepoContributor> repoContributors = CustomPluginRepoContributor.EP_NAME.getExtensionsIfPointIsRegistered(); if (pluginsUrl != null) {
for (CustomPluginRepoContributor contributor : repoContributors) { hosts.add(pluginsUrl);
}
for (var contributor : CustomPluginRepoContributor.EP_NAME.getExtensionsIfPointIsRegistered()) {
hosts.addAll(contributor.getRepoUrls()); hosts.addAll(contributor.getRepoUrls());
} }
hosts.add(null); // main plugin repository 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 Please use {@link #loadPlugins(String, BuildNumber, ProgressIndicator)} to get a list of {@link PluginNode}s.
*/ */
@Deprecated(forRemoval = true) @Deprecated(forRemoval = true)
public static @NotNull List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl, public static @NotNull List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl, @Nullable ProgressIndicator indicator) throws IOException {
@Nullable ProgressIndicator indicator) throws IOException {
return new ArrayList<>(loadPlugins(repositoryUrl, null, indicator)); return new ArrayList<>(loadPlugins(repositoryUrl, null, indicator));
} }
/** /**
* Use method only for getting plugins from custom repositories * Use method only for getting plugins from custom repositories
*/ */
public static @NotNull List<PluginNode> loadPlugins(@Nullable String repositoryUrl, public static @NotNull List<PluginNode> loadPlugins(
@Nullable BuildNumber build, @Nullable String repositoryUrl,
@Nullable ProgressIndicator indicator) throws IOException { @Nullable BuildNumber build,
@Nullable ProgressIndicator indicator
) throws IOException {
Path pluginListFile; Path pluginListFile;
Url url; Url url;
if (repositoryUrl == null) { if (repositoryUrl == null) {
if (ApplicationInfoImpl.getShadowInstance().usesJetBrainsPluginRepository()) { if (ApplicationInfoImpl.getShadowInstance().usesJetBrainsPluginRepository()) {
LOG.error("Using deprecated API for getting plugins from Marketplace"); LOG.error("Using deprecated API for getting plugins from Marketplace");
} }
String base = ApplicationInfoImpl.getShadowInstance().getPluginsListUrl(); var base = ApplicationInfoImpl.getShadowInstance().getPluginsListUrl();
url = Urls.newFromEncoded(base).addParameters(Map.of("uuid", PluginDownloader.getMarketplaceDownloadsUUID())); // NON-NLS url = Urls.newFromEncoded(base).addParameters(Map.of("uuid", PluginDownloader.getMarketplaceDownloadsUUID()));
pluginListFile = Paths.get(PathManager.getPluginsPath(), PLUGIN_LIST_FILE); pluginListFile = Paths.get(PathManager.getPluginsPath(), PLUGIN_LIST_FILE);
} }
else { else {
@@ -100,26 +99,18 @@ public final class RepositoryHelper {
indicator.setText2(IdeBundle.message("progress.connecting.to.plugin.manager", url.getAuthority())); indicator.setText2(IdeBundle.message("progress.connecting.to.plugin.manager", url.getAuthority()));
} }
List<PluginNode> descriptors = MarketplaceRequests.readOrUpdateFile(pluginListFile, var message = IdeBundle.message("progress.downloading.list.of.plugins", url.getAuthority());
url.toExternalForm(), var descriptors = MarketplaceRequests.readOrUpdateFile(pluginListFile, url.toExternalForm(), indicator, message, MarketplaceRequests::parsePluginList);
indicator, return process(descriptors, build != null ? build : PluginManagerCore.getBuildNumber(), repositoryUrl);
IdeBundle.message("progress.downloading.list.of.plugins",
url.getAuthority()),
MarketplaceRequests::parsePluginList);
return process(descriptors,
build != null ? build : PluginManagerCore.getBuildNumber(),
repositoryUrl);
} }
private static @NotNull List<PluginNode> process(@NotNull List<PluginNode> list, private static List<PluginNode> process(List<PluginNode> pluginNodes, BuildNumber build, @Nullable String repositoryUrl) {
@NotNull BuildNumber build, var result = new LinkedHashMap<PluginId, PluginNode>(pluginNodes.size());
@Nullable String repositoryUrl) {
Map<PluginId, PluginNode> result = new LinkedHashMap<>(list.size());
boolean isPaidPluginsRequireMarketplacePlugin = isPaidPluginsRequireMarketplacePlugin(); var isPaidPluginsRequireMarketplacePlugin = isPaidPluginsRequireMarketplacePlugin();
for (PluginNode node : list) { for (var node : pluginNodes) {
PluginId pluginId = node.getPluginId(); var pluginId = node.getPluginId();
if (repositoryUrl != null && node.getDownloadUrl() == null) { if (repositoryUrl != null && node.getDownloadUrl() == null) {
LOG.debug("Malformed plugin record (id:" + pluginId + " repository:" + repositoryUrl + ")"); LOG.debug("Malformed plugin record (id:" + pluginId + " repository:" + repositoryUrl + ")");
@@ -134,12 +125,13 @@ public final class RepositoryHelper {
if (repositoryUrl != null) { if (repositoryUrl != null) {
node.setRepositoryName(repositoryUrl); node.setRepositoryName(repositoryUrl);
} }
if (node.getName() == null) { if (node.getName() == null) {
String url = node.getDownloadUrl(); var url = node.getDownloadUrl();
node.setName(FileUtilRt.getNameWithoutExtension(url.substring(url.lastIndexOf('/') + 1))); 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) { if (previous == null || VersionComparatorUtil.compare(node.getVersion(), previous.getVersion()) > 0) {
result.put(pluginId, node); 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) { public static void addMarketplacePluginDependencyIfRequired(@NotNull PluginNode node) {
boolean isPaidPluginsRequireMarketplacePlugin = isPaidPluginsRequireMarketplacePlugin(); var isPaidPluginsRequireMarketplacePlugin = isPaidPluginsRequireMarketplacePlugin();
addMarketplacePluginDependencyIfRequired(node, isPaidPluginsRequireMarketplacePlugin); addMarketplacePluginDependencyIfRequired(node, isPaidPluginsRequireMarketplacePlugin);
} }
private static boolean isPaidPluginsRequireMarketplacePlugin() { private static boolean isPaidPluginsRequireMarketplacePlugin() {
boolean isCommunityIDE = !ideContainsUltimateModule(); var core = PluginManagerCore.findPlugin(PluginManagerCore.CORE_ID);
boolean isVendorNotJetBrains = !ApplicationInfoImpl.getShadowInstance().isVendorJetBrains(); return core == null || !core.modules.contains(PluginId.getId(ULTIMATE_MODULE)) || !ApplicationInfoImpl.getShadowInstance().isVendorJetBrains();
return isCommunityIDE || isVendorNotJetBrains;
} }
private static void addMarketplacePluginDependencyIfRequired(@NotNull PluginNode node, boolean isPaidPluginsRequireMarketplacePlugin) { private static void addMarketplacePluginDependencyIfRequired(PluginNode node, boolean isPaidPluginsRequireMarketplacePlugin) {
if (isPaidPluginsRequireMarketplacePlugin && node.getProductCode() != null) { if (isPaidPluginsRequireMarketplacePlugin && node.getProductCode() != null) {
node.addDepends(MARKETPLACE_PLUGIN_ID, false); 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 @ApiStatus.Internal
public static @NotNull Collection<PluginNode> mergePluginsFromRepositories(@NotNull List<PluginNode> marketplacePlugins, public static @NotNull Collection<PluginNode> mergePluginsFromRepositories(
@NotNull List<PluginNode> customPlugins, @NotNull List<PluginNode> marketplacePlugins,
boolean addMissing) { @NotNull List<PluginNode> customPlugins,
Map<PluginId, PluginNode> compatiblePluginMap = new LinkedHashMap<>(marketplacePlugins.size()); boolean addMissing
) {
var compatiblePluginMap = new LinkedHashMap<PluginId, PluginNode>(marketplacePlugins.size());
for (PluginNode marketplacePlugin : marketplacePlugins) { for (var marketplacePlugin : marketplacePlugins) {
compatiblePluginMap.put(marketplacePlugin.getPluginId(), marketplacePlugin); compatiblePluginMap.put(marketplacePlugin.getPluginId(), marketplacePlugin);
} }
for (PluginNode customPlugin : customPlugins) { for (var customPlugin : customPlugins) {
PluginId pluginId = customPlugin.getPluginId(); var pluginId = customPlugin.getPluginId();
IdeaPluginDescriptor plugin = compatiblePluginMap.get(pluginId); var plugin = compatiblePluginMap.get(pluginId);
if (plugin == null && addMissing || if (plugin == null && addMissing ||
plugin != null && PluginDownloader.compareVersionsSkipBrokenAndIncompatible(customPlugin.getVersion(), plugin) > 0) { plugin != null && PluginDownloader.compareVersionsSkipBrokenAndIncompatible(customPlugin.getVersion(), plugin) > 0) {
compatiblePluginMap.put(pluginId, customPlugin); compatiblePluginMap.put(pluginId, customPlugin);

View File

@@ -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. // 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.configurationStore.XmlSerializer;
import com.intellij.ide.plugins.RepositoryHelper;
import com.intellij.idea.AppMode; import com.intellij.idea.AppMode;
import com.intellij.openapi.application.ApplicationStarter; import com.intellij.openapi.application.ApplicationStarter;
import com.intellij.openapi.components.impl.stores.ComponentStorageUtil; import com.intellij.openapi.components.impl.stores.ComponentStorageUtil;
@@ -25,8 +24,9 @@ import java.util.List;
import java.util.Set; 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 * Works in two stages.
* {@code idea.force.plugin.updates = "true"} system property to apply the updates. * 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 AppMode#FORCE_PLUGIN_UPDATES
* @see com.intellij.idea.Main#installPluginUpdates * @see com.intellij.idea.Main#installPluginUpdates

View File

@@ -19,7 +19,7 @@
<appStarter id="diff" implementation="com.intellij.diff.applications.DiffApplication"/> <appStarter id="diff" implementation="com.intellij.diff.applications.DiffApplication"/>
<appStarter id="merge" implementation="com.intellij.diff.applications.MergeApplication"/> <appStarter id="merge" implementation="com.intellij.diff.applications.MergeApplication"/>
<appStarter id="reopen" implementation="com.intellij.ui.win.RecentProjectApplication"/> <appStarter id="reopen" implementation="com.intellij.ui.win.RecentProjectApplication"/>
<appStarter id="update" implementation="com.intellij.openapi.command.impl.UpdatePluginsApp"/> <appStarter id="update" implementation="com.intellij.ide.plugins.UpdatePluginsApp"/>
<appStarter id="keymap" implementation="com.intellij.help.impl.KeymapGenerator"/> <appStarter id="keymap" implementation="com.intellij.help.impl.KeymapGenerator"/>
<appStarter id="intentions" implementation="com.intellij.help.impl.IntentionDump"/> <appStarter id="intentions" implementation="com.intellij.help.impl.IntentionDump"/>
<appStarter id="inspections" implementation="com.intellij.help.impl.InspectionDump"/> <appStarter id="inspections" implementation="com.intellij.help.impl.InspectionDump"/>