bundler 0.7.3.pre → 0.7.3.pre2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bundler might be problematic. Click here for more details.

data/Rakefile CHANGED
@@ -37,6 +37,19 @@ else
37
37
  end
38
38
  end
39
39
 
40
+ namespace :spec do
41
+ file "tmp/rg_deps" do
42
+ repo = File.dirname(__FILE__) + '/tmp/rg_deps'
43
+ FileUtils.mkdir_p(repo)
44
+ p repo
45
+ ENV['GEM_HOME'], ENV['GEM_PATH'] = repo, repo
46
+ system "gem install builder --no-rdoc --no-ri"
47
+ end
48
+
49
+ desc "Do all setup needed to run the specs"
50
+ task :setup => "tmp/rg_deps"
51
+ end
52
+
40
53
  begin
41
54
  require 'rake/gempackagetask'
42
55
  rescue LoadError
@@ -19,7 +19,7 @@ require "bundler/dependency"
19
19
  require "bundler/remote_specification"
20
20
 
21
21
  module Bundler
22
- VERSION = "0.7.3.pre"
22
+ VERSION = "0.7.3.pre2"
23
23
 
24
24
  class << self
25
25
  attr_writer :logger
@@ -2,34 +2,86 @@ module Bundler
2
2
  class InvalidRepository < StandardError ; end
3
3
 
4
4
  class Bundle
5
- attr_reader :path
5
+ attr_reader :gemfile, :environment
6
6
 
7
- def initialize(path, bindir)
8
- FileUtils.mkdir_p(path)
7
+ def self.load(gemfile = nil)
8
+ gemfile = Pathname.new(gemfile || default_gemfile).expand_path
9
9
 
10
- @path = Pathname.new(path)
11
- @bindir = Pathname.new(bindir)
10
+ unless gemfile.file?
11
+ raise ManifestFileNotFound, "Manifest file not found: #{gemfile.to_s.inspect}"
12
+ end
13
+
14
+ new(gemfile)
15
+ end
16
+
17
+ def self.default_gemfile
18
+ current = Pathname.new(Dir.pwd)
19
+
20
+ until current.root?
21
+ filename = current.join("Gemfile")
22
+ return filename if filename.exist?
23
+ current = current.parent
24
+ end
25
+
26
+ raise DefaultManifestNotFound
27
+ end
12
28
 
13
- @cache_path = @path.join('cache')
14
- @cache = GemDirectorySource.new(:location => @cache_path)
29
+ # TODO: passing in the filename is not good
30
+ def initialize(gemfile)
31
+ @gemfile = gemfile
32
+ @environment = Environment.new(self)
33
+ Dsl.evaluate(gemfile, self, @environment)
34
+
35
+ # path = env.gem_path
36
+
37
+ FileUtils.mkdir_p(gem_path)
38
+
39
+ @cache_path = gem_path.join('cache')
40
+ @cache = GemDirectorySource.new(self, :location => @cache_path)
41
+
42
+ @specs_path = gem_path.join('specifications')
43
+ @gems_path = gem_path.join('gems')
44
+ end
45
+
46
+ def root
47
+ gemfile.parent
48
+ end
15
49
 
16
- @specs_path = @path.join('specifications')
17
- @gems_path = @path.join('gems')
50
+ def path
51
+ @path ||= root.join("vendor/gems")
18
52
  end
19
53
 
20
- def install(dependencies, sources, options = {})
54
+ def path=(path)
55
+ @path = (path.relative? ? root.join(path) : path).expand_path
56
+ end
57
+
58
+ def gem_path
59
+ path.join("#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}")
60
+ end
61
+
62
+ def bindir
63
+ @bindir ||= root.join("bin")
64
+ end
65
+
66
+ def bindir=(path)
67
+ @bindir = (path.relative? ? root.join(path) : path).expand_path
68
+ end
69
+
70
+ def install(options = {})
71
+ dependencies = @environment.dependencies
72
+ sources = @environment.sources
73
+
74
+ # ========== from env
75
+ if only_envs = options[:only]
76
+ dependencies.reject! { |d| !only_envs.any? {|env| d.in?(env) } }
77
+ end
78
+ # ==========
79
+
21
80
  # TODO: clean this up
22
81
  sources.each do |s|
23
- s.repository = self
24
82
  s.local = options[:cached]
25
83
  end
26
84
 
27
- source_requirements = {}
28
- dependencies = dependencies.map do |dep|
29
- source_requirements[dep.name] = dep.source if dep.source
30
- dep.to_gem_dependency
31
- end
32
-
33
85
  # Check to see whether the existing cache meets all the requirements
34
86
  begin
35
87
  valid = nil
@@ -43,7 +95,7 @@ module Bundler
43
95
  # or the user passed --update
44
96
  if options[:update] || !valid
45
97
  Bundler.logger.info "Calculating dependencies..."
46
- bundle = Resolver.resolve(dependencies, [@cache] + sources, source_requirements)
98
+ bundle = Resolver.resolve(dependencies, [@cache] + sources)
47
99
  download(bundle, options)
48
100
  do_install(bundle, options)
49
101
  valid = bundle
@@ -52,6 +104,8 @@ module Bundler
52
104
  generate_bins(valid, options)
53
105
  cleanup(valid, options)
54
106
  configure(valid, options)
107
+
108
+ Bundler.logger.info "Done."
55
109
  end
56
110
 
57
111
  def cache(*gemfiles)
@@ -62,9 +116,23 @@ module Bundler
62
116
  end
63
117
  end
64
118
 
65
- def prune(dependencies, sources)
119
+ def list_outdated(options={})
120
+ outdated_gems = source_index.outdated.sort
121
+
122
+ if outdated_gems.empty?
123
+ Bundler.logger.info "All gems are up to date."
124
+ else
125
+ Bundler.logger.info "Outdated gems:"
126
+ outdated_gems.each do |name|
127
+ Bundler.logger.info " * #{name}"
128
+ end
129
+ end
130
+ end
131
+
132
+ def prune(options = {})
133
+ dependencies, sources = @environment.gem_dependencies, @environment.sources
134
+
66
135
  sources.each do |s|
67
- s.repository = self
68
136
  s.local = true
69
137
  end
70
138
 
@@ -80,12 +148,15 @@ module Bundler
80
148
  end
81
149
  end
82
150
 
83
- def gems
84
- source_index.gems.values
151
+ def list(options = {})
152
+ Bundler.logger.info "Currently bundled gems:"
153
+ gems.each do |spec|
154
+ Bundler.logger.info " * #{spec.name} (#{spec.version})"
155
+ end
85
156
  end
86
157
 
87
- def outdated_gems
88
- source_index.outdated.sort
158
+ def gems
159
+ source_index.gems.values
89
160
  end
90
161
 
91
162
  def source_index
@@ -98,6 +169,15 @@ module Bundler
98
169
  @repos[type].download_path_for
99
170
  end
100
171
 
172
+ def setup_environment
173
+ unless @environment.system_gems
174
+ ENV["GEM_HOME"] = gem_path
175
+ ENV["GEM_PATH"] = gem_path
176
+ end
177
+ ENV["PATH"] = "#{bindir}:#{ENV["PATH"]}"
178
+ ENV["RUBYOPT"] = "-r#{gem_path}/environment #{ENV["RUBYOPT"]}"
179
+ end
180
+
101
181
  private
102
182
 
103
183
  def only_local(sources)
@@ -106,14 +186,14 @@ module Bundler
106
186
 
107
187
  def download(bundle, options)
108
188
  bundle.sort_by {|s| s.full_name.downcase }.each do |spec|
109
- next if options[:no_bundle].include?(spec.name)
189
+ next if spec.no_bundle?
110
190
  spec.source.download(spec)
111
191
  end
112
192
  end
113
193
 
114
194
  def do_install(bundle, options)
115
195
  bundle.each do |spec|
116
- next if options[:no_bundle].include?(spec.name)
196
+ next if spec.no_bundle?
117
197
  spec.loaded_from = @specs_path.join("#{spec.full_name}.gemspec")
118
198
  # Do nothing if the gem is already expanded
119
199
  next if @gems_path.join(spec.full_name).directory?
@@ -129,10 +209,10 @@ module Bundler
129
209
 
