albacore 2.0.10 → 2.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a54136d8ddfcc5f989ed22bc5861633cba7c6e4
4
- data.tar.gz: 88631f2a41d58d4371378cffc69f89928a9e237d
3
+ metadata.gz: 1308f930ad75cb7e143505c49a53db15aaa988f7
4
+ data.tar.gz: 74473ea92736a01c725e0bbfb5ed36d2421f2a46
5
5
  SHA512:
6
- metadata.gz: f55ecffe6c6de57f1bdcf25456fcb2528ad88c825a2e551dbab671d669dca48e6a0ede8766460123808ae8e1aec9c6dad7ca66b626b083fa7f40b92f7e631bce
7
- data.tar.gz: af6aa9a945778db05d54723f9f2843f3f9c352e3c03508ee5c2d7bb17e169ee40a987f678efb389f50dd17d48ff83637555a728c04d6e953172f8d138556c77b
6
+ metadata.gz: 261d88d30963978abcb8595af5838b52f34c698bbc88fa61bcb207958208e8c4ee2ca494a8578ffab77e837864e81f519d65008128c0eedaa6cf8061177fac42
7
+ data.tar.gz: 6e347fca7aab405e99592826958a9ff6e069a310b627222f373f57f1ac9612ba3b42fa25f08fcd7d80779cc44546c5962688ac367b5f89a012379214543a4aad
@@ -1,405 +1,421 @@
1
- require 'rake'
2
- require 'nokogiri'
3
- require 'fileutils'
4
- require 'albacore'
5
- require 'albacore/paths'
6
- require 'albacore/cmd_config'
7
- require 'albacore/config_dsl'
8
- require 'albacore/cross_platform_cmd'
9
- require 'albacore/project'
10
- require 'albacore/logging'
11
- require 'albacore/nuget_model'
12
-
13
- module Albacore
14
- module NugetsPack
15
- # the nuget command
16
- class Cmd
17
- include CrossPlatformCmd
18
-
19
- # executable => the nuget executable
20
- def initialize executable, *args
21
- opts = Map.options args
22
- raise ArgumentError, 'out is nil' if opts.getopt(:out).nil?
23
-
24
- @work_dir = opts.getopt :work_dir, default: nil
25
- @executable = executable
26
- @parameters = [%W{Pack -OutputDirectory #{opts.get(:out)}}].flatten
27
- @opts = opts
28
-
29
- mono_command
30
- end
31
-
32
- # run nuget on the nuspec to create a new package
33
- # returns: a tuple-array of the package and the symbol package
34
- # of which the symbol package is nil if it was not generated
35
- def execute nuspec_file, nuspec_symbols_file = nil
36
- debug "NugetsPack::Cmd#execute, opts: #{@opts} [nugets pack: cmd]"
37
- original_pars = @parameters.dup
38
-
39
- pars = original_pars.dup
40
- pars << nuspec_file
41
- pkg = get_nuget_path_of do
42
- system @executable, pars, :work_dir => @work_dir
43
- end
44
-
45
- debug "package at '#{pkg}'"
46
-
47
- # if the symbols flag is set and there's a symbols file specified
48
- # then run NuGet.exe to generate the .symbols.nupkg file
49
- if nuspec_symbols_file
50
- pars = original_pars.dup
51
- pars << '-Symbols'
52
- pars << nuspec_symbols_file
53
- spkg = with_subterfuge pkg do
54
- get_nuget_path_of do
55
- system @executable, pars, :work_dir => @work_dir
56
- end
57
- end
58
-
59
- debug "symbol package at '#{spkg}'"
60
-
61
- [pkg, spkg]
62
- else
63
- info "symbols not configured for generation, use Config#gen_symbols to do so [nugets pack: cmd]"
64
- [pkg, nil]
65
- end
66
- end
67
-
68
- private
69
-
70
- # regexpes the package path from the output
71
- def get_nuget_path_of
72
- out = yield
73
- out.match /Successfully created package '([:\s\w\\\/\d\.]+\.symbols\.nupkg)'./i if out.respond_to? :match
74
- trace "Got symbols return value: '#{out}', matched: '#{$1}'" if $1
75
- return $1 if $1
76
-
77
- out.match /Successfully created package '([:\s\w\\\/\d\.]+\.nupkg)'./i if out.respond_to? :match
78
- trace "Got NOT-symbols return value: '#{out}', matched: '#{$1}'"
79
- $1
80
- end
81
-
82
- # hide the original like a ninja while NuGet whimpers in a corner
83
- def with_subterfuge pkg
84
- FileUtils.mv pkg, "#{pkg}.tmp" if pkg && File.exists?(pkg)
85
- res = yield
86
- FileUtils.mv "#{pkg}.tmp", pkg if pkg && File.exists?("#{pkg}.tmp")
87
- res
88
- end
89
- end
90
-
91
- # This tasktype allows you to quickly package project files to nuget
92
- # packages.
93
- #
94
- # Point files to the project files, that should be in MsBuild XML.
95
- #
96
- # Examples
97
- #
98
- # nugets_pack :pack => ['build/pkg', :versioning] do |p|
99
- # p.files = FileList['src/**/*.csproj']
100
- # p.out = 'build/pkg'
101
- # p.exe = 'buildsupport/NuGet.exe'
102
- # p.with_metadata do |m|
103
- # m.version = ENV['NUGET_VERSION']
104
- # end
105
- # p.gen_symbols
106
- # p.no_project_dependencies
107
- # end
108
- class Config
109
- include CmdConfig
110
- self.extend ConfigDSL
111
-
112
- # the output directory to place the newfangled nugets in
113
- attr_path :out
114
-
115
- # the .net target (e.g. net40, mono20, mono3, etc)
116
- attr_writer :target
117
-
118
- # sets the files to search
119
- attr_writer :files
120
-
121
- # sets the MsBuild configuration that is used to produce the output into
122
- # <OutputPath>...</OutputPath>
123
- attr_writer :configuration
124
-
125
- def initialize
126
- @package = Albacore::NugetModel::Package.new
127
- @target = 'net40'
128
- @symbols = false
129
- @project_dependencies = true
130
- @leave_nuspec = false
131
- fill_required
132
- end
133
-
134
- def with_metadata &block
135
- yield @package.metadata
136
- end
137
-
138
- # configure the package with a block
139
- def with_package &block
140
- yield @package
141
- end
142
-
143
- # generate symbols for the nugets: just call this method to
144
- # enable generation
145
- def gen_symbols
146
- @symbols = true
147
- end
148
-
149
- # leave the nuspec behind, don't delete it after generating it
150
- #
151
- def leave_nuspec
152
- @leave_nuspec = true
153
- end
154
-
155
- # call this if you want to cancel 'smart' scanning of the *proj
156
- # file for its dependencies
157
- def no_project_dependencies
158
- @project_dependencies = false
159
- end
160
-
161
- # gets the options specified for the task, used from the task
162
- def opts
163
- files = @files.respond_to?(:each) ? @files : [@files]
164
-
165
- [:authors, :description, :version].each do |required|
166
- warn "metadata##{required} is missing from nugets_pack [nugets pack: config]" if @package.metadata.send(required) == 'MISSING'
167
- end
168
-
169
- Map.new({
170
- :out => @out,
171
- :exe => @exe,
172
- :symbols => @symbols,
173
- :package => @package,
174
- :target => @target,
175
- :files => @files,
176
- :configuration => @configuration,
177
- :project_dependencies => @project_dependencies,
178
- :original_path => FileUtils.pwd,
179
- :leave_nuspec => @leave_nuspec
180
- })
181
- end
182
-
183
- private
184
-
185
- def fill_required
186
- # see http://docs.nuget.org/docs/reference/nuspec-reference
187
- with_metadata do |m|
188
- m.authors = m.description = m.version = 'MISSING'
189
- end
190
- end
191
- end
192
-
193
- # a task that handles the generation of nugets from projects or nuspecs.
194
- class ProjectTask
195
- include Logging
196
-
197
- def initialize opts, &before_execute
198
- raise ArgumentError, 'opts is not a map' unless opts.is_a? Map
199
- raise ArgumentError, 'no files given' unless opts.get(:files).length > 0
200
- @opts = opts.apply :out => '.'
201
- @files = opts.get :files
202
- @before_execute = before_execute
203
- end
204
-
205
- def execute
206
- knowns = compute_knowns
207
- @files.each do |p|
208
- proj, n, ns = generate_nuspec p, knowns
209
- execute_inner! proj, n, ns
210
- end
211
- end
212
-
213
- def path_to relative_file_path, cwd
214
- File.expand_path( File.join(@opts.get(:original_path), relative_file_path), cwd )
215
- end
216
-
217
- # generate all nuspecs
218
- def generate_nuspecs
219
- nuspecs = {}
220
- knowns = compute_knowns
221
- @files.each do |p|
222
- proj, n, ns = generate_nuspec p, knowns
223
- nuspecs[proj.name] = OpenStruct.new({:proj => proj, :nuspec => n, :nuspec_symbols => ns })
224
- end
225
- nuspecs
226
- end
227
-
228
- private
229
-
230
- def compute_knowns
231
- Set.new(@files.map { |f| Albacore::Project.new f }.map { |p| p.name })
232
- end
233
-
234
- def generate_nuspec p, knowns
235
- proj = Albacore::Project.new p
236
- nuspec, nuspec_symbols = create_nuspec proj, knowns
237
- [proj, nuspec, nuspec_symbols]
238
- end
239
-
240
- # execute, for each project file
241
- def execute_inner! proj, nuspec, nuspec_symbols
242
- nuspec_path = write_nuspec! proj, nuspec, false
243
- nuspec_symbols_path = write_nuspec! proj, nuspec_symbols, true if nuspec_symbols
244
-
245
- create_nuget! proj.proj_path_base, nuspec_path, nuspec_symbols_path
246
- rescue => e
247
- err (e.inspect)
248
- raise $!
249
- ensure
250
- trace do
251
- %{
252
- PROJECT #{proj.name} nuspec:
253
-
254
- #{nuspec.to_xml}
255
-
256
- PROJECT #{proj.name} symbol nuspec:
257
-
258
- #{if nuspec_symbols then nuspec_symbols.to_xml else 'NO SYMBOLS' end}}
259
- end
260
-
261
- # now remove them all
262
- [nuspec_path, nuspec_symbols_path].each{|n| cleanup_nuspec n}
263
- end
264
-
265
- ## Creating
266
-
267
- def create_nuspec proj, knowns
268
- version = @opts.get(:package).metadata.version
269
- project_dependencies = @opts.get(:project_dependencies, true)
270
- target = @opts.get :target
271
-
272
- trace "creating NON-SYMBOL package for '#{proj.name}', targeting '#{target}' [nugets pack: task]"
273
- nuspec = Albacore::NugetModel::Package.from_xxproj proj,
274
- symbols: false,
275
- verify_files: true,
276
- dotnet_version: target,
277
- known_projects: knowns,
278
- version: version,
279
- configuration: (@opts.get(:configuration)),
280
- project_dependencies: project_dependencies
281
-
282
- # take data from package as configured in Rakefile, choosing what is in
283
- # Rakefile over what is in projfile.
284
- nuspec = nuspec.merge_with @opts.get(:package)
285
- trace { "nuspec: #{nuspec.to_s} [nugets pack: task]" }
286
-
287
- if @opts.get(:symbols)
288
- trace { "creating SYMBOL package for '#{proj.name}' [nugets pack: task]" }
289
- nuspec_symbols = Albacore::NugetModel::Package.from_xxproj proj,
290
- symbols: true,
291
- verify_files: true,
292
- dotnet_version: target,
293
- known_projects: knowns,
294
- version: version,
295
- configuration: (@opts.get(:configuration)),
296
- project_dependencies: project_dependencies
297
-
298
- nuspec_symbols = nuspec_symbols.merge_with @opts.get(:package)
299
- trace { "nuspec symbols: #{nuspec_symbols.to_s} [nugets pack: task]" }
300
-
301
- [nuspec, nuspec_symbols]
302
- else
303
- trace { "skipping SYMBOL package for #{proj.name} [nugets pack: task]" }
304
- [nuspec, nil]
305
- end
306
- end
307
-
308
- def write_nuspec! proj, nuspec, symbols
309
- raise ArgumentError, "no nuspect metadata id, project at path: #{proj.proj_path_base}, nuspec: #{nuspec.inspect}" unless nuspec.metadata.id
310
- nuspec_path = File.join(proj.proj_path_base, nuspec.metadata.id + "#{ symbols ? '.symbols' : '' }.nuspec")
311
-
312
- File.write(nuspec_path, nuspec.to_xml)
313
-
314
- nuspec_path
315
- end
316
-
317
- def create_nuget! cwd, nuspec, nuspec_symbols = nil
318
- # create the command
319
- exe = path_to(@opts.get(:exe), cwd)
320
- out = path_to(@opts.get(:out), cwd)
321
- nuspec = path_to nuspec, cwd
322
- nuspec_symbols = path_to nuspec_symbols, cwd if nuspec_symbols
323
- cmd = Albacore::NugetsPack::Cmd.new exe,
324
- work_dir: cwd,
325
- out: out
326
-
327
- # run any concerns that modify the command
328
- @before_execute.call cmd if @before_execute
329
-
330
- debug { "generating nuspec at #{nuspec}, and symbols (possibly) at '#{nuspec_symbols}' [nugets pack: task]" }
331
-
332
- # run the command for the file
333
- pkg, spkg = cmd.execute nuspec, nuspec_symbols
334
-
335
- publish_artifact nuspec, pkg
336
- publish_artifact nuspec_symbols, spkg if spkg && nuspec_symbols
337
- end
338
-
339
- ## Cleaning up after generation
340
-
341
- def cleanup_nuspec nuspec
342
- return if nuspec.nil? or not File.exists? nuspec
343
- return if @opts.get :leave_nuspec, false
344
- File.delete nuspec
345
- end
346
-
347
- def publish_artifact nuspec, nuget
348
- Albacore.publish :artifact, OpenStruct.new(
349
- :nuspec => nuspec,
350
- :nupkg => nuget,
351
- :location => nuget
352
- )
353
- end
354
-
355
- def self.accept? f
356
- File.extname(f).downcase != '.nuspec'
357
- end
358
- end
359
-
360
- # generate a nuget from a nuspec
361
- class NuspecTask
362
- include Logging
363
-
364
- def initialize command_line, config, nuspec
365
- @config = config
366
- @nuspec = nuspec
367
- # is a NuspecPack::Cmd
368
- @command_line = command_line
369
- end
370
-
371
- def read_version_from_nuspec
372
- begin
373
- nuspec_file = File.open(@nuspec)
374
- xml = Nokogiri::XML(nuspec_file)
375
- nuspec_file.close
376
- nodes = xml.xpath('.//metadata/version')
377
- raise "No <version/> found" if nodes.empty?
378
- nodes.first.text()
379
- rescue => error
380
- err "Error reading package version from file: #{error}"
381
- raise
382
- end
383
- end
384
-
385
- def execute
386
- version = read_version_from_nuspec
387
- filename = File.basename(@nuspec, File.extname(@nuspec))
388
-
389
- @command_line.execute @nuspec
390
-
391
- path = File.join(@config.opts.get(:out), "#{filename}.#{version}.nupkg")
392
-
393
- Albacore.publish :artifact, OpenStruct.new(
394
- :nuspec => @nuspec,
395
- :nupkg => path,
396
- :location => path
397
- )
398
- end
399
-
400
- def self.accept? file
401
- File.extname(file).downcase == '.nuspec'
402
- end
403
- end
404
- end
405
- end
1
+ require 'rake'
2
+ require 'nokogiri'
3
+ require 'fileutils'
4
+ require 'albacore'
5
+ require 'albacore/paths'
6
+ require 'albacore/cmd_config'
7
+ require 'albacore/config_dsl'
8
+ require 'albacore/cross_platform_cmd'
9
+ require 'albacore/project'
10
+ require 'albacore/logging'
11
+ require 'albacore/nuget_model'
12
+
13
+ module Albacore
14
+ module NugetsPack
15
+ # the nuget command
16
+ class Cmd
17
+ include CrossPlatformCmd
18
+
19
+ # executable => the nuget executable
20
+ def initialize executable, *args
21
+ opts = Map.options args
22
+ raise ArgumentError, 'out is nil' if opts.getopt(:out).nil?
23
+
24
+ @work_dir = opts.getopt :work_dir, default: nil
25
+ @executable = executable
26
+ @parameters = [%W{Pack -OutputDirectory #{opts.get(:out)}}].flatten
27
+ @opts = opts
28
+
29
+ mono_command
30
+ end
31
+
32
+ # run nuget on the nuspec to create a new package
33
+ # returns: a tuple-array of the package and the symbol package
34
+ # of which the symbol package is nil if it was not generated
35
+ def execute nuspec_file, nuspec_symbols_file = nil
36
+ debug "NugetsPack::Cmd#execute, opts: #{@opts} [nugets pack: cmd]"
37
+ original_pars = @parameters.dup
38
+
39
+ pars = original_pars.dup
40
+ pars << nuspec_file
41
+ pkg = get_nuget_path_of do
42
+ system @executable, pars, :work_dir => @work_dir
43
+ end
44
+
45
+ debug "package at '#{pkg}'"
46
+
47
+ # if the symbols flag is set and there's a symbols file specified
48
+ # then run NuGet.exe to generate the .symbols.nupkg file
49
+ if nuspec_symbols_file
50
+ pars = original_pars.dup
51
+ pars << '-Symbols'
52
+ pars << nuspec_symbols_file
53
+ spkg = with_subterfuge pkg do
54
+ get_nuget_path_of do
55
+ system @executable, pars, :work_dir => @work_dir
56
+ end
57
+ end
58
+
59
+ debug "symbol package at '#{spkg}'"
60
+
61
+ [pkg, spkg]
62
+ else
63
+ info "symbols not configured for generation, use Config#gen_symbols to do so [nugets pack: cmd]"
64
+ [pkg, nil]
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ # regexpes the package path from the output
71
+ def get_nuget_path_of
72
+ out = yield
73
+ out.match /Successfully created package '([:\s\w\\\/\d\.\-]+\.symbols\.nupkg)'./i if out.respond_to? :match
74
+ trace "Got symbols return value: '#{out}', matched: '#{$1}'" if $1
75
+ return $1 if $1
76
+
77
+ out.match /Successfully created package '([:\s\w\\\/\d\.]+\.nupkg)'./i if out.respond_to? :match
78
+ trace "Got NOT-symbols return value: '#{out}', matched: '#{$1}'"
79
+
80
+ unless $1
81
+ args = ARGV.inject("") { |state, arg| state + " " + '"' + arg + '"' }
82
+ warn do
83
+ %{Couldn't match package, please run
84
+
85
+ bundle exec rake DEBUG=true #{args} --trace
86
+
87
+ and report a bug to albacore with the full output. Here's the nuget process output:
88
+ --- START OUTPUT ---
89
+ #{out}
90
+ --- END OUTPUT ---
91
+ }
92
+ end
93
+ end
94
+
95
+ $1
96
+ end
97
+
98
+ # hide the original like a ninja while NuGet whimpers in a corner
99
+ def with_subterfuge pkg
100
+ FileUtils.mv pkg, "#{pkg}.tmp" if pkg && File.exists?(pkg)
101
+ res = yield
102
+ FileUtils.mv "#{pkg}.tmp", pkg if pkg && File.exists?("#{pkg}.tmp")
103
+ res
104
+ end
105
+ end
106
+
107
+ # This tasktype allows you to quickly package project files to nuget
108
+ # packages.
109
+ #
110
+ # Point files to the project files, that should be in MsBuild XML.
111
+ #
112
+ # Examples
113
+ #
114
+ # nugets_pack :pack => ['build/pkg', :versioning] do |p|
115
+ # p.files = FileList['src/**/*.csproj']
116
+ # p.out = 'build/pkg'
117
+ # p.exe = 'buildsupport/NuGet.exe'
118
+ # p.with_metadata do |m|
119
+ # m.version = ENV['NUGET_VERSION']
120
+ # end
121
+ # p.gen_symbols
122
+ # p.no_project_dependencies
123
+ # end
124
+ class Config
125
+ include CmdConfig
126
+ self.extend ConfigDSL
127
+
128
+ # the output directory to place the newfangled nugets in
129
+ attr_path :out
130
+
131
+ # the .net target (e.g. net40, mono20, mono3, etc)
132
+ attr_writer :target
133
+
134
+ # sets the files to search
135
+ attr_writer :files
136
+
137
+ # sets the MsBuild configuration that is used to produce the output into
138
+ # <OutputPath>...</OutputPath>
139
+ attr_writer :configuration
140
+
141
+ def initialize
142
+ @package = Albacore::NugetModel::Package.new
143
+ @target = 'net40'
144
+ @symbols = false
145
+ @project_dependencies = true
146
+ @leave_nuspec = false
147
+ fill_required
148
+ end
149
+
150
+ def with_metadata &block
151
+ yield @package.metadata
152
+ end
153
+
154
+ # configure the package with a block
155
+ def with_package &block
156
+ yield @package
157
+ end
158
+
159
+ # generate symbols for the nugets: just call this method to
160
+ # enable generation
161
+ def gen_symbols
162
+ @symbols = true
163
+ end
164
+
165
+ # leave the nuspec behind, don't delete it after generating it
166
+ #
167
+ def leave_nuspec
168
+ @leave_nuspec = true
169
+ end
170
+
171
+ # call this if you want to cancel 'smart' scanning of the *proj
172
+ # file for its dependencies
173
+ def no_project_dependencies
174
+ @project_dependencies = false
175
+ end
176
+
177
+ # gets the options specified for the task, used from the task
178
+ def opts
179
+ files = @files.respond_to?(:each) ? @files : [@files]
180
+
181
+ [:authors, :description, :version].each do |required|
182
+ warn "metadata##{required} is missing from nugets_pack [nugets pack: config]" if @package.metadata.send(required) == 'MISSING'
183
+ end
184
+
185
+ Map.new({
186
+ :out => @out,
187
+ :exe => @exe,
188
+ :symbols => @symbols,
189
+ :package => @package,
190
+ :target => @target,
191
+ :files => @files,
192
+ :configuration => @configuration,
193
+ :project_dependencies => @project_dependencies,
194
+ :original_path => FileUtils.pwd,
195
+ :leave_nuspec => @leave_nuspec
196
+ })
197
+ end
198
+
199
+ private
200
+
201
+ def fill_required
202
+ # see http://docs.nuget.org/docs/reference/nuspec-reference
203
+ with_metadata do |m|
204
+ m.authors = m.description = m.version = 'MISSING'
205
+ end
206
+ end
207
+ end
208
+
209
+ # a task that handles the generation of nugets from projects or nuspecs.
210
+ class ProjectTask
211
+ include Logging
212
+
213
+ def initialize opts, &before_execute
214
+ raise ArgumentError, 'opts is not a map' unless opts.is_a? Map
215
+ raise ArgumentError, 'no files given' unless opts.get(:files).length > 0
216
+ @opts = opts.apply :out => '.'
217
+ @files = opts.get :files
218
+ @before_execute = before_execute
219
+ end
220
+
221
+ def execute
222
+ knowns = compute_knowns
223
+ @files.each do |p|
224
+ proj, n, ns = generate_nuspec p, knowns
225
+ execute_inner! proj, n, ns
226
+ end
227
+ end
228
+
229
+ def path_to relative_file_path, cwd
230
+ File.expand_path( File.join(@opts.get(:original_path), relative_file_path), cwd )
231
+ end
232
+
233
+ # generate all nuspecs
234
+ def generate_nuspecs
235
+ nuspecs = {}
236
+ knowns = compute_knowns
237
+ @files.each do |p|
238
+ proj, n, ns = generate_nuspec p, knowns
239
+ nuspecs[proj.name] = OpenStruct.new({:proj => proj, :nuspec => n, :nuspec_symbols => ns })
240
+ end
241
+ nuspecs
242
+ end
243
+
244
+ private
245
+
246
+ def compute_knowns
247
+ Set.new(@files.map { |f| Albacore::Project.new f }.map { |p| p.name })
248
+ end
249
+
250
+ def generate_nuspec p, knowns
251
+ proj = Albacore::Project.new p
252
+ nuspec, nuspec_symbols = create_nuspec proj, knowns
253
+ [proj, nuspec, nuspec_symbols]
254
+ end
255
+
256
+ # execute, for each project file
257
+ def execute_inner! proj, nuspec, nuspec_symbols
258
+ nuspec_path = write_nuspec! proj, nuspec, false
259
+ nuspec_symbols_path = write_nuspec! proj, nuspec_symbols, true if nuspec_symbols
260
+
261
+ create_nuget! proj.proj_path_base, nuspec_path, nuspec_symbols_path
262
+ rescue => e
263
+ err (e.inspect)
264
+ raise $!
265
+ ensure
266
+ trace do
267
+ %{
268
+ PROJECT #{proj.name} nuspec:
269
+
270
+ #{nuspec.to_xml}
271
+
272
+ PROJECT #{proj.name} symbol nuspec:
273
+
274
+ #{if nuspec_symbols then nuspec_symbols.to_xml else 'NO SYMBOLS' end}}
275
+ end
276
+
277
+ # now remove them all
278
+ [nuspec_path, nuspec_symbols_path].each{|n| cleanup_nuspec n}
279
+ end
280
+
281
+ ## Creating
282
+
283
+ def create_nuspec proj, knowns
284
+ version = @opts.get(:package).metadata.version
285
+ project_dependencies = @opts.get(:project_dependencies, true)
286
+ target = @opts.get :target
287
+
288
+ trace "creating NON-SYMBOL package for '#{proj.name}', targeting '#{target}' [nugets pack: task]"
289
+ nuspec = Albacore::NugetModel::Package.from_xxproj proj,
290
+ symbols: false,
291
+ verify_files: true,
292
+ dotnet_version: target,
293
+ known_projects: knowns,
294
+ version: version,
295
+ configuration: (@opts.get(:configuration)),
296
+ project_dependencies: project_dependencies
297
+
298
+ # take data from package as configured in Rakefile, choosing what is in
299
+ # Rakefile over what is in projfile.
300
+ nuspec = nuspec.merge_with @opts.get(:package)
301
+ trace { "nuspec: #{nuspec.to_s} [nugets pack: task]" }
302
+
303
+ if @opts.get(:symbols)
304
+ trace { "creating SYMBOL package for '#{proj.name}' [nugets pack: task]" }
305
+ nuspec_symbols = Albacore::NugetModel::Package.from_xxproj proj,
306
+ symbols: true,
307
+ verify_files: true,
308
+ dotnet_version: target,
309
+ known_projects: knowns,
310
+ version: version,
311
+ configuration: (@opts.get(:configuration)),
312
+ project_dependencies: project_dependencies
313
+
314
+ nuspec_symbols = nuspec_symbols.merge_with @opts.get(:package)
315
+ trace { "nuspec symbols: #{nuspec_symbols.to_s} [nugets pack: task]" }
316
+
317
+ [nuspec, nuspec_symbols]
318
+ else
319
+ trace { "skipping SYMBOL package for #{proj.name} [nugets pack: task]" }
320
+ [nuspec, nil]
321
+ end
322
+ end
323
+
324
+ def write_nuspec! proj, nuspec, symbols
325
+ raise ArgumentError, "no nuspect metadata id, project at path: #{proj.proj_path_base}, nuspec: #{nuspec.inspect}" unless nuspec.metadata.id
326
+ nuspec_path = File.join(proj.proj_path_base, nuspec.metadata.id + "#{ symbols ? '.symbols' : '' }.nuspec")
327
+
328
+ File.write(nuspec_path, nuspec.to_xml)
329
+
330
+ nuspec_path
331
+ end
332
+
333
+ def create_nuget! cwd, nuspec, nuspec_symbols = nil
334
+ # create the command
335
+ exe = path_to(@opts.get(:exe), cwd)
336
+ out = path_to(@opts.get(:out), cwd)
337
+ nuspec = path_to nuspec, cwd
338
+ nuspec_symbols = path_to nuspec_symbols, cwd if nuspec_symbols
339
+ cmd = Albacore::NugetsPack::Cmd.new exe,
340
+ work_dir: cwd,
341
+ out: out
342
+
343
+ # run any concerns that modify the command
344
+ @before_execute.call cmd if @before_execute
345
+
346
+ debug { "generating nuspec at #{nuspec}, and symbols (possibly) at '#{nuspec_symbols}' [nugets pack: task]" }
347
+
348
+ # run the command for the file
349
+ pkg, spkg = cmd.execute nuspec, nuspec_symbols
350
+
351
+ publish_artifact nuspec, pkg
352
+ publish_artifact nuspec_symbols, spkg if spkg && nuspec_symbols
353
+ end
354
+
355
+ ## Cleaning up after generation
356
+
357
+ def cleanup_nuspec nuspec
358
+ return if nuspec.nil? or not File.exists? nuspec
359
+ return if @opts.get :leave_nuspec, false
360
+ File.delete nuspec
361
+ end
362
+
363
+ def publish_artifact nuspec, nuget
364
+ Albacore.publish :artifact, OpenStruct.new(
365
+ :nuspec => nuspec,
366
+ :nupkg => nuget,
367
+ :location => nuget
368
+ )
369
+ end
370
+
371
+ def self.accept? f
372
+ File.extname(f).downcase != '.nuspec'
373
+ end
374
+ end
375
+
376
+ # generate a nuget from a nuspec
377
+ class NuspecTask
378
+ include Logging
379
+
380
+ def initialize command_line, config, nuspec
381
+ @config = config
382
+ @nuspec = nuspec
383
+ # is a NuspecPack::Cmd
384
+ @command_line = command_line
385
+ end
386
+
387
+ def read_version_from_nuspec
388
+ begin
389
+ nuspec_file = File.open(@nuspec)
390
+ xml = Nokogiri::XML(nuspec_file)
391
+ nuspec_file.close
392
+ nodes = xml.xpath('.//metadata/version')
393
+ raise "No <version/> found" if nodes.empty?
394
+ nodes.first.text()
395
+ rescue => error
396
+ err "Error reading package version from file: #{error}"
397
+ raise
398
+ end
399
+ end
400
+
401
+ def execute
402
+ version = read_version_from_nuspec
403
+ filename = File.basename(@nuspec, File.extname(@nuspec))
404
+
405
+ @command_line.execute @nuspec
406
+
407
+ path = File.join(@config.opts.get(:out), "#{filename}.#{version}.nupkg")
408
+
409
+ Albacore.publish :artifact, OpenStruct.new(
410
+ :nuspec => @nuspec,
411
+ :nupkg => path,
412
+ :location => path
413
+ )
414
+ end
415
+
416
+ def self.accept? file
417
+ File.extname(file).downcase == '.nuspec'
418
+ end
419
+ end
420
+ end
421
+ end
@@ -1,3 +1,3 @@
1
1
  module Albacore
2
- VERSION = "2.0.10"
2
+ VERSION = "2.0.11"
3
3
  end
@@ -138,6 +138,14 @@ Successfully created package '/home/xyz/Shared/build/pkg/MyNuget.Package.1.0.0.s
138
138
  EXAMPLE_OUTPUT
139
139
  end
140
140
 
141
+ let :sample3 do
142
+ <<EXAMPLE_OUTPUT
143
+ Attempting to build package from 'MyNuget.Package.nuspec'.
144
+ Successfully created package '/home/xyz/Shared/build/pkg/MyNuget.Package.1.0.0-alpha3.nupkg'.
145
+ Successfully created package '/home/xyz/Shared/build/pkg/MyNuget.Package.1.0.0-alpha3.symbols.nupkg'.
146
+ EXAMPLE_OUTPUT
147
+ end
148
+
141
149
  it "should match sample1 with last nupkg mentioned" do
142
150
  match = subject.send(:get_nuget_path_of) { sample1 }
143
151
  match.should eq('Y:\\Shared\\build\\pkg\\MyNuget.Package.1.0.0.symbols.nupkg')
@@ -147,6 +155,11 @@ EXAMPLE_OUTPUT
147
155
  match = subject.send(:get_nuget_path_of) { sample2 }
148
156
  match.should eq('/home/xyz/Shared/build/pkg/MyNuget.Package.1.0.0.symbols.nupkg')
149
157
  end
158
+
159
+ it 'should match sample3 with last nupkg mentioned' do
160
+ match = subject.send(:get_nuget_path_of) { sample3 }
161
+ match.should eq('/home/xyz/Shared/build/pkg/MyNuget.Package.1.0.0-alpha3.symbols.nupkg')
162
+ end
150
163
  end
151
164
 
152
165
  # testing nuspec task
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: albacore
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.10
4
+ version: 2.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Feldt