#!/bin/sh
base=`pwd`
echo -
echo ---

if [ "$sbase" == "" ]; then
  apifat=$base/APIFat/target
  apidocs=$base/API/target
	source=$base/Setup/target
	dist=$base/Setup/target/Setup
  target=$base/SikuliX-Setup
else
  echo ----- running on Jenkins
  apifat=$sbase/APIFat/target
  apidocs=$sbase/API/target
  source=$sbase/Setup/target
	dist=$sbase/Setup/target/Setup
  target=$jbase/SikuliX-Setup
  isjenkins=true
fi

echo ----- SikuliX collecting jars in $dist
if [ -e $dist ]; then
  rm -f *.jar
  rm -f -R $dist/Downloads
fi
mkdir $dist/Downloads
if [ -e $target ]; then
  rm -f -R $target
fi
mkdir $target
mkdir $target/Downloads

# ----------- Setup
echo ----- collecting jars
setupjar=`ls $source/*-plain.jar`
pversion=`java -jar $setupjar pversion`
java -jar $setupjar noSetup
echo ----- content of $dist
ls -l $dist
echo ----- content of $dist/Downloads
ls -l $dist/Downloads

# ----------- Setup
echo ----- copy Setup APIFat
apijar=`ls $apifat/*-plain.jar`
cp $dist/*.jar $target/
cp $apijar $target/sikulixapi-$pversion.jar
cp $apidocs/*-javadoc.jar $target
cp $apidocs/*-sources.jar $target

# ----------- Jars
echo ----- copy Download Jars
cp $dist/Downloads/* $target/Downloads/

echo ----------- final content of $target
ls -l $target
echo ----------- final content of $target/Downloads
ls -l $target/Downloads

echo ----------- SikuliX collectjars end -----------
if [ "$isjenkins" == "" ]; then
	echo -
	echo --
	echo ----
	echo ------
	echo -------- If it looks like success -----------
	echo ... move the folder $target
	echo to where you want
	echo and name it as you like
	echo and run setup, to get your wanted packages.
	echo !! BE SURE, not to download anything !!
	echo !! You are doing an offline setup !!
	echo ---------------------------------------------
fi
