blob: 5b0e8b76c1fdbfd078b0ccbdc922f6fc5a1b2d6f [file] [log] [blame]
#!/bin/bash
# -----------------------------------------------------------------------------
# Packages specific ONOS codebase with specific tag or branch
# -----------------------------------------------------------------------------
# Bail on any errors
set -e
# Initialize environment variables
init() {
# Check if ONOS_ROOT is defined
[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1;
# Setup some environmental context for developers
if [ -z "${JAVA_HOME}" ]; then
if [ -x /usr/libexec/java_home ]; then
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8);
elif [ -d /usr/lib/jvm/java-8-oracle ]; then
export JAVA_HOME="/usr/lib/jvm/java-8-oracle";
elif [ -d /usr/lib/jvm/java-8-openjdk-amd64 ]; then
export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64";
fi
fi
# Check if mvn exists
command -v mvn >/dev/null 2>&1 || {
# Following the convention, the default location of maven shows as below.
MAVEN=${MAVEN:-~/Applications/apache-maven-3.3.9};
export PATH="$MAVEN/bin:$PATH";
}
}
# checkout $TAG, build project and copy it to other location
check_copy() {
CHECK_TAG=`git checkout $TAG`
if [[ $CHECK_TAG =~ "error" ]]; then
echo "There is no branch or tag named $TAG in $ONOS_ROOT" >&2 && exit 1
fi
FOLDER=$CURRENT_PATH/onos-$TAG-blackduck
[ -d "$FOLDER" ] && rm -r $FOLDER
mkdir $FOLDER
mvn clean install
if [$? -eq 0 ]; then
cp -r -a * $FOLDER;
if [ -d "$FOLDER/.git" ]; then
rm -r $FOLDER/.git
fi;
else
git checkout $CURRENT_TAG;
rm -r $FOLDER
echo "mvn compilation failed"
fi
}
# Script entry point
CURRENT_PATH=`pwd`
TAG=${1:-'master'}
init
cd $ONOS_ROOT
CURRENT_TAG=`git branch | awk '{print $2}'`
check_copy
cd $FOLDER
zip -rq -m $CURRENT_PATH/onos-$TAG-blackduck.zip *
cd ..
rm -r $FOLDER
cd $ONOS_ROOT
git checkout $CURRENT_TAG