librarian-puppet 0.9.1 → 0.9.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/lib/librarian/puppet.rb +6 -1
  2. data/lib/librarian/puppet/cli.rb +21 -0
  3. data/lib/librarian/puppet/environment.rb +1 -0
  4. data/lib/librarian/puppet/lockfile/parser.rb +53 -0
  5. data/lib/librarian/puppet/source/forge.rb +0 -8
  6. data/lib/librarian/puppet/source/git.rb +29 -0
  7. data/lib/librarian/puppet/source/local.rb +1 -0
  8. data/lib/librarian/puppet/version.rb +5 -0
  9. data/vendor/librarian/CHANGELOG.md +17 -0
  10. data/vendor/librarian/Gemfile +2 -0
  11. data/vendor/librarian/README.md +99 -14
  12. data/vendor/librarian/features/chef/cli/init.feature +1 -0
  13. data/vendor/librarian/features/chef/cli/show.feature +13 -1
  14. data/vendor/librarian/lib/librarian/action/base.rb +6 -4
  15. data/vendor/librarian/lib/librarian/chef/cli.rb +21 -0
  16. data/vendor/librarian/lib/librarian/chef/environment.rb +9 -1
  17. data/vendor/librarian/lib/librarian/chef/manifest_reader.rb +14 -2
  18. data/vendor/librarian/lib/librarian/chef/source/git.rb +13 -0
  19. data/vendor/librarian/lib/librarian/chef/source/local.rb +8 -2
  20. data/vendor/librarian/lib/librarian/chef/source/site.rb +18 -6
  21. data/vendor/librarian/lib/librarian/cli.rb +54 -24
  22. data/vendor/librarian/lib/librarian/config.rb +7 -0
  23. data/vendor/librarian/lib/librarian/config/database.rb +205 -0
  24. data/vendor/librarian/lib/librarian/config/file_source.rb +47 -0
  25. data/vendor/librarian/lib/librarian/config/hash_source.rb +33 -0
  26. data/vendor/librarian/lib/librarian/config/source.rb +149 -0
  27. data/vendor/librarian/lib/librarian/dependency.rb +1 -5
  28. data/vendor/librarian/lib/librarian/dsl.rb +6 -3
  29. data/vendor/librarian/lib/librarian/dsl/target.rb +0 -4
  30. data/vendor/librarian/lib/librarian/environment.rb +30 -25
  31. data/vendor/librarian/lib/librarian/lockfile.rb +0 -4
  32. data/vendor/librarian/lib/librarian/lockfile/compiler.rb +0 -4
  33. data/vendor/librarian/lib/librarian/lockfile/parser.rb +4 -8
  34. data/vendor/librarian/lib/librarian/logger.rb +46 -0
  35. data/vendor/librarian/lib/librarian/manifest.rb +1 -9
  36. data/vendor/librarian/lib/librarian/resolver.rb +6 -1
  37. data/vendor/librarian/lib/librarian/resolver/implementation.rb +1 -5
  38. data/vendor/librarian/lib/librarian/source/git/repository.rb +10 -6
  39. data/vendor/librarian/lib/librarian/source/local.rb +12 -2
  40. data/vendor/librarian/lib/librarian/spec_change_set.rb +6 -3
  41. data/vendor/librarian/lib/librarian/specfile.rb +0 -4
  42. data/vendor/librarian/lib/librarian/version.rb +1 -1
  43. data/vendor/librarian/librarian.gemspec +1 -0
  44. data/vendor/librarian/spec/functional/source/git/repository_spec.rb +149 -0
  45. data/vendor/librarian/spec/unit/config/database_spec.rb +319 -0
  46. data/vendor/librarian/spec/unit/dependency_spec.rb +6 -0
  47. data/vendor/librarian/spec/unit/manifest_spec.rb +6 -0
  48. metadata +107 -66
  49. data/librarian-puppet.gemspec +0 -130
  50. data/vendor/librarian/.rspec +0 -1
  51. data/vendor/librarian/.travis.yml +0 -6
  52. data/vendor/librarian/lib/librarian/helpers/debug.rb +0 -35
