bozo-scripts 0.1.6 → 0.1.7

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.6
1
+ 0.1.7
@@ -1,279 +1,279 @@
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
+
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