corundum 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,35 +7,26 @@ module Corundum
7
7
  extend Rake::DSL
8
8
 
9
9
  class Toolkit < TaskLib
10
- def default_configuration
11
- settings(
12
- :finished_dir => "corundum",
13
- :finished_files => nested(
14
- :build => nil,
15
- :qa => nil,
16
- :package => nil,
17
- :release => nil,
18
- :press => nil),
19
-
20
- :browser => "chromium",
21
- :gemspec => nil,
22
- :gemspec_path => nil,
23
- :email => nested(
24
- :servers => [ nested({ :server => "ruby-lang.org", :helo => "gmail.com" }) ],
25
- :announce_to_email => "ruby-talk@ruby-lang.org"
26
- ),
27
- :package_dir => "pkg",
28
- :files => nested(:code => nil, :test => nil, :docs => nil),
29
- :file_lists => nested(:code => FileList['lib/**/*.rb'],
30
- :test => FileList['test/**/*.rb','spec/**/*.rb','features/**/*.rb'],
31
- :docs => FileList['doc/**/*.rb'],
32
- :project => FileList['Rakefile'],
33
- :all => nil),
34
- :rubyforge => nested().nil_fields(:group_id, :package_id,
35
- :release_name, :home_page, :project_page),
36
- :doc_dir => "rubydoc"
37
- )
38
- end
10
+ settings(
11
+ :gemspec => nil,
12
+ :gemspec_path => nil,
13
+ :finished_dir => "corundum",
14
+ :package_dir => "pkg",
15
+ :doc_dir => "rubydoc",
16
+ :browser => "chromium",
17
+ :finished_files => nested.nil_fields(:build, :qa, :package, :release, :press),
18
+ :files => nested.nil_fields(:code, :test, :docs),
19
+ :rubyforge => nested.nil_fields(:group_id, :package_id, :release_name, :home_page, :project_page),
20
+ :email => nested(
21
+ :servers => [ nested({ :server => "ruby-lang.org", :helo => "gmail.com" }) ],
22
+ :announce_to_email => "ruby-talk@ruby-lang.org"
23
+ ),
24
+ :file_lists => nested(:code => FileList['lib/**/*.rb'],
25
+ :test => FileList['test/**/*.rb','spec/**/*.rb','features/**/*.rb'],
26
+ :docs => FileList['doc/**/*.rb'],
27
+ :project => FileList['Rakefile'],
28
+ :all => nil)
29
+ )
39
30
 
40
31
  def load_gemspec
41
32
  @gemspec_path ||= guess_gemspec
@@ -0,0 +1,21 @@
1
+ require 'mattock/command-task'
2
+
3
+ module Corundum
4
+ class BrowserTask < Mattock::CommandTask
5
+ setting(:browser, "chromium")
6
+ setting(:index_html)
7
+ setting(:task_name, "view")
8
+
9
+ def default_configuration(parent)
10
+ self.browser = parent.browser
11
+ end
12
+
13
+ def task_args
14
+ [{task_name => index_html}]
15
+ end
16
+
17
+ def resolve_configuration
18
+ self.command = Mattock::CommandLine.new(browser, index_html)
19
+ end
20
+ end
21
+ end
@@ -2,17 +2,19 @@ require 'corundum/tasklib'
2
2
 
3
3
  module Corundum
4
4
  class Email < TaskLib
5
- def default_namespace
6
- :email
7
- end
5
+ default_namespace :email
6
+
7
+ setting(:rubyforge)
8
+ setting(:email_servers, [])
9
+ setting(:gemspec)
10
+ setting(:announce_to_email, nil)
11
+ setting(:urls, nested.required_fields(:home_page, :project_page))
8
12
 
9
13
  def default_configuration(toolkit)