@@ -0,0 +1,47 @@
1
+ require "yaml"
2
+
3
+ require "librarian/config/source"
4
+
5
+ module Librarian
6
+ module Config
7
+ class FileSource < Source
8
+
9
+ attr_accessor :config_path
10
+ private :config_path=
11
+
12
+ def initialize(adapter_name, options = { })
13
+ super
14
+
15
+ self.config_path = options.delete(:config_path) or raise ArgumentError, "must provide config_path"
16
+ end
17
+
18
+ def to_s
19
+ config_path
20
+ end
21
+
22
+ private
23
+
24
+ def load
25
+ return { } unless File.file?(config_path)
26
+
27
+ raw = YAML.load_file(config_path)
28
+ return { } unless Hash === raw
29
+
30
+ translate_raw_to_config(raw)
31
+ end
32
+
33
+ def save(config)
34
+ raw = translate_config_to_raw(config)
35
+
36
+ if config.empty?
37
+ File.delete(config_path) if File.file?(config_path)
38
+ else
39
+ config_dir = File.dirname(config_path)
40
+ FileUtils.mkpath(config_dir) unless File.directory?(config_dir)
41
+ File.open(config_path, "wb"){|f| YAML.dump(raw, f)}
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,33 @@
1
+ require "librarian/source"
2
+
3
+ module Librarian
4
+ module Config
5
+ class HashSource < Source
6
+
7
+ attr_accessor :name, :raw
8
+ private :name=, :raw=
9
+
10
+ def initialize(adapter_name, options = { })
11
+ super
12
+
13
+ self.name = options.delete(:name) or raise ArgumentError, "must provide name"
14
+ self.raw = options.delete(:raw) or raise ArgumentError, "must provide raw"
15
+ end
16
+
17
+ def to_s
18
+ name
19
+ end
20
+
21
+ private
22
+
23
+ def load
24
+ translate_raw_to_config(raw)
25
+ end
26
+
27
+ def save(config)
28
+ raise Error, "nonsense!"
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,149 @@
1
+ require "librarian/error"
2
+
3
+ module Librarian
4
+ module Config
5
+ class Source
6
+
7
+ RAW_KEY_SUFFIX_VALIDITY_PATTERN =
8
+ /\A[A-Z0-9_]+\z/
9
+ CONFIG_KEY_VALIDITY_PATTERN =
10
+ /\A[a-z][a-z0-9\-]+(?:\.[a-z0-9\-]+)*\z/
11
+
12
+ class << self
13
+ def raw_key_suffix_validity_pattern
14
+ RAW_KEY_SUFFIX_VALIDITY_PATTERN
15
+ end
16
+ def config_key_validity_pattern
17
+ CONFIG_KEY_VALIDITY_PATTERN
18
+ end
19
+ end
20
+
21
+ attr_accessor :adapter_name
22
+ private :adapter_name=
23
+
24
+ def initialize(adapter_name, options = { })
25
+ self.adapter_name = adapter_name
26
+
27
+ self.forbidden_keys = options.delete(:forbidden_keys) || []
28
+ end
29
+
30
+ def [](key)
31
+ load!
32
+
33
+ data[key]
34
+ end
35
+
36
+ def []=(key, value)
37
+ key_permitted?(key) or raise Error, "key not permitted: #{key.inspect}"
38
+ value_permitted?(key, value) or raise Error, "value for key #{key.inspect} not permitted: #{value.inspect}"
39
+
40
+ load!
41
+ if value.nil?
42
+ data.delete(key)
43
+ else
44
+ data[key] = value
45
+ end
46
+ save(data)
47
+ end
48
+
49
+ def keys
50
+ load!
51
+
52
+ data.keys
53
+ end
54
+
55
+ private
56
+
57
+ attr_accessor :data, :forbidden_keys
58
+
59
+ def load!
60
+ self.data = load unless data
61
+ end
62
+
63
+ def key_permitted?(key)
64
+ String === key &&
65
+ config_key_validity_pattern === key &&
66
+ !forbidden_keys.any?{|k| k === key}
67
+ end
68
+
69
+ def value_permitted?(key, value)
70
+ return true if value.nil?
71
+
72
+ String === value
73
+ end
74
+
75
+ def raw_key_valid?(key)
76
+ return false unless key.start_with?(raw_key_prefix)
77
+
78
+ suffix = key[raw_key_prefix.size..-1]
79
+ raw_key_suffix_validity_pattern =~ suffix
80
+ end
81
+
82
+ def raw_key_suffix_validity_pattern
83
+ self.class.raw_key_suffix_validity_pattern
84
+ end
85
+
86
+ def config_key_valid?(key)
87
+ config_key_validity_pattern === key
88
+ end
89
+
90
+ def config_key_validity_pattern
91
+ self.class.config_key_validity_pattern
92
+ end
93
+
94
+ def raw_key_prefix
95
+ @key_prefix ||= "LIBRARIAN_#{adapter_name.upcase}_"
96
+ end
97
+
98
+ def assert_raw_keys_valid!(raw)
99
+ bad_keys = raw.keys.reject{|k| raw_key_valid?(k)}
100
+ unless bad_keys.empty?
101
+ config_path_s = config_path.to_s.inspect
102
+ bad_keys_s = bad_keys.map(&:inspect).join(", ")
103
+ raise Error, "config #{to_s} has bad keys: #{bad_keys_s}"
104
+ end
105
+ end
106
+
107
+ def assert_config_keys_valid!(config)
108
+ bad_keys = config.keys.reject{|k| config_key_valid?(k)}
109
+ unless bad_keys.empty?
110
+ bad_keys_s = bad_keys.map(&:inspect).join(", ")
111
+ raise Error, "config has bad keys: #{bad_keys_s}"
112
+ end
113
+ end
114
+
115
+ def assert_values_valid!(data)
116
+ bad_data = data.reject{|k, v| String === v}
117
+ bad_keys = bad_data.keys
118
+
119
+ unless bad_keys.empty?
120
+ bad_keys_s = bad_keys.map(&:inspect).join(", ")
121
+ raise Error, "config has bad values for keys: #{bad_keys_s}"
122
+ end
123
+ end
124
+
125
+ def translate_raw_to_config(raw)
126
+ assert_raw_keys_valid!(raw)
127
+ assert_values_valid!(raw)
128
+
129
+ Hash[raw.map do |key, value|
130
+ key = key[raw_key_prefix.size .. -1]
131
+ key = key.downcase.gsub(/__/, ".").gsub(/_/, "-")
132
+ [key, value]
133
+ end]
134
+ end
135
+
136
+ def translate_config_to_raw(config)
137
+ assert_config_keys_valid!(config)
138
+ assert_values_valid!(config)
139
+
140
+ Hash[config.map do |key, value|
141
+ key = key.gsub(/\./, "__").gsub(/\-/, "_").upcase
142
+ key = "#{raw_key_prefix}#{key}"
143
+ [key, value]
144
+ end]
145
+ end
146
+
147
+ end
148
+ end
149
+ end
@@ -1,7 +1,5 @@
1
1
  require 'rubygems'
