documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.io/jammit/
MIT License
1.16k stars 197 forks source link

Fail loudly when java is not installed #4

Closed tarmolehtpuu closed 14 years ago

tarmolehtpuu commented 14 years ago

Jammit fails with pretty cryptic errors (actually from yui-compressor) about broken pipes when java is not installed. Obviously yui-compressor requires java, but it would still be nice to get some sort of warning about not finding java in PATH.

Hope this saves someone a few hours of debugging ;)

ncdc commented 14 years ago

You'll also see similar errors if running the Closure compiler with Java < 6 - something else to watch out for

documentcloud commented 14 years ago

Let's add a big, loud error if Java's not there, or if you're using Closure and it's less than 6. Do either of you have recommended ways to check the version of Java from Ruby?

ncdc commented 14 years ago

The quick thought I have is to capture the output of java -version and parse it:

java version "1.6.0_17" Java(TM) SE Runtime Environment (build 1.6.0_17-b04) Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)

tarmolehtpuu commented 14 years ago

A simple cross platform way to check it would be something like this:

unless system('java -version')
  throw "java not found in PATH"
end
documentcloud commented 14 years ago

I've just pushed a commit that raises a "JavaNotFound" exception if Java doesn't exist, or if the version is too low for your JavaScript compressor of choice. If either or both of you could give it a try, and confirm that it correctly throws the error in your environment, that would be great. To install the gem from a checked-out Jammit repo, just "rake gem:install".

tarmolehtpuu commented 14 years ago

natte:noahworld tarmo$ jammit /Library/Ruby/Gems/1.8/gems/jammit-0.2.5/lib/jammit.rb:116:in check_java_version': the "java" command could not be found (Jammit::JavaNotFound) from /Library/Ruby/Gems/1.8/gems/jammit-0.2.5/lib/jammit.rb:60:inload_configuration' from /Library/Ruby/Gems/1.8/gems/jammit-0.2.5/lib/jammit.rb:136 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:inrequire' from /Library/Ruby/Gems/1.8/gems/jammit-0.2.5/bin/../lib/jammit/command_line.rb:2 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:inrequire' from /Library/Ruby/Gems/1.8/gems/jammit-0.2.5/bin/jammit:3 from /usr/bin/jammit:19:in `load' from /usr/bin/jammit:19

tarmolehtpuu commented 14 years ago

works perfectly, thanks :)

documentcloud commented 14 years ago

Glad to hear it. Jammit 0.2.6 is out as a gem, with the Java exceptions. Closing this ticket -- thanks for the bug report.