Files
inquiry_robot/deploy/_remote_patch_commons_io.ps1
T

77 lines
3.1 KiB
PowerShell

# Hot-fix commons-io inside Spring Boot fat jar for POI 5.2.x.
# Replaces commons-io-2.6.jar with 2.11.0; does NOT use nested module jar uf.
$ErrorActionPreference = 'Stop'
$Fat = 'E:\wwwroot\inquiry-new\jeecg-system-start-3.5.3.jar'
$IncomingLib = 'C:\Users\ytd_extdev_0903\incoming\commons-io-2.11.0.jar'
$Work = Join-Path $env:TEMP 'fix-commons-io-fat'
$JarCmd = $null
foreach ($c in @('C:\yutongda\tools\jdk8\bin\jar.exe', 'C:\Program Files\Java\jdk1.8.0_202\bin\jar.exe')) {
if (Test-Path $c) { $JarCmd = $c; break }
}
if (-not $JarCmd) { throw 'jar.exe missing' }
if (-not (Test-Path $IncomingLib)) { throw "missing $IncomingLib" }
if (-not (Test-Path $Fat)) { throw "missing $Fat" }
# stop ledger only
Get-CimInstance Win32_Process | ForEach-Object {
if ($_.CommandLine -and ($_.CommandLine -like '*inquiry-new*jeecg*' -or $_.CommandLine -like '*run-ledger*')) {
Write-Host ("killing=" + $_.ProcessId)
Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
}
}
Start-Sleep -Seconds 2
if (Test-Path $Work) { Remove-Item $Work -Recurse -Force }
New-Item -ItemType Directory -Force -Path $Work | Out-Null
Copy-Item $Fat (Join-Path $Work 'app.jar') -Force
Push-Location $Work
# Prefer zip -d if available; else jar + rebuild lib entry
$zip = $null
foreach ($z in @('C:\Program Files\7-Zip\7z.exe', 'C:\yutongda\tools\7zip\7z.exe')) {
if (Test-Path $z) { $zip = $z; break }
}
$oldEntry = 'BOOT-INF/lib/commons-io-2.6.jar'
$newEntry = 'BOOT-INF/lib/commons-io-2.11.0.jar'
New-Item -ItemType Directory -Force -Path 'BOOT-INF\lib' | Out-Null
Copy-Item $IncomingLib 'BOOT-INF\lib\commons-io-2.11.0.jar' -Force
if ($zip) {
& $zip d 'app.jar' $oldEntry | Out-Null
& $zip a -tzip 'app.jar' $newEntry | Out-Null
Write-Host 'patched_via_7z'
} else {
# jar uf can add; deleting old entry via .NET ZipArchive
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem
$jarPath = (Resolve-Path 'app.jar').Path
$fs = [IO.File]::Open($jarPath, [IO.FileMode]::Open, [IO.FileAccess]::ReadWrite)
try {
$zipArc = New-Object IO.Compression.ZipArchive($fs, [IO.Compression.ZipArchiveMode]::Update)
$old = $zipArc.GetEntry($oldEntry)
if ($old) { $old.Delete(); Write-Host 'deleted_old_2.6' } else { Write-Host 'old_2.6_absent' }
$existing = $zipArc.GetEntry($newEntry)
if ($existing) { $existing.Delete() }
$entry = $zipArc.CreateEntry($newEntry, [IO.Compression.CompressionLevel]::Optimal)
$src = [IO.File]::OpenRead((Resolve-Path 'BOOT-INF\lib\commons-io-2.11.0.jar').Path)
try {
$dest = $entry.Open()
try { $src.CopyTo($dest) } finally { $dest.Dispose() }
} finally { $src.Dispose() }
$zipArc.Dispose()
} finally { $fs.Dispose() }
Write-Host 'patched_via_ziparchive'
}
Copy-Item 'app.jar' $Fat -Force
Copy-Item 'app.jar' 'C:\Users\ytd_extdev_0903\incoming\jeecg-system-start-3.5.3.jar' -Force
Pop-Location
# confirm entry names
& $JarCmd tf $Fat | Select-String 'commons-io'
Write-Host 'COMMONS_IO_PATCHED'
powershell -NoProfile -ExecutionPolicy Bypass -File C:\Users\ytd_extdev_0903\incoming\_remote_wmi_start_ledger.ps1
Write-Host 'PATCH_RESTART_DONE'