#!/bin/bash
#
# Copyright (C) 2013 Red Hat Inc.
# Author: Salim Badakhchani <sal@redhat.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
########################################################################

# Uncomment to debug script
set -x

SCM='git+'
URL='https://github.com/sbadakhc'
APP='buildmetadata-maven-plugin'
CHK='#7130058036a80c727810f0beb55488ee0ff7ba15'
SRC="${SCM}${URL}/${APP}.git${CHK}"
TAG='rcm-mw-tools'
BLD='rcm-mw-tools-build'
TGT='rcm-mw-tools-candidate'
PKG='com.redhat.rcm.maven.plugin-buildmetadata-maven-plugin'
VER="1.3.1"
OPT="-Dmaven.test.skip=true"

if [ -e "${HOME}/workspace/${APP}/build.log" ]; then
koji maven-build ${OPT} ${TGT} ${SRC}
else
cd ~/workspace
    git clone ${URL}/${APP}.git
    cd ${APP}
    git checkout ${APP}-${VER}
    mvn clean install -C -B dependency:resolve-plugins ${OPT} | tee build.log
    /opt/kojak/scripts/build/mead-load-build-dependencies ${HOME}/workspace/${APP}/build.log
    koji add-pkg ${TAG} ${PKG} --owner ${USER}
    
    # Uncomment the line below so submit the maven-build if your not building using Jenkins
    #koji maven-build ${OPT} ${TGT} ${SRC}
fi
