librarian 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.travis.yml +7 -1
  2. data/CHANGELOG.md +19 -1
  3. data/README.md +2 -9
  4. data/Rakefile +0 -11
  5. data/lib/librarian.rb +0 -8
  6. data/lib/librarian/action/base.rb +6 -4
  7. data/lib/librarian/chef/cli.rb +1 -1
  8. data/lib/librarian/chef/integration/knife.rb +4 -0
  9. data/lib/librarian/chef/manifest_reader.rb +14 -2
  10. data/lib/librarian/chef/source/local.rb +2 -0
  11. data/lib/librarian/chef/source/site.rb +49 -41
  12. data/lib/librarian/cli.rb +32 -17
  13. data/lib/librarian/dependency.rb +1 -9
  14. data/lib/librarian/dsl.rb +6 -3
  15. data/lib/librarian/dsl/receiver.rb +10 -12
  16. data/lib/librarian/dsl/target.rb +5 -10
  17. data/lib/librarian/environment.rb +41 -2
  18. data/lib/librarian/lockfile.rb +0 -4
  19. data/lib/librarian/lockfile/compiler.rb +0 -4
  20. data/lib/librarian/lockfile/parser.rb +0 -4
  21. data/lib/librarian/logger.rb +46 -0
  22. data/lib/librarian/manifest.rb +1 -9
  23. data/lib/librarian/resolution.rb +5 -3
  24. data/lib/librarian/resolver.rb +6 -1
  25. data/lib/librarian/resolver/implementation.rb +18 -8
  26. data/lib/librarian/source/git.rb +2 -0
  27. data/lib/librarian/source/git/repository.rb +9 -5
  28. data/lib/librarian/source/local.rb +12 -2
  29. data/lib/librarian/spec.rb +4 -4
  30. data/lib/librarian/spec_change_set.rb +7 -4
  31. data/lib/librarian/specfile.rb +3 -8
  32. data/lib/librarian/version.rb +1 -1
  33. data/librarian.gemspec +3 -9
  34. data/spec/functional/chef/cli_spec.rb +194 -0
  35. data/spec/functional/chef/source/site_spec.rb +11 -10
  36. data/spec/functional/source/git/repository_spec.rb +1 -1
  37. data/spec/support/cli_macro.rb +122 -0
  38. data/spec/support/with_env_macro.rb +20 -0
  39. data/spec/unit/config/database_spec.rb +2 -2
  40. data/spec/unit/dependency_spec.rb +6 -0
  41. data/spec/unit/dsl_spec.rb +16 -37
  42. data/spec/unit/environment_spec.rb +95 -0
  43. data/spec/unit/manifest_spec.rb +6 -0
  44. data/spec/unit/resolver_spec.rb +41 -0
  45. metadata +7 -42
  46. data/config/cucumber.yaml +0 -1
  47. data/features/chef/cli/init.feature +0 -11
  48. data/features/chef/cli/install.feature +0 -64
  49. data/features/chef/cli/show.feature +0 -77
  50. data/features/chef/cli/version.feature +0 -11
  51. data/features/support/env.rb +0 -9
  52. data/lib/librarian/helpers/debug.rb +0 -35
@@ -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
 
@@ -83,12 +79,8 @@ module Librarian
83
79
 
84
80
  private
85
81
 
86
- def environment
87
- source.environment
88
- end
89
-
90
82
  def assert_name_valid!(name)
91
- raise ArgumentError, "name (#{name.inspect}) must be sensible" unless name =~ /^\S.*\S$/
83
+ raise ArgumentError, "name (#{name.inspect}) must be sensible" unless name =~ /\A\S(?:.*\S)?\z/
92
84
  end
93
85
 
94
86
  end
data/lib/librarian/dsl.rb CHANGED
@@ -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
@@ -23,19 +23,17 @@ module Librarian
23
23
  end
24
24
 
25
25
  def run(specfile = nil)
