librarian-puppet-maestrodev 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/.gitignore +3 -0
  2. data/LICENSE +20 -0
  3. data/README.md +187 -0
  4. data/bin/librarian-puppet +9 -0
  5. data/lib/librarian/puppet.rb +13 -0
  6. data/lib/librarian/puppet/cli.rb +85 -0
  7. data/lib/librarian/puppet/dsl.rb +16 -0
  8. data/lib/librarian/puppet/environment.rb +54 -0
  9. data/lib/librarian/puppet/extension.rb +41 -0
  10. data/lib/librarian/puppet/lockfile/parser.rb +53 -0
  11. data/lib/librarian/puppet/source.rb +4 -0
  12. data/lib/librarian/puppet/source/forge.rb +279 -0
  13. data/lib/librarian/puppet/source/git.rb +114 -0
  14. data/lib/librarian/puppet/source/githubtarball.rb +234 -0
  15. data/lib/librarian/puppet/source/local.rb +57 -0
  16. data/lib/librarian/puppet/source/path.rb +12 -0
  17. data/lib/librarian/puppet/templates/Puppetfile +10 -0
  18. data/lib/librarian/puppet/version.rb +5 -0
  19. data/vendor/librarian/CHANGELOG.md +185 -0
  20. data/vendor/librarian/Gemfile +6 -0
  21. data/vendor/librarian/MIT-LICENSE +20 -0
  22. data/vendor/librarian/README.md +403 -0
  23. data/vendor/librarian/Rakefile +34 -0
  24. data/vendor/librarian/bin/librarian-chef +7 -0
  25. data/vendor/librarian/bin/librarian-mock +7 -0
  26. data/vendor/librarian/config/cucumber.yaml +1 -0
  27. data/vendor/librarian/features/chef/cli/init.feature +11 -0
  28. data/vendor/librarian/features/chef/cli/install.feature +64 -0
  29. data/vendor/librarian/features/chef/cli/show.feature +77 -0
  30. data/vendor/librarian/features/chef/cli/version.feature +11 -0
  31. data/vendor/librarian/features/support/env.rb +9 -0
  32. data/vendor/librarian/lib/librarian.rb +19 -0
  33. data/vendor/librarian/lib/librarian/action.rb +5 -0
  34. data/vendor/librarian/lib/librarian/action/base.rb +24 -0
  35. data/vendor/librarian/lib/librarian/action/clean.rb +44 -0
  36. data/vendor/librarian/lib/librarian/action/ensure.rb +24 -0
  37. data/vendor/librarian/lib/librarian/action/install.rb +99 -0
  38. data/vendor/librarian/lib/librarian/action/resolve.rb +81 -0
  39. data/vendor/librarian/lib/librarian/action/update.rb +78 -0
  40. data/vendor/librarian/lib/librarian/chef.rb +1 -0
  41. data/vendor/librarian/lib/librarian/chef/cli.rb +48 -0
  42. data/vendor/librarian/lib/librarian/chef/dsl.rb +15 -0
  43. data/vendor/librarian/lib/librarian/chef/environment.rb +27 -0
  44. data/vendor/librarian/lib/librarian/chef/extension.rb +9 -0
  45. data/vendor/librarian/lib/librarian/chef/integration/knife.rb +42 -0
  46. data/vendor/librarian/lib/librarian/chef/manifest_reader.rb +59 -0
  47. data/vendor/librarian/lib/librarian/chef/source.rb +3 -0
  48. data/vendor/librarian/lib/librarian/chef/source/git.rb +25 -0
  49. data/vendor/librarian/lib/librarian/chef/source/local.rb +69 -0
  50. data/vendor/librarian/lib/librarian/chef/source/path.rb +12 -0
  51. data/vendor/librarian/lib/librarian/chef/source/site.rb +446 -0
  52. data/vendor/librarian/lib/librarian/chef/templates/Cheffile +15 -0
  53. data/vendor/librarian/lib/librarian/cli.rb +205 -0
  54. data/vendor/librarian/lib/librarian/cli/manifest_presenter.rb +79 -0
  55. data/vendor/librarian/lib/librarian/config.rb +7 -0
  56. data/vendor/librarian/lib/librarian/config/database.rb +205 -0
  57. data/vendor/librarian/lib/librarian/config/file_source.rb +47 -0
  58. data/vendor/librarian/lib/librarian/config/hash_source.rb +33 -0
  59. data/vendor/librarian/lib/librarian/config/source.rb +149 -0
  60. data/vendor/librarian/lib/librarian/dependency.rb +91 -0
  61. data/vendor/librarian/lib/librarian/dsl.rb +108 -0
  62. data/vendor/librarian/lib/librarian/dsl/receiver.rb +48 -0
  63. data/vendor/librarian/lib/librarian/dsl/target.rb +172 -0
  64. data/vendor/librarian/lib/librarian/environment.rb +134 -0
  65. data/vendor/librarian/lib/librarian/error.rb +4 -0
  66. data/vendor/librarian/lib/librarian/helpers.rb +13 -0
  67. data/vendor/librarian/lib/librarian/lockfile.rb +29 -0
  68. data/vendor/librarian/lib/librarian/lockfile/compiler.rb +66 -0
  69. data/vendor/librarian/lib/librarian/lockfile/parser.rb +100 -0
  70. data/vendor/librarian/lib/librarian/logger.rb +46 -0
  71. data/vendor/librarian/lib/librarian/manifest.rb +132 -0
  72. data/vendor/librarian/lib/librarian/manifest_set.rb +153 -0
  73. data/vendor/librarian/lib/librarian/mock.rb +1 -0
  74. data/vendor/librarian/lib/librarian/mock/cli.rb +19 -0
  75. data/vendor/librarian/lib/librarian/mock/dsl.rb +15 -0
  76. data/vendor/librarian/lib/librarian/mock/environment.rb +24 -0
  77. data/vendor/librarian/lib/librarian/mock/extension.rb +9 -0
  78. data/vendor/librarian/lib/librarian/mock/source.rb +1 -0
  79. data/vendor/librarian/lib/librarian/mock/source/mock.rb +97 -0
  80. data/vendor/librarian/lib/librarian/mock/source/mock/registry.rb +83 -0
  81. data/vendor/librarian/lib/librarian/resolution.rb +44 -0
  82. data/vendor/librarian/lib/librarian/resolver.rb +78 -0
  83. data/vendor/librarian/lib/librarian/resolver/implementation.rb +118 -0
  84. data/vendor/librarian/lib/librarian/source.rb +2 -0
  85. data/vendor/librarian/lib/librarian/source/git.rb +150 -0
  86. data/vendor/librarian/lib/librarian/source/git/repository.rb +217 -0
  87. data/vendor/librarian/lib/librarian/source/local.rb +61 -0
  88. data/vendor/librarian/lib/librarian/source/path.rb +74 -0
  89. data/vendor/librarian/lib/librarian/spec.rb +13 -0
  90. data/vendor/librarian/lib/librarian/spec_change_set.rb +173 -0
  91. data/vendor/librarian/lib/librarian/specfile.rb +18 -0
  92. data/vendor/librarian/lib/librarian/support/abstract_method.rb +21 -0
  93. data/vendor/librarian/lib/librarian/ui.rb +64 -0
  94. data/vendor/librarian/lib/librarian/version.rb +3 -0
  95. data/vendor/librarian/librarian.gemspec +34 -0
  96. data/vendor/librarian/spec/functional/chef/source/git_spec.rb +432 -0
  97. data/vendor/librarian/spec/functional/chef/source/site_spec.rb +215 -0
  98. data/vendor/librarian/spec/functional/source/git/repository_spec.rb +149 -0
  99. data/vendor/librarian/spec/unit/action/base_spec.rb +18 -0
  100. data/vendor/librarian/spec/unit/action/clean_spec.rb +102 -0
  101. data/vendor/librarian/spec/unit/action/ensure_spec.rb +37 -0
  102. data/vendor/librarian/spec/unit/action/install_spec.rb +111 -0
  103. data/vendor/librarian/spec/unit/config/database_spec.rb +319 -0
  104. data/vendor/librarian/spec/unit/dependency_spec.rb +36 -0
  105. data/vendor/librarian/spec/unit/dsl_spec.rb +194 -0
  106. data/vendor/librarian/spec/unit/environment_spec.rb +9 -0
  107. data/vendor/librarian/spec/unit/lockfile/parser_spec.rb +162 -0
  108. data/vendor/librarian/spec/unit/lockfile_spec.rb +65 -0
  109. data/vendor/librarian/spec/unit/manifest_set_spec.rb +202 -0
  110. data/vendor/librarian/spec/unit/manifest_spec.rb +36 -0
  111. data/vendor/librarian/spec/unit/mock/source/mock_spec.rb +22 -0
  112. data/vendor/librarian/spec/unit/resolver_spec.rb +192 -0
  113. data/vendor/librarian/spec/unit/source/git_spec.rb +29 -0
  114. data/vendor/librarian/spec/unit/spec_change_set_spec.rb +169 -0
  115. metadata +227 -0
