Skip to content

Instantly share code, notes, and snippets.

@instance-id
Last active January 18, 2025 20:45
Show Gist options
  • Save instance-id/ab95e9f8e5aecd60051660998700c0ce to your computer and use it in GitHub Desktop.
Save instance-id/ab95e9f8e5aecd60051660998700c0ce to your computer and use it in GitHub Desktop.
Generic script to update a JetBrains plugin to allow current Rider (and probably non-Rider IDE) EAP versions if the plugin tells you that you need to use an older version.
#!/usr/bin/env -S pwsh -noProfile -nologo
<#
.NOTES
============================================================
Last Edit: 10/14/2024
Created by: instance.id (https://github.com/instance-id)
Platform: Linux/Windows
Filename: intellij_eap_updater.ps1
PSVersion: Last tested with 7.4.x
============================================================
.DESCRIPTION
Edit a Jetbrains plugin to allow it to work in the current Rider EAP
If the current version is 243.* but the plugin only allows 242.*, setting the parameter `-eapVersion '3'` will update the plugin to 243.*
.EXAMPLE
./intellij_eap_updater.ps1 -sourcePath 'ReSharperPlugin.CodeInspections-9999.0.0.zip' -eapVersion '3'
#>
param(
[string]$sourcePath = '',
[string]$eapVersion = '3'
)
$currentPath = $PSScriptRoot
if ($sourcePath -eq '') {
throw "Please provide a source path"
}
if (-not (Test-Path $sourcePath)) {
throw "Could not find ${sourcePath}"
}
$sourceFile = [System.IO.Path]::GetFileName($sourcePath)
if ($sourceFile.EndsWith('.zip') -eq $false) {
throw "Source file must be a zip file"
}
$fileBaseName = [System.IO.Path]::GetFileNameWithoutExtension($sourceFile)
# This may need additional tweaking. I don't know how standardized plugin naming
# is/needs to be but so far it has worked for the plugins I have used this for.
$pluginBaseName = $fileBaseName -replace '-\d.*$', ''
$fileNameJar = "${fileBaseName}.jar"
$pluginJar = "${pluginBaseName}/lib/${fileNameJar}"
$innerFilePathInJar = "META-INF/plugin.xml"
$sourceZip = $null
$jarFile = $null
$jarStream = $null
$jarArchive = $null
$pluginXmlStream = $null
$pluginXmlWriter = $null
try {
$sourceZip = [System.IO.Compression.ZipFile]::Open($sourcePath, 'Update')
$jarFile = $sourceZip.GetEntry($pluginJar)
if ($jarFile -eq $null) {
throw "Could not find ${pluginJar} in ${sourceFile}"
}
$jarStream = $jarFile.Open()
if ($jarStream -eq $null) {
throw "Could not open ${pluginJar} in ${sourceFile}"
}
$jarArchive = [System.IO.Compression.ZipArchive]::new($jarStream, [System.IO.Compression.ZipArchiveMode]::Update)
if ($jarArchive -eq $null) {
throw "Could not open ${pluginJar} in ${sourceFile}"
}
$pluginXml = $jarArchive.GetEntry($innerFilePathInJar)
if ($pluginXml -eq $null) {
throw "Could not find ${innerFilePathInJar} in ${pluginJar}"
}
$pluginXmlStream = $pluginXml.Open()
$pluginXmlReader = [System.IO.StreamReader]::new($pluginXmlStream)
$pluginXmlContent = $pluginXmlReader.ReadToEnd()
$pluginXmlReader.Close()
$pluginXmlStream.Close()
[xml]$xmlDoc = $pluginXmlContent
$ideaVersionNode = $xmlDoc.'idea-plugin'.'idea-version'
if ($null -eq $ideaVersionNode) {
throw "Could not find 'idea-version' node in ${innerFilePathInJar}"
}
$untilBuildAttr = $ideaVersionNode.'until-build'
if ($null -eq $untilBuildAttr) {
throw "Could not find 'until-build' attribute in 'idea-version' node"
}
$untilBuildValue = $ideaVersionNode.'until-build'
if ($untilBuildValue -match '(\d)(\d)(\d)(\.\*)') {
$firstPart = [int]$matches[1]
$secondPart = [int]$matches[2]
$fourthPart = $matches[4]
$newUntilBuildValue = "${firstPart}$(($secondPart+1))$eapVersion$($fourthPart)"
if ($newUntilBuildValue -eq $untilBuildValue) {
write-host "The 'until-build' attribute value is already set to the expected value"
exit 0
}
$ideaVersionNode.'until-build' = $newUntilBuildValue
} else {
throw "The 'until-build' attribute value does not match the expected pattern"
}
$pluginXmlStream = $pluginXml.Open()
$pluginXmlWriter = [System.IO.StreamWriter]::new($pluginXmlStream)
$xmlDoc.Save($pluginXmlWriter)
$pluginXmlWriter.Close()
$pluginXmlStream.Close()
$jarArchive.Dispose()
$jarStream.Close()
$sourceZip.Dispose()
write-host "Updated the 'until-build' attribute value in ${innerFilePathInJar} to ${newUntilBuildValue}"
} catch { $_ }
finally {
if ($null -ne $jarArchive) { $jarArchive.Dispose() }
if ($null -ne $jarStream) { $jarStream.Close() }
if ($null -ne $pluginXmlStream) { $pluginXmlStream.Close() }
if ($null -ne $pluginXmlWriter) { $pluginXmlWriter.Close() }
if ($null -ne $sourceZip) { $sourceZip.Dispose() }
}
@instance-id
Copy link
Author

Updated to support going from Ex: 243.* to 251.*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment