librarian-puppet-lmco 0.9.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE +20 -0
  4. data/README.md +187 -0
  5. data/bin/librarian-puppet +9 -0
  6. data/lib/librarian/puppet.rb +22 -0
  7. data/lib/librarian/puppet/cli.rb +85 -0
  8. data/lib/librarian/puppet/dsl.rb +16 -0
  9. data/lib/librarian/puppet/environment.rb +54 -0
  10. data/lib/librarian/puppet/extension.rb +47 -0
  11. data/lib/librarian/puppet/lockfile/parser.rb +53 -0
  12. data/lib/librarian/puppet/source.rb +4 -0
  13. data/lib/librarian/puppet/source/forge.rb +348 -0
  14. data/lib/librarian/puppet/source/git.rb +121 -0
  15. data/lib/librarian/puppet/source/githubtarball.rb +249 -0
  16. data/lib/librarian/puppet/source/local.rb +57 -0
  17. data/lib/librarian/puppet/source/path.rb +12 -0
  18. data/lib/librarian/puppet/templates/Puppetfile +10 -0
  19. data/lib/librarian/puppet/version.rb +5 -0
  20. data/vendor/librarian/CHANGELOG.md +224 -0
  21. data/vendor/librarian/Gemfile +6 -0
  22. data/vendor/librarian/MIT-LICENSE +20 -0
  23. data/vendor/librarian/README.md +401 -0
  24. data/vendor/librarian/Rakefile +34 -0
  25. data/vendor/librarian/bin/librarian-chef +7 -0
  26. data/vendor/librarian/bin/librarian-mock +7 -0
  27. data/vendor/librarian/config/cucumber.yaml +1 -0
  28. data/vendor/librarian/features/chef/cli/init.feature +11 -0
  29. data/vendor/librarian/features/chef/cli/install.feature +64 -0
  30. data/vendor/librarian/features/chef/cli/show.feature +77 -0
  31. data/vendor/librarian/features/chef/cli/version.feature +11 -0
  32. data/vendor/librarian/features/support/env.rb +9 -0
  33. data/vendor/librarian/lib/librarian.rb +11 -0
  34. data/vendor/librarian/lib/librarian/action.rb +5 -0
  35. data/vendor/librarian/lib/librarian/action/base.rb +24 -0
  36. data/vendor/librarian/lib/librarian/action/clean.rb +44 -0
  37. data/vendor/librarian/lib/librarian/action/ensure.rb +24 -0
  38. data/vendor/librarian/lib/librarian/action/install.rb +95 -0
  39. data/vendor/librarian/lib/librarian/action/persist_resolution_mixin.rb +51 -0
  40. data/vendor/librarian/lib/librarian/action/resolve.rb +46 -0
  41. data/vendor/librarian/lib/librarian/action/update.rb +44 -0
  42. data/vendor/librarian/lib/librarian/chef.rb +1 -0
  43. data/vendor/librarian/lib/librarian/chef/cli.rb +47 -0
  44. data/vendor/librarian/lib/librarian/chef/dsl.rb +16 -0
  45. data/vendor/librarian/lib/librarian/chef/environment.rb +27 -0
  46. data/vendor/librarian/lib/librarian/chef/extension.rb +9 -0
  47. data/vendor/librarian/lib/librarian/chef/integration/knife.rb +46 -0
  48. data/vendor/librarian/lib/librarian/chef/manifest_reader.rb +59 -0
  49. data/vendor/librarian/lib/librarian/chef/source.rb +4 -0
  50. data/vendor/librarian/lib/librarian/chef/source/git.rb +25 -0
  51. data/vendor/librarian/lib/librarian/chef/source/github.rb +27 -0
  52. data/vendor/librarian/lib/librarian/chef/source/local.rb +69 -0
  53. data/vendor/librarian/lib/librarian/chef/source/path.rb +12 -0
  54. data/vendor/librarian/lib/librarian/chef/source/site.rb +442 -0
  55. data/vendor/librarian/lib/librarian/chef/templates/Cheffile +15 -0
  56. data/vendor/librarian/lib/librarian/cli.rb +223 -0
  57. data/vendor/librarian/lib/librarian/cli/manifest_presenter.rb +93 -0
  58. data/vendor/librarian/lib/librarian/config.rb +7 -0
  59. data/vendor/librarian/lib/librarian/config/database.rb +205 -0
  60. data/vendor/librarian/lib/librarian/config/file_source.rb +47 -0
  61. data/vendor/librarian/lib/librarian/config/hash_source.rb +33 -0
  62. data/vendor/librarian/lib/librarian/config/source.rb +149 -0
  63. data/vendor/librarian/lib/librarian/dependency.rb +147 -0
  64. data/vendor/librarian/lib/librarian/dsl.rb +108 -0
  65. data/vendor/librarian/lib/librarian/dsl/receiver.rb +46 -0
  66. data/vendor/librarian/lib/librarian/dsl/target.rb +171 -0
  67. data/vendor/librarian/lib/librarian/environment.rb +182 -0
  68. data/vendor/librarian/lib/librarian/error.rb +4 -0
  69. data/vendor/librarian/lib/librarian/helpers.rb +13 -0
  70. data/vendor/librarian/lib/librarian/linter/source_linter.rb +55 -0
  71. data/vendor/librarian/lib/librarian/lockfile.rb +29 -0
  72. data/vendor/librarian/lib/librarian/lockfile/compiler.rb +66 -0
  73. data/vendor/librarian/lib/librarian/lockfile/parser.rb +123 -0
  74. data/vendor/librarian/lib/librarian/logger.rb +46 -0
  75. data/vendor/librarian/lib/librarian/manifest.rb +140 -0
  76. data/vendor/librarian/lib/librarian/manifest_set.rb +151 -0
  77. data/vendor/librarian/lib/librarian/mock.rb +1 -0
  78. data/vendor/librarian/lib/librarian/mock/cli.rb +19 -0
  79. data/vendor/librarian/lib/librarian/mock/dsl.rb +15 -0
  80. data/vendor/librarian/lib/librarian/mock/environment.rb +24 -0
  81. data/vendor/librarian/lib/librarian/mock/extension.rb +9 -0
  82. data/vendor/librarian/lib/librarian/mock/source.rb +1 -0
  83. data/vendor/librarian/lib/librarian/mock/source/mock.rb +80 -0
  84. data/vendor/librarian/lib/librarian/mock/source/mock/registry.rb +83 -0
  85. data/vendor/librarian/lib/librarian/resolution.rb +46 -0
  86. data/vendor/librarian/lib/librarian/resolver.rb +81 -0
  87. data/vendor/librarian/lib/librarian/resolver/implementation.rb +223 -0
  88. data/vendor/librarian/lib/librarian/source.rb +2 -0
  89. data/vendor/librarian/lib/librarian/source/basic_api.rb +45 -0
  90. data/vendor/librarian/lib/librarian/source/git.rb +134 -0
  91. data/vendor/librarian/lib/librarian/source/git/repository.rb +217 -0
  92. data/vendor/librarian/lib/librarian/source/local.rb +54 -0
  93. data/vendor/librarian/lib/librarian/source/path.rb +56 -0
  94. data/vendor/librarian/lib/librarian/spec.rb +13 -0
  95. data/vendor/librarian/lib/librarian/spec_change_set.rb +173 -0
  96. data/vendor/librarian/lib/librarian/specfile.rb +17 -0
  97. data/vendor/librarian/lib/librarian/support/abstract_method.rb +21 -0
  98. data/vendor/librarian/lib/librarian/ui.rb +64 -0
  99. data/vendor/librarian/lib/librarian/version.rb +3 -0
  100. data/vendor/librarian/librarian.gemspec +35 -0
  101. data/vendor/librarian/spec/functional/chef/cli_spec.rb +194 -0
  102. data/vendor/librarian/spec/functional/chef/source/git_spec.rb +432 -0
  103. data/vendor/librarian/spec/functional/chef/source/site_spec.rb +266 -0
  104. data/vendor/librarian/spec/functional/source/git/repository_spec.rb +150 -0
  105. data/vendor/librarian/spec/integration/chef/source/git_spec.rb +441 -0
  106. data/vendor/librarian/spec/integration/chef/source/site_spec.rb +217 -0
  107. data/vendor/librarian/spec/support/cli_macro.rb +114 -0
  108. data/vendor/librarian/spec/support/method_patch_macro.rb +30 -0
  109. data/vendor/librarian/spec/support/with_env_macro.rb +20 -0
  110. data/vendor/librarian/spec/unit/action/base_spec.rb +18 -0
  111. data/vendor/librarian/spec/unit/action/clean_spec.rb +102 -0
  112. data/vendor/librarian/spec/unit/action/ensure_spec.rb +37 -0
  113. data/vendor/librarian/spec/unit/action/install_spec.rb +111 -0
  114. data/vendor/librarian/spec/unit/config/database_spec.rb +327 -0
  115. data/vendor/librarian/spec/unit/dependency_spec.rb +212 -0
  116. data/vendor/librarian/spec/unit/dsl_spec.rb +173 -0
  117. data/vendor/librarian/spec/unit/environment_spec.rb +173 -0
  118. data/vendor/librarian/spec/unit/lockfile/parser_spec.rb +162 -0
  119. data/vendor/librarian/spec/unit/lockfile_spec.rb +65 -0
  120. data/vendor/librarian/spec/unit/manifest_set_spec.rb +202 -0
  121. data/vendor/librarian/spec/unit/manifest_spec.rb +36 -0
  122. data/vendor/librarian/spec/unit/mock/source/mock_spec.rb +22 -0
  123. data/vendor/librarian/spec/unit/resolver_spec.rb +233 -0
  124. data/vendor/librarian/spec/unit/source/git_spec.rb +29 -0
  125. data/vendor/librarian/spec/unit/spec_change_set_spec.rb +169 -0
  126. metadata +220 -0