10
- setting(:rubyforge, toolkit.rubyforge)
11
- setting(:email_servers, [])
12
- setting(:gemspec, toolkit.gemspec)
13
- setting(:announce_to_email, nil)
14
- setting(:urls, nested(:home_page => toolkit.gemspec.homepage,
15
- :project_page => toolkit.rubyforge.project_page))
14
+ self.rubyforge = toolkit.rubyforge
15
+ self.gemspec = toolkit.gemspec
16
+ self.urls.home_page = toolkit.gemspec.homepage
17
+ self.urls.project_page = toolkit.rubyforge.project_page
16
18
  end
17
19
 
18
20
  def announcement
@@ -2,10 +2,13 @@ require 'corundum/tasklib'
2
2
 
3
3
  module Corundum
4
4
  class GemBuilding < TaskLib
5
+ setting(:gemspec)
6
+ setting(:qa_finished_file)
7
+ setting(:package_dir, "pkg")
8
+
5
9
  def default_configuration(toolkit)
6
- setting(:gemspec, toolkit.gemspec)
7
- setting(:qa_finished_file, toolkit.finished_files.qa)
8
- setting(:package_dir, "pkg")
10
+ self.gemspec = toolkit.gemspec
11
+ self.qa_finished_file = toolkit.finished_files.qa
9
12
  end
10
13
 
11
14
  def define
@@ -2,21 +2,25 @@ require 'corundum/tasklib'
2
2
 
3
3
  module Corundum
4
4
  class GemCutter < TaskLib
5
- def default_namespace
6
- :gemcutter
7
- end
5
+ default_namespace :gemcutter
6
+
7
+ setting(:gem_path, nil)
8
+ setting(:build)
9
+ setting(:gemspec)
10
+ setting(:build_finished_path)
11
+ setting(:gem_name)
12
+ setting(:package_dir)
8
13
 
9
14
  def default_configuration(toolkit, build)
10
- setting(:build, build)
11
- setting(:gemspec, toolkit.gemspec)
12
- setting(:build_finished_path, toolkit.finished_files.build)
13
- setting(:gem_path, nil)
14
- setting(:gem_name, toolkit.gemspec.full_name)
15
- setting(:package_dir, build.package_dir)
15
+ self.build = build
16
+ self.gemspec = toolkit.gemspec
17
+ self.build_finished_path = toolkit.finished_files.build
18
+ self.gem_name = toolkit.gemspec.full_name
19
+ self.package_dir = build.package_dir
16
20
  end
17
21
 
18
22
  def resolve_configuration
19
- @gem_path ||= File::join(package_dir, gemspec.file_name)
23
+ self.gem_path ||= File::join(package_dir, gemspec.file_name)
20
24
  end
21
25
 
22
26
  module CommandTweaks
@@ -2,16 +2,22 @@ require 'corundum/tasklib'
2
2
 
3
3
  module Corundum
4
4
  class GemspecSanity < TaskLib
5
- def default_namespace
6
- :gemspec_sanity
7
- end
5
+ default_namespace :gemspec_sanity
6
+
7
+ setting(:gemspec)
8
8
 
9
9
  def default_configuration(toolkit)
10
- setting(:gemspec, toolkit.gemspec)
10
+ self.gemspec = toolkit.gemspec
11
11
  end
12
12
 
13
13
  def define
14
14
  in_namespace do
15
+ task :has_files do
16
+ if gemspec.files.nil? or gemspec.files.empty?
17
+ fail "No files mentioned in gemspec - do you intend an empty gem?"
18
+ end
19
+ end
20
+
15
21
  task :files_exist do
16
22
  missing = gemspec.files.find_all do |path|
17
23
  not File::exists?(path)
@@ -21,7 +27,7 @@ module Corundum
21
27
  end
22
28
  end
23
29
 
24
- task :preflight => in_namespace(:files_exist)
30
+ task :preflight => in_namespace(:files_exist, :has_files)
25
31
  end
26
32
  end
27
33
  end
