lib/jbundler/classpath_file.rb in jbundler-0.5.5 vs lib/jbundler/classpath_file.rb in jbundler-0.6.0

- old
+ new

@@ -24,17 +24,21 @@ def initialize(classpathfile = '.jbundler/classpath.rb') @classpathfile = classpathfile end - def require_classpath + def load_classpath load File.expand_path @classpathfile + end + + def require_classpath + load_classpath JBUNDLER_CLASSPATH.each { |c| require c } end def require_test_classpath - load File.expand_path @classpathfile unless defined? JBUNLDER_TEST_CLASSPATH + load_classpath JBUNDLER_TEST_CLASSPATH.each { |c| require c } end def mtime File.mtime(@classpathfile) @@ -42,29 +46,54 @@ def exists? File.exists?(@classpathfile) end + def missing?( jarfile ) + !exists? || !jarfile.exists_lock? + end + + def jarfile_newer?( jarfile ) + jarfile.exists? && (jarfile.mtime > mtime) + end + + def jarlock_newer?( jarfile ) + jarfile.exists_lock? && (jarfile.mtime_lock > mtime) + end + def needs_update?(jarfile, gemfile_lock) - (jarfile.exists? || gemfile_lock.exists? || jarfile.exists_lock?) && (!exists? || !jarfile.exists_lock? || (jarfile.exists? && (jarfile.mtime > mtime)) || (jarfile.exists_lock? && (jarfile.mtime_lock > mtime)) || (gemfile_lock.exists? && (gemfile_lock.mtime > mtime))) + if jarfile.exists? || gemfile_lock.exists? || jarfile.exists_lock? + missing?( jarfile ) || jarfile_newer?( jarfile ) || jarlock_newer?( jarfile ) || gemfile_lock.newer?( mtime ) + else + false + end end - def generate( classpath_array, test_array = [], jruby_array = [] ) + def generate( classpath_array, test_array = [], jruby_array = [], local_repo = nil ) FileUtils.mkdir_p(File.dirname(@classpathfile)) File.open(@classpathfile, 'w') do |f| - dump_array( f, jruby_array || [], 'JRUBY_' ) - dump_array( f, test_array || [], 'TEST_' ) - dump_array( f, classpath_array || [], '' ) - f.puts "JBUNDLER_CLASSPATH.each { |c| require c }" + if local_repo + local_repo = File.expand_path( local_repo ) + f.puts "require 'jar_dependencies'" + f.puts "JBUNDLER_LOCAL_REPO = Jars.home" + end + dump_array( f, jruby_array || [], 'JRUBY_', local_repo ) + dump_array( f, test_array || [], 'TEST_', local_repo ) + dump_array( f, classpath_array || [], '', local_repo ) f.close end end private - def dump_array( file, array, prefix ) + def dump_array( file, array, prefix, local_repo ) file.puts "JBUNDLER_#{prefix}CLASSPATH = []" array.each do |path| - file.puts "JBUNDLER_#{prefix}CLASSPATH << '#{path}'" unless path =~ /pom$/ + if local_repo + path.sub!( /#{local_repo}/, '' ) + file.puts "JBUNDLER_#{prefix}CLASSPATH << (JBUNDLER_LOCAL_REPO + '#{path}')" unless path =~ /pom$/ + else + file.puts "JBUNDLER_#{prefix}CLASSPATH << '#{path}'" unless path =~ /pom$/ + end end file.puts "JBUNDLER_#{prefix}CLASSPATH.freeze" end end end