Class: JBundler::ClasspathFile

Inherits:
Object
  • Object
show all
Defined in:
lib/jbundler/classpath_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(classpathfile = '.jbundler/classpath.rb') ⇒ ClasspathFile

Returns a new instance of ClasspathFile.



25
26
27
# File 'lib/jbundler/classpath_file.rb', line 25

def initialize(classpathfile = '.jbundler/classpath.rb')
  @classpathfile = classpathfile
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/jbundler/classpath_file.rb', line 51

def exists?
  File.exists?(@classpathfile)
end

#fileObject



29
30
31
# File 'lib/jbundler/classpath_file.rb', line 29

def file
  @classpathfile
end

#generate(classpath_array, test_array = [], jruby_array = [], local_repo = nil) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/jbundler/classpath_file.rb', line 75

def generate( classpath_array, test_array = [], jruby_array = [], local_repo = nil )
  FileUtils.mkdir_p(File.dirname(@classpathfile))
  File.open(@classpathfile, 'w') do |f|
    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

#jarfile_newer?(jarfile) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/jbundler/classpath_file.rb', line 59

def jarfile_newer?( jarfile )
  jarfile.exists? && (jarfile.mtime > mtime)
end

#jarlock_newer?(jarfile) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/jbundler/classpath_file.rb', line 63

def jarlock_newer?( jarfile )
  jarfile.exists_lock? && (jarfile.mtime_lock > mtime)
end

#load_classpathObject



33
34
35
# File 'lib/jbundler/classpath_file.rb', line 33

def load_classpath
  load File.expand_path @classpathfile
end

#missing?(jarfile) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/jbundler/classpath_file.rb', line 55

def missing?( jarfile )
  !exists? || !jarfile.exists_lock?
end

#mtimeObject



47
48
49
# File 'lib/jbundler/classpath_file.rb', line 47

def mtime
  File.mtime(@classpathfile)
end

#needs_update?(jarfile, gemfile_lock) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
71
72
73
# File 'lib/jbundler/classpath_file.rb', line 67

def needs_update?(jarfile, gemfile_lock)
  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

#require_classpathObject



37
38
39
40
# File 'lib/jbundler/classpath_file.rb', line 37

def require_classpath
  load_classpath
  JBUNDLER_CLASSPATH.each { |c| require c }
end

#require_test_classpathObject



42
43
44
45
# File 'lib/jbundler/classpath_file.rb', line 42

def require_test_classpath
  load_classpath
  JBUNDLER_TEST_CLASSPATH.each { |c| require c }
end