Class: Jenkins::Plugin::Tools::Resolver
- Inherits:
-
Object
- Object
- Jenkins::Plugin::Tools::Resolver
- Defined in:
- lib/jenkins/plugin/tools/resolver.rb
Instance Method Summary collapse
-
#fetch(uri, limit = 10) ⇒ Object
download with redirect support.
-
#initialize(spec, dir) ⇒ Resolver
constructor
A new instance of Resolver.
- #resolve(short_name, version) ⇒ Object
- #resolve! ⇒ Object
Constructor Details
#initialize(spec, dir) ⇒ Resolver
Returns a new instance of Resolver.
8 9 10 11 12 |
# File 'lib/jenkins/plugin/tools/resolver.rb', line 8 def initialize(spec, dir) @spec = spec @dir = dir FileUtils.mkdir_p(dir) unless File.directory? @dir end |
Instance Method Details
#fetch(uri, limit = 10) ⇒ Object
download with redirect support
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/jenkins/plugin/tools/resolver.rb', line 46 def fetch(uri, limit = 10) # You should choose better exception. raise ArgumentError, 'HTTP redirect too deep' if limit == 0 http = if ENV['HTTP_PROXY'] || ENV['http_proxy'] proxy_uri = URI.parse(ENV['HTTP_PROXY'] || ENV['http_proxy']) Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password) else Net::HTTP end response = http.get_response(URI.parse(uri)) case response when Net::HTTPSuccess then response when Net::HTTPRedirection then fetch(response['location'], limit - 1) else response.error! end end |
#resolve(short_name, version) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jenkins/plugin/tools/resolver.rb', line 20 def resolve(short_name,version) # this is where we expect the retrieved file to be cache = File. "~/.jenkins/cache/plugins/#{short_name}/#{version}/#{short_name}.hpi" return cache if File.exists?(cache) # now we start looking for places to find them # is it in the local maven2 repository? maven = File. "~/.m2/repository/org/jenkins-ci/plugins/#{short_name}/#{version}/#{short_name}-#{version}.hpi" return maven if File.exists?(maven) # download from the community update center FileUtils.mkdir_p(File.dirname(cache)) open(cache+".tmp","wb") do |f| puts "Downloading #{short_name} #{version}" url = "http://updates.jenkins-ci.org/download/plugins/#{short_name}/#{version}/#{short_name}.hpi?for=ruby-plugin" puts " from #{url}" f.write fetch(url).body end FileUtils.mv cache+".tmp", cache return cache end |
#resolve! ⇒ Object
14 15 16 17 18 |
# File 'lib/jenkins/plugin/tools/resolver.rb', line 14 def resolve! @spec.dependencies.each do |name, version| FileUtils.cp resolve(name, version), @dir end end |