#!/bin/bash
# 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

. `dirname $0`/bigtop.bom

IVY_MIRROR_PROP=${IVY_MIRROR_PROP:-https://repo1.maven.org/maven2}
BUILD_OPTS="-Dversion=${FULL_VERSION} -Dhadoop.version=${HADOOP_VERSION} \
            -Dexclude.from.war=nothing   \
            -Divy.home=${HOME}/.ivy2 -Drepo.maven.org=$IVY_MIRROR_PROP \
            -Divy_bootstrap_url1=$IVY_MIRROR_PROP \
            -Divy_install_path=${HOME}/.ant/lib -lib ${HOME}/.ant/lib  \
            -Dreactor.repo=file://${HOME}/.m2/repository"

# FIXME: this needs to be fixed at the product level
ant $BUILD_OPTS ivy-bootstrap

ant $BUILD_OPTS clean

# Build source package
(cd solr ; ant $BUILD_OPTS package-local-src-tgz "$@")

# Build Solr package 
(cd solr ; ant $BUILD_OPTS create-package "$@")

# Install artifacts into the local Maven cache
mvn install:install-file -DcreateChecksum=true -DgroupId=org.apache.solr -DartifactId=solr-dataimporthandler-extras -Dversion=$SOLR_VERSION -Dpackaging=jar -Dfile=solr/dist/solr-dataimporthandler-extras-$SOLR_VERSION.jar
mvn install:install-file -DcreateChecksum=true -DgroupId=org.apache.solr -DartifactId=solr-dataimporthandler -Dversion=$SOLR_VERSION -Dpackaging=jar -Dfile=solr/dist/solr-dataimporthandler-$SOLR_VERSION.jar
mvn install:install-file -DcreateChecksum=true -DgroupId=org.apache.solr -DartifactId=solr-analysis-extras -Dversion=$SOLR_VERSION -Dpackaging=jar -Dfile=solr/dist/solr-analysis-extras-$SOLR_VERSION.jar
mvn install:install-file -DcreateChecksum=true -DgroupId=org.apache.solr -DartifactId=solr-solrj -Dversion=$SOLR_VERSION -Dpackaging=jar -Dfile=solr/dist/solr-solrj-$SOLR_VERSION.jar
mvn install:install-file -DcreateChecksum=true -DgroupId=org.apache.solr -DartifactId=solr-test-framework -Dversion=$SOLR_VERSION -Dpackaging=jar -Dfile=solr/dist/solr-test-framework-$SOLR_VERSION.jar
mvn install:install-file -DcreateChecksum=true -DgroupId=org.apache.solr -DartifactId=solr-cell -Dversion=$SOLR_VERSION -Dpackaging=jar -Dfile=solr/dist/solr-cell-$SOLR_VERSION.jar
mvn install:install-file -DcreateChecksum=true -DgroupId=org.apache.solr -DartifactId=solr-core -Dversion=$SOLR_VERSION -Dpackaging=jar -Dfile=solr/dist/solr-core-$SOLR_VERSION.jar
mvn install:install-file -DcreateChecksum=true -DgroupId=org.apache.solr -DartifactId=solr-velocity -Dversion=$SOLR_VERSION -Dpackaging=jar -Dfile=solr/dist/solr-velocity-$SOLR_VERSION.jar
mvn install:install-file -DcreateChecksum=true -DgroupId=org.apache.solr -DartifactId=solr-langid -Dversion=$SOLR_VERSION -Dpackaging=jar -Dfile=solr/dist/solr-langid-$SOLR_VERSION.jar
