bozo-scripts 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,128 +1,128 @@
1
- require 'erubis'
2
-
3
- module Bozo
4
-
5
- # Class for creating files based upon configuration files and ERB-style
6
- # templates.
7
- #
8
- # == Overview
9
- #
10
- # This class is primarily intended for generating config files with shared
11
- # values but it is capable of generating whatever files you want.
12
- #
13
- # == Configuration files
14
- #
15
- # Configuration files specify a hash of hashes in a more readable format.
16
- # For example:
17
- #
18
- # group :example do
19
- # set :one, 'foo'
20
- # set :two, 'bar'
21
- # end
22
- #
23
- # Internally creates a hash like:
24
- #
25
- # {:example => {:one => 'foo', :two => 'bar'}}
26
- #
27
- # A configuration file can overwrite the values specified by a preceding one
28
- # without error. Groups can be opened and closed as desired and nesting
29
- # groups is possible.
30
- #
31
- # == Template files
32
- #
33
- # To use a value within an ERB template you specify the hash hierarchy as if
34
- # they were method names rather than having to use the full hash syntax.
35
- #
36
- # Therefore, this is valid:
37
- #
38
- # Foo is <%= example.one %>
39
- #
40
- # Whilst this is *not* valid:
41
- #
42
- # Foo is <%= self[:example][:one] %>
43
- #
44
- # If a template uses a value that is not specified within the configuration
45
- # then the hook will raise an error and halt the build.
46
- class ErubisTemplatingCoordinator
47
-
48
- # Create a new instance.
49
- #
50
- # @param [Configuration] configuration
51
- # The configuration to use with templates. If not specified a new
52
- # object is created.
53
- def initialize(configuration = Bozo::Configuration.new)
54
- @templates = []
55
- @configuration = configuration
56
- end
57
-
58
- # Adds a required configuration file to the underlying configuration
59
- # object.
60
- #
61
- # @param [String] path
62
- # The path of the configuration file to load.
63
- def required_config_file(path)
64
- raise RuntimeError.new "Required config file #{path} could not be found" unless File.exist? path
65
- config_file path
66
- end
67
-
68
- # Adds a configuration file to the underlying configuration object if a
69
- # file exists at the given path.
70
- #
71
- # @param [String] path
72
- # The path of the configuration file to load.
73
- def config_file(path)
74
- @configuration.load path if File.exist? path
75
- end
76
-
77
- # Adds a template file to use when generating files.
78
- #
79
- # @param [String] path
80
- # The path of the template file.
81
- def template_file(path)
82
- @templates << path
83
- end
84
-
85
- # Adds a selection of template files to use when generating files.
86
- #
87
- # @param [String] glob
88
- # A glob from that matches template files.
89
- def template_files(glob)
90
- @templates = @templates + Dir[glob]
91
- end
92
-
93
- # Generate all the files matching the underlying configuration.
94
- #
95
- # @param [Proc] block
96
- # A block that will be called with the template path and target file
97
- # path when provided.
98
- def generate_files(&block)
99
- @templates.each {|template| generate_file template, block}
100
- end
101
-
102
- private
103
-
104
- # Generate the file relating to the template file using the given
105
- # configuration.
106
- #
107
- # @param [String] template_path
108
- # The path of the template file that should be filled using the
109
- # configuration.
110
- # @param [Proc] block
111
- # A block that will be called with the template path and target file
112
- # path when provided.
113
- def generate_file(template_path, block)
114
- target_path = template_path.sub /\.[^\.]+$/, ''
115
-
116
- block.call(template_path, target_path) unless block.nil?
117
-
118
- template_content = IO.read template_path
119
- template = Erubis::Eruby.new template_content
120
-
121
- content = @configuration.apply {|binding| template.result(binding)}
122
-
123
- File.open(target_path, 'w+') {|f| f.write(content)}
124
- end
125
-
126
- end
127
-
1
+ require 'erubis'
2
+
3
+ module Bozo
4
+
5
+ # Class for creating files based upon configuration files and ERB-style
6
+ # templates.
7
+ #
8
+ # == Overview
9
+ #
10
+ # This class is primarily intended for generating config files with shared
11
+ # values but it is capable of generating whatever files you want.
12
+ #
13
+ # == Configuration files
14
+ #
15
+ # Configuration files specify a hash of hashes in a more readable format.
16
+ # For example:
17
+ #
18
+ # group :example do
19
+ # set :one, 'foo'
20
+ # set :two, 'bar'
21
+ # end
22
+ #
23
+ # Internally creates a hash like:
24
+ #
25
+ # {:example => {:one => 'foo', :two => 'bar'}}
26
+ #
27
+ # A configuration file can overwrite the values specified by a preceding one
28
+ # without error. Groups can be opened and closed as desired and nesting
29
+ # groups is possible.
30
+ #
31
+ # == Template files
32
+ #
33
+ # To use a value within an ERB template you specify the hash hierarchy as if
34
+ # they were method names rather than having to use the full hash syntax.
35
+ #
36
+ # Therefore, this is valid:
37
+ #
38
+ # Foo is <%= example.one %>
39
+ #
40
+ # Whilst this is *not* valid:
41
+ #
42
+ # Foo is <%= self[:example][:one] %>
43
+ #
44
+ # If a template uses a value that is not specified within the configuration
45
+ # then the hook will raise an error and halt the build.
46
+ class ErubisTemplatingCoordinator
47
+
48
+ # Create a new instance.
49
+ #
50
+ # @param [Configuration] configuration
51
+ # The configuration to use with templates. If not specified a new
52
+ # object is created.
53
+ def initialize(configuration = Bozo::Configuration.new)
54
+ @templates = []
55
+ @configuration = configuration
56
+ end
57
+
58
+ # Adds a required configuration file to the underlying configuration
59
+ # object.
60
+ #
61
+ # @param [String] path
62
+ # The path of the configuration file to load.
63
+ def required_config_file(path)
64
+ raise RuntimeError.new "Required config file #{path} could not be found" unless File.exist? path
65
+ config_file path
66
+ end
67
+
68
+ # Adds a configuration file to the underlying configuration object if a
69
+ # file exists at the given path.
70
+ #
71
+ # @param [String] path
72
+ # The path of the configuration file to load.
73
+ def config_file(path)
74
+ @configuration.load path if File.exist? path
75
+ end
76
+
77
+ # Adds a template file to use when generating files.
78
+ #
79
+ # @param [String] path
80
+ # The path of the template file.
81
+ def template_file(path)
82
+ @templates << path
83
+ end
84
+
85
+ # Adds a selection of template files to use when generating files.
86
+ #
87
+ # @param [String] glob
88
+ # A glob from that matches template files.
89
+ def template_files(glob)
90
+ @templates = @templates + Dir[glob]
91
+ end
92
+
93
+ # Generate all the files matching the underlying configuration.
94
+ #
95
+ # @param [Proc] block
96
+ # A block that will be called with the template path and target file
97
+ # path when provided.
98
+ def generate_files(&block)
99
+ @templates.each {|template| generate_file template, block}
100
+ end
101
+
102
+ private
103
+
104
+ # Generate the file relating to the template file using the given
105
+ # configuration.
106
+ #
107
+ # @param [String] template_path
108
+ # The path of the template file that should be filled using the
109
+ # configuration.
110
+ # @param [Proc] block
111
+ # A block that will be called with the template path and target file
112
+ # path when provided.
113
+ def generate_file(template_path, block)
114
+ target_path = template_path.sub /\.[^\.]+$/, ''
115
+
116
+ block.call(template_path, target_path) unless block.nil?
117
+
118
+ template_content = IO.read template_path
119
+ template = Erubis::Eruby.new template_content
120
+
121
+ content = @configuration.apply {|binding| template.result(binding)}
122
+
123
+ File.open(target_path, 'w+') {|f| f.write(content)}
124
+ end
125
+
126
+ end
127
+
128
128
  end
