bozo-scripts 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWU0ZDc5OTZmMzg4ZGVhOTY4YThjODFjN2UxOTM4MDZiMjQ5OTY2Mw==
5
+ data.tar.gz: !binary |-
6
+ YjBhYjc3MmJhZTdjOGQ5ZGE5Nzg2Y2Y2YzFlM2Y2N2ViNGUxODkzYg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ M2U0NTc5ZGZmZjkxOGY3OGM2Zjc5YjZjZTBjM2Q4ZWZhNzcxYjI5NDEwMjg5
10
+ ZGI0YTkyOTUwZWZhYTAyNDExZDc4OTE1ZmFlOGVmMmQyOTFhYjdjOTRmMmU4
11
+ MjYzZmM2N2QwZTc4MDcyZTJmNzIyNDQzZjQ3MDBjNWMwZGUzMGI=
12
+ data.tar.gz: !binary |-
13
+ NDVkYTgxMTBhM2ZjNjEzNjFkMzc4NjE0ZjMxMzNkNjMxMzI4OWMyMDI3NGE3
14
+ ZWE1Y2Q0MzliN2YxNWM1ZTAxZGUyYzY3ZTY2OWM3YjZhYmVjMTdmYjM3YzVm
15
+ ZTZlOWJmYWU1MjAzOGY1YjQyYzI4NDZiMzBkNTFhOTQxYzdkMjI=
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.10
1
+ 0.1.11
@@ -1,279 +1,299 @@
1
- require 'nokogiri'
2
-
3
- module Bozo::Compilers
4
-
5
- class Msbuild
6
-
7
- def config_with_defaults
8
- defaults = {
9
- :version => 'v4.0.30319',
10
- :framework => 'Framework64',
11
- :properties => {:configuration => :release},
12
- :max_cores => nil
13
- }
14
-
15
- default_targets = [:build]
16
-
17
- config = defaults.merge @config
18
- config[:targets] = (@targets or default_targets).clone
19
- config[:websites_as_zip] = false
20
- config
21
- end
22
-
23
- def initialize
24
- @config = {}
25
- @exclude_projects = []
26
- end
27
-
28
- def version(version)
29
- @config[:version] = version
30
- end
31
-
32
- def framework(framework)
33
- @config[:framework] = framework
34
- end
35
-
36
- def solution(path)
37
- @config[:solution] = path
38
- end
39
-
40
- def property(args)
41
- @config[:properties] ||= {}
42
- @config[:properties] = @config[:properties].merge(args)
43
- end
44
-
45
- def exclude_project(project_name)
46
- @exclude_projects << project_name
47
- end
48
-
49
- def websites_as_zip?
50
- @config[:websites_as_zip] = true
51
- end
52
-
53
- # Assign how many cores should be used by msbuild
54
- #
55
- # @param [Integer] cores
56
- # The maximum number of cores to allow msbuild to use
57
- def max_cores(cores)
58
- @config[:max_cores] = cores
59
- end
60
-
61
- alias :properties :property
62
-
63
- def target(target)
64
- @targets ||= []
65
- @targets << target
66
- end
67
-
68
- def to_s
69
- config = configuration
70
- "Compile with msbuild #{config[:version]} building #{config[:solution]} with properties #{config[:properties]} for targets #{config[:targets]}"
71
- end
72
-
73
- def without_stylecop
74
- @config[:without_stylecop] = true
75
- end
76
-
77
- def configuration
78
- config_with_defaults
79
- end
80
-
81
- def execute
82
- projects = (project_files('test') | project_files('src')).map { |file| create_project file }
83
-
84
- # Clean all the projects first.
85
- projects.each do |project|
86
- project.clean configuration
87
- end
88
-
89
- # Build all the projects so they can utilize each others artifacts.
90
- projects.each do |project|
91
- project.build configuration
92
- end
93
- end
94
-
95
- def project_files(directory)
96
- project_file_matcher = File.expand_path(File.join(directory, 'csharp', '**', '*.csproj'))
97
- Dir[project_file_matcher].select { |p| not @exclude_projects.include?(File.basename p, '.csproj') }
98
- end
99
-
100
- def required_tools
101
- :stylecop unless @config[:without_stylecop]
102
- end
103
-
104
- private
105
-
106
- # Creates a project based on the project_file type.
107
- # Defaults to a class library project if it cannot be determined.
108
- # @return [Project]
109
- def create_project(project_file)
110
- project_name = File.basename(project_file).gsub(/\.csproj$/, '')
111
- log_debug project_name
112
-
113
- project_class_for(project_file).new project_file, project_name
114
- end
115
-
116
- # @return [Class]
117
- def project_class_for(project_file)
118
- project_types = project_types_from project_file
119
- web_app_type = '{349c5851-65df-11da-9384-00065b846f21}'
120
- if tools_version(project_file) == "3.5"
121
- project_types.include?(web_app_type) ? WebProject2008 : ClassLibrary
122
- else
123
- project_types.include?(web_app_type) ? WebProject2010 : ClassLibrary
124
- end
125
- end
126
-
127
- # @return [Array]
128
- def project_types_from(project_file)
129
- project_types = []
130
-
131
- File.open(project_file) do |f|
132
- element = Nokogiri::XML(f).css('Project PropertyGroup ProjectTypeGuids').first
133
- project_types = element.content.split(';').map {|e| e.downcase } unless element.nil?
134
- end
135
-
136
- project_types
137
- end
138
-
139
- def tools_version(project_file)
140
- tools_version = nil
141
-
142
- File.open(project_file) do |f|
143
- element = Nokogiri::XML(f).css('Project').first
144
- tools_version = element['ToolsVersion'] unless element.nil?
145
- end
146
-
147
- tools_version
148
- end
149
-
150
- end
151
-
152
- private
153
-
154
- class Project
155
-
156
- include Bozo::Runner
157
-
158
- def initialize(project_file, project_name)
159
- @project_file = project_file
160
- @project_name = project_name
161
- end
162
-
163
- def build(configuration)
164
- populate_config(configuration)
165
- args = generate_args configuration
166
- execute_command :msbuild, args
167
- end
168
-
169
- def clean(configuration)
170
- configuration[:targets] = [:clean]
171
- args = generate_args configuration
172
- execute_command :msbuild, args
173
- end
174
-
175
- def framework_version
176
- framework_version = 'unknown'
177
-
178
- File.open(@project_file) do |f|
179
- framework_version = Nokogiri::XML(f).css('Project PropertyGroup TargetFrameworkVersion').first.content
180
- framework_version = framework_version.sub('v', 'net').sub('.', '')
181
- end
182
-
183
- framework_version
184
- end
185
-
186
- def generate_args(config)
187
- args = []
188
-
189
- args << File.join(ENV['WINDIR'], 'Microsoft.NET', config[:framework], config[:version], 'msbuild.exe')
190
- args << '/nologo'
191
- args << '/verbosity:normal'
192
- args << '/nodeReuse:false'
193
- args << "/target:#{config[:targets].map{|t| t.to_s}.join(';')}"
194
- args << "/maxcpucount" if config[:max_cores].nil? # let msbuild decide how many cores to use
195
- args << "/maxcpucount:#{config[:max_cores]}" unless config[:max_cores].nil? # specifying the number of cores
196
-
197
- config[:properties].each do |key, value|
198
- args << "/property:#{key}=\"#{value}\""
199
- end
200
-
201
- args << "\"#{@project_file}\""
202
- end
203
-
204
- def windowsize_path(path)
205
- path.gsub(/\//, '\\')
206
- end
207
-
208
- def location
209
- File.expand_path(File.join('temp', 'msbuild', @project_name, framework_version))
210
- end
211
-
212
- end
213
-
214
- class ClassLibrary < Project
215
-
216
- def populate_config(config)
217
- config[:properties][:outputpath] = location + '/'
218
- config[:properties][:solutiondir] = windowsize_path(File.expand_path('.') + '//')
219
- end
220
-
221
- end
222
-
223
- class WebProject2010 < Project
224
-
225
- def populate_config(config)
226
- config[:targets] << :package
227
-
228
- config[:properties][:packagelocation] = location + '/Site.zip'
229
- config[:properties][:packageassinglefile] = true
230
-
231
- config[:properties][:solutiondir] = windowsize_path(File.expand_path('.') + '//')
232
- end
233
-
234
- end
235
-
236
- class WebProject2008 < Project
237
-
238
- require 'zip/zip'
239
-
240
- def build(configuration)
241
- super
242
-
243
- zip_website if configuration[:websites_as_zip]
244
- end
245
-
246
- def zip_website
247
- zip_file = zip_location_dir 'Site.zip'
248
-
249
- Dir["#{location}/**/**"].reject { |f| f == zip_file }.each do |file|
250
- FileUtils.rm_rf file
251
- end
252
- end
253
-
254
- def zip_location_dir(zip_file_name)
255
- zip_path = location + "/#{zip_file_name}"
256
-
257
- Zip::ZipFile.open(zip_path, Zip::ZipFile::CREATE) do |zipfile|
258
- Dir["#{location}/**/**"].each do |file|
259
- zipfile.add(file.sub(location + '/', ''), file)
260
- end
261
- end
262
-
263
- zip_path
264
- end
265
-
266
- def populate_config(config)
267
- config[:targets] << :'ResolveReferences'
268
- config[:targets] << :'_CopyWebApplication'
269
-
270
- config[:properties][:OutDir] = location + '/bin/'
271
- config[:properties][:WebProjectOutputDir] = windowsize_path location
272
- config[:properties][:_DebugSymbolsProduced] = false
273
-
274
- config[:properties][:solutiondir] = windowsize_path(File.expand_path('.') + '//')
275
- end
276
-
277
- end
278
-
279
- 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