Wednesday, November 25, 2009

Download sources jar from maven

We use Maven, when Maven downloads dependencies it doesn't download sources, which I rely on when learn and debug programs....
I was expecting, for what seem a simple thing to me, a flag that I can add in maven's settings files or an option to pass to mvn command.... but I couldn't find the solution (or anything close to it). Don't get me wrong, there are solutions out there, but I just feel it is too much hassle for the task.

So I wrote a little script that go thru my repo and downloads any jar that doesn't have its respective sources :p

#!/bin/bash
prefix="http://mirrors.ibiblio.org/pub/mirrors/maven2"
header="/tmp/$0.header.$$"
find . -name "*.jar" -and ! -name "*sources.jar" | grep -v "siteminder" | \
while read j
do
source_jar=$(echo $j | sed -e's/.jar/-sources.jar/')
if [ ! -e $source_jar ] ; then
echo "Downloading ${source_jar}"
pushd $(dirname $source_jar) >/dev/null 2>&1
curl -D $header -O "${prefix}/${source_jar}" >/dev/null 2>&1
popd >/dev/null 2>&1
error=$(fgrep -c "404 Not Found" $header)
if [ $error -ne 0 ] ; then
echo "It does not exist..."
rm $source_jar 2>/dev/null
fi
fi
done
rm $header

No comments: