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,2 @@
1
+ require 'librarian/source/git'
2
+ require 'librarian/source/path'
@@ -0,0 +1,45 @@
1
+ module Librarian
2
+ module Source
3
+ module BasicApi
4
+
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ class << base
8
+ def lock_name(name)
9
+ def_sclass_prop(:lock_name, name)
10
+ end
11
+
12
+ def spec_options(keys)
13
+ def_sclass_prop(:spec_options, keys)
14
+ end
15
+
16
+ private
17
+
18
+ def def_sclass_prop(name, arg)
19
+ sclass = class << self ; self ; end
20
+ sclass.module_exec do
21
+ remove_method(name)
22
+ define_method(name) { arg }
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ module ClassMethods
29
+ def from_lock_options(environment, options)
30
+ new(environment, options[:remote], options.reject{|k, v| k == :remote})
31
+ end
32
+
33
+ def from_spec_args(environment, param, options)
34
+ recognized_options = spec_options
35
+ unrecognized_options = options.keys - recognized_options
36
+ unrecognized_options.empty? or raise Error,
37
+ "unrecognized options: #{unrecognized_options.join(", ")}"
38
+
39
+ new(environment, param, options)
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,134 @@
1
+ require 'fileutils'
2
+ require 'pathname'
3
+ require 'digest'
4
+
5
+ require 'librarian/source/basic_api'
6
+ require 'librarian/source/git/repository'
7
+ require 'librarian/source/local'
8
+
9
+ module Librarian
10
+ module Source
11
+ class Git
12
+ include BasicApi
13
+ include Local
14
+
15
+ lock_name 'GIT'
16
+ spec_options [:ref, :path]
17
+
18
+ DEFAULTS = {
19
+ :ref => 'master'
20
+ }
21
+
22
+ attr_accessor :environment
23
+ private :environment=
24
+
25
+ attr_accessor :uri, :ref, :sha, :path
26
+ private :uri=, :ref=, :sha=, :path=
27
+
28
+ def initialize(environment, uri, options)
29
+ self.environment = environment
30
+ self.uri = uri
31
+ self.ref = options[:ref] || DEFAULTS[:ref]
32
+ self.sha = options[:sha]
33
+ self.path = options[:path]
34
+
35
+ @repository = nil
36
+ @repository_cache_path = nil
37
+
38
+ ref.kind_of?(String) or raise TypeError, "ref must be a String"
39
+ end
40
+
41
+ def to_s
42
+ path ? "#{uri}##{ref}(#{path})" : "#{uri}##{ref}"
43
+ end
44
+
45
+ def ==(other)
46
+ other &&
47
+ self.class == other.class &&
48
+ self.uri == other.uri &&
49
+ self.ref == other.ref &&
50
+ self.path == other.path &&
51
+ (self.sha.nil? || other.sha.nil? || self.sha == other.sha)
52
+ end
53
+
54
+ def to_spec_args
55
+ options = {}
56
+ options.merge!(:ref => ref) if ref != DEFAULTS[:ref]
57
+ options.merge!(:path => path) if path
58
+ [uri, options]
59
+ end
60
+
61
+ def to_lock_options
62
+ options = {:remote => uri, :ref => ref, :sha => sha}
63
+ options.merge!(:path => path) if path
64
+ options
65
+ end
66
+
67
+ def pinned?
68
+ !!sha
69
+ end
70
+
71
+ def unpin!
72
+ @sha = nil
73
+ end
74
+
75
+ def cache!
76
+ repository_cached? and return or repository_cached!
77
+
78
+ unless repository.git?
79
+ repository.path.rmtree if repository.path.exist?
80
+ repository.path.mkpath
81
+ repository.clone!(uri)
82
+ end
83
+ repository.reset_hard!
84
+ repository.clean!
85
+ unless repository.checked_out?(sha)
86
+ remote = repository.default_remote
87
+ repository.fetch!(remote)
88
+ repository.fetch!(remote, :tags => true)
89
+
90
+ self.sha = repository.hash_from(remote, ref) unless sha
91
+ repository.checkout!(sha) unless repository.checked_out?(sha)
92
+
93
+ raise Error, "failed to checkout #{sha}" unless repository.checked_out?(sha)
94
+ end
95
+ end
96
+
97
+ private
98
+
99
+ attr_accessor :repository_cached
100
+ alias repository_cached? repository_cached
101
+
102
+ def repository_cached!
103
+ self.repository_cached = true
104
+ end
105
+
106
+ def repository_cache_path
107
+ @repository_cache_path ||= begin
108
+ environment.cache_path.join("source/git/#{cache_key}")
109
+ end
110
+ end
111
+
112
+ def repository
113
+ @repository ||= begin
114
+ Repository.new(environment, repository_cache_path)
115
+ end
116
+ end
117
+
118
+ def filesystem_path
119
+ @filesystem_path ||= path ? repository.path.join(path) : repository.path
120
+ end
121
+
122
+ def cache_key
123
+ @cache_key ||= begin
124
+ uri_part = uri
125
+ path_part = "/#{path}" if path
126
+ ref_part = "##{ref}"
127
+ key_source = [uri_part, path_part, ref_part].join
128
+ Digest::MD5.hexdigest(key_source)
129
+ end
130
+ end
131
+
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,217 @@
1
+ require 'open3'
2
+
3
+ module Librarian
4
+ module Source
5
+ class Git
6
+ class Repository
7
+
8
+ class << self
9
+ def clone!(environment, path, repository_url)
10
+ path = Pathname.new(path)
11
+ path.mkpath
12
+ git = new(environment, path)
13
+ git.clone!(repository_url)
14
+ git
15
+ end
16
+
17
+ def bin
18
+ @bin ||= which("git") or raise Error, "cannot find git"
19
+ end
20
+
21
+ private
22
+
23
+ # Cross-platform way of finding an executable in the $PATH.
24
+ #
25
+ # which('ruby') #=> /usr/bin/ruby
26
+ #
27
+ # From:
28
+ # https://github.com/defunkt/hub/commit/353031307e704d860826fc756ff0070be5e1b430#L2R173
29
+ def which(cmd)
30
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
31
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
32
+ path = File.expand_path(path)
33
+ exts.each do |ext|
34
+ exe = File.join(path, cmd + ext)
35
+ return exe if File.file?(exe) && File.executable?(exe)
36
+ end
37
+ end
38
+ nil
39
+ end
40
+ end
41
+
42
+ attr_accessor :environment, :path
43
+ private :environment=, :path=
44
+
45
+ def initialize(environment, path)
46
+ self.environment = environment
47
+ self.path = Pathname.new(path)
48
+ end
49
+
50
+ def git?
51
+ path.join('.git').exist?
52
+ end
53
+
54
+ def default_remote
55
+ "origin"
56
+ end
57
+
58
+ def version(options = { })
59
+ version!(options).strip
60
+ end
61
+
62
+ def version!(options = { })
63
+ silent = options.delete(:silent)
64
+
65
+ command = %w(--version)
66
+ run!(command, :silent => silent)
67
+ end
68
+
69
+ def clone!(repository_url)
70
+ command = %W(clone #{repository_url} . --quiet)
71
+ run!(command, :chdir => true)
72
+ end
73
+
74
+ def checkout!(reference, options ={ })
75
+ command = %W(checkout #{reference} --quiet)
76
+ command << "--force" if options[:force]
77
+ run!(command, :chdir => true)
78
+ end
79
+
80
+ def fetch!(remote, options = { })
81
+ command = %W(fetch #{remote} --quiet)
82
+ command << "--tags" if options[:tags]
83
+ run!(command, :chdir => true)
84
+ end
85
+
86
+ def reset_hard!
87
+ command = %W(reset --hard --quiet)
88
+ run!(command, :chdir => true)
89
+ end
90
+
91
+ def clean!
92
+ command = %w(clean -x -d --force --force)
93
+ run!(command, :chdir => true)
94
+ end
95
+
96
+ def checked_out?(sha)
97
+ current_commit_hash == sha
98
+ end
99
+
100
+ def remote_names
101
+ command = %W(remote)
102
+ run!(command, :chdir => true).strip.lines.map(&:strip)
103
+ end
104
+
105
+ def remote_branch_names
106
+ remotes = remote_names.sort_by(&:length).reverse
107
+
108
+ command = %W(branch -r --no-color)
109
+ names = run!(command, :chdir => true).strip.lines.map(&:strip).to_a
110
+ names.each{|n| n.gsub!(/\s*->.*$/, "")}
111
+ names.reject!{|n| n =~ /\/HEAD$/}
112
+ Hash[remotes.map do |r|
113
+ matching_names = names.select{|n| n.start_with?("#{r}/")}
114
+ matching_names.each{|n| names.delete(n)}
115
+ matching_names.each{|n| n.slice!(0, r.size + 1)}
116
+ [r, matching_names]
117
+ end]
118
+ end
119
+
120
+ def hash_from(remote, reference)
121
+ branch_names = remote_branch_names[remote]
122
+ if branch_names.include?(reference)
123
+ reference = "#{remote}/#{reference}"
124
+ end
125
+
126
+ command = %W(rev-list #{reference} -1)
127
+ run!(command, :chdir => true).strip
128
+ end
129
+
130
+ def current_commit_hash
131
+ command = %W(rev-parse HEAD --quiet)
132
+ run!(command, :chdir => true).strip!
133
+ end
134
+
135
+ private
136
+
137
+ def bin
138
+ self.class.bin
139
+ end
140
+
141
+ def run!(args, options = { })
142
+ chdir = options.delete(:chdir)
143
+ chdir = path.to_s if chdir == true
144
+
145
+ silent = options.delete(:silent)
146
+
147
+ command = [bin]
148
+ command.concat(args)
149
+
150
+ maybe_within(chdir) do
151
+ logging_command(command, :silent => silent) do
152
+ run_command_internal(command)
153
+ end
154
+ end
155
+ end
156
+
157
+ def maybe_within(path)
158
+ if path
159
+ Dir.chdir(path) { with_env_var("GIT_DIR", nil) { yield } }
160
+ else
161
+ yield
162
+ end
163
+ end
164
+
165
+ def with_env_var(name, value)
166
+ original_value = ENV[name]
167
+ begin
168
+ ENV[name] = value
169
+ yield
170
+ ensure
171
+ ENV[name] = original_value
172
+ end
173
+ end
174
+
175
+ def logging_command(command, options)
176
+ silent = options.delete(:silent)
177
+
178
+ pwd = Dir.pwd
179
+
180
+ unless silent
181
+ debug { "Running `#{command.join(' ')}` in #{relative_path_to(pwd)}" }
182
+ end
183
+
184
+ out = yield
185
+
186
+ unless silent
187
+ if out.size > 0
188
+ out.lines.each do |line|
189
+ debug { " --> #{line}" }
190
+ end
191
+ else
192
+ debug { " --- No output" }
193
+ end
194
+ end
195
+
196
+ out
197
+ end
198
+
199
+ def run_command_internal(command)
200
+ Open3.popen3(*command) do |i, o, e, t|
201
+ raise StandardError, e.read unless (t ? t.value : $?).success?
202
+ o.read
203
+ end
204
+ end
205
+
206
+ def debug(*args, &block)
207
+ environment.logger.debug(*args, &block)
208
+ end
209
+
210
+ def relative_path_to(path)
211
+ environment.logger.relative_path_to(path)
212
+ end
213
+
214
+ end
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,54 @@
1
+ require 'librarian/support/abstract_method'
2
+
3
+ module Librarian
4
+ module Source
5
+ # Requires that the including source class have methods:
6
+ # #path
7
+ # #environment
8
+ module Local
9
+
10
+ include Support::AbstractMethod
11
+
12
+ abstract_method :path, :fetch_version, :fetch_dependencies
13
+
14
+ def manifests(name)
15
+ manifest = Manifest.new(self, name)
16
+ [manifest].compact
17
+ end
18
+
19
+ def manifest_search_paths(name)
20
+ @manifest_search_paths ||= { }
21
+ @manifest_search_paths[name] ||= begin
22
+ cache!
23
+ paths = [filesystem_path, filesystem_path.join(name)]
24
+ paths.select{|s| s.exist?}
25
+ end
26
+ end
27
+
28
+ def found_path(name)
29
+ @_found_paths ||= { }
30
+ @_found_paths[name] ||= begin
31
+ paths = manifest_search_paths(name)
32
+ paths.find{|p| manifest?(name, p)}
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ abstract_method :manifest? # (name, path) -> boolean
39
+
40
+ def info(*args, &block)
41
+ environment.logger.info(*args, &block)
42
+ end
43
+
44
+ def debug(*args, &block)
45
+ environment.logger.debug(*args, &block)
46
+ end
47
+
48
+ def relative_path_to(path)
49
+ environment.logger.relative_path_to(path)
50
+ end
51
+
52
+ end
53
+ end
54
+ end