mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
[remote dev] refactoring: use BuildNumber instead of String in code related to downloading of clients
This improves type safety and will make it easier to include product code in the build number (this will be needed for RDCT-235). (Changes in spaceport were reviewed in IJ-MR-145468.) GitOrigin-RevId: 1a2137f0f0b1861fdba6df1bda60ebc2ddf2884d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
63454e5ae9
commit
b3c0f4d21f
@@ -1,11 +1,12 @@
|
||||
package com.intellij.remoteDev.connection
|
||||
|
||||
import com.intellij.openapi.util.BuildNumber
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
@ApiStatus.Experimental
|
||||
open class JetBrainsClientDownloadInfo(
|
||||
val hostBuildNumber: String,
|
||||
val clientBuildNumber: String = hostBuildNumber,
|
||||
val hostBuildNumber: BuildNumber,
|
||||
val clientBuildNumber: BuildNumber = hostBuildNumber,
|
||||
val compatibleClientUrl: String,
|
||||
val compatibleJreUrl: String?,
|
||||
val downloadPgpPublicKeyUrl: String?
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.intellij.util.io.DigestUtil
|
||||
import com.intellij.util.io.HttpRequests
|
||||
import com.intellij.util.io.HttpRequests.HttpStatusException
|
||||
import com.intellij.util.system.CpuArch
|
||||
import com.intellij.util.text.VersionComparatorUtil
|
||||
import com.intellij.util.withFragment
|
||||
import com.intellij.util.withQuery
|
||||
import com.jetbrains.infra.pgpVerifier.JetBrainsPgpConstants
|
||||
@@ -79,7 +78,7 @@ object CodeWithMeClientDownloader {
|
||||
|
||||
val cwmJbrManifestFilter: (Path) -> Boolean = { !it.isDirectory() || isSymlink(it) }
|
||||
|
||||
fun getJetBrainsClientManifestFilter(clientBuildNumber: String): (Path) -> Boolean {
|
||||
fun getJetBrainsClientManifestFilter(clientBuildNumber: BuildNumber): (Path) -> Boolean {
|
||||
val universalFilter: (Path) -> Boolean = if (isClientWithBundledJre(clientBuildNumber)) {
|
||||
{ !it.isDirectory() || isSymlink(it) }
|
||||
} else {
|
||||
@@ -93,8 +92,8 @@ object CodeWithMeClientDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
private const val minimumClientBuildWithBundledJre = "223.4374"
|
||||
fun isClientWithBundledJre(clientBuildNumber: String) = clientBuildNumber.contains("SNAPSHOT") || VersionComparatorUtil.compare(clientBuildNumber, minimumClientBuildWithBundledJre) >= 0
|
||||
private val minimumClientBuildWithBundledJre = BuildNumber("", 223, 4374)
|
||||
fun isClientWithBundledJre(clientBuildNumber: BuildNumber) = clientBuildNumber.isSnapshot || clientBuildNumber > minimumClientBuildWithBundledJre
|
||||
|
||||
@ApiStatus.Internal
|
||||
class DownloadableFileData(
|
||||
@@ -140,32 +139,28 @@ object CodeWithMeClientDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getClientDistributionName(clientBuildVersion: String) = when {
|
||||
clientBuildVersion.contains("SNAPSHOT") -> "JetBrainsClient"
|
||||
VersionComparatorUtil.compare(clientBuildVersion, "211.6167") < 0 -> "IntelliJClient"
|
||||
VersionComparatorUtil.compare(clientBuildVersion, "213.5318") < 0 -> "CodeWithMeGuest"
|
||||
private fun getClientDistributionName(clientBuildNumber: BuildNumber) = when {
|
||||
clientBuildNumber.isSnapshot -> "JetBrainsClient"
|
||||
clientBuildNumber < BuildNumber("", 211, 6167) -> "IntelliJClient"
|
||||
clientBuildNumber < BuildNumber("", 213, 5318) -> "CodeWithMeGuest"
|
||||
else -> "JetBrainsClient"
|
||||
}
|
||||
|
||||
fun createSessionInfo(clientBuildVersion: String, jreBuild: String?, unattendedMode: Boolean): JetBrainsClientDownloadInfo {
|
||||
val buildNumber = requireNotNull(BuildNumber.fromStringOrNull(clientBuildVersion)) { "Invalid build version: $clientBuildVersion" }
|
||||
|
||||
val isSnapshot = buildNumber.isSnapshot
|
||||
fun createSessionInfo(hostBuildNumber: BuildNumber, jreBuild: String?, unattendedMode: Boolean): JetBrainsClientDownloadInfo {
|
||||
val isSnapshot = hostBuildNumber.isSnapshot
|
||||
if (isSnapshot) {
|
||||
LOG.warn("Thin client download from sources may result in failure due to different sources on host and client, " +
|
||||
"don't forget to update your locally built archive")
|
||||
}
|
||||
|
||||
val bundledJre = isClientWithBundledJre(clientBuildVersion)
|
||||
val bundledJre = isClientWithBundledJre(hostBuildNumber)
|
||||
val jreBuildToDownload = if (bundledJre) {
|
||||
null
|
||||
}
|
||||
else {
|
||||
jreBuild ?: error("JRE build number must be passed for client build number < $clientBuildVersion")
|
||||
jreBuild ?: error("JRE build number must be passed for client build number < ${hostBuildNumber.asStringWithoutProductCode()}")
|
||||
}
|
||||
|
||||
val hostBuildNumber = buildNumber.asStringWithoutProductCode()
|
||||
|
||||
val platformSuffix = if (jreBuildToDownload != null) when {
|
||||
SystemInfo.isLinux && CpuArch.isIntel64() -> "-no-jbr.tar.gz"
|
||||
SystemInfo.isLinux && CpuArch.isArm64() -> "-no-jbr-aarch64.tar.gz"
|
||||
@@ -184,10 +179,10 @@ object CodeWithMeClientDownloader {
|
||||
else -> null
|
||||
} ?: error("Current platform is not supported: OS ${SystemInfo.OS_NAME} ARCH ${SystemInfo.OS_ARCH}")
|
||||
|
||||
val clientDistributionName = getClientDistributionName(clientBuildVersion)
|
||||
val clientDistributionName = getClientDistributionName(hostBuildNumber)
|
||||
|
||||
val clientBuildNumber = if (isSnapshot && config.downloadLatestBuildFromCDNForSnapshotHost) getLatestBuild(hostBuildNumber) else hostBuildNumber
|
||||
val clientDownloadUrl = "${config.clientDownloadUrl.toString().trimEnd('/')}/$clientDistributionName-$clientBuildNumber$platformSuffix"
|
||||
val clientDownloadUrl = "${config.clientDownloadUrl.toString().trimEnd('/')}/$clientDistributionName-${clientBuildNumber.asStringWithoutProductCode()}$platformSuffix"
|
||||
|
||||
val jreDownloadUrl = if (jreBuildToDownload != null) {
|
||||
val platformString = when {
|
||||
@@ -226,7 +221,7 @@ object CodeWithMeClientDownloader {
|
||||
|
||||
val sessionInfo = JetBrainsClientDownloadInfo(
|
||||
hostBuildNumber = hostBuildNumber,
|
||||
clientBuildNumber = clientBuildNumber,
|
||||
clientBuildNumber = clientBuildNumber,
|
||||
compatibleClientUrl = clientDownloadUrl,
|
||||
compatibleJreUrl = jreDownloadUrl,
|
||||
downloadPgpPublicKeyUrl = pgpPublicKeyUrl
|
||||
@@ -236,15 +231,15 @@ object CodeWithMeClientDownloader {
|
||||
return sessionInfo
|
||||
}
|
||||
|
||||
private fun getLatestBuild(hostBuildNumber: String): String {
|
||||
val majorVersion = hostBuildNumber.substringBefore('.')
|
||||
val latestBuildTxtFileName = "$majorVersion-LAST-BUILD.txt"
|
||||
private fun getLatestBuild(hostBuildNumber: BuildNumber): BuildNumber {
|
||||
val latestBuildTxtFileName = "${hostBuildNumber.baselineVersion}-LAST-BUILD.txt"
|
||||
val latestBuildTxtUri = "${config.clientDownloadUrl.toASCIIString().trimEnd('/')}/$latestBuildTxtFileName"
|
||||
|
||||
val tempFile = Files.createTempFile(latestBuildTxtFileName, "")
|
||||
return try {
|
||||
downloadWithRetries(URI(latestBuildTxtUri), tempFile, EmptyProgressIndicator()).let {
|
||||
tempFile.readText().trim()
|
||||
val buildNumberString = tempFile.readText().trim()
|
||||
BuildNumber.fromStringOrNull(buildNumberString) ?: error("Invalid build number: $buildNumberString")
|
||||
}
|
||||
}
|
||||
finally {
|
||||
@@ -256,17 +251,18 @@ object CodeWithMeClientDownloader {
|
||||
|
||||
@Deprecated("Use downloadFrontend() instead")
|
||||
fun downloadClientAndJdk(clientBuildVersion: String, progressIndicator: ProgressIndicator): ExtractedJetBrainsClientData? {
|
||||
val installation = downloadFrontend(clientBuildVersion, progressIndicator) ?: return null
|
||||
val clientBuildNumber = BuildNumber.fromStringOrNull(clientBuildVersion) ?: return null
|
||||
val installation = downloadFrontend(clientBuildNumber, progressIndicator) ?: return null
|
||||
return ExtractedJetBrainsClientData(installation.installationHome, (installation as? StandaloneFrontendInstallation)?.jreDir,
|
||||
installation.buildNumber)
|
||||
installation.buildNumber.asStringWithoutProductCode())
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental
|
||||
fun downloadFrontend(clientBuildVersion: String, progressIndicator: ProgressIndicator): FrontendInstallation? {
|
||||
fun downloadFrontend(clientBuildNumber: BuildNumber, progressIndicator: ProgressIndicator): FrontendInstallation? {
|
||||
ApplicationManager.getApplication().assertIsNonDispatchThread()
|
||||
|
||||
val jdkBuildProgressIndicator = progressIndicator.createSubProgress(0.1)
|
||||
val jdkBuild = if (isClientWithBundledJre(clientBuildVersion)) {
|
||||
val jdkBuild = if (isClientWithBundledJre(clientBuildNumber)) {
|
||||
jdkBuildProgressIndicator.fraction = 1.0
|
||||
null
|
||||
} else {
|
||||
@@ -274,8 +270,8 @@ object CodeWithMeClientDownloader {
|
||||
LOG.info("Downloading Thin Client jdk-build.txt")
|
||||
jdkBuildProgressIndicator.text = RemoteDevUtilBundle.message("thinClientDownloader.checking")
|
||||
|
||||
val clientDistributionName = getClientDistributionName(clientBuildVersion)
|
||||
val clientJdkDownloadUrl = "${config.clientDownloadUrl}$clientDistributionName-$clientBuildVersion-jdk-build.txt"
|
||||
val clientDistributionName = getClientDistributionName(clientBuildNumber)
|
||||
val clientJdkDownloadUrl = "${config.clientDownloadUrl}$clientDistributionName-${clientBuildNumber.asStringWithoutProductCode()}-jdk-build.txt"
|
||||
LOG.info("Downloading from $clientJdkDownloadUrl")
|
||||
|
||||
val tempFile = Files.createTempFile("jdk-build", "txt")
|
||||
@@ -289,12 +285,12 @@ object CodeWithMeClientDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
val sessionInfo = createSessionInfo(clientBuildVersion, jdkBuild, true)
|
||||
val sessionInfo = createSessionInfo(clientBuildNumber, jdkBuild, true)
|
||||
return downloadFrontendAndJdk(sessionInfo, progressIndicator.createSubProgress(0.9))
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clientBuildVersion format: 213.1337[.23]
|
||||
* @param clientBuildNumber build number without product code
|
||||
* @param jreBuild format: 11_0_11b1536.1
|
||||
* where 11_0_11 is jdk version, b1536.1 is the build version
|
||||
* @returns Pair(path/to/thin/client, path/to/jre)
|
||||
@@ -302,42 +298,42 @@ object CodeWithMeClientDownloader {
|
||||
* Update this method (any jdk-related stuff) together with:
|
||||
* `org/jetbrains/intellij/build/impl/BundledJreManager.groovy`
|
||||
*/
|
||||
fun downloadFrontendAndJdk(clientBuildVersion: String,
|
||||
fun downloadFrontendAndJdk(clientBuildNumber: BuildNumber,
|
||||
jreBuild: String?,
|
||||
progressIndicator: ProgressIndicator): FrontendInstallation {
|
||||
ApplicationManager.getApplication().assertIsNonDispatchThread()
|
||||
|
||||
val sessionInfo = createSessionInfo(clientBuildVersion, jreBuild, true)
|
||||
val sessionInfo = createSessionInfo(clientBuildNumber, jreBuild, true)
|
||||
return downloadFrontendAndJdk(sessionInfo, progressIndicator)
|
||||
}
|
||||
|
||||
fun isClientDownloaded(
|
||||
clientBuildVersion: String,
|
||||
clientBuildNumber: BuildNumber,
|
||||
): Boolean {
|
||||
val clientUrl = createSessionInfo(clientBuildVersion, null, true).compatibleClientUrl
|
||||
val clientUrl = createSessionInfo(clientBuildNumber, null, true).compatibleClientUrl
|
||||
val tempDir = FileUtil.createTempDirectory("jb-cwm-dl", null).toPath()
|
||||
val guestData = DownloadableFileData.build(
|
||||
url = URI.create(clientUrl),
|
||||
tempDir = tempDir,
|
||||
cachesDir = config.clientCachesDir,
|
||||
includeInManifest = getJetBrainsClientManifestFilter(clientBuildVersion),
|
||||
includeInManifest = getJetBrainsClientManifestFilter(clientBuildNumber),
|
||||
)
|
||||
return isAlreadyDownloaded(guestData)
|
||||
}
|
||||
|
||||
fun extractedClientData(clientBuildVersion: String): StandaloneFrontendInstallation? {
|
||||
if (!isClientDownloaded(clientBuildVersion)) {
|
||||
fun extractedClientData(clientBuildNumber: BuildNumber): StandaloneFrontendInstallation? {
|
||||
if (!isClientDownloaded(clientBuildNumber)) {
|
||||
return null
|
||||
}
|
||||
val clientUrl = createSessionInfo(clientBuildVersion, null, true).compatibleClientUrl
|
||||
val clientUrl = createSessionInfo(clientBuildNumber, null, true).compatibleClientUrl
|
||||
val tempDir = FileUtil.createTempDirectory("jb-cwm-dl", null).toPath()
|
||||
val guestData = DownloadableFileData.build(
|
||||
url = URI.create(clientUrl),
|
||||
tempDir = tempDir,
|
||||
cachesDir = config.clientCachesDir,
|
||||
includeInManifest = getJetBrainsClientManifestFilter(clientBuildVersion),
|
||||
includeInManifest = getJetBrainsClientManifestFilter(clientBuildNumber),
|
||||
)
|
||||
return StandaloneFrontendInstallation(installationHome = guestData.targetPath, jreDir = null, buildNumber = clientBuildVersion)
|
||||
return StandaloneFrontendInstallation(installationHome = guestData.targetPath, jreDir = null, buildNumber = clientBuildNumber)
|
||||
}
|
||||
|
||||
|
||||
@@ -550,9 +546,9 @@ object CodeWithMeClientDownloader {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun createEmbeddedClientLauncherIfAvailable(expectedClientBuildNumber: String): EmbeddedClientLauncher? {
|
||||
internal fun createEmbeddedClientLauncherIfAvailable(expectedClientBuildNumber: BuildNumber): EmbeddedClientLauncher? {
|
||||
if (Registry.`is`("rdct.use.embedded.client") || Registry.`is`("rdct.always.use.embedded.client")) {
|
||||
val hostBuildNumberString = BuildNumber.fromStringOrNull(expectedClientBuildNumber)?.withoutProductCode()
|
||||
val hostBuildNumberString = expectedClientBuildNumber.withoutProductCode()
|
||||
val currentIdeBuildNumber = ApplicationInfo.getInstance().build.withoutProductCode()
|
||||
LOG.debug("Host build number: $hostBuildNumberString, current IDE build number: $currentIdeBuildNumber")
|
||||
if (hostBuildNumberString == currentIdeBuildNumber || Registry.`is`("rdct.always.use.embedded.client")) {
|
||||
@@ -730,7 +726,7 @@ object CodeWithMeClientDownloader {
|
||||
|
||||
return runJetBrainsClientProcess(launcherData,
|
||||
workingDirectory = frontendInstallation.installationHome,
|
||||
clientVersion = frontendInstallation.buildNumber,
|
||||
clientBuild = frontendInstallation.buildNumber,
|
||||
url, lifetime)
|
||||
|
||||
}
|
||||
@@ -739,15 +735,15 @@ object CodeWithMeClientDownloader {
|
||||
|
||||
internal fun runJetBrainsClientProcess(launcherData: JetBrainsClientLauncherData,
|
||||
workingDirectory: Path,
|
||||
clientVersion: String,
|
||||
clientBuild: BuildNumber,
|
||||
url: String,
|
||||
lifetime: Lifetime): Lifetime {
|
||||
return runJetBrainsClientProcess(launcherData, workingDirectory, clientVersion, url, emptyList(), lifetime)
|
||||
return runJetBrainsClientProcess(launcherData, workingDirectory, clientBuild, url, emptyList(), lifetime)
|
||||
}
|
||||
|
||||
internal fun runJetBrainsClientProcess(launcherData: JetBrainsClientLauncherData,
|
||||
workingDirectory: Path,
|
||||
clientVersion: String,
|
||||
clientBuild: BuildNumber,
|
||||
url: String,
|
||||
extraArguments: List<String>,
|
||||
lifetime: Lifetime): Lifetime {
|
||||
@@ -757,7 +753,7 @@ object CodeWithMeClientDownloader {
|
||||
val vmOptionsFile = if (SystemInfoRt.isMac) {
|
||||
// macOS stores vmoptions file inside .app file – we can't edit it
|
||||
Paths.get(
|
||||
PathManager.getDefaultConfigPathFor(PlatformUtils.JETBRAINS_CLIENT_PREFIX + clientVersion),
|
||||
PathManager.getDefaultConfigPathFor(PlatformUtils.JETBRAINS_CLIENT_PREFIX + clientBuild.asStringWithoutProductCode()),
|
||||
"jetbrains_client.vmoptions"
|
||||
)
|
||||
} else if (SystemInfoRt.isWindows) launcherData.executable.resolveSibling("jetbrains_client64.exe.vmoptions")
|
||||
@@ -765,7 +761,7 @@ object CodeWithMeClientDownloader {
|
||||
service<JetBrainsClientDownloaderConfigurationProvider>().patchVmOptions(vmOptionsFile, URI(url))
|
||||
|
||||
val clientEnvironment = mutableMapOf<String, String>()
|
||||
val separateConfigOption = ClientVersionUtil.computeSeparateConfigEnvVariableValue(clientVersion)
|
||||
val separateConfigOption = ClientVersionUtil.computeSeparateConfigEnvVariableValue(clientBuild)
|
||||
if (separateConfigOption != null) {
|
||||
clientEnvironment["JBC_SEPARATE_CONFIG"] = separateConfigOption
|
||||
}
|
||||
@@ -953,11 +949,8 @@ object CodeWithMeClientDownloader {
|
||||
return jbrDirectory
|
||||
}
|
||||
|
||||
fun versionsMatch(hostBuildNumberString: String, localBuildNumberString: String): Boolean {
|
||||
fun versionsMatch(hostBuildNumber: BuildNumber, localBuildNumber: BuildNumber): Boolean {
|
||||
try {
|
||||
val hostBuildNumber = BuildNumber.fromString(hostBuildNumberString)!!
|
||||
val localBuildNumber = BuildNumber.fromString(localBuildNumberString)!!
|
||||
|
||||
// Any guest in that branch compatible with SNAPSHOT version (it's used by IDEA developers mostly)
|
||||
if ((localBuildNumber.isSnapshot || hostBuildNumber.isSnapshot) && hostBuildNumber.baselineVersion == localBuildNumber.baselineVersion) {
|
||||
return true
|
||||
@@ -966,7 +959,7 @@ object CodeWithMeClientDownloader {
|
||||
return hostBuildNumber.asStringWithoutProductCode() == localBuildNumber.asStringWithoutProductCode()
|
||||
}
|
||||
catch (t: Throwable) {
|
||||
LOG.error("Error comparing versions $hostBuildNumberString and $localBuildNumberString: ${t.message}", t)
|
||||
LOG.error("Error comparing versions $hostBuildNumber and $localBuildNumber: ${t.message}", t)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.intellij.openapi.progress.Task.Backgroundable
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.rd.createLifetime
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.util.BuildNumber
|
||||
import com.intellij.openapi.util.NlsContexts
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.remoteDev.RemoteDevUtilBundle
|
||||
@@ -34,7 +35,7 @@ object CodeWithMeGuestLauncher {
|
||||
fun downloadCompatibleClientAndLaunch(
|
||||
lifetime: Lifetime?,
|
||||
project: Project?,
|
||||
clientBuild: String?,
|
||||
clientBuild: BuildNumber?,
|
||||
url: String,
|
||||
@NlsContexts.DialogTitle product: String,
|
||||
onDone: (Lifetime) -> Unit = {}
|
||||
@@ -74,8 +75,9 @@ object CodeWithMeGuestLauncher {
|
||||
try {
|
||||
val sessionInfo = when (uri.scheme) {
|
||||
"tcp", "gwws" -> {
|
||||
val clientBuild = uri.fragmentParameters["cb"] ?: error("there is no client build in url")
|
||||
val clientBuildString = uri.fragmentParameters["cb"] ?: error("there is no client build in url")
|
||||
val jreBuild = uri.fragmentParameters["jb"] ?: error("there is no jre build in url")
|
||||
val clientBuild = BuildNumber.fromStringOrNull(clientBuildString) ?: error("invalid client build: $clientBuildString")
|
||||
val unattendedMode = isUnattendedModeUri(uri)
|
||||
|
||||
CodeWithMeClientDownloader.createSessionInfo(clientBuild, jreBuild, unattendedMode)
|
||||
@@ -114,7 +116,7 @@ object CodeWithMeGuestLauncher {
|
||||
}
|
||||
|
||||
private fun runAlreadyDownloadedClient(
|
||||
clientBuild: String?,
|
||||
clientBuild: BuildNumber?,
|
||||
aLifetime: Lifetime?,
|
||||
project: Project?,
|
||||
url: String,
|
||||
|
||||
@@ -89,9 +89,9 @@ class EmbeddedClientLauncher private constructor(private val moduleRepository: R
|
||||
LOG.debug("Start embedded client using launcher")
|
||||
val workingDirectory = Path(PathManager.getHomePath())
|
||||
return CodeWithMeClientDownloader.runJetBrainsClientProcess(
|
||||
launcherData,
|
||||
launcherData,
|
||||
workingDirectory,
|
||||
clientVersion = ApplicationInfo.getInstance().build.asStringWithoutProductCode(),
|
||||
clientBuild = ApplicationInfo.getInstance().build.withoutProductCode(),
|
||||
url,
|
||||
extraArguments,
|
||||
lifetime
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.intellij.remoteDev.downloader
|
||||
|
||||
import com.intellij.openapi.application.ApplicationInfo
|
||||
import com.intellij.openapi.application.PathManager
|
||||
import com.intellij.openapi.util.BuildNumber
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
|
||||
@@ -10,7 +11,7 @@ import kotlin.io.path.Path
|
||||
*/
|
||||
sealed interface FrontendInstallation {
|
||||
val installationHome: Path
|
||||
val buildNumber: String
|
||||
val buildNumber: BuildNumber
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -18,7 +19,7 @@ sealed interface FrontendInstallation {
|
||||
*/
|
||||
class StandaloneFrontendInstallation(
|
||||
override val installationHome: Path,
|
||||
override val buildNumber: String,
|
||||
override val buildNumber: BuildNumber,
|
||||
/** JBR is bundled with new versions of the frontend, this property is `null` in such cases */
|
||||
val jreDir: Path?,
|
||||
) : FrontendInstallation
|
||||
@@ -29,8 +30,8 @@ class StandaloneFrontendInstallation(
|
||||
class EmbeddedFrontendInstallation(
|
||||
val frontendLauncher: EmbeddedClientLauncher
|
||||
) : FrontendInstallation {
|
||||
override val buildNumber: String
|
||||
get() = ApplicationInfo.getInstance().build.asStringWithoutProductCode()
|
||||
override val buildNumber: BuildNumber
|
||||
get() = ApplicationInfo.getInstance().build.withoutProductCode()
|
||||
override val installationHome: Path
|
||||
get() = Path(PathManager.getHomePath())
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JacksonException
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.intellij.openapi.application.ApplicationInfo
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.util.BuildNumber
|
||||
import com.intellij.openapi.util.SystemInfo
|
||||
import com.intellij.remoteDev.connection.JetBrainsClientDownloadInfo
|
||||
import com.intellij.remoteDev.downloader.exceptions.CodeWithMeUnavailableException
|
||||
@@ -74,8 +75,9 @@ object ThinClientSessionInfoFetcher {
|
||||
|
||||
val sessionInfo = objectMapper.value.reader().readTree(jsonResponseString)
|
||||
val jreUrlNode = sessionInfo["compatibleJreUrl"]
|
||||
val hostBuildNumber = sessionInfo["hostBuildNumber"].asText()
|
||||
return@connect JetBrainsClientDownloadInfo(
|
||||
hostBuildNumber = sessionInfo["hostBuildNumber"].asText(),
|
||||
hostBuildNumber = BuildNumber.fromStringOrNull(hostBuildNumber) ?: error("Invalid host build number: $hostBuildNumber"),
|
||||
compatibleClientUrl = sessionInfo["compatibleClientUrl"].asText(),
|
||||
compatibleJreUrl = if (jreUrlNode.isNull) null else jreUrlNode.asText(),
|
||||
downloadPgpPublicKeyUrl = sessionInfo["downloadPgpPublicKeyUrl"]?.asText()
|
||||
|
||||
@@ -16,25 +16,19 @@ object ClientVersionUtil {
|
||||
private val sameDefaultPathsAsLocalIdesUsedSince: BuildNumber
|
||||
get() = BuildNumber("", 242, 13718)
|
||||
|
||||
fun isJBCSeparateConfigSupported(clientVersion: String): Boolean {
|
||||
val clientBuild = BuildNumber.fromString(clientVersion)
|
||||
return clientBuild != null && isSeparateConfigSupported(clientBuild)
|
||||
}
|
||||
fun isSeparateConfigSupported(clientBuild: BuildNumber): Boolean =
|
||||
clientBuild >= separateConfigSupportedSince || clientBuild.baselineVersion == 232 && clientBuild >= separateConfigSupportedSince232
|
||||
|
||||
fun isClientUsesTheSamePathsAsLocalIde(clientVersion: String): Boolean {
|
||||
val clientBuild = BuildNumber.fromString(clientVersion)
|
||||
return clientBuild != null && clientBuild >= sameDefaultPathsAsLocalIdesUsedSince
|
||||
}
|
||||
|
||||
private fun isSeparateConfigSupported(clientBuild: BuildNumber) =
|
||||
clientBuild >= separateConfigSupportedSince || clientBuild.baselineVersion == 232 && clientBuild >= separateConfigSupportedSince232
|
||||
|
||||
/**
|
||||
* Returns value which should be assigned to 'JBC_SEPARATE_CONFIG' environment variable to explicitly enable or disable the "separate
|
||||
* process per connection" mode.
|
||||
*/
|
||||
fun computeSeparateConfigEnvVariableValue(clientVersion: String): String? {
|
||||
val clientBuild = BuildNumber.fromString(clientVersion) ?: return null
|
||||
fun computeSeparateConfigEnvVariableValue(clientBuild: BuildNumber): String? {
|
||||
if (isSeparateConfigSupported(clientBuild) &&
|
||||
!(clientBuild >= separateConfigEnabledByDefaultSince ||
|
||||
clientBuild.baselineVersion == 232 && clientBuild >= separateConfigEnabledByDefaultSince232)) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.intellij.remoteDev.util
|
||||
|
||||
import com.intellij.openapi.util.BuildNumber
|
||||
import com.intellij.remoteDev.util.ClientVersionUtil.computeSeparateConfigEnvVariableValue
|
||||
import com.intellij.remoteDev.util.ClientVersionUtil.isJBCSeparateConfigSupported
|
||||
import com.intellij.remoteDev.util.ClientVersionUtil.isSeparateConfigSupported
|
||||
import com.intellij.testFramework.junit5.TestApplication
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
@@ -12,21 +13,24 @@ class ClientVersionUtilTest {
|
||||
@ValueSource(strings = ["232.9552", "232.9559.2", "232.SNAPSHOT", "233.2350", "233.SNAPSHOT", "241.1", "241.SNAPSHOT"])
|
||||
@ParameterizedTest
|
||||
fun `separate config supported and enabled`(version: String) {
|
||||
assertTrue(isJBCSeparateConfigSupported(version))
|
||||
assertNull(computeSeparateConfigEnvVariableValue(version))
|
||||
val buildNumber = BuildNumber.fromString(version)!!
|
||||
assertTrue(isSeparateConfigSupported(buildNumber))
|
||||
assertNull(computeSeparateConfigEnvVariableValue(buildNumber))
|
||||
}
|
||||
|
||||
@ValueSource(strings = ["233.172", "232.8660", "232.8660.185"])
|
||||
@ParameterizedTest
|
||||
fun `separate config not supported`(version: String) {
|
||||
assertFalse(isJBCSeparateConfigSupported(version))
|
||||
assertNull(computeSeparateConfigEnvVariableValue(version))
|
||||
val buildNumber = BuildNumber.fromString(version)!!
|
||||
assertFalse(isSeparateConfigSupported(buildNumber))
|
||||
assertNull(computeSeparateConfigEnvVariableValue(buildNumber))
|
||||
}
|
||||
|
||||
@ValueSource(strings = ["232.8661", "233.173", "233.2349"])
|
||||
@ParameterizedTest
|
||||
fun `separate config supported but not enabled`(version: String) {
|
||||
assertTrue(isJBCSeparateConfigSupported(version))
|
||||
assertEquals("true", computeSeparateConfigEnvVariableValue(version))
|
||||
val buildNumber = BuildNumber.fromString(version)!!
|
||||
assertTrue(isSeparateConfigSupported(buildNumber))
|
||||
assertEquals("true", computeSeparateConfigEnvVariableValue(buildNumber))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user