@@ -0,0 +1,147 @@
1
+ require 'corundum/tasklib'
2
+ require 'mattock/task'
3
+
4
+ module Corundum
5
+ class GitTask < Mattock::CommandTask
6
+ setting(:subcommand)
7
+ setting(:arguments, [])
8
+
9
+ def command
10
+ Mattock::CommandLine.new("git", "--no-pager") do |cmd|
11
+ cmd.options << subcommand
12
+ arguments.each do |arg|
13
+ cmd.options += [*arg]
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ class InDirCommandTask < Mattock::CommandTask
20
+ setting :target_dir
21
+
22
+ def default_configuration(parent)
23
+ parent.copy_settings_to(self)
24
+ end
25
+
26
+ def needed?
27
+ FileUtils.cd target_dir do
28
+ super
29
+ end
30
+ end
31
+
32
+ def action
33
+ FileUtils.cd target_dir do
34
+ super
35
+ end
36
+ end
37
+ end
38
+
39
+ class GithubPages < TaskLib
40
+ default_namespace :publish_docs
41
+
42
+ setting(:target_dir, "gh-pages")
43
+ setting(:source_dir)
44
+
45
+ nil_fields :repo_dir
46
+
47
+ def branch
48
+ "gh-pages"
49
+ end
50
+
51
+ def default_configuration(doc_gen)
52
+ self.source_dir = doc_gen.target_dir
53
+ end
54
+
55
+ def resolve_configuration
56
+ self.repo_dir ||= File::join(target_dir, ".git")
57
+ end
58
+
59
+ def git_command(*args)
60
+ Mattock::CommandLine.new("git", "--no-pager") do |cmd|
61
+ args.each do |arg|
62
+ cmd.options += [*arg]
63
+ end
64
+ end
65
+ end
66
+
67
+ def git(*args)
68
+ result = git_command(*args).run
69
+ result.must_succeed!
70
+ result.stdout.lines.to_a
71
+ end
72
+
73
+ $verbose = true
74
+
75
+ def define
76
+ in_namespace do
77
+ InDirCommandTask.new(self) do |t|
78
+ t.task_name = :on_branch
79
+ t.verify_command = Mattock::PipelineChain.new do |chain|
80
+ chain.add git_command(%w{branch})
81
+ chain.add Mattock::CommandLine.new("grep", "-q", "'^[*] #{branch}'")
82
+ end
83
+ t.command = Mattock::PrereqChain.new do |chain|
84
+ chain.add git_command("checkout", branch)
85
+ end
86
+ end
87
+
88
+ file repo_dir do
89
+ fail "Refusing to clobber existing #{target_dir}" if File.exists?(target_dir)
90
+
91
+ url = git("config", "--get", "remote.origin.url").first
92
+
93
+ git("clone", url.chomp, "-b", branch, target_dir)
94
+ Mattock::CommandLine.new("rm", File::join(repo_dir, "hooks", "*")).must_succeed!
95
+ end
96
+
97
+ task :pull => [repo_dir, :on_branch] do
98
+ FileUtils.cd target_dir do
99
+ git("pull")
100
+ end
101
+ end
102
+
103
+ InDirCommandTask.new(self) do |t|
104
+ t.task_name = :setup
105
+ t.verify_command = Mattock::PipelineChain.new do |chain|
106
+ chain.add git_command(%w{branch -r})
107
+ chain.add Mattock::CommandLine.new("grep", "-q", branch)
108
+ end
109
+ t.command = Mattock::PrereqChain.new do |cmd|
110
+ cmd.add git_command("checkout", "-b", branch)
111
+ cmd.add Mattock::CommandLine.new("rm -rf *")
112
+ cmd.add git_command(%w{commit -a -m} + ["'Creating pages'"])
113
+ cmd.add git_command("push", "origin", branch)
114
+ cmd.add git_command("branch", "--set-upstream", branch, "origin/" + branch)
115
+ end
116
+ end
117
+ task :setup => repo_dir
118
+
119
+ task :pre_publish => [repo_dir, :setup, :pull]
120
+
121
+ task :clobber_target => :on_branch do
122
+ Mattock::CommandLine.new(*%w{rm -rf}) do |cmd|
123
+ cmd.options << target_dir + "/*"
124
+ end.must_succeed!
125
+ end
126
+
127
+ task :assemble_docs => [:pre_publish, :clobber_target] do
128
+ Mattock::CommandLine.new(*%w{cp -a}) do |cmd|
129
+ cmd.options << source_dir + "/*"
130
+ cmd.options << target_dir
131
+ end.must_succeed!
132
+ end
133
+
134
+ task :publish => [:assemble_docs, :on_branch] do
135
+ FileUtils.cd target_dir do
136
+ git("add", ".")
137
+ git("commit", "-m", "'Corundum auto-publish'")
138
+ git("push", "origin", branch)
139
+ end
140
+ end
141
+ end
142
+
143
+ desc "Push documentation files to Github Pages"
144
+ task root_task => self[:publish]
145
+ end
146
+ end
147
+ end
@@ -1,114 +1,100 @@
1
1
  require 'corundum/tasklib'
