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,41 +1,41 @@
1
- module Bozo::Hooks
2
-
3
- class Timing
4
-
5
- def initialize
6
- @timings = {}
7
- end
8
-
9
- def print_timings
10
- puts ''
11
- @timings.each do |stage, times|
12
- puts format_timing(stage, times).bright.color(stage == :build ? :cyan : :black)
13
- end
14
- end
15
-
16
- def format_timing(stage, args)
17
- time_taken = (args[:post] - args[:pre]).round(1)
18
- "#{stage.to_s.capitalize.ljust(14)} #{time_taken.to_s.rjust(5)}s"
19
- end
20
-
21
- def record(stage, point)
22
- @timings[stage] ||= {}
23
- @timings[stage][point] = Time.now
24
- end
25
-
26
- def method_missing(method, *args)
27
- if method.to_s =~ /^(pre|post)_(.+)/
28
- record $2.to_sym, $1.to_sym
29
- print_timings if $1 == 'post' and $2 == 'build'
30
- else
31
- super
32
- end
33
- end
34
-
35
- def respond_to?(method)
36
- method.to_s =~ /^(pre|post)_(.+)/ or super
37
- end
38
-
39
- end
40
-
1
+ module Bozo::Hooks
2
+
3
+ class Timing
4
+
5
+ def initialize
6
+ @timings = {}
7
+ end
8
+
9
+ def print_timings
10
+ puts ''
11
+ @timings.each do |stage, times|
12
+ puts format_timing(stage, times).bright.color(stage == :build ? :cyan : :black)
13
+ end
14
+ end
15
+
16
+ def format_timing(stage, args)
17
+ time_taken = (args[:post] - args[:pre]).round(1)
18
+ "#{stage.to_s.capitalize.ljust(14)} #{time_taken.to_s.rjust(5)}s"
19
+ end
20
+
21
+ def record(stage, point)
22
+ @timings[stage] ||= {}
23
+ @timings[stage][point] = Time.now
24
+ end
25
+
26
+ def method_missing(method, *args)
27
+ if method.to_s =~ /^(pre|post)_(.+)/
28
+ record $2.to_sym, $1.to_sym
29
+ print_timings if $1 == 'post' and $2 == 'build'
30
+ else
31
+ super
32
+ end
33
+ end
34
+
35
+ def respond_to?(method)
36
+ method.to_s =~ /^(pre|post)_(.+)/ or super
37
+ end
38
+
39
+ end
40
+
41
41
  end
