Skip to content

Commit

Permalink
feat(#146): provides installation script
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszmajsak committed Sep 21, 2017
1 parent 70f132e commit 67cdcef
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 4 deletions.
27 changes: 23 additions & 4 deletions docs/installation.adoc
@@ -1,14 +1,33 @@
== Installation

=== Don't make me think

Ok, just execute following snippet and you are all set:

[[installing]]
`curl -sS https://git.io/v5jMS | bash` copyToClipboard:installing[]

You can also add these flags:

* `-l|--latest` latest published artifact in Maven Central
* `-r|--release` latest release (that's the default)
* `-v|--version=` - specific version to install

For example:

`curl -sS https://git.io/v5jMS | bash -- --latest`

This script will automatically do what we described below. If you are curious keep on reading, but you may skip it too.

=== Maven Extension

*Smart Testing* is a Maven extension, so needs to be installed as is.
*Smart Testing* is a Maven extension, so depending on the version of Maven you have to follow slightly different approach of installing it.

==== Maven >= 3.1.X
==== Maven above 3.1.X

Get Smart Testing _shaded_ copy from https://bintray.com/arquillian/Arquillian/smart-testing[Bintray] and copy it to `M2_HOME/lib/ext`
Get Smart Testing Extension _shaded jar_ from http://central.maven.org/maven2/org/arquillian/smart/testing/maven-lifecycle-extension/[Maven Central] and copy it to `M2_HOME/lib/ext`.

==== Maven >= 3.3.X
==== Maven above 3.3.X

You can still use the process described at <<Maven >= 3.1.X>> or use the new _core extension configuration mechanism_ by
creating folder called `.mvn` in the root of your project and create inside it an `extensions.xml` file
Expand Down
137 changes: 137 additions & 0 deletions install.sh
@@ -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

0 comments on commit 67cdcef

Please sign in to comment.