librarian-puppet 0.0.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/LICENSE +20 -0
- data/README.md +0 -0
- data/bin/librarian-puppet +9 -0
- data/lib/librarian/puppet.rb +7 -0
- data/lib/librarian/puppet/cli.rb +30 -0
- data/lib/librarian/puppet/dsl.rb +14 -0
- data/lib/librarian/puppet/environment.rb +18 -0
- data/lib/librarian/puppet/extension.rb +9 -0
- data/lib/librarian/puppet/source.rb +2 -0
- data/lib/librarian/puppet/source/git.rb +12 -0
- data/lib/librarian/puppet/source/local.rb +46 -0
- data/lib/librarian/puppet/source/path.rb +12 -0
- data/lib/librarian/puppet/templates/Puppetfile +6 -0
- data/librarian-puppet.gemspec +126 -0
- data/vendor/librarian/.rspec +1 -0
- data/vendor/librarian/.travis.yml +6 -0
- data/vendor/librarian/CHANGELOG.md +168 -0
- data/vendor/librarian/Gemfile +4 -0
- data/vendor/librarian/MIT-LICENSE +20 -0
- data/vendor/librarian/README.md +318 -0
- data/vendor/librarian/Rakefile +34 -0
- data/vendor/librarian/bin/librarian-chef +7 -0
- data/vendor/librarian/bin/librarian-mock +7 -0
- data/vendor/librarian/config/cucumber.yaml +1 -0
- data/vendor/librarian/features/chef/cli/init.feature +10 -0
- data/vendor/librarian/features/chef/cli/install.feature +64 -0
- data/vendor/librarian/features/chef/cli/show.feature +65 -0
- data/vendor/librarian/features/chef/cli/version.feature +11 -0
- data/vendor/librarian/features/support/env.rb +9 -0
- data/vendor/librarian/lib/librarian.rb +19 -0
- data/vendor/librarian/lib/librarian/action.rb +5 -0
- data/vendor/librarian/lib/librarian/action/base.rb +22 -0
- data/vendor/librarian/lib/librarian/action/clean.rb +44 -0
- data/vendor/librarian/lib/librarian/action/ensure.rb +24 -0
- data/vendor/librarian/lib/librarian/action/install.rb +95 -0
- data/vendor/librarian/lib/librarian/action/resolve.rb +81 -0
- data/vendor/librarian/lib/librarian/action/update.rb +78 -0
- data/vendor/librarian/lib/librarian/chef.rb +1 -0
- data/vendor/librarian/lib/librarian/chef/cli.rb +27 -0
- data/vendor/librarian/lib/librarian/chef/dsl.rb +15 -0
- data/vendor/librarian/lib/librarian/chef/environment.rb +19 -0
- data/vendor/librarian/lib/librarian/chef/extension.rb +9 -0
- data/vendor/librarian/lib/librarian/chef/integration/knife.rb +42 -0
- data/vendor/librarian/lib/librarian/chef/manifest_reader.rb +47 -0
- data/vendor/librarian/lib/librarian/chef/source.rb +3 -0
- data/vendor/librarian/lib/librarian/chef/source/git.rb +12 -0
- data/vendor/librarian/lib/librarian/chef/source/local.rb +63 -0
- data/vendor/librarian/lib/librarian/chef/source/path.rb +12 -0
- data/vendor/librarian/lib/librarian/chef/source/site.rb +434 -0
- data/vendor/librarian/lib/librarian/chef/templates/Cheffile +15 -0
- data/vendor/librarian/lib/librarian/cli.rb +175 -0
- data/vendor/librarian/lib/librarian/cli/manifest_presenter.rb +79 -0
- data/vendor/librarian/lib/librarian/dependency.rb +95 -0
- data/vendor/librarian/lib/librarian/dsl.rb +105 -0
- data/vendor/librarian/lib/librarian/dsl/receiver.rb +48 -0
- data/vendor/librarian/lib/librarian/dsl/target.rb +176 -0
- data/vendor/librarian/lib/librarian/environment.rb +129 -0
- data/vendor/librarian/lib/librarian/error.rb +4 -0
- data/vendor/librarian/lib/librarian/helpers.rb +13 -0
- data/vendor/librarian/lib/librarian/helpers/debug.rb +35 -0
- data/vendor/librarian/lib/librarian/lockfile.rb +33 -0
- data/vendor/librarian/lib/librarian/lockfile/compiler.rb +70 -0
- data/vendor/librarian/lib/librarian/lockfile/parser.rb +104 -0
- data/vendor/librarian/lib/librarian/manifest.rb +140 -0
- data/vendor/librarian/lib/librarian/manifest_set.rb +153 -0
- data/vendor/librarian/lib/librarian/mock.rb +1 -0
- data/vendor/librarian/lib/librarian/mock/cli.rb +19 -0
- data/vendor/librarian/lib/librarian/mock/dsl.rb +15 -0
- data/vendor/librarian/lib/librarian/mock/environment.rb +24 -0
- data/vendor/librarian/lib/librarian/mock/extension.rb +9 -0
- data/vendor/librarian/lib/librarian/mock/source.rb +1 -0
- data/vendor/librarian/lib/librarian/mock/source/mock.rb +97 -0
- data/vendor/librarian/lib/librarian/mock/source/mock/registry.rb +83 -0
- data/vendor/librarian/lib/librarian/resolution.rb +44 -0
- data/vendor/librarian/lib/librarian/resolver.rb +73 -0
- data/vendor/librarian/lib/librarian/resolver/implementation.rb +122 -0
- data/vendor/librarian/lib/librarian/source.rb +2 -0
- data/vendor/librarian/lib/librarian/source/git.rb +150 -0
- data/vendor/librarian/lib/librarian/source/git/repository.rb +213 -0
- data/vendor/librarian/lib/librarian/source/local.rb +51 -0
- data/vendor/librarian/lib/librarian/source/path.rb +74 -0
- data/vendor/librarian/lib/librarian/spec.rb +13 -0
- data/vendor/librarian/lib/librarian/spec_change_set.rb +170 -0
- data/vendor/librarian/lib/librarian/specfile.rb +22 -0
- data/vendor/librarian/lib/librarian/support/abstract_method.rb +21 -0
- data/vendor/librarian/lib/librarian/ui.rb +64 -0
- data/vendor/librarian/lib/librarian/version.rb +3 -0
- data/vendor/librarian/librarian.gemspec +33 -0
- data/vendor/librarian/spec/functional/chef/source/git_spec.rb +432 -0
- data/vendor/librarian/spec/functional/chef/source/site_spec.rb +215 -0
- data/vendor/librarian/spec/unit/action/base_spec.rb +18 -0
- data/vendor/librarian/spec/unit/action/clean_spec.rb +102 -0
- data/vendor/librarian/spec/unit/action/ensure_spec.rb +37 -0
- data/vendor/librarian/spec/unit/action/install_spec.rb +111 -0
- data/vendor/librarian/spec/unit/dependency_spec.rb +30 -0
- data/vendor/librarian/spec/unit/dsl_spec.rb +194 -0
- data/vendor/librarian/spec/unit/environment_spec.rb +9 -0
- data/vendor/librarian/spec/unit/lockfile/parser_spec.rb +162 -0
- data/vendor/librarian/spec/unit/lockfile_spec.rb +65 -0
- data/vendor/librarian/spec/unit/manifest_set_spec.rb +202 -0
- data/vendor/librarian/spec/unit/manifest_spec.rb +30 -0
- data/vendor/librarian/spec/unit/mock/source/mock_spec.rb +22 -0
- data/vendor/librarian/spec/unit/resolver_spec.rb +192 -0
- data/vendor/librarian/spec/unit/source/git_spec.rb +29 -0
- data/vendor/librarian/spec/unit/spec_change_set_spec.rb +169 -0
- metadata +163 -0
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'librarian/specfile'
|
2
|
+
|
3
|
+
module Librarian
|
4
|
+
class Dsl
|
5
|
+
class Receiver
|
6
|
+
|
7
|
+
def initialize(target)
|
8
|
+
singleton_class = class << self; self end
|
9
|
+
singleton_class.class_eval do
|
10
|
+
define_method(target.dependency_name) do |*args, &block|
|
11
|
+
target.dependency(*args, &block)
|
12
|
+
end
|
13
|
+
define_method(:source) do |*args, &block|
|
14
|
+
target.source(*args, &block)
|
15
|
+
end
|
16
|
+
target.source_types.each do |source_type|
|
17
|
+
name = source_type[0]
|
18
|
+
define_method(name) do |*args, &block|
|
19
|
+
target.source(name, *args, &block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def run(specfile = nil)
|
26
|
+
if block_given?
|
27
|
+
instance_eval(&Proc.new)
|
28
|
+
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
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def instance_binding
|
43
|
+
binding
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'librarian/helpers/debug'
|
2
|
+
|
3
|
+
require 'librarian/spec'
|
4
|
+
|
5
|
+
module Librarian
|
6
|
+
class Dsl
|
7
|
+
class Target
|
8
|
+
|
9
|
+
include Helpers::Debug
|
10
|
+
|
11
|
+
class SourceShortcutDefinitionReceiver
|
12
|
+
def initialize(target)
|
13
|
+
singleton_class = class << self; self end
|
14
|
+
singleton_class.class_eval do
|
15
|
+
define_method(:source) do |options|
|
16
|
+
target.source_from_options(options)
|
17
|
+
end
|
18
|
+
target.source_types.each do |source_type|
|
19
|
+
name = source_type[0]
|
20
|
+
define_method(name) do |*args|
|
21
|
+
args.push({}) unless Hash === args.last
|
22
|
+
target.source_from_params(name, *args)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
SCOPABLES = [:sources]
|
30
|
+
|
31
|
+
attr_accessor :dsl
|
32
|
+
private :dsl=
|
33
|
+
|
34
|
+
attr_reader :dependency_name, :dependency_type
|
35
|
+
attr_reader :source_types, :source_types_map, :source_types_reverse_map, :source_type_names, :source_shortcuts
|
36
|
+
attr_reader :dependencies, :source_cache, *SCOPABLES
|
37
|
+
|
38
|
+
def initialize(dsl)
|
39
|
+
self.dsl = dsl
|
40
|
+
@dependency_name = dsl.dependency_name
|
41
|
+
@dependency_type = dsl.dependency_type
|
42
|
+
@source_types = dsl.source_types
|
43
|
+
@source_types_map = Hash[source_types]
|
44
|
+
@source_types_reverse_map = Hash[source_types.map{|pair| a, b = pair ; [b, a]}]
|
45
|
+
@source_type_names = source_types.map{|t| t[0]}
|
46
|
+
@source_cache = {}
|
47
|
+
@source_shortcuts = {}
|
48
|
+
@dependencies = []
|
49
|
+
SCOPABLES.each do |scopable|
|
50
|
+
instance_variable_set(:"@#{scopable}", [])
|
51
|
+
end
|
52
|
+
dsl.source_shortcuts.each do |name, param|
|
53
|
+
define_source_shortcut(name, param)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def to_spec
|
58
|
+
Spec.new(@sources.first, @dependencies)
|
59
|
+
end
|
60
|
+
|
61
|
+
def dependency(name, *args)
|
62
|
+
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
|
67
|
+
dep = dependency_type.new(name, args, source)
|
68
|
+
@dependencies << dep
|
69
|
+
end
|
70
|
+
|
71
|
+
def source(name, param = nil, options = nil, &block)
|
72
|
+
if !(Hash === name) && [Array, Hash, Proc].any?{|c| c === param} && !options && !block
|
73
|
+
define_source_shortcut(name, param)
|
74
|
+
elsif !(Hash === name) && !param && !options
|
75
|
+
source = source_shortcuts[name]
|
76
|
+
scope_or_directive(block) do
|
77
|
+
@sources = @sources.dup << source
|
78
|
+
end
|
79
|
+
else
|
80
|
+
name, param, options = *normalize_source_options(name, param, options || {})
|
81
|
+
source = source_from_params(name, param, options)
|
82
|
+
scope_or_directive(block) do
|
83
|
+
@sources = @sources.dup << source
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def precache_sources(sources)
|
89
|
+
sources.each do |source|
|
90
|
+
key = [source_types_reverse_map[source.class], *source.to_spec_args]
|
91
|
+
source_cache[key] = source
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def scope
|
96
|
+
currents = { }
|
97
|
+
SCOPABLES.each do |scopable|
|
98
|
+
currents[scopable] = instance_variable_get(:"@#{scopable}").dup
|
99
|
+
end
|
100
|
+
yield
|
101
|
+
ensure
|
102
|
+
SCOPABLES.reverse.each do |scopable|
|
103
|
+
instance_variable_set(:"@#{scopable}", currents[scopable])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def scope_or_directive(scoped_block = nil)
|
108
|
+
unless scoped_block
|
109
|
+
yield
|
110
|
+
else
|
111
|
+
scope do
|
112
|
+
yield
|
113
|
+
scoped_block.call
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def normalize_source_options(name, param, options)
|
119
|
+
if name.is_a?(Hash)
|
120
|
+
extract_source_parts(name)
|
121
|
+
else
|
122
|
+
[name, param, options]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def extract_source_parts(options)
|
127
|
+
if name = source_type_names.find{|name| options.key?(name)}
|
128
|
+
options = options.dup
|
129
|
+
param = options.delete(name)
|
130
|
+
[name, param, options]
|
131
|
+
else
|
132
|
+
nil
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def source_from_options(options)
|
137
|
+
if options[:source]
|
138
|
+
source_shortcuts[options[:source]]
|
139
|
+
elsif source_parts = extract_source_parts(options)
|
140
|
+
source_from_params(*source_parts)
|
141
|
+
else
|
142
|
+
nil
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def source_from_params(name, param, options)
|
147
|
+
source_cache[[name, param, options]] ||= begin
|
148
|
+
type = source_types_map[name]
|
149
|
+
type.from_spec_args(environment, param, options)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def source_from_source_shortcut_definition(definition)
|
154
|
+
case definition
|
155
|
+
when Array
|
156
|
+
source_from_params(*definition)
|
157
|
+
when Hash
|
158
|
+
source_from_options(definition)
|
159
|
+
when Proc
|
160
|
+
receiver = SourceShortcutDefinitionReceiver.new(self)
|
161
|
+
receiver.instance_eval(&definition)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def define_source_shortcut(name, definition)
|
166
|
+
source = source_from_source_shortcut_definition(definition)
|
167
|
+
source_shortcuts[name] = source
|
168
|
+
end
|
169
|
+
|
170
|
+
def environment
|
171
|
+
dsl.environment
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
require "librarian/helpers/debug"
|
4
|
+
require "librarian/support/abstract_method"
|
5
|
+
|
6
|
+
require "librarian/error"
|
7
|
+
require "librarian/lockfile"
|
8
|
+
require "librarian/specfile"
|
9
|
+
require "librarian/resolver"
|
10
|
+
require "librarian/dsl"
|
11
|
+
require "librarian/source"
|
12
|
+
|
13
|
+
module Librarian
|
14
|
+
class Environment
|
15
|
+
|
16
|
+
include Support::AbstractMethod
|
17
|
+
include Helpers::Debug
|
18
|
+
|
19
|
+
attr_accessor :ui
|
20
|
+
|
21
|
+
abstract_method :specfile_name, :dsl_class, :install_path
|
22
|
+
|
23
|
+
def initialize(options = { })
|
24
|
+
@project_path = options[:project_path]
|
25
|
+
@specfile_name = options[:specfile_name]
|
26
|
+
end
|
27
|
+
|
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
|
35
|
+
end
|
36
|
+
|
37
|
+
def project_path?(path)
|
38
|
+
path.join(config_name).directory? ||
|
39
|
+
path.join(specfile_name).file? ||
|
40
|
+
path.dirname == path
|
41
|
+
end
|
42
|
+
|
43
|
+
def default_specfile_name
|
44
|
+
@default_specfile_name ||= begin
|
45
|
+
capped = adapter_name.capitalize
|
46
|
+
"#{capped}file"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def specfile_name
|
51
|
+
@specfile_name ||= default_specfile_name
|
52
|
+
end
|
53
|
+
|
54
|
+
def specfile_path
|
55
|
+
project_path.join(specfile_name)
|
56
|
+
end
|
57
|
+
|
58
|
+
def specfile
|
59
|
+
Specfile.new(self, specfile_path)
|
60
|
+
end
|
61
|
+
|
62
|
+
def adapter_name
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
|
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
|
+
def lockfile_name
|
75
|
+
"#{specfile_name}.lock"
|
76
|
+
end
|
77
|
+
|
78
|
+
def lockfile_path
|
79
|
+
project_path.join(lockfile_name)
|
80
|
+
end
|
81
|
+
|
82
|
+
def lockfile
|
83
|
+
Lockfile.new(self, lockfile_path)
|
84
|
+
end
|
85
|
+
|
86
|
+
def ephemeral_lockfile
|
87
|
+
Lockfile.new(self, nil)
|
88
|
+
end
|
89
|
+
|
90
|
+
def resolver
|
91
|
+
Resolver.new(self)
|
92
|
+
end
|
93
|
+
|
94
|
+
def cache_path
|
95
|
+
project_path.join("tmp/librarian/cache")
|
96
|
+
end
|
97
|
+
|
98
|
+
def scratch_path
|
99
|
+
project_path.join("tmp/librarian/scratch")
|
100
|
+
end
|
101
|
+
|
102
|
+
def project_relative_path_to(path)
|
103
|
+
Pathname.new(path).relative_path_from(project_path)
|
104
|
+
end
|
105
|
+
|
106
|
+
def spec
|
107
|
+
specfile.read
|
108
|
+
end
|
109
|
+
|
110
|
+
def lock
|
111
|
+
lockfile.read
|
112
|
+
end
|
113
|
+
|
114
|
+
def dsl(*args, &block)
|
115
|
+
dsl_class.run(self, *args, &block)
|
116
|
+
end
|
117
|
+
|
118
|
+
def dsl_class
|
119
|
+
self.class.name.split("::")[0 ... -1].inject(Object, &:const_get)::Dsl
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def environment
|
125
|
+
self
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Librarian
|
2
|
+
module Helpers
|
3
|
+
extend self
|
4
|
+
|
5
|
+
# [active_support/core_ext/string/strip]
|
6
|
+
def strip_heredoc(string)
|
7
|
+
indent = string.scan(/^[ \t]*(?=\S)/).min
|
8
|
+
indent = indent.respond_to?(:size) ? indent.size : 0
|
9
|
+
string.gsub(/^[ \t]{#{indent}}/, '')
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'librarian/support/abstract_method'
|
2
|
+
|
3
|
+
module Librarian
|
4
|
+
module Helpers
|
5
|
+
module Debug
|
6
|
+
|
7
|
+
include Support::AbstractMethod
|
8
|
+
|
9
|
+
LIBRARIAN_PATH = Pathname.new('../../../../').expand_path(__FILE__)
|
10
|
+
|
11
|
+
abstract_method :environment
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def relative_path_to(path)
|
16
|
+
environment.project_relative_path_to(path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def debug
|
20
|
+
if ui = environment.ui
|
21
|
+
if ui.respond_to? :debug_line_numbers and ui.debug_line_numbers
|
22
|
+
loc = caller.find{|l| !(l =~ /in `debug'$/)}
|
23
|
+
if loc =~ /^(.+):(\d+):in `(.+)'$/
|
24
|
+
loc = "#{Pathname.new($1).relative_path_from(LIBRARIAN_PATH)}:#{$2}:in `#{$3}'"
|
25
|
+
end
|
26
|
+
ui.debug { "[Librarian] #{yield} [#{loc}]" }
|
27
|
+
else
|
28
|
+
ui.debug { "[Librarian] #{yield}" }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'librarian/helpers/debug'
|
2
|
+
|
3
|
+
require 'librarian/lockfile/compiler'
|
4
|
+
require 'librarian/lockfile/parser'
|
5
|
+
|
6
|
+
module Librarian
|
7
|
+
class Lockfile
|
8
|
+
|
9
|
+
include Helpers::Debug
|
10
|
+
|
11
|
+
attr_accessor :environment
|
12
|
+
private :environment=
|
13
|
+
attr_reader :path
|
14
|
+
|
15
|
+
def initialize(environment, path)
|
16
|
+
self.environment = environment
|
17
|
+
@path = path
|
18
|
+
end
|
19
|
+
|
20
|
+
def save(resolution)
|
21
|
+
Compiler.new(environment).compile(resolution)
|
22
|
+
end
|
23
|
+
|
24
|
+
def load(string)
|
25
|
+
Parser.new(environment).parse(string)
|
26
|
+
end
|
27
|
+
|
28
|
+
def read
|
29
|
+
load(path.read)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'librarian/helpers/debug'
|
2
|
+
|
3
|
+
module Librarian
|
4
|
+
class Lockfile
|
5
|
+
class Compiler
|
6
|
+
|
7
|
+
include Helpers::Debug
|
8
|
+
|
9
|
+
attr_accessor :environment
|
10
|
+
private :environment=
|
11
|
+
|
12
|
+
def initialize(environment)
|
13
|
+
self.environment = environment
|
14
|
+
end
|
15
|
+
|
16
|
+
def compile(resolution)
|
17
|
+
out = StringIO.new
|
18
|
+
save_sources(out, resolution.manifests)
|
19
|
+
save_dependencies(out, resolution.dependencies)
|
20
|
+
out.string
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def save_sources(out, manifests)
|
26
|
+
dsl_class.source_types.map{|t| t[1]}.each do |type|
|
27
|
+
type_manifests = manifests.select{|m| type === m.source}
|
28
|
+
sources = type_manifests.map{|m| m.source}.uniq.sort_by{|s| s.to_s}
|
29
|
+
sources.each do |source|
|
30
|
+
source_manifests = type_manifests.select{|m| source == m.source}
|
31
|
+
save_source(out, source, source_manifests)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def save_source(out, source, manifests)
|
37
|
+
out.puts "#{source.class.lock_name}"
|
38
|
+
options = source.to_lock_options
|
39
|
+
remote = options.delete(:remote)
|
40
|
+
out.puts " remote: #{remote}"
|
41
|
+
options.to_a.sort_by{|a| a[0].to_s}.each do |o|
|
42
|
+
out.puts " #{o[0]}: #{o[1]}"
|
43
|
+
end
|
44
|
+
out.puts " specs:"
|
45
|
+
manifests.sort_by{|a| a.name}.each do |manifest|
|
46
|
+
out.puts " #{manifest.name} (#{manifest.version})"
|
47
|
+
manifest.dependencies.sort_by{|a| a.name}.each do |dependency|
|
48
|
+
out.puts " #{dependency.name} (#{dependency.requirement})"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
out.puts ""
|
52
|
+
end
|
53
|
+
|
54
|
+
def save_dependencies(out, dependencies)
|
55
|
+
out.puts "DEPENDENCIES"
|
56
|
+
dependencies.sort_by{|a| a.name}.each do |d|
|
57
|
+
res = "#{d.name}"
|
58
|
+
res << " (#{d.requirement})" if d.requirement
|
59
|
+
out.puts " #{res}"
|
60
|
+
end
|
61
|
+
out.puts ""
|
62
|
+
end
|
63
|
+
|
64
|
+
def dsl_class
|
65
|
+
environment.dsl_class
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|