From b75eb32eeffef58baf24a88c2f7437bf0d323c1d Mon Sep 17 00:00:00 2001 From: Nikita Iarychenko Date: Wed, 18 Jun 2025 19:00:43 +0400 Subject: [PATCH] OPENIDE refactor OpenIdePluginBundler --- .../src/ru/openide/OpenIdePluginBundler.kt | 49 +++---------------- 1 file changed, 6 insertions(+), 43 deletions(-) diff --git a/openide/src/ru/openide/OpenIdePluginBundler.kt b/openide/src/ru/openide/OpenIdePluginBundler.kt index a981379aa123..e76103dbcd93 100644 --- a/openide/src/ru/openide/OpenIdePluginBundler.kt +++ b/openide/src/ru/openide/OpenIdePluginBundler.kt @@ -13,39 +13,35 @@ // along with this program. If not, see http://www.gnu.org/licenses/. package ru.openide -import com.intellij.openapi.util.JDOMUtil import com.intellij.util.Urls -import com.intellij.util.io.HttpRequests -import org.jdom.Element import org.jetbrains.intellij.build.BuildContext +import org.jetbrains.intellij.build.BuildPaths.Companion.COMMUNITY_ROOT import org.jetbrains.intellij.build.dependencies.BuildDependenciesDownloader import org.jetbrains.intellij.build.dependencies.BuildDependenciesExtractOptions -import org.jetbrains.intellij.build.BuildPaths.Companion.COMMUNITY_ROOT import java.net.URI import java.nio.file.Path object OpenIdePluginBundler { private const val DOWNLOADABLE_PLUGINS_DIR = "build/download/plugins" - private const val AMPLICODE_URL = "https://amplicode.ru" - private const val AMPLICODE_MARKETPLACE_URL = "https://amplicode.ru/jetbrains-marketplace" private const val PLUGINS_DOWNLOAD_URL = "https://plugins.openide.ru/pluginManager" private val plugins = listOf( PluginInfo("Lombook Plugin", "lombok"), - PluginInfo("com.haulmont.intellij.rupack", "ru_pack") + PluginInfo("com.haulmont.intellij.rupack", "ru_pack"), + PluginInfo("com.haulmont.amplicode", "amplicode") ) fun getBundlePluginPaths(context: BuildContext): List { if (System.getProperty("without.bundle.plugins") != null) return emptyList() val communityHomeDir = context.paths.communityHomeDir - return plugins.map { Path.of("${communityHomeDir}/$DOWNLOADABLE_PLUGINS_DIR/${it.folderName}") } + - listOf(Path.of("${communityHomeDir}/$DOWNLOADABLE_PLUGINS_DIR/amplicode")) + return plugins.map { + Path.of("${communityHomeDir}/$DOWNLOADABLE_PLUGINS_DIR/${it.folderName}") + } } fun bundlePlugins(context: BuildContext) { plugins.forEach { bundlePluginFromMarketplace(context, it) } - bundleAmplicodePlugin(context) } private fun bundlePluginFromMarketplace(context: BuildContext, pluginInfo: PluginInfo) { @@ -64,38 +60,5 @@ object OpenIdePluginBundler { BuildDependenciesDownloader.extractFile(archivePath, targetDir, COMMUNITY_ROOT, BuildDependenciesExtractOptions.STRIP_ROOT) } - // TODO: download amplicode from marketplace like lombok plugin - private fun bundleAmplicodePlugin(context: BuildContext) { - val majorVersion = context.buildNumber.substringBefore('.') - val uri = resolveAmplicodeUri(majorVersion) - val archivePath = BuildDependenciesDownloader.downloadFileToCacheLocation(COMMUNITY_ROOT, uri) - val targetDir = context.paths.communityHomeDir.resolve("$DOWNLOADABLE_PLUGINS_DIR/amplicode") - BuildDependenciesDownloader.extractFile(archivePath, targetDir, COMMUNITY_ROOT, BuildDependenciesExtractOptions.STRIP_ROOT) - } - - private fun resolveAmplicodeUri(majorVersion: String): URI { - val result = runCatching { - HttpRequests.request(AMPLICODE_MARKETPLACE_URL) - .connect { JDOMUtil.load(it.getReader()) } - .let { findFragmentUrl(it, majorVersion) } - } - - val specificUrl = result.getOrThrow().substring(1) - return URI.create("$AMPLICODE_URL$specificUrl") - } - - private fun findFragmentUrl(element: Element?, majorVersion: String): String { - return element?.getChildren("plugin") - ?.lastOrNull { it.getAttributeValue("version").extractMajorVersion() == majorVersion } - ?.getAttributeValue("url") - ?: throw RuntimeException("Amlicode plugin url not found for $majorVersion version") - } - - private fun String.extractMajorVersion(): String? { - val regex = Regex("""-(\d+?)(?:-EAP)?$""") - val match = regex.find(this) - return match?.groupValues?.get(1) - } - private class PluginInfo(val pluginId: String, val folderName: String) } \ No newline at end of file