26
- if block_given?
27
- instance_eval(&Proc.new)
26
+ specfile = Proc.new if block_given?
27
+
28
+ case specfile
29
+ when Specfile
30
+ eval(specfile.path.read, instance_binding, specfile.path.to_s, 1)
31
+ when String
32
+ eval(specfile, instance_binding)
33
+ when Proc
34
+ instance_eval(&specfile)
28
35
  else
29
- case specfile
30
- when Specfile
31
- eval(specfile.path.read, instance_binding, specfile.path.to_s, 1)
32
- when String
33
- eval(specfile, instance_binding)
34
- when Proc
35
- instance_eval(&specfile)
36
- else
37
- raise ArgumentError, "specfile must be a #{Specfile}, #{String}, or #{Proc} if no block is given (it was #{specfile.inspect})"
38
- end
36
+ raise ArgumentError, "specfile must be a #{Specfile}, #{String}, or #{Proc} if no block is given (it was #{specfile.inspect})"
39
37
  end
40
38
  end
41
39
 
@@ -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
@@ -26,7 +22,7 @@ module Librarian
26
22
  end
27
23
  end
28
24
 
29
- SCOPABLES = [:sources]
25
+ SCOPABLES = [:source, :sources]
30
26
 
31
27
  attr_accessor :dsl
32
28
  private :dsl=
@@ -55,15 +51,12 @@ module Librarian
55
51
  end
56
52
 
57
53
  def to_spec
58
- Spec.new(@sources.first, @dependencies)
54
+ Spec.new(@sources, @dependencies)
59
55
  end
60
56
 
61
57
  def dependency(name, *args)
62
58
  options = args.last.is_a?(Hash) ? args.pop : {}
63
- source = source_from_options(options) || @sources.last
64
- unless source
65
- raise Error, "#{dependency_name} #{name} is specified without a source!"
66
- end
59
+ source = source_from_options(options) || @source
67
60
  dep = dependency_type.new(name, args, source)
68
61
  @dependencies << dep
69
62
  end
@@ -74,12 +67,14 @@ module Librarian
74
67
  elsif !(Hash === name) && !param && !options
75
68
  source = source_shortcuts[name]
76
69
  scope_or_directive(block) do
70
+ @source = source
77
71
  @sources = @sources.dup << source
78
72
  end
79
73
  else
80
74
  name, param, options = *normalize_source_options(name, param, options || {})
81
75
  source = source_from_params(name, param, options)
82
76
  scope_or_directive(block) do
77
+ @source = source
83
78
  @sources = @sources.dup << source
84
79
  end
85
80
  end
@@ -1,11 +1,13 @@
1
1
  require "pathname"
2
+ require 'net/http'
3
+ require "uri"
2
4
 
3
- require "librarian/helpers/debug"
4
5
  require "librarian/support/abstract_method"
5
6
 
6
7
  require "librarian/error"
7
8
  require "librarian/config"
8
9
  require "librarian/lockfile"
10
+ require "librarian/logger"
9
11
  require "librarian/specfile"
10
12
  require "librarian/resolver"
11
13
  require "librarian/dsl"
@@ -15,7 +17,6 @@ module Librarian
15
17
  class Environment
16
18
 
17
19
  include Support::AbstractMethod
18
- include Helpers::Debug
19
20
 
20
21
  attr_accessor :ui
21
22
 
@@ -29,6 +30,10 @@ module Librarian
29
30
  @specfile_name = options[:specfile_name]
30
31
  end
31
32
 
33
+ def logger
34
+ @logger ||= Logger.new(self)
35
+ end
36
+
32
37
  def config_db
33
38
  @config_db ||= begin