130
210
  def generate_bins(bundle, options)
131
211
  bundle.each do |spec|
132
- next if options[:no_bundle].include?(spec.name)
212
+ next if spec.no_bundle?
133
213
  # HAX -- Generate the bin
134
- bin_dir = @bindir
135
- path = @path
214
+ bin_dir = bindir
215
+ path = gem_path
136
216
  gems_path = @gems_path
137
217
  installer = Gem::Installer.allocate
138
218
  installer.instance_eval do
@@ -158,11 +238,11 @@ module Bundler
158
238
  end
159
239
 
160
240
  installer = Gem::Installer.new(gemfile, options.merge(
161
- :install_dir => @path,
241
+ :install_dir => gem_path,
162
242
  :ignore_dependencies => true,
163
243
  :env_shebang => true,
164
244
  :wrappers => true,
165
- :bin_dir => @bindir
245
+ :bin_dir => bindir
166
246
  ))
167
247
  installer.install
168
248
  rescue Gem::InstallError
@@ -202,7 +282,7 @@ module Bundler
202
282
  spec.executables.each do |bin|
203
283
  next if valid_executables.include?(bin)
204
284
  Bundler.logger.info "Deleting bin file: #{bin}"
205
- FileUtils.rm_rf(@bindir.join(bin))
285
+ FileUtils.rm_rf(bindir.join(bin))
206
286
  end
207
287
  end
208
288
  end
@@ -219,48 +299,17 @@ module Bundler
219
299
  end
220
300
 
221
301
  def configure(specs, options)
222
- FileUtils.mkdir_p(path)
223
- generate_environment(specs, options)
224
- generate_environment_picker
225
- end
226
-
227
- def generate_environment_picker
228
- FileUtils.cp("#{File.dirname(__FILE__)}/templates/environment_picker.erb", path.join("../../environment.rb"))
229
- end
230
-
231
- def generate_environment(specs, options)
232
- load_paths = load_paths_for_specs(specs, options)
233
- bindir = @bindir.relative_path_from(path).to_s
234
- filename = options[:manifest].relative_path_from(path).to_s
235
-
236
- File.open(path.join("environment.rb"), "w") do |file|
237
- template = File.read(File.join(File.dirname(__FILE__), "templates", "environment.erb"))
238
- erb = ERB.new(template, nil, '-')
239
- file.puts erb.result(binding)
240
- end
241
- end
302
+ FileUtils.mkdir_p(gem_path)
242
303
 
243
- def load_paths_for_specs(specs, options)
244
- load_paths = []
245
- specs.each do |spec|
246
- next if options[:no_bundle].include?(spec.name)
247
- gem_path = Pathname.new(spec.full_gem_path)
248
- if spec.bindir && gem_path.join(spec.bindir).exist?
249
- load_paths << load_path_for(gem_path, spec.bindir)
250
- end
251
- spec.require_paths.each do |path|
252
- load_paths << load_path_for(gem_path, path)
253
- end
304
+ File.open(gem_path.join("environment.rb"), "w") do |file|
305
+ file.puts @environment.environment_rb(specs, options)
254
306
  end
255
- load_paths
256
- end
257
307
 
258
- def load_path_for(gem_path, path)
259
- gem_path.join(path).relative_path_from(@path).to_s
308
+ generate_environment_picker
260
309
  end
261
310
 
262
- def spec_file_for(spec)
263
- spec.loaded_from.relative_path_from(@path).to_s
311
+ def generate_environment_picker
312
+ FileUtils.cp("#{File.dirname(__FILE__)}/templates/environment_picker.erb", path.join("environment.rb"))
264
313
  end
265
314
 
266
315
  def require_code(file, dep)
@@ -32,31 +32,49 @@ module Bundler
32
32
 
33
33
  def initialize(options)
34
34
  @options = options
35
- @environment = Dsl.load_gemfile(@options[:manifest])
35
+ @bundle = Bundle.load(@options[:manifest])
36
36
  end
37
37
 
38
38
  def bundle
39
- @environment.install(@options)
39
+ @bundle.install(@options)
40
40
  end
41
41
 
42
42
  def cache