2
2
 
3
- require 'librarian/helpers/debug'
4
-
5
3
  module Librarian
6
4
  class Dependency
7
5
 
@@ -42,8 +40,6 @@ module Librarian
42
40
  end
43
41
  end
44
42
 
45
- include Helpers::Debug
46
-
47
43
  attr_accessor :name, :requirement, :source
48
44
  private :name=, :requirement=, :source=
49
45
 
@@ -88,7 +84,7 @@ module Librarian
88
84
  end
89
85
 
90
86
  def assert_name_valid!(name)
91
- raise ArgumentError, "name (#{name.inspect}) must be sensible" unless name =~ /^\S.*\S$/
87
+ raise ArgumentError, "name (#{name.inspect}) must be sensible" unless name =~ /\A\S(?:.*\S)?\z/
92
88
  end
93
89
 
94
90
  end
@@ -1,13 +1,10 @@
1
1
  require 'librarian/dependency'
2
2
  require 'librarian/dsl/receiver'
3
3
  require 'librarian/dsl/target'
4
- require 'librarian/helpers/debug'
5
4
 
6
5
  module Librarian
7
6
  class Dsl
8
7
 
9
- include Helpers::Debug
10
-
11
8
  class Error < Exception
12
9
  end
13
10
 
@@ -101,5 +98,11 @@ module Librarian
101
98
  end
