Skip to content

Instantly share code, notes, and snippets.

@mfellner
Created July 1, 2013 18:43
Show Gist options
  • Save mfellner/5903443 to your computer and use it in GitHub Desktop.
Save mfellner/5903443 to your computer and use it in GitHub Desktop.
Bash script to download cucumber-jvm, the Android module and dependencies.
#!/bin/sh
REPO_ROOT=https://oss.sonatype.org/content/repositories
RELEASE=/releases
SNAPSHOT=/snapshots
CUCUMBER=/info/cukes
META=/maven-metadata.xml
V_LATEST_TAG=latest
V_LAST_TAG=version
# MODULES
MODULES[0]=/gherkin
MODULES[1]=/cucumber-jvm-deps
MODULES[2]=/cucumber-core
MODULES[3]=/cucumber-java
MODULES[4]=/cucumber-android
# Try to download snapshot versions if available.
USE_SNAPSHOTS=true
function get_version_string {
if ${1} ; then
echo ${SNAPSHOT}
else
echo ${RELEASE}
fi
}
function get_latest_version {
local latest=`curl -silent {$1}${META} | grep "<${2}>.\{1,\}</${2}>" | tail -1`
local regex="<${2}>(.+)</${2}>"
[[ $latest =~ $regex ]]
echo ${BASH_REMATCH[1]}
}
function get_download_url {
local module=${1}
local version=$(get_version_string ${USE_SNAPSHOTS})
local latest=$(get_latest_version ${REPO_ROOT}${version}${CUCUMBER}${module} ${V_LATEST_TAG})
if [ -z "$latest" ] ; then
# If the latest-version tag doesn't exist, try the last-version tag instead.
local latest=$(get_latest_version ${REPO_ROOT}${version}${CUCUMBER}${module} ${V_LAST_TAG})
fi
if [ -z "$latest" ] ; then
# If one version doesn't exist, try the other.
if ${USE_SNAPSHOTS} ; then
local use_snapshots=false
else
local use_snapshots=true
fi
# echo "# ${version} not available"
local version=$(get_version_string ${use_snapshots})
# echo "# trying ${version} instead..."
local latest=$(get_latest_version ${REPO_ROOT}${version}${CUCUMBER}${module} ${V_LAST_TAG})
if [ -z "$latest" ] ; then
# If the last-version tag doesn't exist, try the latest-version tag instead.
local latest=$(get_latest_version ${REPO_ROOT}${version}${CUCUMBER}${module} ${V_LATEST_TAG})
fi
fi
local directory=${REPO_ROOT}${version}${CUCUMBER}${module}/${latest}
local url=`curl -silent ${directory}/ | grep "<a.\{1,\}</a>" | grep "${latest}.\{0,\}.jar\">" | grep -v "sources" | grep -v "javadoc"`
local regex="href=\"(.+)\">"
[[ $url =~ $regex ]]
echo ${BASH_REMATCH[1]}
}
for m in ${MODULES[@]}
do
echo "# downloading ${m}..."
url=$(get_download_url ${m})
if [ -n "$url" ] ; then
curl -silent -O ${url}
else
echo "No .jar for ${m} available!"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment