librarian 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/lib/librarian.rb +5 -178
  3. data/lib/librarian/action.rb +5 -0
  4. data/lib/librarian/action/base.rb +22 -0
  5. data/lib/librarian/action/clean.rb +56 -0
  6. data/lib/librarian/action/ensure.rb +24 -0
  7. data/lib/librarian/action/install.rb +101 -0
  8. data/lib/librarian/action/resolve.rb +81 -0
  9. data/lib/librarian/action/update.rb +76 -0
  10. data/lib/librarian/chef/cli.rb +7 -2
  11. data/lib/librarian/chef/dsl.rb +0 -3
  12. data/lib/librarian/chef/environment.rb +19 -0
  13. data/lib/librarian/chef/extension.rb +1 -16
  14. data/lib/librarian/chef/integration/knife.rb +9 -16
  15. data/lib/librarian/chef/source/git.rb +0 -2
  16. data/lib/librarian/chef/source/local.rb +1 -74
  17. data/lib/librarian/chef/source/local/manifest.rb +82 -0
  18. data/lib/librarian/chef/source/path.rb +0 -2
  19. data/lib/librarian/chef/source/site.rb +9 -89
  20. data/lib/librarian/chef/source/site/manifest.rb +94 -0
  21. data/lib/librarian/cli.rb +56 -17
  22. data/lib/librarian/dependency.rb +2 -2
  23. data/lib/librarian/dsl.rb +15 -5
  24. data/lib/librarian/dsl/receiver.rb +2 -0
  25. data/lib/librarian/dsl/target.rb +13 -1
  26. data/lib/librarian/environment.rb +94 -0
  27. data/lib/librarian/error.rb +4 -0
  28. data/lib/librarian/helpers/debug.rb +6 -6
  29. data/lib/librarian/lockfile.rb +7 -5
  30. data/lib/librarian/lockfile/compiler.rb +5 -4
  31. data/lib/librarian/lockfile/parser.rb +6 -5
  32. data/lib/librarian/manifest.rb +2 -2
  33. data/lib/librarian/mock/cli.rb +6 -1
  34. data/lib/librarian/mock/dsl.rb +0 -3
  35. data/lib/librarian/mock/environment.rb +24 -0
  36. data/lib/librarian/mock/extension.rb +1 -20
  37. data/lib/librarian/mock/source/mock.rb +7 -7
  38. data/lib/librarian/mock/source/mock/registry.rb +16 -12
  39. data/lib/librarian/resolver.rb +5 -116
  40. data/lib/librarian/resolver/implementation.rb +117 -0
  41. data/lib/librarian/source/git.rb +8 -7
  42. data/lib/librarian/source/git/repository.rb +7 -5
  43. data/lib/librarian/source/local.rb +1 -1
  44. data/lib/librarian/source/path.rb +7 -6
  45. data/lib/librarian/spec_change_set.rb +6 -5
  46. data/lib/librarian/specfile.rb +10 -4
  47. data/lib/librarian/version.rb +1 -1
  48. data/librarian.gemspec +1 -0
  49. data/spec/functional/chef/source/git_spec.rb +177 -89
  50. data/spec/functional/chef/source/site_spec.rb +111 -52
  51. data/spec/unit/action/base_spec.rb +18 -0
  52. data/spec/unit/action/clean_spec.rb +133 -0
  53. data/spec/unit/action/ensure_spec.rb +37 -0
  54. data/spec/unit/action/install_spec.rb +113 -0
  55. data/spec/unit/dsl_spec.rb +15 -13
  56. data/spec/unit/environment_spec.rb +9 -0
  57. data/spec/unit/lockfile_spec.rb +15 -4
  58. data/spec/unit/mock/source/mock.rb +22 -0
  59. data/spec/unit/resolver_spec.rb +24 -24
  60. data/spec/unit/spec_change_set_spec.rb +29 -25
  61. metadata +47 -19
  62. data/lib/librarian/chef/particularity.rb +0 -9
  63. data/lib/librarian/mock/particularity.rb +0 -9
  64. data/lib/librarian/particularity.rb +0 -7
