Created
June 28, 2016 22:08
-
-
Save marcingrzejszczak/60b1cd18963cc53232abaf0557a6c4c8 to your computer and use it in GitHub Desktop.
Find and replace in JARs
This file contains hidden or 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/sh | |
# From within a (bash) script you need to use double quotes instead of singel qoutes to expand the variable | |
newAddress="org.springframework.cloud.contract.verifier.dsl" | |
oldAddress="org.springframework.cloud.contract.spec" | |
repo="$HOME/repo/accurest" | |
currentDir=`pwd` | |
cd $repo | |
for fname in $(find "$repo" -regex '.*/src/test/resources/m2repo/.*.jar') | |
do | |
echo "Found $fname" | |
zipgrep -q $oldAddress $fname; | |
result=$? | |
echo "Result $result" | |
if [ $? -eq 0 ]; then | |
echo "Changing $fname since it matches the pattern" | |
filename="${fname%.*}" | |
unzip -qp $fname | sed -e 's#'$oldAddress'#'$newAddress'#g' > $filename | |
zip $filename.jar $filename | |
echo "Changed $fname's contents" | |
fi | |
done | |
cd $currentDir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment