capistrano 1.4.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG +140 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README +22 -14
  4. data/bin/cap +1 -8
  5. data/bin/capify +77 -0
  6. data/examples/sample.rb +10 -109
  7. data/lib/capistrano.rb +1 -0
  8. data/lib/capistrano/callback.rb +41 -0
  9. data/lib/capistrano/cli.rb +17 -317
  10. data/lib/capistrano/cli/execute.rb +82 -0
  11. data/lib/capistrano/cli/help.rb +102 -0
  12. data/lib/capistrano/cli/help.txt +53 -0
  13. data/lib/capistrano/cli/options.rb +183 -0
  14. data/lib/capistrano/cli/ui.rb +28 -0
  15. data/lib/capistrano/command.rb +62 -29
  16. data/lib/capistrano/configuration.rb +25 -226
  17. data/lib/capistrano/configuration/actions/file_transfer.rb +35 -0
  18. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  19. data/lib/capistrano/configuration/actions/invocation.rb +127 -0
  20. data/lib/capistrano/configuration/callbacks.rb +148 -0
  21. data/lib/capistrano/configuration/connections.rb +159 -0
  22. data/lib/capistrano/configuration/execution.rb +126 -0
  23. data/lib/capistrano/configuration/loading.rb +112 -0
  24. data/lib/capistrano/configuration/namespaces.rb +190 -0
  25. data/lib/capistrano/configuration/roles.rb +51 -0
  26. data/lib/capistrano/configuration/servers.rb +75 -0
  27. data/lib/capistrano/configuration/variables.rb +127 -0
  28. data/lib/capistrano/errors.rb +15 -0
  29. data/lib/capistrano/extensions.rb +27 -8
  30. data/lib/capistrano/gateway.rb +54 -29
  31. data/lib/capistrano/logger.rb +11 -11
  32. data/lib/capistrano/recipes/compat.rb +32 -0
  33. data/lib/capistrano/recipes/deploy.rb +483 -0
  34. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  35. data/lib/capistrano/recipes/deploy/local_dependency.rb +46 -0
  36. data/lib/capistrano/recipes/deploy/remote_dependency.rb +65 -0
  37. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  38. data/lib/capistrano/recipes/deploy/scm/base.rb +180 -0
  39. data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
  40. data/lib/capistrano/recipes/deploy/scm/cvs.rb +151 -0
  41. data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
  42. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +129 -0
  43. data/lib/capistrano/recipes/deploy/scm/perforce.rb +126 -0
  44. data/lib/capistrano/recipes/deploy/scm/subversion.rb +103 -0
  45. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  46. data/lib/capistrano/recipes/deploy/strategy/base.rb +64 -0
  47. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  48. data/lib/capistrano/recipes/deploy/strategy/copy.rb +143 -0
  49. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  50. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  51. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +47 -0
  52. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
  53. data/lib/capistrano/recipes/standard.rb +26 -276
  54. data/lib/capistrano/recipes/templates/maintenance.rhtml +1 -1
  55. data/lib/capistrano/recipes/upgrade.rb +33 -0
  56. data/lib/capistrano/server_definition.rb +51 -0
  57. data/lib/capistrano/shell.rb +125 -81
  58. data/lib/capistrano/ssh.rb +80 -36
  59. data/lib/capistrano/task_definition.rb +69 -0
  60. data/lib/capistrano/upload.rb +146 -0
  61. data/lib/capistrano/version.rb +13 -17
  62. data/test/cli/execute_test.rb +132 -0
  63. data/test/cli/help_test.rb +139 -0
  64. data/test/cli/options_test.rb +226 -0
  65. data/test/cli/ui_test.rb +28 -0
  66. data/test/cli_test.rb +17 -0
  67. data/test/command_test.rb +284 -25
  68. data/test/configuration/actions/file_transfer_test.rb +40 -0
  69. data/test/configuration/actions/inspect_test.rb +62 -0
  70. data/test/configuration/actions/invocation_test.rb +195 -0
  71. data/test/configuration/callbacks_test.rb +206 -0
  72. data/test/configuration/connections_test.rb +288 -0
  73. data/test/configuration/execution_test.rb +159 -0
  74. data/test/configuration/loading_test.rb +119 -0
  75. data/test/configuration/namespace_dsl_test.rb +283 -0
  76. data/test/configuration/roles_test.rb +47 -0
  77. data/test/configuration/servers_test.rb +90 -0
  78. data/test/configuration/variables_test.rb +180 -0
  79. data/test/configuration_test.rb +60 -212
  80. data/test/deploy/scm/base_test.rb +55 -0
  81. data/test/deploy/strategy/copy_test.rb +146 -0
  82. data/test/extensions_test.rb +69 -0
  83. data/test/fixtures/cli_integration.rb +5 -0
  84. data/test/fixtures/custom.rb +2 -2
  85. data/test/gateway_test.rb +167 -0
  86. data/test/logger_test.rb +123 -0
  87. data/test/server_definition_test.rb +108 -0
  88. data/test/shell_test.rb +64 -0
  89. data/test/ssh_test.rb +67 -154
  90. data/test/task_definition_test.rb +101 -0
  91. data/test/upload_test.rb +131 -0
  92. data/test/utils.rb +31 -39
  93. data/test/version_test.rb +24 -0
  94. metadata +145 -98
  95. data/THANKS +0 -4
  96. data/lib/capistrano/actor.rb +0 -567
  97. data/lib/capistrano/generators/rails/deployment/deployment_generator.rb +0 -25
  98. data/lib/capistrano/generators/rails/deployment/templates/capistrano.rake +0 -49
  99. data/lib/capistrano/generators/rails/deployment/templates/deploy.rb +0 -122
  100. data/lib/capistrano/generators/rails/loader.rb +0 -20
  101. data/lib/capistrano/scm/base.rb +0 -61
  102. data/lib/capistrano/scm/baz.rb +0 -118
  103. data/lib/capistrano/scm/bzr.rb +0 -70
  104. data/lib/capistrano/scm/cvs.rb +0 -129
  105. data/lib/capistrano/scm/darcs.rb +0 -27
  106. data/lib/capistrano/scm/mercurial.rb +0 -83
  107. data/lib/capistrano/scm/perforce.rb +0 -139
  108. data/lib/capistrano/scm/subversion.rb +0 -128
  109. data/lib/capistrano/transfer.rb +0 -97
  110. data/lib/capistrano/utils.rb +0 -26
  111. data/test/actor_test.rb +0 -402
  112. data/test/scm/cvs_test.rb +0 -196
  113. data/test/scm/subversion_test.rb +0 -145
