librarian 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e028910687d6a6448f8f51929c7048701c10c768
4
+ data.tar.gz: f3d3ea0d6bffa41369b7bd224a2a93d5fe314fc8
5
+ SHA512:
6
+ metadata.gz: b5b069d30eb1d8a067d7f7cd95d04e92570776e4ee7f08f9a6c4d572b0f3bc25026f5324d5686933bafed0e96247e23bea499f90c49a7c93397abc14241ddc9d
7
+ data.tar.gz: 02c8c5b25f217db0d2188cc2e4f48675fce74f9ff29ceb1fc30ea894c5ca511fd61c4e59a9e40a76c863c3307eeea5fa2f8344f281db086b3a4ce7d2ae158383
@@ -1,5 +1,5 @@
1
1
  language: ruby
2
- script: rspec spec
2
+ script: rspec spec -b
3
3
  rvm:
4
4
  - 1.8.7
5
5
  - 1.9.2
@@ -12,8 +12,4 @@ rvm:
12
12
  - ruby-head
13
13
  matrix:
14
14
  allow_failures:
15
- - rvm: rbx-18mode
16
- - rvm: rbx-19mode
17
- - rvm: jruby-18mode
18
- - rvm: jruby-19mode
19
15
  - rvm: ruby-head
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.1.1
4
+
5
+ * \#147. Handle the case where HOME is not in the environment. Thanks @bradleyd.
6
+
7
+ * \#140. Properly handle the failure to clone a git repository. Avoid wiping out
8
+ the host project's changes.
9
+
10
+ * \#127. Support Rubinius and JRuby, including when shelling out to system
11
+ commands.
12
+
13
+ * \#144. Allow running the test suite with a simple `rake`. Thanks @nickhammond.
14
+
3
15
  ## 0.1.0
4
16
 
5
17
  * Extract the chef adapter to its own gem.
data/README.md CHANGED
@@ -22,7 +22,11 @@ Ensure the gem dependencies are installed:
22
22
 
23
23
  $ bundle
24
24
 
25
- Run the tests:
25
+ Run the tests with the default rake task:
26
+
27
+ $ [bundle exec] rake
28
+
29
+ or directly with the rspec command:
26
30
 
27
31
  $ [bundle exec] rspec spec
28
32
 
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'bundler'
2
+ require 'rspec/core/rake_task'
2
3
 
3
4
  module Bundler
4
5
  class GemHelper
@@ -21,3 +22,7 @@ module Bundler
21
22
  end
22
23
 
23
24
  Bundler::GemHelper.install_tasks
25
+
26
+ RSpec::Core::RakeTask.new('spec')
27
+ task :default => :spec
28
+
@@ -8,7 +8,7 @@ module Librarian
8
8
  private
9
9
 
10
10
  def persist_resolution(resolution)
11
- resolution.correct? or raise Error,
11
+ resolution && resolution.correct? or raise Error,
12
12
  "Could not resolve the dependencies."
13
13
 
14
14
  lockfile_text = lockfile.save(resolution)
@@ -183,13 +183,14 @@ module Librarian
183
183
  debug { "Rubinius Version: #{Rubinius::VERSION}" } if defined?(Rubinius)
184
184
  debug { "JRuby Version: #{JRUBY_VERSION}" } if defined?(JRUBY_VERSION)
185
185
  debug { "Rubygems Version: #{Gem::VERSION}" }
186
- debug { "Librarian Version: #{VERSION}" }
186
+ debug { "Librarian Version: #{environment.version}" }
187
187
  debug { "Librarian Adapter: #{environment.adapter_name}"}
188
+ debug { "Librarian Adapter Version: #{environment.adapter_version}" }
188
189
  debug { "Project: #{environment.project_path}" }
189
190
  debug { "Specfile: #{relative_path_to(environment.specfile_path)}" }
190
191
  debug { "Lockfile: #{relative_path_to(environment.lockfile_path)}" }
191
192
  debug { "Git: #{Source::Git::Repository.bin}" }
192
- debug { "Git Version: #{Source::Git::Repository.new(environment, environment.project_path).version(:silent => true)}" }
193
+ debug { "Git Version: #{Source::Git::Repository.git_version}" }
193
194
  debug { "Git Environment Variables:" }
194
195
  git_env = ENV.to_a.select{|(k, v)| k =~ /\AGIT/}.sort_by{|(k, v)| k}
195
196
  if git_env.empty?
@@ -1,6 +1,7 @@
1
1
  require "pathname"
2
2
  require 'net/http'
3
3
  require "uri"
4
+ require "etc"
4
5
 
5
6
  require "librarian/support/abstract_method"
6
7
 
@@ -26,9 +27,8 @@ module Librarian
26
27
  def initialize(options = { })
27
28
  @pwd = options.fetch(:pwd) { Dir.pwd }
28
29
  @env = options.fetch(:env) { ENV.to_hash }
29
- @home = options.fetch(:home) { File.expand_path("~") }
30
+ @home = options.fetch(:home) { default_home }
30
31
  @project_path = options[:project_path]