@@ -1,220 +1,229 @@
1
- require 'nokogiri'
2
-
3
- module Bozo::Packagers
4
-
5
- class Nuget
6
-
7
- def initialize
8
- @libraries = []
9
- @executables = []
10
- @websites = []
11
- end
12
-
13
- def destination(destination)
14
- @destination = destination
15
- end
16
-
17
- def library(project)
18
- @libraries << LibraryPackage.new(project, self)
19
- end
20
-
21
- def executable(project)
22
- @executables << ExecutablePackage.new(project)
23
- end
24
-
25
- def website(project)
26
- @websites << WebsitePackage.new(project)
27
- end
28
-
29
- def required_tools
30
- :nuget
31
- end
32
-
33
- def project_url(url)
34
- @project_url = url
35
- end
36
-
37
- def license_url(url)
38
- @license_url = url
39
- end
40
-
41
- def author(author)
42
- @author = author
43
- end
44
-
45
- def to_s
46
- "Publish projects with nuget #{@libraries | @executables | @websites} to #{@destination}"
47
- end
48
-
49
- def execute
50
- @libraries.each {|project| package project}
51
- @executables.each {|project| package project}
52
- @websites.each {|project| package project}
53
- end
54
-
55
- # Returns the version that the package should be given.
56
- def package_version
57
- env['BUILD_VERSION']
58
- end
59
-
60
- private
61
-
62
- def package(project)
63
- spec_path = generate_specification(project)
64
- create_package(project.name, spec_path, true)
65
- end
66
-
67
- def generate_specification(project)
68
- log_debug "Generating specification for #{project.name}"
69
- builder = Nokogiri::XML::Builder.new do |doc|
70
- doc.package(:xmlns => "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd") do
71
- doc.metadata do
72
- doc.id project.name
73
- doc.version_ package_version
74
- doc.authors @author
75
- doc.description project.name
76
- doc.projectUrl @project_url
77
- doc.licenseUrl @license_url
78
- doc.dependencies do
79
- project.dependencies.each do |dep|
80
- doc.dependency(dep)
81
- end
82
- end
83
- end
84
- doc.files do
85
- project.files.each do |file|
86
- doc.file(file)
87
- end
88
- end
89
- end
90
- end
91
- spec_path = File.expand_path(File.join('temp', 'nuget', "#{project.name}.nuspec"))
92
- FileUtils.mkdir_p File.dirname(spec_path)
93
- File.open(spec_path, 'w+') {|f| f.write(builder.to_xml)}
94
- spec_path
95
- end
96
-
97
- def create_package(project, spec_path, omit_analysis = false)
98
- args = []
99
-
100
- dist_dir = File.expand_path(File.join('dist', 'nuget'))
101
-
102
- args << File.expand_path(File.join('build', 'tools', 'nuget', 'NuGet.exe'))
103
- args << 'pack'
104
- args << "\"#{spec_path}\""
105
- args << '-OutputDirectory'
106
- args << "\"#{dist_dir}\""
107
- args << '-NoPackageAnalysis' if omit_analysis
108
-
109
- # Ensure the directory is there because Nuget won't make it
110
- FileUtils.mkdir_p dist_dir
111
-
112
- log_debug "Creating nuget package for #{project}"
113
-
114
- execute_command :nuget, args
115
- end
116
-
117
- end
118
-
119
- private
120
-
121
- class ExecutablePackage
122
-
123
- def initialize(project)
124
- @name = project
125
- end
126
-
127
- def name
128
- @name
129
- end
130
-
131
- def dependencies
132
- []
133
- end
134
-
135
- def files
136
- [{:src => File.expand_path(File.join('temp', 'msbuild', @name, '**', '*.*')).gsub(/\//, '\\'), :target => 'exe'}]
137
- end
138
-
139
- end
140
-
141
- class LibraryPackage
142
-
143
- def initialize(project, nuget)
144
- @name = project
145
- @nuget = nuget
146
- end
147
-
148
- def name
149
- @name
150
- end
151
-
152
- def dependencies
153
- project_reference_dependencies + nuget_dependencies
154
- end
155
-
156
- def files
157
- %w{dll pdb xml}.map do |extension|
158
- {:src => File.expand_path(File.join('temp', 'msbuild', @name, '**', "#{@name}.#{extension}")).gsub(/\//, '\\'), :target => 'lib'}
159
- end
160
- end
161
-
162
- private
163
-
164
- def project_reference_dependencies
165
- doc = Nokogiri::XML(File.open(project_file))
166
-
167
- doc.xpath('//proj:Project/proj:ItemGroup/proj:ProjectReference/proj:Name', {"proj" => "http://schemas.microsoft.com/developer/msbuild/2003"}).map do |node|
168
- {:id => node.text, :version => "[#{@nuget.package_version}]"}
169
- end
170
- end
171
-
172
- # get dependencies from packages.config
173
- def nuget_dependencies
174
- package_file = packages_file
175
- return [] unless File.exist? package_file
176
-
177
- doc = Nokogiri::XML(File.open(package_file))
178
-
179
- doc.xpath('//packages/package').map do |node|
180
- {:id => node[:id], :version => "[#{node[:version]}]"}
181
- end
182
- end
183
-
184
- def packages_file
185
- find_file_in_project 'packages.config'
186
- end
187
-
188
- def project_file
189
- find_file_in_project "#{@name}.csproj"
190
- end
191
-
192
- def find_file_in_project(file_name)
193
- file = File.expand_path(File.join('src', 'csharp', @name, file_name))
194
- file = File.expand_path(File.join('test', 'csharp', @name, file_name)) unless File.exist? file
195
- file
196
- end
197
-
198
- end
199
-
200
- class WebsitePackage
201
-
202
- def initialize(project)
203
- @name = project
204
- end
205
-
206
- def name
207
- @name
208
- end
209
-
210
- def dependencies
211
- []
212
- end
213
-
214
- def files
215
- [{:src => File.expand_path(File.join('temp', 'msbuild', @name, '**', '*.*')).gsub(/\//, '\\'), :target => 'website'}]
216
- end
217
-
218
- end
219
-
220
- end
1
+ require 'nokogiri'
2
+
3
+ module Bozo::Packagers
4
+
5
+ class Nuget
6
+
7
+ def initialize
8
+ @libraries = []
9
+ @executables = []
10
+ @websites = []
11
+ end
12
+
13
+ def destination(destination)
14
+ @destination = destination
15
+ end
16
+
17
+ def library(project, *extfiles)
18
+ @libraries << LibraryPackage.new(project, extfiles, self)
19
+ end
20
+
21
+ def executable(project)
22
+ @executables << ExecutablePackage.new(project)
23
+ end
24
+
25
+ def website(project)
26
+ @websites << WebsitePackage.new(project)
27
+ end
28
+
29
+ def required_tools
30
+ :nuget
31
+ end
32
+
33
+ def project_url(url)
34
+ @project_url = url
35
+ end
36
+
37
+ def license_url(url)
38
+ @license_url = url
39
+ end
40
+
41
+ def author(author)
42
+ @author = author
43
+ end
44
+
45
+ def to_s
46
+ "Publish projects with nuget #{@libraries | @executables | @websites} to #{@destination}"
47
+ end
48
+
49
+ def execute
50
+ @libraries.each {|project| package project}
51
+ @executables.each {|project| package project}
52
+ @websites.each {|project| package project}
53
+ end
54
+
55
+ # Returns the version that the package should be given.
56
+ def package_version
57
+ env['BUILD_VERSION']
58
+ end
59
+
60
+ private
61
+
62
+ def package(project)
63
+ spec_path = generate_specification(project)
64
+ create_package(project.name, spec_path, true)
65
+ end
66
+
67
+ def generate_specification(project)
68
+ log_debug "Generating specification for #{project.name}"
69
+ builder = Nokogiri::XML::Builder.new do |doc|
70
+ doc.package(:xmlns => "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd") do
71
+ doc.metadata do
72
+ doc.id project.name
73
+ doc.version_ package_version
74
+ doc.authors @author
75
+ doc.description project.name
76
+ doc.projectUrl @project_url
77
+ doc.licenseUrl @license_url
78
+ doc.dependencies do
79
+ project.dependencies.each do |dep|
80
+ doc.dependency(dep)
81
+ end
82
+ end
83
+ end
84
+ doc.files do
85
+ project.files.each do |file|
86
+ doc.file(file)
87
+ end
88
+ end
89
+ end
90
+ end
91
+ spec_path = File.expand_path(File.join('temp', 'nuget', "#{project.name}.nuspec"))
92
+ FileUtils.mkdir_p File.dirname(spec_path)
93
+ File.open(spec_path, 'w+') {|f| f.write(builder.to_xml)}
94
+ spec_path
95
+ end
96
+
97
+ def create_package(project, spec_path, omit_analysis = false)
98
+ args = []
99
+
100
+ dist_dir = File.expand_path(File.join('dist', 'nuget'))
101
+
102
+ args << File.expand_path(File.join('build', 'tools', 'nuget', 'NuGet.exe'))
103
+ args << 'pack'
104
+ args << "\"#{spec_path}\""
105
+ args << '-OutputDirectory'
106
+ args << "\"#{dist_dir}\""
107
+ args << '-NoPackageAnalysis' if omit_analysis
108
+
109
+ # Ensure the directory is there because Nuget won't make it
110
+ FileUtils.mkdir_p dist_dir
111
+
112
+ log_debug "Creating nuget package for #{project}"
113
+
114
+ execute_command :nuget, args
115
+ end
116
+
117
+ end
118
+
119
+ private
120
+
121
+ class ExecutablePackage
122
+
123
+ def initialize(project)
124
+ @name = project
125
+ end
126
+
127
+ def name
128
+ @name
129
+ end
130
+
131
+ def dependencies
132
+ []
133
+ end
134
+
135
+ def files
136
+ [{:src => File.expand_path(File.join('temp', 'msbuild', @name, '**', '*.*')).gsub(/\//, '\\'), :target => 'exe'}]
137
+ end
138
+
139
+ end
140
+
141
+ class LibraryPackage
142
+
143
+ def initialize(project, extfiles, nuget)
144
+ @name = project
145
+ @nuget = nuget
146
+ @extfiles = extfiles
147
+ end
148
+
149
+ def name
150
+ @name
151
+ end
152
+
153
+ def dependencies
154
+ project_reference_dependencies + nuget_dependencies
155
+ end
156
+
157
+ def files
158
+ files = []
159
+
160
+ %w{dll pdb xml}.map do |extension|
161
+ files << {:src => File.expand_path(File.join('temp', 'msbuild', @name, '**', "#{@name}.#{extension}")).gsub(/\//, '\\'), :target => 'lib'}
162
+ end
163
+
164
+ @extfiles.map do |file|
165
+ files << {:src => File.expand_path(File.join('temp', 'msbuild', @name, '**', file)).gsub(/\//, '\\'), :target => 'lib'}
166
+ end
167
+
168
+ files
169
+ end
170
+
171
+ private
172
+
173
+ def project_reference_dependencies
174
+ doc = Nokogiri::XML(File.open(project_file))
175
+
176
+ doc.xpath('//proj:Project/proj:ItemGroup/proj:ProjectReference/proj:Name', {"proj" => "http://schemas.microsoft.com/developer/msbuild/2003"}).map do |node|
177
+ {:id => node.text, :version => "[#{@nuget.package_version}]"}
178
+ end
179
+ end
180
+
181
+ # get dependencies from packages.config
182
+ def nuget_dependencies
183
+ package_file = packages_file
184
+ return [] unless File.exist? package_file
185
+
186
+ doc = Nokogiri::XML(File.open(package_file))
187
+
188
+ doc.xpath('//packages/package').map do |node|
189
+ {:id => node[:id], :version => "[#{node[:version]}]"}
190
+ end
191
+ end
192
+
193
+ def packages_file
194
+ find_file_in_project 'packages.config'
195
+ end
196
+
197
+ def project_file
198
+ find_file_in_project "#{@name}.csproj"
199
+ end
200
+
201
+ def find_file_in_project(file_name)
202
+ file = File.expand_path(File.join('src', 'csharp', @name, file_name))
203
+ file = File.expand_path(File.join('test', 'csharp', @name, file_name)) unless File.exist? file
204
+ file
205
+ end
206
+
207
+ end
208
+
209
+ class WebsitePackage
210
+
211
+ def initialize(project)
212
+ @name = project
213
+ end
214
+
215
+ def name
216
+ @name
217
+ end
218
+
219
+ def dependencies
220
+ []
221
+ end
222
+
223
+ def files
224
+ [{:src => File.expand_path(File.join('temp', 'msbuild', @name, '**', '*.*')).gsub(/\//, '\\'), :target => 'website'}]
225
+ end
226
+
227
+ end
228
+
229
+ end
@@ -1,50 +1,50 @@
1
- module Bozo::Packagers
2
-
3
- # Specifies gem packager.
4
- #
5
- # Builds any '*.gemspec' file in the root directory
6
- class Rubygems
7
-
8
- def execute
9
- dist_dir = File.expand_path(File.join('dist', 'gem'))
10
- FileUtils.mkdir_p dist_dir
11
-
12
- Dir['*.gemspec'].each { |spec| build_gem spec }
13
- Dir['*.gem'].each { |file| FileUtils.mv file, File.join(dist_dir, file) }
14
- end
15
-
16
- private
17
-
18
- def build_gem(spec)
19
- if pre_release?
20
- package_version.write_to_file
21
- end
22
-
23
- begin
24
- execute_command :rubygems, ['gem', 'build', spec]
25
- ensure
26
- if pre_release?
27
- version.write_to_file
28
- end
29
- end
30
- end
31
-
32
- def package_version
33
- RubyGemVersion.parse(env['BUILD_VERSION'])
34
- end
35
-
36
- class RubyGemVersion < Bozo::Versioning::Version
37
-
38
- def self.parse(version)
39
- new version.major, version.minor, version.patch, version.extension
40
- end
41
-
42
- def to_s
43
- "#{major}.#{minor}.#{patch}.#{extension}"
44
- end
45
-
46
- end
47
-
48
- end
49
-
1
+ module Bozo::Packagers
2
+
3
+ # Specifies gem packager.
4
+ #
5
+ # Builds any '*.gemspec' file in the root directory
6
+ class Rubygems
7
+
8
+ def execute
9
+ dist_dir = File.expand_path(File.join('dist', 'gem'))
10
+ FileUtils.mkdir_p dist_dir
11
+
12
+ Dir['*.gemspec'].each { |spec| build_gem spec }
13
+ Dir['*.gem'].each { |file| FileUtils.mv file, File.join(dist_dir, file) }
14
+ end
15
+
16
+ private
17
+
18
+ def build_gem(spec)
19
+ if pre_release?
20
+ package_version.write_to_file
21
+ end
22
+
23
+ begin
24
+ execute_command :rubygems, ['gem', 'build', spec]
25
+ ensure
26
+ if pre_release?
27
+ version.write_to_file
28
+ end
29
+ end
30
+ end
31
+
32
+ def package_version
33
+ RubyGemVersion.parse(env['BUILD_VERSION'])
34
+ end
35
+
36
+ class RubyGemVersion < Bozo::Versioning::Version
37
+
38
+ def self.parse(version)
39
+ new version.major, version.minor, version.patch, version.extension
40
+ end
41
+
42
+ def to_s
43
+ "#{major}.#{minor}.#{patch}.#{extension}"
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
50
  end