mguymon / lock_jar

LockJar manages Java Jars for Ruby
http://mguymon.github.io/lock_jar/
Apache License 2.0
46 stars 9 forks source link

LockJar breaks on simple usecase #1

Closed alexandru closed 12 years ago

alexandru commented 12 years ago

I have the following Jarfile ...

jar "org.eclipse.jetty:jetty-servlet:8.1.3.v20120416"

From IRB here's what I get:

1.9.3p125 :006 > LockJar.lock('Jarfile', :local_repo => BASEDIR.join('lib').to_path)
...
16:35:34 INFO  NaetherTransfer - Downloading: http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-servlet/8.1.3.v20120416/jetty-servlet-8.1.3.v20120416.pom
IllegalStateException: The super POM /org/apache/maven/model/pom-4.0.0.xml was not found, please verify the integrity of your Maven installation
    from /home/alex/.rvm/gems/ruby-1.9.3-p125/gems/naether-0.7.1/lib/naether.rb:244:in `method_missing'
    from /home/alex/.rvm/gems/ruby-1.9.3-p125/gems/naether-0.7.1/lib/naether.rb:244:in `resolve_dependencies'
    from /home/alex/.rvm/gems/ruby-1.9.3-p125/gems/lock_jar-0.2.2/lib/lock_jar/resolver.rb:62:in `resolve'
    from /home/alex/.rvm/gems/ruby-1.9.3-p125/gems/lock_jar-0.2.2/lib/lock_jar/runtime.rb:105:in `block in lock'
    from /home/alex/.rvm/gems/ruby-1.9.3-p125/gems/lock_jar-0.2.2/lib/lock_jar/runtime.rb:93:in `each'
    from /home/alex/.rvm/gems/ruby-1.9.3-p125/gems/lock_jar-0.2.2/lib/lock_jar/runtime.rb:93:in `lock'
    from /home/alex/.rvm/gems/ruby-1.9.3-p125/gems/lock_jar-0.2.2/lib/lock_jar.rb:32:in `lock'
    from (irb):6
    from /home/alex/.rvm/rubies/ruby-1.9.3-p125/bin/irb:16:in `<main>'

This keeps repeating itself if I run that command in the same session. I noticed that if I exit IRB and then I go back and retry, it works. But the issue is reproducible by deleting my local repo of downloaded libraries. As I see it, LockJar downloads Naether dependencies the first time I do a lock(), as Naether has a bootstrap process.

For the moment, I can't find a workaround. To make matters worse, I want to install "lock_file" straight from my build file, to not require users to install it manually and after that I want to lock(). This means I have something like this:

    begin
      require 'lock_jar'
    rescue LoadError
      sh "gem install lock_jar"
      Gem.clear_paths
      require 'lock_jar'      
    end

     # later ...
     LockJar.lock('Jarfile', ...)

Thanks,

alexandru commented 12 years ago

Btw, the listing above was from using Ruby 1.9.3. However the error is different under JRuby ...

17:10:01 INFO  NaetherRepository - Installed org.jsoup:jsoup/maven-metadata.xml to /home/alex/Projects/geosmartly/./lib/org/jsoup/jsoup/maven-metadata-local.xml
Errno::EACCES: Permission denied - /tmp/d20120514-11199-1coeh7a/.
    from org/jruby/RubyFile.java:443:in `initialize'
    from org/jruby/RubyIO.java:1135:in `open'
    from /home/alex/.rvm/rubies/jruby-1.6.7/lib/ruby/1.8/fileutils.rb:699:in `remove_entry_secure'
    from /home/alex/.rvm/rubies/jruby-1.6.7/lib/ruby/1.8/tmpdir.rb:131:in `mktmpdir'
    from /home/alex/.rvm/gems/jruby-1.6.7/gems/lock_jar-0.2.2/lib/lock_jar/resolver.rb:34:in `initialize'
    from /home/alex/.rvm/gems/jruby-1.6.7/gems/lock_jar-0.2.2/lib/lock_jar/runtime.rb:32:in `resolver'
    from /home/alex/.rvm/gems/jruby-1.6.7/gems/lock_jar-0.2.2/lib/lock_jar/runtime.rb:105:in `lock'
    from org/jruby/RubyHash.java:1181:in `each'
    from /home/alex/.rvm/gems/jruby-1.6.7/gems/lock_jar-0.2.2/lib/lock_jar/runtime.rb:93:in `lock'
    from /home/alex/.rvm/gems/jruby-1.6.7/gems/lock_jar-0.2.2/lib/lock_jar.rb:32:in `lock'
    from (irb):6:in `evaluate'
    from org/jruby/RubyKernel.java:1083:in `eval'
    from /home/alex/.rvm/rubies/jruby-1.6.7/lib/ruby/1.8/irb.rb:158:in `eval_input'
    from /home/alex/.rvm/rubies/jruby-1.6.7/lib/ruby/1.8/irb.rb:271:in `signal_status'
    from /home/alex/.rvm/rubies/jruby-1.6.7/lib/ruby/1.8/irb.rb:155:in `eval_input'
    from org/jruby/RubyKernel.java:1410:in `loop'
    from org/jruby/RubyKernel.java:1183:in `catch'
    from /home/alex/.rvm/rubies/jruby-1.6.7/lib/ruby/1.8/irb.rb:154:in `eval_input'
    from /home/alex/.rvm/rubies/jruby-1.6.7/lib/ruby/1.8/irb.rb:71:in `start'
    from org/jruby/RubyKernel.java:1183:in `catch'
    from /home/alex/.rvm/rubies/jruby-1.6.7/lib/ruby/1.8/irb.rb:70:in `start'
    from /home/alex/.rvm/rubies/jruby-1.6.7/bin/irb:17:in `(root)'

Again, to make this work, I have to restart IRB and try again. But if I exit IRB, delete my local repository and then retry the command in IRB, then it gives me the above error. So the same pattern I got with Ruby 1.9.3

mguymon commented 12 years ago

Try adding:

repository 'http://repo1.maven.org/maven2'

To the top of the Jarfile. It looks like the default repo is not being applied correctly, hence the 'cannot find super pom'.

This is an issue with 1.9, in both 1.9.2 and 1.9.3. I cannot reproduce it with JRuby or 1.8.

The error Errno::EACCES: Permission denied looks like the JRuby bug for Dir.mktmpdir, which LockJar uses when downloading Jars to bootstrap. http://jira.codehaus.org/browse/JRUBY-5678. If you try the call a second time, it works.

alexandru commented 12 years ago

So I guess JRuby fixed the issue in 1.7

mguymon commented 12 years ago

I believe so, I have not tested with JRuby 1.7 yet, only with 1.6

mguymon commented 12 years ago

I pushed a new version, 0.3.0, that will fix this issue.

The problem was due to the temporary directory created for downloading jjars used to boot strap LockJar. After boot strapping, the temp dir was removed. While the JVM was fine, it caused the problem with the dependency resolution when it needed to access files used deleted with the temp dir. The work around is to create a .lock_jar/naether dir in the local repo for the bootstrap jars. After boot strapping, the temp jars are removed.