librarian-puppet 0.0.1.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/.gitignore +1 -0
  2. data/LICENSE +20 -0
  3. data/README.md +0 -0
  4. data/bin/librarian-puppet +9 -0
  5. data/lib/librarian/puppet.rb +7 -0
  6. data/lib/librarian/puppet/cli.rb +30 -0
  7. data/lib/librarian/puppet/dsl.rb +14 -0
  8. data/lib/librarian/puppet/environment.rb +18 -0
  9. data/lib/librarian/puppet/extension.rb +9 -0
  10. data/lib/librarian/puppet/source.rb +2 -0
  11. data/lib/librarian/puppet/source/git.rb +12 -0
  12. data/lib/librarian/puppet/source/local.rb +46 -0
  13. data/lib/librarian/puppet/source/path.rb +12 -0
  14. data/lib/librarian/puppet/templates/Puppetfile +6 -0
  15. data/librarian-puppet.gemspec +126 -0
  16. data/vendor/librarian/.rspec +1 -0
  17. data/vendor/librarian/.travis.yml +6 -0
  18. data/vendor/librarian/CHANGELOG.md +168 -0
  19. data/vendor/librarian/Gemfile +4 -0
  20. data/vendor/librarian/MIT-LICENSE +20 -0
  21. data/vendor/librarian/README.md +318 -0
  22. data/vendor/librarian/Rakefile +34 -0
  23. data/vendor/librarian/bin/librarian-chef +7 -0
  24. data/vendor/librarian/bin/librarian-mock +7 -0
  25. data/vendor/librarian/config/cucumber.yaml +1 -0
  26. data/vendor/librarian/features/chef/cli/init.feature +10 -0
  27. data/vendor/librarian/features/chef/cli/install.feature +64 -0
  28. data/vendor/librarian/features/chef/cli/show.feature +65 -0
  29. data/vendor/librarian/features/chef/cli/version.feature +11 -0
  30. data/vendor/librarian/features/support/env.rb +9 -0
  31. data/vendor/librarian/lib/librarian.rb +19 -0
  32. data/vendor/librarian/lib/librarian/action.rb +5 -0
  33. data/vendor/librarian/lib/librarian/action/base.rb +22 -0
  34. data/vendor/librarian/lib/librarian/action/clean.rb +44 -0
  35. data/vendor/librarian/lib/librarian/action/ensure.rb +24 -0
  36. data/vendor/librarian/lib/librarian/action/install.rb +95 -0
  37. data/vendor/librarian/lib/librarian/action/resolve.rb +81 -0
  38. data/vendor/librarian/lib/librarian/action/update.rb +78 -0
  39. data/vendor/librarian/lib/librarian/chef.rb +1 -0
  40. data/vendor/librarian/lib/librarian/chef/cli.rb +27 -0
  41. data/vendor/librarian/lib/librarian/chef/dsl.rb +15 -0
  42. data/vendor/librarian/lib/librarian/chef/environment.rb +19 -0
  43. data/vendor/librarian/lib/librarian/chef/extension.rb +9 -0
  44. data/vendor/librarian/lib/librarian/chef/integration/knife.rb +42 -0
  45. data/vendor/librarian/lib/librarian/chef/manifest_reader.rb +47 -0
  46. data/vendor/librarian/lib/librarian/chef/source.rb +3 -0
  47. data/vendor/librarian/lib/librarian/chef/source/git.rb +12 -0
  48. data/vendor/librarian/lib/librarian/chef/source/local.rb +63 -0
  49. data/vendor/librarian/lib/librarian/chef/source/path.rb +12 -0
  50. data/vendor/librarian/lib/librarian/chef/source/site.rb +434 -0
  51. data/vendor/librarian/lib/librarian/chef/templates/Cheffile +15 -0
  52. data/vendor/librarian/lib/librarian/cli.rb +175 -0
  53. data/vendor/librarian/lib/librarian/cli/manifest_presenter.rb +79 -0
  54. data/vendor/librarian/lib/librarian/dependency.rb +95 -0
  55. data/vendor/librarian/lib/librarian/dsl.rb +105 -0
  56. data/vendor/librarian/lib/librarian/dsl/receiver.rb +48 -0
  57. data/vendor/librarian/lib/librarian/dsl/target.rb +176 -0
  58. data/vendor/librarian/lib/librarian/environment.rb +129 -0
  59. data/vendor/librarian/lib/librarian/error.rb +4 -0
  60. data/vendor/librarian/lib/librarian/helpers.rb +13 -0
  61. data/vendor/librarian/lib/librarian/helpers/debug.rb +35 -0
  62. data/vendor/librarian/lib/librarian/lockfile.rb +33 -0
  63. data/vendor/librarian/lib/librarian/lockfile/compiler.rb +70 -0
  64. data/vendor/librarian/lib/librarian/lockfile/parser.rb +104 -0
  65. data/vendor/librarian/lib/librarian/manifest.rb +140 -0
  66. data/vendor/librarian/lib/librarian/manifest_set.rb +153 -0
  67. data/vendor/librarian/lib/librarian/mock.rb +1 -0
  68. data/vendor/librarian/lib/librarian/mock/cli.rb +19 -0
  69. data/vendor/librarian/lib/librarian/mock/dsl.rb +15 -0
  70. data/vendor/librarian/lib/librarian/mock/environment.rb +24 -0
  71. data/vendor/librarian/lib/librarian/mock/extension.rb +9 -0
  72. data/vendor/librarian/lib/librarian/mock/source.rb +1 -0
  73. data/vendor/librarian/lib/librarian/mock/source/mock.rb +97 -0
  74. data/vendor/librarian/lib/librarian/mock/source/mock/registry.rb +83 -0
  75. data/vendor/librarian/lib/librarian/resolution.rb +44 -0
  76. data/vendor/librarian/lib/librarian/resolver.rb +73 -0
  77. data/vendor/librarian/lib/librarian/resolver/implementation.rb +122 -0
  78. data/vendor/librarian/lib/librarian/source.rb +2 -0
  79. data/vendor/librarian/lib/librarian/source/git.rb +150 -0
  80. data/vendor/librarian/lib/librarian/source/git/repository.rb +213 -0
  81. data/vendor/librarian/lib/librarian/source/local.rb +51 -0
  82. data/vendor/librarian/lib/librarian/source/path.rb +74 -0
  83. data/vendor/librarian/lib/librarian/spec.rb +13 -0
  84. data/vendor/librarian/lib/librarian/spec_change_set.rb +170 -0
  85. data/vendor/librarian/lib/librarian/specfile.rb +22 -0
  86. data/vendor/librarian/lib/librarian/support/abstract_method.rb +21 -0
  87. data/vendor/librarian/lib/librarian/ui.rb +64 -0
  88. data/vendor/librarian/lib/librarian/version.rb +3 -0
  89. data/vendor/librarian/librarian.gemspec +33 -0
  90. data/vendor/librarian/spec/functional/chef/source/git_spec.rb +432 -0
  91. data/vendor/librarian/spec/functional/chef/source/site_spec.rb +215 -0
  92. data/vendor/librarian/spec/unit/action/base_spec.rb +18 -0
  93. data/vendor/librarian/spec/unit/action/clean_spec.rb +102 -0
  94. data/vendor/librarian/spec/unit/action/ensure_spec.rb +37 -0
  95. data/vendor/librarian/spec/unit/action/install_spec.rb +111 -0
  96. data/vendor/librarian/spec/unit/dependency_spec.rb +30 -0
  97. data/vendor/librarian/spec/unit/dsl_spec.rb +194 -0
  98. data/vendor/librarian/spec/unit/environment_spec.rb +9 -0
  99. data/vendor/librarian/spec/unit/lockfile/parser_spec.rb +162 -0
  100. data/vendor/librarian/spec/unit/lockfile_spec.rb +65 -0
  101. data/vendor/librarian/spec/unit/manifest_set_spec.rb +202 -0
  102. data/vendor/librarian/spec/unit/manifest_spec.rb +30 -0
  103. data/vendor/librarian/spec/unit/mock/source/mock_spec.rb +22 -0
  104. data/vendor/librarian/spec/unit/resolver_spec.rb +192 -0
  105. data/vendor/librarian/spec/unit/source/git_spec.rb +29 -0
  106. data/vendor/librarian/spec/unit/spec_change_set_spec.rb +169 -0
  107. metadata +163 -0
