lib/gem2rpm.rb in gem2rpm-0.9.0 vs lib/gem2rpm.rb in gem2rpm-0.9.1
- old
+ new
@@ -5,21 +5,31 @@
require 'gem2rpm/format'
require 'gem2rpm/spec_fetcher'
require 'gem2rpm/specification'
module Gem2Rpm
- Gem2Rpm::VERSION = "0.9.0"
+ Gem2Rpm::VERSION = "0.9.1"
+ class Exception < RuntimeError; end
+ class DownloadUrlError < Exception; end
+
def self.find_download_url(name, version)
dep = Gem::Dependency.new(name, "=#{version}")
fetcher = Gem2Rpm::SpecFetcher.new(Gem::SpecFetcher.fetcher)
- dummy, source = fetcher.spec_for_dependency(dep, false).first.first
- download_path = source.uri
+ spec_and_source, errors = fetcher.spec_for_dependency(dep, false)
- download_path += "gems/" if download_path.to_s != ""
- return download_path
+ raise DownloadUrlError.new(errors.first.error.message) unless errors.empty?
+
+ spec, source = spec_and_source.first
+
+ if source && source.uri
+ download_path = source.uri.to_s
+ download_path += "gems/"
+ end
+
+ download_path
end
def Gem2Rpm.convert(fname, template=TEMPLATE, out=$stdout,
nongem=true, local=false, doc_subpackage = true)
package = Gem2Rpm::Package.new(fname)
@@ -28,12 +38,12 @@
spec.description ||= spec.summary
download_path = ""
unless local
begin
download_path = find_download_url(spec.name, spec.version)
- rescue Gem::Exception => e
+ rescue DownloadUrlError => e
$stderr.puts "Warning: Could not retrieve full URL for #{spec.name}\nWarning: Edit the specfile and enter the full download URL as 'Source0' manually"
- $stderr.puts "#{e.inspect}"
+ $stderr.puts e.inspect
end
end
template = ERB.new(template, 0, '-')
out.puts template.result(binding)
rescue Gem::Exception => e