#!/bin/bash

if [ -z "$PROJECT_PREFIX" ]; then
  echo "PROJECT_PREFIX environment variable not set, exiting." 1>&2
  exit 1
fi

cp -a /usr/share/java/monasca-common ${PROJECT_PREFIX}/kit/m2

# Determine monasca-common jar version
VERSION=$(basename $(find ${PROJECT_PREFIX}/kit/m2/monasca-common/monasca-common/* -maxdepth 1 -type d))

export POM_FILE=$(readlink -e ${PROJECT_PREFIX}/kit/m2/monasca-common/monasca-common/${VERSION}/monasca-common-${VERSION}.pom)

mkdir -p /tmp/bin/
export PATH=$PATH:/tmp/bin
echo "$PROJECT_PREFIX/kit/apache-maven-3.3.9/bin/mvn -Dmaven.repo.local=$PROJECT_PREFIX/kit/m2 --settings $PROJECT_PREFIX/kit/m2/settings.xml --strict-checksums -o \$*" > /tmp/bin/mvn
chmod 755 /tmp/bin/mvn

mvn clean package
