honkster-bundler 1.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -0
- data/CHANGELOG.md +547 -0
- data/ISSUES.md +32 -0
- data/LICENSE +20 -0
- data/README.md +29 -0
- data/Rakefile +150 -0
- data/UPGRADING.md +103 -0
- data/bin/bundle +21 -0
- data/bundler.gemspec +30 -0
- data/lib/bundler.rb +268 -0
- data/lib/bundler/capistrano.rb +11 -0
- data/lib/bundler/cli.rb +515 -0
- data/lib/bundler/definition.rb +427 -0
- data/lib/bundler/dependency.rb +114 -0
- data/lib/bundler/deployment.rb +37 -0
- data/lib/bundler/dsl.rb +245 -0
- data/lib/bundler/environment.rb +47 -0
- data/lib/bundler/gem_helper.rb +145 -0
- data/lib/bundler/graph.rb +130 -0
- data/lib/bundler/index.rb +114 -0
- data/lib/bundler/installer.rb +84 -0
- data/lib/bundler/lazy_specification.rb +71 -0
- data/lib/bundler/lockfile_parser.rb +108 -0
- data/lib/bundler/remote_specification.rb +59 -0
- data/lib/bundler/resolver.rb +454 -0
- data/lib/bundler/rubygems_ext.rb +203 -0
- data/lib/bundler/runtime.rb +148 -0
- data/lib/bundler/settings.rb +117 -0
- data/lib/bundler/setup.rb +15 -0
- data/lib/bundler/shared_helpers.rb +151 -0
- data/lib/bundler/source.rb +662 -0
- data/lib/bundler/spec_set.rb +134 -0
- data/lib/bundler/templates/Executable +16 -0
- data/lib/bundler/templates/Gemfile +4 -0
- data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
- data/lib/bundler/templates/newgem/Rakefile.tt +2 -0
- data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
- data/lib/bundler/templates/newgem/gitignore.tt +3 -0
- data/lib/bundler/templates/newgem/lib/newgem.rb.tt +7 -0
- data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
- data/lib/bundler/templates/newgem/newgem.gemspec.tt +21 -0
- data/lib/bundler/ui.rb +60 -0
- data/lib/bundler/vendor/thor.rb +319 -0
- data/lib/bundler/vendor/thor/actions.rb +297 -0
- data/lib/bundler/vendor/thor/actions/create_file.rb +105 -0
- data/lib/bundler/vendor/thor/actions/directory.rb +93 -0
- data/lib/bundler/vendor/thor/actions/empty_directory.rb +134 -0
- data/lib/bundler/vendor/thor/actions/file_manipulation.rb +229 -0
- data/lib/bundler/vendor/thor/actions/inject_into_file.rb +104 -0
- data/lib/bundler/vendor/thor/base.rb +556 -0
- data/lib/bundler/vendor/thor/core_ext/file_binary_read.rb +9 -0
- data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +75 -0
- data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/bundler/vendor/thor/error.rb +30 -0
- data/lib/bundler/vendor/thor/invocation.rb +168 -0
- data/lib/bundler/vendor/thor/parser.rb +4 -0
- data/lib/bundler/vendor/thor/parser/argument.rb +67 -0
- data/lib/bundler/vendor/thor/parser/arguments.rb +161 -0
- data/lib/bundler/vendor/thor/parser/option.rb +120 -0
- data/lib/bundler/vendor/thor/parser/options.rb +174 -0
- data/lib/bundler/vendor/thor/shell.rb +88 -0
- data/lib/bundler/vendor/thor/shell/basic.rb +275 -0
- data/lib/bundler/vendor/thor/shell/color.rb +108 -0
- data/lib/bundler/vendor/thor/shell/html.rb +121 -0
- data/lib/bundler/vendor/thor/task.rb +114 -0
- data/lib/bundler/vendor/thor/util.rb +229 -0
- data/lib/bundler/vendor/thor/version.rb +3 -0
- data/lib/bundler/version.rb +6 -0
- data/lib/bundler/vlad.rb +9 -0
- data/man/bundle-config.ronn +90 -0
- data/man/bundle-exec.ronn +98 -0
- data/man/bundle-install.ronn +310 -0
- data/man/bundle-package.ronn +59 -0
- data/man/bundle-update.ronn +176 -0
- data/man/bundle.ronn +77 -0
- data/man/gemfile.5.ronn +273 -0
- data/man/index.txt +6 -0
- data/spec/cache/gems_spec.rb +205 -0
- data/spec/cache/git_spec.rb +9 -0
- data/spec/cache/path_spec.rb +27 -0
- data/spec/cache/platform_spec.rb +57 -0
- data/spec/install/deploy_spec.rb +197 -0
- data/spec/install/deprecated_spec.rb +43 -0
- data/spec/install/gems/c_ext_spec.rb +48 -0
- data/spec/install/gems/env_spec.rb +107 -0
- data/spec/install/gems/flex_spec.rb +272 -0
- data/spec/install/gems/groups_spec.rb +228 -0
- data/spec/install/gems/packed_spec.rb +72 -0
- data/spec/install/gems/platform_spec.rb +195 -0
- data/spec/install/gems/resolving_spec.rb +72 -0
- data/spec/install/gems/simple_case_spec.rb +749 -0
- data/spec/install/gems/sudo_spec.rb +77 -0
- data/spec/install/gems/win32_spec.rb +26 -0
- data/spec/install/gemspec_spec.rb +96 -0
- data/spec/install/git_spec.rb +553 -0
- data/spec/install/invalid_spec.rb +17 -0
- data/spec/install/path_spec.rb +329 -0
- data/spec/install/upgrade_spec.rb +26 -0
- data/spec/lock/flex_spec.rb +650 -0
- data/spec/lock/git_spec.rb +35 -0
- data/spec/other/check_spec.rb +221 -0
- data/spec/other/config_spec.rb +40 -0
- data/spec/other/console_spec.rb +54 -0
- data/spec/other/exec_spec.rb +241 -0
- data/spec/other/ext_spec.rb +16 -0
- data/spec/other/gem_helper_spec.rb +126 -0
- data/spec/other/help_spec.rb +36 -0
- data/spec/other/init_spec.rb +40 -0
- data/spec/other/newgem_spec.rb +24 -0
- data/spec/other/open_spec.rb +35 -0
- data/spec/other/show_spec.rb +82 -0
- data/spec/pack/gems_spec.rb +22 -0
- data/spec/quality_spec.rb +55 -0
- data/spec/resolver/basic_spec.rb +20 -0
- data/spec/resolver/platform_spec.rb +57 -0
- data/spec/runtime/environment_rb_spec.rb +162 -0
- data/spec/runtime/executable_spec.rb +110 -0
- data/spec/runtime/load_spec.rb +102 -0
- data/spec/runtime/platform_spec.rb +90 -0
- data/spec/runtime/require_spec.rb +231 -0
- data/spec/runtime/setup_spec.rb +412 -0
- data/spec/runtime/with_clean_env_spec.rb +15 -0
- data/spec/spec_helper.rb +82 -0
- data/spec/support/builders.rb +566 -0
- data/spec/support/helpers.rb +243 -0
- data/spec/support/indexes.rb +113 -0
- data/spec/support/matchers.rb +89 -0
- data/spec/support/path.rb +71 -0
- data/spec/support/platforms.rb +49 -0
- data/spec/support/ruby_ext.rb +19 -0
- data/spec/support/rubygems_ext.rb +30 -0
- data/spec/support/rubygems_hax/rubygems_plugin.rb +9 -0
- data/spec/support/sudo.rb +21 -0
- data/spec/update/gems_spec.rb +112 -0
- data/spec/update/git_spec.rb +159 -0
- data/spec/update/source_spec.rb +50 -0
- metadata +251 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
module Bundler
|
2
|
+
class Deployment
|
3
|
+
def self.define_task(context, task_method = :task, opts = {})
|
4
|
+
context.send :namespace, :bundle do
|
5
|
+
send :desc, <<-DESC
|
6
|
+
Install the current Bundler environment. By default, gems will be \
|
7
|
+
installed to the shared/bundle path. Gems in the development and \
|
8
|
+
test group will not be installed. The install command is executed \
|
9
|
+
with the --deployment and --quiet flags. You can override any of \
|
10
|
+
these defaults by setting the variables shown below. If the bundle \
|
11
|
+
cmd cannot be found then you can override the bundle_cmd variable \
|
12
|
+
to specifiy which one it should use.
|
13
|
+
|
14
|
+
set :bundle_gemfile, "Gemfile"
|
15
|
+
set :bundle_dir, File.join(fetch(:shared_path), 'bundle')
|
16
|
+
set :bundle_flags, "--deployment --quiet"
|
17
|
+
set :bundle_without, [:development, :test]
|
18
|
+
set :bundle_cmd, "bundle" # e.g. change to "/opt/ruby/bin/bundle"
|
19
|
+
DESC
|
20
|
+
send task_method, :install, opts do
|
21
|
+
bundle_cmd = context.fetch(:bundle_cmd, "bundle")
|
22
|
+
bundle_flags = context.fetch(:bundle_flags, "--deployment --quiet")
|
23
|
+
bundle_dir = context.fetch(:bundle_dir, File.join(context.fetch(:shared_path), 'bundle'))
|
24
|
+
bundle_gemfile = context.fetch(:bundle_gemfile, "Gemfile")
|
25
|
+
bundle_without = [*context.fetch(:bundle_without, [:development, :test])].compact
|
26
|
+
|
27
|
+
args = ["--gemfile #{File.join(context.fetch(:current_release), bundle_gemfile)}"]
|
28
|
+
args << "--path #{bundle_dir}" unless bundle_dir.to_s.empty?
|
29
|
+
args << bundle_flags.to_s
|
30
|
+
args << "--without #{bundle_without.join(" ")}" unless bundle_without.empty?
|
31
|
+
|
32
|
+
run "#{bundle_cmd} install #{args.join(' ')}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/bundler/dsl.rb
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
require 'bundler/dependency'
|
2
|
+
|
3
|
+
module Bundler
|
4
|
+
class Dsl
|
5
|
+
def self.evaluate(gemfile, lockfile, unlock)
|
6
|
+
builder = new
|
7
|
+
builder.instance_eval(Bundler.read_file(gemfile.to_s), gemfile.to_s, 1)
|
8
|
+
builder.to_definition(lockfile, unlock)
|
9
|
+
end
|
10
|
+
|
11
|
+
VALID_PLATFORMS = Bundler::Dependency::PLATFORM_MAP.keys.freeze
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@rubygems_source = Source::Rubygems.new
|
15
|
+
@source = nil
|
16
|
+
@sources = []
|
17
|
+
@dependencies = []
|
18
|
+
@groups = []
|
19
|
+
@platforms = []
|
20
|
+
@env = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def gemspec(opts = nil)
|
24
|
+
path = opts && opts[:path] || '.'
|
25
|
+
name = opts && opts[:name] || '*'
|
26
|
+
development_group = opts && opts[:development_group] || :development
|
27
|
+
path = File.expand_path(path, Bundler.default_gemfile.dirname)
|
28
|
+
gemspecs = Dir[File.join(path, "#{name}.gemspec")]
|
29
|
+
|
30
|
+
case gemspecs.size
|
31
|
+
when 1
|
32
|
+
spec = Gem::Specification.load(gemspecs.first)
|
33
|
+
gem spec.name, :path => path
|
34
|
+
spec.runtime_dependencies.each do |dep|
|
35
|
+
gem dep.name, *dep.requirement.as_list
|
36
|
+
end
|
37
|
+
group(development_group) do
|
38
|
+
spec.development_dependencies.each do |dep|
|
39
|
+
gem dep.name, *dep.requirement.as_list
|
40
|
+
end
|
41
|
+
end
|
42
|
+
when 0
|
43
|
+
raise InvalidOption, "There are no gemspecs at #{path}."
|
44
|
+
else
|
45
|
+
raise InvalidOption, "There are multiple gemspecs at #{path}. Please use the :name option to specify which one."
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def gem(name, *args)
|
50
|
+
if name.is_a?(Symbol)
|
51
|
+
raise GemfileError, %{You need to specify gem names as Strings. Use 'gem "#{name.to_s}"' instead.}
|
52
|
+
end
|
53
|
+
|
54
|
+
options = Hash === args.last ? args.pop : {}
|
55
|
+
version = args || [">= 0"]
|
56
|
+
|
57
|
+
_deprecated_options(options)
|
58
|
+
_normalize_options(name, version, options)
|
59
|
+
|
60
|
+
dep = Dependency.new(name, version, options)
|
61
|
+
|
62
|
+
if current = @dependencies.find { |d| d.name == dep.name }
|
63
|
+
if current.requirement != dep.requirement
|
64
|
+
raise DslError, "You cannot specify the same gem twice with different version requirements. " \
|
65
|
+
"You specified: #{current.name} (#{current.requirement}) and " \
|
66
|
+
"#{dep.name} (#{dep.requirement})"
|
67
|
+
end
|
68
|
+
|
69
|
+
if current.source != dep.source
|
70
|
+
raise DslError, "You cannot specify the same gem twice coming from different sources. You " \
|
71
|
+
"specified that #{dep.name} (#{dep.requirement}) should come from " \
|
72
|
+
"#{current.source || 'an unspecfied source'} and #{dep.source}"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
@dependencies << Dependency.new(name, version, options)
|
76
|
+
end
|
77
|
+
|
78
|
+
def source(source, options = {})
|
79
|
+
case source
|
80
|
+
when :gemcutter, :rubygems, :rubyforge then
|
81
|
+
rubygems_source "http://rubygems.org"
|
82
|
+
return
|
83
|
+
when String
|
84
|
+
rubygems_source source
|
85
|
+
return
|
86
|
+
end
|
87
|
+
|
88
|
+
@source = source
|
89
|
+
options[:prepend] ? @sources.unshift(@source) : @sources << @source
|
90
|
+
|
91
|
+
yield if block_given?
|
92
|
+
@source
|
93
|
+
ensure
|
94
|
+
@source = nil
|
95
|
+
end
|
96
|
+
|
97
|
+
def path(path, options = {}, source_options = {}, &blk)
|
98
|
+
source Source::Path.new(_normalize_hash(options).merge("path" => Pathname.new(path))), source_options, &blk
|
99
|
+
end
|
100
|
+
|
101
|
+
def git(uri, options = {}, source_options = {}, &blk)
|
102
|
+
unless block_given?
|
103
|
+
msg = "You can no longer specify a git source by itself. Instead, \n" \
|
104
|
+
"either use the :git option on a gem, or specify the gems that \n" \
|
105
|
+
"bundler should find in the git source by passing a block to \n" \
|
106
|
+
"the git method, like: \n\n" \
|
107
|
+
" git 'git://github.com/rails/rails.git' do\n" \
|
108
|
+
" gem 'rails'\n" \
|
109
|
+
" end"
|
110
|
+
raise DeprecatedError, msg
|
111
|
+
end
|
112
|
+
|
113
|
+
source Source::Git.new(_normalize_hash(options).merge("uri" => uri)), source_options, &blk
|
114
|
+
end
|
115
|
+
|
116
|
+
def to_definition(lockfile, unlock)
|
117
|
+
@sources << @rubygems_source
|
118
|
+
@sources.uniq!
|
119
|
+
Definition.new(lockfile, @dependencies, @sources, unlock)
|
120
|
+
end
|
121
|
+
|
122
|
+
def group(*args, &blk)
|
123
|
+
@groups.concat args
|
124
|
+
yield
|
125
|
+
ensure
|
126
|
+
args.each { @groups.pop }
|
127
|
+
end
|
128
|
+
|
129
|
+
def platforms(*platforms)
|
130
|
+
@platforms.concat platforms
|
131
|
+
yield
|
132
|
+
ensure
|
133
|
+
platforms.each { @platforms.pop }
|
134
|
+
end
|
135
|
+
alias_method :platform, :platforms
|
136
|
+
|
137
|
+
def env(name)
|
138
|
+
@env, old = name, @env
|
139
|
+
yield
|
140
|
+
ensure
|
141
|
+
@env = old
|
142
|
+
end
|
143
|
+
|
144
|
+
# Deprecated methods
|
145
|
+
|
146
|
+
def self.deprecate(name, replacement = nil)
|
147
|
+
define_method(name) do |*|
|
148
|
+
message = "'#{name}' has been removed from the Gemfile DSL, "
|
149
|
+
if replacement
|
150
|
+
message << "and has been replaced with '#{replacement}'."
|
151
|
+
else
|
152
|
+
message << "and is no longer supported."
|
153
|
+
end
|
154
|
+
message << "\nSee the README for more information on upgrading from Bundler 0.8."
|
155
|
+
raise DeprecatedError, message
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
deprecate :only, :group
|
160
|
+
deprecate :except
|
161
|
+
deprecate :disable_system_gems
|
162
|
+
deprecate :disable_rubygems
|
163
|
+
deprecate :clear_sources
|
164
|
+
deprecate :bundle_path
|
165
|
+
deprecate :bin_path
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
def rubygems_source(source)
|
170
|
+
@rubygems_source.add_remote source
|
171
|
+
@sources << @rubygems_source
|
172
|
+
end
|
173
|
+
|
174
|
+
def _normalize_hash(opts)
|
175
|
+
# Cannot modify a hash during an iteration in 1.9
|
176
|
+
opts.keys.each do |k|
|
177
|
+
next if String === k
|
178
|
+
v = opts[k]
|
179
|
+
opts.delete(k)
|
180
|
+
opts[k.to_s] = v
|
181
|
+
end
|
182
|
+
opts
|
183
|
+
end
|
184
|
+
|
185
|
+
def _normalize_options(name, version, opts)
|
186
|
+
_normalize_hash(opts)
|
187
|
+
|
188
|
+
invalid_keys = opts.keys - %w(group groups git path name branch ref tag require submodules platform platforms)
|
189
|
+
if invalid_keys.any?
|
190
|
+
plural = invalid_keys.size > 1
|
191
|
+
message = "You passed #{invalid_keys.map{|k| ':'+k }.join(", ")} "
|
192
|
+
if plural
|
193
|
+
message << "as options for gem '#{name}', but they are invalid."
|
194
|
+
else
|
195
|
+
message << "as an option for gem '#{name}', but it is invalid."
|
196
|
+
end
|
197
|
+
raise InvalidOption, message
|
198
|
+
end
|
199
|
+
|
200
|
+
groups = @groups.dup
|
201
|
+
opts["group"] = opts.delete("groups") || opts["group"]
|
202
|
+
groups.concat Array(opts.delete("group"))
|
203
|
+
groups = [:default] if groups.empty?
|
204
|
+
|
205
|
+
platforms = @platforms.dup
|
206
|
+
opts["platforms"] = opts["platform"] || opts["platforms"]
|
207
|
+
platforms.concat Array(opts.delete("platforms"))
|
208
|
+
platforms.map! { |p| p.to_sym }
|
209
|
+
platforms.each do |p|
|
210
|
+
next if VALID_PLATFORMS.include?(p)
|
211
|
+
raise DslError, "`#{p}` is not a valid platform. The available options are: #{VALID_PLATFORMS.inspect}"
|
212
|
+
end
|
213
|
+
|
214
|
+
# Normalize git and path options
|
215
|
+
["git", "path"].each do |type|
|
216
|
+
if param = opts[type]
|
217
|
+
if version.first && version.first =~ /^\s*=?\s*(\d[^\s]*)\s*$/
|
218
|
+
options = opts.merge("name" => name, "version" => $1)
|
219
|
+
else
|
220
|
+
options = opts.dup
|
221
|
+
end
|
222
|
+
source = send(type, param, options, :prepend => true) {}
|
223
|
+
opts["source"] = source
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
opts["source"] ||= @source
|
228
|
+
opts["env"] ||= @env
|
229
|
+
opts["platforms"] = platforms.dup
|
230
|
+
opts["group"] = groups
|
231
|
+
end
|
232
|
+
|
233
|
+
def _deprecated_options(options)
|
234
|
+
if options.include?(:require_as)
|
235
|
+
raise DeprecatedError, "Please replace :require_as with :require"
|
236
|
+
elsif options.include?(:vendored_at)
|
237
|
+
raise DeprecatedError, "Please replace :vendored_at with :path"
|
238
|
+
elsif options.include?(:only)
|
239
|
+
raise DeprecatedError, "Please replace :only with :group"
|
240
|
+
elsif options.include?(:except)
|
241
|
+
raise DeprecatedError, "The :except option is no longer supported"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Bundler
|
2
|
+
class Environment
|
3
|
+
attr_reader :root
|
4
|
+
|
5
|
+
def initialize(root, definition)
|
6
|
+
@root = root
|
7
|
+
@definition = definition
|
8
|
+
|
9
|
+
env_file = Bundler.app_config_path.join('environment.rb')
|
10
|
+
env_file.rmtree if env_file.exist?
|
11
|
+
end
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
@definition.to_lock.inspect
|
15
|
+
end
|
16
|
+
|
17
|
+
# TODO: Remove this method. It's used in cli.rb still
|
18
|
+
def index
|
19
|
+
@definition.index
|
20
|
+
end
|
21
|
+
|
22
|
+
def requested_specs
|
23
|
+
@definition.requested_specs
|
24
|
+
end
|
25
|
+
|
26
|
+
def specs
|
27
|
+
@definition.specs
|
28
|
+
end
|
29
|
+
|
30
|
+
def dependencies
|
31
|
+
@definition.dependencies
|
32
|
+
end
|
33
|
+
|
34
|
+
def current_dependencies
|
35
|
+
@definition.current_dependencies
|
36
|
+
end
|
37
|
+
|
38
|
+
def lock
|
39
|
+
@definition.lock(Bundler.default_lockfile)
|
40
|
+
end
|
41
|
+
|
42
|
+
def update(*gems)
|
43
|
+
# Nothing
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
$:.unshift File.expand_path('../vendor', __FILE__)
|
2
|
+
require 'thor'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
module Bundler
|
6
|
+
class GemHelper
|
7
|
+
def self.install_tasks(opts = nil)
|
8
|
+
dir = File.dirname(Rake.application.rakefile_location)
|
9
|
+
self.new(dir, opts && opts[:name]).install
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :spec_path, :base, :gemspec
|
13
|
+
|
14
|
+
def initialize(base, name = nil)
|
15
|
+
Bundler.ui = UI::Shell.new(Thor::Shell::Color.new)
|
16
|
+
@base = base
|
17
|
+
gemspecs = name ? [File.join(base, "#{name}.gemspec")] : Dir[File.join(base, "*.gemspec")]
|
18
|
+
raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1
|
19
|
+
@spec_path = gemspecs.first
|
20
|
+
@gemspec = Bundler.load_gemspec(@spec_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def install
|
24
|
+
desc "Build #{name}-#{version}.gem into the pkg directory"
|
25
|
+
task 'build' do
|
26
|
+
build_gem
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Build and install #{name}-#{version}.gem into system gems"
|
30
|
+
task 'install' do
|
31
|
+
install_gem
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Create tag #{version_tag} and build and push #{name}-#{version}.gem to Rubygems"
|
35
|
+
task 'release' do
|
36
|
+
release_gem
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def build_gem
|
41
|
+
file_name = nil
|
42
|
+
sh("gem build #{spec_path}") { |out, code|
|
43
|
+
raise out unless out[/Successfully/]
|
44
|
+
file_name = File.basename(built_gem_path)
|
45
|
+
FileUtils.mkdir_p(File.join(base, 'pkg'))
|
46
|
+
FileUtils.mv(built_gem_path, 'pkg')
|
47
|
+
Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}"
|
48
|
+
}
|
49
|
+
File.join(base, 'pkg', file_name)
|
50
|
+
end
|
51
|
+
|
52
|
+
def install_gem
|
53
|
+
built_gem_path = build_gem
|
54
|
+
out, code = sh_with_code("gem install #{built_gem_path}")
|
55
|
+
raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" unless out[/Successfully installed/]
|
56
|
+
Bundler.ui.confirm "#{name} (#{version}) installed"
|
57
|
+
end
|
58
|
+
|
59
|
+
def release_gem
|
60
|
+
guard_clean
|
61
|
+
guard_already_tagged
|
62
|
+
built_gem_path = build_gem
|
63
|
+
tag_version {
|
64
|
+
git_push
|
65
|
+
rubygem_push(built_gem_path)
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
protected
|
70
|
+
def rubygem_push(path)
|
71
|
+
out, status = sh("gem push #{path}")
|
72
|
+
raise "Gem push failed due to lack of RubyGems.org credentials." if out[/Enter your RubyGems.org credentials/]
|
73
|
+
Bundler.ui.confirm "Pushed #{name} #{version} to rubygems.org"
|
74
|
+
end
|
75
|
+
|
76
|
+
def built_gem_path
|
77
|
+
Dir[File.join(base, "#{name}-*.gem")].sort_by{|f| File.mtime(f)}.last
|
78
|
+
end
|
79
|
+
|
80
|
+
def git_push
|
81
|
+
perform_git_push
|
82
|
+
perform_git_push ' --tags'
|
83
|
+
Bundler.ui.confirm "Pushed git commits and tags"
|
84
|
+
end
|
85
|
+
|
86
|
+
def perform_git_push(options = '')
|
87
|
+
cmd = "git push #{options}"
|
88
|
+
out, code = sh_with_code(cmd)
|
89
|
+
raise "Couldn't git push. `#{cmd}' failed with the following output:\n\n#{out}\n" unless code == 0
|
90
|
+
end
|
91
|
+
|
92
|
+
def guard_already_tagged
|
93
|
+
if sh('git tag').split(/\n/).include?(version_tag)
|
94
|
+
raise("This tag has already been committed to the repo.")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def guard_clean
|
99
|
+
clean? or raise("There are files that need to be committed first.")
|
100
|
+
end
|
101
|
+
|
102
|
+
def clean?
|
103
|
+
out, code = sh_with_code("git diff --exit-code")
|
104
|
+
code == 0
|
105
|
+
end
|
106
|
+
|
107
|
+
def tag_version
|
108
|
+
sh "git tag -a -m \"Version #{version}\" #{version_tag}"
|
109
|
+
Bundler.ui.confirm "Tagged #{version_tag}"
|
110
|
+
yield if block_given?
|
111
|
+
rescue
|
112
|
+
Bundler.ui.error "Untagged #{version_tag} due to error"
|
113
|
+
sh_with_code "git tag -d #{version_tag}"
|
114
|
+
raise
|
115
|
+
end
|
116
|
+
|
117
|
+
def version
|
118
|
+
gemspec.version
|
119
|
+
end
|
120
|
+
|
121
|
+
def version_tag
|
122
|
+
"v#{version}"
|
123
|
+
end
|
124
|
+
|
125
|
+
def name
|
126
|
+
gemspec.name
|
127
|
+
end
|
128
|
+
|
129
|
+
def sh(cmd, &block)
|
130
|
+
out, code = sh_with_code(cmd, &block)
|
131
|
+
code == 0 ? out : raise(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out)
|
132
|
+
end
|
133
|
+
|
134
|
+
def sh_with_code(cmd, &block)
|
135
|
+
outbuf = ''
|
136
|
+
Dir.chdir(base) {
|
137
|
+
outbuf = `#{cmd} 2>&1`
|
138
|
+
if $? == 0
|
139
|
+
block.call(outbuf) if block
|
140
|
+
end
|
141
|
+
}
|
142
|
+
[outbuf, $?]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|