#!/bin/bash

# Absolute path to this script, e.g. /home/user/xxx/infoRlease.sh
SCRIPT="$(cd $(dirname "$0") && pwd)/$(basename "$0")"
# Absolute path this script is in, thus /home/user/xxx
scriptDir=$(dirname "$SCRIPT")


if [ $# != 3 ] ; then
    echo
    echo "Usage:"
    echo "  $0 tagName targetProdBuild cutOffDate"
    echo "For example:"
    echo "  $0 3.8.x-prod-ip6.2-ER1 2015-04-27"
    echo
    exit 1
fi

productTag=$1
targetProdBuild=$2
cutOffDate=$3

echo "The tag name is: $productTag"
echo "The target product build is: $targetProdBuild"
echo "The cutoff date is: $cutOffDate"
echo -n "Is this ok? (Hit control-c if is not): "
read ok

cd $scriptDir

if [ ! -d "../reports" ]; then
	mkdir ../reports
fi

# name of file to be written and pushed  
fileToWrite=reports/$productTag.txt

#COMPILE_DEPS=$(mvn -f ../modeshape-distribution/pom.xml dependency:tree | grep -v "test" | grep "INFO")
VERSION=$(head ../pom.xml | grep version | tr -d ' \t\n<version/>')
CONTACTS="modeshape                 hchiorea@redhat.com"
REPOSITORIES="https://github.com/jboss-integration/modeshape/tree/"$(echo $productTag) 
MAVEN=$(mvn -version | head -1)
BLDCOMMAND="mvn -s ./settings.xml clean install -Passembly -DskipTests"
# JAVA version as it needs a workaround
java -version 2>>javaVersion.txt
JAVAV=$(cat javaVersion.txt)
rm javaVersion.txt
DATETIME=`date +%F-%H:%M`

cat <<EOF >../$fileToWrite

------------------------------------------------------------------------
          ModeShape (DV) Engineering to Productization Handoff Report
------------------------------------------------------------------------
Report Date: $DATETIME
Code Cutoff Date: $cutOffDate
Target Product Build: $targetProdBuild
Source Product Tag: $productTag

Product Page: 
https://pp.engineering.redhat.com/pp/product/eds/overview

-----------------------------------------------------------------------  
                     Component owners contacts                           
------------------------------------------------------------------------
$CONTACTS

------------------------------------------------------------------------
                          Build Tools                               
------------------------------------------------------------------------
JAVA: 
$JAVAV

MAVEN: 
$MAVEN

------------------------------------------------------------------------
                        Sources to build                         
------------------------------------------------------------------------
$REPOSITORIES

------------------------------------------------------------------------
                          Build Commands
------------------------------------------------------------------------

$BLDCOMMAND

------------------------------------------------------------------------  
             Build artifacts for product (based on EAP 6.4)                       
------------------------------------------------------------------------

- (JDBC Driver)  modeshape-client/target/modeshape-client-$VERSION.jar

  placed in folder dataVirtualization/jdbc
	
- (DV Kit)  modeshape-distribution/target/modeshape-$VERSION-jbosseap-dist.zip
	 
  unzipped into DV modules layer

- (JavaDoc) modeshape-distribution/target/modeshape-$VERSION-javadoc.zip
  	
  delivered as part of DV javadocs 

------------------------------------------------------------------------  
                               Notes                       
------------------------------------------------------------------------
No new 3rd party dependencies
EOF