@@ -0,0 +1,81 @@
1
+ require "librarian/error"
2
+ require "librarian/resolver"
3
+ require "librarian/spec_change_set"
4
+ require "librarian/action/base"
5
+
6
+ module Librarian
7
+ module Action
8
+ class Resolve < Base
9
+
10
+ def run
11
+ if force? || !lockfile_path.exist?
12
+ spec = specfile.read
13
+ manifests = []
14
+ else
15
+ lock = lockfile.read
16
+ spec = specfile.read(lock.sources)
17
+ changes = spec_change_set(spec, lock)
18
+ if changes.same?
19
+ debug { "The specfile is unchanged: nothing to do." }
20
+ return
21
+ end
22
+ manifests = changes.analyze
23
+ end
24
+
25
+ resolution = resolver.resolve(spec, manifests)
26
+ unless resolution.correct?
27
+ raise Error, "Could not resolve the dependencies."
28
+ else
29
+ lockfile_text = lockfile.save(resolution)
30
+ debug { "Bouncing #{lockfile_name}" }
31
+ bounced_lockfile_text = lockfile.save(lockfile.load(lockfile_text))
32
+ unless bounced_lockfile_text == lockfile_text
33
+ debug { "lockfile_text: \n#{lockfile_text}"}
34
+ debug { "bounced_lockfile_text: \n#{bounced_lockfile_text}"}
35
+ raise Error, "Cannot bounce #{lockfile_name}!"
36
+ end
37
+ lockfile_path.open('wb') { |f| f.write(lockfile_text) }
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def force?
44
+ options[:force]
45
+ end
46
+
47
+ def specfile_name
48
+ environment.specfile_name
49
+ end
50
+
51
+ def lockfile_name
52
+ environment.lockfile_name
53
+ end
54
+
55
+ def specfile_path
56
+ environment.specfile_path
57
+ end
58
+
59
+ def lockfile_path
60
+ environment.lockfile_path
61
+ end
62
+
63
+ def specfile
64
+ environment.specfile
65
+ end
66
+
67
+ def lockfile
68
+ environment.lockfile
69
+ end
70
+
71
+ def resolver
72
+ Resolver.new(environment)
73
+ end
74
+
75
+ def spec_change_set(spec, lock)
76
+ SpecChangeSet.new(environment, spec, lock)
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,78 @@
1
+ require "librarian/error"
2
+ require "librarian/manifest_set"
3
+ require "librarian/resolver"
4
+ require "librarian/spec_change_set"
5
+ require "librarian/action/base"
6
+
7
+ module Librarian
8
+ module Action
9
+ class Update < Base
10
+
11
+ def run
12
+ unless lockfile_path.exist?
13
+ raise Error, "Lockfile missing!"
14
+ end
15
+ previous_resolution = lockfile.load(lockfile_path.read)
16
+ spec = specfile.read(previous_resolution.sources)
17
+ changes = spec_change_set(spec, previous_resolution)
18
+ manifests = changes.same? ? previous_resolution.manifests : changes.analyze
19
+ partial_manifests = ManifestSet.deep_strip(manifests, dependency_names)
20
+ unpinnable_sources = previous_resolution.sources - partial_manifests.map(&:source)
21
+ unpinnable_sources.each(&:unpin!)
22
+ resolution = resolver.resolve(spec, partial_manifests)
23
+ unless resolution.correct?
24
+ raise Error, "Could not resolve the dependencies."
25
+ else
26
+ lockfile_text = lockfile.save(resolution)
27
+ debug { "Bouncing #{lockfile_name}" }
28
+ bounced_lockfile_text = lockfile.save(lockfile.load(lockfile_text))
29
+ unless bounced_lockfile_text == lockfile_text
30
+ debug { "lockfile_text: \n#{lockfile_text}"}
31
+ debug { "bounced_lockfile_text: \n#{bounced_lockfile_text}"}
32
+ raise Error, "Cannot bounce #{lockfile_name}!"
33
+ end
34
+ lockfile_path.open('wb') { |f| f.write(lockfile_text) }
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def dependency_names
41
+ options[:names]
42
+ end
43
+
44
+ def specfile_name
45
+ environment.specfile_name
46
+ end
47
+
48
+ def lockfile_name
49
+ environment.lockfile_name
50
+ end
51
+
52
+ def specfile_path
53
+ environment.specfile_path
54
+ end
55
+
56
+ def lockfile_path
57
+ environment.lockfile_path
58
+ end
59
+
60
+ def specfile
61
+ environment.specfile
62
+ end
63
+
64
+ def lockfile
65
+ environment.lockfile
66
+ end
67
+
68
+ def resolver
69
+ Resolver.new(environment)
70
+ end
71
+
72
+ def spec_change_set(spec, lock)
73
+ SpecChangeSet.new(environment, spec, lock)
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1 @@
1
+ require 'librarian/chef/extension'
@@ -0,0 +1,48 @@
1
+ require 'librarian/helpers'
2
+
3
+ require 'librarian/cli'
4
+ require 'librarian/chef'
5
+
6
+ module Librarian
7
+ module Chef
8
+ class Cli < Librarian::Cli
9
+
10
+ module Particularity
11
+ def root_module
12
+ Chef
13
+ end
14
+ end
15
+
16
+ include Particularity
17
+ extend Particularity
18
+
19
+ source_root Pathname.new(__FILE__).dirname.join("templates")
20
+
21
+ def init
22
+ copy_file environment.specfile_name
23
+ end
24
+
25
+ desc "install", "Resolves and installs all of the dependencies you specify."
26
+ option "quiet", :type => :boolean, :default => false
27
+ option "verbose", :type => :boolean, :default => false
28
+ option "line-numbers", :type => :boolean, :default => false
29
+ option "clean", :type => :boolean, :default => false
30
+ option "strip-dot-git", :type => :boolean
31
+ option "path", :type => :string
32
+ def install
33
+ ensure!
34
+ clean! if options["clean"]
35
+ if options.include?("strip-dot-git")
36
+ strip_dot_git_val = options["strip-dot-git"] ? "1" : nil
37
+ environment.config_db.local["install.strip-dot-git"] = strip_dot_git_val
38
+ end
39
+ if options.include?("path")
40
+ environment.config_db.local["path"] = options["path"]
41
+ end
42
+ resolve!
43
+ install!
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ require 'librarian/dsl'
2
+ require 'librarian/chef/source'
3
+
4
+ module Librarian
5
+ module Chef
6
+ class Dsl < Librarian::Dsl
7
+
8
+ dependency :cookbook
9
+
10
+ source :site => Source::Site
11
+ source :git => Source::Git
12
+ source :path => Source::Path
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ require "librarian/environment"
2
+ require "librarian/chef/dsl"
3
+ require "librarian/chef/source"
4
+
5
+ module Librarian
6
+ module Chef
7
+ class Environment < Environment
8
+
9
+ def adapter_name
10
+ "chef"
11
+ end
12
+
13
+ def install_path
14
+ part = config_db["path"] || "cookbooks"
15
+ project_path.join(part)
16
+ end
17
+
18
+ def config_keys
19
+ super + %w[
20
+ install.strip-dot-git
21
+ path
22
+ ]
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,9 @@
1
+ require 'librarian/chef/environment'
2
+
3
+ module Librarian
4
+ module Chef
5
+ extend self
6
+ extend Librarian
7
+
8
+ end
9
+ end
@@ -0,0 +1,42 @@
1
+ require 'pathname'
2
+ require 'securerandom'
3
+ require 'highline'
4
+
5
+ require 'librarian'
6
+ require 'librarian/action/install'
7
+ require 'librarian/chef'
8
+
9
+ module Librarian
10
+ module Chef
11
+
12
+ class Environment
13
+ def install_path
14
+ @install_path ||= begin
15
+ has_home = ENV["HOME"] && File.directory?(ENV["HOME"])
16
+ tmp_dir = Pathname.new(has_home ? "~/.librarian/tmp" : "/tmp/librarian").expand_path
17
+ enclosing = tmp_dir.join("chef/integration/knife/install")
18
+ enclosing.mkpath unless enclosing.exist?
19
+ dir = enclosing.join(SecureRandom.hex(16))
20
+ dir.mkpath
21
+ at_exit { dir.rmtree }
22
+ dir
23
+ end
24
+ end
25
+ end
26
+
27
+ def install_path
28
+ environment.install_path
29
+ end
30
+
31
+ hl = HighLine.new
32
+
33
+ begin
34
+ Action::Install.new(environment).run
35
+ rescue Error => e
36
+ message = hl.color(e.message, HighLine::RED)
37
+ hl.say(message)
38
+ Process.exit!(1)
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,59 @@
1
+ require 'json'
2
+ require 'yaml'
3
+
4
+ require 'librarian/manifest'
5
+
6
+ module Librarian
7
+ module Chef
8
+ module ManifestReader
9
+ extend self
10
+
11
+ MANIFESTS = %w(metadata.json metadata.yml metadata.yaml metadata.rb)
12
+
13
+ def manifest_path(path)
14
+ MANIFESTS.map{|s| path.join(s)}.find{|s| s.exist?}
15
+ end
16
+
17
+ def read_manifest(name, manifest_path)
18
+ case manifest_path.extname
19
+ when ".json" then JSON.parse(binread(manifest_path))
20
+ when ".yml", ".yaml" then YAML.load(binread(manifest_path))
21
+ when ".rb" then compile_manifest(name, manifest_path.dirname)
22
+ end
23
+ end
24
+
25
+ def compile_manifest(name, path)
26
+ # Inefficient, if there are many cookbooks with uncompiled metadata.
27
+ require 'chef/json_compat'
28
+ require 'chef/cookbook/metadata'
29
+ md = ::Chef::Cookbook::Metadata.new
30
+ md.name(name)
31
+ md.from_file(path.join('metadata.rb').to_s)
32
+ {"name" => md.name, "version" => md.version, "dependencies" => md.dependencies}
33
+ end
34
+
35
+ def manifest?(name, path)
36
+ path = Pathname.new(path)
37
+ !!manifest_path(path)
38
+ end
39
+
40
+ def check_manifest(name, manifest_path)
41
+ manifest = read_manifest(name, manifest_path)
42
+ manifest["name"] == name
43
+ end
44
+
45
+ private
46
+
47
+ if IO.respond_to?(:binread)
48
+ def binread(path)
49
+ path.binread
50
+ end
51
+ else
52
+ def binread(path)
53
+ path.read
54
+ end
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ require 'librarian/chef/source/path'
2
+ require 'librarian/chef/source/git'
3
+ require 'librarian/chef/source/site'
@@ -0,0 +1,25 @@
1
+ require 'librarian/source/git'
2
+ require 'librarian/chef/source/local'
3
+
4
+ module Librarian
5
+ module Chef
6
+ module Source
7
+ class Git < Librarian::Source::Git
8
+ include Local
9
+
10
+ private
11
+
12
+ def install_perform_step_copy!(found_path, install_path)
13
+ debug { "Copying #{relative_path_to(found_path)} to #{relative_path_to(install_path)}" }
14
+ FileUtils.cp_r(found_path, install_path)
15
+
16
+ if environment.config_db["install.strip-dot-git"] == "1"
17
+ dot_git = install_path.join(".git")
18
+ dot_git.rmtree if dot_git.directory?
19
+ end
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,69 @@
1
+ require 'librarian/chef/manifest_reader'
2
+
3
+ module Librarian
4
+ module Chef
5
+ module Source
6
+ module Local
7
+
8
+ def install!(manifest)
9
+ manifest.source == self or raise ArgumentError
10
+
11
+ info { "Installing #{manifest.name} (#{manifest.version})" }
12
+
13
+ debug { "Installing #{manifest}" }
14
+
15
+ name, version = manifest.name, manifest.version
16
+ found_path = found_path(name)
17
+
18
+ install_path = environment.install_path.join(name)
19
+ if install_path.exist?
20
+ debug { "Deleting #{relative_path_to(install_path)}" }
21
+ install_path.rmtree
22
+ end
23
+
24
+ install_perform_step_copy!(found_path, install_path)
25
+ end
26
+
27
+ def fetch_version(name, extra)
28
+ manifest_data(name)["version"]
29
+ end
30
+
31
+ def fetch_dependencies(name, version, extra)
32
+ manifest_data(name)["dependencies"]
33
+ end
34
+
35
+ private
36
+
37
+ def install_perform_step_copy!(found_path, install_path)
38
+ debug { "Copying #{relative_path_to(found_path)} to #{relative_path_to(install_path)}" }
39
+ FileUtils.cp_r(found_path, install_path)
40
+ end
41
+
42
+ def manifest_data(name)
43
+ @manifest_data ||= { }
44
+ @manifest_data[name] ||= fetch_manifest_data(name)
45
+ end
46
+
47
+ def fetch_manifest_data(name)
48
+ expect_manifest!(name)
49
+
50
+ found_path = found_path(name)
51
+ manifest_path = ManifestReader.manifest_path(found_path)
52
+ ManifestReader.read_manifest(name, manifest_path)
53
+ end
54
+
55
+ def manifest?(name, path)
56
+ ManifestReader.manifest?(name, path)
57
+ end
58
+
59
+ def expect_manifest!(name)
60
+ found_path = found_path(name)
61
+ return if found_path && ManifestReader.manifest_path(found_path)
62
+
63
+ raise Error, "No metadata file found for #{name} from #{self}! If this should be a cookbook, you might consider contributing a metadata file upstream or forking the cookbook to add your own metadata file."
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+ end