OPENIDE refactor OpenIdePluginBundler

This commit is contained in:
Nikita Iarychenko
2025-06-18 19:00:43 +04:00
parent 46500e9e00
commit b75eb32eef

View File

@@ -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<Path> {
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)
}