librarianp 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e5a06c0a6a47dda122deace8d00c4c84d7954c0
4
- data.tar.gz: 7dda5da1818865763613e09a2ccb3a1e306028df
3
+ metadata.gz: a318f3a8c81d302b411ab7c49a30516b919052d0
4
+ data.tar.gz: a6f81353d1114c4be9c0e800855c4111f45c5ad1
5
5
  SHA512:
6
- metadata.gz: ba9235a2eb1b29099b8c9e5b1bcacb0f49f71f2317f636de7985a6261a57596e966050692089c4072d459492a2df59ab1f3eb614d3cb22e66349133c04d755c0
7
- data.tar.gz: 2746710feb6e2eb489f922e5d3069ac2494096d686cb3f67ffd20e66461573b386c552bd7c8fae5cb2f1ed911ea0d97374b7799e3ca8fdca39fa423126fd99c9
6
+ metadata.gz: b8d8828d8a3691916a68ce07b538630d5aa84e87fda4bd49e9c177ea2dc882594acb240387720ae1c9a9ee92baf5b829c5e468eb815cfc32783f25803e531f07
7
+ data.tar.gz: c4ae9428382e90ae828e839a731848bc3b0277f9f590f321aee0c717412c7f2938aba9001e3b851a346f495dad88cbf38f6b29cac2801bd328b945bd60b47323
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- librarianp (0.5.1)
4
+ librarianp (0.6.0)
5
5
  thor (~> 0.15)
6
6
 
7
7
  GEM
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
1
+ 0.6.0
@@ -23,14 +23,14 @@ module Librarian
23
23
  manifests = changes.analyze
24
24
  end
25
25
 
26
- dupes = spec.dependencies.group_by{ |e| e.name }.select { |k, v| v.size > 1 }
27
- dupes = Hash[dupes] if dupes.is_a? Array # Ruby 1.8 support
28
- unless dupes.empty?
29
- raise Error, "Duplicated dependencies: #{dupes.values.flatten.map {|d| {d.name => d.source.to_s} }}"
26
+ spec.dependencies, duplicated = Dependency.remove_duplicate_dependencies(spec.dependencies)
27
+ duplicated.each do |name, dependencies_same_name|
28
+ environment.logger.info { "Dependency '#{name}' duplicated for module #{name}, merging: #{dependencies_same_name.map{|d| d.to_s}}" }
30
29
  end
31
30
 
32
31
  resolution = resolver.resolve(spec, manifests)
33
32
  persist_resolution(resolution)
33
+ resolution
34
34
  end
35
35
 
36
36
  private
@@ -185,6 +185,32 @@ module Librarian
185
185
  !consistent_with?(other)
186
186
  end
187
187
 
188
+ class << self
189
+ # merge dependencies with the same name into one
190
+ # with the source of the first one and merged requirements
191
+ def merge_dependencies(dependencies)
192
+ requirement = Dependency::Requirement.new(*dependencies.map{|d| d.requirement})
193
+ dependencies.last.class.new(dependencies.last.name, requirement, dependencies.last.source)
194
+ end
195
+
196
+ # Avoid duplicated dependencies with different sources or requirements
197
+ # Return [merged dependnecies, duplicates as a map by name]
198
+ def remove_duplicate_dependencies(dependencies)
199
+ uniq = []
200
+ duplicated = {}
201
+ dependencies_by_name = dependencies.group_by{|d| d.name}
202
+ dependencies_by_name.map do |name, dependencies_same_name|
203
+ if dependencies_same_name.size > 1
204
+ duplicated[name] = dependencies_same_name
205
+ uniq << merge_dependencies(dependencies_same_name)
206
+ else
207
+ uniq << dependencies_same_name.first
208
+ end
209
+ end
210
+ [uniq, duplicated]
211
+ end
212
+ end
213
+
188
214
  private
189
215
 
190
216
  def assert_name_valid!(name)
@@ -71,7 +71,7 @@ module Librarian
71
71
  end
72
72
 
73
73
  def specfile
74
- Specfile.new(self, specfile_path)
74
+ @specfile ||= Specfile.new(self, specfile_path)
75
75
  end
76
76
 
77
77
  def adapter_module
@@ -94,31 +94,10 @@ module Librarian
94
94
  end
95
95
 
96
96
  def fetch_dependencies!
