bozo-scripts 0.1.11 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,19 +1,19 @@
1
- Copyright (C) 2012 Zopa Ltd
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- this software and associated documentation files (the "Software"), to deal in
5
- the Software without restriction, including without limitation the rights to
6
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
- of the Software, and to permit persons to whom the Software is furnished to do
8
- so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ Copyright (C) 2012 Zopa Ltd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
19
  SOFTWARE.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.11
1
+ 0.2.0
@@ -1,299 +1,299 @@
1
- require 'nokogiri'
2
- require 'fileutils'
3
-
4
- module Bozo::Compilers
5
-
6
- class Msbuild
7
-
8
- def config_with_defaults
9
- defaults = {
10
- :version => 'v4.0.30319',
11
- :framework => 'Framework64',
12
- :properties => {:configuration => :release},
13
- :max_cores => nil
14
- }
15
-
16
- default_targets = [:build]
17
-
18
- config = defaults.merge @config
19
- config[:targets] = (@targets or default_targets).clone
20
- config[:websites_as_zip] = false
21
- config
22
- end
23
-
24
- def initialize
25
- @config = {}
26
- @exclude_projects = []
27
- end
28
-
29
- def version(version)
30
- @config[:version] = version
31
- end
32
-
33
- def framework(framework)
34
- @config[:framework] = framework
35
- end
36
-
37
- def solution(path)
38
- @config[:solution] = path
39
- end
40
-
41
- def property(args)
42
- @config[:properties] ||= {}
43
- @config[:properties] = @config[:properties].merge(args)
44
- end
45
-
46
- def exclude_project(project_name)
47
- @exclude_projects << project_name
48
- end
49
-
50
- def websites_as_zip?
51
- @config[:websites_as_zip] = true
52
- end
53
-
54
- # Assign how many cores should be used by msbuild
55
- #
56
- # @param [Integer] cores
57
- # The maximum number of cores to allow msbuild to use
58
- def max_cores(cores)
59
- @config[:max_cores] = cores
60
- end
61
-
62
- alias :properties :property
63
-
64
- def target(target)
65
- @targets ||= []
66
- @targets << target
67
- end
68
-
69
- def to_s
70
- config = configuration
71
- "Compile with msbuild #{config[:version]} building #{config[:solution]} with properties #{config[:properties]} for targets #{config[:targets]}"
72
- end
73
-
74
- def without_stylecop
75
- @config[:without_stylecop] = true
76
- end
77
-
78
- def configuration
79
- config_with_defaults
80
- end
81
-
82
- def execute
83
- projects = (project_files('test') | project_files('src')).map { |file| create_project file }
84
-
85
- # Clean all the projects first.
86
- projects.each do |project|
87
- project.clean configuration
88
- end
89
-
90
- # Build all the projects so they can utilize each others artifacts.
91
- projects.each do |project|
92
- project.build configuration
93
- end
94
- end
95
-
96
- def project_files(directory)
97
- project_file_matcher = File.expand_path(File.join(directory, 'csharp', '**', '*.csproj'))
98
- Dir[project_file_matcher].select { |p| not @exclude_projects.include?(File.basename p, '.csproj') }
99
- end
100
-
101
- def required_tools
102
- :stylecop unless @config[:without_stylecop]
103
- end
104
-
105
- private
106
-
107
- # Creates a project based on the project_file type.
108
- # Defaults to a class library project if it cannot be determined.
109
- # @return [Project]
110
- def create_project(project_file)
111
- project_name = File.basename(project_file).gsub(/\.csproj$/, '')
112
- log_debug project_name
113
-
114
- project_class_for(project_file).new project_file, project_name
115
- end
116
-
117
- # @return [Class]
118
- def project_class_for(project_file)
119
- project_types = project_types_from project_file
120
- web_app_type = '{349c5851-65df-11da-9384-00065b846f21}'
121
- if tools_version(project_file) == "3.5"
122
- project_types.include?(web_app_type) ? WebProject2008 : ClassLibrary
123
- else
124
- project_types.include?(web_app_type) ? WebProject2010 : ClassLibrary
125
- end
126
- end
127
-
128
- # @return [Array]
129
- def project_types_from(project_file)
130
- project_types = []
131
-
132
- File.open(project_file) do |f|
133
- element = Nokogiri::XML(f).css('Project PropertyGroup ProjectTypeGuids').first
134
- project_types = element.content.split(';').map {|e| e.downcase } unless element.nil?
135
- end
136
-
137
- project_types
138
- end
139
-
140
- def tools_version(project_file)
141
- tools_version = nil
142
-
143
- File.open(project_file) do |f|
144
- element = Nokogiri::XML(f).css('Project').first
145
- tools_version = element['ToolsVersion'] unless element.nil?
146
- end
147
-
148
- tools_version
149
- end
150
-
151
- end
152
-
153
- private
154
-
155
- class Project
156
-
157
- include Bozo::Runner
158
-
159
- def initialize(project_file, project_name)
160
- @project_file = project_file
161
- @project_name = project_name
162
- end
163
-
164
- def build(configuration)
165
- populate_config(configuration)
166
- args = generate_args configuration
167
- execute_command :msbuild, args
168
- end
169
-
170
- def clean(configuration)
171
- configuration[:targets] = [:clean]
172
- args = generate_args configuration
173
- execute_command :msbuild, args
174
-
175
- remove_obj_directory
176
- end
177
-
178
- def framework_version
179
- framework_version = 'unknown'
180
-
181
- File.open(@project_file) do |f|
182
- framework_version = Nokogiri::XML(f).css('Project PropertyGroup TargetFrameworkVersion').first.content
183
- framework_version = framework_version.sub('v', 'net').sub('.', '')
184
- end
185
-
186
- framework_version
187
- end
188
-
189
- def generate_args(config)
190
- args = []
191
-
192
- args << File.join(ENV['WINDIR'], 'Microsoft.NET', config[:framework], config[:version], 'msbuild.exe')
193
- args << '/nologo'
194
- args << '/verbosity:normal'
195
- args << '/nodeReuse:false'
196
- args << "/target:#{config[:targets].map{|t| t.to_s}.join(';')}"
197
- args << "/maxcpucount" if config[:max_cores].nil? # let msbuild decide how many cores to use
198
- args << "/maxcpucount:#{config[:max_cores]}" unless config[:max_cores].nil? # specifying the number of cores
199
-
200
- config[:properties].each do |key, value|
201
- args << "/property:#{key}=\"#{value}\""
202
- end
203
-
204
- args << "\"#{@project_file}\""
205
- end
206
-
207
- def windowsize_path(path)
208
- path.gsub(/\//, '\\')
209
- end
210
-
211
- def location
212
- File.expand_path(File.join('temp', 'msbuild', @project_name, framework_version))
213
- end
214
-
215
- private
216
-
217
- def remove_obj_directory
218
- if Dir.exists?(obj_directory)
219
- log_info "Removing #{obj_directory}"
220
- FileUtils.rm_rf obj_directory
221
- end
222
- end
223
-
224
- def obj_directory
225
- File.join(project_path, 'obj')
226
- end
227
-
228
- def project_path
229
- File.dirname(@project_file)
230
- end
231
-
232
- end
233
-
234
- class ClassLibrary < Project
235
-
236
- def populate_config(config)
237
- config[:properties][:outputpath] = location + '/'
238
- config[:properties][:solutiondir] = windowsize_path(File.expand_path('.') + '//')
239
- end
240
-
241
- end
242
-
243
- class WebProject2010 < Project
244
-
245
- def populate_config(config)
246
- config[:targets] << :package
247
-
248
- config[:properties][:packagelocation] = location + '/Site.zip'
249
- config[:properties][:packageassinglefile] = true
250
-
251
- config[:properties][:solutiondir] = windowsize_path(File.expand_path('.') + '//')
252
- end
253
-
254
- end
255
-
256
- class WebProject2008 < Project
257
-
258
- require 'zip/zip'
259
-
260
- def build(configuration)
261
- super
262
-
263
- zip_website if configuration[:websites_as_zip]
264
- end
265
-
266
- def zip_website
267
- zip_file = zip_location_dir 'Site.zip'
268
-
269
- Dir["#{location}/**/**"].reject { |f| f == zip_file }.each do |file|
270
- FileUtils.rm_rf file
271
- end
272
- end
273
-
274
- def zip_location_dir(zip_file_name)
275
- zip_path = location + "/#{zip_file_name}"
276
-
277
- Zip::ZipFile.open(zip_path, Zip::ZipFile::CREATE) do |zipfile|
278
- Dir["#{location}/**/**"].each do |file|
279
- zipfile.add(file.sub(location + '/', ''), file)
280
- end
281
- end
282
-
283
- zip_path
284
- end
285
-
286
- def populate_config(config)
287
- config[:targets] << :'ResolveReferences'
288
- config[:targets] << :'_CopyWebApplication'
289
-
290
- config[:properties][:OutDir] = location + '/bin/'
291
- config[:properties][:WebProjectOutputDir] = windowsize_path location
292
- config[:properties][:_DebugSymbolsProduced] = false
293
-
294
- config[:properties][:solutiondir] = windowsize_path(File.expand_path('.') + '//')
295
- end
296
-
297
- end
298
-
299
- end
1
+ require 'nokogiri'
2
+ require 'fileutils'
3
+
4
+ module Bozo::Compilers
5
+
6
+ class Msbuild
7
+
8
+ def config_with_defaults
9
+ defaults = {
10
+ :version => 'v4.0.30319',
11
+ :framework => 'Framework64',
12
+ :properties => {:configuration => :release},
13
+ :max_cores => nil
14
+ }
15
+
16
+ default_targets = [:build]
17
+
18
+ config = defaults.merge @config
19
+ config[:targets] = (@targets or default_targets).clone
20
+ config[:websites_as_zip] = false
21
+ config
22
+ end
23
+
24
+ def initialize
25
+ @config = {}
26
+ @exclude_projects = []
27
+ end
28
+
29
+ def version(version)
30
+ @config[:version] = version
31
+ end
32
+
33
+ def framework(framework)
34
+ @config[:framework] = framework
35
+ end
36
+
37
+ def solution(path)
38
+ @config[:solution] = path
39
+ end
40
+
41
+ def property(args)
42
+ @config[:properties] ||= {}
43
+ @config[:properties] = @config[:properties].merge(args)
44
+ end
45
+
46
+ def exclude_project(project_name)
47
+ @exclude_projects << project_name
48
+ end
49
+
50
+ def websites_as_zip?
51
+ @config[:websites_as_zip] = true
52
+ end
53
+
54
+ # Assign how many cores should be used by msbuild
55
+ #
56
+ # @param [Integer] cores
57
+ # The maximum number of cores to allow msbuild to use
58
+ def max_cores(cores)
59
+ @config[:max_cores] = cores
60
+ end
61
+
62
+ alias :properties :property
63
+
64
+ def target(target)
65
+ @targets ||= []
66
+ @targets << target
67
+ end
68
+
69
+ def to_s
70
+ config = configuration
71
+ "Compile with msbuild #{config[:version]} building #{config[:solution]} with properties #{config[:properties]} for targets #{config[:targets]}"
72
+ end
73
+
74
+ def without_stylecop
75
+ @config[:without_stylecop] = true
76
+ end
77
+
78
+ def configuration
79
+ config_with_defaults
80
+ end
81
+
82
+ def execute
83
+ projects = (project_files('test') | project_files('src')).map { |file| create_project file }
84
+
85
+ # Clean all the projects first.
86
+ projects.each do |project|
87
+ project.clean configuration
88
+ end
89
+
90
+ # Build all the projects so they can utilize each others artifacts.
91
+ projects.each do |project|
92
+ project.build configuration
93
+ end
94
+ end
95
+
96
+ def project_files(directory)
97
+ project_file_matcher = File.expand_path(File.join(directory, 'csharp', '**', '*.csproj'))
98
+ Dir[project_file_matcher].select { |p| not @exclude_projects.include?(File.basename p, '.csproj') }
99
+ end
100
+
101
+ def required_tools
102
+ :stylecop unless @config[:without_stylecop]
103
+ end
104
+
105
+ private
106
+
107
+ # Creates a project based on the project_file type.
108
+ # Defaults to a class library project if it cannot be determined.
109
+ # @return [Project]
110
+ def create_project(project_file)
111
+ project_name = File.basename(project_file).gsub(/\.csproj$/, '')
112
+ log_debug project_name
113
+
114
+ project_class_for(project_file).new project_file, project_name
115
+ end
116
+
117
+ # @return [Class]
118
+ def project_class_for(project_file)
119
+ project_types = project_types_from project_file
120
+ web_app_type = '{349c5851-65df-11da-9384-00065b846f21}'
121
+ if tools_version(project_file) == "3.5"
122
+ project_types.include?(web_app_type) ? WebProject2008 : ClassLibrary
123
+ else
124
+ project_types.include?(web_app_type) ? WebProject2010 : ClassLibrary
125
+ end
126
+ end
127
+
128
+ # @return [Array]
129
+ def project_types_from(project_file)
130
+ project_types = []
131
+
132
+ File.open(project_file) do |f|
133
+ element = Nokogiri::XML(f).css('Project PropertyGroup ProjectTypeGuids').first
134
+ project_types = element.content.split(';').map {|e| e.downcase } unless element.nil?
135
+ end
136
+
137
+ project_types
138
+ end
139
+
140
+ def tools_version(project_file)
141
+ tools_version = nil
142
+
143
+ File.open(project_file) do |f|
144
+ element = Nokogiri::XML(f).css('Project').first
145
+ tools_version = element['ToolsVersion'] unless element.nil?
146
+ end
147
+
148
+ tools_version
149
+ end
150
+
151
+ end
152
+
153
+ private
154
+
155
+ class Project
156
+
157
+ include Bozo::Runner
158
+
159
+ def initialize(project_file, project_name)
160
+ @project_file = project_file
161
+ @project_name = project_name
162
+ end
163
+
164
+ def build(configuration)
165
+ populate_config(configuration)
166
+ args = generate_args configuration
167
+ execute_command :msbuild, args
168
+ end
169
+
170
+ def clean(configuration)
171
+ configuration[:targets] = [:clean]
172
+ args = generate_args configuration
173
+ execute_command :msbuild, args
174
+
175
+ remove_obj_directory
176
+ end
177
+
178
+ def framework_version
179
+ framework_version = 'unknown'
180
+
181
+ File.open(@project_file) do |f|
182
+ framework_version = Nokogiri::XML(f).css('Project PropertyGroup TargetFrameworkVersion').first.content
183
+ framework_version = framework_version.sub('v', 'net').sub('.', '')
184
+ end
185
+
186
+ framework_version
187
+ end
188
+
189
+ def generate_args(config)
190
+ args = []
191
+
192
+ args << File.join(ENV['WINDIR'], 'Microsoft.NET', config[:framework], config[:version], 'msbuild.exe')
193
+ args << '/nologo'
194
+ args << '/verbosity:normal'
195
+ args << '/nodeReuse:false'
196
+ args << "/target:#{config[:targets].map{|t| t.to_s}.join(';')}"
197
+ args << "/maxcpucount" if config[:max_cores].nil? # let msbuild decide how many cores to use
198
+ args << "/maxcpucount:#{config[:max_cores]}" unless config[:max_cores].nil? # specifying the number of cores
199
+
200
+ config[:properties].each do |key, value|
201
+ args << "/property:#{key}=\"#{value}\""
202
+ end
203
+
204
+ args << "\"#{@project_file}\""
205
+ end
206
+
207
+ def windowsize_path(path)
208
+ path.gsub(/\//, '\\')
209
+ end
210
+
211
+ def location
212
+ File.expand_path(File.join('temp', 'msbuild', @project_name, framework_version))
213
+ end
214
+
215
+ private
216
+
217
+ def remove_obj_directory
218
+ if Dir.exists?(obj_directory)
219
+ log_info "Removing #{obj_directory}"
220
+ FileUtils.rm_rf obj_directory
221
+ end
222
+ end
223
+
224
+ def obj_directory
225
+ File.join(project_path, 'obj')
226
+ end
227
+
228
+ def project_path
229
+ File.dirname(@project_file)
230
+ end
231
+
232
+ end
233
+
234
+ class ClassLibrary < Project
235
+
236
+ def populate_config(config)
237
+ config[:properties][:outputpath] = location + '/'
238
+ config[:properties][:solutiondir] = windowsize_path(File.expand_path('.') + '//')
239
+ end
240
+
241
+ end
242
+
243
+ class WebProject2010 < Project
244
+
245
+ def populate_config(config)
246
+ config[:targets] << :package
247
+
248
+ config[:properties][:packagelocation] = location + '/Site.zip'
249
+ config[:properties][:packageassinglefile] = true
250
+
251
+ config[:properties][:solutiondir] = windowsize_path(File.expand_path('.') + '//')
252
+ end
253
+
254
+ end
255
+
256
+ class WebProject2008 < Project
257
+
258
+ require 'zip/zip'
259
+
260
+ def build(configuration)
261
+ super
262
+
263
+ zip_website if configuration[:websites_as_zip]
264
+ end
265
+
266
+ def zip_website
267
+ zip_file = zip_location_dir 'Site.zip'
268
+
269
+ Dir["#{location}/**/**"].reject { |f| f == zip_file }.each do |file|
270
+ FileUtils.rm_rf file
271
+ end
272
+ end
273
+
274
+ def zip_location_dir(zip_file_name)
275
+ zip_path = location + "/#{zip_file_name}"
276
+
277
+ Zip::ZipFile.open(zip_path, Zip::ZipFile::CREATE) do |zipfile|
278
+ Dir["#{location}/**/**"].each do |file|
279
+ zipfile.add(file.sub(location + '/', ''), file)
280
+ end
281
+ end
282
+
283
+ zip_path
284
+ end
285
+
286
+ def populate_config(config)
287
+ config[:targets] << :'ResolveReferences'
288
+ config[:targets] << :'_CopyWebApplication'
289
+
290
+ config[:properties][:OutDir] = location + '/bin/'
291
+ config[:properties][:WebProjectOutputDir] = windowsize_path location
292
+ config[:properties][:_DebugSymbolsProduced] = false
293
+
294
+ config[:properties][:solutiondir] = windowsize_path(File.expand_path('.') + '//')
295
+ end
296
+
297
+ end
298
+
299
+ end