Created
October 8, 2024 12:45
-
-
Save mbcolbert/caf6f42eef5e66146bf8cec3285c5051 to your computer and use it in GitHub Desktop.
Find corrupt jar files in a maven repo (powershell)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -AssemblyName System.IO.Compression.FileSystem | |
# Initialize a counter for processed files | |
$processedCount = 0 | |
Get-ChildItem -Path "C:\Users\<USERNAME>\.m2\repository" -Recurse -Filter "*.jar" | | |
ForEach-Object { | |
Write-Host "Checking file: $($_.FullName)" -ForegroundColor Green | |
try { | |
# Increment the counter for each file processed | |
$processedCount++ | |
# Attempt to open the JAR file (ZIP format) to check its integrity | |
[System.IO.Compression.ZipFile]::OpenRead($_.FullName).Dispose() | |
} | |
catch { | |
# If there is an error, print the file name and throw to stop execution | |
Write-Host "Error in file: $($_.FullName)" -ForegroundColor Red | |
throw "Invalid or corrupted JAR file detected: $($_.FullName)" | |
} | |
} | |
# Print the number of files successfully processed | |
Write-Host "`nTotal files processed: $processedCount" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment