albacore 2.8.0 → 3.0.0.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/albacore/cli.rb +2 -2
  3. data/lib/albacore/dsl.rb +2 -42
  4. data/lib/albacore/nuget_model.rb +173 -67
  5. data/lib/albacore/paket.rb +20 -5
  6. data/lib/albacore/paths.rb +1 -0
  7. data/lib/albacore/project.rb +228 -45
  8. data/lib/albacore/task_types/nugets_pack.rb +73 -425
  9. data/lib/albacore/task_types/sql_cmd.rb +1 -1
  10. data/lib/albacore/tasks/release.rb +2 -2
  11. data/lib/albacore/version.rb +1 -1
  12. data/spec/dsl_spec.rb +1 -1
  13. data/spec/nuget_model_spec.rb +208 -79
  14. data/spec/nugets_pack_spec.rb +1 -353
  15. data/spec/paket_spec.rb +51 -2
  16. data/spec/project_spec.rb +118 -43
  17. data/spec/shared_contexts.rb +28 -14
  18. data/spec/testdata/Project/Project.fsproj +1 -1
  19. data/spec/testdata/console-core-argu/.gitignore +4 -0
  20. data/spec/testdata/console-core-argu/.paket/Paket.Restore.targets +239 -0
  21. data/spec/testdata/console-core-argu/.paket/paket.exe +0 -0
  22. data/spec/testdata/console-core-argu/.paket/paket.targets +72 -0
  23. data/spec/testdata/console-core-argu/ConsoleArgu.fsproj +12 -0
  24. data/spec/testdata/console-core-argu/Library.fs +31 -0
  25. data/spec/testdata/console-core-argu/build.sh +4 -0
  26. data/spec/testdata/console-core-argu/paket.dependencies +3 -0
  27. data/spec/testdata/console-core-argu/paket.lock +565 -0
  28. data/spec/testdata/console-core-argu/paket.references +2 -0
  29. data/spec/testdata/console-core-argu/paket.template +1 -0
  30. metadata +26 -16
  31. data/lib/albacore/app_spec.rb +0 -229
  32. data/lib/albacore/cpack_app_spec.rb +0 -135
  33. data/lib/albacore/task_types/nugets.rb +0 -8
  34. data/lib/albacore/task_types/nugets_restore.rb +0 -181
  35. data/spec/app_spec_spec.rb +0 -147
  36. data/spec/fpm_app_spec_spec.rb +0 -157
  37. data/spec/nugets_find_gem_exe_spec.rb +0 -21
  38. data/spec/nugets_restore_spec.rb +0 -77
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc8baa52d6989b0d3f080795555823d9ae24685a
4
- data.tar.gz: 441f7dcbbe42462740445415106c420a072e531c
3
+ metadata.gz: 9dfa11c2bc3112b05ccea24961efa85bba34debd
4
+ data.tar.gz: a7cfcaa1dab72c5136ff7f41b08b08f638b34827
5
5
  SHA512:
6
- metadata.gz: 0fff84ebb448c5cfa105d1f8d45c511c6bb40ed9e5ea1da283b171d3e064bfb4b11d28b09ed565394e990e7009430af3f08c12faa1e2a635a752cd5fa2f29064
7
- data.tar.gz: d00c5499c3e82e2e07c9bc88fdf498c22b2df7fefdc96be63d4dd9453eed62e764d3907051638dfbe1a80d3e2fc7e6a9c3b4dd1f920612adbaac9b2468de5d03
6
+ metadata.gz: b9052b233fb098ac1d6a5abc9b1085525fe700c882633fadb67ab2d215185b315c78c3b6f3447ab396b5bcb4731ccac2ac223e4af2e99131796c2e5303a02d86
7
+ data.tar.gz: 2e9efe5a7afac83b40d7526ae640046853bab62757654eb8ef89ffcbedafabac1c0d186b27d8aab1c1911b295869822256892e76696c7f040c73fe9ed8bb40a5
@@ -161,7 +161,7 @@ nugets_pack :create_nugets => ['build/pkg', :versioning, :compile] do |p|
161
161
  p.files = FileList['src/**/*.{csproj,fsproj,nuspec}'].
162
162
  exclude(/Tests/)
163
163
  p.out = 'build/pkg'
164
- p.exe = 'packages/NuGet.CommandLine/tools/NuGet.exe'
164
+ p.exe = '.paket/paket.exe'
165
165
  p.with_metadata do |m|
166
166
  # m.id = 'MyProj'
167
167
  m.title = 'TODO'
@@ -190,7 +190,7 @@ task :default => :create_nugets #, :tests ]
190
190
  #Albacore::Tasks::Release.new :release,
191
191
  # pkg_dir: 'build/pkg',
192
192
  # depend_on: [:create_nugets, :ensure_nuget_key],
193
- # nuget_exe: 'packages/NuGet.CommandLine/tools/NuGet.exe',
193
+ # nuget_exe: '.paket/paket.exe',
194
194
  # api_key: ENV['NUGET_KEY']
195
195
  DATA
196
196
  end
@@ -51,17 +51,8 @@ module Albacore
51
51
 
52
52
  # restore the nugets to the solution
53
53
  def nugets_restore *args, &block
54
- require 'albacore/task_types/nugets_restore'
55
54
  Albacore.define_task *args do |task_name, own_args|
56
- c = Albacore::NugetsRestore::Config.new
57
- yield c, own_args
58
-
59
- c.ensure_authentication!
60
-
61
- c.packages.each do |p|
62
- command = Albacore::NugetsRestore::Cmd.new(c.work_dir, c.exe, c.opts_for_pkgcfg(p))
63
- Albacore::NugetsRestore::Task.new(command).execute
64
- end
55
+ system '.paket/paket.exe', %w|restore|
65
56
  end
66
57
  end
67
58
 
@@ -71,38 +62,7 @@ module Albacore
71
62
  Albacore.define_task *args do |task_name, own_args|
72
63
  c = Albacore::NugetsPack::Config.new
73
64
  yield c, own_args
74
- Albacore::NugetsPack::ProjectTask.new(c.opts).execute
75
- end
76
- end
77
-
78
- # Restore hint paths to registered nugets
79
- def restore_hint_paths *args, &block
80
- require 'albacore/tools/restore_hint_paths'
81
- Albacore.define_task *args do |task_name, own_args|
82
- c = Albacore::RestoreHintPaths::Config.new
83
- yield c, own_args
84
-
85
- t = Albacore::RestoreHintPaths::Task.new c
86
- t.execute
87
- end
88
- end
89
-
90
- # Generate .rpm or .deb files from .appspec files
91
- def appspecs *args, &block
92
- if Albacore.windows?
93
- require 'albacore/cpack_app_spec'
94
- Albacore.define_task *args do |task_name, own_args|
95
- c = ::Albacore::CpackAppSpec::Config.new
96
- yield c, own_args
97
- ::Albacore::CpackAppSpec::Task.new(c.opts).execute
98
- end
99
- else
100
- require 'albacore/fpm_app_spec'
101
- Albacore.define_task *args do |task_name, own_args|
102
- c = ::Albacore::FpmAppSpec::Config.new
103
- yield c, own_args
104
- ::Albacore::FpmAppSpec::Task.new(c.opts).execute
105
- end
65
+ Albacore::NugetsPack::Cmd.new(c).execute
106
66
  end
107
67
  end
108
68
 
@@ -9,12 +9,18 @@ require 'albacore/tools'
9
9
  module Albacore
10
10
  module NugetModel
11
11
  class IdVersion
12
- attr_reader :id, :version
13
- def initialize id, version
14
- @id, @version = id, version
12
+ attr_reader :id, :version, :group, :target_framework
13
+
14
+ def initialize id, version, group, target_framework
15
+ @id, @version, @group, @target_framework = id, version, group, target_framework
15
16
  end
17
+
16
18
  def to_s
17
- "#{id}@#{version}"
19
+ if ! target_framework.nil? && target_framework != ''
20
+ "#{id}@#{version} when #{target_framework}"
21
+ else
22
+ "#{id}@#{version} grouped:#{group}"
23
+ end
18
24
  end
19
25
  end
20
26
 
@@ -106,7 +112,7 @@ end})
106
112
 
107
113
  # (v2.5 or above) Specifies the minimum version of the NuGet client that
108
114
  # can install this package. This requirement is enforced by both the
109
- # NuGet Visual Studio extension and nuget.exe program.
115
+ # NuGet Visual Studio extension and .paket/paket.exe program.
110
116
  nuspec_field :min_client_version
111
117
 
112
118
  # gets the field symbols that have been set
@@ -117,41 +123,110 @@ end})
117
123
  @set_fields = Set.new
118
124
  @dependencies = dependencies || Hash.new
119
125
  @framework_assemblies = framework_assemblies || Hash.new
126
+ @has_group = false
120
127
 
121
128
  debug "creating new metadata with dependencies: #{dependencies} [nuget model: metadata]" unless dependencies.nil?
122
129
  debug "creating new metadata (same as prev) with fw asms: #{framework_assemblies} [nuget model: metadata]" unless framework_assemblies.nil?
123
130
  end
124
131
 
125
132
  # add a dependency to the package; id and version
126
- def add_dependency id, version
127
- @dependencies[id] = IdVersion.new id, version
133
+ def add_dependency id, version, target_framework = '', group = true
134
+ guard_groups_or_not group
135
+ extra = (target_framework || '') == '' ? '' : "|#{target_framework}"
136
+ @has_group ||= group
137
+ @dependencies["#{id}#{extra}"] = IdVersion.new id, version, group, target_framework
128
138
  end
129
139
 
130
140
  # add a framework dependency for the package
131
- def add_framework_dependency id, version
132
- @framework_assemblies[id] = IdVersion.new id, version
141
+ def add_framework_dependency id, version, target_framework = '', group = true
142
+ guard_groups_or_not group
143
+ @has_group ||= group
144
+ @framework_assemblies[id] = IdVersion.new id, version, group, target_framework
145
+ end
146
+
147
+ def to_template
148
+ lines = []
149
+ lines << 'type file'
150
+
151
+ # fields
152
+ @set_fields.each do |f|
153
+ lines << "#{Metadata.pascal_case(f)} #{send(f)}"
154
+ end
155
+
156
+ lines << 'dependencies' unless @dependencies.empty?
157
+ if @has_group
158
+ groups = @dependencies.group_by { |k, d| d.target_framework }
159
+ groups.each do |group|
160
+ fw, deps = group
161
+ if fw == ''
162
+ deps.each do |k, d|
163
+ lines << " #{d.id} ~> #{d.version}"
164
+ end
165
+ else
166
+ lines << " framework: #{fw}"
167
+ deps.each do |k, d|
168
+ lines << " #{d.id} ~> #{d.version}"
169
+ end
170
+ end
171
+ end
172
+ else
173
+ @dependencies.each do |k, d|
174
+ lines << " #{d.id} ~> #{d.version}"
175
+ end
176
+ end
177
+
178
+ if @framework_assemblies.respond_to?(:each) && @framework_assemblies.length > 0
179
+ lines << 'frameworkAssemblies'
180
+ @framework_assemblies.each do |k, d|
181
+ lines << " #{d.id}"
182
+ end
183
+ end
184
+
185
+ lines
133
186
  end
134
187
 
135
188
  def to_xml_builder
136
189
  # alt: new(encoding: 'utf-8')
137
190
  Nokogiri::XML::Builder.new do |x|
