Skip to content

Commit 960f613

Browse files
committed
Install unbundled plugin dependencies into dev IDE #SCL-23786 fixed
Install the plugin dependencies and updates into `<ideaHome>/sdk/%version%/custom-plugins`. This keeps an option to roll back a bundled plugin update compared to `<ideaHome>/sdk/%version%/plugins` and supports versioning compared to `<ideaHome>/system/plugins`, i.e.: you can have different plugins/versions in different branches. Pass this path as `-Didea.plugins.path` so that IDE's plugin manager could pick up these custom plugins
1 parent e0adceb commit 960f613

5 files changed

Lines changed: 31 additions & 8 deletions

File tree

ideaSupport/src/main/scala/org/jetbrains/sbtidea/download/api/IdeInstallationProcessContext.scala

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jetbrains.sbtidea.download.api
22

3+
import org.jetbrains.sbtidea.download.api.IdeInstallationContext.customPluginsDirName
34
import org.jetbrains.sbtidea.productInfo.{ProductInfo, ProductInfoParser}
45
import sbt.pathToPathOps
56

@@ -18,7 +19,21 @@ sealed class IdeInstallationContext(
1819
ProductInfoParser.parse(productInfoFile.toFile)
1920
}
2021

21-
def pluginsDir: Path = baseDirectory / "plugins"
22+
/**
23+
* Represents the path to the "custom" plugins:
24+
* - installed via Marketplace;
25+
* - installed via "Install Plugin from Disk";
26+
* - plugins from [[org.jetbrains.sbtidea.Keys.intellijPlugins]], except bundled;
27+
* - a plugin from `org.jetbrains.sbtidea.packaging.PackagingKeys.packageOutputDir` when running locally;
28+
* - updates for bundled plugins.
29+
*
30+
* Passed to the IDE via `-Didea.plugins.path` option, see [[org.jetbrains.sbtidea.runIdea.IntellijVMOptionsBuilder.build]]
31+
*/
32+
def pluginsDir: Path = baseDirectory / customPluginsDirName
33+
}
34+
35+
object IdeInstallationContext {
36+
val customPluginsDirName: String = "custom-plugins"
2237
}
2338