@@ -1,23 +1,23 @@
1
- module Bozo::Hooks
2
-
3
- class BuildNumberVersion
4
-
5
- def pre_prepare
6
- env['GIT_HASH_FULL'] = `git log -1 --format="%H"`.strip
7
- env['BUILD_VERSION'] = build_version
8
- build_version.write_to_file "NEW_VERSION"
9
- end
10
-
11
- private
12
-
13
- def build_version
14
- if env['BUILD_NUMBER']
15
- Bozo::Versioning::Version.new(version.major, version.minor, env['BUILD_NUMBER'])
16
- else
17
- version
18
- end
19
- end
20
-
21
- end
22
-
1
+ module Bozo::Hooks
2
+
3
+ class BuildNumberVersion
4
+
5
+ def pre_prepare
6
+ env['GIT_HASH_FULL'] = `git log -1 --format="%H"`.strip
7
+ env['BUILD_VERSION'] = build_version
8
+ build_version.write_to_file "NEW_VERSION"
9
+ end
10
+
11
+ private
12
+
13
+ def build_version
14
+ if env['BUILD_NUMBER']
15
+ Bozo::Versioning::Version.new(version.major, version.minor, env['BUILD_NUMBER'])
16
+ else
17
+ version
18
+ end
19
+ end
20
+
21
+ end
22
+
23
23
  end