102
99
  end
103
100
 
101
+ private
102
+
103
+ def debug(*args, &block)
104
+ environment.logger.debug(*args, &block)
105
+ end
106
+
104
107
  end
105
108
  end
@@ -1,13 +1,9 @@
1
- require 'librarian/helpers/debug'
2
-
3
1
  require 'librarian/spec'
4
2
 
5
3
  module Librarian
6
4
  class Dsl
7
5
  class Target
8
6
 
9
- include Helpers::Debug
10
-
11
7
  class SourceShortcutDefinitionReceiver
12
8
  def initialize(target)
13
9
  singleton_class = class << self; self end
@@ -1,10 +1,11 @@
1
1
  require "pathname"
2
2
 
3
- require "librarian/helpers/debug"
4
3
  require "librarian/support/abstract_method"
5
4
 
6
5
  require "librarian/error"
6
+ require "librarian/config"
7
7
  require "librarian/lockfile"
8
+ require "librarian/logger"
8
9
  require "librarian/specfile"
9
10
  require "librarian/resolver"
10
11
  require "librarian/dsl"
@@ -14,30 +15,33 @@ module Librarian
14
15
  class Environment
15
16
 
16
17
  include Support::AbstractMethod
17
- include Helpers::Debug
18
18
 
19
19
  attr_accessor :ui
20
20
 
21
21
  abstract_method :specfile_name, :dsl_class, :install_path
22
22
 
23
23
  def initialize(options = { })
24
+ @pwd = options.fetch(:pwd) { Dir.pwd }
25
+ @env = options.fetch(:env) { ENV.to_hash }
26
+ @home = options.fetch(:home) { File.expand_path("~") }
24
27
  @project_path = options[:project_path]
25
28
  @specfile_name = options[:specfile_name]
26
29
  end
27
30
 
28
- def project_path
29
- @project_path ||= begin
30
- root = Pathname.new(Dir.pwd)
31
- root = root.dirname until project_path?(root)
32
- path = root.join(specfile_name)
33
- path.file? ? root : nil
34
- end
31
+ def logger
32
+ @logger ||= Logger.new(self)
35
33
  end
36
34
 
37
- def project_path?(path)
38
- path.join(config_name).directory? ||
39
- path.join(specfile_name).file? ||
40
- path.dirname == path
35
+ def config_db
36
+ @config_db ||= begin
37
+ Config::Database.new(adapter_name,
38
+ :pwd => @pwd,
39
+ :env => @env,
40
+ :home => @home,
41
+ :project_path => @project_path,
42
+ :specfile_name => default_specfile_name
43
+ )
44
+ end
41
45
  end
42
46
 
43
47
  def default_specfile_name
@@ -47,12 +51,16 @@ module Librarian
47
51
  end
48
52
  end
49
53
 
54
+ def project_path
55
+ config_db.project_path
56
+ end
57
+
50
58
  def specfile_name
51
- @specfile_name ||= default_specfile_name
59
+ config_db.specfile_name
52
60
  end
53
61
 
54
62
  def specfile_path
55
- project_path.join(specfile_name)
63
+ config_db.specfile_path
56
64
  end
57
65
 
58
66
  def specfile
@@ -63,20 +71,12 @@ module Librarian
63
71
  nil