43
- @environment.cache(@options)
43
+ gemfile = @options[:cache]
44
+
45
+ if File.extname(gemfile) == ".gem"
46
+ if !File.exist?(gemfile)
47
+ raise InvalidCacheArgument, "'#{gemfile}' does not exist."
48
+ end
49
+ @bundle.cache(gemfile)
50
+ elsif File.directory?(gemfile) || gemfile.include?('/')
51
+ if !File.directory?(gemfile)
52
+ raise InvalidCacheArgument, "'#{gemfile}' does not exist."
53
+ end
54
+ gemfiles = Dir["#{gemfile}/*.gem"]
55
+ if gemfiles.empty?
56
+ raise InvalidCacheArgument, "'#{gemfile}' contains no gemfiles"
57
+ end
58
+ @bundle.cache(*gemfiles)
59
+ else
60
+ raise InvalidCacheArgument, "w0t? '#{gemfile}' means nothing to me."
61
+ end
44
62
  end
45
63
 
46
64
  def prune
47
- @environment.prune(@options)
65
+ @bundle.prune(@options)
48
66
  end
49
67
 
50
68
  def list
51
- @environment.list(@options)
69
+ @bundle.list(@options)
52
70
  end
53
71
 
54
72
  def list_outdated
55
- @environment.list_outdated(@options)
73
+ @bundle.list_outdated(@options)
56
74
  end
57
75
 
58
76
  def exec
59
- @environment.setup_environment
77
+ @bundle.setup_environment
60
78
  # w0t?
61
79
  super(*$command)
62
80
  end
@@ -1,7 +1,7 @@
1
1
  module Bundler
2
2
  class InvalidEnvironmentName < StandardError; end
3
3
 
4
- class Dependency
4
+ class Dependency < Gem::Dependency
5
5
  attr_reader :name, :version, :require_as, :only, :except
6
6
  attr_accessor :source
7
7
 
@@ -10,8 +10,8 @@ module Bundler
10
10
  options[k.to_s] = v
11
11
  end
12
12
 
13
- @name = name
14
- @version = options["version"] || ">= 0"
13
+ super(name, options["version"] || ">= 0")
14
+
15
15
  @require_as = options["require_as"]
16
16
  @only = options["only"]
17
17
  @except = options["except"]
@@ -31,10 +31,6 @@ module Bundler
31
31
  true
32
32
  end
33
33
 
34
- def to_s
35
- to_gem_dependency.to_s
36
- end
37
-
38
34
  def require_env(environment)
39
35
  return unless in?(environment)
40
36
 
@@ -51,8 +47,8 @@ module Bundler
51
47
  @block.call if @block
52
48
  end
53
49
 
54
- def to_gem_dependency
55
- @gem_dep ||= Gem::Dependency.new(name, version)
50
+ def no_bundle?
51
+ source == SystemGemSource.instance
56
52
  end
57
53
 
58
54
  def ==(o)
@@ -60,5 +56,7 @@ module Bundler
60
56
  [o.name, o.version, o.require_as, o.only, o.except]
61
57
  end
62
58
 
59
+ alias version version_requirements
60
+
63
61
  end
64
62
  end
@@ -4,36 +4,14 @@ module Bundler
4
4
  class DefaultManifestNotFound < StandardError; end
5
5
 
6
6
  class Dsl
7
- def self.load_gemfile(file)
8
- gemfile = Pathname.new(file || default_gemfile).expand_path
9
-
10
- unless gemfile.file?
11
- raise ManifestFileNotFound, "Manifest file not found: #{gemfile.to_s.inspect}"
12
- end
13
-
14
- evaluate(gemfile)
15
- end
16
-
17
- def self.default_gemfile
18
- current = Pathname.new(Dir.pwd)
19
-
20
- until current.root?
21
- filename = current.join("Gemfile")
22
- return filename if filename.exist?
23
- current = current.parent
24
- end
25
-
26
- raise DefaultManifestNotFound
27
- end
28
-
29
- def self.evaluate(file)
30
- environment = Environment.new(file)
31
- builder = new(environment)
7
+ def self.evaluate(file, bundle, environment)
8
+ builder = new(bundle, environment)
32
9
  builder.instance_eval(File.read(file.to_s), file.to_s, 1)
