hen 0.2.7 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/hen/version.rb CHANGED
@@ -3,8 +3,8 @@ class Hen
3
3
  module Version
4
4
 
5
5
  MAJOR = 0
6
- MINOR = 2
7
- TINY = 7
6
+ MINOR = 3
7
+ TINY = 2
8
8
 
9
9
  class << self
10
10
 
data/lib/hens/gem.rake CHANGED
@@ -1,38 +1,58 @@
1
1
  Hen :gem => :rdoc do
2
2
  # Dependencies:
3
- # * rdoc -- Uses RDOC_OPTIONS and 'publish_docs' task
3
+ # * rdoc -- Uses RDOC_OPTIONS and 'doc:publish' task
4
4
 
5
5
  require 'rake/gempackagetask'
6
6
 
7
- gem_options = config[:gem]
8
- rf_config = config[:rubyforge]
7
+ gem_options = config[:gem].merge(
8
+ :files => FileList[
9
+ 'lib/**/*.rb',
10
+ 'bin/*'
11
+ ].to_a,
12
+ :default_extra_files => FileList[
13
+ '[A-Z]*',
14
+ 'example/**/*',
15
+ 'ext/**/*',
16
+ 'spec/**/*', '.rspec',
17
+ 'test/**/*', '.autotest'
18
+ ].to_a,
19
+ :extensions => FileList[
20
+ 'ext/**/extconf.rb'
21
+ ].to_a,
22
+ :require_path => 'lib'
23
+ )
24
+
25
+ rf_config = config[:rubyforge]
9
26
 
10
27
  if Object.const_defined?(:RDOC_OPTIONS)
28
+ rdoc_files = RDOC_OPTIONS[:rdoc_files]
29
+ gem_options[:has_rdoc] = !rdoc_files.empty?
30
+
11
31
  gem_options[:rdoc_options] ||= RDOC_OPTIONS[:options]
12
- rdoc_files = RDOC_OPTIONS[:rdoc_files]
13
32
  end
14
33
 