31
- @specfile_name = options[:specfile_name]
32
32
  end
33
33
 
34
34
  def logger
@@ -70,8 +70,19 @@ module Librarian
70
70
  Specfile.new(self, specfile_path)
71
71
  end
72
72
 
73
+ def adapter_module
74
+ implementation? or return
75
+ self.class.name.split("::")[0 ... -1].inject(Object, &:const_get)
76
+ end
77
+
73
78
  def adapter_name
74
- nil
79
+ implementation? or return
80
+ Helpers.camel_cased_to_dasherized(self.class.name.split("::")[-2])
81
+ end
82
+
83
+ def adapter_version
84
+ implementation? or return
85
+ adapter_module::VERSION
75
86
  end
76
87
 
77
88
  def lockfile_name
@@ -124,7 +135,7 @@ module Librarian
124
135
  end
125
136
 
126
137
  def dsl_class
127
- self.class.name.split("::")[0 ... -1].inject(Object, &:const_get)::Dsl
138
+ adapter_module::Dsl
128
139
  end
129
140
 
130
141
  def version
@@ -160,12 +171,7 @@ module Librarian
160
171
  end
161
172
 
162
173
  def net_http_class(host)
163
- return Net::HTTP if no_proxy?(host)
164
-
165
- @net_http_class ||= begin
166
- p = http_proxy_uri
167
- p ? Net::HTTP::Proxy(p.host, p.port, p.user, p.password) : Net::HTTP
168
- end
174
+ no_proxy?(host) ? Net::HTTP : net_http_default_class
169
175
  end
170
176
 
171
177
  private
@@ -174,13 +180,31 @@ module Librarian
174
180
  self
175
181
  end
176
182
 
177
- def no_proxy?(host)
178
- @no_proxy ||= begin
183
+ def implementation?
184
+ self.class != ::Librarian::Environment
185
+ end
186
+
187
+ def default_home
188
+ File.expand_path(ENV["HOME"] || Etc.getpwnam(Etc.getlogin).dir)
189
+ end
190
+
191
+ def no_proxy_list
192
+ @no_proxy_list ||= begin
179
193
  list = ENV['NO_PROXY'] || ENV['no_proxy'] || ""
180
194
  list.split(/\s*,\s*/) + %w(localhost 127.0.0.1)
181
195
  end
182
- @no_proxy.any? do |host_addr|
183
- host.match(Regexp.quote(host_addr)+'$')
196
+ end
197
+
198
+ def no_proxy?(host)
199
+ no_proxy_list.any? do |host_addr|
200
+ host.end_with?(host_addr)
201
+ end
202
+ end
203
+
204
+ def net_http_default_class
205
+ @net_http_default_class ||= begin
206
+ p = http_proxy_uri
207
+ p ? Net::HTTP::Proxy(p.host, p.port, p.user, p.password) : Net::HTTP
184
208
  end
185
209
  end
186
210
 
@@ -1,4 +1,10 @@
1
1
  module Librarian
2
+
3
+ # PRIVATE
4
+ #
5
+ # Adapters must not rely on these methods since they will change.
6
+ #
7
+ # Adapters requiring similar methods ought to re-implement them.
2
8
  module Helpers
3
9
  extend self
4
10
 