64
72
  end
65
73
 
66
- def config_name
67
- File.join(*[config_prefix, adapter_name].compact)
68
- end
69
-
70
- def config_prefix
71
- ".librarian"
72
- end
73
-
74
74
  def lockfile_name
75
- "#{specfile_name}.lock"
75
+ config_db.lockfile_name
76
76
  end
77
77
 
78
78
  def lockfile_path
79
- project_path.join(lockfile_name)
79
+ config_db.lockfile_path
80
80
  end
81
81
 
82
82
  def lockfile
@@ -119,6 +119,11 @@ module Librarian
119
119
  self.class.name.split("::")[0 ... -1].inject(Object, &:const_get)::Dsl
120
120
  end
121
121
 
122
+ def config_keys
123
+ %[
124
+ ]
125
+ end
126
+
122
127
  private
123
128
 
124
129
  def environment
@@ -1,13 +1,9 @@
1
- require 'librarian/helpers/debug'
2
-
3
1
  require 'librarian/lockfile/compiler'
4
2
  require 'librarian/lockfile/parser'
5
3
 
6
4
  module Librarian
7
5
  class Lockfile
8
6
 
9
- include Helpers::Debug
10
-
11
7
  attr_accessor :environment
12
8
  private :environment=
13
9
  attr_reader :path
@@ -1,11 +1,7 @@
1
- require 'librarian/helpers/debug'
2
-
3
1
  module Librarian
4
2
  class Lockfile
5
3
  class Compiler
6
4
 
7
- include Helpers::Debug
8
-
9
5
  attr_accessor :environment
10
6
  private :environment=
11
7
 
@@ -1,5 +1,3 @@
1
- require 'librarian/helpers/debug'
2
-
3
1
  require 'librarian/manifest'
4
2
  require 'librarian/dependency'
5
3
  require 'librarian/manifest_set'
@@ -15,8 +13,6 @@ module Librarian
15
13
  end
16
14
  end
17
15
 
18
- include Helpers::Debug
19
-
20
16
  attr_accessor :environment
21
17
  private :environment=
22
18
 
@@ -35,18 +31,18 @@ module Librarian
35
31
  source_type_name = lines.shift
36
32
  source[:type] = source_type_names_map[source_type_name]
37
33
  options = {}
38
- while lines.first =~ /^ {2}([\w\/-]+):\s+(.+)$/
34
+ while lines.first =~ /^ {2}([\w-]+):\s+(.+)$/
39
35
  lines.shift
40
36
  options[$1.to_sym] = $2
41
37
  end
42
38
  source[:options] = options
43
39
  lines.shift # specs
44
40
  manifests = {}
45
- while lines.first =~ /^ {4}([\w\/-]+) \((.*)\)$/
41
+ while lines.first =~ /^ {4}([\w-]+) \((.*)\)$/
46
42
  lines.shift
47
43
  name = $1
48
44
  manifests[name] = {:version => $2, :dependencies => {}}
49
- while lines.first =~ /^ {6}([\w\/-]+) \((.*)\)$/
45
+ while lines.first =~ /^ {6}([\w-]+) \((.*)\)$/
50
46
  lines.shift
51
47
  manifests[name][:dependencies][$1] = $2.split(/,\s*/)
52
48
  end
@@ -58,7 +54,7 @@ module Librarian
58
54
  manifests_index = Hash[manifests.map{|m| [m.name, m]}]
59
55
  raise StandardError, "Expected DEPENDENCIES topic!" unless lines.shift == "DEPENDENCIES"
60
56
  dependencies = []
61
- while lines.first =~ /^ {2}([\w\/-]+)(?: \((.*)\))?$/
57
+ while lines.first =~ /^ {2}([\w-]+)(?: \((.*)\))?$/
62
58
  lines.shift
63
59
  name, requirement = $1, $2.split(/,\s*/)
64
60
  dependencies << Dependency.new(name, requirement, manifests_index[name].source)