Reversed the order of tests to find a scala executable (in the case when SPARK_LAUNCH_WITH_SCALA is defined): instead of checking in the PATH first, and only then (if not found) for SCALA_HOME, now we check for SCALA_HOME first, and only then (if not defined) do we look in the PATH.  The advantage is that now if the user has a more recent (non-compatible) version of scala in her PATH, she can use SCALA_HOME to point to the older (compatible) version for use with spark.
Reversed the order of tests to find a scala executable (in the case when SPARK_LAUNCH_WITH_SCALA is defined): instead of checking in the PATH first, and only then (if not found) for SCALA_HOME, now we check for SCALA_HOME first, and only then (if not defined) do we look in the PATH.  The advantage is that now if the user has a more recent (non-compatible) version of scala in her PATH, she can use SCALA_HOME to point to the older (compatible) version for use with spark.

Suggested by Josh Rosen in this thread:

  https://groups.google.com/forum/?fromgroups=#!topic/spark-users/NC9JKvP8808

zero323/spark,UndeadBaneGitHub/spark,SnappyDataInc/spark,taroplus/spark,icexelloss/spark,rezasafi/spark,cloudera/spark,shaneknapp/spark,kimoonkim/spark,SnappyDataInc/spark,andrewor14/iolap,sureshthalamati/spark,guoxiaolongzte/spark,metamx/spark,mzl9039/spark,markhamstra/spark,ioana-delaney/spark,big-pegasus/spark,lxsmnv/spark,nchammas/spark,wangmiao1981/spark,actuaryzhang/spark,adrian-ionescu/apache-spark,andrewor14/iolap,liyichao/spark,shubhamchopra/spark,janewangfb/spark,dbtsai/spark,goldmedal/spark,SHASHANKB/spark,panfengfeng/spark,jiangxb1987/spark,shubhamchopra/spark,darionyaphet/spark,liutang123/spark,big-pegasus/spark,adrian-ionescu/apache-spark,aray/spark,tengpeng/spark,WeichenXu123/spark,szhem/spark,rekhajoshm/spark,xflin/spark,esi-mineset/spark,stanzhai/spark,sahilTakiar/spark,JerryLead/spark,wangyum/spark,mdespriee/spark,pgandhi999/spark,zzcclp/spark,janewangfb/spark,alunarbeach/spark,chuckchen/spark,aray/spark,bdrillard/spark,pgandhi999/spark,skonto/spark,esi-mineset/spark,bravo-zhang/spark,yanboliang/spark,panfengfeng/spark,nilsgrabbert/spark,wangmiao1981/spark,big-pegasus/spark,minixalpha/spark,patrick-nicholson/spark,rednaxelafx/apache-spark,nilsgrabbert/spark,vax11780/spark,yanboliang/spark,wzhfy/spark,janewangfb/spark,shuangshuangwang/spark,ajaysaini725/spark,taroplus/spark,HyukjinKwon/spark,Aegeaner/spark,dongjoon-hyun/spark,pgandhi999/spark,caneGuy/spark,sureshthalamati/spark,adrian-ionescu/apache-spark,tengpeng/spark,jkbradley/spark,caneGuy/spark,andrewor14/iolap,WindCanDie/spark,pronix/spark,darionyaphet/spark,ibm-research-ireland/sparkoscope,maropu/spark,bOOm-X/spark,milliman/spark,vinodkc/spark,actuaryzhang/spark,darionyaphet/spark,eyalfa/spark,tengpeng/spark,zzcclp/spark,adrian-ionescu/apache-spark,jrshust/spark,huang1900/spark,patrick-nicholson/spark,Panos-Bletsos/spark-cost-model-optimizer,icexelloss/spark,BryanCutler/spark,liutang123/spark,sahilTakiar/spark,aray/spark,liyichao/spark,spark-test/spark,apache/spark,LantaoJin/spark,poffuomo/spark,actuaryzhang/spark,ron8hu/spark,vinodkc/spark,JerryLead/spark,andrewor14/iolap,mike0sv/spark,goldmedal/spark,cin/spark,icexelloss/spark,darionyaphet/spark,actuaryzhang/spark,pronix/spark,panfengfeng/spark,ConeyLiu/spark,liutang123/spark,jkbradley/spark,shubhamchopra/spark,akopich/spark,panfengfeng/spark,maropu/spark,caneGuy/spark,dongjoon-hyun/spark,gioenn/xSpark,dhruve/spark,cloudera/spark,holdenk/spark,shuangshuangwang/spark,akopich/spark,taroplus/spark,esi-mineset/spark,1haodian/spark,setjet/spark,ptkool/spark,rikima/spark,map222/spark,techaddict/spark,szhem/spark,ron8hu/spark,loneknightpy/spark,wangmiao1981/spark,lyogavin/spark,kiszk/spark,brad-kaiser/spark,WindCanDie/spark,kevinyu98/spark,jianran/spark,chuckchen/spark,debugger87/spark,sachintyagi22/spark,patrick-nicholson/spark,mahak/spark,sachintyagi22/spark,darionyaphet/spark,wangyum/spark,ddna1021/spark,mahak/spark,huang1900/spark,vinodkc/spark,jkbradley/spark,witgo/spark,zuotingbing/spark,ddna1021/spark,jianran/spark,mzl9039/spark,WindCanDie/spark,markhamstra/spark,taroplus/spark,apache/spark,cloudera/spark,metamx/spark,ahnqirage/spark,caneGuy/spark,lvdongr/spark,tengpeng/spark,Panos-Bletsos/spark-cost-model-optimizer,guoxiaolongzte/spark,JerryLead/spark,bravo-zhang/spark,mdespriee/spark,jlopezmalla/spark,shaneknapp/spark,srowen/spark,vinodkc/spark,panfengfeng/spark,ajaysaini725/spark,mike0sv/spark,eyalfa/spark,liutang123/spark,xflin/spark,saltstar/spark,andrewor14/spark,mahak/spark,sachintyagi22/spark,shuangshuangwang/spark,zhouyejoe/spark,someorz/spark,alunarbeach/spark,jrshust/spark,ddna1021/spark,rjpower/spark,eyalfa/spark,jiangxb1987/spark,andrewor14/spark,holdenk/spark,UndeadBaneGitHub/spark,apache-spark-on-k8s/spark,alunarbeach/spark,saltstar/spark,JoshRosen/spark,LantaoJin/spark,rikima/spark,jrshust/spark,tejasapatil/spark,skonto/spark,loneknightpy/spark,apache-spark-on-k8s/spark,aokolnychyi/spark,ibm-research-ireland/sparkoscope,debugger87/spark,techaddict/spark,skonto/spark,tejasapatil/spark,haowu80s/spark,bravo-zhang/spark,chuckchen/spark,kiszk/spark,witgo/spark,jianran/spark,metamx/spark,srowen/spark,icexelloss/spark,srowen/spark,zuotingbing/spark,hhbyyh/spark,Panos-Bletsos/spark-cost-model-optimizer,bOOm-X/spark,mdespriee/spark,ahnqirage/spark,byakuinss/spark,WeichenXu123/spark,witgo/spark,milliman/spark,Panos-Bletsos/spark-cost-model-optimizer,alunarbeach/spark,zhouyejoe/spark,stanzhai/spark,MLnick/spark,brad-kaiser/spark,sureshthalamati/spark,SHASHANKB/spark,vax11780/spark,1haodian/spark,taroplus/spark,WindCanDie/spark,wgpshashank/spark,zero323/spark,sryza/spark,ron8hu/spark,debugger87/spark,wangmiao1981/spark,gioenn/xSpark,mahak/spark,tejasapatil/spark,jrshust/spark,liyichao/spark,lxsmnv/spark,witgo/spark,pgandhi999/spark,shubhamchopra/spark,ueshin/apache-spark,poffuomo/spark,wangyum/spark,ddna1021/spark,tejasapatil/spark,ptkool/spark,map222/spark,mike0sv/spark,ibm-research-ireland/sparkoscope,ConeyLiu/spark,haowu80s/spark,cin/spark,saturday-shi/spark,srowen/spark,kevinyu98/spark,joseph-torres/spark,bOOm-X/spark,nlalevee/spark,highfei2011/spark,SnappyDataInc/spark,lyogavin/spark,ioana-delaney/spark,metamx/spark,pronix/spark,big-pegasus/spark,rjpower/spark,mkolod/incubator-spark,chuckchen/spark,maropu/spark,BryanCutler/spark,saltstar/spark,akopich/spark,ddna1021/spark,setjet/spark,stanzhai/spark,dbtsai/spark,sureshthalamati/spark,WeichenXu123/spark,narahari92/spark,WeichenXu123/spark,akopich/spark,hhbyyh/spark,WindCanDie/spark,lvdongr/spark,JoshRosen/spark,bravo-zhang/spark,mkolod/incubator-spark,mkolod/incubator-spark,nlalevee/spark,SHASHANKB/spark,joseph-torres/spark,1haodian/spark,ioana-delaney/spark,apache/spark,zero323/spark,LantaoJin/spark,hvanhovell/spark,spark-test/spark,wangyum/spark,xuanyuanking/spark,cloud-fan/spark,chuckchen/spark,ptkool/spark,xflin/spark,mkolod/incubator-spark,map222/spark,setjet/spark,michalsenkyr/spark,mzl9039/spark,poffuomo/spark,someorz/spark,sahilTakiar/spark,lvdongr/spark,HyukjinKwon/spark,nchammas/spark,ConeyLiu/spark,JerryLead/spark,ericvandenbergfb/spark,jiangxb1987/spark,ueshin/apache-spark,debugger87/spark,zhouyejoe/spark,hhbyyh/spark,spark-test/spark,rezasafi/spark,mdespriee/spark,gioenn/xSpark,ahnqirage/spark,zzcclp/spark,zuotingbing/spark,loneknightpy/spark,yanboliang/spark,highfei2011/spark,debugger87/spark,jlopezmalla/spark,shaneknapp/spark,liyichao/spark,patrick-nicholson/spark,apache/spark,wgpshashank/spark,esi-mineset/spark,facaiy/spark,facaiy/spark,UndeadBaneGitHub/spark,panfengfeng/spark,zhouyejoe/spark,publicRoman/spark,minixalpha/spark,milliman/spark,markhamstra/spark,nilsgrabbert/spark,szhem/spark,vax11780/spark,tengpeng/spark,actuaryzhang/spark,rezasafi/spark,rekhajoshm/spark,witgo/spark,nlalevee/spark,jkbradley/spark,UndeadBaneGitHub/spark,hvanhovell/spark,kevinyu98/spark,rednaxelafx/apache-spark,jlopezmalla/spark,janewangfb/spark,nchammas/spark,poffuomo/spark,liyichao/spark,saltstar/spark,ueshin/apache-spark,liutang123/spark,highfei2011/spark,mdespriee/spark,cin/spark,minixalpha/spark,ahnqirage/spark,loneknightpy/spark,kimoonkim/spark,hhbyyh/spark,UndeadBaneGitHub/spark,dbtsai/spark,rekhajoshm/spark,bravo-zhang/spark,LantaoJin/spark,mdespriee/spark,jiangxb1987/spark,Aegeaner/spark,shuangshuangwang/spark,gengliangwang/spark,someorz/spark,kimoonkim/spark,saturday-shi/spark,jrshust/spark,nlalevee/spark,apache/spark,aray/spark,xuanyuanking/spark,milliman/spark,tengpeng/spark,milliman/spark,SHASHANKB/spark,facaiy/spark,kimoonkim/spark,gioenn/xSpark,minixalpha/spark,dhruve/spark,ericvandenbergfb/spark,mzl9039/spark,ajaysaini725/spark,gengliangwang/spark,lvdongr/spark,aokolnychyi/spark,skonto/spark,dbtsai/spark,publicRoman/spark,ConeyLiu/spark,koeninger/spark,someorz/spark,yanboliang/spark,jlopezmalla/spark,xuanyuanking/spark,lxsmnv/spark,kevinyu98/spark,dongjoon-hyun/spark,jlopezmalla/spark,mdespriee/spark,tejasapatil/spark,mzl9039/spark,Aegeaner/spark,taroplus/spark,eyalfa/spark,rikima/spark,dotunolafunmiloye/spark,rjpower/spark,nilsgrabbert/spark,spark-test/spark,cin/spark,shaneknapp/spark,andrewor14/spark,vax11780/spark,ajaysaini725/spark,HyukjinKwon/spark,caneGuy/spark,michalsenkyr/spark,holdenk/spark,mzl9039/spark,maropu/spark,goldmedal/spark,bdrillard/spark,highfei2011/spark,poffuomo/spark,ptkool/spark,ibm-research-ireland/sparkoscope,SHASHANKB/spark,jkbradley/spark,ibm-research-ireland/sparkoscope,saltstar/spark,wzhfy/spark,rikima/spark,techaddict/spark,zero323/spark,MLnick/spark,zzcclp/spark,map222/spark,zuotingbing/spark,MLnick/spark,BryanCutler/spark,publicRoman/spark,dhruve/spark,eyalfa/spark,stanzhai/spark,huang1900/spark,narahari92/spark,taroplus/spark,rednaxelafx/apache-spark,lxsmnv/spark,pgandhi999/spark,apache/spark,nilsgrabbert/spark,setjet/spark,bravo-zhang/spark,vinodkc/spark,JoshRosen/spark,JoshRosen/spark,vinodkc/spark,nchammas/spark,debugger87/spark,nchammas/spark,BryanCutler/spark,vinodkc/spark,JoshRosen/spark,SHASHANKB/spark,caneGuy/spark,aosagie/spark,JerryLead/spark,ahnqirage/spark,liyichao/spark,matthewfranglen/spark,dhruve/spark,rednaxelafx/apache-spark,jianran/spark,cloud-fan/spark,sahilTakiar/spark,aokolnychyi/spark,kevinyu98/spark,joseph-torres/spark,minixalpha/spark,icexelloss/spark,rezasafi/spark,Panos-Bletsos/spark-cost-model-optimizer,1haodian/spark,sachintyagi22/spark,darionyaphet/spark,rjpower/spark,goldmedal/spark,darionyaphet/spark,brad-kaiser/spark,someorz/spark,ioana-delaney/spark,szhem/spark,pronix/spark,WindCanDie/spark,JerryLead/spark,hvanhovell/spark,lxsmnv/spark,hvanhovell/spark,joseph-torres/spark,1haodian/spark,narahari92/spark,gengliangwang/spark,guoxiaolongzte/spark,xuanyuanking/spark,mike0sv/spark,cloud-fan/spark,kimoonkim/spark,LantaoJin/spark,zuotingbing/spark,joseph-torres/spark,markhamstra/spark,rekhajoshm/spark,patrick-nicholson/spark,szhem/spark,hvanhovell/spark,ConeyLiu/spark,dhruve/spark,dongjoon-hyun/spark,publicRoman/spark,ron8hu/spark,mzl9039/spark,sachintyagi22/spark,someorz/spark,aray/spark,Panos-Bletsos/spark-cost-model-optimizer,szhem/spark,HyukjinKwon/spark,LantaoJin/spark,brad-kaiser/spark,byakuinss/spark,spark-test/spark,koeninger/spark,mkolod/incubator-spark,HyukjinKwon/spark,zuotingbing/spark,ueshin/apache-spark,srowen/spark,alunarbeach/spark,ioana-delaney/spark,Aegeaner/spark,publicRoman/spark,joseph-torres/spark,bdrillard/spark,dongjoon-hyun/spark,zzcclp/spark,techaddict/spark,cin/spark,rednaxelafx/apache-spark,saturday-shi/spark,highfei2011/spark,ueshin/apache-spark,brad-kaiser/spark,wgpshashank/spark,ConeyLiu/spark,spark-test/spark,saturday-shi/spark,WindCanDie/spark,markhamstra/spark,mahak/spark,markhamstra/spark,shubhamchopra/spark,wangmiao1981/spark,narahari92/spark,dbtsai/spark,haowu80s/spark,saturday-shi/spark,guoxiaolongzte/spark,yanboliang/spark,lxsmnv/spark,zhouyejoe/spark,SnappyDataInc/spark,jianran/spark,zuotingbing/spark,Panos-Bletsos/spark-cost-model-optimizer,bdrillard/spark,publicRoman/spark,icexelloss/spark,stanzhai/spark,xuanyuanking/spark,koeninger/spark,apache-spark-on-k8s/spark,guoxiaolongzte/spark,kiszk/spark,debugger87/spark,vax11780/spark,akopich/spark,SnappyDataInc/spark,witgo/spark,kissmetrics/spark,ericvandenbergfb/spark,aokolnychyi/spark,adrian-ionescu/apache-spark,aokolnychyi/spark,maropu/spark,sahilTakiar/spark,lvdongr/spark,liutang123/spark,setjet/spark,jiangxb1987/spark,MLnick/spark,wangyum/spark,gengliangwang/spark,aosagie/spark,rezasafi/spark,markhamstra/spark,ptkool/spark,rekhajoshm/spark,ron8hu/spark,andrewor14/spark,byakuinss/spark,dbtsai/spark,big-pegasus/spark,hhbyyh/spark,techaddict/spark,narahari92/spark,sryza/spark,wzhfy/spark,haowu80s/spark,ueshin/apache-spark,apache-spark-on-k8s/spark,dongjoon-hyun/spark,lvdongr/spark,rikima/spark,koeninger/spark,BryanCutler/spark,cloud-fan/spark,map222/spark,rezasafi/spark,wangyum/spark,setjet/spark,michalsenkyr/spark,ericvandenbergfb/spark,ioana-delaney/spark,andrewor14/iolap,dbtsai/spark,kissmetrics/spark,maropu/spark,jiangxb1987/spark,sachintyagi22/spark,stanzhai/spark,MLnick/spark,szhem/spark,byakuinss/spark,jianran/spark,shaneknapp/spark,kevinyu98/spark,liutang123/spark,saltstar/spark,WeichenXu123/spark,saltstar/spark,rednaxelafx/apache-spark,dhruve/spark,gioenn/xSpark,kissmetrics/spark,sahilTakiar/spark,rekhajoshm/spark,goldmedal/spark,minixalpha/spark,bOOm-X/spark,sryza/spark,nilsgrabbert/spark,bOOm-X/spark,SnappyDataInc/spark,JoshRosen/spark,wzhfy/spark,haowu80s/spark,ueshin/apache-spark,SHASHANKB/spark,xuanyuanking/spark,WeichenXu123/spark,metamx/spark,narahari92/spark,JerryLead/spark,lvdongr/spark,shubhamchopra/spark,joseph-torres/spark,michalsenkyr/spark,sryza/spark,JoshRosen/spark,pronix/spark,aosagie/spark,ajaysaini725/spark,hhbyyh/spark,cloud-fan/spark,gengliangwang/spark,janewangfb/spark,zero323/spark,chuckchen/spark,loneknightpy/spark,wangmiao1981/spark,hhbyyh/spark,wzhfy/spark,apache-spark-on-k8s/spark,gengliangwang/spark,sureshthalamati/spark,esi-mineset/spark,tengpeng/spark,rednaxelafx/apache-spark,shaneknapp/spark,facaiy/spark,kiszk/spark,holdenk/spark,rezasafi/spark,andrewor14/iolap,nlalevee/spark,bdrillard/spark,esi-mineset/spark,wgpshashank/spark,zhouyejoe/spark,guoxiaolongzte/spark,sureshthalamati/spark,someorz/spark,shuangshuangwang/spark,huang1900/spark,andrewor14/iolap,jianran/spark,lyogavin/spark,eyalfa/spark,pgandhi999/spark,mike0sv/spark,rikima/spark,witgo/spark,shuangshuangwang/spark,minixalpha/spark,publicRoman/spark,wzhfy/spark,byakuinss/spark,ptkool/spark,adrian-ionescu/apache-spark,apache-spark-on-k8s/spark,facaiy/spark,loneknightpy/spark,janewangfb/spark,sureshthalamati/spark,rjpower/spark,ron8hu/spark,tejasapatil/spark,nlalevee/spark,BryanCutler/spark,actuaryzhang/spark,huang1900/spark,nchammas/spark,jrshust/spark,alunarbeach/spark,dotunolafunmiloye/spark,kimoonkim/spark,dotunolafunmiloye/spark,LantaoJin/spark,jlopezmalla/spark,facaiy/spark,BryanCutler/spark,jiangxb1987/spark,michalsenkyr/spark,maropu/spark,aray/spark,skonto/spark,rekhajoshm/spark,Aegeaner/spark,icexelloss/spark,adrian-ionescu/apache-spark,milliman/spark,skonto/spark,aosagie/spark,milliman/spark,dongjoon-hyun/spark,saturday-shi/spark,ioana-delaney/spark,xflin/spark,jlopezmalla/spark,ibm-research-ireland/sparkoscope,saturday-shi/spark,ddna1021/spark,apache/spark,cin/spark,kissmetrics/spark,zero323/spark,eyalfa/spark,rikima/spark,michalsenkyr/spark,1haodian/spark,UndeadBaneGitHub/spark,1haodian/spark,zzcclp/spark,aokolnychyi/spark,chuckchen/spark,aray/spark,gioenn/xSpark,kissmetrics/spark,kiszk/spark,alunarbeach/spark,tejasapatil/spark,nlalevee/spark,metamx/spark,akopich/spark,ptkool/spark,shaneknapp/spark,Aegeaner/spark,stanzhai/spark,cin/spark,haowu80s/spark,apache-spark-on-k8s/spark,goldmedal/spark,hvanhovell/spark,MLnick/spark,sahilTakiar/spark,panfengfeng/spark,akopich/spark,xuanyuanking/spark,ericvandenbergfb/spark,zero323/spark,techaddict/spark,poffuomo/spark,cloudera/spark,pronix/spark,HyukjinKwon/spark,cloud-fan/spark,andrewor14/spark,actuaryzhang/spark,dotunolafunmiloye/spark,big-pegasus/spark,ahnqirage/spark,koeninger/spark,liyichao/spark,michalsenkyr/spark,spark-test/spark,mike0sv/spark,aosagie/spark,SnappyDataInc/spark,WeichenXu123/spark,holdenk/spark,bdrillard/spark,cloud-fan/spark,dhruve/spark,guoxiaolongzte/spark,map222/spark,patrick-nicholson/spark,narahari92/spark,wangyum/spark,aosagie/spark,mahak/spark,andrewor14/spark,huang1900/spark,bOOm-X/spark,yanboliang/spark,brad-kaiser/spark,highfei2011/spark,zhouyejoe/spark,ibm-research-ireland/sparkoscope,UndeadBaneGitHub/spark,mahak/spark,goldmedal/spark,ahnqirage/spark,pgandhi999/spark,xflin/spark,zzcclp/spark,jrshust/spark,sryza/spark,holdenk/spark,andrewor14/spark,kimoonkim/spark,kiszk/spark,holdenk/spark,kissmetrics/spark,caneGuy/spark,setjet/spark,ericvandenbergfb/spark,poffuomo/spark,wangmiao1981/spark,techaddict/spark,jkbradley/spark,Aegeaner/spark,aokolnychyi/spark,ddna1021/spark,kiszk/spark,map222/spark,xflin/spark,metamx/spark,MLnick/spark,ajaysaini725/spark,gengliangwang/spark,ericvandenbergfb/spark,ajaysaini725/spark,srowen/spark,aosagie/spark,esi-mineset/spark,lyogavin/spark,xflin/spark,srowen/spark,big-pegasus/spark,patrick-nicholson/spark,wzhfy/spark,kissmetrics/spark,loneknightpy/spark,sachintyagi22/spark,shuangshuangwang/spark,cloudera/spark,lyogavin/spark,nchammas/spark,janewangfb/spark,HyukjinKwon/spark,byakuinss/spark,jkbradley/spark,bdrillard/spark,mike0sv/spark,lxsmnv/spark,nilsgrabbert/spark,hvanhovell/spark,highfei2011/spark,skonto/spark,bOOm-X/spark,huang1900/spark,shubhamchopra/spark,yanboliang/spark,ron8hu/spark,bravo-zhang/spark,kevinyu98/spark,facaiy/spark,ConeyLiu/spark,byakuinss/spark,brad-kaiser/spark,gioenn/xSpark