bozo-scripts 0.1.11 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ require 'fileutils'
2
+
3
+ module Bozo::Publishers
4
+
5
+ # Publisher that pushes package to nuget
6
+ class Nuget
7
+
8
+ def server(server)
9
+ @server = server
10
+ end
11
+
12
+ def api_key(api_key)
13
+ @api_key = api_key
14
+ end
15
+
16
+ def execute
17
+ raise Bozo::ConfigurationError.new 'You must specify a nuget server address' if @server.empty?
18
+ raise Bozo::ConfigurationError.new 'You must specify a nuget api key' if @api_key.empty?
19
+
20
+ Dir[File.join('dist', 'nuget', '**', '*')].each do |source_file|
21
+ push File.expand_path(source_file)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def push(source_file)
28
+ args = []
29
+ args << File.expand_path(File.join('build', 'tools', 'nuget', 'NuGet.exe'))
30
+ args << "push"
31
+ args << "\"#{source_file}\""
32
+ args << "\"#{@api_key}\""
33
+ args << "-s #{@server}"
34
+ execute_command :nuget, args
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -1,18 +1,18 @@
1
- module Bozo::Publishers
2
-
3
- # Publisher that publishes gem files to rubygems.org
4
- class Rubygems
5
-
6
- def execute
7
- Dir['dist/gem/*.gem'].each { |gem| push gem }
8
- end
9
-
10
- private
11
-
12
- def push(gem)
13
- execute_command :rubygems, ['gem', 'push', gem]
14
- end
15
-
16
- end
17
-
1
+ module Bozo::Publishers
2
+
3
+ # Publisher that publishes gem files to rubygems.org
4
+ class Rubygems
5
+
6
+ def execute
7
+ Dir['dist/gem/*.gem'].each { |gem| push gem }
8
+ end
9
+
10
+ private
11
+
12
+ def push(gem)
13
+ execute_command :rubygems, ['gem', 'push', gem]
14
+ end
15
+
16
+ end
17
+
18
18
  end
