lib/jar_installer.rb in jar-dependencies-0.0.5 vs lib/jar_installer.rb in jar-dependencies-0.0.6
- old
+ new
@@ -53,14 +53,18 @@
@file = line.sub( /^.*:/, '' ).strip
@gav = line.sub( /:[^:]+$/, '' )
end
end
- def self.install_jars
- new.install_jars
+ def self.install_jars( write_require_file = false )
+ new.install_jars( write_require_file )
end
+ def self.vendor_jars( write_require_file = false )
+ new.vendor_jars( write_require_file )
+ end
+
def self.load_from_maven( file )
result = []
File.read( file ).each_line do |line|
dep = Dependency.new( line )
result << dep if dep
@@ -111,42 +115,53 @@
end
end
private :find_spec
def initialize( spec = nil )
+ setup( spec )
+ end
+
+ def setup( spec = nil )
spec ||= find_spec
case spec
when String
- @basedir = File.dirname( File.expand_path( spec ) )
- @specfile = spec
+ @specfile = File.expand_path( spec )
+ @basedir = File.dirname( @specfile )
spec = eval( File.read( spec ) )
- when
+ when Gem::Specification
if File.exists?( spec.spec_file )
@basedir = spec.gem_dir
@specfile = spec.spec_file
else
- initialize( nil )
+ # this happens with bundle and local gems
+ # there the spec_file is "not installed" but inside
+ # the gem_dir directory
+ Dir.chdir( spec.gem_dir ) do
+ setup( nil )
+ end
end
+ else
+ raise 'spec must be either String or Gem::Specification'
end
@spec = spec
end
def ruby_maven_install_options=( options )
@options = options.dup
end
- def vendor_jars
+ def vendor_jars( write_require_file = true )
return unless has_jars?
# do not vendor only if set explicitly via ENV/system-properties
- do_install( Jars.to_prop( Jars::VENDOR ) != 'false', false )
+ do_install( Jars.to_prop( Jars::VENDOR ) != 'false', write_require_file )
end
- def install_jars
+ def install_jars( write_require_file = true )
return unless has_jars?
- do_install( false, true )
+ do_install( false, write_require_file )
end
private
def has_jars?
@@ -156,17 +171,19 @@
! @spec.requirements.empty? && @spec.dependencies.detect { |d| d.name == 'jar-dependencies' && d.type == :runtime }
end
def do_install( vendor, write_require_file )
vendor_dir = File.join( @basedir, @spec.require_path )
- if write_require_file
- jars_file = File.join( vendor_dir, "#{@spec.name}_jars.rb" )
+ jars_file = File.join( vendor_dir, "#{@spec.name}_jars.rb" )
- # do not generate file if specfile is older then the generated file
- if File.exists?( jars_file ) &&
- File.mtime( @specfile ) < File.mtime( jars_file )
- jars_file = nil
- end
+ # write out new jars_file it write_require_file is true or
+ # check timestamps:
+ # do not generate file if specfile is older then the generated file
+ if ! write_require_file &&
+ File.exists?( jars_file ) &&
+ File.mtime( @specfile ) < File.mtime( jars_file )
+ # leave jars_file as is
+ jars_file = nil
end
self.class.install_deps( install_dependencies, vendor_dir,
jars_file, vendor )
end