#!/bin/bash
# This script gives instructions for building NeXtMidas without the outdated lucene jar dependency

echo 'NMROOT, JAVAHOME, JAVA_HOME, GRADLEHOME and JAVAHOME and GRADLEHOME added to PATH'
echo 'before running the instructions in this script'
echo 'either set them outside of this script or at the beginning of this script'
# uncomment out and properly populate the setting of the environment variables, if desired
#setenv NMROOT     /share/dev/nxm/nxmbase_64/snapshot-2020-05-11-nxm39x
#setenv JAVAHOME   /share/apps/lang/java_64/jdk-14/
#setenv JAVA_HOME  $JAVAHOME
#setenv GRADLEHOME /share/apps/gradle/gradle-6.3
#setenv PATH       ${JAVAHOME}/bin:${GRADLEHOME}/bin:${PATH}

gradle --version

set QUOTE='"'

echo 'Building NeXtMidas:'
echo '  '
echo '  <unzip snapshot>'
echo '  '
echo '  cd $NMROOT'
echo '  mv convertgradle.sh convertgradle.sh.ORIG'
# -v: select non-matching items
echo '  grep -v "^gradle " convertgradle.sh.ORIG > convertgradle.sh'
echo '  diff convertgradle.sh.ORIG convertgradle.sh'
echo '  chmod a+x ./convertgradle.sh'
echo '  ./convertgradle.sh'
echo '  mv sys/src/main/midas/nxm/sys/intr/Help.java      sys/src/main/midas/nxm/sys/intr/Help.java.ORIG'
echo '  mv sys/src/main/midas/nxm/sys/libg/MJHelp.java    sys/src/main/midas/nxm/sys/libg/MJHelp.java.ORIG'
echo '  mv sys/src/main/midas/nxm/sys/libg/MJBrowser.java sys/src/main/midas/nxm/sys/libg/MJBrowser.java.ORIG'
echo '  mv sys/build.gradle                               sys/build.gradle.ORIG'
echo '  mv common.gradle                                  common.gradle.ORIG'
echo '  grep -v "thirdPartyDeps.*org.apache.lucene" sys/build.gradle.ORIG > sys/build.gradle'
echo "  cat common.gradle.ORIG | sed ${QUOTE}s/'nexusSnapshotUrl']/'nexusSnapshotUrl'/g${QUOTE} > common.gradle"
echo '  diff sys/build.gradle.ORIG sys/build.gradle'
echo '  diff common.gradle.ORIG    common.gradle'
echo '  gradle build -x test'
echo '  gradle eclipse'
echo '  gradle publish -x test'
echo '  '