@@ -1,158 +1,158 @@
1
- require 'nokogiri'
2
-
3
- module Bozo::TestRunners
4
-
5
- # Adds a code coverage test runner using dotCover
6
- #
7
- # The default configuration looks for dotCover in the ProgramFiles(x86) path
8
- #
9
- # Test runners can be defined for dotCover to run against. Each runner
10
- # produces a separate dotcover output
11
- class DotCover
12
- def self.default_path
13
- if ENV['teamcity.dotCover.home'].nil?
14
- if ENV['ProgramFiles(x86)'].nil?
15
- program_files_path = ENV['ProgramFiles']
16
- else
17
- program_files_path = ENV['ProgramFiles(x86)']
18
- end
19
-
20
- File.join(program_files_path, 'JetBrains', 'dotCover', 'v1.2', 'Bin', 'dotcover.exe')
21
- else
22
- File.join(ENV['teamcity.dotCover.home'], 'dotcover.exe')
23
- end
24
- end
25
-
26
- def initialize
27
- @@defaults = {
28
- :path => DotCover.default_path,
29
- :required => true
30
- }
31
-
32
- @config = {}
33
- @runners = []
34
- end
35
-
36
- # Returns whether dotcover is installed at the configured path
37
- def dotcover_installed?
38
- path = configuration[:path]
39
-
40
- return false if path.nil?
41
-
42
- File.exist? path
43
- end
44
-
45
- # Adds a test runner
46
- #
47
- # @param [Symbol] runner
48
- # A test runner to wrap with dotcover
49
- def runner(runner, &block)
50
- add_instance runner, block
51
- end
52
-
53
- # Specifies whether covering with dotcover is required
54
- #
55
- # If it is not required, and dotcover cannot be found, then test runners
56
- # are executed without coverage. If dotcover is required but cannot be
57
- # found then an error will occur.
58
- #
59
- # @param [boolean] required
60
- # Whether dotCover coverage is required
61
- def required?(required = nil)
62
- @config[:required] = required unless required.nil?
63
-
64
- @config[:required]
65
- end
66
-
67
- def execute
68
- if required? or dotcover_installed?
69
- @runners.each {|runner| execute_with_coverage runner}
70
- else
71
- @runners.each {|runner| execute_without_coverage(runner)}
72
- end
73
- end
74
-
75
- private
76
-
77
- # Resolves the named class within the given namespace and then created an
78
- # instance of the class before adding it to the given collection and
79
- # yielding it to the configuration block when one is provided.
80
- #
81
- # @param [Symbol] type
82
- # The name of the step executor.
83
- # @param [Proc] block
84
- # Optional block to refine the configuration of the step executor.
85
- def add_instance(type, block)
86
- instance = Bozo::TestRunners.const_get(to_class_name(type)).new
87
- instance.extend Bozo::Runner
88
- @runners << instance
89
- block.call instance if block
90
- end
91
-
92
- # Converts a symbol into a Pascal Case class name.
93
- #
94
- # eg. `:single` => `"Single"`, `:two_words` => `"TwoWords"`.
95
- #
96
- # @param [Symbol] type
97
- # The name of a step executor.
98
- def to_class_name(type)
99
- type.to_s.split('_').map{|word| word.capitalize}.join
100
- end
101
-
102
- def execute_without_coverage(runner)
103
- log_debug 'Running ' + runner.class.to_s + ' without coverage'
104
- runner.execute
105
- end
106
-
107
- def execute_with_coverage(runner)
108
- if required? & !dotcover_installed?
109
- log_fatal "Attempting to run with coverage but dotcover could not be found at #{configuration[:path]}"
110
- end
111
-
112
- log_debug "Running #{runner.class} with coverage"
113
-
114
- config = configuration
115
- dotcover_path = config[:path]
116
- coverage_path = generate_coverage_file runner
117
-
118
- args = []
119
- args << '"' + dotcover_path + '"'
120
- args << "analyse #{coverage_path}"
121
-
122
- log_debug 'Running dotcover from "' + dotcover_path + '"'
123
- execute_command :dot_cover, args
124
- end
125
-
126
- def generate_coverage_file(runner)
127
- output_file = File.expand_path(File.join('temp', 'dotcover', "#{Time.now.to_i}-dotcover-report.xml"))
128
-
129
- runner_args = runner.runner_args
130
- runner_args.flatten!
131
-
132
- builder = Nokogiri::XML::Builder.new do |doc|
133
- doc.AnalyseParams do
134
- doc.Executable runner.runner_path.gsub(/\//, '\\')
135
- doc.Arguments runner_args.join(' ')
136
- doc.WorkingDir File.expand_path(File.join('temp', 'dotcover'))
137
- doc.Output output_file
138
- end
139
- end
140
-
141
- coverage_path = File.expand_path(File.join('temp', 'dotcover', "coverage.xml"))
142
- FileUtils.mkdir_p File.dirname(coverage_path)
143
- File.open(coverage_path, 'w+') {|f| f.write(builder.to_xml)}
144
-
145
- coverage_path
146
- end
147
-
148
- def configuration
149
- config_with_defaults
150
- end
151
-
152
- def config_with_defaults
153
- @@defaults.merge @config
154
- end
155
-
156
- end
157
-
1
+ require 'nokogiri'
2
+
3
+ module Bozo::TestRunners
4
+
5
+ # Adds a code coverage test runner using dotCover
6
+ #
7
+ # The default configuration looks for dotCover in the ProgramFiles(x86) path
8
+ #
9
+ # Test runners can be defined for dotCover to run against. Each runner
10
+ # produces a separate dotcover output
11
+ class DotCover
12
+ def self.default_path
13
+ if ENV['teamcity.dotCover.home'].nil?
14
+ if ENV['ProgramFiles(x86)'].nil?
15
+ program_files_path = ENV['ProgramFiles']
16
+ else
17
+ program_files_path = ENV['ProgramFiles(x86)']
18
+ end
19
+
20
+ File.join(program_files_path, 'JetBrains', 'dotCover', 'v1.2', 'Bin', 'dotcover.exe')
21
+ else
22
+ File.join(ENV['teamcity.dotCover.home'], 'dotcover.exe')
23
+ end
24
+ end
25
+
26
+ def initialize
27
+ @@defaults = {
28
+ :path => DotCover.default_path,
29
+ :required => true
30
+ }
31
+
32
+ @config = {}
33
+ @runners = []
34
+ end
35
+
36
+ # Returns whether dotcover is installed at the configured path
37
+ def dotcover_installed?
38
+ path = configuration[:path]
39
+
40
+ return false if path.nil?
41
+
42
+ File.exist? path
43
+ end
44
+
45
+ # Adds a test runner
46
+ #
47
+ # @param [Symbol] runner
48
+ # A test runner to wrap with dotcover
49
+ def runner(runner, &block)
50
+ add_instance runner, block
51
+ end
52
+
53
+ # Specifies whether covering with dotcover is required
54
+ #
55
+ # If it is not required, and dotcover cannot be found, then test runners
56
+ # are executed without coverage. If dotcover is required but cannot be
57
+ # found then an error will occur.
58
+ #
59
+ # @param [boolean] required
60
+ # Whether dotCover coverage is required
61
+ def required?(required = nil)
62
+ @config[:required] = required unless required.nil?
63
+
64
+ @config[:required]
65
+ end
66
+
67
+ def execute
68
+ if required? or dotcover_installed?
69
+ @runners.each {|runner| execute_with_coverage runner}
70
+ else
71
+ @runners.each {|runner| execute_without_coverage(runner)}
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ # Resolves the named class within the given namespace and then created an
78
+ # instance of the class before adding it to the given collection and
79
+ # yielding it to the configuration block when one is provided.
80
+ #
81
+ # @param [Symbol] type
82
+ # The name of the step executor.
83
+ # @param [Proc] block
84
+ # Optional block to refine the configuration of the step executor.
85
+ def add_instance(type, block)
86
+ instance = Bozo::TestRunners.const_get(to_class_name(type)).new
87
+ instance.extend Bozo::Runner
88
+ @runners << instance
89
+ block.call instance if block
90
+ end
91
+
92
+ # Converts a symbol into a Pascal Case class name.
93
+ #
94
+ # eg. `:single` => `"Single"`, `:two_words` => `"TwoWords"`.
95
+ #
96
+ # @param [Symbol] type
97
+ # The name of a step executor.
98
+ def to_class_name(type)
99
+ type.to_s.split('_').map{|word| word.capitalize}.join
100
+ end
101
+
102
+ def execute_without_coverage(runner)
103
+ log_debug 'Running ' + runner.class.to_s + ' without coverage'
104
+ runner.execute
105
+ end
106
+
107
+ def execute_with_coverage(runner)
108
+ if required? & !dotcover_installed?
109
+ log_fatal "Attempting to run with coverage but dotcover could not be found at #{configuration[:path]}"
110
+ end
111
+
112
+ log_debug "Running #{runner.class} with coverage"
113
+
114
+ config = configuration
115
+ dotcover_path = config[:path]
116
+ coverage_path = generate_coverage_file runner
117
+
118
+ args = []
119
+ args << '"' + dotcover_path + '"'
120
+ args << "analyse #{coverage_path}"
121
+
122
+ log_debug 'Running dotcover from "' + dotcover_path + '"'
123
+ execute_command :dot_cover, args
124
+ end
125
+
126
+ def generate_coverage_file(runner)
127
+ output_file = File.expand_path(File.join('temp', 'dotcover', "#{Time.now.to_i}-dotcover-report.xml"))
128
+
129
+ runner_args = runner.runner_args
130
+ runner_args.flatten!
131
+
132
+ builder = Nokogiri::XML::Builder.new do |doc|
133
+ doc.AnalyseParams do
134
+ doc.Executable runner.runner_path.gsub(/\//, '\\')
135
+ doc.Arguments runner_args.join(' ')
136
+ doc.WorkingDir File.expand_path(File.join('temp', 'dotcover'))
137
+ doc.Output output_file
138
+ end
139
+ end
140
+
141
+ coverage_path = File.expand_path(File.join('temp', 'dotcover', "coverage.xml"))
142
+ FileUtils.mkdir_p File.dirname(coverage_path)
143
+ File.open(coverage_path, 'w+') {|f| f.write(builder.to_xml)}
144
+
145
+ coverage_path
146
+ end
147
+
148
+ def configuration
149
+ config_with_defaults
150
+ end
151
+
152
+ def config_with_defaults
153
+ @@defaults.merge @config
154
+ end
155
+
156
+ end
157
+
158
158
  end
@@ -1,131 +1,131 @@
1
- module Bozo::TestRunners
2
-
3
- # A TestRunner for NUnit
4
- # By default the x64 runner is used. If you want to use a different
5
- # platform runner then set the platform, e.g. 'x86'.
6
- #
7
- # == Dotcover integration
8
- # To enable integration with the dotcover test runner the following
9
- # interface needs to be used
10
- #
11
- # runner_path # should return the path to the runners executable
12
- # runner_args # should return the arguments to be passed to use
13
- class Nunit
14
-
15
- def initialize
16
- @projects = []
17
- @include = []
18
- @exclude = []
19
- end
20
-
21
- def destination(destination)
22
- @destination = destination
23
- end
24
-
25
- def platform(platform)
26
- @platform = platform
27
- end
28
-
29
- def project(path)
30
- @projects << path
31
- end
32
-
33
- def report_path(path)
34
- @report_path = path
35
- end
36
-
37
- def coverage(coverage)
38
- @coverage = coverage
39
- end
40
-
41
- def include(include)
42
- cannot_define_both_include_and_exclude_categories if @exclude.any?
43
- @include << include
44
- end
45
-
46
- def exclude(exclude)
47
- cannot_define_both_include_and_exclude_categories if @include.any?
48
- @exclude << exclude
49
- end
50
-
51
- def to_s
52
- "Run tests with nunit against projects #{@projects}"
53
- end
54
-
55
- # Returns the path to the runner's executable.
56
- #
57
- # @returns [String]
58
- def runner_path
59
- exe_name = "nunit-console.exe"
60
-
61
- if defined? @platform
62
- log_debug "Looking for runner with #@platform platform"
63
- exe_name = "nunit-console-#@platform.exe"
64
- end
65
-
66
- nunit_runners = expand_and_glob('packages', 'NUnit*', 'tools', exe_name)
67
- raise nunit_runner_not_found if nunit_runners.empty?
68
- raise multiple_runners_found if nunit_runners.size > 1
69
-
70
- nunit_runner = nunit_runners.first
71
-
72
- log_debug "Found runner at #{nunit_runner}"
73
-
74
- nunit_runner
75
- end
76
-
77
- # Returns the arguments required for the runner's executable.
78
- #
79
- # @returns [Array]
80
- def runner_args
81
- args = []
82
-
83
- @projects.each do |project|
84
- expand_and_glob('temp', 'msbuild', project, '**', "#{project}.dll").each do |test_dll|
85
- args << "\"#{test_dll}\""
86
- end
87
- end
88
- args << '/nologo'
89
-
90
- report_path = @report_path
91
- report_path = expand_path('temp', 'nunit', "#{Time.now.to_i}-nunit-report.xml") unless report_path
92
-
93
- # Ensure the directory is there because NUnit won't make it
94
- FileUtils.mkdir_p File.dirname(report_path)
95
-
96
- args << "/xml:\"#{report_path}\""
97
- args << "/include:#{@include.join(',')}" if @include.any?
98
- args << "/exclude:#{@exclude.join(',')}" if @exclude.any?
99
-
100
- args
101
- end
102
-
103
- def execute
104
- execute_command :nunit, [runner_path] << runner_args
105
- end
106
-
107
- private
108
-
109
- def nunit_runner_not_found
110
- Bozo::ConfigurationError.new 'No NUnit runners found. You must install one via nuget.'
111
- end
112
-
113
- def multiple_runners_found
114
- Bozo::ConfigurationError.new 'Multiple NUnit runners found. There should only be one.'
115
- end
116
-
117
- def expand_path(*args)
118
- File.expand_path(File.join(args))
119
- end
120
-
121
- def expand_and_glob(*args)
122
- Dir[expand_path(*args)]
123
- end
124
-
125
- def cannot_define_both_include_and_exclude_categories
126
- raise Bozo::ConfigurationError.new 'Both include and exclude categories defined. You cannot specify both for nunit.'
127
- end
128
-
129
- end
130
-
1
+ module Bozo::TestRunners
2
+
3
+ # A TestRunner for NUnit
4
+ # By default the x64 runner is used. If you want to use a different
5
+ # platform runner then set the platform, e.g. 'x86'.
6
+ #
7
+ # == Dotcover integration
8
+ # To enable integration with the dotcover test runner the following
9
+ # interface needs to be used
10
+ #
11
+ # runner_path # should return the path to the runners executable
12
+ # runner_args # should return the arguments to be passed to use
13
+ class Nunit
14
+
15
+ def initialize
16
+ @projects = []
17
+ @include = []
18
+ @exclude = []
19
+ end
20
+
21
+ def destination(destination)
22
+ @destination = destination
23
+ end
24
+
25
+ def platform(platform)
26
+ @platform = platform
27
+ end
28
+
29
+ def project(path)
30
+ @projects << path
31
+ end
32
+
33
+ def report_path(path)
34
+ @report_path = path
35
+ end
36
+
37
+ def coverage(coverage)
38
+ @coverage = coverage
39
+ end
40
+
41
+ def include(include)
42
+ cannot_define_both_include_and_exclude_categories if @exclude.any?
43
+ @include << include
44
+ end
45
+
46
+ def exclude(exclude)
47
+ cannot_define_both_include_and_exclude_categories if @include.any?
48
+ @exclude << exclude
49
+ end
50
+
51
+ def to_s
52
+ "Run tests with nunit against projects #{@projects}"
53
+ end
54
+
55
+ # Returns the path to the runner's executable.
56
+ #
57
+ # @returns [String]
58
+ def runner_path
59
+ exe_name = "nunit-console.exe"
60
+
61
+ if defined? @platform
62
+ log_debug "Looking for runner with #@platform platform"
63
+ exe_name = "nunit-console-#@platform.exe"
64
+ end
65
+
66
+ nunit_runners = expand_and_glob('packages', 'NUnit*', 'tools', exe_name)
67
+ raise nunit_runner_not_found if nunit_runners.empty?
68
+ raise multiple_runners_found if nunit_runners.size > 1
69
+
70
+ nunit_runner = nunit_runners.first
71
+
72
+ log_debug "Found runner at #{nunit_runner}"
73
+
74
+ nunit_runner
75
+ end
76
+
77
+ # Returns the arguments required for the runner's executable.
78
+ #
79
+ # @returns [Array]
80
+ def runner_args
81
+ args = []
82
+
83
+ @projects.each do |project|
84
+ expand_and_glob('temp', 'msbuild', project, '**', "#{project}.dll").each do |test_dll|
85
+ args << "\"#{test_dll}\""
86
+ end
87
+ end
88
+ args << '/nologo'
89
+
90
+ report_path = @report_path
91
+ report_path = expand_path('temp', 'nunit', "#{Time.now.to_i}-nunit-report.xml") unless report_path
92
+
93
+ # Ensure the directory is there because NUnit won't make it
94
+ FileUtils.mkdir_p File.dirname(report_path)
95
+
96
+ args << "/xml:\"#{report_path}\""
97
+ args << "/include:#{@include.join(',')}" if @include.any?
98
+ args << "/exclude:#{@exclude.join(',')}" if @exclude.any?
99
+
100
+ args
101
+ end
102
+
103
+ def execute
104
+ execute_command :nunit, [runner_path] << runner_args
105
+ end
106
+
107
+ private
108
+
109
+ def nunit_runner_not_found
110
+ Bozo::ConfigurationError.new 'No NUnit runners found. You must install one via nuget.'
111
+ end
112
+
113
+ def multiple_runners_found
114
+ Bozo::ConfigurationError.new 'Multiple NUnit runners found. There should only be one.'
115
+ end
116
+
117
+ def expand_path(*args)
118
+ File.expand_path(File.join(args))
119
+ end
120
+
121
+ def expand_and_glob(*args)
122
+ Dir[expand_path(*args)]
123
+ end
124
+
125
+ def cannot_define_both_include_and_exclude_categories
126
+ raise Bozo::ConfigurationError.new 'Both include and exclude categories defined. You cannot specify both for nunit.'
127
+ end
128
+
129
+ end
130
+
131
131
  end