@@ -0,0 +1,104 @@
1
+ require 'librarian/helpers/debug'
2
+
3
+ require 'librarian/manifest'
4
+ require 'librarian/dependency'
5
+ require 'librarian/manifest_set'
6
+
7
+ module Librarian
8
+ class Lockfile
9
+ class Parser
10
+
11
+ class ManifestPlaceholder
12
+ attr_reader :source, :name, :version, :dependencies
13
+ def initialize(source, name, version, dependencies)
14
+ @source, @name, @version, @dependencies = source, name, version, dependencies
15
+ end
16
+ end
17
+
18
+ include Helpers::Debug
19
+
20
+ attr_accessor :environment
21
+ private :environment=
22
+
23
+ def initialize(environment)
24
+ self.environment = environment
25
+ end
26
+
27
+ def parse(string)
28
+ string = string.dup
29
+ source_type_names_map = Hash[dsl_class.source_types.map{|t| [t[1].lock_name, t[1]]}]
30
+ source_type_names = dsl_class.source_types.map{|t| t[1].lock_name}
31
+ lines = string.split(/(\r|\n|\r\n)+/).select{|l| l =~ /\S/}
32
+ sources = []
33
+ while source_type_names.include?(lines.first)
34
+ source = {}
35
+ source_type_name = lines.shift
36
+ source[:type] = source_type_names_map[source_type_name]
37
+ options = {}
38
+ while lines.first =~ /^ {2}([\w-]+):\s+(.+)$/
39
+ lines.shift
40
+ options[$1.to_sym] = $2
41
+ end
42
+ source[:options] = options
43
+ lines.shift # specs
44
+ manifests = {}
45
+ while lines.first =~ /^ {4}([\w-]+) \((.*)\)$/
46
+ lines.shift
47
+ name = $1
48
+ manifests[name] = {:version => $2, :dependencies => {}}
49
+ while lines.first =~ /^ {6}([\w-]+) \((.*)\)$/
50
+ lines.shift
51
+ manifests[name][:dependencies][$1] = $2.split(/,\s*/)
52
+ end
53
+ end
54
+ source[:manifests] = manifests
55
+ sources << source
56
+ end
57
+ manifests = compile(sources)
58
+ manifests_index = Hash[manifests.map{|m| [m.name, m]}]
59
+ raise StandardError, "Expected DEPENDENCIES topic!" unless lines.shift == "DEPENDENCIES"
60
+ dependencies = []
61
+ while lines.first =~ /^ {2}([\w-]+)(?: \((.*)\))?$/
62
+ lines.shift
63
+ name, requirement = $1, $2.split(/,\s*/)
64
+ dependencies << Dependency.new(name, requirement, manifests_index[name].source)
65
+ end
66
+ Resolution.new(dependencies, manifests)
67
+ end
68
+
69
+ private
70
+
71
+ def compile(sources_ast)
72
+ manifests = {}
73
+ sources_ast.each do |source_ast|
74
+ source_type = source_ast[:type]
75
+ source = source_type.from_lock_options(environment, source_ast[:options])
76
+ source_ast[:manifests].each do |manifest_name, manifest_ast|
77
+ manifests[manifest_name] = ManifestPlaceholder.new(
78
+ source,
79
+ manifest_name,
80
+ manifest_ast[:version],
81
+ manifest_ast[:dependencies].map{|k, v| Dependency.new(k, v, nil)}
82
+ )
83
+ end
84
+ end
85
+ manifests = manifests.map do |name, manifest|
86
+ dependencies = manifest.dependencies.map do |d|
87
+ Dependency.new(d.name, d.requirement, manifests[d.name].source)
88
+ end
89
+ manifest.source.manifest(
90
+ manifest.name,
91
+ manifest.version,
92
+ dependencies
93
+ )
94
+ end
95
+ ManifestSet.sort(manifests)
96
+ end
97
+
98
+ def dsl_class
99
+ environment.dsl_class
100
+ end
101
+
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,140 @@
1
+ require 'rubygems'
2
+
3
+ require 'librarian/helpers/debug'
4
+ require 'librarian/support/abstract_method'
5
+
6
+ module Librarian
7
+ class Manifest
8
+
9
+ class Version
10
+ include Comparable
11
+
12
+ def initialize(*args)
13
+ args = initialize_normalize_args(args)
14
+
15
+ self.backing = Gem::Version.new(*args)
16
+ end
17
+
18
+ def to_gem_version
19
+ backing
20
+ end
21
+
22
+ def <=>(other)
23
+ to_gem_version <=> other.to_gem_version
24
+ end
25
+
26
+ def to_s
27
+ to_gem_version.to_s
28
+ end
29
+
30
+ private
31
+
32
+ def initialize_normalize_args(args)
33
+ args.map do |arg|
34
+ arg = [arg] if self.class === arg
35
+ arg
36
+ end
37
+ end
38
+
39
+ attr_accessor :backing
40
+ end
41
+
42
+ include Support::AbstractMethod
43
+ include Helpers::Debug
44
+
45
+ attr_accessor :source, :name, :extra
46
+ private :source=, :name=, :extra=
47
+
48
+ abstract_method :fetch_version!, :fetch_dependencies!
49
+
50
+ def initialize(source, name, extra = nil)
51
+ assert_name_valid! name
52
+
53
+ self.source = source
54
+ self.name = name
55
+ self.extra = extra
56
+ end
57
+
58
+ def to_s
59
+ "#{name}/#{version} <#{source}>"
60
+ end
61
+
62
+ def version
63
+ defined_version || fetched_version
64
+ end
65
+
66
+ def version=(version)
67
+ self.defined_version = _normalize_version(version)
68
+ end
69
+
70
+ def version?
71
+ return unless defined_version
72
+
73
+ defined_version == fetched_version
74
+ end
75
+
76
+ def dependencies
77
+ defined_dependencies || fetched_dependencies
78
+ end
79
+
80
+ def dependencies=(dependencies)
81
+ self.defined_dependencies = _normalize_dependencies(dependencies)
82
+ end
83
+
84
+ def dependencies?
85
+ return unless defined_dependencies
86
+
87
+ defined_dependencies.zip(fetched_dependencies).all? do |(a, b)|
88
+ a.name == b.name && a.requirement == b.requirement
89
+ end
90
+ end
91
+
92
+ def satisfies?(dependency)
93
+ dependency.requirement.satisfied_by?(version)
94
+ end
95
+
96
+ def install!
97
+ source.install!(self)
98
+ end
99
+
100
+ private
101
+
102
+ attr_accessor :defined_version, :defined_dependencies
103
+
104
+ def environment
105
+ source.environment
106
+ end
107
+
108
+ def fetched_version
109
+ @fetched_version ||= _normalize_version(fetch_version!)
110
+ end
111
+
112
+ def fetched_dependencies
113
+ @fetched_dependencies ||= _normalize_dependencies(fetch_dependencies!)
114
+ end
115
+
116
+ def fetch_version!
117
+ source.fetch_version(name, extra)
118
+ end
119
+
120
+ def fetch_dependencies!
121
+ source.fetch_dependencies(name, version, extra)
122
+ end
123
+
124
+ def _normalize_version(version)
125
+ Version.new(version)
126
+ end
127
+
128
+ def _normalize_dependencies(dependencies)
129
+ if Hash === dependencies
130
+ dependencies = dependencies.map{|k, v| Dependency.new(k, v, nil)}
131
+ end
132
+ dependencies.sort_by(&:name)
133
+ end
134
+
135
+ def assert_name_valid!(name)
136
+ raise ArgumentError, "name (#{name.inspect}) must be sensible" unless name =~ /^\S.*\S$/
137
+ end
138
+
139
+ end
140
+ end
@@ -0,0 +1,153 @@
1
+ require 'set'
2
+ require 'tsort'
3
+
4
+ module Librarian
5
+ class ManifestSet
6
+
7
+ class GraphHash < Hash
8
+ include TSort
9
+ alias tsort_each_node each_key
10
+ def tsort_each_child(node, &block)
11
+ self[node].each(&block)
12
+ end
13
+ end
14
+
15
+ class << self
16
+ def shallow_strip(manifests, names)
17
+ new(manifests).shallow_strip!(names).send(method_for(manifests))
18
+ end
19
+ def deep_strip(manifests, names)
20
+ new(manifests).deep_strip!(names).send(method_for(manifests))
21
+ end
22
+ def shallow_keep(manifests, names)
23
+ new(manifests).shallow_keep!(names).send(method_for(manifests))
24
+ end
25
+ def deep_keep(manifests, names)
26
+ new(manifests).deep_keep!(names).send(method_for(manifests))
27
+ end
28
+ def sort(manifests)
29
+ manifests = Hash[manifests.map{|m| [m.name, m]}] if Array === manifests
30
+ manifest_pairs = GraphHash[manifests.map{|k, m| [k, m.dependencies.map{|d| d.name}]}]
31
+ manifest_names = manifest_pairs.tsort
32
+ manifest_names.map{|n| manifests[n]}
33
+ end
34
+ private
35
+ def method_for(manifests)
36
+ case manifests
37
+ when Hash
38
+ :to_hash
39
+ when Array
40
+ :to_a
41
+ end
42
+ end
43
+ end
44
+
45
+ def initialize(manifests)
46
+ self.index = Hash === manifests ? manifests.dup : Hash[manifests.map{|m| [m.name, m]}]
47
+ end
48
+
49
+ def to_a
50
+ index.values
51
+ end
52
+
53
+ def to_hash
54
+ index.dup
55
+ end
56
+
57
+ def dup
58
+ self.class.new(index)
59
+ end
60
+
61
+ def shallow_strip(names)
62
+ dup.shallow_strip!(names)
63
+ end
64
+
65
+ def shallow_strip!(names)
66
+ assert_strings!(names)
67
+
68
+ names.each do |name|
69
+ index.delete(name)
70
+ end
71
+ self
72
+ end
73
+
74
+ def deep_strip(names)
75
+ dup.deep_strip!(names)
76
+ end
77
+
78
+ def deep_strip!(names)
79
+ names = Array === names ? names.dup : names.to_a
80
+ assert_strings!(names)
81
+
82
+ strippables = dependencies_of(names)
83
+ shallow_strip!(strippables)
84
+
85
+ self
86
+ end
87
+
88
+ def shallow_keep(names)
89
+ dup.shallow_keep!(names)
90
+ end
91
+
92
+ def shallow_keep!(names)
93
+ assert_strings!(names)
94
+
95
+ names = Set.new(names) unless Set === names
96
+ index.reject! { |k, v| !names.include?(k) }
97
+ self
98
+ end
99
+
100
+ def deep_keep(names)
101
+ dup.conservative_strip!(names)
102
+ end
103
+
104
+ def deep_keep!(names)
105
+ names = Array === names ? names.dup : names.to_a
106
+ assert_strings!(names)
107
+
108
+ keepables = dependencies_of(names)
109
+ shallow_keep!(keepables)
110
+
111
+ self
112
+ end
113
+
114
+ def consistent?
115
+ index.values.all? do |manifest|
116
+ in_compliance_with?(manifest.dependencies)
117
+ end
118
+ end
119
+
120
+ def in_compliance_with?(dependencies)
121
+ dependencies.all? do |dependency|
122
+ manifest = index[dependency.name]
123
+ manifest && manifest.satisfies?(dependency)
124
+ end
125
+ end
126
+
127
+ private
128
+
129
+ attr_accessor :index
130
+
131
+ def assert_strings!(names)
132
+ non_strings = names.reject{|name| String === name}
133
+ non_strings.empty? or raise TypeError, "names must all be strings"
134
+ end
135
+
136
+ # Straightforward breadth-first graph traversal algorithm.
137
+ def dependencies_of(names)
138
+ names = Array === names ? names.dup : names.to_a
139
+ assert_strings!(names)
140
+
141
+ deps = Set.new
142
+ until names.empty?
143
+ name = names.shift
144
+ next if deps.include?(name)
145
+
146
+ deps << name
147
+ names.concat index[name].dependencies.map(&:name)
148
+ end
149
+ deps.to_a
150
+ end
151
+
152
+ end
153
+ end
@@ -0,0 +1 @@
1
+ require 'librarian/mock/extension'
@@ -0,0 +1,19 @@
1
+ require 'librarian/cli'
2
+ require 'librarian/mock'
3
+
4
+ module Librarian
5
+ module Mock
6
+ class Cli < Librarian::Cli
7
+
8
+ module Particularity
9
+ def root_module
10
+ Mock
11
+ end
12
+ end
13
+
14
+ include Particularity
15
+ extend Particularity
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'librarian/dsl'
2
+ require 'librarian/mock/source'
3
+
4
+ module Librarian
5
+ module Mock
6
+ class Dsl < Librarian::Dsl
7
+
8
+ dependency :dep
9
+
10
+ source :src => Source::Mock
11
+
12
+ shortcut :a, :src => 'source-a'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ require "librarian/environment"
2
+ require "librarian/mock/dsl"
3
+
4
+ module Librarian
5
+ module Mock
6
+ class Environment < Environment
7
+
8
+ def adapter_name
9
+ "mock"
10
+ end
11
+
12
+ def install_path
13
+ nil
14
+ end
15
+
16
+ def registry(options = nil, &block)
17
+ @registry ||= Source::Mock::Registry.new
18
+ @registry.merge!(options, &block)
19
+ @registry
20
+ end
21
+ end
22
+
23
+ end
24
+ end