@@ -0,0 +1,4 @@
1
+ module Librarian
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -8,24 +8,24 @@ module Librarian
8
8
 
9
9
  LIBRARIAN_PATH = Pathname.new('../../../../').expand_path(__FILE__)
10
10
 
11
- abstract_method :root_module
11
+ abstract_method :environment
12
12
 
13
13
  private
14
14
 
15
15
  def relative_path_to(path)
16
- root_module.project_relative_path_to(path)
16
+ environment.project_relative_path_to(path)
17
17
  end
18
18
 
19
19
  def debug
20
- if root_module.ui
21
- if root_module.ui.respond_to? :debug_line_numbers and root_module.ui.debug_line_numbers
20
+ if ui = environment.ui
21
+ if ui.respond_to? :debug_line_numbers and ui.debug_line_numbers
22
22
  loc = caller.find{|l| !(l =~ /in `debug'$/)}
23
23
  if loc =~ /^(.+):(\d+):in `(.+)'$/
24
24
  loc = "#{Pathname.new($1).relative_path_from(LIBRARIAN_PATH)}:#{$2}:in `#{$3}'"
25
25
  end
26
- root_module.ui.debug { "[Librarian] #{yield} [#{loc}]" }
26
+ ui.debug { "[Librarian] #{yield} [#{loc}]" }
27
27
  else
28
- root_module.ui.debug { "[Librarian] #{yield}" }
28
+ ui.debug { "[Librarian] #{yield}" }
29
29
  end
30
30
  end
31
31
  end
@@ -8,19 +8,21 @@ module Librarian
8
8
 
9
9
  include Helpers::Debug
10
10
 
11
- attr_reader :root_module, :path
11
+ attr_accessor :environment
12
+ private :environment=
13
+ attr_reader :path
12
14
 
13
- def initialize(root_module, path)
14
- @root_module = root_module
15
+ def initialize(environment, path)
16
+ self.environment = environment
15
17
  @path = path
16
18
  end
17
19
 
18
20
  def save(resolution)
19
- Compiler.new(root_module).compile(resolution)
21
+ Compiler.new(environment).compile(resolution)
20
22
  end
21
23
 
22
24
  def load(string)
23
- Parser.new(root_module).parse(string)
25
+ Parser.new(environment).parse(string)
24
26
  end
25
27
 
26
28
  def read
@@ -6,10 +6,11 @@ module Librarian
6
6
 
7
7
  include Helpers::Debug
8
8
 
9
- attr_reader :root_module
9
+ attr_accessor :environment
10
+ private :environment=
10
11
 
11
- def initialize(root_module)
12
- @root_module = root_module
12
+ def initialize(environment)
13
+ self.environment = environment
13
14
  end
14
15
 
15
16
  def compile(resolution)
@@ -61,7 +62,7 @@ module Librarian
61
62
  end
62
63
 
63
64
  def dsl_class
64
- root_module.dsl_class
65
+ environment.dsl_class
65
66
  end
66
67
 
67
68
  end
@@ -17,10 +17,11 @@ module Librarian
17
17
 
18
18
  include Helpers::Debug
19
19
 
20
- attr_reader :root_module
20
+ attr_accessor :environment
21
+ private :environment=
21
22
 
22
- def initialize(root_module)
23
- @root_module = root_module
23
+ def initialize(environment)
24
+ self.environment = environment
24
25
  end
25
26
 
26
27
  def parse(string)
@@ -71,7 +72,7 @@ module Librarian
71
72
  manifests = {}
72
73
  sources_ast.each do |source_ast|
73
74
  source_type = source_ast[:type]
74
- source = source_type.from_lock_options(source_ast[:options])
75
+ source = source_type.from_lock_options(environment, source_ast[:options])
75
76
  source_ast[:manifests].each do |manifest_name, manifest_ast|
76
77
  manifests[manifest_name] = ManifestPlaceholder.new(
77
78
  source,
@@ -95,7 +96,7 @@ module Librarian
95
96
  end
96
97
 
97
98
  def dsl_class
98
- root_module.dsl_class
99
+ environment.dsl_class
99
100
  end
100
101
 
101
102
  end
@@ -69,8 +69,8 @@ module Librarian
69
69
 
70
70
  private
71
71
 
72
- def root_module
73
- source.root_module
72
+ def environment
73
+ source.environment
74
74
  end
75
75
 
76
76
  def _normalize_version(version)
@@ -1,11 +1,16 @@
1
1
  require 'librarian/cli'
2
2
  require 'librarian/mock'
3
- require 'librarian/mock/particularity'
4
3
 
5
4
  module Librarian
6
5
  module Mock
7
6
  class Cli < Librarian::Cli
8
7
 
8
+ module Particularity
9
+ def root_module
10
+ Mock
11
+ end
12
+ end
13
+
9
14
  include Particularity
10
15
  extend Particularity
11
16
 
@@ -1,13 +1,10 @@
1
1
  require 'librarian/dsl'
2
- require 'librarian/mock/particularity'
3
2
  require 'librarian/mock/source'
4
3
 
5
4
  module Librarian
6
5
  module Mock
7
6
  class Dsl < Librarian::Dsl
8
7
 
9
- include Particularity
10
-
11
8
  dependency :dep
12
9
 
13
10
  source :src => Source::Mock
@@ -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 specfile_name
9
+ "Mockfile"
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
@@ -1,28 +1,9 @@
1
- require 'librarian/specfile'
2
- require 'librarian/mock/dsl'
1
+ require 'librarian/mock/environment'
3
2
 
4
3
  module Librarian
5
4
  module Mock
6
5
  extend self
7
6
  extend Librarian
8
7
 
9
- module Overrides
10
- def specfile_name
11
- 'Mockfile'
12
- end
13
-
14
- def install_path
15
- nil
16
- end
17
-
18
- def registry(options = nil, &block)
19
- registry = Source::Mock::Registry
20
- registry.clear! if options && options[:clear]
21
- registry.merge!(&block) if block
22
- registry
23
- end
24
- end
25
-
26
- extend Overrides
27
8
  end
28
9
  end
@@ -1,5 +1,4 @@
1
1
  require 'librarian/manifest'
2
- require 'librarian/mock/particularity'
3
2
  require 'librarian/mock/source/mock/registry'
4
3
 
5
4
  module Librarian
@@ -23,21 +22,22 @@ module Librarian
23
22
  end
24
23
  end
25
24
 
26
- include Particularity
27
-
28
25
  class << self
29
26
  LOCK_NAME = 'MOCK'
30
27
  def lock_name
31
28
  LOCK_NAME
32
29
  end
33
- def from_lock_options(options)
34
- new(options[:remote], options.reject{|k, v| k == :remote})
30
+ def from_lock_options(environment, options)
31
+ new(environment, options[:remote], options.reject{|k, v| k == :remote})
35
32
  end
36
33
  end
37
34
 
35
+ attr_accessor :environment
36
+ private :environment=
38
37
  attr_reader :name
39
38
 
40
- def initialize(name, options)
39
+ def initialize(environment, name, options)
40
+ self.environment = environment
41
41
  @name = name
42
42
  end
43
43
 
@@ -60,7 +60,7 @@ module Librarian
60
60
  end
61
61
 
62
62
  def registry
63
- Registry[name]
63
+ environment.registry[name]
64
64
  end
65
65
 
66
66
  def manifest(name, version, dependencies)
@@ -58,19 +58,23 @@ module Librarian
58
58
 
59
59
  end
60
60
 
61
- class << self
62
- def clear!
63
- @sources = nil
64
- end
65
- def merge!(&block)
66
- @sources ||= {}
67
- Dsl.run!(@sources, &block) if block
68
- end
69
- def [](name)
70
- @sources ||= {}
71
- @sources[name] ||= {}
72
- end
61
+ def initialize
62
+ clear!
63
+ end
64
+ def clear!
65
+ self.sources = { }
73
66
  end
67
+ def merge!(options = nil, &block)
68
+ clear! if options && options[:clear]
69
+ Dsl.run!(sources, &block) if block
70
+ end
71
+ def [](name)
72
+ sources[name] ||= {}
73
+ end
74
+
75
+ private
76
+
77
+ attr_accessor :sources
74
78
 
75
79
  end
76
80
  end
@@ -1,126 +1,15 @@
1
- require 'librarian/helpers/debug'
2
-
3
- require 'librarian/dependency'
1
+ require 'librarian/resolver/implementation'
4
2
  require 'librarian/manifest_set'
5
3
  require 'librarian/resolution'
6
4
 
7
5
  module Librarian
8
6
  class Resolver
9
7
 
10
- class Implementation
11
- include Helpers::Debug
12
-
13
- attr_reader :resolver, :source, :dependency_source_map
14
-
15
- def initialize(resolver, spec)
16
- @resolver = resolver
17
- @source = spec.source
18
- @dependency_source_map = Hash[spec.dependencies.map{|d| [d.name, d.source]}]
19
- @level = 0
20
- end
21
-
22
- def resolve(dependencies, manifests = {})
23
- resolution = recursive_resolve([], manifests, dependencies.dup)
24
- resolution ? resolution[1] : nil
25
- end
26
-
27
- def recursive_resolve(dependencies, manifests, queue)
28
- if dependencies.empty?
29
- queue.each do |dependency|
30
- debug { "Scheduling #{dependency}" }
31
- end
32
- end
33
- failure = false
34
- until failure || queue.empty?
35
- dependency = queue.shift
36
- dependencies << dependency
37
- debug { "Resolving #{dependency}" }
38
- scope do
39
- if manifests.key?(dependency.name)
40
- unless dependency.satisfied_by?(manifests[dependency.name])
41
- debug { "Conflicts with #{manifests[dependency.name]}" }
42
- failure = true
43
- else
44
- debug { "Accords with all prior constraints" }
45
- # nothing left to do
46
- end
47
- else
48
- debug { "No known prior constraints" }
49
- resolution = nil
50
- related_dependencies = dependencies.select{|d| d.name == dependency.name}
51
- unless dependency.manifests && dependency.manifests.first
52
- debug { "No known manifests" }
53
- else
54
- debug { "Checking manifests" }
55
- scope do
56
- dependency.manifests.each do |manifest|
57
- unless resolution
58
- debug { "Checking #{manifest}" }
59
- scope do
60
- if related_dependencies.all?{|d| d.satisfied_by?(manifest)}
61
- m = manifests.merge(dependency.name => manifest)
62
- a = manifest.dependencies.map { |d|
63
- d.source ? d :
64
- !dependency_source_map.key?(d.name) ?
65
- Dependency.new(d.name, d.requirement, source) :
66
- Dependency.new(d.name, d.requirement, dependency_source_map[d.name])
67
- }
68
- a.each do |d|
69
- debug { "Scheduling #{d}" }
70
- end
71
- q = queue + a
72
- resolution = recursive_resolve(dependencies.dup, m, q)
73
- end
74
- if resolution
75
- debug { "Resolved #{dependency} at #{manifest}" }
76
- else
77
- debug { "Backtracking from #{manifest}" }
78
- end
79
- end
80
- end
81
- end
82
- end
83
- if resolution
84
- debug { "Resolved #{dependency}" }
85
- else
86
- debug { "Failed to resolve #{dependency}" }
87
- end
88
- end
89
- unless resolution
90
- failure = true
91
- else
92
- dependencies, manifests, queue = *resolution
93
- end
94
- end
95
- end
96
- end
97
- failure ? nil : [dependencies, manifests, queue]
98
- end
99
-
100
- private
101
-
102
- def scope
103
- @level += 1
104
- yield
105
- ensure
106
- @level -= 1
107
- end
108
-
109
- def debug
110
- super { ' ' * @level + yield }
111
- end
112
-
113
- def root_module
114
- resolver.root_module
115
- end
116
- end
117
-
118
- include Helpers::Debug
119
-
120
- attr_reader :root_module
8
+ attr_accessor :environment
9
+ private :environment=
121
10
 
122
- def initialize(root_module)
123
- @root_module = root_module
11
+ def initialize(environment)
12
+ self.environment = environment
124
13
  end
125
14
 
126
15
  def resolve(spec, partial_manifests = [])
@@ -0,0 +1,117 @@
1
+ require 'librarian/helpers/debug'
2
+
3
+ require 'librarian/dependency'
4
+
5
+ module Librarian
6
+ class Resolver
7
+ class Implementation
8
+
9
+ include Helpers::Debug
10
+
11
+ attr_reader :resolver, :source, :dependency_source_map
12
+
13
+ def initialize(resolver, spec)
14
+ @resolver = resolver
15
+ @source = spec.source
16
+ @dependency_source_map = Hash[spec.dependencies.map{|d| [d.name, d.source]}]
17
+ @level = 0
18
+ end
19
+
20
+ def resolve(dependencies, manifests = {})
21
+ resolution = recursive_resolve([], manifests, dependencies.dup)
22
+ resolution ? resolution[1] : nil
23
+ end
24
+
25
+ def recursive_resolve(dependencies, manifests, queue)
26
+ if dependencies.empty?
27
+ queue.each do |dependency|
28
+ debug { "Scheduling #{dependency}" }
29
+ end
30
+ end
31
+ failure = false
32
+ until failure || queue.empty?
33
+ dependency = queue.shift
34
+ dependencies << dependency
35
+ debug { "Resolving #{dependency}" }
36
+ scope do
37
+ if manifests.key?(dependency.name)
38
+ unless dependency.satisfied_by?(manifests[dependency.name])
39
+ debug { "Conflicts with #{manifests[dependency.name]}" }
40
+ failure = true
41
+ else
42
+ debug { "Accords with all prior constraints" }
43
+ # nothing left to do
44
+ end
45
+ else
46
+ debug { "No known prior constraints" }
47
+ resolution = nil
48
+ related_dependencies = dependencies.select{|d| d.name == dependency.name}
49
+ unless dependency.manifests && dependency.manifests.first
50
+ debug { "No known manifests" }
51
+ else
52
+ debug { "Checking manifests" }
53
+ scope do
54
+ dependency.manifests.each do |manifest|
55
+ unless resolution
56
+ debug { "Checking #{manifest}" }
57
+ scope do
58
+ if related_dependencies.all?{|d| d.satisfied_by?(manifest)}
59
+ m = manifests.merge(dependency.name => manifest)
60
+ a = manifest.dependencies.map { |d|
61
+ d.source ? d :
62
+ !dependency_source_map.key?(d.name) ?
63
+ Dependency.new(d.name, d.requirement, source) :
64
+ Dependency.new(d.name, d.requirement, dependency_source_map[d.name])
65
+ }
66
+ a.each do |d|
67
+ debug { "Scheduling #{d}" }
68
+ end
69
+ q = queue + a
70
+ resolution = recursive_resolve(dependencies.dup, m, q)
71
+ end
72
+ if resolution
73
+ debug { "Resolved #{dependency} at #{manifest}" }
74
+ else
75
+ debug { "Backtracking from #{manifest}" }
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ if resolution
82
+ debug { "Resolved #{dependency}" }
83
+ else
84
+ debug { "Failed to resolve #{dependency}" }
85
+ end
86
+ end
87
+ unless resolution
88
+ failure = true
89
+ else
90
+ dependencies, manifests, queue = *resolution
91
+ end
92
+ end
93
+ end
94
+ end
95
+ failure ? nil : [dependencies, manifests, queue]
96
+ end
97
+
98
+ private
99
+
100
+ def scope
101
+ @level += 1
102
+ yield
103
+ ensure
104
+ @level -= 1
105
+ end
106
+
107
+ def debug
108
+ super { ' ' * @level + yield }
109
+ end
110
+
111
+ def environment
112
+ resolver.environment
113
+ end
114
+
115
+ end
116
+ end
117
+ end