Made build.sh a bit more rescilient

I modified the build.sh script to do the following:
* Determine the OS X version rather than assume we're building on 10.8, so one can now build on 10.8 or 10.9.
* Added detection for an unset JAVA_HOME variable, and setting JAVA_HOME if it is missing.

Thanks for an awesome plugin.