138
- x.metadata {
191
+ x.metadata do
139
192
  @set_fields.each do |f|
140
193
  x.send(Metadata.pascal_case(f), send(f))
141
194
  end
142
- x.dependencies {
143
- @dependencies.each { |k, d|
144
- x.dependency id: d.id, version: d.version
145
- }
146
- }
147
- if @frameworkAssemblies.respond_to? :each
148
- x.frameworkAssemblies {
149
- @framework_assemblies.each { |k, d|
195
+
196
+ x.dependencies do
197
+ if @has_group
198
+ groups = @dependencies.group_by { |k, d| d.target_framework }
199
+ groups.each do |group|
200
+ fw, deps = group
201
+ if fw == ''
202
+ x.group do
203
+ deps.each do |k, d|
204
+ x.dependency id: d.id, version: d.version
205
+ end
206
+ end
207
+ else
208
+ x.group(targetFramework: fw) do
209
+ deps.each do |k, d|
210
+ x.dependency id: d.id, version: d.version
211
+ end
212
+ end
213
+ end
214
+ end
215
+ else
216
+ @dependencies.each do |k, d|
217
+ x.dependency id: d.id, version: d.version
218
+ end
219
+ end
220
+ end
221
+
222
+ if @framework_assemblies.respond_to?(:each) && @framework_assemblies.length > 0
223
+ x.frameworkAssemblies do
224
+ @framework_assemblies.each do |k, d|
150
225
  x.frameworkAssembly assemblyName: d.id, targetFramework: d.version
151
- }
152
- }
226
+ end
227
+ end
153
228
  end
154
- }
229
+ end
155
230
  end
156
231
  end
157
232
 
@@ -196,12 +271,26 @@ end})
196
271
  m = Metadata.new
197
272
  node.children.reject { |n| n.text? }.each do |n|
198
273
  if n.name == 'dependencies'
199
- n.children.reject { |n| n.text? }.each do |dep|
200
- m.add_dependency dep['id'], dep['version']
274
+ n.children.reject { |n| n.text? }.each do |node|
275
+ if node.name == 'group'
276
+ node.children.reject { |n| n.text? }.each do |dep|
277
+ tfw = node['targetFramework'] || ''
278
+ m.add_dependency dep['id'], dep['version'], tfw, group=true
279
+ end
280
+ else
281
+ m.add_dependency node['id'], node['version'], group=false
282
+ end
201
283
  end
202
284
  elsif n.name == 'frameworkDependencies'
203
- n.children.reject { |n| n.text? }.each do |dep|
204
- m.add_framework_dependency dep['id'], dep['version']
285
+ n.children.reject { |n| n.text? }.each do |node|
286
+ if node.name == 'group'
287
+ node.children.reject { |n| n.text? }.each do |dep|
288
+ tfw = node['targetFramework'] || ''
289
+ m.add_framework_dependency dep['id'], dep['version'], tfw, group=true
290
+ end
291
+ else
292
+ m.add_framework_dependency node['id'], node['version'], group=false
293
+ end
205
294
  end
206
295
  else
207
296
  # just set the property
@@ -224,8 +313,18 @@ end})
224
313
  tr("-", "_").
225
314
  downcase
226
315
  end
316
+
317
+ private
318
+ def guard_groups_or_not add_in_group
319
+ if @has_group && ! add_in_group \
320
+ || ! @has_group && @dependencies.length > 0 && add_in_group
321
+ raise ArgumentError.new("If you've added dependencies in group, you must add the rest in groups, too. See https://docs.microsoft.com/en-us/nuget/schema/nuspec#framework-assembly-references")
322
+ end
323
+ end
227
324
  end
228
325
 
326
+ ############################ PACKAGE
327
+
229
328
  # the nuget package element writer
230
329
  class Package
231
330
  include Logging
@@ -263,14 +362,26 @@ end})
263
362
  self
264
363
  end
265
364
 
365
+ def to_template
366
+ lines = @metadata.to_template
367
+
368
+ unless @files.empty?
369
+ lines << 'files'
370
+ @files.each do |file|
371
+ lines << " #{file.src} ==> #{file.target}" unless file.exclude
372
+ lines << " !#{file.src}" if file.exclude
373
+ end
374
+ end
375
+
376
+ lines.join("\n")
377
+ end
378
+
266
379
  # gets the current package as a xml builder
267
380
  def to_xml_builder
268
381
  md = Nokogiri::XML(@metadata.to_xml).at_css('metadata').to_xml
269
382
  Nokogiri::XML::Builder.new(encoding: 'utf-8') do |x|