34
39
  Config::Database.new(adapter_name,
@@ -116,11 +121,45 @@ module Librarian
116
121
  self.class.name.split("::")[0 ... -1].inject(Object, &:const_get)::Dsl
117
122
  end
118
123
 
124
+ def version
125
+ VERSION
126
+ end
127
+
119
128
  def config_keys
120
129
  %[
121
130
  ]
122
131
  end
123
132
 
133
+ # The HTTP proxy specified in the environment variables:
134
+ # * HTTP_PROXY
135
+ # * HTTP_PROXY_USER
136
+ # * HTTP_PROXY_PASS
137
+ # Adapted from:
138
+ # https://github.com/rubygems/rubygems/blob/v1.8.24/lib/rubygems/remote_fetcher.rb#L276-293
139
+ def http_proxy_uri
140
+ @http_proxy_uri ||= begin
141
+ keys = %w( HTTP_PROXY HTTP_PROXY_USER HTTP_PROXY_PASS )
142
+ env = Hash[ENV.
143
+ map{|k, v| [k.upcase, v]}.
144
+ select{|k, v| keys.include?(k)}.
145
+ reject{|k, v| v.nil? || v.empty?}]
146
+
147
+ uri = env["HTTP_PROXY"] or return
148
+ uri = "http://#{uri}" unless uri =~ /^(https?|ftp|file):/
149
+ uri = URI.parse(uri)
150
+ uri.user ||= env["HTTP_PROXY_USER"]
151
+ uri.password ||= env["HTTP_PROXY_PASS"]
152
+ uri
153
+ end
154
+ end
155
+
156
+ def net_http_class
157
+ @net_http_class ||= begin
158
+ p = http_proxy_uri
159
+ p ? Net::HTTP::Proxy(p.host, p.port, p.user, p.password) : Net::HTTP
160
+ end
161
+ end
162
+
124
163
  private
125
164
 
126
165
  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
 
@@ -0,0 +1,46 @@
1
+ module Librarian
2
+ class Logger
3
+
4
+ librarian_path = Pathname(__FILE__)
5
+ librarian_path = librarian_path.dirname until librarian_path.join("lib").directory?
6
+ LIBRARIAN_PATH = librarian_path
7
+
8
+ attr_accessor :environment
9
+ private :environment=
10
+
11
+ def initialize(environment)
12
+ self.environment = environment
13
+ end
14
+
15
+ def info(string = nil, &block)
16
+ return unless ui
17
+
18
+ ui.info(string || yield)
19
+ end
20
+
21
+ def debug(string = nil, &block)
22
+ return unless ui
23
+
24
+ if ui.respond_to?(:debug_line_numbers) && ui.debug_line_numbers
25
+ loc = caller.find{|l| !(l =~ /in `debug'$/)}
26
+ if loc =~ /^(.+):(\d+):in `(.+)'$/
27
+ loc = "#{Pathname.new($1).relative_path_from(LIBRARIAN_PATH)}:#{$2}:in `#{$3}'"
28
+ end
29
+ ui.debug { "[Librarian] #{string || yield} [#{loc}]" }
30
+ else
31
+ ui.debug { "[Librarian] #{string || yield}" }
32
+ end
33
+ end
34
+
35
+ def relative_path_to(path)
36
+ environment.project_relative_path_to(path)
37
+ end
38
+
39
+ private
40
+
41
+ def ui
42
+ environment.ui
43
+ end
44
+
45
+ end
46
+ end
@@ -1,8 +1,5 @@
1
1
  require 'rubygems'
2
2
 
3
- require 'librarian/helpers/debug'
4
- require 'librarian/support/abstract_method'
5
-
6
3
  module Librarian
7
4
  class Manifest
8
5
 
@@ -39,14 +36,9 @@ module Librarian
39
36
  attr_accessor :backing
40
37
  end
41
38
 
42
- include Support::AbstractMethod
43
- include Helpers::Debug
44
-
45
39
  attr_accessor :source, :name, :extra
46
40
  private :source=, :name=, :extra=
47
41
 
48
- abstract_method :fetch_version!, :fetch_dependencies!
49
-
50
42
  def initialize(source, name, extra = nil)
51
43
  assert_name_valid! name
52
44
 
@@ -133,7 +125,7 @@ module Librarian
133
125
  end
134
126
 
135
127
  def assert_name_valid!(name)
136
- raise ArgumentError, "name (#{name.inspect}) must be sensible" unless name =~ /^\S.*\S$/
128
+ raise ArgumentError, "name (#{name.inspect}) must be sensible" unless name =~ /\A\S(?:.*\S)?\z/
137
129
  end
138
130
 
139
131
  end
@@ -11,11 +11,13 @@ module Librarian
11
11
  # the serialization-deserialization process is just the identity function.
12
12
  #
13
13
  class Resolution
14
- attr_reader :dependencies, :manifests, :manifests_index
14
+ attr_accessor :dependencies, :manifests, :manifests_index
15
+ private :dependencies=, :manifests=, :manifests_index=
15
16
 
16
17
  def initialize(dependencies, manifests)
17
- @dependencies, @manifests = dependencies, manifests
18
- @manifests_index = build_manifests_index(manifests)
18
+ self.dependencies = dependencies
19
+ self.manifests = manifests
20
+ self.manifests_index = build_manifests_index(manifests)
19
21
  end
20
22
 
21
23
  def correct?
@@ -4,7 +4,6 @@ require 'librarian/resolution'
4
4
 
5
5
  module Librarian
6
6
  class Resolver
7
- include Helpers::Debug
8
7
 
9
8
  attr_accessor :environment
10
9
  private :environment=
@@ -69,5 +68,11 @@ module Librarian
69
68
  ManifestSet.sort(manifests)
70
69
  end
71
70
 
71
+ private
72
+
73
+ def debug(*args, &block)
74
+ environment.logger.debug(*args, &block)
75
+ end
76
+
72
77
  end
73
78
  end
@@ -1,18 +1,24 @@
1
- require 'librarian/helpers/debug'
2
-
3
1
  require 'librarian/dependency'
4
2
 
5
3
  module Librarian
6
4
  class Resolver
7
5
  class Implementation
8
6
 
9
- include Helpers::Debug
7
+ class MultiSource
8
+ attr_accessor :sources
9
+ def initialize(sources)
10
+ self.sources = sources
11
+ end
12
+ def manifests(name)
13
+ sources.reverse.map{|source| source.manifests(name)}.flatten(1)
14
+ end
15
+ end
10
16
 
11
- attr_reader :resolver, :source, :dependency_source_map
17
+ attr_reader :resolver, :spec, :dependency_source_map
12
18
 
13
19
  def initialize(resolver, spec)
14
20
  @resolver = resolver
15
- @source = spec.source
21
+ @spec = spec
16
22
  @dependency_source_map = Hash[spec.dependencies.map{|d| [d.name, d.source]}]
17
23
  @level = 0
18
24
  end
@@ -25,11 +31,15 @@ module Librarian
25
31
  resolution ? resolution[1] : nil
26
32
  end
27
33
 
34
+ def default_source
35
+ MultiSource.new(spec.sources)
36
+ end
37
+
28
38
  def sourced_dependency_for(dependency)
29
39
  return dependency if dependency.source
30
40
 
31
- s = dependency_source_map[dependency.name] || source
32
- Dependency.new(dependency.name, dependency.requirement, s)
41
+ source = dependency_source_map[dependency.name] || default_source
42
+ Dependency.new(dependency.name, dependency.requirement, source)
33
43
  end
34
44
 
35
45
  def recursive_resolve(dependencies, manifests, queue)
@@ -110,7 +120,7 @@ module Librarian
110
120
  end
111
121
 
112
122
  def debug
113
- super { ' ' * @level + yield }
123
+ environment.logger.debug { ' ' * @level + yield }
114
124
  end
115
125
 
116
126
  def environment
@@ -52,6 +52,8 @@ module Librarian
52
52
 
53
53
  @repository = nil
54
54
  @repository_cache_path = nil
55
+
56
+ ref.kind_of?(String) or raise TypeError, "ref must be a String"
55
57
  end
56
58
 
57
59
  def to_s