33
10
  environment
34
11
  end
35
12
 
36
- def initialize(environment)
13
+ def initialize(bundle, environment)
14
+ @bundle = bundle
37
15
  @environment = environment
38
16
  @directory_sources = []
39
17
  @git_sources = {}
@@ -41,15 +19,11 @@ module Bundler
41
19
  end
42
20
 
43
21
  def bundle_path(path)
44
- path = Pathname.new(path)
45
- @environment.gem_path = (path.relative? ?
46
- @environment.root.join(path) : path).expand_path
22
+ @bundle.path = Pathname.new(path)
47
23
  end
48
24
 
49
25
  def bin_path(path)
50
- path = Pathname.new(path)
51
- @environment.bindir = (path.relative? ?
52
- @environment.root.join(path) : path).expand_path
26
+ @bundle.bindir = Pathname.new(path)
53
27
  end
54
28
 
55
29
  def disable_rubygems
@@ -61,7 +35,7 @@ module Bundler
61
35
  end
62
36
 
63
37
  def source(source)
64
- source = GemSource.new(:uri => source)
38
+ source = GemSource.new(@bundle, :uri => source)
65
39
  unless @environment.sources.include?(source)
66
40
  @environment.add_source(source)
67
41
  end
@@ -81,7 +55,7 @@ module Bundler
81
55
 
82
56
  def directory(path, options = {})
83
57
  raise DirectorySourceError, "cannot nest calls to directory or git" if @directory || @git
84
- @directory = DirectorySource.new(options.merge(:location => path))
58
+ @directory = DirectorySource.new(@bundle, options.merge(:location => path))
85
59
  @directory_sources << @directory
86
60
  @environment.add_priority_source(@directory)
87
61
  retval = yield if block_given?
@@ -91,7 +65,7 @@ module Bundler
91
65
 
92
66
  def git(uri, options = {})
93
67
  raise DirectorySourceError, "cannot nest calls to directory or git" if @directory || @git
94
- @git = GitSource.new(options.merge(:uri => uri))
68
+ @git = GitSource.new(@bundle, options.merge(:uri => uri))
95
69
  @git_sources[uri] = @git
96
70
  @environment.add_priority_source(@git)
97
71
  retval = yield if block_given?
@@ -123,7 +97,7 @@ module Bundler
123
97
  dep = Dependency.new(name, options.merge(:version => version))
124
98
 
125
99
  if options.key?(:bundle) && !options[:bundle]
126
- dep.source = SystemGemSource.instance
100
+ dep.source = SystemGemSource.new(@bundle)
127
101
  elsif @git || options[:git]
128
102
  dep.source = _handle_git_option(name, version, options)
129
103
  elsif @directory || options[:path]
@@ -158,7 +132,7 @@ module Bundler
158
132
  return @directory, Pathname.new(path || '')
159
133
  end
160
134
 
161
- path = @environment.filename.dirname.join(path)
135
+ path = @bundle.gemfile.dirname.join(path)
162
136
 
163
137
  @directory_sources.each do |s|
164
138
  if s.location.expand_path.to_s < path.expand_path.to_s
@@ -5,16 +5,11 @@ module Bundler
5
5
  class SourceNotCached < StandardError; end
6
6
 
7
7
  class Environment
8
- attr_reader :filename, :dependencies
8
+ attr_reader :dependencies
9
9
  attr_accessor :rubygems, :system_gems
10
- attr_writer :gem_path, :bindir
11
10
 
12
- def self.default_gem_path(root)
13
- Pathname.new("#{root}/vendor/gems/#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}")
14
- end
15
-
16
- def initialize(filename)
17
- @filename = filename
11
+ def initialize(bundle)
12
+ @bundle = bundle # TODO: remove this
18
13
  @default_sources = default_sources
19
14
  @sources = []
20
15
  @priority_sources = []
@@ -23,110 +18,22 @@ module Bundler
23
18
  @system_gems = true
24
19
  end
25
20
 