15
34
  gem_spec = Gem::Specification.new { |spec|
16
35
 
17
36
  ### name
18
37
 
19
- gem_options[:name] ||= rf_config[:package]
38
+ gem_name = gem_options[:name] ||= rf_config[:package]
20
39
 
21
- abort 'Gem name missing' unless gem_options[:name]
40
+ abort 'Gem name missing' unless gem_name
22
41
 
23
42
  ### version
24
43
 
25
44
  abort 'Gem version missing' unless gem_options[:version]
26
45
 
27
- if gem_options.delete(:append_svnversion) && svnversion = `svnversion`[/\d+/]
28
- gem_options[:version] << '.' << svnversion
29
- end
46
+ svn { |svn|
47
+ gem_options[:version] << '.' << svn.version
48
+ } if gem_options.delete(:append_svnversion)
30
49
 
31
50
  ### author(s)
32
51
 
33
- if author = gem_options.delete(:author)
34
- gem_options[:authors] ||= [author]
35
- end
52
+ authors = gem_options[:authors] ||= []
53
+ authors.concat(Array(gem_options.delete(:author))).uniq!
54
+
55
+ warn 'Gem author(s) missing' if authors.empty?
36
56
 
37
57
  ### description
38
58
 
@@ -43,28 +63,35 @@ Hen :gem => :rdoc do
43
63
  gem_options[:rubyforge_project] ||= rf_config[:project]
44
64
 
45
65
  if rf_project = gem_options[:rubyforge_project] and !rf_project.empty?
46
- rdoc_dir = rf_config[:rdoc_dir] == :package ?
47
- rf_config[:package] || gem_options[:name] : RDOC_OPTIONS[:rdoc_dir]
48
-
49
- gem_options[:homepage] ||= "#{rf_project}.rubyforge.org/#{rdoc_dir}"
66
+ rf_rdoc_dir = RDOC_OPTIONS[:rf_rdoc_dir] if Object.const_defined?(:RDOC_OPTIONS)
67
+ gem_options[:homepage] ||= "#{rf_project}.rubyforge.org/#{rf_rdoc_dir}"
50
68
  end
51
69
 
52
- if gem_options[:homepage] && gem_options[:homepage] !~ %r{://}
53
- gem_options[:homepage] = 'http://' << gem_options[:homepage]
70
+ if homepage = gem_options[:homepage]
71
+ homepage = "github.com/#{homepage}/#{gem_name}" if homepage.is_a?(Symbol)
72
+ homepage.insert(0, 'http://') unless homepage.empty? || homepage =~ %r{://}
54
73
  end
55
74
 
56
- ### extra_rdoc_files, files, executables, bindir
75
+ ### extra_rdoc_files, files, extensions, executables, bindir
57
76
 
58
77
  gem_options[:files] ||= []
78
+ gem_options[:extensions] ||= []
59
79
  gem_options[:extra_rdoc_files] ||= rdoc_files - gem_options[:files] if rdoc_files
60
- gem_options[:files] += gem_options.delete(:extra_files) || []
61
-
62
- gem_options[:executables] ||= gem_options[:files].grep(/\Abin\//)
63
80
 
64
- [:extra_rdoc_files, :files, :executables].each { |files|
65
- gem_options[files].delete_if { |file| !File.exists?(file) }
81
+ [:extra_files, :default_extra_files].each { |files|
82
+ gem_options[:files].concat(gem_options.delete(files) || [])
66
83
  }
67
84
 
85
+ if exclude_files = gem_options.delete(:exclude_files)
86
+ gem_options[:files] -= exclude_files
87
+ end
88
+
89
+ gem_options[:executables] ||= gem_options[:files].grep(%r{\Abin/})
90
+
91
+ mangle_files!(*gem_options.values_at(
92
+ :extra_rdoc_files, :files, :executables, :extensions
93
+ ))
94
+
68
95
  unless gem_options[:executables].empty?
69
96
  gem_options[:bindir] ||= File.dirname(gem_options[:executables].first)
70
97
  gem_options[:executables].map! { |executable| File.basename(executable) }
@@ -76,20 +103,22 @@ Hen :gem => :rdoc do
76
103
  spec.add_dependency(*dependency)
77
104
  }
78
105
 
106
+ (gem_options.delete(:development_dependencies) || []).each { |dependency|
107
+ spec.add_development_dependency(*dependency)
108
+ }
109
+
79
110
  ### => set options!
80
111
 
81
- gem_options.each { |option, value|
82
- spec.send("#{option}=", value)
83
- }
112
+ gem_options.each { |option, value| spec.send("#{option}=", value) }
84
113
  }
85
114
 
86
115
  desc 'Display the gem specification'
87
- task :gemspec do
116
+ task 'gem:spec' do
88
117
  puts gem_spec.to_ruby
89
118
  end
90
119
 
91
120
  desc "Update (or create) the project's gemspec file"
92
- task 'gemspec:update' do
121
+ task 'gem:spec:update' do
93
122
  file = "#{gem_spec.name}.gemspec"
94
123
  action = File.exists?(file) ? 'Updated' : 'Created'
95
124
 
@@ -98,7 +127,7 @@ Hen :gem => :rdoc do
98
127
  puts "#{action} #{file}"
99
128
  end
100
129
 
101
- pkg_task = Rake::GemPackageTask.new(gem_spec) do |pkg|
130
+ pkg_task = Rake::GemPackageTask.new(gem_spec) { |pkg|
102
131
  pkg.need_tar_gz = true
103
132
  pkg.need_zip = true
104
133
 
@@ -106,13 +135,33 @@ Hen :gem => :rdoc do
106
135
  require 'nuggets/file/which'
107
136
  pkg.zip_command = File.which_command(ZIP_COMMANDS) || ZIP_COMMANDS.first
108
137
  end
138
+ }
139
+
140
+ release_desc = "Release #{pkg_task.name} version #{pkg_task.version}"
141
+
142
+ rubygems do |rg_pool|
143
+
144
+ gem_path = File.join(pkg_task.package_dir, pkg_task.gem_file)
145
+
146
+ desc "Create the gem and install it"
147
+ task 'gem:install' => :gem do
148
+ rg_pool.call.install(gem_path)
149
+ end
150
+
151
+ desc 'Create the gem and upload it to RubyGems.org'
152
+ task 'gem:push' => :gem do
153
+ rg_pool.call.push(gem_path)
154
+ end
155
+
156
+ desc release_desc; release_desc = nil
157
+ task :release => 'gem:push'
158
+
109
159
  end
110
160
 
111
- begin
112
161
  rubyforge do |rf_config, rf_pool|
113
162
 
114
- desc 'Package and upload the release to Rubyforge'
115
- task :release => [:package, :publish_docs] do
163
+ desc 'Package and upload the release to RubyForge'
164
+ task 'release:rubyforge' => [:package, 'doc:publish'] do
116
165
  files = Dir[File.join(pkg_task.package_dir, "#{pkg_task.package_name}.*")]
117
166
  abort 'Nothing to release!' if files.empty?
118
167
 
@@ -130,19 +179,9 @@ begin
130
179
  rf.add_release(rf_config[:project], pkg_task.name, version, *files)
131
180
  end
132
181
 
133
- end
134
- rescue RuntimeError => err
135
- raise unless err.to_s == 'Skipping Rubyforge tasks'
136
-
137
- gemcutter do |gc_pool|
138
-
139
- desc 'Create the gem and upload it to Gemcutter'
140
- task :release => [:gem] do
141
- gc = gc_pool.call
142
- gc.push(File.join(pkg_task.package_dir, pkg_task.gem_file))
143
- end
182
+ desc release_desc
183
+ task :release => 'release:rubyforge'
144
184
 
145
185
  end
146
- end
147
186
 
148
187
  end
data/lib/hens/rdoc.rake CHANGED
@@ -1,8 +1,25 @@
1
1
  Hen :rdoc do
2
2
 
3
- require 'rake/rdoctask'
4
-
5
- rdoc_options = config[:rdoc]
3
+ rdoc_options = config[:rdoc].merge(
4
+ :rdoc_dir => 'doc',
5
+ :rdoc_files => %w[README COPYING ChangeLog lib/**/*.rb],
6
+ :charset => 'UTF-8',
7
+ :inline_source => true,
8
+ :line_numbers => true,
9
+ :all => true
10
+ )
11
+
12
+ rdoc_klass = begin
13
+ raise LoadError if rdoc_options.delete(:legacy)
14
+
15
+ require 'rdoc/task'
16
+
17
+ rdoc_options.delete(:inline_source) # deprecated
18
+ RDoc::Task
19
+ rescue LoadError
20
+ require 'rake/rdoctask'
21
+ Rake::RDocTask
22
+ end
6
23
 
7
24
  rdoc_options[:title] ||= begin
8
25
  title = 'Application documentation'
@@ -22,14 +39,21 @@ Hen :rdoc do
22
39
 
23
40
  rdoc_dir = rdoc_options.delete(:rdoc_dir)
24
41
 
25
- ### rdoc_files
42
+ ### rdoc_files, main
26
43
 
27
- rdoc_files = FileList[rdoc_options.delete(:rdoc_files)].
28
- sort.uniq.select { |file| File.exists?(file) }
44
+ rdoc_files = FileList[rdoc_options.delete(:rdoc_files)].to_a
45
+ rdoc_files_local = rdoc_files.dup
29
46
 
30
- ### rdoc_options
47
+ if mangle_files!(rdoc_files)
48
+ mangle_files!(rdoc_files_local, :managed => false)
49
+ else
50
+ rdoc_files_local = nil
51
+ end
31
52
 
32
53
  rdoc_options.delete(:main) unless rdoc_files.include?(rdoc_options[:main])
54
+ rdoc_options[:main] ||= rdoc_files.first
55
+
56
+ ### rdoc_options
33
57
 
34
58
  rdoc_options = rdoc_options.map { |option, value|
35
59
  option = '--' << option.to_s.tr('_', '-')
@@ -44,8 +68,7 @@ Hen :rdoc do
44
68
  }
45
69
 
46
70
  unless rdoc_files.empty?
47
- # Rake::RDocTask -> RDoc::Task (require 'rdoc/task')
48
- rdoc_task = Rake::RDocTask.new(:doc) { |rdoc|
71
+ rdoc_task = rdoc_klass.new(:doc) { |rdoc|
49
72
  rdoc.rdoc_dir = rdoc_dir
50
73
  rdoc.rdoc_files = rdoc_files
51
74
  rdoc.options = rdoc_options
@@ -56,39 +79,23 @@ Hen :rdoc do
56
79
  end
57
80
  end
58
81
 
59
- begin
60
- rubyforge do |rf_config|
61
-
62
- desc 'Publish RDoc to Rubyforge'
63
- task :publish_docs => :doc do
64
- rf_project = rf_config[:project]
65
- abort 'Rubyforge project name missing' unless rf_project
66
-
67
- rf_user = rf_config[:username]
68
- abort 'Rubyforge user name missing' unless rf_user
69
-
70
- rf_host = "#{rf_user}@rubyforge.org"
71
-
72
- local_dir = rdoc_task.rdoc_dir
73
- remote_dir = "/var/www/gforge-projects/#{rf_project}"
74
-
75
- if rdoc_dir = rf_config[:rdoc_dir]
76
- if rf_package = rf_config[:package]
77
- rdoc_dir = rf_package if rdoc_dir == :package
78
- end
79
-
80
- remote_dir = File.join(remote_dir, rdoc_dir)
81
- end
82
+ unless rdoc_files_local.nil? || rdoc_files_local.empty?
83
+ rdoc_klass.new('doc:local') { |rdoc|
84
+ rdoc.rdoc_dir = rdoc_dir + '.local'
85
+ rdoc.rdoc_files = rdoc_files_local
86
+ rdoc.options = rdoc_options
82
87
 
83
- execute(
84
- "rsync -av --delete #{local_dir}/ #{rf_host}:#{remote_dir}/",
85
- "scp -r #{local_dir}/ #{rf_host}:#{remote_dir}/"
86
- )
87
- end
88
+ extend_object(rdoc) {
89
+ def local_description(desc); "#{desc} (including unmanaged files)"; end
88
90
 
91
+ def clobber_task_description; local_description(super); end
92
+ def rdoc_task_description; local_description(super); end
93
+ def rerdoc_task_description; local_description(super); end
94
+ }
95
+ }
89
96
  end
90
- rescue RuntimeError => err
91
- raise unless err.to_s == 'Skipping Rubyforge tasks'
97
+
98
+ publish_desc = "Publish RDoc documentation"
92
99
 
93
100
  git do |git|
94
101
 
@@ -105,7 +112,7 @@ rescue RuntimeError => err
105
112
  if pages_url # inside git repo and found gh-pages branch
106
113
 
107
114
  desc "Publish RDoc to GitHub pages"
108
- task :publish_docs => :doc do
115
+ task 'doc:publish:github' => :doc do
109
116
  rm_rf clone_dir
110
117
 
111
118
  git.easy_clone pages_url, clone_dir, git_remote
@@ -120,10 +127,13 @@ rescue RuntimeError => err
120
127
  }
121
128
  end
122
129
 
130
+ desc publish_desc; publish_desc = nil
131
+ task 'doc:publish' => 'doc:publish:github'
132
+
123
133
  elsif clone_url # still git repo, but no gh-pages branch
124
134
 
125
135
  desc "Create #{git_branch} branch on #{git_remote}"
126
- task :make_ghpages do
136
+ task 'doc:make_ghpages' do
127
137
  git.easy_clone clone_url, clone_dir, git_remote
128
138
 
129
139
  Dir.chdir(clone_dir) {
@@ -146,6 +156,37 @@ rescue RuntimeError => err
146
156
  end
147
157
 
148
158
  end
149
- end
159
+
160
+ rubyforge do |rf_config|
161
+
162
+ rf_project = rf_config[:project]
163
+
164
+ rf_rdoc_dir, rf_package = rf_config.values_at(:rdoc_dir, :package)
165
+ rf_rdoc_dir ||= :package if rf_package && rf_package != rf_project
166
+ rf_rdoc_dir = rf_package if rf_package && rf_rdoc_dir == :package
167
+
168
+ RDOC_OPTIONS[:rf_rdoc_dir] = rf_rdoc_dir
169
+
170
+ desc 'Publish RDoc to RubyForge'
171
+ task 'doc:publish:rubyforge' => :doc do
172
+ rf_user = rf_config[:username]
173
+ abort 'RubyForge user name missing' unless rf_user
174
+
175
+ rf_host = "#{rf_user}@rubyforge.org"
176
+
177
+ local_dir = rdoc_task.rdoc_dir
178
+ remote_dir = "/var/www/gforge-projects/#{rf_project}"
179
+ remote_dir = File.join(remote_dir, rf_rdoc_dir) if rf_rdoc_dir
180
+
181
+ execute(
182
+ "rsync -av --delete #{local_dir}/ #{rf_host}:#{remote_dir}/",
183
+ "scp -r #{local_dir}/ #{rf_host}:#{remote_dir}/"
184
+ )
185
+ end
186
+
187
+ desc publish_desc
188
+ task 'doc:publish' => 'doc:publish:rubyforge'
189
+
190
+ end
150
191
 
151
192
  end
data/lib/hens/spec.rake CHANGED
@@ -1,17 +1,30 @@
1
1
  Hen :spec do
2
2
 
3
- begin
3
+ spec_options = config[:spec].merge(
4
+ :pattern => 'spec/**/*_spec.rb',
5
+ :helper => 'spec/spec_helper.rb',
6
+ :options => 'spec/spec.opts'
7
+ )
8
+
9
+ spec_klass = begin
10
+ raise LoadError if spec_options.delete(:legacy)
11
+
4
12
  require 'rspec/core/rake_task'
13
+ RSpec::Core::RakeTask
5
14
  rescue LoadError
6
15
  require 'spec/rake/spectask'
16
+ Spec::Rake::SpecTask
7
17
  end
8
18
 
9
- spec_options = config[:spec]
19
+ spec_files = spec_options.delete(:files) ||
20
+ FileList[spec_options.delete(:pattern)].to_a
10
21
 
11
- spec_files = spec_options.delete(:files) || FileList[spec_options.delete(:pattern)]
22
+ mangle_files!(spec_files, :managed => false)
12
23
 
13
- if spec_files && !spec_files.empty?
14
- if spec_helper = spec_options.delete(:helper) and File.readable?(spec_helper)
24
+ unless spec_files.empty?
25
+ spec_helper = spec_options.delete(:helper)
26
+
27
+ if spec_helper && File.readable?(spec_helper)
15
28
  spec_files.delete(spec_helper)
16
29
  spec_files.unshift(spec_helper)
17
30
  end
@@ -27,30 +40,28 @@ Hen :spec do
27
40
  File.readlines(opts_file).each { |l| spec_opts << l.chomp }
28
41
  end
29
42
 
30
- klass, spec_task = if defined?(RSpec::Core::RakeTask)
31
- [RSpec::Core::RakeTask, lambda { |t|
32
- t.pattern = spec_files
33
- t.rspec_opts = spec_opts
34
- }]
35
- else
36
- [Spec::Rake::SpecTask, lambda { |t|
43
+ spec_block = lambda { |t|
44
+ if t.respond_to?(:spec_files=)
37
45
  t.spec_files = spec_files
38
46
  t.spec_opts = spec_opts
39
- }]
40
- end
47
+ else
48
+ t.pattern = spec_files
49
+ t.rspec_opts = spec_opts
50
+ end
51
+ }
41
52
 
42
- klass.new(&spec_task)
53
+ spec_klass.new(&spec_block)
43
54
 
44
55
  rcov_opts = ['--exclude', spec_files.join(',')]
45
- rcov_file = File.join(spec_files.first[/[^\/.]+/], 'rcov.opts')
56
+ rcov_file = File.join(spec_files.first[%r{[^/.]+}], 'rcov.opts')
46
57
 
47
58
  if rcov_file && File.readable?(rcov_file)
48
- File.readlines(rcov_file).each { |l| rcov_opts << l.chomp }
59
+ File.readlines(rcov_file).each { |line| rcov_opts << line.chomp }
49
60
  end
50
61
 
51
62
  #desc "Run specs with RCov"
52
63
  klass.new('spec:rcov') do |t|
53
- spec_task[t]
64
+ spec_block[t]
54
65
 
55
66
  t.rcov = true
56
67
  t.rcov_opts = rcov_opts