2
2
  require 'rspec/core'
3
+ require 'mattock/command-task'
4
+ require 'rbconfig'
3
5
 
4
6
  module Corundum
5
- #TODO: this should take two command generators as arguments: the test runner,
6
- #and the coverage tool - then the various tasks are the result of the
7
- #collaboration of those two.
8
- #
9
- class RSpec < TaskLib
10
- def default_namespace
11
- :rspec
7
+ class RSpecTask < Mattock::CommandTask
8
+ setting :ruby_command, Mattock::CommandLine.new(RbConfig.ruby) do |cmd|
9
+ if /^1\.8/ =~ RUBY_VERSION
10
+ cmd.options << "-S"
11
+ end
12
12
  end
13
13
 
14
- def default_configuration(toolkit)
15
- setting(:task_options, nested(
16
- :pattern => './spec{,/*/**}/*_spec.rb',
17
- :ruby_opts => nil,
18
- :rspec_configs => nil,
19
- :rspec_opts => nil,
20
- :warning => false,
21
- :verbose => true,
22
- :fail_on_error => true,
23
- :ruby_opts => [],
24
- :rspec_path => 'rspec',
25
- :rspec_opts => %w{--format documentation --out last_run --color --format documentation},
26
- :failure_message => "Spec examples failed.",
27
- :files_to_run => "spec"
28
- ))
29
-
30
- setting(:gemspec_path, toolkit.gemspec_path)
31
- setting(:qa_finished_path, toolkit.finished_files.qa)
14
+ setting :runner_command
15
+
16
+ required_fields :pattern, :ruby_opts, :rspec_configs, :rspec_opts,
17
+ :warning, :rspec_path, :rspec_opts, :failure_message, :files_to_run
18
+
19
+ def default_configuration(rspec)
20
+ self.pattern = rspec.pattern
21
+ self.ruby_opts = rspec.ruby_opts
22
+ self.rspec_configs = rspec.rspec_configs
23
+ self.rspec_opts = rspec.rspec_opts
24
+ self.warning = rspec.warning
25
+ self.rspec_path = rspec.rspec_path
26
+ self.rspec_opts = rspec.rspec_opts
27
+ self.failure_message = rspec.failure_message
28
+ self.files_to_run = rspec.files_to_run
32
29
  end
33
30
 
34
31
  def resolve_configuration
35
- #XXX Que?
36
- @task_options.rspec_configs = task_options.rspec_opts
37
- @task_options.rspec_opts = []
38
- @task_options.rspec_path = %x"which #{task_options.rspec_path}".chomp
39
- end
32
+ self.rspec_configs = rspec_opts
33
+ self.rspec_path = %x"which #{rspec_path}".chomp
40
34
 