97
- remove_duplicate_dependencies(name, source.fetch_dependencies(name, version, extra))
98
- end
99
-
100
- # merge dependencies with the same name into one
101
- # with the source of the first one and merged requirements
102
- def merge_dependencies(dependencies)
103
- requirement = Dependency::Requirement.new(*dependencies.map{|d| d.requirement})
104
- dependencies.first.class.new(dependencies.first.name, requirement, dependencies.first.source)
105
- end
106
-
107
- # Avoid duplicated dependencies with different sources or requirements
108
- def remove_duplicate_dependencies(module_name, dependencies)
109
- uniq = []
110
- dependencies_by_name = dependencies.group_by{|d| d.name}
111
- dependencies_by_name.map do |name, dependencies_same_name|
112
- if dependencies_same_name.size > 1
113
- environment.logger.warn { "Dependency '#{name}' duplicated for module #{module_name}, trying to merge: #{dependencies_same_name.map{|d| d.to_s}}" }
114
- merged = merge_dependencies(dependencies_same_name)
115
- environment.logger.warn { "Dependency '#{name}' merged as #{merged}" }
116
- uniq << merged
117
- else
118
- uniq << dependencies_same_name.first
119
- end
97
+ dependencies, duplicated = Dependency.remove_duplicate_dependencies(source.fetch_dependencies(name, version, extra))
98
+ duplicated.each do |name, dependencies_same_name|
99
+ environment.logger.info { "Dependency '#{name}' duplicated for module #{module_name}, merging: #{dependencies_same_name.map{|d| d.to_s}}" }
120
100
  end
121
- uniq
122
101
  end
123
102
 
124
103
  def _normalize_version(version)
@@ -1,13 +1,15 @@
1
1
  require "librarian/environment"
2
+ require "librarian/ui"
2
3
  require "librarian/mock/dsl"
3
4
  require "librarian/mock/version"
5
+ require 'thor'
4
6
 
5
7
  module Librarian
6
8
  module Mock
7
9
  class Environment < Environment
8
10
 
9
- def install_path
10
- nil
11
+ def ui
12
+ Librarian::UI::Shell.new(Thor::Shell::Basic.new)
11
13
  end
12
14
 
13
15
  def registry(options = nil, &block)
@@ -107,7 +107,7 @@ module Librarian
107
107
  reference = "#{remote}/#{reference}"
108
108
  end
109
109
 
