Class: BuildrDependencyExtensions::DependencyCaching

Inherits:
Object
  • Object
show all
Defined in:
lib/buildr-dependency-extensions/dependency_caching.rb

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ DependencyCaching

Returns a new instance of DependencyCaching.



5
6
7
# File 'lib/buildr-dependency-extensions/dependency_caching.rb', line 5

def initialize project
  @project = project
end

Instance Method Details

#read_cacheObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/buildr-dependency-extensions/dependency_caching.rb', line 30

def read_cache
  begin
    dependency_caching_filename = @project.path_to('dependency.cache')
    dependdencies_cache = YAML.load_file(dependency_caching_filename)

    runtime_dependencies = dependdencies_cache['runtime']
    compile_dependencies = dependdencies_cache['compile']
    test_dependencies = dependdencies_cache['test']

    dependdencies_cache['runtime'] = runtime_dependencies.map {|dep| @project.artifact(dep)}
    dependdencies_cache['compile'] = compile_dependencies.map {|dep| @project.artifact(dep)}
    dependdencies_cache['test']    = test_dependencies.map {|dep| @project.artifact(dep)}
    dependdencies_cache
  rescue Errno::ENOENT
    nil
  end
end

#write_cacheObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/buildr-dependency-extensions/dependency_caching.rb', line 9

def write_cache
  dependencies_cache = {}
  dependencies_cache['runtime'] = @project.run.classpath.
    select {|dep| HelperFunctions.is_artifact?(dep)}.
    map    {|dep| dep.to_spec}

  dependencies_cache['compile'] = @project.compile.dependencies.to_a.
    select {|dep| HelperFunctions.is_artifact?(dep)}.
    map    {|dep| dep.to_spec}

  dependencies_cache['test'] = @project.test.dependencies.to_a.
    select {|dep| HelperFunctions.is_artifact?(dep)}.
    map    {|dep| dep.to_spec}

  dependency_caching_filename = @project.path_to('dependency.cache')
  FileUtils.mkdir_p(File.dirname(dependency_caching_filename))
  f = File.new(dependency_caching_filename, 'w')
  f.write(dependencies_cache.to_yaml)
  f.close
end