270
383
  x.package(xmlns: 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd') {
271
384
  x << md
272
- #x.__send__ :insert, md.at_css("metadata")
273
- # x << md.at_css("metadata").to_xml(indent: 4)
274
385
  unless @files.empty?
275
386
  x.files {
276
387
  @files.each do |f|
@@ -338,7 +449,6 @@ end})
338
449
  # Read the nuget specification from a xxproj instance (e.g. csproj, fsproj)
339
450
  # Options:
340
451
  # - symbols
341
- # - dotnet_version
342
452
  # Specifies the version to use for constructing the nuspec's lib folder
343
453
  # - known_projects
344
454
  # - configuration
@@ -349,19 +459,19 @@ end})
349
459
  def self.from_xxproj proj, *opts
350
460
  opts = Map.options(opts || {}).
351
461
  apply({
352
- symbols: false,
353
- dotnet_version: 'net45',
354
- known_projects: Set.new,
355
- configuration: 'Debug',
356
- project_dependencies: true,
357
- verify_files: false,
358
- nuget_dependencies: true,
359
- framework_dependencies: true })
462
+ symbols: false,
463
+ known_projects: Set.new,
464
+ configuration: 'Debug',
465
+ project_dependencies: true,
466
+ verify_files: false,
467
+ nuget_dependencies: true,
468
+ framework_dependencies: true,
469
+ metadata: Metadata.new })
360
470
 
361
471
  trace { "#from_xxproj proj: '#{proj}' opts: #{opts} [nuget model: package]" }
362
472
 
363
473
  version = opts.get :version
364
- package = Package.new
474
+ package = Package.new(opts.get(:metadata))
365
475
  package.metadata.id = proj.id if proj.id
366
476
  package.metadata.title = proj.name if proj.name
367
477
  package.metadata.version = version if version
@@ -369,11 +479,12 @@ end})
369
479
  package.metadata.release_notes = Albacore::Tools.git_release_notes
370
480
 
371
481
  if opts.get :nuget_dependencies
372
- trace "adding nuget dependencies for id #{proj.id}"
482
+ trace "adding nuget dependencies for id #{proj.id} [nuget model: package]"
373
483
  # add declared packages as dependencies
374
484
  proj.declared_packages.each do |p|
375
- debug "adding package dependency: #{proj.id} => #{p.id} at #{p.version} [nuget model: package]"
376
- package.metadata.add_dependency p.id, p.version
485
+ # p is a Package
486
+ debug "adding package dependency: #{proj.id} => #{p.id} at #{p.version}, fw #{p.target_framework} [nuget model: package]"
487
+ package.metadata.add_dependency p.id, p.version, p.target_framework, group=true
377
488
  end
378
489
  end
379
490
 
@@ -383,44 +494,39 @@ end})
383
494
  declared_projects.
384
495
  keep_if { |p| opts.get(:known_projects).include? p.id }.
385
496
  each do |p|
386
- debug "adding project dependency: #{proj.id} => #{p.id} at #{version} [nuget model: package]"
387
- package.metadata.add_dependency p.id, version
497
+ # p is a Project
498
+ debug "adding project dependency: #{proj.id} => #{p.id} at #{version}, fw #{p.target_frameworks.inspect} [nuget model: package]"
499
+ p.target_frameworks.each do |fw|
500
+ package.metadata.add_dependency p.id, version, fw, group=true
501
+ end
388
502
  end
389
503
  end
390
504
 
391
-
392
505
  fd = opts.get :framework_dependencies
393
506
  if fd && fd.respond_to?(:each)
394
507
  fd.each { |n, p|
395
- package.metadata.add_framework_dependency p.id, p.version
508
+ package.metadata.add_framework_dependency p.id, p.version, p.target_framework, p.group
396
509
  }
397
510
  end
398
511
 
