Skip to content

Commit 1f05071

Browse files
committed
product-info: drop BuildInfo.getActualIdeaBuild extension method, instead read the build number from product info #SCL-22564
1 parent 0d4f01f commit 1f05071

7 files changed

Lines changed: 34 additions & 27 deletions

File tree

ideaSupport/src/main/scala/org/jetbrains/sbtidea/download/CommunityUpdater.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CommunityUpdater(
3939
def update(): Unit = {
4040
topoSort(dependencies).foreach(update)
4141

42-
val actualBuildNumber = ideaBuildInfo.getActualIdeaBuild(baseDirectory)
42+
val actualBuildNumber = context.productInfo.buildNumber
4343
val buildNumber = ideaBuildInfo.buildNumber
4444
if (buildNumber != actualBuildNumber) {
4545
log.warn(

ideaSupport/src/main/scala/org/jetbrains/sbtidea/download/package.scala

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,5 @@ package object download {
4040
}
4141
}
4242

43-
implicit class BuildInfoOps(private val buildInfo: BuildInfo) extends AnyVal {
44-
45-
/**
46-
* @note build number can be obtained from two places:
47-
* - build.txt
48-
* - product-info.json
49-
* In this method we use `build.txt` because has a primitive structure
50-
*/
51-
def getActualIdeaBuild(ideaRoot: Path): String = {
52-
val buildTxt = ideaRoot.resolve("build.txt")
53-
//example: `IU-241.17011.2`
54-
val content = new String(Files.readAllBytes(buildTxt)).trim
55-
content.substring(content.indexOf("-") + 1)
56-
}
57-
}
58-
5943
val NotFoundHttpResponseCode = 404
6044
}

ideaSupport/src/main/scala/org/jetbrains/sbtidea/download/plugin/PluginRepoUtils.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ class PluginRepoUtils(implicit ctx: InstallContext) extends PluginRepoApi {
2020
case IntellijPlugin.Id(id, Some(version), channel, _) =>
2121
MerketplaceUrls.download(id, version, channel)
2222
case IntellijPlugin.Id(id, None, channel, _) =>
23-
MerketplaceUrls.downloadViaPLuginManager(id, idea, channel)
23+
MerketplaceUrls.downloadViaPluginManager(id, idea, channel)
2424
}
2525

2626
private object MerketplaceUrls {
2727
private val BaseUrl = "https://plugins.jetbrains.com"
2828

2929
def pluginsList(id: String, buildInfo: BuildInfo, channel: Option[String]): URL = {
3030
val edition = buildInfo.edition.edition
31-
val buildNumber = buildInfo.getActualIdeaBuild(ctx.baseDirectory)
31+
val buildNumber = ctx.productInfo.buildNumber
3232
val channelQuery = channel.fold("")(c => s"&channel=$c")
3333
new URL(s"$BaseUrl/plugins/list?pluginId=$id$channelQuery&build=$edition-$buildNumber")
3434
}
@@ -38,9 +38,9 @@ class PluginRepoUtils(implicit ctx: InstallContext) extends PluginRepoApi {
3838
new URL(s"$BaseUrl/plugin/download?noStatistic=true&pluginId=$id&version=$version$channelQuery")
3939
}
4040

41-
def downloadViaPLuginManager(id: String, buildInfo: BuildInfo, channel: Option[String]): URL = {
41+
def downloadViaPluginManager(id: String, buildInfo: BuildInfo, channel: Option[String]): URL = {
4242
val edition = buildInfo.edition.edition
43-
val buildNumber = buildInfo.getActualIdeaBuild(ctx.baseDirectory)
43+
val buildNumber = ctx.productInfo.buildNumber
4444
val channelQuery = channel.fold("")(c => s"&channel=$c")
4545
new URL(s"$BaseUrl/pluginManager?action=download&noStatistic=true&id=$id$channelQuery&build=$edition-$buildNumber")
4646
}

ideaSupport/src/main/scala/org/jetbrains/sbtidea/download/plugin/RepoPluginInstaller.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class RepoPluginInstaller(buildInfo: BuildInfo)
102102
private[plugin] def isPluginCompatibleWithIdea(metadata: PluginDescriptor)(implicit ctx: InstallContext): Boolean = {
103103
val lower = metadata.sinceBuild.replaceAll("^.+-", "") // strip IC- / PC- etc. prefixes
104104
val upper = metadata.untilBuild.replaceAll("^.+-", "")
105-
val actualIdeaBuild = buildInfo.getActualIdeaBuild(ctx.baseDirectory)
105+
val actualIdeaBuild = ctx.productInfo.buildNumber
106106
val lowerValid = compareIdeaVersions(lower, actualIdeaBuild) <= 0
107107
val upperValid = compareIdeaVersions(upper, actualIdeaBuild) >= 0
108108
lowerValid && upperValid

ideaSupport/src/main/scala/org/jetbrains/sbtidea/tasks/SearchPluginId.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class SearchPluginId(
4949
private def searchPluginIdRemote(queryRaw: String): Map[String, (String, Boolean)] = {
5050
try {
5151
val query: String = URLEncoder.encode(queryRaw, "UTF-8")
52-
val build: String = s"${buildInfo.edition.edition}-${buildInfo.getActualIdeaBuild(ideaRoot)}"
52+
val build: String = s"${buildInfo.edition.edition}-${context.productInfo.buildNumber}"
5353
val url: String = getMarketplaceSearchUrl(query, build)
5454
val data: String = getHttpGetResponseString(url)
5555

ideaSupport/src/test/scala/org/jetbrains/sbtidea/download/idea/IdeaInstallerTest.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ class IdeaInstallerTest extends AnyFunSuite with Matchers with IdeaMock with Tmp
3535
val dist = getDistCopy
3636
val ideaInstallRoot = installer.installDist(dist)
3737
ideaInstallRoot.toFile.exists() shouldBe true
38-
ideaInstallRoot.list.map(_.getFileName.toString) should contain allElementsOf Seq("lib", "bin", "plugins", "build.txt")
39-
}
4038

39+
val fileNamesInRoot = ideaInstallRoot.list.map(_.getFileName.toString).toList
40+
fileNamesInRoot should contain allElementsOf Seq(
41+
"lib",
42+
"bin",
43+
"plugins",
44+
"product-info.json",
45+
"build.txt",
46+
"dependencies.txt"
47+
)
48+
}
4149
}

ideaSupport/src/test/scala/org/jetbrains/sbtidea/download/plugin/PluginRepoUtilsTest.scala

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.jetbrains.sbtidea.download.plugin
33
import org.apache.commons.io.FileUtils
44
import org.jetbrains.sbtidea.download.BuildInfo
55
import org.jetbrains.sbtidea.download.api.InstallContext
6+
import org.jetbrains.sbtidea.productInfo.{ProductInfo, ProductInfoParser}
67
import org.jetbrains.sbtidea.{IntelliJPlatform, IntellijPlugin}
78
import org.scalatest.BeforeAndAfterAll
89
import org.scalatest.featurespec.AnyFeatureSpecLike
@@ -12,6 +13,20 @@ import java.nio.file.Files
1213

1314
class PluginRepoUtilsTest extends AnyFeatureSpecLike with BeforeAndAfterAll {
1415

16+
private def createDummyProductInfoJson(buildNumber: String): String = {
17+
val productInfo = ProductInfo(
18+
name = "",
19+
version = "",
20+
versionSuffix = "",
21+
buildNumber = buildNumber,
22+
productCode = "",
23+
modules = Nil,
24+
launch = Nil,
25+
layout = Nil
26+
)
27+
ProductInfoParser.toJsonString(productInfo)
28+
}
29+
1530
Feature("getPluginDownloadURL") {
1631
val buildInfo = BuildInfo("1.2.3", IntelliJPlatform.IdeaUltimate)
1732

@@ -20,8 +35,8 @@ class PluginRepoUtilsTest extends AnyFeatureSpecLike with BeforeAndAfterAll {
2035
val downloadDir = Files.createTempDirectory("PluginRepoUtilsTest_downloadDir")
2136

2237
FileUtils.writeStringToFile(
23-
baseDir.resolve("build.txt").toFile,
24-
"IU-11.22.33-actual",
38+
baseDir.resolve("product-info.json").toFile,
39+
createDummyProductInfoJson("11.22.33-actual"),
2540
"UTF-8"
2641
)
2742

0 commit comments

Comments
 (0)