@@ -0,0 +1,53 @@
1
+ require 'librarian/manifest'
2
+ require 'librarian/dependency'
3
+ require 'librarian/manifest_set'
4
+
5
+ module Librarian
6
+ class Lockfile
7
+ class Parser
8
+
9
+ def parse(string)
10
+ string = string.dup
11
+ source_type_names_map = Hash[dsl_class.source_types.map{|t| [t[1].lock_name, t[1]]}]
12
+ source_type_names = dsl_class.source_types.map{|t| t[1].lock_name}
13
+ lines = string.split(/(\r|\n|\r\n)+/).select{|l| l =~ /\S/}
14
+ sources = []
15
+ while source_type_names.include?(lines.first)
16
+ source = {}
17
+ source_type_name = lines.shift
18
+ source[:type] = source_type_names_map[source_type_name]
19
+ options = {}
20
+ while lines.first =~ /^ {2}([\w\-\/]+):\s+(.+)$/
21
+ lines.shift
22
+ options[$1.to_sym] = $2
23
+ end
24
+ source[:options] = options
25
+ lines.shift # specs
26
+ manifests = {}
27
+ while lines.first =~ /^ {4}([\w\-\/]+) \((.*)\)$/ # This change allows forward slash
28
+ lines.shift
29
+ name = $1
30
+ manifests[name] = {:version => $2, :dependencies => {}}
31
+ while lines.first =~ /^ {6}([\w\-\/]+) \((.*)\)$/
32
+ lines.shift
33
+ manifests[name][:dependencies][$1] = $2.split(/,\s*/)
34
+ end
35
+ end
36
+ source[:manifests] = manifests
37
+ sources << source
38
+ end
39
+ manifests = compile(sources)
40
+ manifests_index = Hash[manifests.map{|m| [m.name, m]}]
41
+ raise StandardError, "Expected DEPENDENCIES topic!" unless lines.shift == "DEPENDENCIES"
42
+ dependencies = []
43
+ while lines.first =~ /^ {2}([\w\-\/]+)(?: \((.*)\))?$/ # This change allows forward slash
44
+ lines.shift
45
+ name, requirement = $1, $2.split(/,\s*/)
46
+ dependencies << Dependency.new(name, requirement, manifests_index[name].source)
47
+ end
48
+ Resolution.new(dependencies, manifests)
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,4 @@
1
+ require 'librarian/puppet/source/path'
2
+ require 'librarian/puppet/source/git'
3
+ require 'librarian/puppet/source/forge'
4
+ require 'librarian/puppet/source/githubtarball'
@@ -0,0 +1,348 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ module Librarian
6
+ module Puppet
7
+ module Source
8
+ class Forge
9
+ class Repo
10
+
11
+ attr_accessor :source, :name
12
+ private :source=, :name=
13
+
14
+ def initialize(source, name)
15
+ self.source = source
16
+ self.name = name
17
+ end
18
+
19
+ def versions
20
+ data = api_call("#{name}.json")
21
+ if data.nil?
22
+ raise Error, "Unable to find module '#{name}' on #{source}"
23
+ end
24
+
25
+ versions = data['releases'].map { |r| r['version'] }.sort.reverse
26
+ versions.select { |v| ! Gem::Version.correct? v }.each { |v| debug { "Ignoring invalid version '#{v}' for module #{name}" } }
27
+ versions.select { |v| Gem::Version.correct? v }
28
+ end
29
+
30
+ def dependencies(version)
31
+ data = api_call("api/v1/releases.json?module=#{name}&version=#{version}")
32
+ data[name].first['dependencies']
33
+ end
34
+
35
+ def manifests
36
+ versions.map do |version|
37
+ Manifest.new(source, name, version)
38
+ end
39
+ end
40
+
41
+ def install_version!(version, install_path)
42
+ if environment.local? && !vendored?(name, version)
43
+ raise Error, "Could not find a local copy of #{name} at #{version}."
44
+ end
45
+
46
+ if environment.vendor?
47
+ vendor_cache(name, version) unless vendored?(name, version)
48
+ end
49
+
50
+ cache_version_unpacked! version
51
+
52
+ if install_path.exist?
53
+ install_path.rmtree
54
+ end
55
+
56
+ unpacked_path = version_unpacked_cache_path(version).join(name.split('/').last)
57
+
58
+ unless unpacked_path.exist?
59
+ raise Error, "#{unpacked_path} does not exist, something went wrong. Try removing it manually"
60
+ else
61
+ FileUtils.cp_r(unpacked_path, install_path)
62
+ end
63
+
64
+ end
65
+
66
+ def environment
67
+ source.environment
68
+ end
69
+
70
+ def cache_path
71
+ @cache_path ||= source.cache_path.join(name)
72
+ end
73
+
74
+ def version_unpacked_cache_path(version)
75
+ cache_path.join('version').join(hexdigest(version.to_s))
76
+ end
77
+
78
+ def hexdigest(value)
79
+ Digest::MD5.hexdigest(value)
80
+ end
81
+
82
+ def cache_version_unpacked!(version)
83
+ path = version_unpacked_cache_path(version)
84
+ return if path.directory?
85
+
86
+ # The puppet module command is only available from puppet versions >= 2.7.13
87
+ #
88
+ # Specifying the version in the gemspec would force people to upgrade puppet while it's still usable for git
89
+ # So we do some more clever checking
90
+ #
91
+ # Executing older versions or via puppet-module tool gives an exit status = 0 .
92
+ #
93
+ check_puppet_module_options
94
+
95
+ path.mkpath
96
+
97
+ target = vendored?(name, version) ? vendored_path(name, version) : name
98
+
99
+
100
+ command = "puppet module install --version #{version} --target-dir '#{path}' --modulepath '#{path}' --ignore-dependencies '#{target}'"
101
+ output = `#{command}`
102
+
103
+ # Check for bad exit code
104
+ unless $? == 0
105
+ # Rollback the directory if the puppet module had an error
106
+ path.unlink
107
+ raise Error, "Error executing puppet module install:\n#{command}\nError:\n#{output}"
108
+ end
109
+ end
110
+
111
+ def check_puppet_module_options
112
+ min_version = Gem::Version.create('2.7.13')
113
+ puppet_version = Gem::Version.create(`puppet --version`.split(' ').first.strip.gsub('-', '.'))
114
+
115
+ if puppet_version < min_version
116
+ raise Error, "To get modules from the forge, we use the puppet faces module command. For this you need at least puppet version 2.7.13 and you have #{puppet_version}"
117
+ end
118
+ end
119
+
120
+ def vendored?(name, version)
121
+ vendored_path(name, version).exist?
122
+ end
123
+
124
+ def vendored_path(name, version)
125
+ environment.vendor_cache.join("#{name.sub("/", "-")}-#{version}.tar.gz")
126
+ end
127
+
128
+ def vendor_cache(name, version)
129
+ File.open(vendored_path(name, version).to_s, 'w') do |f|
130
+ download(name, version) do |data|
131
+ f << data
132
+ end
133
+ end
134
+ end
135
+
136
+ def download(name, version, &block)
137
+ data = api_call("api/v1/releases.json?module=#{name}&version=#{version}")
138
+
139
+ info = data[name].detect {|h| h['version'] == version.to_s }
140
+
141
+ stream(info['file'], &block)
142
+ end
143
+
144
+ def stream(file, &block)
145
+ #Net::HTTP.get_response(URI.parse("#{source}#{file}")) do |res|
146
+ http_get(URI.parse("#{source}#{file}")) do |res|
147
+ res.code
148
+
149
+ res.read_body(&block)
150
+ end
151
+ end
152
+
153
+ def debug(*args, &block)
154
+ environment.logger.debug(*args, &block)
155
+ end
156
+
157
+ private
158
+
159
+ def http(uri)
160
+ environment.net_http_class(uri.host).new(uri.host, uri.port)
161
+ end
162
+
163
+ def http_get(uri)
164
+ max_redirects = 10
165
+ redirects = []
166
+
167
+ loop do
168
+
169
+ debug { "Performing http-get for #{uri}" }
170
+ debug { " uri.path = #{uri.path}"}
171
+ debug { " uri.host = #{uri.host}"}
172
+ debug { " uri.port = #{uri.port}"}
173
+ debug { " uri.request_uri = #{uri.request_uri}"}
174
+
175
+ http = http(uri)
176
+
177
+ if http.proxy?()
178
+ debug {" proxy_address = #{http.proxy_address()}" }
179
+ debug {" proxy_port = #{http.proxy_port()}" }
180
+ end
181
+
182
+ request = Net::HTTP::Get.new(uri.request_uri)
183
+ response = http.start{|http| http.request(request)}
184
+
185
+ case response
186
+ when Net::HTTPSuccess
187
+ debug { "Responded with success" }
188
+ return response
189
+ when Net::HTTPRedirection
190
+ location = response["Location"]
191
+ debug { "Responded with redirect to #{uri}" }
192
+ redirects.size > max_redirects and raise Error,
193
+ "Could not get #{uri} because too many redirects!"
194
+ redirects.include?(location) and raise Error,
195
+ "Could not get #{uri} because redirect cycle!"
196
+ redirects << location
197
+ uri = URI.parse(location)
198
+ # continue the loop
199
+ else
200
+ raise Error, "Could not get #{uri} because #{response.code} #{response.message}!"
201
+ end
202
+ end
203
+ end
204
+
205
+ def api_call(path)
206
+ base_url = source.uri
207
+ #resp = Net::HTTP.get_response(URI.parse("#{base_url}/#{path}"))
208
+ resp = http_get(URI.parse("#{base_url}/#{path}"))
209
+ if resp.code.to_i != 200
210
+ nil
211
+ else
212
+ data = resp.body
213
+ JSON.parse(data)
214
+ end
215
+ end
216
+ end
217
+
218
+ class << self
219
+ LOCK_NAME = 'FORGE'
220
+
221
+ def lock_name
222
+ LOCK_NAME
223
+ end
224
+
225
+ def from_lock_options(environment, options)
226
+ new(environment, options[:remote], options.reject { |k, v| k == :remote })
227
+ end
228
+
229
+ def from_spec_args(environment, uri, options)
230
+ recognised_options = []
231
+ unrecognised_options = options.keys - recognised_options
232
+ unless unrecognised_options.empty?
233
+ raise Error, "unrecognised options: #{unrecognised_options.join(", ")}"
234
+ end
235
+
236
+ new(environment, uri, options)
237
+ end
238
+ end
239
+
240
+ attr_accessor :environment
241
+ private :environment=
242
+ attr_reader :uri
243
+
244
+ def initialize(environment, uri, options = {})
245
+ self.environment = environment
246
+ @uri = uri
247
+ @cache_path = nil
248
+ end
249
+
250
+ def to_s
251
+ uri
252
+ end
253
+
254
+ def ==(other)
255
+ other &&
256
+ self.class == other.class &&
257
+ self.uri == other.uri
258
+ end
259
+ alias eql? ==
260
+
261
+ def hash
262
+ self.uri.hash
263
+ end
264
+
265
+ alias :eql? :==
266
+
267
+ def hash
268
+ self.to_s.hash
269
+ end
270
+
271
+ def to_spec_args
272
+ [uri, {}]
273
+ end
274
+
275
+ def to_lock_options
276
+ {:remote => uri}
277
+ end
278
+
279
+ def pinned?
280
+ false
281
+ end
282
+
283
+ def unpin!
284
+ end
285
+
286
+ def install!(manifest)
287
+ manifest.source == self or raise ArgumentError
288
+
289
+ name = manifest.name
290
+ version = manifest.version
291
+ install_path = install_path(name)
292
+ repo = repo(name)
293
+
294
+ repo.install_version! version, install_path
295
+ end
296
+
297
+ def manifest(name, version, dependencies)
298
+ manifest = Manifest.new(self, name)
299
+ manifest.version = version
300
+ manifest.dependencies = dependencies
301
+ manifest
302
+ end
303
+
304
+ def cache_path
305
+ @cache_path ||= begin
306
+ dir = Digest::MD5.hexdigest(uri)
307
+ environment.cache_path.join("source/puppet/forge/#{dir}")
308
+ end
309
+ end
310
+
311
+ def install_path(name)
312
+ environment.install_path.join(name.split('/').last)
313
+ end
314
+
315
+ def fetch_version(name, version_uri)
316
+ versions = repo(name).versions
317
+ if versions.include? version_uri
318
+ version_uri
319
+ else
320
+ versions.first
321
+ end
322
+ end
323
+
324
+ def fetch_dependencies(name, version, version_uri)
325
+ environment.logger.debug { " Fetching dependencies for #{name} #{version}" }
326
+ repo(name).dependencies(version).map do |k, v|
327
+ begin
328
+ Dependency.new(k, v, nil)
329
+ rescue ArgumentError => e
330
+ raise Error, "Error fetching dependency for #{name} [#{version}]: #{k} [#{v}]: #{e}"
331
+ end
332
+ end
333
+ end
334
+
335
+ def manifests(name)
336
+ repo(name).manifests
337
+ end
338
+
339
+ private
340
+
341
+ def repo(name)
342
+ @repo ||= {}
343
+ @repo[name] ||= Repo.new(self, name)
344
+ end
345
+ end
346
+ end
347
+ end
348
+ end
@@ -0,0 +1,121 @@
1
+ require 'librarian/source/git'
2
+ require 'librarian/puppet/source/local'
3
+
4
+ module Librarian
5
+ module Source
6
+ class Git
7
+ class Repository
8
+ def hash_from(remote, reference)
9
+ branch_names = remote_branch_names[remote]
10
+ if branch_names.include?(reference)
11
+ reference = "#{remote}/#{reference}"
12
+ end
13
+
14
+ command = %W(rev-parse #{reference}^{commit} --quiet)
15
+ run!(command, :chdir => true).strip
16
+ end
17
+
18
+ # Naming this method 'version' causes an exception to be raised.
19
+ def module_version
20
+ return '0.0.1' unless modulefile?
21
+
22
+ metadata = ::Puppet::ModuleTool::Metadata.new
23
+ ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
24
+
25
+ metadata.version
26
+ end
27
+
28
+ def dependencies
29
+ return {} unless modulefile?
30
+
31
+ metadata = ::Puppet::ModuleTool::Metadata.new
32
+
33
+ ::Puppet::ModuleTool::ModulefileReader.evaluate(metadata, modulefile)
34
+
35
+ metadata.dependencies.inject({}) do |h, dependency|
36
+ name = dependency.instance_variable_get(:@full_module_name)
37
+ version = dependency.instance_variable_get(:@version_requirement)
38
+ h.update(name => version)
39
+ end
40
+ end
41
+
42
+ def modulefile
43
+ File.join(path, 'Modulefile')
44
+ end
45
+
46
+ def modulefile?
47
+ File.exists?(modulefile)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ module Puppet
54
+ module Source
55
+ class Git < Librarian::Source::Git
56
+ include Local
57
+
58
+ def cache!
59
+ return vendor_checkout! if vendor_cached?
60
+
61
+ if environment.local?
62
+ raise Error, "Could not find a local copy of #{uri} at #{sha}."
63
+ end
64
+
65
+ super
66
+
67
+ cache_in_vendor(repository.path) if environment.vendor?
68
+ end
69
+
70
+ def vendor_tgz
71
+ environment.vendor_source + "#{sha}.tar.gz"
72
+ end
73
+
74
+ def vendor_cached?
75
+ vendor_tgz.exist?
76
+ end
77
+
78
+ def vendor_checkout!
79
+ repository.path.rmtree if repository.path.exist?
80
+ repository.path.mkpath
81
+
82
+ Dir.chdir(repository.path.to_s) do
83
+ %x{tar xzf #{vendor_tgz}}
84
+ end
85
+
86
+ repository_cached!
87
+ end
88
+
89
+ def cache_in_vendor(tmp_path)
90
+ Dir.chdir(tmp_path.to_s) do
91
+ %x{git archive #{sha} | gzip > #{vendor_tgz}}
92
+ end
93
+ end
94
+
95
+ def fetch_version(name, extra)
96
+ cache!
97
+ found_path = found_path(name)
98
+ v = repository.module_version
99
+ v = v.gsub("-",".") # fix for some invalid versions like 1.0.0-rc1
100
+
101
+ # if still not valid, use some default version
102
+ unless Gem::Version.correct? v
103
+ debug { "Ignoring invalid version '#{v}' for module #{name}, using 0.0.1" }
104
+ v = '0.0.1'
105
+ end
106
+ end
107
+
108
+ def fetch_dependencies(name, version, extra)
109
+ repository.dependencies.map do |k, v|
110
+ Dependency.new(k, v, forge_source)
111
+ end
112
+ end
113
+
114
+ def forge_source
115
+ Forge.from_lock_options(environment, :remote=>"http://forge.puppetlabs.com")
116
+ end
117
+
118
+ end
119
+ end
120
+ end
121
+ end