26
- def install(options = {})
27
- if only_envs = options[:only]
28
- dependencies.reject! { |d| !only_envs.any? {|env| d.in?(env) } }
29
- end
30
-
31
- no_bundle = dependencies.map do |dep|
32
- dep.source == SystemGemSource.instance && dep.name
33
- end.compact
34
-
35
- update = options[:update]
36
- cached = options[:cached]
37
-
38
- repository.install(dependencies, sources,
39
- :rubygems => rubygems,
40
- :system_gems => system_gems,
41
- :manifest => filename,
42
- :update => options[:update],
43
- :cached => options[:cached],
44
- :build_options => options[:build_options],
45
- :no_bundle => no_bundle
46
- )
47
- Bundler.logger.info "Done."
48
- end
49
-
50
- def cache(options = {})
51
- gemfile = options[:cache]
52
-
53
- if File.extname(gemfile) == ".gem"
54
- if !File.exist?(gemfile)
55
- raise InvalidCacheArgument, "'#{gemfile}' does not exist."
56
- end
57
- repository.cache(gemfile)
58
- elsif File.directory?(gemfile) || gemfile.include?('/')
59
- if !File.directory?(gemfile)
60
- raise InvalidCacheArgument, "'#{gemfile}' does not exist."
61
- end
62
- gemfiles = Dir["#{gemfile}/*.gem"]
63
- if gemfiles.empty?
64
- raise InvalidCacheArgument, "'#{gemfile}' contains no gemfiles"
65
- end
66
- repository.cache(*gemfiles)
67
- else
68
- local = Gem::SourceIndex.from_installed_gems.find_name(gemfile).last
69
-
70
- if !local
71
- raise InvalidCacheArgument, "w0t? '#{gemfile}' means nothing to me."
72
- end
73
-
74
- gemfile = Pathname.new(local.loaded_from)
75
- gemfile = gemfile.dirname.join('..', 'cache', "#{local.full_name}.gem").expand_path
76
- repository.cache(gemfile)
77
- end
78
- end
79
-
80
- def prune(options = {})
81
- repository.prune(gem_dependencies, sources)
82
- end
21
+ def environment_rb(specs, options)
22
+ load_paths = load_paths_for_specs(specs, options)
23
+ bindir = @bundle.bindir.relative_path_from(@bundle.gem_path).to_s
24
+ filename = @bundle.gemfile.relative_path_from(@bundle.gem_path).to_s
83
25
 
84
- def list(options = {})
85
- Bundler.logger.info "Currently bundled gems:"
86
- repository.gems.each do |spec|
87
- Bundler.logger.info " * #{spec.name} (#{spec.version})"
88
- end
89
- end
90
-
91
- def list_outdated(options={})
92
- outdated_gems = repository.outdated_gems
93
- if outdated_gems.empty?
94
- Bundler.logger.info "All gems are up to date."
95
- else
96
- Bundler.logger.info "Outdated gems:"
97
- outdated_gems.each do |name|
98
- Bundler.logger.info " * #{name}"
99
- end
100
- end
101
- end
102
-
103
- def setup_environment
104
- unless system_gems
105
- ENV["GEM_HOME"] = gem_path
106
- ENV["GEM_PATH"] = gem_path
107
- end
108
- ENV["PATH"] = "#{bindir}:#{ENV["PATH"]}"
109
- ENV["RUBYOPT"] = "-r#{gem_path}/environment #{ENV["RUBYOPT"]}"
26
+ template = File.read(File.join(File.dirname(__FILE__), "templates", "environment.erb"))
27
+ erb = ERB.new(template, nil, '-')
28
+ erb.result(binding)
110
29
  end
111
30
 
112
31
  def require_env(env = nil)
113
32
  dependencies.each { |d| d.require_env(env) }
114
33
  end
115
34
 
116
- def root
117
- filename.parent
118
- end
119
-
120
- def gem_path
121
- @gem_path ||= self.class.default_gem_path(root)
122
- end
123
-
124
- def bindir
125
- @bindir ||= root.join("bin")
126
- end
127
-
128
35
  def sources
129
- @priority_sources + @sources + @default_sources
36
+ @priority_sources + @sources + @default_sources + [SystemGemSource.new(@bundle)]
130
37
  end
131
38
 
132
39
  def add_source(source)
@@ -142,18 +49,39 @@ module Bundler
142
49
  @default_sources.clear
