capistrano 2.0.0 → 2.15.5
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 +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +7 -0
- data/CHANGELOG +737 -18
- data/Gemfile +13 -0
- data/README.md +94 -0
- data/Rakefile +11 -0
- data/bin/cap +0 -0
- data/bin/capify +37 -22
- data/capistrano.gemspec +40 -0
- data/lib/capistrano/callback.rb +5 -1
- data/lib/capistrano/cli/execute.rb +10 -7
- data/lib/capistrano/cli/help.rb +39 -16
- data/lib/capistrano/cli/help.txt +44 -16
- data/lib/capistrano/cli/options.rb +71 -11
- data/lib/capistrano/cli/ui.rb +13 -1
- data/lib/capistrano/cli.rb +5 -5
- data/lib/capistrano/command.rb +215 -58
- data/lib/capistrano/configuration/actions/file_transfer.rb +29 -14
- data/lib/capistrano/configuration/actions/inspect.rb +3 -3
- data/lib/capistrano/configuration/actions/invocation.rb +224 -22
- data/lib/capistrano/configuration/alias_task.rb +26 -0
- data/lib/capistrano/configuration/callbacks.rb +26 -27
- data/lib/capistrano/configuration/connections.rb +130 -52
- data/lib/capistrano/configuration/execution.rb +34 -18
- data/lib/capistrano/configuration/loading.rb +99 -6
- data/lib/capistrano/configuration/log_formatters.rb +75 -0
- data/lib/capistrano/configuration/namespaces.rb +45 -12
- data/lib/capistrano/configuration/roles.rb +28 -2
- data/lib/capistrano/configuration/servers.rb +51 -10
- data/lib/capistrano/configuration/variables.rb +3 -3
- data/lib/capistrano/configuration.rb +20 -4
- data/lib/capistrano/errors.rb +12 -8
- data/lib/capistrano/ext/multistage.rb +67 -0
- data/lib/capistrano/ext/string.rb +5 -0
- data/lib/capistrano/extensions.rb +1 -1
- data/lib/capistrano/fix_rake_deprecated_dsl.rb +8 -0
- data/lib/capistrano/logger.rb +112 -5
- data/lib/capistrano/processable.rb +55 -0
- data/lib/capistrano/recipes/compat.rb +2 -2
- data/lib/capistrano/recipes/deploy/assets.rb +201 -0
- data/lib/capistrano/recipes/deploy/dependencies.rb +2 -2
- data/lib/capistrano/recipes/deploy/local_dependency.rb +10 -2
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +54 -2
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
- data/lib/capistrano/recipes/deploy/scm/base.rb +31 -11
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +14 -14
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +11 -9
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +12 -1
- data/lib/capistrano/recipes/deploy/scm/git.rb +293 -0
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +23 -15
- data/lib/capistrano/recipes/deploy/scm/none.rb +55 -0
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +54 -28
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +36 -18
- data/lib/capistrano/recipes/deploy/scm.rb +1 -1
- data/lib/capistrano/recipes/deploy/strategy/base.rb +32 -4
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +238 -43
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +1 -1
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +11 -1
- data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +21 -0
- data/lib/capistrano/recipes/deploy/strategy.rb +1 -1
- data/lib/capistrano/recipes/deploy.rb +265 -123
- data/lib/capistrano/recipes/standard.rb +1 -1
- data/lib/capistrano/role.rb +102 -0
- data/lib/capistrano/server_definition.rb +6 -1
- data/lib/capistrano/shell.rb +30 -33
- data/lib/capistrano/ssh.rb +46 -60
- data/lib/capistrano/task_definition.rb +16 -8
- data/lib/capistrano/transfer.rb +218 -0
- data/lib/capistrano/version.rb +6 -17
- data/lib/capistrano.rb +4 -1
- data/test/cli/execute_test.rb +3 -3
- data/test/cli/help_test.rb +33 -7
- data/test/cli/options_test.rb +109 -6
- data/test/cli/ui_test.rb +2 -2
- data/test/cli_test.rb +3 -3
- data/test/command_test.rb +144 -124
- data/test/configuration/actions/file_transfer_test.rb +41 -20
- data/test/configuration/actions/inspect_test.rb +21 -7
- data/test/configuration/actions/invocation_test.rb +123 -30
- data/test/configuration/alias_task_test.rb +118 -0
- data/test/configuration/callbacks_test.rb +41 -46
- data/test/configuration/connections_test.rb +187 -36
- data/test/configuration/execution_test.rb +18 -2
- data/test/configuration/loading_test.rb +33 -4
- data/test/configuration/namespace_dsl_test.rb +54 -5
- data/test/configuration/roles_test.rb +114 -4
- data/test/configuration/servers_test.rb +97 -4
- data/test/configuration/variables_test.rb +12 -2
- data/test/configuration_test.rb +9 -13
- data/test/deploy/local_dependency_test.rb +76 -0
- data/test/deploy/remote_dependency_test.rb +146 -0
- data/test/deploy/scm/accurev_test.rb +23 -0
- data/test/deploy/scm/base_test.rb +1 -1
- data/test/deploy/scm/bzr_test.rb +51 -0
- data/test/deploy/scm/darcs_test.rb +37 -0
- data/test/deploy/scm/git_test.rb +274 -0
- data/test/deploy/scm/mercurial_test.rb +134 -0
- data/test/deploy/scm/none_test.rb +35 -0
- data/test/deploy/scm/perforce_test.rb +23 -0
- data/test/deploy/scm/subversion_test.rb +68 -0
- data/test/deploy/strategy/copy_test.rb +240 -26
- data/test/extensions_test.rb +2 -2
- data/test/logger_formatting_test.rb +149 -0
- data/test/logger_test.rb +13 -2
- data/test/recipes_test.rb +25 -0
- data/test/role_test.rb +11 -0
- data/test/server_definition_test.rb +15 -2
- data/test/shell_test.rb +33 -1
- data/test/ssh_test.rb +40 -24
- data/test/task_definition_test.rb +18 -2
- data/test/transfer_test.rb +168 -0
- data/test/utils.rb +28 -33
- metadata +215 -101
- data/MIT-LICENSE +0 -20
- data/README +0 -43
- data/examples/sample.rb +0 -14
- data/lib/capistrano/gateway.rb +0 -131
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/recipes/upgrade.rb +0 -33
- data/lib/capistrano/upload.rb +0 -146
- data/test/gateway_test.rb +0 -167
- data/test/upload_test.rb +0 -131
- data/test/version_test.rb +0 -24
|
@@ -23,6 +23,60 @@ module Capistrano
|
|
|
23
23
|
def initialize_with_invocation(*args) #:nodoc:
|
|
24
24
|
initialize_without_invocation(*args)
|
|
25
25
|
set :default_environment, {}
|
|
26
|
+
set :default_run_options, {}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Executes different commands in parallel. This is useful for commands
|
|
30
|
+
# that need to be different on different hosts, but which could be
|
|
31
|
+
# otherwise run in parallel.
|
|
32
|
+
#
|
|
33
|
+
# The +options+ parameter is currently unused.
|
|
34
|
+
#
|
|
35
|
+
# Example:
|
|
36
|
+
#
|
|
37
|
+
# task :restart_everything do
|
|
38
|
+
# parallel do |session|
|
|
39
|
+
# session.when "in?(:app)", "/path/to/restart/mongrel"
|
|
40
|
+
# session.when "in?(:web)", "/path/to/restart/apache"
|
|
41
|
+
# session.when "in?(:db)", "/path/to/restart/mysql"
|
|
42
|
+
# end
|
|
43
|
+
# end
|
|
44
|
+
#
|
|
45
|
+
# Each command may have its own callback block, for capturing and
|
|
46
|
+
# responding to output, with semantics identical to #run:
|
|
47
|
+
#
|
|
48
|
+
# session.when "in?(:app)", "/path/to/restart/mongrel" do |ch, stream, data|
|
|
49
|
+
# # ch is the SSH channel for this command, used to send data
|
|
50
|
+
# # back to the command (e.g. ch.send_data("password\n"))
|
|
51
|
+
# # stream is either :out or :err, for which stream the data arrived on
|
|
52
|
+
# # data is a string containing data sent from the remote command
|
|
53
|
+
# end
|
|
54
|
+
#
|
|
55
|
+
# Also, you can specify a fallback command, to use when none of the
|
|
56
|
+
# conditions match a server:
|
|
57
|
+
#
|
|
58
|
+
# session.else "/execute/something/else"
|
|
59
|
+
#
|
|
60
|
+
# The string specified as the first argument to +when+ may be any valid
|
|
61
|
+
# Ruby code. It has access to the following variables and methods:
|
|
62
|
+
#
|
|
63
|
+
# * +in?(role)+ returns true if the server participates in the given role
|
|
64
|
+
# * +server+ is the ServerDefinition object for the server. This can be
|
|
65
|
+
# used to get the host-name, etc.
|
|
66
|
+
# * +configuration+ is the current Capistrano::Configuration object, which
|
|
67
|
+
# you can use to get the value of variables, etc.
|
|
68
|
+
#
|
|
69
|
+
# For example:
|
|
70
|
+
#
|
|
71
|
+
# session.when "server.host =~ /app/", "/some/command"
|
|
72
|
+
# session.when "server.host == configuration[:some_var]", "/another/command"
|
|
73
|
+
# session.when "in?(:web) || in?(:app)", "/more/commands"
|
|
74
|
+
#
|
|
75
|
+
# See #run for a description of the valid +options+.
|
|
76
|
+
def parallel(options={})
|
|
77
|
+
raise ArgumentError, "parallel() requires a block" unless block_given?
|
|
78
|
+
tree = Command::Tree.new(self) { |t| yield t }
|
|
79
|
+
run_tree(tree, options)
|
|
26
80
|
end
|
|
27
81
|
|
|
28
82
|
# Invokes the given command. If a +via+ key is given, it will be used
|
|
@@ -41,37 +95,146 @@ module Capistrano
|
|
|
41
95
|
# channel (which may be used to send data back to the remote process),
|
|
42
96
|
# the stream identifier (<tt>:err</tt> for stderr, and <tt>:out</tt> for
|
|
43
97
|
# stdout), and the data that was received.
|
|
98
|
+
#
|
|
99
|
+
# The +options+ hash may include any of the following keys:
|
|
100
|
+
#
|
|
101
|
+
# * :hosts - this is either a string (for a single target host) or an array
|
|
102
|
+
# of strings, indicating which hosts the command should run on. By default,
|
|
103
|
+
# the hosts are determined from the task definition.
|
|
104
|
+
# * :roles - this is either a string or symbol (for a single target role) or
|
|
105
|
+
# an array of strings or symbols, indicating which roles the command should
|
|
106
|
+
# run on. If :hosts is specified, :roles will be ignored.
|
|
107
|
+
# * :only - specifies a condition limiting which hosts will be selected to
|
|
108
|
+
# run the command. This should refer to values set in the role definition.
|
|
109
|
+
# For example, if a role is defined with :primary => true, then you could
|
|
110
|
+
# select only hosts with :primary true by setting :only => { :primary => true }.
|
|
111
|
+
# * :except - specifies a condition limiting which hosts will be selected to
|
|
112
|
+
# run the command. This is the inverse of :only (hosts that do _not_ match
|
|
113
|
+
# the condition will be selected).
|
|
114
|
+
# * :on_no_matching_servers - if :continue, will continue to execute tasks if
|
|
115
|
+
# no matching servers are found for the host criteria. The default is to raise
|
|
116
|
+
# a NoMatchingServersError exception.
|
|
117
|
+
# * :once - if true, only the first matching server will be selected. The default
|
|
118
|
+
# is false (all matching servers will be selected).
|
|
119
|
+
# * :max_hosts - specifies the maximum number of hosts that should be selected
|
|
120
|
+
# at a time. If this value is less than the number of hosts that are selected
|
|
121
|
+
# to run, then the hosts will be run in groups of max_hosts. The default is nil,
|
|
122
|
+
# which indicates that there is no maximum host limit. Please note this does not
|
|
123
|
+
# limit the number of SSH channels that can be open, only the number of hosts upon
|
|
124
|
+
# which this will be called.
|
|
125
|
+
# * :shell - says which shell should be used to invoke commands. This
|
|
126
|
+
# defaults to "sh". Setting this to false causes Capistrano to invoke
|
|
127
|
+
# the commands directly, without wrapping them in a shell invocation.
|
|
128
|
+
# * :data - if not nil (the default), this should be a string that will
|
|
129
|
+
# be passed to the command's stdin stream.
|
|
130
|
+
# * :pty - if true, a pseudo-tty will be allocated for each command. The
|
|
131
|
+
# default is false. Note that there are benefits and drawbacks both ways.
|
|
132
|
+
# Empirically, it appears that if a pty is allocated, the SSH server daemon
|
|
133
|
+
# will _not_ read user shell start-up scripts (e.g. bashrc, etc.). However,
|
|
134
|
+
# if a pty is _not_ allocated, some commands will refuse to run in
|
|
135
|
+
# interactive mode and will not prompt for (e.g.) passwords.
|
|
136
|
+
# * :env - a hash of environment variable mappings that should be made
|
|
137
|
+
# available to the command. The keys should be environment variable names,
|
|
138
|
+
# and the values should be their corresponding values. The default is
|
|
139
|
+
# empty, but may be modified by changing the +default_environment+
|
|
140
|
+
# Capistrano variable.
|
|
141
|
+
# * :eof - if true, the standard input stream will be closed after sending
|
|
142
|
+
# any data specified in the :data option. If false, the input stream is
|
|
143
|
+
# left open. The default is to close the input stream only if no block is
|
|
144
|
+
# passed.
|
|
145
|
+
#
|
|
146
|
+
# Note that if you set these keys in the +default_run_options+ Capistrano
|
|
147
|
+
# variable, they will apply for all invocations of #run, #invoke_command,
|
|
148
|
+
# and #parallel.
|
|
44
149
|
def run(cmd, options={}, &block)
|
|
150
|
+
if options[:eof].nil? && !cmd.include?(sudo)
|
|
151
|
+
options = options.merge(:eof => !block_given?)
|
|
152
|
+
end
|
|
45
153
|
block ||= self.class.default_io_proc
|
|
46
|
-
|
|
154
|
+
tree = Command::Tree.new(self) { |t| t.else(cmd, &block) }
|
|
155
|
+
run_tree(tree, options)
|
|
156
|
+
end
|
|
47
157
|
|
|
158
|
+
# Executes a Capistrano::Command::Tree object. This is not for direct
|
|
159
|
+
# use, but should instead be called indirectly, via #run or #parallel,
|
|
160
|
+
# or #invoke_command.
|
|
161
|
+
def run_tree(tree, options={}) #:nodoc:
|
|
48
162
|
options = add_default_command_options(options)
|
|
49
163
|
|
|
164
|
+
if tree.branches.any? || tree.fallback
|
|
165
|
+
_, servers = filter_servers(options)
|
|
166
|
+
branches = branches_for_servers(tree,servers)
|
|
167
|
+
case branches.size
|
|
168
|
+
when 0
|
|
169
|
+
branches = tree.branches.dup + [tree.fallback]
|
|
170
|
+
branches.compact!
|
|
171
|
+
case branches.size
|
|
172
|
+
when 1
|
|
173
|
+
logger.debug "no servers for #{branches.first}"
|
|
174
|
+
else
|
|
175
|
+
logger.debug "no servers for commands"
|
|
176
|
+
branches.each{ |branch| logger.trace "-> #{branch.to_s(true)}" }
|
|
177
|
+
end
|
|
178
|
+
when 1
|
|
179
|
+
logger.debug "executing #{branches.first}" unless options[:silent]
|
|
180
|
+
else
|
|
181
|
+
logger.debug "executing multiple commands in parallel"
|
|
182
|
+
branches.each {|branch| logger.trace "-> #{branch.to_s(true)}" }
|
|
183
|
+
end
|
|
184
|
+
else
|
|
185
|
+
raise ArgumentError, "attempt to execute without specifying a command"
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
return if dry_run || (debug && continue_execution(tree) == false)
|
|
189
|
+
|
|
190
|
+
tree.each do |branch|
|
|
191
|
+
if branch.command.include?(sudo)
|
|
192
|
+
branch.callback = sudo_behavior_callback(branch.callback)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
50
196
|
execute_on_servers(options) do |servers|
|
|
51
197
|
targets = servers.map { |s| sessions[s] }
|
|
52
|
-
Command.process(
|
|
198
|
+
Command.process(tree, targets, options.merge(:logger => logger))
|
|
53
199
|
end
|
|
54
200
|
end
|
|
55
201
|
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
# logging in to the server.
|
|
202
|
+
# Returns the command string used by capistrano to invoke a comamnd via
|
|
203
|
+
# sudo.
|
|
59
204
|
#
|
|
60
|
-
#
|
|
205
|
+
# run "#{sudo :as => 'bob'} mkdir /path/to/dir"
|
|
206
|
+
#
|
|
207
|
+
# It can also be invoked like #run, but executing the command via sudo.
|
|
208
|
+
# This assumes that the sudo password (if required) is the same as the
|
|
209
|
+
# password for logging in to the server.
|
|
210
|
+
#
|
|
211
|
+
# sudo "mkdir /path/to/dir"
|
|
212
|
+
#
|
|
213
|
+
# Also, this method understands a <tt>:sudo</tt> configuration variable,
|
|
61
214
|
# which (if specified) will be used as the full path to the sudo
|
|
62
215
|
# executable on the remote machine:
|
|
63
216
|
#
|
|
64
217
|
# set :sudo, "/opt/local/bin/sudo"
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
218
|
+
#
|
|
219
|
+
# If you know what you're doing, you can also set <tt>:sudo_prompt</tt>,
|
|
220
|
+
# which tells capistrano which prompt sudo should use when asking for
|
|
221
|
+
# a password. (This is so that capistrano knows what prompt to look for
|
|
222
|
+
# in the output.) If you set :sudo_prompt to an empty string, Capistrano
|
|
223
|
+
# will not send a preferred prompt.
|
|
224
|
+
def sudo(*parameters, &block)
|
|
225
|
+
options = parameters.last.is_a?(Hash) ? parameters.pop.dup : {}
|
|
226
|
+
command = parameters.first
|
|
227
|
+
user = options[:as] && "-u #{options.delete(:as)}"
|
|
70
228
|
|
|
71
|
-
|
|
72
|
-
|
|
229
|
+
sudo_prompt_option = "-p '#{sudo_prompt}'" unless sudo_prompt.empty?
|
|
230
|
+
sudo_command = [fetch(:sudo, "sudo"), sudo_prompt_option, user].compact.join(" ")
|
|
73
231
|
|
|
74
|
-
|
|
232
|
+
if command
|
|
233
|
+
command = sudo_command + " " + command
|
|
234
|
+
run(command, options, &block)
|
|
235
|
+
else
|
|
236
|
+
return sudo_command
|
|
237
|
+
end
|
|
75
238
|
end
|
|
76
239
|
|
|
77
240
|
# Returns a Proc object that defines the behavior of the sudo
|
|
@@ -83,17 +246,19 @@ module Capistrano
|
|
|
83
246
|
# was wrong, let's track which host prompted first and only allow
|
|
84
247
|
# subsequent prompts from that host.
|
|
85
248
|
prompt_host = nil
|
|
86
|
-
|
|
249
|
+
|
|
87
250
|
Proc.new do |ch, stream, out|
|
|
88
|
-
if out =~ /
|
|
89
|
-
ch.send_data "#{self[:password]}\n"
|
|
90
|
-
elsif out =~ /try again/
|
|
251
|
+
if out =~ /^Sorry, try again/
|
|
91
252
|
if prompt_host.nil? || prompt_host == ch[:server]
|
|
92
253
|
prompt_host = ch[:server]
|
|
93
254
|
logger.important out, "#{stream} :: #{ch[:server]}"
|
|
94
255
|
reset! :password
|
|
95
256
|
end
|
|
96
|
-
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
if out =~ /^#{Regexp.escape(sudo_prompt)}/
|
|
260
|
+
ch.send_data "#{self[:password]}\n"
|
|
261
|
+
elsif fallback
|
|
97
262
|
fallback.call(ch, stream, out)
|
|
98
263
|
end
|
|
99
264
|
end
|
|
@@ -110,18 +275,55 @@ module Capistrano
|
|
|
110
275
|
# Otherwise, if the :default_shell key exists in the configuration,
|
|
111
276
|
# it will be used. Otherwise, no :shell key is added.
|
|
112
277
|
def add_default_command_options(options)
|
|
113
|
-
|
|
278
|
+
defaults = self[:default_run_options]
|
|
279
|
+
options = defaults.merge(options)
|
|
114
280
|
|
|
115
281
|
env = self[:default_environment]
|
|
116
282
|
env = env.merge(options[:env]) if options[:env]
|
|
117
283
|
options[:env] = env unless env.empty?
|
|
118
284
|
|
|
119
285
|
shell = options[:shell] || self[:default_shell]
|
|
120
|
-
options[:shell] = shell
|
|
286
|
+
options[:shell] = shell unless shell.nil?
|
|
121
287
|
|
|
122
288
|
options
|
|
123
289
|
end
|
|
290
|
+
|
|
291
|
+
# Returns the prompt text to use with sudo
|
|
292
|
+
def sudo_prompt
|
|
293
|
+
fetch(:sudo_prompt, "sudo password: ")
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def continue_execution(tree)
|
|
297
|
+
if tree.branches.length == 1
|
|
298
|
+
continue_execution_for_branch(tree.branches.first)
|
|
299
|
+
else
|
|
300
|
+
tree.each { |branch| branch.skip! unless continue_execution_for_branch(branch) }
|
|
301
|
+
tree.any? { |branch| !branch.skip? }
|
|
302
|
+
end
|
|
303
|
+
end
|
|
304
|
+
|
|
305
|
+
def continue_execution_for_branch(branch)
|
|
306
|
+
case Capistrano::CLI.debug_prompt(branch)
|
|
307
|
+
when "y"
|
|
308
|
+
true
|
|
309
|
+
when "n"
|
|
310
|
+
false
|
|
311
|
+
when "a"
|
|
312
|
+
exit(-1)
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
private
|
|
317
|
+
def branches_for_servers(tree,servers)
|
|
318
|
+
servers.inject([]) do |branches,server|
|
|
319
|
+
if server_branches = tree.branches_for(server)
|
|
320
|
+
branches += server_branches
|
|
321
|
+
end
|
|
322
|
+
branches
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
|
|
124
326
|
end
|
|
125
327
|
end
|
|
126
328
|
end
|
|
127
|
-
end
|
|
329
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module Capistrano
|
|
2
|
+
class Configuration
|
|
3
|
+
module AliasTask
|
|
4
|
+
# Attempts to find the task at the given fully-qualified path, and
|
|
5
|
+
# alias it. If arguments don't have correct task names, an ArgumentError
|
|
6
|
+
# wil be raised. If no such task exists, a Capistrano::NoSuchTaskError
|
|
7
|
+
# will be raised.
|
|
8
|
+
#
|
|
9
|
+
# Usage:
|
|
10
|
+
#
|
|
11
|
+
# alias_task :original_deploy, :deploy
|
|
12
|
+
#
|
|
13
|
+
def alias_task(new_name, old_name)
|
|
14
|
+
if !new_name.respond_to?(:to_sym) or !old_name.respond_to?(:to_sym)
|
|
15
|
+
raise ArgumentError, "expected a valid task name"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
original_task = find_task(old_name) or raise NoSuchTaskError, "the task `#{old_name}' does not exist"
|
|
19
|
+
task = original_task.dup # Dup. task to avoid modify original task
|
|
20
|
+
task.name = new_name
|
|
21
|
+
|
|
22
|
+
define_task(task)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -4,7 +4,7 @@ module Capistrano
|
|
|
4
4
|
class Configuration
|
|
5
5
|
module Callbacks
|
|
6
6
|
def self.included(base) #:nodoc:
|
|
7
|
-
%w(initialize
|
|
7
|
+
%w(initialize invoke_task_directly).each do |method|
|
|
8
8
|
base.send :alias_method, "#{method}_without_callbacks", method
|
|
9
9
|
base.send :alias_method, method, "#{method}_with_callbacks"
|
|
10
10
|
end
|
|
@@ -18,19 +18,14 @@ module Capistrano
|
|
|
18
18
|
@callbacks = {}
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
def
|
|
22
|
-
before = find_hook(task, :before)
|
|
23
|
-
execute_task(before) if before
|
|
21
|
+
def invoke_task_directly_with_callbacks(task) #:nodoc:
|
|
24
22
|
|
|
25
23
|
trigger :before, task
|
|
26
24
|
|
|
27
|
-
result =
|
|
25
|
+
result = invoke_task_directly_without_callbacks(task)
|
|
28
26
|
|
|
29
27
|
trigger :after, task
|
|
30
28
|
|
|
31
|
-
after = find_hook(task, :after)
|
|
32
|
-
execute_task(after) if after
|
|
33
|
-
|
|
34
29
|
return result
|
|
35
30
|
end
|
|
36
31
|
|
|
@@ -95,7 +90,7 @@ module Capistrano
|
|
|
95
90
|
# Usage:
|
|
96
91
|
#
|
|
97
92
|
# on :before, "some:hook", "another:hook", :only => "deploy:update"
|
|
98
|
-
# on :after, "some:hook", :except => "deploy:
|
|
93
|
+
# on :after, "some:hook", :except => "deploy:create_symlink"
|
|
99
94
|
# on :before, "global:hook"
|
|
100
95
|
# on :after, :only => :deploy do
|
|
101
96
|
# puts "after deploy here"
|
|
@@ -111,10 +106,28 @@ module Capistrano
|
|
|
111
106
|
elsif block
|
|
112
107
|
callbacks[event] << ProcCallback.new(block, options)
|
|
113
108
|
else
|
|
114
|
-
args
|
|
115
|
-
|
|
116
|
-
|
|
109
|
+
args = filter_deprecated_tasks(args)
|
|
110
|
+
options[:only] = filter_deprecated_tasks(options[:only])
|
|
111
|
+
options[:except] = filter_deprecated_tasks(options[:except])
|
|
112
|
+
|
|
113
|
+
callbacks[event].concat(args.map { |name| TaskCallback.new(self, name, options) })
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Filters the given task name or names and attempts to replace deprecated tasks with their equivalents.
|
|
118
|
+
def filter_deprecated_tasks(names)
|
|
119
|
+
deprecation_msg = "[Deprecation Warning] This API has changed, please hook `deploy:create_symlink` instead of" \
|
|
120
|
+
" `deploy:symlink`."
|
|
121
|
+
|
|
122
|
+
if names == "deploy:symlink"
|
|
123
|
+
warn deprecation_msg
|
|
124
|
+
names = "deploy:create_symlink"
|
|
125
|
+
elsif names.is_a?(Array) && names.include?("deploy:symlink")
|
|
126
|
+
warn deprecation_msg
|
|
127
|
+
names = names.map { |name| name == "deploy:symlink" ? "deploy:create_symlink" : name }
|
|
117
128
|
end
|
|
129
|
+
|
|
130
|
+
names
|
|
118
131
|
end
|
|
119
132
|
|
|
120
133
|
# Trigger the named event for the named task. All associated callbacks
|
|
@@ -129,20 +142,6 @@ module Capistrano
|
|
|
129
142
|
end
|
|
130
143
|
end
|
|
131
144
|
|
|
132
|
-
private
|
|
133
|
-
|
|
134
|
-
# Looks for before_foo or after_foo tasks. This method of extending tasks
|
|
135
|
-
# is now discouraged (though not formally deprecated). You should use the
|
|
136
|
-
# before and after methods to declare hooks for such callbacks.
|
|
137
|
-
def find_hook(task, hook)
|
|
138
|
-
if task == task.namespace.default_task
|
|
139
|
-
result = task.namespace.search_task("#{hook}_#{task.namespace.name}")
|
|
140
|
-
return result if result
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
task.namespace.search_task("#{hook}_#{task.name}")
|
|
144
|
-
end
|
|
145
|
-
|
|
146
145
|
end
|
|
147
146
|
end
|
|
148
|
-
end
|
|
147
|
+
end
|