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,98 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Define a package task library to aid in the definition of GEM
4
+ # packages.
5
+
6
+ require 'rubygems'
7
+ require 'rake'
8
+ require 'rake/packagetask'
9
+
10
+ begin
11
+ Gem.manage_gems
12
+ rescue NoMethodError => ex
13
+ # Using rubygems prior to 0.6.1
14
+ end
15
+
16
+ module Rake
17
+
18
+ # Create a package based upon a Gem spec. Gem packages, as well as
19
+ # zip files and tar/gzipped packages can be produced by this task.
20
+ #
21
+ # In addition to the Rake targets generated by PackageTask, a
22
+ # GemPackageTask will also generate the following tasks:
23
+ #
24
+ # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.gem"</b>]
25
+ # Create a Ruby GEM package with the given name and version.
26
+ #
27
+ # Example using a Ruby GEM spec:
28
+ #
29
+ # require 'rubygems'
30
+ #
31
+ # spec = Gem::Specification.new do |s|
32
+ # s.platform = Gem::Platform::RUBY
33
+ # s.summary = "Ruby based make-like utility."
34
+ # s.name = 'rake'
35
+ # s.version = PKG_VERSION
36
+ # s.requirements << 'none'
37
+ # s.require_path = 'lib'
38
+ # s.autorequire = 'rake'
39
+ # s.files = PKG_FILES
40
+ # s.description = <<EOF
41
+ # Rake is a Make-like program implemented in Ruby. Tasks
42
+ # and dependencies are specified in standard Ruby syntax.
43
+ # EOF
44
+ # end
45
+ #
46
+ # Rake::GemPackageTask.new(spec) do |pkg|
47
+ # pkg.need_zip = true
48
+ # pkg.need_tar = true
49
+ # end
50
+ #
51
+ class GemPackageTask < PackageTask
52
+ # Ruby GEM spec containing the metadata for this package. The
53
+ # name, version and package_files are automatically determined
54
+ # from the GEM spec and don't need to be explicitly provided.
55
+ attr_accessor :gem_spec
56
+
57
+ # Create a GEM Package task library. Automatically define the gem
58
+ # if a block is given. If no block is supplied, then +define+
59
+ # needs to be called to define the task.
60
+ def initialize(gem_spec)
61
+ init(gem_spec)
62
+ yield self if block_given?
63
+ define if block_given?
64
+ end
65
+
66
+ # Initialization tasks without the "yield self" or define
67
+ # operations.
68
+ def init(gem)
69
+ super(gem.name, gem.version)
70
+ @gem_spec = gem
71
+ @package_files += gem_spec.files if gem_spec.files
72
+ end
73
+
74
+ # Create the Rake tasks and actions specified by this
75
+ # GemPackageTask. (+define+ is automatically called if a block is
76
+ # given to +new+).
77
+ def define
78
+ super
79
+ task :package => [:gem]
80
+ task :gem => ["#{package_dir}/#{gem_file}"]
81
+ file "#{package_dir}/#{gem_file}" => [package_dir] + @gem_spec.files do
82
+ when_writing("Creating GEM") {
83
+ Gem::Builder.new(gem_spec).build
84
+ verbose(true) {
85
+ mv gem_file, "#{package_dir}/#{gem_file}"
86
+ }
87
+ }
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ def gem_file
94
+ "#{package_name}.gem"
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Define a package task libarary to aid in the definition of
4
+ # redistributable package files.
5
+
6
+ require 'rake'
7
+ require 'rake/tasklib'
8
+
9
+ module Rake
10
+
11
+ # Create a packaging task that will package the project into
12
+ # distributable files (e.g zip archive or tar files).
13
+ #
14
+ # The PackageTask will create the following targets:
15
+ #
16
+ # [<b>:package</b>]
17
+ # Create all the requested package files.
18
+ #
19
+ # [<b>:clobber_package</b>]
20
+ # Delete all the package files. This target is automatically
21
+ # added to the main clobber target.
22
+ #
23
+ # [<b>:repackage</b>]
24
+ # Rebuild the package files from scratch, even if they are not out
25
+ # of date.
26
+ #
27
+ # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.tgz"</b>]
28
+ # Create a gzipped tar package (if <em>need_tar</em> is true).
29
+ #
30
+ # [<b>"<em>package_dir</em>/<em>name</em>-<em>version</em>.zip"</b>]
31
+ # Create a zip package archive (if <em>need_zip</em> is true).
32
+ #
33
+ # Example:
34
+ #
35
+ # PackageTask.new("rake", "1.2.3") do |p|
36
+ # p.need_tar = true
37
+ # p.package_files.include("lib/**/*.rb")
38
+ # end
39
+ #
40
+ class PackageTask < TaskLib
41
+ # Name of the package (from the GEM Spec).
42
+ attr_accessor :name
43
+
44
+ # Version of the package (e.g. '1.3.2').
45
+ attr_accessor :version
46
+
47
+ # Directory used to store the package files (default is 'pkg').
48
+ attr_accessor :package_dir
49
+
50
+ # True if a gzipped tar file should be produced (default is false).
51
+ attr_accessor :need_tar
52
+
53
+ # True if a zip file should be produced (default is false)
54
+ attr_accessor :need_zip
55
+
56
+ # List of files to be included in the package.
57
+ attr_accessor :package_files
58
+
59
+ # Create a Package Task with the given name and version.
60
+ def initialize(name=nil, version=nil)
61
+ init(name, version)
62
+ yield self if block_given?
63
+ define unless name.nil?
64
+ end
65
+
66
+ # Initialization that bypasses the "yield self" and "define" step.
67
+ def init(name, version)
68
+ @name = name
69
+ @version = version
70
+ @package_files = Rake::FileList.new
71
+ @package_dir = 'pkg'
72
+ @need_tar = false
73
+ @need_zip = false
74
+ end
75
+
76
+ # Create the tasks defined by this task library.
77
+ def define
78
+ fail "Version required (or :noversion)" if @version.nil?
79
+ @version = nil if :noversion == @version
80
+
81
+ desc "Build all the packages"
82
+ task :package
83
+
84
+ desc "Force a rebuild of the package files"
85
+ task :repackage => [:clobber_package, :package]
86
+
87
+ desc "Remove package products"
88
+ task :clobber_package do
89
+ rm_r package_dir rescue nil
90
+ end
91
+
92
+ task :clobber => [:clobber_package]
93
+
94
+ if need_tar
95
+ task :package => ["#{package_dir}/#{tgz_file}"]
96
+ file "#{package_dir}/#{tgz_file}" => [package_dir_path] + package_files do
97
+ chdir(package_dir) do
98
+ sh %{tar zcvf #{tgz_file} #{package_name}}
99
+ end
100
+ end
101
+ end
102
+
103
+ if need_zip
104
+ task :package => ["#{package_dir}/#{zip_file}"]
105
+ file "#{package_dir}/#{zip_file}" => [package_dir_path] + package_files do
106
+ chdir(package_dir) do
107
+ sh %{zip -r #{zip_file} #{package_name}}
108
+ end
109
+ end
110
+ end
111
+
112
+ directory package_dir
113
+
114
+ file package_dir_path => @package_files do
115
+ mkdir_p package_dir rescue nil
116
+ @package_files.each do |fn|
117
+ f = File.join(package_dir_path, fn)
118
+ fdir = File.dirname(f)
119
+ mkdir_p(fdir) if !File.exist?(fdir)
120
+ if File.directory?(fn)
121
+ mkdir_p(f)
122
+ else
123
+ rm_f f
124
+ safe_ln(fn, f)
125
+ end
126
+ end
127
+ end
128
+ self
129
+ end
130
+
131
+ private
132
+
133
+ def package_name
134
+ @version ? "#{@name}-#{@version}" : @name
135
+ end
136
+
137
+ def package_dir_path
138
+ "#{package_dir}/#{package_name}"
139
+ end
140
+
141
+ def tgz_file
142
+ "#{package_name}.tgz"
143
+ end
144
+
145
+ def zip_file
146
+ "#{package_name}.zip"
147
+ end
148
+ end
149
+
150
+ end
151
+
152
+
@@ -0,0 +1,128 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rake'
4
+ require 'rake/tasklib'
5
+
6
+ module Rake
7
+
8
+ # Create a documentation task that will generate the RDoc files for
9
+ # a project.
10
+ #
11
+ # The PackageTask will create the following targets:
12
+ #
13
+ # [<b><em>rdoc</em></b>]
14
+ # Main task for this RDOC task.
15
+ #
16
+ # [<b>:clobber_<em>rdoc</em></b>]
17
+ # Delete all the package files. This target is automatically
18
+ # added to the main clobber target.
19
+ #
20
+ # [<b>:re<em>rdoc</em></b>]
21
+ # Rebuild the package files from scratch, even if they are not out
22
+ # of date.
23
+ #
24
+ # Simple Example:
25
+ #
26
+ # RDocTask.new do |rd|
27
+ # rd.main = "README.rdoc"
28
+ # rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
29
+ # end
30
+ #
31
+ # You may wish to give the task a different name, such as if you are
32
+ # generating two sets of documentation. For instance, if you want to have a
33
+ # development set of documentation including private methods:
34
+ #
35
+ # RDocTask.new(:rdoc_dev) do |rd|
36
+ # rd.main = "README.doc"
37
+ # rd.rdoc_files.include("README.rdoc", "lib/**/*.rb")
38
+ # rd.options << "--all"
39
+ # end
40
+ #
41
+ # The tasks would then be named :<em>rdoc_dev</em>, :clobber_<em>rdoc_dev</em>, and
42
+ # :re<em>rdoc_dev</em>.
43
+ #
44
+ class RDocTask < TaskLib
45
+ # Name of the main, top level task. (default is :rdoc)
46
+ attr_accessor :name
47
+
48
+ # Name of directory to receive the html output files. (default is "html")
49
+ attr_accessor :rdoc_dir
50
+
51
+ # Title of RDoc documentation. (default is none)
52
+ attr_accessor :title
53
+
54
+ # Name of file to be used as the main, top level file of the
55
+ # RDoc. (default is none)
56
+ attr_accessor :main
57
+
58
+ # Name of template to be used by rdoc. (default is 'html')
59
+ attr_accessor :template
60
+
61
+ # List of files to be included in the rdoc generation. (default is [])
62
+ attr_accessor :rdoc_files
63
+
64
+ # List of options to be passed rdoc. (default is [])
65
+ attr_accessor :options
66
+
67
+ # Create an RDoc task named <em>rdoc</em>. Default task name is +rdoc+.
68
+ def initialize(name=:rdoc) # :yield: self
69
+ @name = name
70
+ @rdoc_files = Rake::FileList.new
71
+ @rdoc_dir = 'html'
72
+ @main = nil
73
+ @title = nil
74
+ @template = 'html'
75
+ @options = []
76
+ yield self if block_given?
77
+ define
78
+ end
79
+
80
+ # Create the tasks defined by this task lib.
81
+ def define
82
+ if name.to_s != "rdoc"
83
+ desc "Build the RDOC HTML Files"
84
+ end
85
+
86
+ desc "Build the #{name} HTML Files"
87
+ task name
88
+
89
+ desc "Force a rebuild of the RDOC files"
90
+ task paste("re", name) => [paste("clobber_", name), name]
91
+
92
+ desc "Remove rdoc products"
93
+ task paste("clobber_", name) do
94
+ rm_r rdoc_dir rescue nil
95
+ end
96
+
97
+ task :clobber => [paste("clobber_", name)]
98
+
99
+ directory @rdoc_dir
100
+ task name => [rdoc_target]
101
+ file rdoc_target => @rdoc_files + ["Rakefile"] do
102
+ rm_r @rdoc_dir rescue nil
103
+ opts = option_list.join(' ')
104
+ sh %{rdoc -o #{@rdoc_dir} #{opts} #{@rdoc_files}}
105
+ end
106
+ self
107
+ end
108
+
109
+ def option_list
110
+ result = @options.dup
111
+ result << "--main" << "'#{main}'" if main
112
+ result << "--title" << "'#{title}'" if title
113
+ result << "-T" << "'#{template}'" if template
114
+ result
115
+ end
116
+
117
+ def option_string
118
+ option_list.join(' ')
119
+ end
120
+
121
+ private
122
+
123
+ def rdoc_target
124
+ "#{rdoc_dir}/index.html"
125
+ end
126
+
127
+ end
128
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'test/unit/assertions'
5
+
6
+ module Rake
7
+ include Test::Unit::Assertions
8
+
9
+ def run_tests(pattern='test/test*.rb', log_enabled=false)
10
+ Dir["#{pattern}"].each { |fn|
11
+ puts fn if log_enabled
12
+ begin
13
+ load fn
14
+ rescue Exception => ex
15
+ puts "Error in #{fn}: #{ex.message}"
16
+ puts ex.backtrace
17
+ assert false
18
+ end
19
+ }
20
+ end
21
+
22
+ extend self
23
+ end
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ module Rake
4
+
5
+ # Base class for Task Libraries.
6
+ class TaskLib
7
+
8
+ # Make a copy of a task.
9
+ def clone
10
+ sibling = self.class.new
11
+ instance_variables.each do |ivar|
12
+ value = self.instance_variable_get(ivar)
13
+ sibling.instance_variable_set(ivar, value.dup) if value
14
+ end
15
+ sibling
16
+ end
17
+
18
+ # Make a symbol by pasting two strings together.
19
+ def paste(a,b)
20
+ (a.to_s + b.to_s).intern
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Define a task library for running unit tests.
4
+
5
+ require 'rake'
6
+ require 'rake/tasklib'
7
+
8
+ module Rake
9
+
10
+ # Create a task that runs a set of tests.
11
+ #
12
+ # Example:
13
+ #
14
+ # Rake::TestTask.new do |t|
15
+ # t.libs << "test"
16
+ # t.test_files = FileList['test/test*.rb']
17
+ # t.verbose = true
18
+ # end
19
+ #
20
+ # If rake is invoked with a "TEST=filename" command line option,
21
+ # then the list of test files will be overridden to include only the
22
+ # filename specified on the command line. This provides an easy way
23
+ # to run just one test.
24
+ #
25
+ # If rake is invoked with a "TESTOPTS=options" command line option,
26
+ # then the given options are passed to the test process after a
27
+ # '--'. This allows Test::Unit options to be passed to the test
28
+ # suite.
29
+ #
30
+ # Examples:
31
+ #
32
+ # rake test # run tests normally
33
+ # rake test TEST=just_one_file.rb # run just one test file.
34
+ # rake test TESTOPTS="-v" # run in verbose mode
35
+ # rake test TESTOPTS="--runner=fox" # use the fox test runner
36
+ #
37
+ class TestTask < TaskLib
38
+
39
+ SEP = ''
40
+
41
+ # Name of test task. (default is :test)
42
+ attr_accessor :name
43
+
44
+ # List of directories to added to $LOAD_PATH before running the
45
+ # tests. (default is 'lib')
46
+ attr_accessor :libs
47
+
48
+ # True if verbose test output desired. (default is false)
49
+ attr_accessor :verbose
50
+
51
+ # Test options passed to the test suite. (default is NONE)
52
+ attr_accessor :options
53
+
54
+ # Glob pattern to match test files. (default is 'test/test*.rb')
55
+ attr_accessor :pattern
56
+
57
+ # Explicitly define the list of test files to be included in a
58
+ # test. +list+ is expected to be an array of file names (a
59
+ # FileList is acceptable). If both +pattern+ and +test_files+ are
60
+ # used, then the list of test files is the union of the two.
61
+ def test_files=(list)
62
+ @test_files = list
63
+ end
64
+
65
+ # Create a testing task.
66
+ def initialize(name=:test)
67
+ @name = name
68
+ @libs = ["lib"]
69
+ @pattern = nil
70
+ @test_files = nil
71
+ @verbose = false
72
+ yield self if block_given?
73
+ @pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil?
74
+ define
75
+ end
76
+
77
+ # Create the tasks defined by this task lib.
78
+ def define
79
+ lib_path = @libs.join(File::PATH_SEPARATOR)
80
+ desc "Run tests" + (@name==:test ? "" : " for #{@name}")
81
+ task @name do
82
+ RakeFileUtils.verbose(@verbose) do
83
+ ruby %{-I#{lib_path} -e0 #{SEP}#{required_files}#{option_list}}
84
+ end
85
+ end
86
+ self
87
+ end
88
+
89
+ def required_files # :nodoc:
90
+ file_list.gsub(/^(.*)\.rb$/, ' -r\1').join(" #{SEP}")
91
+ end
92
+
93
+ def option_list # :nodoc:
94
+ if get_options
95
+ testoptions = " #{SEP} -- #{get_options}"
96
+ else
97
+ testoptions = ''
98
+ end
99
+ end
100
+
101
+ def get_options # :nodoc:
102
+ ENV['TESTOPTS'] || @options
103
+ end
104
+
105
+ def file_list # :nodoc:
106
+ if ENV['TEST']
107
+ FileList[ ENV['TEST'] ]
108
+ else
109
+ result = []
110
+ result += @test_files.to_a if @test_files
111
+ result += FileList[ @pattern ].to_a if @pattern
112
+ FileList[result]
113
+ end
114
+ end
115
+
116
+ end
117
+ end
118
+