#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -ex

if [ "${BIGTOP_JDK:=8}" == "8" ]; then
    MAVEN_ADDITIONAL="-Dadditionalparam=-Xdoclint:none"
fi

if [ -z "$GIT_REPO" ]; then
    export MAVEN_OPTS='-Xmx512m'
    if [ -z "${DO_MAVEN_DEPLOY}" ]; then
        MAVEN_INST_DEPLOY=install
    else
        MAVEN_INST_DEPLOY=$DO_MAVEN_DEPLOY
    fi

    mvn -DskipTests=true source:jar-no-fork javadoc:jar \
        -P=binary ${MAVEN_ADDITIONAL} $@ $MAVEN_INST_DEPLOY
    
# Repackaging and changing the name to "sqoop2" is necessary as long
# as we continue to distribute a version of Sqoop 1.x as "sqoop"
    cd dist/target
    for file in `find ./ -name 'sqoop-*-bin-hadoop*' -type d`; do
        mv $file sqoop2-$FULL_VERSION
    done
    tar czf sqoop2-$FULL_VERSION.tar.gz sqoop2-$FULL_VERSION
    cd ../..
    
    mkdir build
    mv dist/target/sqoop2-$FULL_VERSION.tar.gz build/
else
    git add .
    git commit -a -m "Temporary commit for tarball"
    mkdir -p build
    git archive --prefix=sqoop2-${FULL_VERSION}/ --format=tar HEAD | gzip > build/sqoop2-${FULL_VERSION}.tar.gz
fi

