1require 'rake/dsl_definition'
2require 'rake/contrib/compositepublisher'
3
4module Rake
5
6  # Publish an entire directory to an existing remote directory using
7  # SSH.
8  class SshDirPublisher
9    include Rake::DSL
10
11    def initialize(host, remote_dir, local_dir)
12      @host = host
13      @remote_dir = remote_dir
14      @local_dir = local_dir
15    end
16
17    def upload
18      sh %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}}
19    end
20  end
21
22  # Publish an entire directory to a fresh remote directory using SSH.
23  class SshFreshDirPublisher < SshDirPublisher
24    def upload
25      sh %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil
26      sh %{ssh #{@host} mkdir #{@remote_dir}}
27      super
28    end
29  end
30
31  # Publish a list of files to an existing remote directory.
32  class SshFilePublisher
33    include Rake::DSL
34
35    # Create a publisher using the give host information.
36    def initialize(host, remote_dir, local_dir, *files)
37      @host = host
38      @remote_dir = remote_dir
39      @local_dir = local_dir
40      @files = files
41    end
42
43    # Upload the local directory to the remote directory.
44    def upload
45      @files.each do |fn|
46        sh %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}}
47      end
48    end
49  end
50end
51