41
- #XXX some point in the future, there needs to be a composible command
42
- #object
43
- def ruby_command(options)
44
- cmd_parts = []
45
- cmd_parts << RUBY
46
- cmd_parts << options.ruby_opts
47
- cmd_parts << "-w" if options.warning
48
- if /^1\.8/ =~ RUBY_VERSION
49
- cmd_parts << "-S"
35
+ ruby_command.options << ruby_opts if ruby_opts
36
+ ruby_command.options << "-w" if warning
37
+
38
+ self.runner_command = Mattock::CommandLine.new(rspec_path) do |cmd|
39
+ cmd.options << rspec_opts
40
+ cmd.options << files_to_run
50
41
  end
51
- return cmd_parts
52
- end
53
42
 
54
- def runner_command(options)
55
- cmd_parts = []
56
- cmd_parts << options.rspec_path
57
- cmd_parts << options.rspec_opts
58
- cmd_parts << options.files_to_run
59
- return cmd_parts
43
+ self.command = Mattock::WrappingChain.new do |cmd|
44
+ cmd.add ruby_command
45
+ cmd.add runner_command
46
+ end
60
47
  end
48
+ end
61
49
 
62
- def full_command(options)
63
- cmd_parts = ruby_command(options) + runner_command(options)
64
- return cmd_parts.flatten.compact.reject{|part| part.nil? or part.empty?}.join(" ")
65
- end
66
50
 
67
- def custom_options
68
- options = task_options.dup
69
- yield(options)
70
- return options
51
+ class RSpec < TaskLib
52
+ default_namespace :rspec
53
+
54
+ settings(
55
+ :pattern => './spec{,/*/**}/*_spec.rb',
56
+ :rspec_configs => nil,
57
+ :rspec_opts => nil,
58
+ :warning => false,
59
+ :verbose => true,
60
+ :ruby_opts => [],
61
+ :rspec_path => 'rspec',
62
+ :rspec_opts => %w{--format documentation --out last_run --color --format documentation},
63
+ :failure_message => "Spec examples failed.",
64
+ :files_to_run => "spec"
65
+ )
66
+
67
+ required_fields :gemspec_path, :qa_finished_path
68
+
69
+ def default_configuration(toolkit)
70
+ self.gemspec_path = toolkit.gemspec_path
71
+ self.qa_finished_path = toolkit.finished_files.qa
71
72
  end
72
73
 
73
- def define_spec_task(name)
74
- options = if block_given?
75
- custom_options{|options| yield(options) if block_given?}
76
- else
77
- task_options
78
- end
79
- task name do
80
- RakeFileUtils.send(:verbose, verbose) do
81
- if options.files_to_run.empty?
82
- puts "No examples matching #{options.pattern} could be found"
83
- else
84
- begin
85
- cmd = full_command(options)
86
- puts cmd if options.verbose
87
- success = system(cmd)
88
- rescue Object => ex
89
- p ex
90
- puts options.failure_message if options.failure_message
91
- end
92
- raise("ruby #{cmd} failed") if options.fail_on_error unless success
93
- end
94
- end
95
- end
74
+ def resolve_configuration
75
+ #XXX Que?
76
+ self.rspec_configs = rspec_opts
77
+ self.rspec_opts = []
78
+ self.rspec_path = %x"which #{rspec_path}".chomp
96
79
  end
97
80
 
98
81
  def define
99
82
  in_namespace do
100
83
  desc "Always run every spec"
101
- define_spec_task(:all)
84
+ RSpecTask.new(self) do |t|
85
+ t.task_name = :all
86
+ end
102
87
 
103
88
  desc "Generate specifications documentation"
104
- define_spec_task(:doc) do |t|
89
+ RSpecTask.new(self) do |t|
90
+ t.task_name = :doc
105
91
  t.rspec_opts = %w{-o /dev/null -f d -o doc/Specifications}
106
92
  t.failure_message = "Failed generating specification docs"
107
- t.verbose = false
108
93
  end
109
94
 
110
95
  desc "Run only failing examples listed in last_run"
111
- define_spec_task(:quick) do |t|
96
+ RSpecTask.new(self) do |t|
97
+ t.task_name = :quick
112
98
  examples = []
113
99
  begin
114
100
  File.open("last_run", "r") do |fail_list|