Skip to content

Commit

Permalink
Fix build errors caused by different submodules using IU & IC at the …
Browse files Browse the repository at this point in the history
…same time, which led to overwriting Ivy XML files in the local Ivy repository.
  • Loading branch information
AlexanderBartash authored and hsz committed Oct 23, 2024
1 parent a8d1715 commit 6abb4f9
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,10 @@ class IntelliJPlatformDependenciesHelper(
localProductInfo.validateSupportedVersion()

val type = localProductInfo.productCode.toIntelliJPlatformType()
val version = localProductInfo.buildNumber
// It is crucial to use the IDE type + build number to the version.
// Because if UI & IC are used by different submodules in the same build, they might rewrite each other's Ivy
// XML files, which might have different optional transitive dependencies defined due to IC having fewer plugins.
val version = localProductInfo.getFullVersion()

writeIvyModule(Dependencies.LOCAL_IDE_GROUP, type.code, version, artifactPath) {
IvyModule(
Expand Down Expand Up @@ -773,7 +776,11 @@ class IntelliJPlatformDependenciesHelper(
}

val artifactPath = requireNotNull(plugin.originalFile)
val version = requireNotNull(plugin.pluginVersion)
// It is crucial to use the IDE type + build number to the version.
// Because if UI & IC are used by different submodules in the same build, they might rewrite each other's Ivy
// XML files, which might have different optional transitive dependencies defined due to IC having fewer plugins.
// Should be the same as [collectDependencies]
val version = productInfo.get().getFullVersion()

writeIvyModule(Dependencies.BUNDLED_PLUGIN_GROUP, id, version, artifactPath) {
IvyModule(
Expand Down Expand Up @@ -824,7 +831,11 @@ class IntelliJPlatformDependenciesHelper(
val artifactPath = requireNotNull(plugin.originalFile)
val group = Dependencies.BUNDLED_PLUGIN_GROUP
val name = requireNotNull(plugin.pluginId)
val version = requireNotNull(plugin.pluginVersion)
// It is crucial to use the IDE type + build number to the version.
// Because if UI & IC are used by different submodules in the same build, they might rewrite each other's Ivy
// XML files, which might have different optional transitive dependencies defined due to IC having fewer plugins.
// Should be the same as [createIntelliJPlatformBundledPlugin]
val version = productInfo.get().getFullVersion()

val doesNotDependOnSelf = id != plugin.pluginId
val hasNeverBeenSeen = plugin.pluginId !in alreadyProcessedOrProcessing
Expand Down Expand Up @@ -867,7 +878,10 @@ class IntelliJPlatformDependenciesHelper(
*/
private fun writeBundledModuleDependency(name: String, classPath: List<String>): Triple<String, String, String> {
val group = Dependencies.BUNDLED_MODULE_GROUP
val version = productInfo.get().buildNumber
// It is crucial to use the IDE type + build number to the version.
// Because if UI & IC are used by different submodules in the same build, they might rewrite each other's Ivy
// XML files, which might have different optional transitive dependencies defined due to IC having fewer plugins.
val version = productInfo.get().getFullVersion()
val platformPath = platformPath.get()
val artifacts = classPath.flatMap {
platformPath.resolve(it).toIvyArtifacts(metadataRulesModeProvider, platformPath)
Expand Down Expand Up @@ -908,7 +922,10 @@ class IntelliJPlatformDependenciesHelper(
pluginManager.safelyCreatePlugin(pluginPath).getOrThrow()
}

val version = plugin.pluginVersion ?: "0.0.0"
// It is crucial to use the IDE type + build number to the version.
// Because if UI & IC are used by different submodules in the same build, they might rewrite each other's Ivy
// XML files, which might have different optional transitive dependencies defined due to IC having fewer plugins.
val version = productInfo.get().getFullVersion() + "-" + (plugin.pluginVersion ?: "0.0.0")
val name = plugin.pluginId ?: artifactPath.name

writeIvyModule(Dependencies.LOCAL_PLUGIN_GROUP, name, version, artifactPath) {
Expand Down Expand Up @@ -943,13 +960,21 @@ class IntelliJPlatformDependenciesHelper(
}
}.get()

// E.g.: JBR-21.0.4+13-509.17-jcef
val javaVendorVersion = runtimeMetadata["java.vendor.version"]
requireNotNull(javaVendorVersion)

// E.g.: 21.0.4
val javaVersion = runtimeMetadata["java.version"]
requireNotNull(javaVersion)

// E.g.: JBR
val name = javaVendorVersion.substringBefore(javaVersion).trim('-')
// It is crucial to use the full version.
// Because if someone decides to bump JBR within the same marketing version,
// but in the next build – it’ll still refer to the incorrect version as they’ll be treated equally.
// They would rewrite each other's Ivy XML files since they would have the same name.
// E.g.: 21.0.4+13-509.17-jcef
val version = javaVendorVersion.removePrefix(name).trim('-')

writeIvyModule(Dependencies.LOCAL_JETBRAINS_RUNTIME_GROUP, name, version, artifactPath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ data class ProductInfo(
}
}

/** [ProductInfo.productCode] + "-" + [ProductInfo.buildNumber] */
fun ProductInfo.getFullVersion() = productCode + "-" + buildNumber

/**
* Validates that the resolved IntelliJ Platform is supported by checking against the minimal supported IntelliJ Platform version.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,71 @@ abstract class JavaRuntimeMetadataValueSource : ValueSource<Map<String, String>,
val executable: RegularFileProperty
}

/**
* Sample output:
* ```
* user@user-kubuntu:~ $ /opt/ideau/jbr/bin/java -XshowSettings:properties -version
* Property settings:
* awt.toolkit.name = XToolkit
* file.encoding = UTF-8
* file.separator = /
* intellij.os.virtualization = none
* java.class.path =
* java.class.version = 65.0
* java.home = /opt/ideau/jbr
* java.io.tmpdir = /tmp
* java.library.path = /usr/java/packages/lib
* /usr/lib64
* /lib64
* /lib
* /usr/lib
* java.runtime.name = OpenJDK Runtime Environment
* java.runtime.version = 21.0.4+13-b509.17
* java.specification.name = Java Platform API Specification
* java.specification.vendor = Oracle Corporation
* java.specification.version = 21
* java.vendor = JetBrains s.r.o.
* java.vendor.url = https://openjdk.org/
* java.vendor.url.bug = https://bugreport.java.com/bugreport/
* java.vendor.version = JBR-21.0.4+13-509.17-jcef
* java.version = 21.0.4
* java.version.date = 2024-07-16
* java.vm.compressedOopsMode = Zero based
* java.vm.info = mixed mode
* java.vm.name = OpenJDK 64-Bit Server VM
* java.vm.specification.name = Java Virtual Machine Specification
* java.vm.specification.vendor = Oracle Corporation
* java.vm.specification.version = 21
* java.vm.vendor = JetBrains s.r.o.
* java.vm.version = 21.0.4+13-b509.17
* jbr.virtualization.information = No virtualization detected
* jdk.debug = release
* line.separator = \n
* native.encoding = UTF-8
* os.arch = amd64
* os.name = Linux
* os.version = 6.8.0-47-generic
* path.separator = :
* stderr.encoding = UTF-8
* stdout.encoding = UTF-8
* sun.arch.data.model = 64
* sun.boot.library.path = /opt/ideau/jbr/lib
* sun.cpu.endian = little
* sun.io.unicode.encoding = UnicodeLittle
* sun.java.launcher = SUN_STANDARD
* sun.jnu.encoding = UTF-8
* sun.management.compiler = HotSpot 64-Bit Tiered Compilers
* user.country = GB
* user.dir = /home/sasha
* user.home = /home/sasha
* user.language = en
* user.name = sasha
*
* openjdk version "21.0.4" 2024-07-16
* OpenJDK Runtime Environment JBR-21.0.4+13-509.17-jcef (build 21.0.4+13-b509.17)
* OpenJDK 64-Bit Server VM JBR-21.0.4+13-509.17-jcef (build 21.0.4+13-b509.17, mixed mode)
* ```
*/
override fun obtain() = ByteArrayOutputStream().use { os ->
execOperations.exec {
commandLine(
Expand Down

0 comments on commit 6abb4f9

Please sign in to comment.