fxcop 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/fxcop.rb ADDED
@@ -0,0 +1,135 @@
1
+ module BuildQuality
2
+ class FxCop
3
+ def initialize(shell_command = ShellCommand.new, parameters)
4
+ parameters[:fxcop_binary]
5
+ fxcop_binary = parameters[:fxcop_binary]
6
+ @fxcop_command = FxCopCommand.new(fxcop_binary,shell_command)
7
+ @fxcop_settings_adapter = FxCopSettingsAdapterFactory.new(@fxcop_command).create
8
+ end
9
+
10
+ def start(fxcop_settings = FxCopSettings.new)
11
+ @fxcop_settings_adapter.adapt(fxcop_settings)
12
+ @fxcop_command.execute
13
+ end
14
+ end
15
+
16
+ class FxCopSettings
17
+ attr_reader :assemblies, :output_file_name, :dictionary_file_name, :ruleset_file_name, :culture
18
+
19
+ def initialize(parameters = {})
20
+ @assemblies = parameters[:assemblies] || []
21
+ @output_file_name = parameters[:output_file_name]
22
+ @dictionary_file_name = parameters[:dictionary_file_name]
23
+ @ruleset_file_name = parameters[:ruleset_file_name]
24
+ @culture = parameters[:culture]
25
+ end
26
+ end
27
+
28
+ class FxCopSettingsAdapterFactory
29
+ def initialize(fxcop_command)
30
+ @fxcop_command = fxcop_command
31
+ end
32
+
33
+ def create
34
+ culture_adapter = CultureAdapter.new(@fxcop_command)
35
+ ruleset_file_name_adapter = RulesetFileNameAdapter.new(@fxcop_command,culture_adapter)
36
+ dictionary_file_name_adapter = DictionaryFileNameAdapter.new(@fxcop_command,ruleset_file_name_adapter)
37
+ assemblies_adapter = AssembliesAdapter.new(@fxcop_command, dictionary_file_name_adapter)
38
+ OutputFileNameAdapter.new(@fxcop_command, assemblies_adapter)
39
+ end
40
+ end
41
+
42
+ class FxCopCommand
43
+ def initialize(fxcop_binary,shell_command)
44
+ @fxcop_binary = fxcop_binary
45
+ @shell_command = shell_command
46
+ @arguments = []
47
+ end
48
+
49
+ def execute
50
+ fxcop_command = "#{@fxcop_binary}" << @arguments.join
51
+ @shell_command.execute(fxcop_command)
52
+ end
53
+
54
+ def add_argument(argument)
55
+ @arguments.push(argument)
56
+ end
57
+ end
58
+
59
+ class OutputFileNameAdapter
60
+ OUTPUT_SWITCH = "/o:"
61
+ def initialize(fxcop_command, next_adapter)
62
+ @fxcop_command = fxcop_command
63
+ @next_adapter = next_adapter
64
+ end
65
+
66
+ def adapt(fxcop_settings)
67
+ output_file_name = fxcop_settings.output_file_name
68
+ output_argument = " #{OUTPUT_SWITCH}#{output_file_name}" unless output_file_name.nil?
69
+ @fxcop_command.add_argument(output_argument)
70
+ @next_adapter.adapt(fxcop_settings)
71
+ end
72
+ end
73
+
74
+ class CultureAdapter
75
+ CULTURE_SWITCH = ' /cul:'
76
+ def initialize(fxcop_command)
77
+ @fxcop_command = fxcop_command
78
+ end
79
+
80
+ def adapt(fxcop_settings)
81
+ culture = fxcop_settings.culture
82
+ @fxcop_command.add_argument("#{CULTURE_SWITCH}#{culture}") unless fxcop_settings.culture.nil?
83
+ end
84
+ end
85
+
86
+ class RulesetFileNameAdapter
87
+ RULESET_SWITCH = " /rs:="
88
+ def initialize(fxcop_command, next_adapter)
89
+ @fxcop_command = fxcop_command
90
+ @next_adapter = next_adapter
91
+ end
92
+ def adapt(fxcop_settings)
93
+ ruleset_file_name = fxcop_settings.ruleset_file_name
94
+ @fxcop_command.add_argument("#{RULESET_SWITCH}#{ruleset_file_name}") unless ruleset_file_name.nil?
95
+ @next_adapter.adapt(fxcop_settings)
96
+ end
97
+ end
98
+
99
+ class DictionaryFileNameAdapter
100
+ DICTIONARY_SWITCH = "/dic:"
101
+ def initialize(fxcop_command, next_adapter)
102
+ @next_adapter = next_adapter
103
+ @fxcop_command = fxcop_command
104
+ end
105
+ def adapt(fxcop_settings)
106
+ dictionary_file_name = fxcop_settings.dictionary_file_name
107
+ dictionary_argument = " #{DICTIONARY_SWITCH}#{dictionary_file_name}" unless dictionary_file_name.nil?
108
+ @fxcop_command.add_argument(dictionary_argument)
109
+ @next_adapter.adapt(fxcop_settings)
110
+ end
111
+ end
112
+
113
+ class AssembliesAdapter
114
+ FILE_SWITCH = "/f:"
115
+
116
+ def initialize(fxcop_command, next_adapter)
117
+ @fxcop_command = fxcop_command
118
+ @next_adapter = next_adapter
119
+ end
120
+
121
+ def adapt(fxcop_settings)
122
+ fxcop_settings.assemblies.each do | assembly |
123
+ file_command = " #{FILE_SWITCH}#{assembly}"
124
+ @fxcop_command.add_argument(file_command)
125
+ end
126
+ @next_adapter.adapt(fxcop_settings)
127
+ end
128
+ end
129
+
130
+ class ShellCommand
131
+ def execute(command)
132
+ system command
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,43 @@
1
+ require_relative "fxcop"
2
+
3
+ def fxcop(*args, &block)
4
+ fxcop_wrapper = FxCopWrapper.new(&block)
5
+ task = Proc.new { fxcop_wrapper.run }
6
+ Rake::Task.define_task(*args, &task)
7
+ end
8
+
9
+
10
+ class FxCopWrapper
11
+ def initialize(&block)
12
+ @block = block;
13
+ end
14
+
15
+ def run()
16
+ configuration = FxCopConfiguration.new
17
+ @block.call(configuration)
18
+ fxcop_settings = create_fxcop_settings_from_configuration(configuration)
19
+ BuildQuality::FxCop.new(self,fxcop_binary: configuration.fxcop_binary).start(fxcop_settings)
20
+ end
21
+
22
+ def create_fxcop_settings_from_configuration(configuration)
23
+ BuildQuality::FxCopSettings.new(assemblies: configuration.assemblies,
24
+ output_file_name: configuration.output_file_name,
25
+ dictionary_file_name: configuration.dictionary_file_name,
26
+ ruleset_file_name: configuration.ruleset_file_name,
27
+ culture: configuration.culture)
28
+ end
29
+
30
+ def execute(command)
31
+ puts command
32
+ BuildQuality::ShellCommand.new.execute(command)
33
+ end
34
+ end
35
+
36
+ class FxCopConfiguration
37
+ attr_accessor :fxcop_binary,
38
+ :assemblies,
39
+ :output_file_name,
40
+ :dictionary_file_name,
41
+ :ruleset_file_name,
42
+ :culture
43
+ end
@@ -0,0 +1,57 @@
1
+ require 'test/unit'
2
+ require_relative '../lib/fxcop'
3
+
4
+ class TestFxCop < Test::Unit::TestCase
5
+
6
+ def test_when_started_with_no_arguments_Then_command_is_fxcop_binary
7
+ fxcop_binary = '.\FxCopCmd.exe'
8
+ BuildQuality::FxCop.new(self, fxcop_binary: fxcop_binary).start
9
+ assert_equal(fxcop_binary, @command)
10
+ end
11
+
12
+ def test_when_fxcop_started_with_two_assemblies_Then_command_contains_both_assemblies_as_files_switches
13
+ assembly1 = 'c:\workspace\mydll1.dll'
14
+ assembly2 = 'c:\workspace\mydll2.dll'
15
+ file_switch = '/f:'
16
+ fxcop_settings = BuildQuality::FxCopSettings.new(assemblies: [assembly1,assembly2])
17
+ BuildQuality::FxCop.new(self, {}).start(fxcop_settings)
18
+ assert_equal(" #{file_switch}#{assembly1} #{file_switch}#{assembly2}", @command)
19
+ end
20
+
21
+ def test_when_fxcop_started_with_out_file_name_provided_Then_command_contains_output_file_with_output_switch
22
+ output_file_name = "fred.xml"
23
+ output_switch = '/o:'
24
+ fxcop_settings = BuildQuality::FxCopSettings.new(output_file_name: output_file_name)
25
+ BuildQuality::FxCop.new(self, {}).start(fxcop_settings)
26
+ assert_equal(" #{output_switch}#{output_file_name}",@command)
27
+ end
28
+
29
+ def test_when_fxcop_started_with_custom_dictionary_provided_Then_command_contains_custom_dictionary_switch
30
+ dictionary_file_name = "mydictionary.txt"
31
+ dictionary_switch = '/dic:'
32
+ fxcop_settings = BuildQuality::FxCopSettings.new(dictionary_file_name: dictionary_file_name)
33
+ BuildQuality::FxCop.new(self, {}).start(fxcop_settings)
34
+ assert_equal(" #{dictionary_switch}#{dictionary_file_name}",@command)
35
+ end
36
+
37
+ def test_when_fxcop_started_with_custom_ruleset_provided_Then_command_contains_ruleset_switch
38
+ ruleset_file_name = "myruleset.ruleset"
39
+ ruleset_switch = '/rs:='
40
+ fxcop_settings = BuildQuality::FxCopSettings.new(ruleset_file_name: ruleset_file_name)
41
+ BuildQuality::FxCop.new(self, {}).start(fxcop_settings)
42
+ assert_equal(" #{ruleset_switch}#{ruleset_file_name}",@command)
43
+ end
44
+
45
+ def test_when_fxcop_started_with_culture_provided_Then_command_contains_culture_switch
46
+ culture_type = 'en-gb'
47
+ culture_switch = '/cul:'
48
+ fxcop_settings = BuildQuality::FxCopSettings.new(culture: culture_type)
49
+ BuildQuality::FxCop.new(self, {}).start(fxcop_settings)
50
+ assert_equal(" #{culture_switch}#{culture_type}",@command)
51
+ end
52
+
53
+
54
+ def execute(command)
55
+ @command = command
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fxcop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Flowers
9
+ - Iain Mitchell
10
+ - Rikk Renshaw
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2013-04-26 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rake
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: 10.0.3
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: 10.0.3
32
+ description: FxCop Wrapper for running FxCop on Continuous integration. Comes with
33
+ Rake Task or can be used with Standard Ruby
34
+ email:
35
+ - ben.j.flowers@gmail.com
36
+ - iainjmitchell@gmail.com
37
+ - rikk62@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - lib/fxcop.rb
43
+ - lib/fxcop_raketask.rb
44
+ - tests/test_fxcop.rb
45
+ homepage: https://github.com/team-beast/fxcop
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Simple FxCop wrapper gem
69
+ test_files:
70
+ - tests/test_fxcop.rb