lib/librarian/puppet/dsl.rb in librarian-puppet-2.0.0 vs lib/librarian/puppet/dsl.rb in librarian-puppet-2.0.1
- old
+ new
@@ -4,10 +4,12 @@
module Librarian
module Puppet
class Dsl < Librarian::Dsl
+ FORGE_URL = "https://forgeapi.puppetlabs.com"
+
dependency :mod
source :forge => Source::Forge
source :git => Source::Git
source :path => Source::Path
@@ -18,11 +20,11 @@
specfile, sources = nil, specfile if specfile.kind_of?(Array) && sources.empty?
if specfile.kind_of?(Pathname) and !File.exists?(specfile)
debug { "Specfile not found, using defaults: #{specfile}" }
specfile = Proc.new do
- forge "https://forgeapi.puppetlabs.com"
+ forge FORGE_URL
metadata
end
end
Target.new(self).tap do |target|
@@ -31,10 +33,14 @@
specfile ||= Proc.new if block_given?
receiver = Receiver.new(target)
receiver.run(specfile)
+ # save the default forge defined
+ default_forge = target.sources.select {|s| s.is_a? Librarian::Puppet::Source::Forge}.first
+ Librarian::Puppet::Source::Forge.default = default_forge || Librarian::Puppet::Source::Forge.from_lock_options(environment, :remote => FORGE_URL)
+
debug_named_source_cache("Post-Cached Sources", target)
end.to_spec
end
class Receiver < Librarian::Dsl::Receiver
@@ -68,10 +74,15 @@
return
else
raise Error, msg
end
end
- dependencyList = JSON.parse(File.read(f))['dependencies']
+ begin
+ json = JSON.parse(File.read(f))
+ rescue JSON::ParserError => e
+ raise Error, "Unable to parse json file #{f}: #{e}"
+ end
+ dependencyList = json['dependencies']
dependencyList.each do |d|
mod(d['name'], d['version_requirement'])
end
end