399
- output = get_output_path proj, opts
400
- target_lib = %W[lib #{opts.get(:dotnet_version)}].join(Albacore::Paths.separator)
512
+ debug "including files for frameworks #{proj.target_frameworks.inspect}"
513
+ proj.target_frameworks.each do |fw|
514
+ conf = opts.get(:configuration)
401
515
 
402
- if opts.get :symbols
403
- compile_files = proj.included_files.keep_if { |f| f.item_name == "compile" }
516
+ proj.outputs(conf, fw).each do |output|
517
+ lib_filepath = %W|lib #{fw}|.join(Albacore::Paths.separator)
518
+ debug "adding output file #{output.path} => #{lib_filepath} [nuget model: package]"
519
+ package.add_file output.path, lib_filepath
520
+ end
404
521
 
405
- debug "add compiled files: #{compile_files} [nuget model: package]"
406
- compile_files.each do |f|
407
- target = %W[src #{Albacore::Paths.normalise_slashes(f.include)}].join(Albacore::Paths.separator)
408
- package.add_file f.include, target
409
- end
522
+ if opts.get :sources
523
+ compile_files = proj.included_files.keep_if { |f| f.item_name == "compile" }
410
524
 
411
- debug "add dll and pdb files [nuget model: package]"
412
- package.add_file(Albacore::Paths.normalise_slashes(output + proj.asmname + '.pdb'), target_lib)
413
- package.add_file(Albacore::Paths.normalise_slashes(output + proj.asmname + '.dll.mdb'), target_lib)
414
- package.add_file(Albacore::Paths.normalise_slashes(output + proj.asmname + '.dll'), target_lib)
415
- else
416
- # add *.{dll,xml,config}
417
- %w[dll xml config pdb dll.mdb].each do |ext|
418
- file = %W{#{output} #{proj.asmname}.#{ext}}.
419
- map { |f| f.gsub /\\$/, '' }.
420
- map { |f| Albacore::Paths.normalise_slashes f }.
421
- join(Albacore::Paths.separator)
422
- debug "adding binary file #{file} [nuget model: package]"
423
- package.add_file file, target_lib
525
+ debug "add compiled files: #{compile_files} [nuget model: package]"
526
+ compile_files.each do |f|
527
+ target = %W[src #{Albacore::Paths.normalise_slashes(f.include)}].join(Albacore::Paths.separator)
528
+ package.add_file f.include, target
529
+ end
424
530
  end
425
531
  end
426
532
 
@@ -446,4 +552,4 @@ end})
446
552
  end
447
553
  end
448
554
  end
449
- end
555
+ end
@@ -3,21 +3,36 @@ require 'albacore/semver'
3
3
 
4
4
  module Albacore
5
5
  module Paket
6
- def self.parse_line line
6
+ def self.parse_lock_line line
7
7
  if (m = line.match(/^\s*(?<id>[\w\-\.]+) \((?<ver>[\.\d\w\-]+)\)( - )?((framework: >= (?<tf>\w+))|(redirects: (?<redir>\w+)))?$/i))
8
8
  ver = Albacore::SemVer.parse(m[:ver], '%M.%m.%p', false)
9
9
  OpenStruct.new(:id => m[:id],
10
10
  :version => m[:ver],
11
- :target_framework => m[:tf] || 'net40',
11
+ :group => true,
12
+ :target_framework => m[:tf],
12
13
  :redirects => m[:redir] || nil,
13
14
  :semver => ver)
14
15
  end
15
16
  end
16
17
 
18
+ # returns [id, {id,version,group,target_framework,redirects,semver}][]
17
19
  def self.parse_paket_lock data
18
- data.map { |line| parse_line line }.
19
- compact.
20
- map { |package| [package.id, package] }
20
+ data.map { |line| parse_lock_line line }
21
+ .compact
22
+ .map { |package| [package.id, package] }
23
+ end
24
+
25
+ # returns string or nil
26
+ def self.parse_dependencies_line line
27
+ if (m = line.match(/^nuget (?<id>[\w\-\.]+)$/i))
28
+ m[:id]
29
+ end
30
+ end
31
+
32
+ # returns a string[]
33
+ def self.parse_dependencies_file data
34
+ data.map { |line| parse_dependencies_line line }
35
+ .compact
21
36
  end
22
37
  end
23
38
  end