Class: LockJar::Resolver

Inherits:
Object
  • Object
show all
Defined in:
lib/lock_jar/resolver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Resolver

Returns a new instance of Resolver.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/lock_jar/resolver.rb', line 26

def initialize(opts = {})
  @opts = opts
  local_repo = opts[:local_repo] || Naether::Bootstrap.default_local_repo

  # Bootstrap Naether
  Naether::Bootstrap.bootstrap_local_repo(local_repo, opts)

  # Bootstrapping naether will create an instance from downloaded jars.
  # If jars exist locally already, create manually
  @naether = Naether.create
  @naether.local_repo_path = local_repo if local_repo
  @naether.clear_remote_repositories if opts[:offline]
end

Instance Attribute Details

#naetherObject (readonly)

Returns the value of attribute naether.



24
25
26
# File 'lib/lock_jar/resolver.rb', line 24

def naether
  @naether
end

#optsObject (readonly)

Returns the value of attribute opts.



24
25
26
# File 'lib/lock_jar/resolver.rb', line 24

def opts
  @opts
end

Instance Method Details

#add_remote_repository(repo) ⇒ Object



48
49
50
# File 'lib/lock_jar/resolver.rb', line 48

def add_remote_repository(repo)
  @naether.add_remote_repository(repo)
end

#clear_remote_repositoriesObject



44
45
46
# File 'lib/lock_jar/resolver.rb', line 44

def clear_remote_repositories
  @naether.clear_remote_repositories
end

#dependencies_graphObject



58
59
60
# File 'lib/lock_jar/resolver.rb', line 58

def dependencies_graph
  @naether.dependencies_graph
end

#download(dependencies) ⇒ Object



62
63
64
# File 'lib/lock_jar/resolver.rb', line 62

def download(dependencies)
  @naether.download_artifacts(dependencies)
end

#load_to_classpath(artifacts) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/lock_jar/resolver.rb', line 79

def load_to_classpath(artifacts)
  paths = []
  notations = []

  artifacts.each do |art|
    if File.exist?(art)
      paths << art
    else
      notations << art
    end
  end

  paths += @naether.to_local_paths(notations)
  Naether::Java.load_paths(paths)

  paths
end

#remote_repositoriesObject



40
41
42
# File 'lib/lock_jar/resolver.rb', line 40

def remote_repositories
  @naether.remote_repository_urls
end

#resolve(dependencies, download_artifacts = true) ⇒ Object



52
53
54
55
56
# File 'lib/lock_jar/resolver.rb', line 52

def resolve(dependencies, download_artifacts = true)
  @naether.dependencies = dependencies
  @naether.resolve_dependencies(download_artifacts)
  @naether.dependencies_notation
end

#to_local_paths(notations) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/lock_jar/resolver.rb', line 66

def to_local_paths(notations)
  paths = []
  notations.each do |notation|
    if File.exist?(notation)
      paths << notation
    else
      paths += @naether.to_local_paths([notation])
    end
  end

  paths
end