143
50
  end
144
51
 
52
+ def gem_dependencies
53
+ @gem_dependencies ||= dependencies.map { |d| d.to_gem_dependency }
54
+ end
55
+
56
+ alias rubygems? rubygems
57
+ alias system_gems? system_gems
58
+
145
59
  private
146
60
 
147
61
  def default_sources
148
- [GemSource.new(:uri => "http://gems.rubyforge.org"), SystemGemSource.instance]
62
+ [GemSource.new(@bundle, :uri => "http://gems.rubyforge.org")]
63
+ end
64
+
65
+ def load_paths_for_specs(specs, options)
66
+ load_paths = []
67
+ specs.each do |spec|
68
+ next if spec.no_bundle?
69
+ full_gem_path = Pathname.new(spec.full_gem_path)
70
+
71
+ load_paths << load_path_for(full_gem_path, spec.bindir) if spec.bindir
72
+ spec.require_paths.each do |path|
73
+ load_paths << load_path_for(full_gem_path, path)
74
+ end
75
+ end
76
+ load_paths
149
77
  end
150
78
 
151
- def repository
152
- @repository ||= Bundle.new(gem_path, bindir)
79
+ def load_path_for(gem_path, path)
80
+ gem_path.join(path).relative_path_from(@bundle.gem_path).to_s
153
81
  end
154
82
 
155
- def gem_dependencies
156
- @gem_dependencies ||= dependencies.map { |d| d.to_gem_dependency }
83
+ def spec_file_for(spec)
84
+ spec.loaded_from.relative_path_from(@bundle.gem_path).to_s
157
85
  end
158
86
  end
159
87
  end
@@ -11,8 +11,9 @@ module Gem
11
11
  end
12
12
 
13
13
  class Specification
14
- attr_accessor :source
15
- attr_accessor :location
14
+ attr_accessor :source, :location, :no_bundle
15
+
16
+ alias no_bundle? no_bundle
16
17
 
17
18
  remove_method(:specification_version) if method_defined?(:specification_version)
18
19
 
@@ -36,7 +36,14 @@ module Bundler
36
36
  # ==== Returns
37
37
  # <GemBundle>,nil:: If the list of dependencies can be resolved, a
38
38
  # collection of gemspecs is returned. Otherwise, nil is returned.
39
- def self.resolve(requirements, sources, source_requirements = {})
39
+ def self.resolve(requirements, sources)
40
+ source_requirements = {}
41
+
42
+ requirements.each do |r|
43
+ next unless r.source
44
+ source_requirements[r.name] = r.source
45
+ end
46
+
40
47
  resolver = new(sources, source_requirements)
41
48
  result = catch(:success) do
42
49
  resolver.resolve(requirements, {})
@@ -54,6 +61,7 @@ module Bundler
54
61
  # a smaller index in the array.
55
62
  ordered = []
56
63
  result.values.each do |spec1|
64
+ spec1.no_bundle = true if source_requirements[spec1.name] == SystemGemSource.instance
57
65
  index = nil
58
66
  place = ordered.detect do |spec2|
59
67
  spec1.dependencies.any? { |d| d.name == spec2.name }
@@ -4,9 +4,12 @@ module Bundler
4
4
  # Represents a source of rubygems. Initially, this is only gem repositories, but
5
5
  # eventually, this will be git, svn, HTTP
6
6
  class Source
7
- attr_accessor :repository, :local
7
+ attr_accessor :local
8
+ attr_reader :bundle
8
9
 
9
- def initialize(options) ; end
10
+ def initialize(bundle, options)
11
+ @bundle = bundle
12
+ end
10
13
 
11
14
  private
12
15
 
@@ -23,7 +26,8 @@ module Bundler
23
26
  class GemSource < Source
24
27
  attr_reader :uri
25
28
 
26
- def initialize(options)
29
+ def initialize(bundle, options)
30
+ super
27
31
  @uri = options[:uri]
28
32
  @uri = URI.parse(@uri) unless @uri.is_a?(URI)
29
33
  raise ArgumentError, "The source must be an absolute URI" unless @uri.absolute?
@@ -50,7 +54,7 @@ module Bundler
50
54
  def download(spec)
