Skip to content

Commit

Permalink
Fix compiler resolution for long build numbers (#883)
Browse files Browse the repository at this point in the history
* Fix compiler resolution for long build numbers

In recent versions of Android Studio, the build number contains
additional components from major.minor.patch, e.g. 2020-3.1-patch-4 has
build number AI-203.7717.56.2031.7935034.
When configuration the plugin with a localPath that points to a recent Android Studio dist, these additional components causes the instrumentCode task to fail due to trying to resolve a non-existent compiler version (203.7717.56.2031.7935034).
With this commit we're stripping out components exceeding patch that are
not equal to SNAPSHOT or *. I.e, 1.2.3.4.5.SNAPSHOT becomes
1.2.3.SNAPSHOT.

* Bump com.gradle.plugin-publish from 0.19.0 to 0.20.0

Bumps com.gradle.plugin-publish from 0.19.0 to 0.20.0.

---
updated-dependencies:
- dependency-name: com.gradle.plugin-publish
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump gradle-idea-ext from 1.1.1 to 1.1.2

Bumps gradle-idea-ext from 1.1.1 to 1.1.2.

---
updated-dependencies:
- dependency-name: gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fixed JBR resolving for MacOSX M1

* CHANGES update

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jakub Chrzanowski <jakub.chrzanowski@jetbrains.com>
  • Loading branch information
3 people committed Jan 31, 2022
1 parent 3eecafd commit bd3f12e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## next
- Fixed JBR resolving for MacOSX M1
- Fix compiler resolution for long build numbers [#883](../../issues/883)

## 1.3.1
- Fixed execution bit filter when extracting Rider [RIDER-72922](https://youtrack.jetbrains.com/issue/RIDER-72922)
Expand Down
22 changes: 18 additions & 4 deletions src/main/kotlin/org/jetbrains/intellij/IntelliJPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,9 @@ open class IntelliJPlugin : Plugin<Project> {
val isEap = localPath?.let { ideProductInfo(ideaDependency.classes)?.versionSuffix == "EAP" } ?: false
val eapSuffix = "-EAP-SNAPSHOT".takeIf { isEap } ?: ""

IdeVersion.createIdeVersion(ideaDependency.buildNumber).asStringWithoutProductCode() + eapSuffix
IdeVersion.createIdeVersion(ideaDependency.buildNumber)
.stripExcessComponents()
.asStringWithoutProductCode() + eapSuffix
}
})
ideaDependency.convention(setupDependenciesTask.idea)
Expand All @@ -719,9 +721,8 @@ open class IntelliJPlugin : Plugin<Project> {
})
compilerClassPathFromMaven.convention(project.provider {
val compilerVersion = compilerVersion.get()
if (compilerVersion == IntelliJPluginConstants.DEFAULT_IDEA_VERSION || Version.parse(compilerVersion) >= Version(183,
3795,
13)
if (compilerVersion == IntelliJPluginConstants.DEFAULT_IDEA_VERSION ||
Version.parse(compilerVersion) >= Version(183, 3795, 13)
) {
dependenciesDownloader.downloadFromMultipleRepositories(logCategory(), {
create(
Expand Down Expand Up @@ -1160,4 +1161,17 @@ open class IntelliJPlugin : Plugin<Project> {
private fun ProjectSettings.taskTriggers(
action: TaskTriggersConfig.() -> Unit,
) = (this as ExtensionAware).extensions.configure("taskTriggers", action)

/**
* Strips an [IdeVersion] of components other than SNAPSHOT and * that exceeds patch, i.e. "excess" in the following
* version will be stripped: major.minor.patch.excess.SNAPSHOT.
* This is needed due to recent versions of Android Studio having additional components in its build number; e.g.
* 2020.3.1-patch-4 has build number AI-203.7717.56.2031.7935034, with these additional components instrumentCode
* fails because it tries to resolve a non-existent compiler version (203.7717.56.2031.7935034). This function
* strips it down so that only major minor and patch are used.
*/
private fun IdeVersion.stripExcessComponents(): IdeVersion = asStringWithoutProductCode().split(".")
.filterIndexed { index, component -> index < 3 || component == "SNAPSHOT" || component == "*" }
.joinToString(prefix = "$productCode-", separator = ".")
.let(IdeVersion::createIdeVersion)
}

0 comments on commit bd3f12e

Please sign in to comment.