Class: PomPomPom::Resolver::JarDownloader

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

Instance Method Summary collapse

Constructor Details

#initialize(pom, local_path, repositories, downloader, logger) ⇒ JarDownloader

Returns a new instance of JarDownloader.



154
155
156
# File 'lib/pompompom/resolver.rb', line 154

def initialize(pom, local_path, repositories, downloader, logger)
  @pom, @local_path, @repositories, @downloader, @logger = pom, local_path, repositories, downloader, logger
end

Instance Method Details

#download!Object

Raises:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/pompompom/resolver.rb', line 158

def download!
  data = nil
  @repositories.detect do |repository|
    url = @pom.jar_url(repository)
    @logger.debug(%(Loading JAR from "#{url}"))
    begin
      data = @downloader.get(url)
    rescue => e
      @logger.debug(%(Could not download "#{url}": #{e.message}))
    end
    data
  end
  raise JarNotFoundError, "Could not download JAR for #{@pom.to_dependency} in any repository" unless data
  File.open(@local_path, 'w') { |f| f.write(data) }
end