rake 0.4.8

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rake might be problematic. Click here for more details.

@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # The 'rake/clean' file defines two file lists (CLEAN and CLOBBER) and
4
+ # two rake tasks (:clean and :clobber).
5
+ #
6
+ # [:clean] Clean up the project by deleting scratch files and backup
7
+ # files. Add files to the CLEAN file list to have the :clean
8
+ # target handle them.
9
+ #
10
+ # [:clobber] Clobber all generated and non-source files in a project.
11
+ # The task depends on :clean, so all the clean files will
12
+ # be deleted as well as files in the CLOBBER file list.
13
+ # The intent of this task is to return a project to its
14
+ # pristine, just unpacked state.
15
+
16
+ require 'rake'
17
+
18
+ CLEAN = Rake::FileList["**/*~", "**/*.bak", "**/core"]
19
+ CLEAN.clear_exclude
20
+
21
+ desc "Remove any temporary products."
22
+ task :clean do
23
+ CLEAN.each { |fn| rm_r fn rescue nil }
24
+ end
25
+
26
+ CLOBBER = Rake::FileList.new
27
+
28
+ desc "Remove any generated file."
29
+ task :clobber => [:clean] do
30
+ CLOBBER.each { |fn| rm_r fn rescue nil }
31
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Rake
4
+
5
+ # Manage several publishers as a single entity.
6
+ class CompositePublisher
7
+ def initialize
8
+ @publishers = []
9
+ end
10
+
11
+ # Add a publisher to the composite.
12
+ def add(pub)
13
+ @publishers << pub
14
+ end
15
+
16
+ # Upload all the individual publishers.
17
+ def upload
18
+ @publishers.each { |p| p.upload }
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # = Tools for FTP uploading.
4
+ #
5
+ # This file is still under development and is not released for general
6
+ # use.
7
+
8
+ require 'date'
9
+ require 'parsedate'
10
+ require 'net/ftp'
11
+
12
+ module Rake # :nodoc:
13
+
14
+ ####################################################################
15
+ # <b>Note:</b> <em> Not released for general use.</em>
16
+ class FtpFile
17
+ attr_reader :name, :size, :owner, :group, :time
18
+
19
+ def self.date
20
+ @date_class ||= Date
21
+ end
22
+
23
+ def initialize(path, entry)
24
+ @path = path
25
+ @mode, line, @owner, @group, size, d1, d2, d3, @name = entry.split(' ')
26
+ @size = size.to_i
27
+ @time = determine_time(d1, d2, d3)
28
+ end
29
+
30
+ def path
31
+ File.join(@path, @name)
32
+ end
33
+
34
+ def directory?
35
+ @mode[0] == ?d
36
+ end
37
+
38
+ def mode
39
+ parse_mode(@mode)
40
+ end
41
+
42
+ def symlink?
43
+ @mode[0] == ?l
44
+ end
45
+
46
+ private # --------------------------------------------------------
47
+
48
+ def parse_mode(m)
49
+ result = 0
50
+ (1..9).each do |i|
51
+ result = 2*result + ((m[i]==?-) ? 0 : 1)
52
+ end
53
+ result
54
+ end
55
+
56
+ def determine_time(d1, d2, d3)
57
+ elements = ParseDate.parsedate("#{d1} #{d2} #{d3}")
58
+ if elements[0].nil?
59
+ today = self.class.date.today
60
+ if elements[1] > today.month
61
+ elements[0] = today.year - 1
62
+ else
63
+ elements[0] = today.year
64
+ end
65
+ end
66
+ elements = elements.collect { |el| el.nil? ? 0 : el }
67
+ Time.mktime(*elements[0,7])
68
+ end
69
+ end
70
+
71
+ ####################################################################
72
+ # Manage the uploading of files to an FTP account.
73
+ class FtpUploader
74
+
75
+ # Log uploads to standard output when true.
76
+ attr_accessor :verbose
77
+
78
+ class << FtpUploader
79
+ # Create an uploader and pass it to the given block as +up+.
80
+ # When the block is complete, close the uploader.
81
+ def connect(path, host, account, password)
82
+ up = self.new(path, host, account, password)
83
+ begin
84
+ yield(up)
85
+ ensure
86
+ up.close
87
+ end
88
+ end
89
+ end
90
+
91
+ # Create an FTP uploader targetting the directory +path+ on +host+
92
+ # using the given account and password. +path+ will be the root
93
+ # path of the uploader.
94
+ def initialize(path, host, account, password)
95
+ @created = Hash.new
96
+ @path = path
97
+ @ftp = Net::FTP.new(host, account, password)
98
+ makedirs(@path)
99
+ @ftp.chdir(@path)
100
+ end
101
+
102
+ # Create the directory +path+ in the uploader root path.
103
+ def makedirs(path)
104
+ route = []
105
+ File.split(path).each do |dir|
106
+ route << dir
107
+ current_dir = File.join(route)
108
+ if @created[current_dir].nil?
109
+ @created[current_dir] = true
110
+ puts "Creating Directory #{current_dir}" if @verbose
111
+ @ftp.mkdir(current_dir) rescue nil
112
+ end
113
+ end
114
+ end
115
+
116
+ # Upload all files matching +wildcard+ to the uploader's root
117
+ # path.
118
+ def upload_files(wildcard)
119
+ Dir[wildcard].each do |fn|
120
+ upload(fn)
121
+ end
122
+ end
123
+
124
+ # Close the uploader.
125
+ def close
126
+ @ftp.close
127
+ end
128
+
129
+ private # --------------------------------------------------------
130
+
131
+ # Upload a single file to the uploader's root path.
132
+ def upload(file)
133
+ puts "Uploading #{file}" if @verbose
134
+ dir = File.dirname(file)
135
+ makedirs(dir)
136
+ @ftp.putbinaryfile(file, file) unless File.directory?(file)
137
+ end
138
+ end
139
+ end
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright 2003, 2004 by Jim Weirich (jim@weirichhouse.org)
4
+ # All rights reserved.
5
+
6
+ # Permission is granted for use, copying, modification, distribution,
7
+ # and distribution of modified versions of this work as long as the
8
+ # above copyright notice is included.
9
+
10
+ # Configuration information about an upload host system.
11
+ # * name :: Name of host system.
12
+ # * webdir :: Base directory for the web information for the
13
+ # application. The application name (APP) is appended to
14
+ # this directory before using.
15
+ # * pkgdir :: Directory on the host system where packages can be
16
+ # placed.
17
+ HostInfo = Struct.new(:name, :webdir, :pkgdir)
18
+
19
+ # Manage several publishers as a single entity.
20
+ class CompositePublisher
21
+ def initialize
22
+ @publishers = []
23
+ end
24
+
25
+ # Add a publisher to the composite.
26
+ def add(pub)
27
+ @publishers << pub
28
+ end
29
+
30
+ # Upload all the individual publishers.
31
+ def upload
32
+ @publishers.each { |p| p.upload }
33
+ end
34
+ end
35
+
36
+ # Publish an entire directory to an existing remote directory using
37
+ # SSH.
38
+ class SshDirPublisher
39
+ def initialize(host, remote_dir, local_dir)
40
+ @host = host
41
+ @remote_dir = remote_dir
42
+ @local_dir = local_dir
43
+ end
44
+
45
+ def upload
46
+ run %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}}
47
+ end
48
+ end
49
+
50
+ # Publish an entire directory to a fresh remote directory using SSH.
51
+ class SshFreshDirPublisher < SshDirPublisher
52
+ def upload
53
+ run %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil
54
+ run %{ssh #{@host} mkdir #{@remote_dir}}
55
+ super
56
+ end
57
+ end
58
+
59
+ # Publish a list of files to an existing remote directory.
60
+ class SshFilePublisher
61
+ # Create a publisher using the give host information.
62
+ def initialize(host, remote_dir, local_dir, *files)
63
+ @host = host
64
+ @remote_dir = remote_dir
65
+ @local_dir = local_dir
66
+ @files = files
67
+ end
68
+
69
+ # Upload the local directory to the remote directory.
70
+ def upload
71
+ @files.each do |fn|
72
+ run %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}}
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rake/contrib/sshpublisher'
4
+
5
+ module Rake
6
+
7
+ class RubyForgePublisher < SshDirPublisher
8
+ attr_reader :project, :proj_id, :user
9
+
10
+ def initialize(projname, user)
11
+ super(
12
+ "#{user}@rubyforge.org",
13
+ "/var/www/gforge-projects/#{projname}",
14
+ "html")
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rake/contrib/compositepublisher'
4
+
5
+ module Rake
6
+
7
+ # Publish an entire directory to an existing remote directory using
8
+ # SSH.
9
+ class SshDirPublisher
10
+ def initialize(host, remote_dir, local_dir)
11
+ @host = host
12
+ @remote_dir = remote_dir
13
+ @local_dir = local_dir
14
+ end
15
+
16
+ def upload
17
+ sh %{scp -rq #{@local_dir}/* #{@host}:#{@remote_dir}}
18
+ end
19
+ end
20
+
21
+ # Publish an entire directory to a fresh remote directory using SSH.
22
+ class SshFreshDirPublisher < SshDirPublisher
23
+ def upload
24
+ sh %{ssh #{@host} rm -rf #{@remote_dir}} rescue nil
25
+ sh %{ssh #{@host} mkdir #{@remote_dir}}
26
+ super
27
+ end
28
+ end
29
+
30
+ # Publish a list of files to an existing remote directory.
31
+ class SshFilePublisher
32
+ # Create a publisher using the give host information.
33
+ def initialize(host, remote_dir, local_dir, *files)
34
+ @host = host
35
+ @remote_dir = remote_dir
36
+ @local_dir = local_dir
37
+ @files = files
38
+ end
39
+
40
+ # Upload the local directory to the remote directory.
41
+ def upload
42
+ @files.each do |fn|
43
+ sh %{scp -q #{@local_dir}/#{fn} #{@host}:#{@remote_dir}}
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,207 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #--
4
+ # Copyright (c) 2003, 2004 Jim Weirich
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+ #++
25
+ #
26
+ require 'ftools'
27
+ require 'rbconfig'
28
+
29
+ ######################################################################
30
+ # Sys provides a number of file manipulation tools for the convenience
31
+ # of writing Rakefiles. All commands in this module will announce
32
+ # their activity on standard output if the $verbose flag is set
33
+ # ($verbose = true is the default). You can control this by globally
34
+ # setting $verbose or by using the +verbose+ and +quiet+ methods.
35
+ #
36
+ # Sys has been deprecated in favor of the FileUtils module available
37
+ # in Ruby 1.8.
38
+ #
39
+ module Sys
40
+ RUBY = Config::CONFIG['ruby_install_name']
41
+
42
+ # Install all the files matching +wildcard+ into the +dest_dir+
43
+ # directory. The permission mode is set to +mode+.
44
+ def install(wildcard, dest_dir, mode)
45
+ Dir[wildcard].each do |fn|
46
+ File.install(fn, dest_dir, mode, $verbose)
47
+ end
48
+ end
49
+
50
+ # Run the system command +cmd+.
51
+ def run(cmd)
52
+ log cmd
53
+ system(cmd) or fail "Command Failed: [#{cmd}]"
54
+ end
55
+
56
+ # Run a Ruby interpreter with the given arguments.
57
+ def ruby(*args)
58
+ run "#{RUBY} #{args.join(' ')}"
59
+ end
60
+
61
+ # Copy a single file from +file_name+ to +dest_file+.
62
+ def copy(file_name, dest_file)
63
+ log "Copying file #{file_name} to #{dest_file}"
64
+ File.copy(file_name, dest_file)
65
+ end
66
+
67
+ # Copy all files matching +wildcard+ into the directory +dest_dir+.
68
+ def copy_files(wildcard, dest_dir)
69
+ for_matching_files(wildcard, dest_dir) { |from, to| copy(from, to) }
70
+ end
71
+
72
+ # Link +file_name+ to +dest_file+.
73
+ def link(file_name, dest_file)
74
+ log "Linking file #{file_name} to #{dest_file}"
75
+ File.link(file_name, dest_file)
76
+ end
77
+
78
+ # Link all files matching +wildcard+ into the directory +dest_dir+.
79
+ def link_files(wildcard, dest_dir)
80
+ for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
81
+ end
82
+
83
+ # Symlink +file_name+ to +dest_file+.
84
+ def symlink(file_name, dest_file)
85
+ log "Symlinking file #{file_name} to #{dest_file}"
86
+ File.symlink(file_name, dest_file)
87
+ end
88
+
89
+ # Symlink all files matching +wildcard+ into the directory +dest_dir+.
90
+ def symlink_files(wildcard, dest_dir)
91
+ for_matching_files(wildcard, dest_dir) { |from, to| link(from, to) }
92
+ end
93
+
94
+ # Remove all files matching +wildcard+. If a matching file is a
95
+ # directory, it must be empty to be removed. used +delete_all+ to
96
+ # recursively delete directories.
97
+ def delete(*wildcards)
98
+ wildcards.each do |wildcard|
99
+ Dir[wildcard].each do |fn|
100
+ if File.directory?(fn)
101
+ log "Deleting directory #{fn}"
102
+ Dir.delete(fn)
103
+ else
104
+ log "Deleting file #{fn}"
105
+ File.delete(fn)
106
+ end
107
+ end
108
+ end
109
+ end
110
+
111
+ # Recursively delete all files and directories matching +wildcard+.
112
+ def delete_all(*wildcards)
113
+ wildcards.each do |wildcard|
114
+ Dir[wildcard].each do |fn|
115
+ next if ! File.exist?(fn)
116
+ if File.directory?(fn)
117
+ Dir["#{fn}/*"].each do |subfn|
118
+ next if subfn=='.' || subfn=='..'
119
+ delete_all(subfn)
120
+ end
121
+ log "Deleting directory #{fn}"
122
+ Dir.delete(fn)
123
+ else
124
+ log "Deleting file #{fn}"
125
+ File.delete(fn)
126
+ end
127
+ end
128
+ end
129
+ end
130
+
131
+ # Make the directories given in +dirs+.
132
+ def makedirs(*dirs)
133
+ dirs.each do |fn|
134
+ log "Making directory #{fn}"
135
+ File.makedirs(fn)
136
+ end
137
+ end
138
+
139
+ # Make +dir+ the current working directory for the duration of
140
+ # executing the given block.
141
+ def indir(dir)
142
+ olddir = Dir.pwd
143
+ Dir.chdir(dir)
144
+ yield
145
+ ensure
146
+ Dir.chdir(olddir)
147
+ end
148
+
149
+ # Split a file path into individual directory names.
150
+ #
151
+ # For example:
152
+ # split_all("a/b/c") => ['a', 'b', 'c']
153
+ def split_all(path)
154
+ head, tail = File.split(path)
155
+ return [tail] if head == '.' || tail == '/'
156
+ return [head, tail] if head == '/'
157
+ return split_all(head) + [tail]
158
+ end
159
+
160
+ # Write a message to standard out if $verbose is enabled.
161
+ def log(msg)
162
+ print " " if $trace && $verbose
163
+ puts msg if $verbose
164
+ end
165
+
166
+ # Perform a block with $verbose disabled.
167
+ def quiet(&block)
168
+ with_verbose(false, &block)
169
+ end
170
+
171
+ # Perform a block with $verbose enabled.
172
+ def verbose(&block)
173
+ with_verbose(true, &block)
174
+ end
175
+
176
+ # Perform a block with each file matching a set of wildcards.
177
+ def for_files(*wildcards)
178
+ wildcards.each do |wildcard|
179
+ Dir[wildcard].each do |fn|
180
+ yield(fn)
181
+ end
182
+ end
183
+ end
184
+
185
+ extend(self)
186
+
187
+ private # ----------------------------------------------------------
188
+
189
+ def for_matching_files(wildcard, dest_dir)
190
+ Dir[wildcard].each do |fn|
191
+ dest_file = File.join(dest_dir, fn)
192
+ parent = File.dirname(dest_file)
193
+ makedirs(parent) if ! File.directory?(parent)
194
+ yield(fn, dest_file)
195
+ end
196
+ end
197
+
198
+ def with_verbose(v)
199
+ oldverbose = $verbose
200
+ $verbose = v
201
+ yield
202
+ ensure
203
+ $verbose = oldverbose
204
+ end
205
+
206
+ end
207
+