summaryrefslogtreecommitdiff
path: root/lib/rake/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rake/contrib')
-rw-r--r--lib/rake/contrib/compositepublisher.rb1
-rw-r--r--lib/rake/contrib/ftptools.rb6
-rw-r--r--lib/rake/contrib/publisher.rb6
-rw-r--r--lib/rake/contrib/sshpublisher.rb5
-rw-r--r--lib/rake/contrib/sys.rb191
5 files changed, 201 insertions, 8 deletions
diff --git a/lib/rake/contrib/compositepublisher.rb b/lib/rake/contrib/compositepublisher.rb
index 31ef080dd7..69952a0808 100644
--- a/lib/rake/contrib/compositepublisher.rb
+++ b/lib/rake/contrib/compositepublisher.rb
@@ -18,3 +18,4 @@ module Rake
end
end
+
diff --git a/lib/rake/contrib/ftptools.rb b/lib/rake/contrib/ftptools.rb
index 12e4ff25de..78420c7412 100644
--- a/lib/rake/contrib/ftptools.rb
+++ b/lib/rake/contrib/ftptools.rb
@@ -99,7 +99,7 @@ module Rake # :nodoc:
end
end
- # Create an FTP uploader targetting the directory +path+ on +host+
+ # Create an FTP uploader targeting the directory +path+ on +host+
# using the given account and password. +path+ will be the root
# path of the uploader.
def initialize(path, host, account, password)
@@ -118,7 +118,7 @@ module Rake # :nodoc:
current_dir = File.join(route)
if @created[current_dir].nil?
@created[current_dir] = true
- puts "Creating Directory #{current_dir}" if @verbose
+ $stderr.puts "Creating Directory #{current_dir}" if @verbose
@ftp.mkdir(current_dir) rescue nil
end
end
@@ -141,7 +141,7 @@ module Rake # :nodoc:
# Upload a single file to the uploader's root path.
def upload(file)
- puts "Uploading #{file}" if @verbose
+ $stderr.puts "Uploading #{file}" if @verbose
dir = File.dirname(file)
makedirs(dir)
@ftp.putbinaryfile(file, file) unless File.directory?(file)
diff --git a/lib/rake/contrib/publisher.rb b/lib/rake/contrib/publisher.rb
index 7f69d3a654..baa9a3607d 100644
--- a/lib/rake/contrib/publisher.rb
+++ b/lib/rake/contrib/publisher.rb
@@ -1,10 +1,6 @@
-# Copyright 2003, 2004, 2005, 2006, 2007, 2008 by Jim Weirich (jim@weirichhouse.org)
+# Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com)
# All rights reserved.
-# Permission is granted for use, copying, modification, distribution,
-# and distribution of modified versions of this work as long as the
-# above copyright notice is included.
-
# Configuration information about an upload host system.
# * name :: Name of host system.
# * webdir :: Base directory for the web information for the
diff --git a/lib/rake/contrib/sshpublisher.rb b/lib/rake/contrib/sshpublisher.rb
index e679716c7b..bd6adc127e 100644
--- a/lib/rake/contrib/sshpublisher.rb
+++ b/lib/rake/contrib/sshpublisher.rb
@@ -1,3 +1,4 @@
+require 'rake/dsl_definition'
require 'rake/contrib/compositepublisher'
module Rake
@@ -5,6 +6,8 @@ module Rake
# Publish an entire directory to an existing remote directory using
# SSH.
class SshDirPublisher
+ include Rake::DSL
+
def initialize(host, remote_dir, local_dir)
@host = host
@remote_dir = remote_dir
@@ -27,6 +30,8 @@ module Rake
# Publish a list of files to an existing remote directory.
class SshFilePublisher
+ include Rake::DSL
+
# Create a publisher using the give host information.
def initialize(host, remote_dir, local_dir, *files)
@host = host
diff --git a/lib/rake/contrib/sys.rb b/lib/rake/contrib/sys.rb
new file mode 100644
index 0000000000..41963f1fef
--- /dev/null
+++ b/lib/rake/contrib/sys.rb
@@ -0,0 +1,191 @@
+warn 'Sys has been deprecated in favor of FileUtils'
+
+#--
+# Copyright 2003-2010 by Jim Weirich (jim.weirich@gmail.com)
+# All rights reserved.
+#++
+#
+begin
+ require 'ftools'
+rescue LoadError
+end
+require 'rbconfig'
+
+######################################################################
+# Sys provides a number of file manipulation tools for the convenience
+# of writing Rakefiles. All commands in this module will announce
+# their activity on standard output if the $verbose flag is set
+# ($verbose = true is the default). You can control this by globally
+# setting $verbose or by using the +verbose+ and +quiet+ methods.
+#
+# Sys has been deprecated in favor of the FileUtils module available
+# in Ruby 1.8.
+#
+module Sys
+ RUBY = RbConfig::CONFIG['ruby_install_name']
+
+ # Install all the files matching +wildcard+ into the +dest_dir+
+ # directory. The permission mode is set to +mode+.
+ def install(wildcard, dest_dir, mode)
+ Dir[wildcard].each do |fn|
+ File.install(fn, dest_dir, mode, $verbose)
+ end
+ end
+
+ # Run the system command +cmd+.
+ def run(cmd)
+ log cmd
+ system(cmd) or fail "Command Failed: [#{cmd}]"
+ end
+
+ # Run a Ruby interpreter with the given arguments.
+ def ruby(*args)
+ run "#{RUBY} #{args.join(' ')}"
+ end
+
+ # Copy a single file from +file_name+ to +dest_file+.
+ def copy(file_name, dest_file)
+ log "Copying file #{file_name} to #{dest_file}"
+ File.copy(file_name, dest_file)
+ end
+
+ # Copy all files matching +wildcard+ into the directory +dest_dir+.
+ def copy_files(wildcard, dest_dir)
+ for_matching_files(wildcard, dest_dir) { |from, to| copy(from, to) }
+ end
+
+ # Link +file_name+ to +dest_file+.
+ def link(file_name, dest_file)
+ log "Linking file #{file_name} to #{dest_file}"
+ File.link(file_name, dest_file)
+ end
+
+ # Link all files matching +wildcard+ into the directory +dest_dir+.
+ def link_files(wildcard, dest_dir)
+ for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
+ end
+
+ # Symlink +file_name+ to +dest_file+.
+ def symlink(file_name, dest_file)
+ log "Symlinking file #{file_name} to #{dest_file}"
+ File.symlink(file_name, dest_file)
+ end
+
+ # Symlink all files matching +wildcard+ into the directory +dest_dir+.
+ def symlink_files(wildcard, dest_dir)
+ for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
+ end
+
+ # Remove all files matching +wildcard+. If a matching file is a
+ # directory, it must be empty to be removed. used +delete_all+ to
+ # recursively delete directories.
+ def delete(*wildcards)
+ wildcards.each do |wildcard|
+ Dir[wildcard].each do |fn|
+ if File.directory?(fn)
+ log "Deleting directory #{fn}"
+ Dir.delete(fn)
+ else
+ log "Deleting file #{fn}"
+ File.delete(fn)
+ end
+ end
+ end
+ end
+
+ # Recursively delete all files and directories matching +wildcard+.
+ def delete_all(*wildcards)
+ wildcards.each do |wildcard|
+ Dir[wildcard].each do |fn|
+ next if ! File.exist?(fn)
+ if File.directory?(fn)
+ Dir["#{fn}/*"].each do |subfn|
+ next if subfn=='.' || subfn=='..'
+ delete_all(subfn)
+ end
+ log "Deleting directory #{fn}"
+ Dir.delete(fn)
+ else
+ log "Deleting file #{fn}"
+ File.delete(fn)
+ end
+ end
+ end
+ end
+
+ # Make the directories given in +dirs+.
+ def makedirs(*dirs)
+ dirs.each do |fn|
+ log "Making directory #{fn}"
+ File.makedirs(fn)
+ end
+ end
+
+ # Make +dir+ the current working directory for the duration of
+ # executing the given block.
+ def indir(dir)
+ olddir = Dir.pwd
+ Dir.chdir(dir)
+ yield
+ ensure
+ Dir.chdir(olddir)
+ end
+
+ # Split a file path into individual directory names.
+ #
+ # For example:
+ # split_all("a/b/c") => ['a', 'b', 'c']
+ def split_all(path)
+ head, tail = File.split(path)
+ return [tail] if head == '.' || tail == '/'
+ return [head, tail] if head == '/'
+ return split_all(head) + [tail]
+ end
+
+ # Write a message to standard error if $verbose is enabled.
+ def log(msg)
+ print " " if $trace && $verbose
+ $stderr.puts msg if $verbose
+ end
+
+ # Perform a block with $verbose disabled.
+ def quiet(&block)
+ with_verbose(false, &block)
+ end
+
+ # Perform a block with $verbose enabled.
+ def verbose(&block)
+ with_verbose(true, &block)
+ end
+
+ # Perform a block with each file matching a set of wildcards.
+ def for_files(*wildcards)
+ wildcards.each do |wildcard|
+ Dir[wildcard].each do |fn|
+ yield(fn)
+ end
+ end
+ end
+
+ extend(self)
+
+ private # ----------------------------------------------------------
+
+ def for_matching_files(wildcard, dest_dir)
+ Dir[wildcard].each do |fn|
+ dest_file = File.join(dest_dir, fn)
+ parent = File.dirname(dest_file)
+ makedirs(parent) if ! File.directory?(parent)
+ yield(fn, dest_file)
+ end
+ end
+
+ def with_verbose(v)
+ oldverbose = $verbose
+ $verbose = v
+ yield
+ ensure
+ $verbose = oldverbose
+ end
+
+end