51
55
  Bundler.logger.info "Downloading #{spec.full_name}.gem"
52
56
 
53
- destination = repository.path
57
+ destination = bundle.gem_path
54
58
 
55
59
  unless destination.writable?
56
60
  raise RubygemsRetardation, "destination: #{destination} is not writable"
@@ -99,10 +103,15 @@ module Bundler
99
103
  class SystemGemSource < Source
100
104
 
101
105
  def self.instance
102
- @instance ||= new({})
106
+ @instance
107
+ end
108
+
109
+ def self.new(*args)
110
+ @instance ||= super
103
111
  end
104
112
 
105
- def initialize(options)
113
+ def initialize(bundle, options = {})
114
+ super
106
115
  @source = Gem::SourceIndex.from_installed_gems
107
116
  end
108
117
 
@@ -125,7 +134,7 @@ module Bundler
125
134
  def download(spec)
126
135
  gemfile = Pathname.new(spec.loaded_from)
127
136
  gemfile = gemfile.dirname.join('..', 'cache', "#{spec.full_name}.gem")
128
- repository.cache(gemfile)
137
+ bundle.cache(gemfile)
129
138
  end
130
139
 
131
140
  private
@@ -135,7 +144,8 @@ module Bundler
135
144
  class GemDirectorySource < Source
136
145
  attr_reader :location
137
146
 
138
- def initialize(options)
147
+ def initialize(bundle, options)
148
+ super
139
149
  @location = options[:location]
140
150
  end
141
151
 
@@ -177,7 +187,8 @@ module Bundler
177
187
  class DirectorySource < Source
178
188
  attr_reader :location, :specs, :required_specs
179
189
 
180
- def initialize(options)
190
+ def initialize(bundle, options)
191
+ super
181
192
  if options[:location]
182
193
  @location = Pathname.new(options[:location]).expand_path
183
194
  end
@@ -289,7 +300,7 @@ module Bundler
289
300
  class GitSource < DirectorySource
290
301
  attr_reader :ref, :uri, :branch
291
302
 
292
- def initialize(options)
303
+ def initialize(bundle, options)
293
304
  super
294
305
  @uri = options[:uri]
295
306
  @branch = options[:branch] || 'master'
@@ -298,7 +309,7 @@ module Bundler
298
309
 
299
310
  def location
300
311
  # TMP HAX to get the *.gemspec reading to work
301
- repository.path.join('dirs', File.basename(@uri, '.git'))
312
+ bundle.gem_path.join('dirs', File.basename(@uri, '.git'))
302
313
  end
303
314
 
304
315
  def gems
@@ -3,7 +3,7 @@ module Bundler
3
3
  file = File.expand_path(__FILE__)
4
4
  dir = File.dirname(file)
5
5
 
6
- <% unless options[:system_gems] -%>
6
+ <% unless system_gems? -%>
7
7
  ENV["GEM_HOME"] = dir
8
8
  ENV["GEM_PATH"] = dir
9
9
 
@@ -25,12 +25,12 @@ module Bundler
25
25
 
26
26
  @gemfile = "#{dir}/<%= filename %>"
27
27
 
28
- <% if options[:rubygems] -%>
28
+ <% if rubygems? -%>
29
29
  require "rubygems" unless respond_to?(:gem) # 1.9 already has RubyGems loaded
30
30
 
31
31
  @bundled_specs = {}
32
32
  <% specs.each do |spec| -%>
33
- <% if options[:no_bundle].include?(spec.name) -%>
33
+ <% if spec.no_bundle? -%>
34
34
  gem "<%= spec.name %>", "<%= spec.version %>"
35
35
  <% else -%>
36
36
  <% path = spec_file_for(spec) -%>
@@ -108,7 +108,7 @@ module Bundler
108
108
  end
109
109
  end
110
110
 
111
- <% if options[:rubygems] -%>
111
+ <% if rubygems? -%>
112
112
  module Gem
113
113
  @loaded_stacks = Hash.new { |h,k| h[k] = [] }
114
114
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3.pre
4
+ version: 0.7.3.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yehuda Katz
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-03 00:00:00 -08:00
13
+ date: 2010-01-04 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16