@@ -9,5 +15,15 @@ module Librarian
9
15
  string.gsub(/^[ \t]{#{indent}}/, '')
10
16
  end
11
17
 
18
+ # [active_support/inflector/methods]
19
+ def camel_cased_to_dasherized(camel_cased_word)
20
+ word = camel_cased_word.to_s.dup
21
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1-\2')
22
+ word.gsub!(/([a-z\d])([A-Z])/,'\1-\2')
23
+ word.downcase!
24
+ word
25
+ end
26
+
12
27
  end
28
+
13
29
  end
@@ -6,14 +6,6 @@ module Librarian
6
6
  module Mock
7
7
  class Environment < Environment
8
8
 
9
- def adapter_name
10
- "mock"
11
- end
12
-
13
- def adapter_version
14
- VERSION
15
- end
16
-
17
9
  def install_path
18
10
  nil
19
11
  end
@@ -0,0 +1,120 @@
1
+ require "open3"
2
+
3
+ require "librarian/error"
4
+
5
+ module Librarian
6
+ module Posix
7
+
8
+ class << self
9
+
10
+ # Cross-platform way of finding an executable in the $PATH.
11
+ #
12
+ # which('ruby') #=> /usr/bin/ruby
13
+ #
14
+ # From:
15
+ # https://github.com/defunkt/hub/commit/353031307e704d860826fc756ff0070be5e1b430#L2R173
16
+ def which(cmd)
17
+ exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(';') : ['']
18
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
19
+ path = File.expand_path(path)
20
+ exts.each do |ext|
21
+ exe = File.join(path, cmd + ext)
22
+ return exe if File.file?(exe) && File.executable?(exe)
23
+ end
24
+ end
25
+ nil
26
+ end
27
+
28
+ def which!(cmd)
29
+ which(cmd) or raise Error, "cannot find #{cmd}"
30
+ end
31
+
32
+ end
33
+
34
+ class CommandFailure < Error
35
+ class << self
36
+ def raise!(command, status, message)
37
+ ex = new(message)
38
+ ex.command = command
39
+ ex.status = status
40
+ ex.set_backtrace caller
41
+ raise ex
42
+ end
43
+ end
44
+
45
+ attr_accessor :command, :status
46
+ end
47
+
48
+ class << self
49
+
50
+ if defined?(JRuby) # built with jruby-1.7.4 in mind
51
+
52
+ def run!(command, options = { })
53
+ out, err = nil, nil
54
+ chdir = options[:chdir].to_s if options[:chdir]
55
+ env = options[:env] || { }
56
+ old_env = Hash[env.keys.map{|k| [k, ENV[k]]}]
57
+ begin
58
+ ENV.update env
59
+ Dir.chdir(chdir || Dir.pwd) do
60
+ IO.popen3(*command) do |i, o, e|
61
+ i.close
62
+ out, err = o.read, e.read
63
+ end
64
+ end
65
+ ensure
66
+ ENV.update old_env
67
+ end
68
+ $?.success? or CommandFailure.raise! command, $?, err
69
+ out
70
+ end
71
+
72
+ else
73
+
74
+ if RUBY_VERSION < "1.9"
75
+
76
+ def run!(command, options = { })
77
+ i, o, e = IO.pipe, IO.pipe, IO.pipe
78
+ pid = fork do
79
+ $stdin.reopen i[0]
80
+ $stdout.reopen o[1]
81
+ $stderr.reopen e[1]
82
+ [i[1], i[0], o[0], e[0]].each &:close
83
+ ENV.update options[:env] || { }
84
+ Dir.chdir options[:chdir].to_s if options[:chdir]
85
+ exec *command
86
+ end
87
+ [i[0], i[1], o[1], e[1]].each &:close
88
+ Process.waitpid pid
89
+ $?.success? or CommandFailure.raise! command, $?, e[0].read
90
+ o[0].read
91
+ ensure
92
+ [i, o, e].flatten(1).each{|io| io.close unless io.closed?}
93
+ end
94
+
95
+ else
96
+
97
+ def run!(command, options = { })
98
+ i, o, e = IO.pipe, IO.pipe, IO.pipe
99
+ opts = {:in => i[0], :out => o[1], :err => e[1]}
100
+ opts[:chdir] = options[:chdir].to_s if options[:chdir]
101
+ command = command.dup
102
+ command.unshift options[:env] || { }
103
+ command.push opts
104
+ pid = Process.spawn(*command)
105
+ [i[0], i[1], o[1], e[1]].each &:close
106
+ Process.waitpid pid
107
+ $?.success? or CommandFailure.raise! command, $?, e[0].read
108
+ o[0].read
109
+ ensure
110
+ [i, o, e].flatten(1).each{|io| io.close unless io.closed?}
111
+ end
112
+
113
+ end
114
+
115
+ end
116
+
117
+ end
118
+
119
+ end
120
+ end
@@ -2,6 +2,7 @@ require 'fileutils'
2
2
  require 'pathname'
3
3
  require 'digest'
4
4
 
5
+ require 'librarian/error'
5
6
  require 'librarian/source/basic_api'
6
7
  require 'librarian/source/git/repository'
7
8
  require 'librarian/source/local'
@@ -79,6 +80,7 @@ module Librarian
79
80
  repository.path.rmtree if repository.path.exist?
80
81
  repository.path.mkpath
81
82
  repository.clone!(uri)
83
+ raise Error, "failed to clone #{uri}" unless repository.git?
82
84
  end
83
85
  repository.reset_hard!
84
86
  repository.clean!
@@ -1,4 +1,4 @@
1
- require 'open3'
1
+ require "librarian/posix"
2
2
 
3
3
  module Librarian
4
4
  module Source
@@ -15,27 +15,12 @@ module Librarian
15
15
  end
16
16
 
17
17
  def bin
18
- @bin ||= which("git") or raise Error, "cannot find git"
18
+ @bin ||= Posix.which!("git")
19
19
  end
20
20
 
21
- private
22
-
23
- # Cross-platform way of finding an executable in the $PATH.
24
- #
25
- # which('ruby') #=> /usr/bin/ruby
26
- #
27
- # From:
28
- # https://github.com/defunkt/hub/commit/353031307e704d860826fc756ff0070be5e1b430#L2R173
29
- def which(cmd)
30
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
31
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
32
- path = File.expand_path(path)
33
- exts.each do |ext|
34
- exe = File.join(path, cmd + ext)
35
- return exe if File.file?(exe) && File.executable?(exe)
36
- end
37
- end
38
- nil
21
+ def git_version
22
+ command = %W[#{bin} version --silent]
23
+ Posix.run!(command).strip =~ /([.\d]+)$/ && $1
39
24
  end
40
25
  end
41
26
 
@@ -55,17 +40,6 @@ module Librarian
55
40
  "origin"
56
41
  end
57
42
 
58
- def version(options = { })
59
- version!(options).strip
60
- end
61
-
62
- def version!(options = { })
63
- silent = options.delete(:silent)
64
-
65
- command = %w(--version)
66
- run!(command, :silent => silent)
67
- end
68
-
69
43
  def clone!(repository_url)
70
44
  command = %W(clone #{repository_url} . --quiet)
71
45
  run!(command, :chdir => true)
@@ -143,32 +117,15 @@ module Librarian
143
117
  chdir = path.to_s if chdir == true
144
118
 
145
119
  silent = options.delete(:silent)
120
+ pwd = chdir || Dir.pwd
121
+ git_dir = File.join(path, ".git") if path
122
+ env = {"GIT_DIR" => git_dir}
146
123
 
147
124
  command = [bin]
148
125
  command.concat(args)
149
126
 
150
- maybe_within(chdir) do
151
- logging_command(command, :silent => silent) do
152
- run_command_internal(command)
153
- end
154
- end
155
- end
156
-
157
- def maybe_within(path)
158
- if path
159
- Dir.chdir(path) { with_env_var("GIT_DIR", nil) { yield } }
160
- else
161
- yield
162
- end
163
- end
164
-
165
- def with_env_var(name, value)
166
- original_value = ENV[name]
167
- begin
168
- ENV[name] = value
169
- yield
170
- ensure
171
- ENV[name] = original_value
127
+ logging_command(command, :silent => silent, :pwd => pwd) do
128
+ Posix.run!(command, :chdir => chdir, :env => env)
172
129
  end
173
130
  end
174
131
 
@@ -177,10 +134,6 @@ module Librarian
177
134
 
178
135
  pwd = Dir.pwd
179
136
 
180
- unless silent
181
- debug { "Running `#{command.join(' ')}` in #{relative_path_to(pwd)}" }
182
- end
183
-
184
137
  out = yield
185
138
 
186
139
  unless silent
@@ -196,21 +149,6 @@ module Librarian
196
149
  out
197
150
  end
198
151
 
199
- def run_command_internal(command)
200
- std = ""
201
- err = ""
202
- thread = nil
203
- Open3.popen3(*command) do |i, o, e, t|
204
- std = o.read
205
- err = e.read
206
- thread = t
207
- end
208
-
209
- raise StandardError, err unless (thread ? thread.value : $?).success?
210
-
211
- std
212
- end
213
-
214
152
  def debug(*args, &block)
215
153
  environment.logger.debug(*args, &block)
216
154
  end
@@ -1,3 +1,3 @@
1
1
  module Librarian
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -2,22 +2,22 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "librarian"
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jay Feldblum"]
9
- s.date = "2013-04-03"
10
- s.description = "Librarian"
9
+ s.date = "2013-08-17"
10
+ s.description = "A Framework for Bundlers."
11
11
  s.email = ["y_feldblum@yahoo.com"]
12
- s.files = [".gitignore", ".rspec", ".travis.yml", "CHANGELOG.md", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "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/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/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_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/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/source/git/repository_spec.rb", "spec/support/fakefs.rb", "spec/support/method_patch_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/config/database_spec.rb", "spec/unit/dependency_spec.rb", "spec/unit/dsl_spec.rb", "spec/unit/environment_spec.rb", "spec/unit/lockfile/parser_spec.rb", "spec/unit/lockfile_spec.rb", "spec/unit/manifest_set_spec.rb", "spec/unit/manifest_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"]
12
+ s.files = [".gitignore", ".rspec", ".travis.yml", "CHANGELOG.md", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "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/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/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_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/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/config/database_spec.rb", "spec/unit/dependency_spec.rb", "spec/unit/dsl_spec.rb", "spec/unit/environment_spec.rb", "spec/unit/lockfile/parser_spec.rb", "spec/unit/lockfile_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"]
13
13
  s.homepage = ""
14
14
  s.require_paths = ["lib"]
15
- s.rubygems_version = "1.8.25"
16
- s.summary = "Librarian"
17
- s.test_files = ["spec/functional/cli_spec.rb", "spec/functional/source/git/repository_spec.rb", "spec/support/fakefs.rb", "spec/support/method_patch_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/config/database_spec.rb", "spec/unit/dependency_spec.rb", "spec/unit/dsl_spec.rb", "spec/unit/environment_spec.rb", "spec/unit/lockfile/parser_spec.rb", "spec/unit/lockfile_spec.rb", "spec/unit/manifest_set_spec.rb", "spec/unit/manifest_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"]
15
+ s.rubygems_version = "2.0.3"
16
+ s.summary = "A Framework for Bundlers."
17
+ s.test_files = ["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/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/config/database_spec.rb", "spec/unit/dependency_spec.rb", "spec/unit/dsl_spec.rb", "spec/unit/environment_spec.rb", "spec/unit/lockfile/parser_spec.rb", "spec/unit/lockfile_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"]
18
18
 
19
19
  if s.respond_to? :specification_version then
20
- s.specification_version = 3
20
+ s.specification_version = 4
21
21
 
22
22
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
23
23
  s.add_runtime_dependency(%q<thor>, ["~> 0.15"])
@@ -0,0 +1,34 @@
1
+ require "librarian/posix"
2
+
3
+ describe Librarian::Posix do
4
+
5
+ let(:project_path) do
6
+ project_path = Pathname.new(__FILE__).expand_path
7
+ project_path = project_path.dirname until project_path.join("Rakefile").exist?
8
+ project_path
9
+ end
10
+ let(:tmp_path) { project_path + "tmp/spec/functional/posix" }
11
+ after { tmp_path.rmtree if tmp_path && tmp_path.exist? }
12
+
13
+ describe ".run!" do
14
+
15
+ it "returns the stdout" do
16
+ res = described_class.run!(%w[echo hello there]).strip
17
+ res.should be == "hello there"
18
+ end
19
+
20
+ it "changes directory" do
21
+ tmp_path.mkpath
22
+ res = described_class.run!(%w[pwd], :chdir => tmp_path).strip
23
+ res.should be == tmp_path.to_s
24
+ end
25
+
26
+ it "reads the env" do
27
+ res = described_class.run!(%w[env], :env => {"KOALA" => "BEAR"})
28
+ line = res.lines.find{|l| l.start_with?("KOALA=")}.strip
29
+ line.should be == "KOALA=BEAR"
30
+ end
31
+
32
+ end
33
+
34
+ end
@@ -2,6 +2,8 @@ require "fileutils"
2
2
  require "pathname"
3
3
  require "securerandom"
4
4
 
5
+ require "librarian/posix"
6
+
5
7
  require "librarian/source/git/repository"
6
8
 
7
9
  describe Librarian::Source::Git::Repository do
@@ -22,45 +24,53 @@ describe Librarian::Source::Git::Repository do
22
24
  let(:tag) { "the-tag" }
23
25
  let(:atag) { "the-atag" }
24
26
 
27
+ def cmd!(command)
28
+ Librarian::Posix.run! command
29
+ end
30
+
31
+ def git!(command)
32
+ cmd!([described_class.bin] + command)
33
+ end
34
+
25
35
  before do
26
36
  git_source_path.mkpath
27
37
  Dir.chdir(git_source_path) do
28
- `git init`
29
- `git config user.name "Simba"`
30
- `git config user.email "simba@savannah-pride.gov"`
38
+ git! %W[init]
39
+ git! %W[config user.name Simba]
40
+ git! %W[config user.email simba@savannah-pride.gov]
31
41
 
32
42
  # master
33
- `touch butter.txt`
34
- `git add butter.txt`
35
- `git commit -m "Initial Commit"`
43
+ FileUtils.touch "butter.txt"
44
+ git! %W[add butter.txt]
45
+ git! %W[commit -m #{"Initial Commit"}]
36
46
 
37
47
  # branch
38
- `git checkout -b #{branch} --quiet`
39
- `touch jam.txt`
40
- `git add jam.txt`
41
- `git commit -m "Branch Commit"`
42
- `git checkout master --quiet`
43
-
44
- # tag
45
- `git checkout -b deletable --quiet`
46
- `touch jelly.txt`
47
- `git add jelly.txt`
48
- `git commit -m "Tag Commit"`
49
- `git tag #{tag}`
50
- `git checkout master --quiet`
51
- `git branch -D deletable`
52
-
53
- # annotated tag
54
- `git checkout -b deletable --quiet`
55
- `touch jelly.txt`
56
- `git add jelly.txt`
57
- `git commit -m "Tag Commit"`
58
- `git tag -am "Annotated Tag Commit" #{atag}`
59
- `git checkout master --quiet`
60
- `git branch -D deletable`
48
+ git! %W[checkout -b #{branch} --quiet]
49
+ FileUtils.touch "jam.txt"
50
+ git! %W[add jam.txt]
51
+ git! %W[commit -m #{"Branch Commit"}]
52
+ git! %W[checkout master --quiet]
53
+
54
+ # tag/atag
55
+ git! %W[checkout -b deletable --quiet]
56
+ FileUtils.touch "jelly.txt"
57
+ git! %W[add jelly.txt]
58
+ git! %W[commit -m #{"Tag Commit"}]
59
+ git! %W[tag #{tag}]
60
+ git! %W[tag -am #{"Annotated Tag Commit"} #{atag}]
61
+ git! %W[checkout master --quiet]
62
+ git! %W[branch -D deletable]
61
63
  end
62
64
  end
63
65
 
66
+ describe ".bin" do
67
+ specify { described_class.bin.should_not be_empty }
68
+ end
69
+
70
+ describe ".git_version" do
71
+ specify { described_class.git_version.should =~ /^\d+(\.\d+)+$/ }
72
+ end
73
+
64
74
  context "the original" do
65
75
  subject { described_class.new(env, git_source_path) }
66
76
 
@@ -75,6 +85,15 @@ describe Librarian::Source::Git::Repository do
75
85
  it "should not list any remote branches for it" do
76
86
  subject.remote_branch_names.should be_empty
77
87
  end
88
+
89
+ it "should have divergent shas for master, branch, tag, and atag" do
90
+ revs = %W[ master #{branch} #{tag} #{atag} ]
91
+ rev_parse = proc{|rev| git!(%W[rev-parse #{rev} --quiet]).strip}
92
+ shas = Dir.chdir(git_source_path){revs.map(&rev_parse)}
93
+ shas.map(&:class).uniq.should be == [String]
94
+ shas.map(&:size).uniq.should be == [40]
95
+ shas.uniq.should be == shas
96
+ end
78
97
  end
79
98
 
80
99
  context "a clone" do
@@ -0,0 +1,30 @@
1
+ require "pathname"
2
+ require "securerandom"
3
+
4
+ require "librarian/error"
5
+ require "librarian/source/git"
6
+
7
+ describe Librarian::Source::Git do
8
+
9
+ let(:project_path) do
10
+ project_path = Pathname.new(__FILE__).expand_path
11
+ project_path = project_path.dirname until project_path.join("Rakefile").exist?
12
+ project_path
13
+ end
14
+ let(:tmp_path) { project_path + "tmp/spec/functional/source/git" }
15
+ after { tmp_path.rmtree if tmp_path && tmp_path.exist? }
16
+ let(:cache_path) { tmp_path + "cache" }
17
+
18
+ context "when the remote is bad" do
19
+ let(:remote) { tmp_path.join(SecureRandom.hex(8)).to_s }
20
+ let(:logger) { double(:debug => nil, :info => nil) }
21
+ let(:env) { double(:ui => nil, :logger => logger, :cache_path => cache_path) }
22
+ let(:source) { described_class.new(env, remote, {}) }
23
+
24
+ it "fails when caching" do
25
+ expect { source.cache! }.to raise_error Librarian::Error,
26
+ /^fatal: repository .+ does not exist$/ # from git
27
+ end
28
+ end
29
+
30
+ end
@@ -2,6 +2,19 @@ require "fakefs/safe"
2
2
  require "fakefs/spec_helpers"
3
3
  require "support/method_patch_macro"
4
4
 
5
+ if defined?(Rubinius)
6
+ module Rubinius
7
+ class CodeLoader
8
+ class << self
9
+ alias_method :require_fakefs_original, :require
10
+ def require(s)
11
+ ::FakeFS.without { require_fakefs_original(s) }
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
5
18
  module Support
6
19
  module FakeFS
7
20
 
@@ -3,7 +3,7 @@ require "librarian/action/base"
3
3
  module Librarian
4
4
  describe Action::Base do
5
5
 
6
- let(:env) { mock }
6
+ let(:env) { double }
7
7
  let(:action) { described_class.new(env) }
8
8
 
9
9
  subject { action }
@@ -3,7 +3,7 @@ require "librarian/action/clean"
3
3
  module Librarian
4
4
  describe Action::Clean do
5
5
 
6
- let(:env) { mock }
6
+ let(:env) { double }
7
7
  let(:action) { described_class.new(env) }
8
8
 
9
9
  before do
@@ -68,7 +68,7 @@ module Librarian
68
68
  end
69
69
 
70
70
  it "should try to clear the install path" do
71
- children = [mock, mock, mock]
71
+ children = [double, double, double]
72
72
  children.each do |child|
73
73
  child.stub(:file?) { false }
74
74
  end
@@ -80,7 +80,7 @@ module Librarian
80
80
  end
81
81
 
82
82
  it "should only try to clear out directories from the install path, not files" do
83
- children = [mock(:file? => false), mock(:file? => true), mock(:file? => true)]
83
+ children = [double(:file? => false), double(:file? => true), double(:file? => true)]
84
84
  env.stub_chain(:install_path, :children) { children }
85
85
 
86
86
  children.select(&:file?).each do |child|
@@ -6,7 +6,7 @@ require "librarian/action/ensure"
6
6
  module Librarian
7
7
  describe Action::Ensure do
8
8
 
9
- let(:env) { mock }
9
+ let(:env) { double }
10
10
  let(:action) { described_class.new(env) }
11
11
 
12
12
  before do
@@ -4,7 +4,7 @@ require "librarian/action/install"
4
4
  module Librarian
5
5
  describe Action::Install do
6
6
 
7
- let(:env) { mock(:specfile_name => "Specfile", :lockfile_name => "Specfile.lock") }
7
+ let(:env) { double(:specfile_name => "Specfile", :lockfile_name => "Specfile.lock") }
8
8
  let(:action) { described_class.new(env) }
9
9
 
10
10
  describe "#run" do
@@ -69,7 +69,7 @@ module Librarian
69
69
 
70
70
  let(:manifests) { 3.times.map{|i| mock_manifest(i)} }
71
71
  let(:sorted_manifests) { 4.times.map{|i| mock_manifest(i + 3)} }
72
- let(:install_path) { mock }
72
+ let(:install_path) { double }
73
73
 
74
74
  before do
75
75
  env.stub(:install_path) { install_path }
@@ -8,6 +8,41 @@ module Librarian
8
8
 
9
9
  let(:env) { described_class.new }
10
10
 
11
+ describe "#adapter_module" do
12
+ specify { env.adapter_module.should be nil }
13
+ end
14
+
15
+ describe "#adapter_name" do
16
+ specify { env.adapter_name.should be nil }
17
+ end
18
+
19
+ describe "#adapter_version" do
20
+ specify { env.adapter_version.should be nil }
21
+ end
22
+
23
+ describe "computing the home" do
24
+
25
+ context "with the HOME env var" do
26
+ with_env "HOME" => "/path/to/home"
27
+
28
+ it "finds the home" do
29
+ env.stub(:adapter_name).and_return("cat")
30
+ env.config_db.underlying_home.to_s.should == "/path/to/home"
31
+ end
32
+ end
33
+
34
+ context "without the HOME env var" do
35
+ let!(:real_home) { File.expand_path("~") }
36
+ with_env "HOME" => nil
37
+
38
+ it "finds the home" do
39
+ env.stub(:adapter_name).and_return("cat")
40
+ env.config_db.underlying_home.to_s.should == real_home
41
+ end
42
+ end
43
+
44
+ end
45
+
11
46
  describe "#http_proxy_uri" do
12
47
 
13
48
  context "sanity" do
@@ -165,6 +200,7 @@ module Librarian
165
200
  env.net_http_class(proxied_host).should be_proxy_class
166
201
  end
167
202
  end
203
+
168
204
  end
169
205
 
170
206
  end
@@ -0,0 +1,25 @@
1
+ require "librarian/mock/environment"
2
+
3
+ module Librarian::Mock
4
+ describe Environment do
5
+
6
+ let(:env) { described_class.new }
7
+
8
+ describe "#version" do
9
+ specify { env.version.should be == Librarian::VERSION }
10
+ end
11
+
12
+ describe "#adapter_module" do
13
+ specify { env.adapter_module.should be Librarian::Mock }
14
+ end
15
+
16
+ describe "#adapter_name" do
17
+ specify { env.adapter_name.should be == "mock" }
18
+ end
19
+
20
+ describe "#adapter_version" do
21
+ specify { env.adapter_version.should be == Librarian::Mock::VERSION }
22
+ end
23
+
24
+ end
25
+ end
metadata CHANGED
@@ -1,113 +1,100 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: librarian
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.0
4
+ version: 0.1.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jay Feldblum
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-03 00:00:00.000000000 Z
11
+ date: 2013-08-17 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- type: :runtime
16
- version_requirements: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '0.15'
22
14
  name: thor
23
- prerelease: false
24
15
  requirement: !ruby/object:Gem::Requirement
25
- none: false
26
16
  requirements:
27
17
  - - ~>
28
18
  - !ruby/object:Gem::Version
29
19
  version: '0.15'
30
- - !ruby/object:Gem::Dependency
31
20
  type: :runtime
21
+ prerelease: false
32
22
  version_requirements: !ruby/object:Gem::Requirement
33
- none: false
34
23
  requirements:
35
- - - ! '>='
24
+ - - ~>
36
25
  - !ruby/object:Gem::Version
37
- version: '0'
26
+ version: '0.15'
27
+ - !ruby/object:Gem::Dependency
38
28
  name: highline
39
- prerelease: false
40
29
  requirement: !ruby/object:Gem::Requirement
41
- none: false
42
30
  requirements:
43
- - - ! '>='
31
+ - - '>='
44
32
  - !ruby/object:Gem::Version
45
33
  version: '0'
46
- - !ruby/object:Gem::Dependency
47
- type: :development
34
+ type: :runtime
35
+ prerelease: false
48
36
  version_requirements: !ruby/object:Gem::Requirement
49
- none: false
50
37
  requirements:
51
- - - ! '>='
38
+ - - '>='
52
39
  - !ruby/object:Gem::Version
53
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
54
42
  name: rake
55
- prerelease: false
56
43
  requirement: !ruby/object:Gem::Requirement
57
- none: false
58
44
  requirements:
59
- - - ! '>='
45
+ - - '>='
60
46
  - !ruby/object:Gem::Version
61
47
  version: '0'
62
- - !ruby/object:Gem::Dependency
63
48
  type: :development
49
+ prerelease: false
64
50
  version_requirements: !ruby/object:Gem::Requirement
65
- none: false
66
51
  requirements:
67
- - - ! '>='
52
+ - - '>='
68
53
  - !ruby/object:Gem::Version
69
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
70
56
  name: rspec
71
- prerelease: false
72
57
  requirement: !ruby/object:Gem::Requirement
73
- none: false
74
58
  requirements:
75
- - - ! '>='
59
+ - - '>='
76
60
  - !ruby/object:Gem::Version
77
61
  version: '0'
78
- - !ruby/object:Gem::Dependency
79
62
  type: :development
63
+ prerelease: false
80
64
  version_requirements: !ruby/object:Gem::Requirement
81
- none: false
82
65
  requirements:
83
- - - ! '>='
66
+ - - '>='
84
67
  - !ruby/object:Gem::Version
85
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
86
70
  name: json
87
- prerelease: false
88
71
  requirement: !ruby/object:Gem::Requirement
89
- none: false
90
72
  requirements:
91
- - - ! '>='
73
+ - - '>='
92
74
  - !ruby/object:Gem::Version
93
75
  version: '0'
94
- - !ruby/object:Gem::Dependency
95
76
  type: :development
77
+ prerelease: false
96
78
  version_requirements: !ruby/object:Gem::Requirement
97
- none: false
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: fakefs
85
+ requirement: !ruby/object:Gem::Requirement
98
86
  requirements:
99
87
  - - ~>
100
88
  - !ruby/object:Gem::Version
101
89
  version: 0.4.2
102
- name: fakefs
90
+ type: :development
103
91
  prerelease: false
104
- requirement: !ruby/object:Gem::Requirement
105
- none: false
92
+ version_requirements: !ruby/object:Gem::Requirement
106
93
  requirements:
107
94
  - - ~>
108
95
  - !ruby/object:Gem::Version
109
96
  version: 0.4.2
110
- description: Librarian
97
+ description: A Framework for Bundlers.
111
98
  email:
112
99
  - y_feldblum@yahoo.com
113
100
  executables: []
@@ -161,6 +148,7 @@ files:
161
148
  - lib/librarian/mock/source/mock.rb
162
149
  - lib/librarian/mock/source/mock/registry.rb
163
150
  - lib/librarian/mock/version.rb
151
+ - lib/librarian/posix.rb
164
152
  - lib/librarian/resolution.rb
165
153
  - lib/librarian/resolver.rb
166
154
  - lib/librarian/resolver/implementation.rb
@@ -179,7 +167,9 @@ files:
179
167
  - lib/librarian/version.rb
180
168
  - librarian.gemspec
181
169
  - spec/functional/cli_spec.rb
170
+ - spec/functional/posix_spec.rb
182
171
  - spec/functional/source/git/repository_spec.rb
172
+ - spec/functional/source/git_spec.rb
183
173
  - spec/support/fakefs.rb
184
174
  - spec/support/method_patch_macro.rb
185
175
  - spec/support/with_env_macro.rb
@@ -195,40 +185,39 @@ files:
195
185
  - spec/unit/lockfile_spec.rb
196
186
  - spec/unit/manifest_set_spec.rb
197
187
  - spec/unit/manifest_spec.rb
188
+ - spec/unit/mock/environment_spec.rb
198
189
  - spec/unit/mock/source/mock_spec.rb
199
190
  - spec/unit/resolver_spec.rb
200
191
  - spec/unit/source/git_spec.rb
201
192
  - spec/unit/spec_change_set_spec.rb
202
193
  homepage: ''
203
194
  licenses: []
195
+ metadata: {}
204
196
  post_install_message:
205
197
  rdoc_options: []
206
198
  require_paths:
207
199
  - lib
208
200
  required_ruby_version: !ruby/object:Gem::Requirement
209
- none: false
210
201
  requirements:
211
- - - ! '>='
202
+ - - '>='
212
203
  - !ruby/object:Gem::Version
213
- segments:
214
- - 0
215
- hash: -845093804329551248
216
204
  version: '0'
217
205
  required_rubygems_version: !ruby/object:Gem::Requirement
218
- none: false
219
206
  requirements:
220
- - - ! '>='
207
+ - - '>='
221
208
  - !ruby/object:Gem::Version
222
209
  version: '0'
223
210
  requirements: []
224
211
  rubyforge_project:
225
- rubygems_version: 1.8.25
212
+ rubygems_version: 2.0.3
226
213
  signing_key:
227
- specification_version: 3
228
- summary: Librarian
214
+ specification_version: 4
215
+ summary: A Framework for Bundlers.
229
216
  test_files:
230
217
  - spec/functional/cli_spec.rb
218
+ - spec/functional/posix_spec.rb
231
219
  - spec/functional/source/git/repository_spec.rb
220
+ - spec/functional/source/git_spec.rb
232
221
  - spec/support/fakefs.rb
233
222
  - spec/support/method_patch_macro.rb
234
223
  - spec/support/with_env_macro.rb
@@ -244,6 +233,7 @@ test_files:
244
233
  - spec/unit/lockfile_spec.rb
245
234
  - spec/unit/manifest_set_spec.rb
246
235
  - spec/unit/manifest_spec.rb
236
+ - spec/unit/mock/environment_spec.rb
247
237
  - spec/unit/mock/source/mock_spec.rb
248
238
  - spec/unit/resolver_spec.rb
249
239
  - spec/unit/source/git_spec.rb