@@ -0,0 +1,44 @@
1
+ require 'capistrano/recipes/deploy/local_dependency'
2
+ require 'capistrano/recipes/deploy/remote_dependency'
3
+
4
+ module Capistrano
5
+ module Deploy
6
+ class Dependencies
7
+ include Enumerable
8
+
9
+ attr_reader :configuration
10
+
11
+ def initialize(configuration)
12
+ @configuration = configuration
13
+ @dependencies = []
14
+ yield self if block_given?
15
+ end
16
+
17
+ def check
18
+ yield self
19
+ self
20
+ end
21
+
22
+ def remote
23
+ dep = RemoteDependency.new(configuration)
24
+ @dependencies << dep
25
+ dep
26
+ end
27
+
28
+ def local
29
+ dep = LocalDependency.new(configuration)
30
+ @dependencies << dep
31
+ dep
32
+ end
33
+
34
+ def each
35
+ @dependencies.each { |d| yield d }
36
+ self
37
+ end
38
+
39
+ def pass?
40
+ all? { |d| d.pass? }
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,46 @@
1
+ module Capistrano
2
+ module Deploy
3
+ class LocalDependency
4
+ attr_reader :configuration
5
+ attr_reader :message
6
+
7
+ def initialize(configuration)
8
+ @configuration = configuration
9
+ @success = true
10
+ end
11
+
12
+ def command(command)
13
+ @message ||= "`#{command}' could not be found in the path on the local host"
14
+ @success = find_in_path(command)
15
+ self
16
+ end
17
+
18
+ def or(message)
19
+ @message = message
20
+ self
21
+ end
22
+
23
+ def pass?
24
+ @success
25
+ end
26
+
27
+ private
28
+
29
+ # Searches the path, looking for the given utility. If an executable
30
+ # file is found that matches the parameter, this returns true.
31
+ def find_in_path(utility)
32
+ path = (ENV['PATH'] || "").split(File::PATH_SEPARATOR)
33
+ suffixes = RUBY_PLATFORM =~ /mswin/ ? %w(.bat .exe .com .cmd) : [""]
34
+
35
+ path.each do |dir|
36
+ suffixes.each do |sfx|
37
+ file = File.join(dir, utility + sfx)
38
+ return true if File.executable?(file)
39
+ end
40
+ end
41
+
42
+ false
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,65 @@
1
+ module Capistrano
2
+ module Deploy
3
+ class RemoteDependency
4
+ attr_reader :configuration
5
+ attr_reader :hosts
6
+
7
+ def initialize(configuration)
8
+ @configuration = configuration
9
+ @success = true
10
+ end
11
+
12
+ def directory(path, options={})
13
+ @message ||= "`#{path}' is not a directory"
14
+ try("test -d #{path}", options)
15
+ self
16
+ end
17
+
18
+ def writable(path, options={})
19
+ @message ||= "`#{path}' is not writable"
20
+ try("test -w #{path}", options)
21
+ self
22
+ end
23
+
24
+ def command(command, options={})
25
+ @message ||= "`#{command}' could not be found in the path"
26
+ try("which #{command}", options)
27
+ self
28
+ end
29
+
30
+ def gem(name, version, options={})
31
+ @message ||= "gem `#{name}' #{version} could not be found"
32
+ gem_cmd = configuration.fetch(:gem_command, "gem")
33
+ try("#{gem_cmd} specification --version '#{version}' #{name} 2>&1 | awk 'BEGIN { s = 0 } /^name:/ { s = 1; exit }; END { if(s == 0) exit 1 }'", options)
34
+ self
35
+ end
36
+
37
+ def or(message)
38
+ @message = message
39
+ self
40
+ end
41
+
42
+ def pass?
43
+ @success
44
+ end
45
+
46
+ def message
47
+ s = @message.dup
48
+ s << " (#{@hosts})" if @hosts && @hosts.any?
49
+ s
50
+ end
51
+
52
+ private
53
+
54
+ def try(command, options)
55
+ return unless @success # short-circuit evaluation
56
+ configuration.run(command, options) do |ch,stream,out|
57
+ warn "#{ch[:server]}: #{out}" if stream == :err
58
+ end
59
+ rescue Capistrano::CommandError => e
60
+ @success = false
61
+ @hosts = e.hosts.join(', ')
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,19 @@
1
+ module Capistrano
2
+ module Deploy
3
+ module SCM
4
+ def self.new(scm, config={})
5
+ scm_file = "capistrano/recipes/deploy/scm/#{scm}"
6
+ require(scm_file)
7
+
8
+ scm_const = scm.to_s.capitalize.gsub(/_(.)/) { $1.upcase }
9
+ if const_defined?(scm_const)
10
+ const_get(scm_const).new(config)
11
+ else
12
+ raise Capistrano::Error, "could not find `#{name}::#{scm_const}' in `#{scm_file}'"
13
+ end
14
+ rescue LoadError
15
+ raise Capistrano::Error, "could not find any SCM named `#{scm}'"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,180 @@
1
+ module Capistrano
2
+ module Deploy
3
+ module SCM
4
+
5
+ # The ancestor class for all Capistrano SCM implementations. It provides
6
+ # minimal infrastructure for subclasses to build upon and override.
7
+ #
8
+ # Note that subclasses that implement this abstract class only return
9
+ # the commands that need to be executed--they do not execute the commands
10
+ # themselves. In this way, the deployment method may execute the commands
11
+ # either locally or remotely, as necessary.
12
+ class Base
13
+ class << self
14
+ # If no parameters are given, it returns the current configured
15
+ # name of the command-line utility of this SCM. If a parameter is
16
+ # given, the defeault command is set to that value.
17
+ def default_command(value=nil)
18
+ if value
19
+ @default_command = value
20
+ else
21
+ @default_command
22
+ end
23
+ end
24
+ end
25
+
26
+ # Wraps an SCM instance and forces all messages sent to it to be
27
+ # relayed to the underlying SCM instance, in "local" mode. See
28
+ # Base#local.
29
+ class LocalProxy
30
+ def initialize(scm)
31
+ @scm = scm
32
+ end
33
+
34
+ def method_missing(sym, *args, &block)
35
+ @scm.local { return @scm.send(sym, *args, &block) }
36
+ end
37
+ end
38
+
39
+ # The options available for this SCM instance to reference. Should be
40
+ # treated like a hash.
41
+ attr_reader :configuration
42
+
43
+ # Creates a new SCM instance with the given configuration options.
44
+ def initialize(configuration={})
45
+ @configuration = configuration
46
+ end
47
+
48
+ # Returns a proxy that wraps the SCM instance and forces it to operate
49
+ # in "local" mode, which changes how variables are looked up in the
50
+ # configuration. Normally, if the value of a variable "foo" is needed,
51
+ # it is queried for in the configuration as "foo". However, in "local"
52
+ # mode, first "local_foo" would be looked for, and only if it is not
53
+ # found would "foo" be used. This allows for both (e.g.) "scm_command"
54
+ # and "local_scm_command" to be set, if the two differ.
55
+ #
56
+ # Alternatively, it may be called with a block, and for the duration of
57
+ # the block, all requests on this configuration object will be
58
+ # considered local.
59
+ def local
60
+ if block_given?
61
+ begin
62
+ saved, @local_mode = @local_mode, true
63
+ yield
64
+ ensure
65
+ @local_mode = saved
66
+ end
67
+ else
68
+ LocalProxy.new(self)
69
+ end
70
+ end
71
+
72
+ # Returns true if running in "local" mode. See #local.
73
+ def local?
74
+ @local_mode
75
+ end
76
+
77
+ # Returns the string used to identify the latest revision in the
78
+ # repository. This will be passed as the "revision" parameter of
79
+ # the methods below.
80
+ def head
81
+ raise NotImplementedError, "`head' is not implemented by #{self.class.name}"
82
+ end
83
+
84
+ # Checkout a copy of the repository, at the given +revision+, to the
85
+ # given +destination+. The checkout is suitable for doing development
86
+ # work in, e.g. allowing subsequent commits and updates.
87
+ def checkout(revision, destination)
88
+ raise NotImplementedError, "`checkout' is not implemented by #{self.class.name}"
89
+ end
90
+
91
+ # Resynchronize the working copy in +destination+ to the specified
92
+ # +revision+.
93
+ def sync(revision, destination)
94
+ raise NotImplementedError, "`sync' is not implemented by #{self.class.name}"
95
+ end
96
+
97
+ # Compute the difference between the two revisions, +from+ and +to+.
98
+ def diff(from, to=nil)
99
+ raise NotImplementedError, "`diff' is not implemented by #{self.class.name}"
100
+ end
101
+
102
+ # Return a log of all changes between the two specified revisions,
103
+ # +from+ and +to+, inclusive.
104
+ def log(from, to=nil)
105
+ raise NotImplementedError, "`log' is not implemented by #{self.class.name}"
106
+ end
107
+
108
+ # If the given revision represents a "real" revision, this should
109
+ # simply return the revision value. If it represends a pseudo-revision
110
+ # (like Subversions "HEAD" identifier), it should yield a string
111
+ # containing the commands that, when executed will return a string
112
+ # that this method can then extract the real revision from.
113
+ def query_revision(revision)
114
+ raise NotImplementedError, "`query_revision' is not implemented by #{self.class.name}"
115
+ end
116
+
117
+ # Should analyze the given text and determine whether or not a
118
+ # response is expected, and if so, return the appropriate response.
119
+ # If no response is expected, return nil. The +state+ parameter is a
120
+ # hash that may be used to preserve state between calls. This method
121
+ # is used to define how Capistrano should respond to common prompts
122
+ # and messages from the SCM, like password prompts and such. By
123
+ # default, the output is simply displayed.
124
+ def handle_data(state, stream, text)
125
+ logger.info "[#{stream}] #{text}"
126
+ nil
127
+ end
128
+
129
+ # Returns the name of the command-line utility for this SCM. It first
130
+ # looks at the :scm_command variable, and if it does not exist, it
131
+ # then falls back to whatever was defined by +default_command+.
132
+ #
133
+ # If scm_command is set to :default, the default_command will be
134
+ # returned.
135
+ def command
136
+ command = variable(:scm_command)
137
+ command = nil if command == :default
138
+ command || default_command
139
+ end
140
+
141
+ private
142
+
143
+ # A helper for accessing variable values, which takes into
144
+ # consideration the current mode ("normal" vs. "local").
145
+ def variable(name)
146
+ if local? && configuration.exists?("local_#{name}".to_sym)
147
+ return configuration["local_#{name}".to_sym]
148
+ else
149
+ configuration[name]
150
+ end
151
+ end
152
+
153
+ # A reference to a Logger instance that the SCM can use to log
154
+ # activity.
155
+ def logger
156
+ @logger ||= variable(:logger) || Capistrano::Logger.new(:output => STDOUT)
157
+ end
158
+
159
+ # A helper for accessing the default command name for this SCM. It
160
+ # simply delegates to the class' +default_command+ method.
161
+ def default_command
162
+ self.class.default_command
163
+ end
164
+
165
+ # A helper method that can be used to define SCM commands naturally.
166
+ # It returns a single string with all arguments joined by spaces,
167
+ # with the scm command prefixed onto it.
168
+ def scm(*args)
169
+ [command, *args].compact.join(" ")
170
+ end
171
+
172
+ # A convenience method for accessing the declared repository value.
173
+ def repository
174
+ variable(:repository)
175
+ end
176
+ end
177
+
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,86 @@
1
+ require 'capistrano/recipes/deploy/scm/base'
2
+
3
+ module Capistrano
4
+ module Deploy
5
+ module SCM
6
+
7
+ # Implements the Capistrano SCM interface for the Bazaar-NG revision
8
+ # control system (http://bazaar-vcs.org/).
9
+ class Bzr < Base
10
+ # Sets the default command name for this SCM. Users may override this
11
+ # by setting the :scm_command variable.
12
+ default_command "bzr"
13
+
14
+ # Bazaar-NG doesn't support any pseudo-id's, so we'll use the convention
15
+ # in this adapter that the :head symbol means the most recently
16
+ # committed revision.
17
+ def head
18
+ :head
19
+ end
20
+
21
+ # Returns the command that will check out the given revision to the
22
+ # given destination.
23
+ def checkout(revision, destination)
24
+ scm :branch, revswitch(revision), repository, destination
25
+ end
26
+
27
+ # The bzr 'update' command does not support updating to a specific
28
+ # revision, so this just does update, followed by revert (unless
29
+ # updating to head).
30
+ def sync(revision, destination)
31
+ commands = [scm(:update, destination)]
32
+ commands << [scm(:revert, revswitch(revision), destination)] if revision != head
33
+ commands.join(" && ")
34
+ end
35
+
36
+ # The bzr 'export' command would work fine, except it doesn't let you
37
+ # specify the repository itself, so it only works if there is a working
38
+ # tree handy, locally. Since this needs to work even on a remote host
39
+ # where there is no working tree, we'll just do a checkout, followed
40
+ # by a deletion of the ".bzr" metadata directory.
41
+ def export(revision, destination)
42
+ [checkout(revision, destination) && "rm -rf #{destination}/.bzr"].join(" && ")
43
+ end
44
+
45
+ # The bzr "diff" command doesn't accept a repository argument, so it
46
+ # must be run from within a working tree.
47
+ def diff(from, to=nil)
48
+ switch = "-r#{from}"
49
+ switch << "..#{to}" if to
50
+
51
+ scm :diff, switch
52
+ end
53
+
54
+ # Returns a log of changes between the two revisions (inclusive).
55
+ def log(from, to=nil)
56
+ scm :log, "--short", "-r#{from}..#{to}", repository
57
+ end
58
+
59
+ # Attempts to translate the given revision identifier to a "real"
60
+ # revision. If the identifier is :head, the "bzr revno" command will
61
+ # be yielded, and the block must execute the command and return the
62
+ # output. The revision will be extracted from the output and returned.
63
+ # If the 'revision' argument, on the other hand, is not :head, it is
64
+ # simply returned.
65
+ def query_revision(revision)
66
+ if revision == head
67
+ yield(scm(:revno, repository)).chomp
68
+ else
69
+ revision
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def revswitch(revision)
76
+ if revision == :head
77
+ nil
78
+ else
79
+ "-r #{revision}"
80
+ end
81
+ end
82
+ end
83
+
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,151 @@
1
+ require 'capistrano/recipes/deploy/scm/base'
2
+
3
+ module Capistrano
4
+ module Deploy
5
+ module SCM
6
+
7
+ # Implements the Capistrano SCM interface for the CVS revision
8
+ # control system.
9
+ class Cvs < Base
10
+ # Sets the default command name for this SCM. Users may override this
11
+ # by setting the :scm_command variable.
12
+ default_command "cvs"
13
+
14
+ # CVS understands 'HEAD' to refer to the latest revision in the
15
+ # repository.
16
+ def head
17
+ "HEAD"
18
+ end
19
+
20
+ # Returns the command that will check out the given revision to the
21
+ # given destination.
22
+ def checkout(revision, destination)
23
+ [ prep_destination(destination),
24
+ scm(verbose, cvs_root, :checkout, cvs_revision(revision), cvs_destination(destination), variable(:scm_module))
25
+ ].join(' && ')
26
+ end
27
+
28
+ # Returns the command that will do an "cvs update" to the given
29
+ # revision, for the working copy at the given destination.
30
+ def sync(revision, destination)
31
+ [ prep_destination(destination),
32
+ scm(verbose, cvs_root, :update, cvs_revision(revision), cvs_destination(destination))
33
+ ].join(' && ')
34
+ end
35
+
36
+ # Returns the command that will do an "cvs export" of the given revision
37
+ # to the given destination.
38
+ def export(revision, destination)
39
+ [ prep_destination(destination),
40
+ scm(verbose, cvs_root, :export, cvs_revision(revision), cvs_destination(destination), variable(:scm_module))
41
+ ].join(' && ')
42
+ end
43
+
44
+ # Returns the command that will do an "cvs diff" for the two revisions.
45
+ def diff(from, to=nil)
46
+ rev_type = revision_type(from)
47
+ if rev_type == :date
48
+ range_args = "-D '#{from}' -D '#{to || 'now'}'"
49
+ else
50
+ range_args = "-r '#{from}' -r '#{to || head}'"
51
+ end
52
+ scm cvs_root, :diff, range_args
53
+ end
54
+
55
+ # Returns an "cvs log" command for the two revisions.
56
+ def log(from, to=nil)
57
+ rev_type = revision_type(from)
58
+ if rev_type == :date
59
+ range_arg = "-d '#{from}<#{to || 'now'}'"
60
+ else
61
+ range_arg = "-r '#{from}:#{to || head}'"
62
+ end
63
+ scm cvs_root, :log, range_arg
64
+ end
65
+
66
+ # Unfortunately, cvs doesn't support the concept of a revision number like
67
+ # subversion and other SCM's do. For now, we'll rely on getting the timestamp
68
+ # of the latest checkin under the revision that's passed to us.
69
+ def query_revision(revision)
70
+ return revision if revision_type(revision) == :date
71
+ revision = yield(scm(cvs_root, :log, "-r#{revision}")).
72
+ grep(/^date:/).
73
+ map { |line| line[/^date: (.*?);/, 1] }.
74
+ sort.last
75
+ return revision
76
+ end
77
+
78
+ # Determines what the response should be for a particular bit of text
79
+ # from the SCM. Password prompts, connection requests, passphrases,
80
+ # etc. are handled here.
81
+ def handle_data(state, stream, text)
82
+ logger.info "[#{stream}] #{text}"
83
+ case text
84
+ when /\bpassword.*:/i
85
+ # prompting for a password
86
+ "#{variable(:scm_password) || variable(:password)}\n"
87
+ when %r{\(yes/no\)}
88
+ # let's be agreeable...
89
+ "yes\n"
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ # Constructs the CVSROOT command-line option
96
+ def cvs_root
97
+ root = ""
98
+ root << "-d #{repository} " if repository
99
+ root
100
+ end
101
+
102
+ # Constructs the destination dir command-line option
103
+ def cvs_destination(destination)
104
+ dest = ""
105
+ if destination
106
+ dest_parts = destination.split(/\//);
107
+ dest << "-d #{dest_parts.pop}"
108
+ end
109
+ dest
110
+ end
111
+
112
+ # attempts to guess what type of revision we're working with
113
+ def revision_type(rev)
114
+ return :date if rev =~ /^\d{4}\/\d{2}\/\d{2} \d{2}:\d{2}:\d{2}$/ # i.e 2007-05-15 08:13:25
115
+ return :revision if rev =~ /^\d/ # i.e. 1.2.1
116
+ return :tag # i.e. RELEASE_1_2
117
+ end
118
+
119
+ # constructs the appropriate command-line switch for specifying a
120
+ # "revision" in CVS. This could be a tag, branch, revision (i.e. 1.3)
121
+ # or a date (to be used with -d)
122
+ def cvs_revision(rev)
123
+ revision = ""
124
+ revision << case revision_type(rev)
125
+ when :date:
126
+ "-D \"#{rev}\"" if revision_type(rev) == :date
127
+ when :revision:
128
+ "-r #{rev}"
129
+ else
130
+ "-r #{head}"
131
+ end
132
+ return revision
133
+ end
134
+
135
+ # If verbose output is requested, return nil, otherwise return the
136
+ # command-line switch for "quiet" ("-Q").
137
+ def verbose
138
+ variable(:scm_verbose) ? nil : "-Q"
139
+ end
140
+
141
+ def prep_destination(destination)
142
+ dest_parts = destination.split(/\//);
143
+ checkout_dir = dest_parts.pop
144
+ dest = dest_parts.join('/')
145
+ "mkdir -p #{ dest } && cd #{ dest }"
146
+ end
147
+ end
148
+
149
+ end
150
+ end
151
+ end