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(config, 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(config, opts = {})
  @config = config || LockJar::Config.new({})
  @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.
  @naether = Naether.create
  @naether.local_repo_path = local_repo if local_repo
  @naether.clear_remote_repositories if opts[:offline]
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#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
51
52
53
# File 'lib/lock_jar/resolver.rb', line 48

def add_remote_repository(repo)
  repo_config = config.repositories[repo] || {}
  username = repo_config['username']
  password = repo_config['password']
  @naether.add_remote_repository(repo, username, password)
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



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

def dependencies_graph
  @naether.dependencies_graph
end

#download(dependencies) ⇒ Object



65
66
67
# File 'lib/lock_jar/resolver.rb', line 65

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

#load_to_classpath(artifacts) ⇒ Object



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

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



55
56
57
58
59
# File 'lib/lock_jar/resolver.rb', line 55

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

#to_local_paths(notations) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/lock_jar/resolver.rb', line 69

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