request-log-analyzer 1.3.7 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +3 -3
- data/README.rdoc +1 -1
- data/bin/request-log-analyzer +17 -14
- data/lib/cli/command_line_arguments.rb +51 -51
- data/lib/cli/database_console.rb +3 -3
- data/lib/cli/database_console_init.rb +2 -2
- data/lib/cli/progressbar.rb +10 -10
- data/lib/cli/tools.rb +3 -3
- data/lib/request_log_analyzer.rb +4 -4
- data/lib/request_log_analyzer/aggregator.rb +10 -10
- data/lib/request_log_analyzer/aggregator/database_inserter.rb +9 -9
- data/lib/request_log_analyzer/aggregator/echo.rb +14 -9
- data/lib/request_log_analyzer/aggregator/summarizer.rb +26 -26
- data/lib/request_log_analyzer/controller.rb +153 -69
- data/lib/request_log_analyzer/database.rb +13 -13
- data/lib/request_log_analyzer/database/base.rb +17 -17
- data/lib/request_log_analyzer/database/connection.rb +3 -3
- data/lib/request_log_analyzer/database/request.rb +2 -2
- data/lib/request_log_analyzer/database/source.rb +1 -1
- data/lib/request_log_analyzer/file_format.rb +15 -15
- data/lib/request_log_analyzer/file_format/amazon_s3.rb +16 -16
- data/lib/request_log_analyzer/file_format/apache.rb +20 -19
- data/lib/request_log_analyzer/file_format/merb.rb +12 -12
- data/lib/request_log_analyzer/file_format/rack.rb +4 -4
- data/lib/request_log_analyzer/file_format/rails.rb +146 -70
- data/lib/request_log_analyzer/file_format/rails_development.rb +4 -49
- data/lib/request_log_analyzer/filter.rb +6 -6
- data/lib/request_log_analyzer/filter/anonymize.rb +6 -6
- data/lib/request_log_analyzer/filter/field.rb +9 -9
- data/lib/request_log_analyzer/filter/timespan.rb +12 -10
- data/lib/request_log_analyzer/line_definition.rb +15 -14
- data/lib/request_log_analyzer/log_processor.rb +22 -22
- data/lib/request_log_analyzer/mailer.rb +15 -9
- data/lib/request_log_analyzer/output.rb +53 -12
- data/lib/request_log_analyzer/output/fixed_width.rb +40 -41
- data/lib/request_log_analyzer/output/html.rb +20 -20
- data/lib/request_log_analyzer/request.rb +35 -36
- data/lib/request_log_analyzer/source.rb +7 -7
- data/lib/request_log_analyzer/source/database_loader.rb +7 -7
- data/lib/request_log_analyzer/source/log_parser.rb +48 -43
- data/lib/request_log_analyzer/tracker.rb +128 -14
- data/lib/request_log_analyzer/tracker/duration.rb +39 -132
- data/lib/request_log_analyzer/tracker/frequency.rb +31 -32
- data/lib/request_log_analyzer/tracker/hourly_spread.rb +20 -19
- data/lib/request_log_analyzer/tracker/timespan.rb +17 -17
- data/lib/request_log_analyzer/tracker/traffic.rb +36 -116
- data/request-log-analyzer.gemspec +19 -15
- data/spec/fixtures/rails_22.log +1 -1
- data/spec/integration/command_line_usage_spec.rb +1 -1
- data/spec/lib/helpers.rb +7 -7
- data/spec/lib/macros.rb +3 -3
- data/spec/lib/matchers.rb +41 -27
- data/spec/lib/mocks.rb +15 -14
- data/spec/lib/testing_format.rb +9 -9
- data/spec/spec_helper.rb +6 -6
- data/spec/unit/aggregator/database_inserter_spec.rb +13 -13
- data/spec/unit/aggregator/summarizer_spec.rb +4 -4
- data/spec/unit/controller/controller_spec.rb +2 -2
- data/spec/unit/controller/log_processor_spec.rb +1 -1
- data/spec/unit/database/base_class_spec.rb +19 -19
- data/spec/unit/database/connection_spec.rb +3 -3
- data/spec/unit/database/database_spec.rb +25 -25
- data/spec/unit/file_format/amazon_s3_format_spec.rb +5 -5
- data/spec/unit/file_format/apache_format_spec.rb +13 -13
- data/spec/unit/file_format/file_format_api_spec.rb +13 -13
- data/spec/unit/file_format/line_definition_spec.rb +24 -17
- data/spec/unit/file_format/merb_format_spec.rb +41 -45
- data/spec/unit/file_format/rails_format_spec.rb +157 -117
- data/spec/unit/filter/anonymize_filter_spec.rb +2 -2
- data/spec/unit/filter/field_filter_spec.rb +13 -13
- data/spec/unit/filter/filter_spec.rb +1 -1
- data/spec/unit/filter/timespan_filter_spec.rb +15 -15
- data/spec/unit/mailer_spec.rb +30 -0
- data/spec/unit/{source/request_spec.rb → request_spec.rb} +30 -30
- data/spec/unit/source/log_parser_spec.rb +27 -27
- data/spec/unit/tracker/duration_tracker_spec.rb +115 -78
- data/spec/unit/tracker/frequency_tracker_spec.rb +74 -63
- data/spec/unit/tracker/hourly_spread_spec.rb +28 -20
- data/spec/unit/tracker/timespan_tracker_spec.rb +25 -13
- data/spec/unit/tracker/tracker_api_spec.rb +13 -13
- data/spec/unit/tracker/traffic_tracker_spec.rb +81 -79
- data/tasks/github-gem.rake +125 -75
- data/tasks/request_log_analyzer.rake +2 -2
- metadata +8 -6
@@ -3,14 +3,14 @@ require File.dirname(__FILE__) + '/../../spec_helper'
|
|
3
3
|
describe RequestLogAnalyzer::Tracker::Base do
|
4
4
|
|
5
5
|
describe 'API' do
|
6
|
-
|
6
|
+
|
7
7
|
before(:each) do
|
8
8
|
@tracker = Class.new(RequestLogAnalyzer::Tracker::Base).new
|
9
9
|
|
10
10
|
@summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(mock_source)
|
11
11
|
@summarizer.trackers << @tracker
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "should receive :prepare when the summarizer is preparing" do
|
15
15
|
@tracker.should_receive(:prepare).once
|
16
16
|
@summarizer.prepare
|
@@ -33,8 +33,8 @@ describe RequestLogAnalyzer::Tracker::Base do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should receive :report when the summary report is being built" do
|
36
|
-
@tracker.should_receive(:report).with(anything).once
|
37
|
-
@summarizer.report(mock_output)
|
36
|
+
@tracker.should_receive(:report).with(anything).once
|
37
|
+
@summarizer.report(mock_output)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "should receieve :finalize when the summarizer is finalizing" do
|
@@ -42,27 +42,27 @@ describe RequestLogAnalyzer::Tracker::Base do
|
|
42
42
|
@summarizer.finalize
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
describe '#should_update?' do
|
47
47
|
before(:each) do
|
48
48
|
@tracker_class = Class.new(RequestLogAnalyzer::Tracker::Base)
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it "should return true by default, when no checks are installed" do
|
52
52
|
tracker = @tracker_class.new
|
53
53
|
tracker.should_update?(testing_format.request).should be_true
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it "should return false if the line type is not in the request" do
|
57
57
|
tracker = @tracker_class.new(:line_type => :not_there)
|
58
58
|
tracker.should_update?(request(:line_type => :different)).should be_false
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
it "should return true if the line type is in the request" do
|
62
62
|
tracker = @tracker_class.new(:line_type => :there)
|
63
63
|
tracker.should_update?(request(:line_type => :there)).should be_true
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
it "should return true if a field name is given to :if and it is in the request" do
|
67
67
|
tracker = @tracker_class.new(:if => :field)
|
68
68
|
tracker.should_update?(request(:field => 'anything')).should be_true
|
@@ -103,18 +103,18 @@ describe RequestLogAnalyzer::Tracker::Base do
|
|
103
103
|
tracker.should_update?(request(:line_type => :present, :field => 'anything')).should be_true
|
104
104
|
end
|
105
105
|
|
106
|
-
|
106
|
+
|
107
107
|
end
|
108
|
-
|
108
|
+
|
109
109
|
describe '#to_yaml_object' do
|
110
|
-
|
110
|
+
|
111
111
|
before(:each) do
|
112
112
|
@tracker = Class.new(RequestLogAnalyzer::Tracker::Base).new
|
113
113
|
|
114
114
|
@summarizer = RequestLogAnalyzer::Aggregator::Summarizer.new(mock_source)
|
115
115
|
@summarizer.trackers << @tracker
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
it "should receive :to_yaml object when finalizing" do
|
119
119
|
@summarizer.options[:dump] = temp_output_file(:dump)
|
120
120
|
@tracker.should_receive(:to_yaml_object).once
|
@@ -1,105 +1,107 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
2
|
|
3
3
|
describe RequestLogAnalyzer::Tracker::Traffic do
|
4
|
-
|
4
|
+
|
5
|
+
context 'using a field-based category' do
|
6
|
+
before(:each) do
|
7
|
+
@tracker = RequestLogAnalyzer::Tracker::Traffic.new(:traffic => :traffic, :category => :category)
|
8
|
+
@tracker.prepare
|
9
|
+
|
10
|
+
@tracker.update(request(:category => 'a', :traffic => 1))
|
11
|
+
@tracker.update(request(:category => 'b', :traffic => 2))
|
12
|
+
@tracker.update(request(:category => 'b', :traffic => 3))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should register a request in the right category using the category field" do
|
16
|
+
@tracker.categories.should include('a', 'b')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should register requests under the correct category" do
|
20
|
+
@tracker.hits('a').should == 1
|
21
|
+
@tracker.hits('b').should == 2
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'using a dynamic category' do
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
@categorizer = lambda { |request| request[:traffic] < 2 ? 'few' : 'lots' }
|
29
|
+
@tracker = RequestLogAnalyzer::Tracker::Traffic.new(:traffic => :traffic, :category => @categorizer)
|
30
|
+
@tracker.prepare
|
31
|
+
|
32
|
+
@tracker.update(request(:category => 'a', :traffic => 1))
|
33
|
+
@tracker.update(request(:category => 'b', :traffic => 2))
|
34
|
+
@tracker.update(request(:category => 'b', :traffic => 3))
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should use the categorizer to determine the category" do
|
38
|
+
@tracker.categories.should include('few', 'lots')
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should register requests under the correct category using the categorizer" do
|
42
|
+
@tracker.hits('few').should == 1
|
43
|
+
@tracker.hits('lots').should == 2
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
5
47
|
describe '#update' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
@tracker.update(request(:category => 'b', :traffic => 3))
|
40
|
-
|
41
|
-
@tracker.average_traffic('a').should == 1.0
|
42
|
-
@tracker.average_traffic('b').should == 2.5
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should set min and max traffic correctly" do
|
46
|
-
@tracker.update(request(:category => 'a', :traffic => 1))
|
47
|
-
@tracker.update(request(:category => 'b', :traffic => 2))
|
48
|
-
@tracker.update(request(:category => 'b', :traffic => 3))
|
49
|
-
|
50
|
-
@tracker.min_traffic('b').should == 2
|
51
|
-
@tracker.max_traffic('b').should == 3
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'using a dynamic category' do
|
57
|
-
before(:each) do
|
58
|
-
@categorizer = Proc.new { |request| request[:traffic] < 2 ? 'few' : 'lots' }
|
59
|
-
@tracker = RequestLogAnalyzer::Tracker::Traffic.new(:traffic => :traffic, :category => @categorizer)
|
60
|
-
@tracker.prepare
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should use the categorizer to determine the right category" do
|
64
|
-
@tracker.update(request(:category => 'a', :traffic => 1))
|
65
|
-
@tracker.update(request(:category => 'b', :traffic => 2))
|
66
|
-
@tracker.update(request(:category => 'b', :traffic => 3))
|
67
|
-
|
68
|
-
@tracker.categories.should include('few', 'lots')
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should use the categorizer to aggregate the values correctly" do
|
72
|
-
@tracker.update(request(:category => 'a', :traffic => 1))
|
73
|
-
@tracker.update(request(:category => 'b', :traffic => 2))
|
74
|
-
@tracker.update(request(:category => 'b', :traffic => 3))
|
75
|
-
|
76
|
-
@tracker.max_traffic('few').should == 1
|
77
|
-
@tracker.min_traffic('lots').should == 2
|
78
|
-
end
|
48
|
+
|
49
|
+
before(:each) do
|
50
|
+
@tracker = RequestLogAnalyzer::Tracker::Traffic.new(:traffic => :traffic, :category => :category)
|
51
|
+
@tracker.prepare
|
52
|
+
|
53
|
+
@tracker.update(request(:category => 'a', :traffic => 2))
|
54
|
+
@tracker.update(request(:category => 'a', :traffic => 1))
|
55
|
+
@tracker.update(request(:category => 'a', :traffic => 3))
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should calculate the total traffic correctly" do
|
59
|
+
@tracker.sum('a').should == 6
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should calculate the traffic variance correctly" do
|
63
|
+
@tracker.variance('a').should == 1.0
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should calculate the traffic standard deviation correctly" do
|
67
|
+
@tracker.stddev('a').should == 1.0
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should calculate the average traffic correctly" do
|
71
|
+
@tracker.mean('a').should == 2.0
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should calculate the overall mean traffic correctly" do
|
75
|
+
@tracker.mean_overall.should == 2.0
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should set min and max traffic correctly" do
|
79
|
+
@tracker.min('a').should == 1
|
80
|
+
@tracker.max('a').should == 3
|
79
81
|
end
|
80
82
|
end
|
81
|
-
|
83
|
+
|
82
84
|
describe '#report' do
|
83
85
|
before(:each) do
|
84
86
|
@tracker = RequestLogAnalyzer::Tracker::Traffic.new(:category => :category, :traffic => :traffic)
|
85
87
|
@tracker.prepare
|
86
88
|
end
|
87
|
-
|
89
|
+
|
88
90
|
it "should generate a report without errors when one category is present" do
|
89
91
|
@tracker.update(request(:category => 'a', :traffic => 2))
|
90
92
|
@tracker.report(mock_output)
|
91
93
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
92
94
|
end
|
93
|
-
|
95
|
+
|
94
96
|
it "should generate a report without errors when no category is present" do
|
95
97
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
96
98
|
end
|
97
|
-
|
99
|
+
|
98
100
|
it "should generate a report without errors when multiple categories are present" do
|
99
101
|
@tracker.update(request(:category => 'a', :traffic => 2))
|
100
102
|
@tracker.update(request(:category => 'b', :traffic => 2))
|
101
103
|
lambda { @tracker.report(mock_output) }.should_not raise_error
|
102
104
|
end
|
103
|
-
|
105
|
+
|
104
106
|
end
|
105
107
|
end
|
data/tasks/github-gem.rake
CHANGED
@@ -5,26 +5,30 @@ require 'date'
|
|
5
5
|
require 'git'
|
6
6
|
|
7
7
|
module GithubGem
|
8
|
-
|
8
|
+
|
9
|
+
# Detects the gemspc file of this project using heuristics.
|
9
10
|
def self.detect_gemspec_file
|
10
11
|
FileList['*.gemspec'].first
|
11
12
|
end
|
12
|
-
|
13
|
+
|
14
|
+
# Detects the main include file of this project using heuristics
|
13
15
|
def self.detect_main_include
|
14
16
|
if detect_gemspec_file =~ /^(\.*)\.gemspec$/ && File.exist?("lib/#{$1}.rb")
|
15
17
|
"lib/#{$1}.rb"
|
16
18
|
elsif FileList['lib/*.rb'].length == 1
|
17
19
|
FileList['lib/*.rb'].first
|
18
20
|
else
|
19
|
-
|
21
|
+
nil
|
20
22
|
end
|
21
23
|
end
|
22
|
-
|
24
|
+
|
23
25
|
class RakeTasks
|
24
|
-
|
26
|
+
|
25
27
|
attr_reader :gemspec, :modified_files, :git
|
26
28
|
attr_accessor :gemspec_file, :task_namespace, :main_include, :root_dir, :spec_pattern, :test_pattern, :remote, :remote_branch, :local_branch
|
27
|
-
|
29
|
+
|
30
|
+
# Initializes the settings, yields itself for configuration
|
31
|
+
# and defines the rake tasks based on the gemspec file.
|
28
32
|
def initialize(task_namespace = :gem)
|
29
33
|
@gemspec_file = GithubGem.detect_gemspec_file
|
30
34
|
@task_namespace = task_namespace
|
@@ -36,17 +40,17 @@ module GithubGem
|
|
36
40
|
@local_branch = 'master'
|
37
41
|
@remote = 'origin'
|
38
42
|
@remote_branch = 'master'
|
39
|
-
|
40
|
-
|
43
|
+
|
41
44
|
yield(self) if block_given?
|
42
45
|
|
43
|
-
@git = Git.open(@root_dir)
|
44
|
-
load_gemspec!
|
46
|
+
@git = Git.open(@root_dir)
|
47
|
+
load_gemspec!
|
45
48
|
define_tasks!
|
46
49
|
end
|
47
|
-
|
50
|
+
|
48
51
|
protected
|
49
|
-
|
52
|
+
|
53
|
+
# Define Unit test tasks
|
50
54
|
def define_test_tasks!
|
51
55
|
require 'rake/testtask'
|
52
56
|
|
@@ -57,11 +61,12 @@ module GithubGem
|
|
57
61
|
t.libs << 'test'
|
58
62
|
end
|
59
63
|
end
|
60
|
-
|
64
|
+
|
61
65
|
desc "Run all unit tests for #{gemspec.name}"
|
62
66
|
task(:test => ['test:basic'])
|
63
67
|
end
|
64
|
-
|
68
|
+
|
69
|
+
# Defines RSpec tasks
|
65
70
|
def define_rspec_tasks!
|
66
71
|
require 'spec/rake/spectask'
|
67
72
|
|
@@ -70,204 +75,249 @@ module GithubGem
|
|
70
75
|
Spec::Rake::SpecTask.new(:basic) do |t|
|
71
76
|
t.spec_files = FileList[spec_pattern]
|
72
77
|
end
|
73
|
-
|
78
|
+
|
74
79
|
desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
|
75
80
|
Spec::Rake::SpecTask.new(:specdoc) do |t|
|
76
81
|
t.spec_files = FileList[spec_pattern]
|
77
82
|
t.spec_opts << '--format' << 'specdoc' << '--color'
|
78
83
|
end
|
79
|
-
|
84
|
+
|
80
85
|
desc "Run RCov on specs for #{gemspec.name}"
|
81
86
|
Spec::Rake::SpecTask.new(:rcov) do |t|
|
82
87
|
t.spec_files = FileList[spec_pattern]
|
83
88
|
t.rcov = true
|
84
|
-
t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
|
85
|
-
end
|
89
|
+
t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
|
90
|
+
end
|
86
91
|
end
|
87
|
-
|
92
|
+
|
88
93
|
desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
|
89
|
-
task(:spec => ['spec:specdoc'])
|
94
|
+
task(:spec => ['spec:specdoc'])
|
90
95
|
end
|
91
|
-
|
96
|
+
|
92
97
|
# Defines the rake tasks
|
93
98
|
def define_tasks!
|
94
|
-
|
99
|
+
|
95
100
|
define_test_tasks! if has_tests?
|
96
101
|
define_rspec_tasks! if has_specs?
|
97
|
-
|
102
|
+
|
98
103
|
namespace(@task_namespace) do
|
99
104
|
desc "Updates the filelist in the gemspec file"
|
100
|
-
task(:manifest) { manifest_task }
|
101
|
-
|
105
|
+
task(:manifest) { manifest_task }
|
106
|
+
|
102
107
|
desc "Builds the .gem package"
|
103
108
|
task(:build => :manifest) { build_task }
|
104
109
|
|
105
110
|
desc "Sets the version of the gem in the gemspec"
|
106
111
|
task(:set_version => [:check_version, :check_current_branch]) { version_task }
|
107
|
-
task(:check_version => :fetch_origin) { check_version_task }
|
108
|
-
|
112
|
+
task(:check_version => :fetch_origin) { check_version_task }
|
113
|
+
|
109
114
|
task(:fetch_origin) { fetch_origin_task }
|
110
|
-
task(:check_current_branch) { check_current_branch_task }
|
115
|
+
task(:check_current_branch) { check_current_branch_task }
|
111
116
|
task(:check_clean_status) { check_clean_status_task }
|
112
117
|
task(:check_not_diverged => :fetch_origin) { check_not_diverged_task }
|
113
|
-
|
118
|
+
|
114
119
|
checks = [:check_current_branch, :check_clean_status, :check_not_diverged, :check_version]
|
115
120
|
checks.unshift('spec:basic') if has_specs?
|
116
121
|
checks.unshift('test:basic') if has_tests?
|
117
122
|
checks.push << [:check_rubyforge] if gemspec.rubyforge_project
|
118
|
-
|
123
|
+
|
119
124
|
desc "Perform all checks that would occur before a release"
|
120
|
-
task(:release_checks => checks)
|
125
|
+
task(:release_checks => checks)
|
121
126
|
|
122
127
|
release_tasks = [:release_checks, :set_version, :build, :github_release]
|
123
128
|
release_tasks << [:rubyforge_release] if gemspec.rubyforge_project
|
124
|
-
|
129
|
+
|
125
130
|
desc "Release a new verison of the gem"
|
126
131
|
task(:release => release_tasks) { release_task }
|
127
|
-
|
132
|
+
|
128
133
|
task(:check_rubyforge) { check_rubyforge_task }
|
129
134
|
task(:rubyforge_release) { rubyforge_release_task }
|
130
135
|
task(:github_release => [:commit_modified_files, :tag_version]) { github_release_task }
|
131
136
|
task(:tag_version) { tag_version_task }
|
132
137
|
task(:commit_modified_files) { commit_modified_files_task }
|
138
|
+
|
139
|
+
desc "Updates the gem release tasks with the latest version on Github"
|
140
|
+
task(:update_tasks) { update_tasks_task }
|
133
141
|
end
|
134
142
|
end
|
135
|
-
|
143
|
+
|
144
|
+
# Updates the files list and test_files list in the gemspec file using the list of files
|
145
|
+
# in the repository and the spec/test file pattern.
|
136
146
|
def manifest_task
|
137
147
|
# Load all the gem's files using "git ls-files"
|
138
148
|
repository_files = git.ls_files.keys
|
139
149
|
test_files = Dir[test_pattern] + Dir[spec_pattern]
|
140
|
-
|
150
|
+
|
141
151
|
update_gemspec(:files, repository_files)
|
142
152
|
update_gemspec(:test_files, repository_files & test_files)
|
143
153
|
end
|
144
|
-
|
154
|
+
|
155
|
+
# Builds the gem
|
145
156
|
def build_task
|
146
157
|
sh "gem build -q #{gemspec_file}"
|
147
158
|
Dir.mkdir('pkg') unless File.exist?('pkg')
|
148
|
-
sh "mv #{gemspec.name}-#{gemspec.version}.gem pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
159
|
+
sh "mv #{gemspec.name}-#{gemspec.version}.gem pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
149
160
|
end
|
150
|
-
|
161
|
+
|
162
|
+
# Updates the version number in the gemspec file, the VERSION constant in the main
|
163
|
+
# include file and the contents of the VERSION file.
|
151
164
|
def version_task
|
152
165
|
update_gemspec(:version, ENV['VERSION']) if ENV['VERSION']
|
153
166
|
update_gemspec(:date, Date.today)
|
154
|
-
|
167
|
+
|
155
168
|
update_version_file(gemspec.version)
|
156
169
|
update_version_constant(gemspec.version)
|
157
170
|
end
|
158
|
-
|
171
|
+
|
159
172
|
def check_version_task
|
160
173
|
raise "#{ENV['VERSION']} is not a valid version number!" if ENV['VERSION'] && !Gem::Version.correct?(ENV['VERSION'])
|
161
174
|
proposed_version = Gem::Version.new(ENV['VERSION'] || gemspec.version)
|
162
175
|
# Loads the latest version number using the created tags
|
163
|
-
newest_version = git.tags.map { |tag| tag.name.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max
|
176
|
+
newest_version = git.tags.map { |tag| tag.name.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max
|
164
177
|
raise "This version (#{proposed_version}) is not higher than the highest tagged version (#{newest_version})" if newest_version && newest_version >= proposed_version
|
165
178
|
end
|
166
|
-
|
179
|
+
|
180
|
+
# Checks whether the current branch is not diverged from the remote branch
|
167
181
|
def check_not_diverged_task
|
168
|
-
raise "The current branch is diverged from the remote branch!" if git.log.between('HEAD', git.
|
182
|
+
raise "The current branch is diverged from the remote branch!" if git.log.between('HEAD', git.remote(remote).branch(remote_branch).gcommit).any?
|
169
183
|
end
|
170
|
-
|
184
|
+
|
185
|
+
# Checks whether the repository status ic clean
|
171
186
|
def check_clean_status_task
|
172
|
-
|
187
|
+
raise "The current working copy contains modifications" if git.status.changed.any?
|
173
188
|
end
|
174
|
-
|
189
|
+
|
190
|
+
# Checks whether the current branch is correct
|
175
191
|
def check_current_branch_task
|
176
192
|
raise "Currently not on #{local_branch} branch!" unless git.branch.name == local_branch.to_s
|
177
193
|
end
|
178
|
-
|
194
|
+
|
195
|
+
# Fetches the latest updates from Github
|
179
196
|
def fetch_origin_task
|
180
197
|
git.fetch('origin')
|
181
198
|
end
|
182
|
-
|
199
|
+
|
200
|
+
# Commits every file that has been changed by the release task.
|
183
201
|
def commit_modified_files_task
|
184
202
|
if modified_files.any?
|
185
203
|
modified_files.each { |file| git.add(file) }
|
186
204
|
git.commit("Released #{gemspec.name} gem version #{gemspec.version}")
|
187
205
|
end
|
188
206
|
end
|
189
|
-
|
207
|
+
|
208
|
+
# Adds a tag for the released version
|
190
209
|
def tag_version_task
|
191
210
|
git.add_tag("#{gemspec.name}-#{gemspec.version}")
|
192
211
|
end
|
193
|
-
|
212
|
+
|
213
|
+
# Pushes the changes and tag to github
|
194
214
|
def github_release_task
|
195
215
|
git.push(remote, remote_branch, true)
|
196
216
|
end
|
197
|
-
|
217
|
+
|
218
|
+
# Checks whether Rubyforge is configured properly
|
198
219
|
def check_rubyforge_task
|
199
|
-
|
220
|
+
# Login no longer necessary when using rubyforge 2.0.0 gem
|
221
|
+
# raise "Could not login on rubyforge!" unless `rubyforge login 2>&1`.strip.empty?
|
200
222
|
output = `rubyforge names`.split("\n")
|
201
223
|
raise "Rubyforge group not found!" unless output.any? { |line| %r[^groups\s*\:.*\b#{Regexp.quote(gemspec.rubyforge_project)}\b.*] =~ line }
|
202
|
-
raise "Rubyforge package not found!" unless output.any? { |line| %r[^packages\s*\:.*\b#{Regexp.quote(gemspec.name)}\b.*] =~ line }
|
224
|
+
raise "Rubyforge package not found!" unless output.any? { |line| %r[^packages\s*\:.*\b#{Regexp.quote(gemspec.name)}\b.*] =~ line }
|
203
225
|
end
|
204
|
-
|
226
|
+
|
227
|
+
# Task to release the .gem file toRubyforge.
|
205
228
|
def rubyforge_release_task
|
206
229
|
sh 'rubyforge', 'add_release', gemspec.rubyforge_project, gemspec.name, gemspec.version.to_s, "pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
207
230
|
end
|
208
|
-
|
231
|
+
|
232
|
+
# Gem release task.
|
233
|
+
# All work is done by the task's dependencies, so just display a release completed message.
|
209
234
|
def release_task
|
210
235
|
puts
|
211
236
|
puts '------------------------------------------------------------'
|
212
237
|
puts "Released #{gemspec.name} version #{gemspec.version}"
|
213
238
|
end
|
214
|
-
|
239
|
+
|
215
240
|
private
|
216
|
-
|
241
|
+
|
242
|
+
# Checks whether this project has any RSpec files
|
217
243
|
def has_specs?
|
218
244
|
FileList[spec_pattern].any?
|
219
245
|
end
|
220
|
-
|
246
|
+
|
247
|
+
# Checks whether this project has any unit test files
|
221
248
|
def has_tests?
|
222
249
|
FileList[test_pattern].any?
|
223
250
|
end
|
224
|
-
|
225
|
-
|
251
|
+
|
226
252
|
# Loads the gemspec file
|
227
253
|
def load_gemspec!
|
228
254
|
@gemspec = eval(File.read(@gemspec_file))
|
229
255
|
end
|
230
|
-
|
256
|
+
|
231
257
|
# Updates the VERSION file with the new version
|
232
258
|
def update_version_file(version)
|
233
259
|
if File.exists?('VERSION')
|
234
|
-
File.open('VERSION', 'w') { |f| f << version.to_s }
|
260
|
+
File.open('VERSION', 'w') { |f| f << version.to_s }
|
235
261
|
modified_files << 'VERSION'
|
236
262
|
end
|
237
263
|
end
|
238
|
-
|
264
|
+
|
239
265
|
# Updates the VERSION constant in the main include file if it exists
|
240
266
|
def update_version_constant(version)
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
267
|
+
if main_include && File.exist?(main_include)
|
268
|
+
file_contents = File.read(main_include)
|
269
|
+
if file_contents.sub!(/^(\s+VERSION\s*=\s*)[^\s].*$/) { $1 + version.to_s.inspect }
|
270
|
+
File.open(main_include, 'w') { |f| f << file_contents }
|
271
|
+
modified_files << main_include
|
272
|
+
end
|
273
|
+
end
|
246
274
|
end
|
247
|
-
|
275
|
+
|
248
276
|
# Updates an attribute of the gemspec file.
|
249
277
|
# This function will open the file, and search/replace the attribute using a regular expression.
|
250
278
|
def update_gemspec(attribute, new_value, literal = false)
|
251
|
-
|
279
|
+
|
252
280
|
unless literal
|
253
281
|
new_value = case new_value
|
254
282
|
when Array then "%w(#{new_value.join(' ')})"
|
255
283
|
when Hash, String then new_value.inspect
|
256
|
-
when Date then new_value.strftime('%Y-%m-%d').inspect
|
284
|
+
when Date then new_value.strftime('%Y-%m-%d').inspect
|
257
285
|
else raise "Cannot write value #{new_value.inspect} to gemspec file!"
|
258
286
|
end
|
259
287
|
end
|
260
|
-
|
288
|
+
|
261
289
|
spec = File.read(gemspec_file)
|
262
290
|
regexp = Regexp.new('^(\s+\w+\.' + Regexp.quote(attribute.to_s) + '\s*=\s*)[^\s].*$')
|
263
291
|
if spec.sub!(regexp) { $1 + new_value }
|
264
|
-
File.open(gemspec_file, 'w') { |f| f << spec }
|
292
|
+
File.open(gemspec_file, 'w') { |f| f << spec }
|
265
293
|
modified_files << gemspec_file
|
266
|
-
|
294
|
+
|
267
295
|
# Reload the gemspec so the changes are incorporated
|
268
296
|
load_gemspec!
|
269
297
|
end
|
270
298
|
end
|
271
|
-
|
299
|
+
|
300
|
+
# Updates the tasks file using the latest file found on Github
|
301
|
+
def update_tasks_task
|
302
|
+
require 'net/http'
|
303
|
+
|
304
|
+
server = 'github.com'
|
305
|
+
path = '/wvanbergen/github-gem/raw/master/tasks/github-gem.rake'
|
306
|
+
|
307
|
+
Net::HTTP.start(server) do |http|
|
308
|
+
response = http.get(path)
|
309
|
+
open(__FILE__, "w") { |file| file.write(response.body) }
|
310
|
+
end
|
311
|
+
|
312
|
+
relative_file = File.expand_path(__FILE__).sub(%r[^#{git.dir.path}/], '')
|
313
|
+
if git.status[relative_file] && git.status[relative_file].type == 'M'
|
314
|
+
git.add(relative_file)
|
315
|
+
git.commit("Updated to latest gem release management tasks.")
|
316
|
+
puts "Updated to latest version of gem release management tasks."
|
317
|
+
else
|
318
|
+
puts "Release managament tasks already are at the latest version."
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
272
322
|
end
|
273
323
|
end
|