110
- command = %W(rev-list #{reference} -1)
110
+ command = %W(rev-parse #{reference}^{commit} --quiet)
111
111
  run!(command, :chdir => true).strip
112
112
  end
113
113
 
@@ -2,7 +2,6 @@ module Librarian
2
2
  class Spec
3
3
 
4
4
  attr_accessor :sources, :dependencies, :exclusions
5
- private :sources=, :dependencies=, :exclusions=
6
5
 
7
6
  def initialize(sources, dependencies, exclusions = [])
8
7
  self.sources = sources
@@ -12,7 +12,7 @@ module Librarian
12
12
  end
13
13
 
14
14
  def read(precache_sources = [])
15
- environment.dsl(path, precache_sources)
15
+ @spec ||= environment.dsl(path, precache_sources)
16
16
  end
17
17
 
18
18
  end
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: librarianp 0.5.1 ruby lib
2
+ # stub: librarianp 0.6.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "librarianp"
6
- s.version = "0.5.1"
6
+ s.version = "0.6.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Jay Feldblum", "Carlos Sanchez"]
11
- s.date = "2015-03-02"
11
+ s.date = "2015-03-06"
12
12
  s.description = "A Framework for Bundlers, used by librarian-puppet."
13
13
  s.email = ["y_feldblum@yahoo.com", "carlos@apache.org"]
14
14
  s.files = [".gitignore", ".rspec", ".travis.yml", "CHANGELOG.md", "Gemfile", "Gemfile.lock", "LICENSE.txt", "README.md", "Rakefile", "VERSION", "lib/librarian.rb", "lib/librarian/action.rb", "lib/librarian/action/base.rb", "lib/librarian/action/clean.rb", "lib/librarian/action/ensure.rb", "lib/librarian/action/install.rb", "lib/librarian/action/persist_resolution_mixin.rb", "lib/librarian/action/resolve.rb", "lib/librarian/action/update.rb", "lib/librarian/algorithms.rb", "lib/librarian/cli.rb", "lib/librarian/cli/manifest_presenter.rb", "lib/librarian/config.rb", "lib/librarian/config/database.rb", "lib/librarian/config/file_source.rb", "lib/librarian/config/hash_source.rb", "lib/librarian/config/source.rb", "lib/librarian/dependency.rb", "lib/librarian/dsl.rb", "lib/librarian/dsl/receiver.rb", "lib/librarian/dsl/target.rb", "lib/librarian/environment.rb", "lib/librarian/environment/runtime_cache.rb", "lib/librarian/error.rb", "lib/librarian/helpers.rb", "lib/librarian/linter/source_linter.rb", "lib/librarian/lockfile.rb", "lib/librarian/lockfile/compiler.rb", "lib/librarian/lockfile/parser.rb", "lib/librarian/logger.rb", "lib/librarian/manifest.rb", "lib/librarian/manifest/pre_release_version.rb", "lib/librarian/manifest/version.rb", "lib/librarian/manifest_set.rb", "lib/librarian/mock.rb", "lib/librarian/mock/cli.rb", "lib/librarian/mock/dsl.rb", "lib/librarian/mock/environment.rb", "lib/librarian/mock/extension.rb", "lib/librarian/mock/source.rb", "lib/librarian/mock/source/mock.rb", "lib/librarian/mock/source/mock/registry.rb", "lib/librarian/mock/version.rb", "lib/librarian/posix.rb", "lib/librarian/resolution.rb", "lib/librarian/resolver.rb", "lib/librarian/resolver/implementation.rb", "lib/librarian/rspec/support/cli_macro.rb", "lib/librarian/source.rb", "lib/librarian/source/basic_api.rb", "lib/librarian/source/git.rb", "lib/librarian/source/git/repository.rb", "lib/librarian/source/local.rb", "lib/librarian/source/path.rb", "lib/librarian/spec.rb", "lib/librarian/spec_change_set.rb", "lib/librarian/specfile.rb", "lib/librarian/support/abstract_method.rb", "lib/librarian/ui.rb", "lib/librarian/version.rb", "librarian.gemspec", "spec/functional/cli_spec.rb", "spec/functional/posix_spec.rb", "spec/functional/source/git/repository_spec.rb", "spec/functional/source/git_spec.rb", "spec/support/fakefs.rb", "spec/support/method_patch_macro.rb", "spec/support/project_path_macro.rb", "spec/support/with_env_macro.rb", "spec/unit/action/base_spec.rb", "spec/unit/action/clean_spec.rb", "spec/unit/action/ensure_spec.rb", "spec/unit/action/install_spec.rb", "spec/unit/action/resolve_spec.rb", "spec/unit/algorithms_spec.rb", "spec/unit/config/database_spec.rb", "spec/unit/dependency/requirement_spec.rb", "spec/unit/dependency_spec.rb", "spec/unit/dsl_spec.rb", "spec/unit/environment/runtime_cache_spec.rb", "spec/unit/environment_spec.rb", "spec/unit/lockfile/parser_spec.rb", "spec/unit/lockfile_spec.rb", "spec/unit/manifest/version_spec.rb", "spec/unit/manifest_set_spec.rb", "spec/unit/manifest_spec.rb", "spec/unit/mock/environment_spec.rb", "spec/unit/mock/source/mock_spec.rb", "spec/unit/resolver_spec.rb", "spec/unit/source/git_spec.rb", "spec/unit/spec_change_set_spec.rb"]
@@ -1,27 +1,44 @@
1
1
  require "librarian/error"
2
+ require "librarian/logger"
2
3
  require "librarian/action/resolve"
4
+ require "librarian/mock/environment"
3
5
  require "librarian/mock/source"
4
6
 
5
7
  module Librarian
6
8
  describe Action::Resolve do
7
9
 
8
10
  let(:options) { {} }
9
- let(:spec) { double() }
10
- let(:env) { double(:specfile => double(:read => spec)) }
11
+ let(:spec) { Spec.new([], dependencies, []) }
12
+ let(:env) { Librarian::Mock::Environment.new }
11
13
  let(:action) { described_class.new(env, options) }
14
+ let(:source1) { Librarian::Mock::Source::Mock.new(env, "source1", {}) }
15
+ let(:source2) { Librarian::Mock::Source::Mock.new(env, "source2", {}) }
16
+
17
+ before do
18
+ env.stub(:specfile => double(:read => spec))
19
+ end
12
20
 
13
21
  describe "#run" do
14
22
 
15
23
  describe "behavior" do
16
24
 
17
- describe "fail with duplicated dependencies" do
25
+ describe "merge duplicated dependencies" do
18
26
  let(:options) { {:force => true} }
19
- let(:dependency) { Dependency.new('dependency_name', '1.0.0', nil ) }
20
- let(:dependencies) { [ dependency, dependency ] }
21
- let(:spec) { double(:dependencies => dependencies) }
27
+ let(:dependency1) { Dependency.new('dependency_name', '1.0.0', source1) }
28
+ let(:dependency2) { Dependency.new('dependency_name', '1.0.0', source2) }
29
+ let(:dependencies) { [ dependency1, dependency2 ] }
30
+ let(:manifest) do
31
+ m = Manifest.new(source1, dependency1.name)
32
+ m.version = '1.0.0'
33
+ m.dependencies = []
34
+ m
35
+ end
22
36
 
23
- it "should fail with duplicated dependencies" do
24
- expect { action.run }.to raise_error(Error, /^Duplicated dependencies: /)
37
+ it "should merge duplicated dependencies" do
38
+ Dependency.any_instance.stub(:manifests => [manifest])
39
+ action.stub(:persist_resolution)
40
+ resolution = action.run
41
+ expect(resolution.dependencies).to eq([dependency2])
25
42
  end
26
43
 
27
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librarianp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Feldblum
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-02 00:00:00.000000000 Z
12
+ date: 2015-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor