Created
May 28, 2024 14:22
-
-
Save andrewloux/863434f893d29848f3a047f8f2093d90 to your computer and use it in GitHub Desktop.
Dump JAR Dependencies
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
#!/bin/bash | |
JAR_FILE=$1 | |
EXTRACT_DIR="extracted" | |
# Ensure the extracted directory exists | |
mkdir -p $EXTRACT_DIR | |
# Extract the jar file | |
unzip -q "$JAR_FILE" -d $EXTRACT_DIR | |
# Function to read MANIFEST.MF and pom.properties | |
read_metadata() { | |
local file=$1 | |
if [[ $file == *"META-INF/MANIFEST.MF"* ]]; then | |
echo "From $file:" | |
grep -E "^(Bundle-SymbolicName|Bundle-Version|Implementation-Title|Implementation-Version|Specification-Title|Specification-Version):" "$file" | |
elif [[ $file == *"pom.properties"* ]]; then | |
echo "From $file:" | |
grep -E "^(groupId|artifactId|version)=" "$file" | |
fi | |
} | |
# Find and read MANIFEST.MF and pom.properties | |
find $EXTRACT_DIR -type f \( -name "MANIFEST.MF" -o -name "pom.properties" \) | while read file; do | |
read_metadata "$file" | |
done | |
# Clean up | |
rm -rf $EXTRACT_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment