Class: Albacore::NugetsPack::NuspecTask

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/albacore/task_types/nugets_pack.rb

Overview

generate a nuget from a nuspec

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #err, #error, #fatal, #info, #puts, #trace, #warn

Constructor Details

#initialize(command_line, config, nuspec) ⇒ NuspecTask

Returns a new instance of NuspecTask.



413
414
415
416
417
418
# File 'lib/albacore/task_types/nugets_pack.rb', line 413

def initialize command_line, config, nuspec
  @config = config
  @nuspec = nuspec
  # is a NuspecPack::Cmd
  @command_line = command_line
end

Class Method Details

.accept?(file) ⇒ Boolean

Returns:

  • (Boolean)


449
450
451
# File 'lib/albacore/task_types/nugets_pack.rb', line 449

def self.accept? file
  File.extname(file).downcase == '.nuspec'
end

Instance Method Details

#executeObject



434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/albacore/task_types/nugets_pack.rb', line 434

def execute
  version = read_version_from_nuspec
  filename = File.basename(@nuspec, File.extname(@nuspec))

  @command_line.execute @nuspec

  path = File.join(@config.opts.get(:out), "#{filename}.#{version}.nupkg")

  Albacore.publish :artifact, OpenStruct.new(
    :nuspec   => @nuspec,
    :nupkg    => path,
    :location => path
  )
end

#read_version_from_nuspecObject



420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/albacore/task_types/nugets_pack.rb', line 420

def read_version_from_nuspec
  begin
    nuspec_file = File.open(@nuspec)
    xml = Nokogiri::XML(nuspec_file)
    nuspec_file.close
    nodes = xml.xpath('.//metadata/version')
    raise "No <version/> found" if nodes.empty?
    nodes.first.text()
  rescue => error
    err "Error reading package version from file: #{error}"
    raise
  end
end