Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#146): provides installation script
- Loading branch information
1 parent
70f132e
commit 67cdcef
Showing
2 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#!/usr/bin/env bash | ||
|
||
MAVEN_METADATA=$(curl -sL http://central.maven.org/maven2/org/arquillian/smart/testing/smart-testing-parent/maven-metadata.xml) | ||
LATEST=$(echo ${MAVEN_METADATA} | grep -oPm1 "(?<=<latest>)[^<]+") | ||
RELEASE=$(echo ${MAVEN_METADATA} | grep -oPm1 "(?<=<release>)[^<]+") | ||
|
||
VERSION=${RELEASE} | ||
INSTALL_SPECIFIC_VERSION="0" | ||
|
||
while test $# -gt 0; do | ||
case "$1" in | ||
-h|--help) | ||
echo "Installs Arquillian Smart Testing Extension" | ||
echo "options:" | ||
echo "-l, --latest installs latest version of the extension" | ||
echo "-r, --release installs latest released version of the extension" | ||
echo "-v, --version=VERSION installs defined version (doesn't check if exists!)" | ||
exit 0 | ||
;; | ||
-l|--latest) | ||
shift | ||
VERSION=${LATEST} | ||
shift | ||
;; | ||
-r|--release) | ||
shift | ||
VERSION=${RELEASE} | ||
shift | ||
;; | ||
-v) | ||
shift | ||
if test $# -gt 0; then | ||
VERSION=$1 | ||
INSTALL_SPECIFIC_VERSION="1" | ||
else | ||
echo "no version specified" | ||
exit 1 | ||
fi | ||
shift | ||
;; | ||
--version*) | ||
VERSION=`echo $1 | sed -e 's/^[^=]*=//g'` | ||
INSTALL_SPECIFIC_VERSION="1" | ||
shift | ||
;; | ||
*) | ||
echo "$1 is not a recognized flag!" | ||
exit -1 | ||
;; | ||
esac | ||
done | ||
|
||
function install_shaded_library() { | ||
if [ -z "$M2_HOME" ]; then | ||
echo "Please set M2_HOME" | ||
exit 1 | ||
fi | ||
SHADED_JAR="maven-lifecycle-extension-${VERSION}-shaded.jar" | ||
wget http://central.maven.org/maven2/org/arquillian/smart/testing/maven-lifecycle-extension/${VERSION}/${SHADED_JAR} | ||
read -r -p "We want to move shaded jar to M2_HOME with sudo. Can we? [y/N] " response | ||
case "$response" in | ||
[yY][eE][sS]|[yY]) | ||
sudo mv $SHADED_JAR $M2_HOME/lib/ext | ||
;; | ||
*) | ||
;; | ||
esac | ||
} | ||
|
||
function install_extension() { | ||
|
||
# Needs to be without new lines, otherwise my sed skills below will fail badly :\ | ||
EXTENSION="<extension><groupId>org.arquillian.smart.testing</groupId><artifactId>maven-lifecycle-extension</artifactId><version>${VERSION}</version></extension>" | ||
|
||
if [ ! -f .mvn/extensions.xml ]; then | ||
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?> | ||
<extensions> | ||
${EXTENSION} | ||
</extensions>" > .mvn/extensions.xml | ||
else | ||
EXTENSION_REGISTERED=$(cat .mvn/extensions.xml | grep 'org.arquillian.smart.testing' -A 2 | grep -oPm1 "(?<=<version>)[^<]+"); | ||
|
||
if [ ! ${EXTENSION_REGISTERED} ]; then | ||
EXTENSION=$(echo ${EXTENSION} | sed -e "s#/#\\\/#g"); | ||
sed -i -E 's/(.*<extensions>)(.*)/\1\n'$EXTENSION'\2/g' .mvn/extensions.xml | ||
else | ||
echo -e "Extension already registered with version ${EXTENSION_REGISTERED}\c" | ||
|
||
if [ ${INSTALL_SPECIFIC_VERSION} -eq 1 ]; then | ||
if [ "${EXTENSION_REGISTERED}" != "${VERSION}" ]; then | ||
echo -e " - overwritting with ${VERSION}\c" | ||
override_version $VERSION | ||
fi | ||
echo "." | ||
elif [ $EXTENSION_REGISTERED != $LATEST ]; then | ||
read -r -p ". Do you want to override with latest ${LATEST}? [y/N] " response | ||
case "$response" in | ||
[yY][eE][sS]|[yY]) | ||
override_version ${LATEST} | ||
;; | ||
*) | ||
|
||
;; | ||
esac | ||
else | ||
echo " which is the latest stable version." | ||
fi | ||
fi | ||
fi | ||
|
||
mv .mvn/extensions.xml .mvn/extensions-unformatted.xml | ||
xmllint --format .mvn/extensions-unformatted.xml > .mvn/extensions.xml | ||
rm .mvn/extensions-unformatted.xml | ||
} | ||
|
||
function override_version() { | ||
cat .mvn/extensions.xml | awk -v groupId="org.arquillian.smart.testing" -v version=$1 -v RS="</extension>" ' | ||
$0 ~ "<groupId>" groupId "</groupId>" { | ||
sub("<version>.*</version>", "<version>" version "</version>") | ||
} | ||
{printf "%s", $0 RS}' | sed '$ d' > .mvn/extensions-new.xml | ||
mv .mvn/extensions-new.xml .mvn/extensions.xml | ||
} | ||
|
||
## MAIN LOGIC | ||
|
||
MVN_VERSION=$(mvn --version | head -n1 | cut -d' ' -f3) | ||
echo $MVN_VERSION | ||
|
||
if [[ $MVN_VERSION =~ ^[3].[3-9].[0-9]$ ]]; then | ||
install_extension | ||
elif [[ $MVN_VERSION =~ ^[3].[1-2].[0-9]$ ]]; then | ||
install_shaded_library | ||
else | ||
echo "Version ${MVN_VERSION} is not supported."; | ||
fi | ||
|