2439
/**
@@ -31,4 +46,4 @@ sealed class IdeInstallationContext(
3146
final class IdeInstallationProcessContext(
3247
baseDirectory: Path,
3348
val artifactsDownloadsDir: Path
34-
) extends IdeInstallationContext(baseDirectory)
49+
) extends IdeInstallationContext(baseDirectory)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,21 @@ class RepoPluginInstaller(buildInfo: BuildInfo)
4949
downloadInfo: Option[PluginDownloadInfo] = None
5050
)(implicit ctx: IdeInstallationContext): Path = {
5151
val downloadedPluginFileNameHint = downloadInfo.map(_.downloadedFileName).fold("")(name => s" ($name)")
52+
val pluginsInstallationDir = Files.createDirectories(ctx.pluginsDir)
5253
val installedPluginRoot = if (!PluginXmlDetector.Default.isPluginJar(artifact)) {
5354
val tmpPluginDir = extractPluginToTemporaryDir(
5455
artifact,
5556
plugin,
5657
s"${buildInfo.edition.name}-${buildInfo.buildNumber}-plugin"
5758
)
58-
val installDir = ctx.pluginsDir.resolve(tmpPluginDir.getFileName)
59+
val installDir = pluginsInstallationDir.resolve(tmpPluginDir.getFileName)
5960
NioUtils.delete(installDir)
6061
Files.move(tmpPluginDir, installDir)
6162
NioUtils.delete(tmpPluginDir.getParent)
6263
log.info(s"Installed plugin '$plugin'$downloadedPluginFileNameHint to $installDir")
6364
installDir
6465
} else {
65-
val targetJar = ctx.pluginsDir.resolve(artifact.getFileName)
66+
val targetJar = pluginsInstallationDir.resolve(artifact.getFileName)
6667
Files.move(artifact, targetJar)
6768
log.info(s"Installed plugin '$plugin'$downloadedPluginFileNameHint to $targetJar")
6869
targetJar

ideaSupport/src/main/scala/org/jetbrains/sbtidea/runIdea/IntellijVMOptionsBuilder.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jetbrains.sbtidea.runIdea
22

33
import org.jetbrains.sbtidea.*
4+
import org.jetbrains.sbtidea.download.api.IdeInstallationContext
45
import org.jetbrains.sbtidea.download.{IntelliJVersionDetector, Version}
56
import org.jetbrains.sbtidea.productInfo.ProductInfoExtraDataProvider
67
import org.jetbrains.sbtidea.runIdea.CustomIntellijVMOptions.DebugInfo
@@ -133,7 +134,7 @@ final case class IntellijVMOptionsBuilder(
133134
}
134135
val (systemPath, configPath) = (ideaHome.resolve(systemDirName), ideaHome.resolve(configDirName))
135136

136-
val customPluginsPath = systemPath.resolve("plugins")
137+
val customPluginsPath = intellijDirectory.resolve(IdeInstallationContext.customPluginsDirName)
137138
val logPath = systemPath.resolve("log")
138139

139140
// IntelliJ requires all these paths to be set when "idea.paths.selector" VM options is used (that comes from product-info.json)
@@ -230,6 +231,8 @@ object IntellijVMOptionsBuilder {
230231
else (ideaHome.resolve("system"), ideaHome.resolve("config"))
231232
buffer += s"-Didea.system.path=${OQ(system.toString)}"
232233
buffer += s"-Didea.config.path=${OQ(config.toString)}"
234+
val customPlugins = intellijDirectory.resolve(IdeInstallationContext.customPluginsDirName)
235+
buffer += s"-Didea.plugins.path=${OQ(customPlugins.toString)}"
233236
buffer += s"-Dplugin.path=${OQ(pluginPath.toString)}"
234237
if (forTests) {
235238
buffer += "-Didea.use.core.classloader.for.plugin.path=true"

ideaSupport/src/test/scala/org/jetbrains/sbtidea/IdeaVmOptionsTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ class IdeaVmOptionsTest extends AnyFunSuite with Matchers {
7777

7878
private val mustBeQuoted = Seq(
7979
"plugin.path",
80+
"idea.config.path",
81+
"idea.plugins.path",
8082
"idea.system.path",
81-
"idea.config.path"
8283
)
8384

8485
test("paths are quoted in xml version") {

ideaSupport/src/test/scala/org/jetbrains/sbtidea/integrationTests/SbtIdeaPluginIntegrationTest.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class SbtIdeaPluginIntegrationTest
5252
val intellijSdkRoot = runUpdateIntellijCommand("simple-with-plugin")
5353

5454
doCommonAssertions(intellijSdkRoot)
55-
assertFileExists(intellijSdkRoot / "plugins" / "Scala")
55+
assertFileDoesNotExist(intellijSdkRoot / "plugins" / "Scala")
56+
assertFileExists(intellijSdkRoot / "custom-plugins")
57+
assertFileExists(intellijSdkRoot / "custom-plugins" / "Scala")
5658
assertSourcesDirectoryContents(intellijSdkRoot, Seq(
5759
"ideaIC-243.22562.145-sources.zip"
5860
))
@@ -68,6 +70,7 @@ class SbtIdeaPluginIntegrationTest
6870
"ideaIU-243.22562.145-sources.zip"
6971
))
7072
assertFileDoesNotExist(intellijSdkRoot / "plugins" / "scala")
73+
assertFileDoesNotExist(intellijSdkRoot / "custom-plugins")
7174
new IdeInstallationContext(intellijSdkRoot.toPath).productInfo.productCode shouldBe "IU"
7275
}
7376

@@ -151,4 +154,4 @@ class SbtIdeaPluginIntegrationTest
151154

152155
intellijSdkRoot / "sdk" / CommonIntellijBuild
153156
}
154-
}
157+
}

0 commit comments

Comments
 (0)