blob: 5b0e8b76c1fdbfd078b0ccbdc922f6fc5a1b2d6f [file] [log] [blame]
Boyuan Yan510425f2016-04-22 09:25:12 +08001#!/bin/bash
2# -----------------------------------------------------------------------------
3# Packages specific ONOS codebase with specific tag or branch
4# -----------------------------------------------------------------------------
5
6# Bail on any errors
7set -e
8
9# Initialize environment variables
10init() {
11 # Check if ONOS_ROOT is defined
12 [ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1;
13
14 # Setup some environmental context for developers
15 if [ -z "${JAVA_HOME}" ]; then
16 if [ -x /usr/libexec/java_home ]; then
17 export JAVA_HOME=$(/usr/libexec/java_home -v 1.8);
18 elif [ -d /usr/lib/jvm/java-8-oracle ]; then
19 export JAVA_HOME="/usr/lib/jvm/java-8-oracle";
20 elif [ -d /usr/lib/jvm/java-8-openjdk-amd64 ]; then
21 export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64";
22 fi
23 fi
24 # Check if mvn exists
25 command -v mvn >/dev/null 2>&1 || {
26 # Following the convention, the default location of maven shows as below.
27 MAVEN=${MAVEN:-~/Applications/apache-maven-3.3.9};
28 export PATH="$MAVEN/bin:$PATH";
29 }
30}
31
32# checkout $TAG, build project and copy it to other location
33check_copy() {
34 CHECK_TAG=`git checkout $TAG`
35 if [[ $CHECK_TAG =~ "error" ]]; then
36 echo "There is no branch or tag named $TAG in $ONOS_ROOT" >&2 && exit 1
37 fi
38 FOLDER=$CURRENT_PATH/onos-$TAG-blackduck
39 [ -d "$FOLDER" ] && rm -r $FOLDER
40 mkdir $FOLDER
41 mvn clean install
42 if [$? -eq 0 ]; then
43 cp -r -a * $FOLDER;
44 if [ -d "$FOLDER/.git" ]; then
45 rm -r $FOLDER/.git
46 fi;
47 else
48 git checkout $CURRENT_TAG;
49 rm -r $FOLDER
50 echo "mvn compilation failed"
51 fi
52}
53
54# Script entry point
55CURRENT_PATH=`pwd`
56TAG=${1:-'master'}
57
58init
59cd $ONOS_ROOT
60CURRENT_TAG=`git branch | awk '{print $2}'`
61check_copy
62cd $FOLDER
63zip -rq -m $CURRENT_PATH/onos-$TAG-blackduck.zip *
64cd ..
65rm -r $FOLDER
66
67cd $ONOS_ROOT
68git checkout $CURRENT_TAG