@@ -1,152 +1,152 @@
1
- module Bozo::Hooks
2
-
3
- # Specifies a hook for running FxCop.
4
- #
5
- # The default configuration runs against the compiled assemblies produced via
6
- # msbuild.
7
- #
8
- # Alternatively a specific .fxcop project file can be specified in the
9
- # configuration.
10
- class FxCop
11
-
12
- def self.default_path
13
- if ENV['ProgramFiles(x86)'].nil?
14
- program_files_path = ENV['ProgramFiles']
15
- else
16
- program_files_path = ENV['ProgramFiles(x86)']
17
- end
18
-
19
- File.join(program_files_path, 'Microsoft Fxcop 10.0', 'fxcopcmd.exe') unless program_files_path.nil?
20
- end
21
-
22
- def initialize
23
- @@defaults = {
24
- :types => [],
25
- :framework_versions => [:net35, :net40],
26
- :project => nil,
27
- :path => FxCop.default_path
28
- }
29
-
30
- @config = {}
31
- end
32
-
33
- # Adds a type to analyze
34
- def type(type)
35
- @config[:types] ||= []
36
- @config[:types] << type
37
- end
38
-
39
- # Specifies an fxcop project file
40
- def project(project)
41
- @config[:project] = project
42
- end
43
-
44
- # Specifies the fxcop path
45
- def path(path = nil)
46
- @config[:path] = path unless path.nil?
47
-
48
- @config[:path]
49
- end
50
-
51
- # Runs the post_compile hook
52
- def post_compile
53
- config = config_with_defaults
54
-
55
- raise no_executable_path_specified if path.nil?
56
- raise no_executable_exists unless File.exists?(path)
57
-
58
- if config[:project].nil?
59
- execute_projects config
60
- else
61
- execute_fxcop_project config
62
- end
63
- end
64
-
65
- private
66
-
67
- def config_with_defaults
68
- @@defaults.merge @config
69
- end
70
-
71
- # The path to output the fxcop results to
72
- def output_path
73
- out_path = File.expand_path File.join('temp', 'fxcop')
74
- FileUtils.mkdir_p out_path
75
- out_path
76
- end
77
-
78
- # Executes fxcop against the msbuild built assemblies
79
- #
80
- # @param [Hash] config
81
- # The fxcop configuration
82
- def execute_projects(config)
83
- log_debug "Executing projects with '#{path}'" if config[:framework_versions].any?
84
-
85
- config[:framework_versions].each do |framework_version|
86
- args = []
87
- args << '"' + path + '"'
88
- args << "/out:#{output_path}\\#{Time.now.to_i}-#{framework_version}-FxCop-report.xml"
89
- args << "/types:" + config[:types].join(',') unless config[:types].empty?
90
-
91
- project_dirs.each do |project|
92
- projects = project_files(project, framework_version)
93
-
94
- projects.each do |project_file|
95
- project_path = File.expand_path(project_file).gsub(/\//, '\\')
96
- args << "/file:\"#{project_path}\""
97
- end
98
- end
99
-
100
- execute_command :fx_cop, args
101
- end
102
- end
103
-
104
- # Executes a .fxcop file
105
- #
106
- # @param [Hash] config
107
- # The fxcop configuration
108
- def execute_fxcop_project(config)
109
- log_debug "Executing fxcop project '#{config[:project]}' with '#{path}'"
110
-
111
- args = []
112
- args << '"' + path + '"'
113
- args << "/out:\"#{output_path}\\#{File.basename(config[:project], '.*')}-FxCop-report.xml\""
114
- args << "/project:\"#{config[:project]}\""
115
- args << "/types:" + config[:types].join(',') unless config[:types].empty?
116
-
117
- execute_command :fx_cop, args
118
- end
119
-
120
- # Create a new error specifying that the executable path
121
- # has not been specified.
122
- def no_executable_path_specified
123
- ConfigurationError.new "No path specified for fxcop"
124
- end
125
-
126
- # Create a new error specifying that the fxcop executable
127
- # does not exist at the path.
128
- def no_executable_exists
129
- ConfigurationError.new "FxCop executable does not exist at #{path}"
130
- end
131
-
132
- # List of compiled assemblies and executables
133
-
134
- # @param [String] project_path
135
- # The path of the project
136
- # @param [Symbol] framework_version
137
- # The framework_version to find assemblies for
138
- def project_files(project_path, framework_version)
139
- project_name = File.basename(project_path)
140
- file_matcher = File.expand_path File.join(project_path, framework_version.to_s, "#{project_name}.{dll,exe}")
141
- Dir[file_matcher]
142
- end
143
-
144
- # List of all the msbuild built projects
145
- def project_dirs
146
- project_file_matcher = File.expand_path File.join('temp', 'msbuild', '*')
147
- Dir[project_file_matcher]
148
- end
149
-
150
- end
151
-
1
+ module Bozo::Hooks
2
+
3
+ # Specifies a hook for running FxCop.
4
+ #
5
+ # The default configuration runs against the compiled assemblies produced via
6
+ # msbuild.
7
+ #
8
+ # Alternatively a specific .fxcop project file can be specified in the
9
+ # configuration.
10
+ class FxCop
11
+
12
+ def self.default_path
13
+ if ENV['ProgramFiles(x86)'].nil?
14
+ program_files_path = ENV['ProgramFiles']
15
+ else
16
+ program_files_path = ENV['ProgramFiles(x86)']
17
+ end
18
+
19
+ File.join(program_files_path, 'Microsoft Fxcop 10.0', 'fxcopcmd.exe') unless program_files_path.nil?
20
+ end
21
+
22
+ def initialize
23
+ @@defaults = {
24
+ :types => [],
25
+ :framework_versions => [:net35, :net40],
26
+ :project => nil,
27
+ :path => FxCop.default_path
28
+ }
29
+
30
+ @config = {}
31
+ end
32
+
33
+ # Adds a type to analyze
34
+ def type(type)
35
+ @config[:types] ||= []
36
+ @config[:types] << type
37
+ end
38
+
39
+ # Specifies an fxcop project file
40
+ def project(project)
41
+ @config[:project] = project
42
+ end
43
+
44
+ # Specifies the fxcop path
45
+ def path(path = nil)
46
+ @config[:path] = path unless path.nil?
47
+
48
+ @config[:path]
49
+ end
50
+
51
+ # Runs the post_compile hook
52
+ def post_compile
53
+ config = config_with_defaults
54
+
55
+ raise no_executable_path_specified if path.nil?
56
+ raise no_executable_exists unless File.exists?(path)
57
+
58
+ if config[:project].nil?
59
+ execute_projects config
60
+ else
61
+ execute_fxcop_project config
62
+ end
63
+ end
64
+
65
+ private
66
+
67
+ def config_with_defaults
68
+ @@defaults.merge @config
69
+ end
70
+
71
+ # The path to output the fxcop results to
72
+ def output_path
73
+ out_path = File.expand_path File.join('temp', 'fxcop')
74
+ FileUtils.mkdir_p out_path
75
+ out_path
76
+ end
77
+
78
+ # Executes fxcop against the msbuild built assemblies
79
+ #
80
+ # @param [Hash] config
81
+ # The fxcop configuration
82
+ def execute_projects(config)
83
+ log_debug "Executing projects with '#{path}'" if config[:framework_versions].any?
84
+
85
+ config[:framework_versions].each do |framework_version|
86
+ args = []
87
+ args << '"' + path + '"'
88
+ args << "/out:#{output_path}\\#{Time.now.to_i}-#{framework_version}-FxCop-report.xml"
89
+ args << "/types:" + config[:types].join(',') unless config[:types].empty?
90
+
91
+ project_dirs.each do |project|
92
+ projects = project_files(project, framework_version)
93
+
94
+ projects.each do |project_file|
95
+ project_path = File.expand_path(project_file).gsub(/\//, '\\')
96
+ args << "/file:\"#{project_path}\""
97
+ end
98
+ end
99
+
100
+ execute_command :fx_cop, args
101
+ end
102
+ end
103
+
104
+ # Executes a .fxcop file
105
+ #
106
+ # @param [Hash] config
107
+ # The fxcop configuration
108
+ def execute_fxcop_project(config)
109
+ log_debug "Executing fxcop project '#{config[:project]}' with '#{path}'"
110
+
111
+ args = []
112
+ args << '"' + path + '"'
113
+ args << "/out:\"#{output_path}\\#{File.basename(config[:project], '.*')}-FxCop-report.xml\""
114
+ args << "/project:\"#{config[:project]}\""
115
+ args << "/types:" + config[:types].join(',') unless config[:types].empty?
116
+
117
+ execute_command :fx_cop, args
118
+ end
119
+
120
+ # Create a new error specifying that the executable path
121
+ # has not been specified.
122
+ def no_executable_path_specified
123
+ ConfigurationError.new "No path specified for fxcop"
124
+ end
125
+
126
+ # Create a new error specifying that the fxcop executable
127
+ # does not exist at the path.
128
+ def no_executable_exists
129
+ ConfigurationError.new "FxCop executable does not exist at #{path}"
130
+ end
131
+
132
+ # List of compiled assemblies and executables
133
+
134
+ # @param [String] project_path
135
+ # The path of the project
136
+ # @param [Symbol] framework_version
137
+ # The framework_version to find assemblies for
138
+ def project_files(project_path, framework_version)
139
+ project_name = File.basename(project_path)
140
+ file_matcher = File.expand_path File.join(project_path, framework_version.to_s, "#{project_name}.{dll,exe}")
141
+ Dir[file_matcher]
142
+ end
143
+
144
+ # List of all the msbuild built projects
145
+ def project_dirs
146
+ project_file_matcher = File.expand_path File.join('temp', 'msbuild', '*')
147
+ Dir[project_file_matcher]
148
+ end
149
+
150
+ end
151
+
152
152
  end
@@ -1,23 +1,23 @@
1
- module Bozo::Hooks
2
-
3
- class GitCommitHashes
4
-
5
- def pre_prepare
6
- env['GIT_HASH'] = `git log -1 --format="%h"`.strip
7
- env['GIT_HASH_FULL'] = `git log -1 --format="%H"`.strip
8
- env['BUILD_VERSION'] = build_version
9
- end
10
-
11
- private
12
-
13
- def build_version
14
- if pre_release?
15
- Bozo::Versioning::Version.new(version.major, version.minor, version.patch, "pre#{env['GIT_HASH']}")
16
- else
17
- version
18
- end
19
- end
20
-
21
- end
22
-
1
+ module Bozo::Hooks
2
+
3
+ class GitCommitHashes
4
+
5
+ def pre_prepare
6
+ env['GIT_HASH'] = `git log -1 --format="%h"`.strip
7
+ env['GIT_HASH_FULL'] = `git log -1 --format="%H"`.strip
8
+ env['BUILD_VERSION'] = build_version
9
+ end
10
+
11
+ private
12
+
13
+ def build_version
14
+ if pre_release?
15
+ Bozo::Versioning::Version.new(version.major, version.minor, version.patch, "pre#{env['GIT_HASH']}")
16
+ else
17
+ version
18
+ end
19
+ end
20
+
21
+ end
22
+
23
23
  end