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.



383
384
385
386
387
388
# File 'lib/albacore/task_types/nugets_pack.rb', line 383

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)


419
420
421
# File 'lib/albacore/task_types/nugets_pack.rb', line 419

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

Instance Method Details

#executeObject



404
405
406
407
408
409
410
411
412
413
414
415
416
417
# File 'lib/albacore/task_types/nugets_pack.rb', line 404

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



390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/albacore/task_types/nugets_pack.rb', line 390

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