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.



364
365
366
367
368
369
# File 'lib/albacore/task_types/nugets_pack.rb', line 364

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)


400
401
402
# File 'lib/albacore/task_types/nugets_pack.rb', line 400

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

Instance Method Details

#executeObject



385
386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/albacore/task_types/nugets_pack.rb', line 385

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



371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/albacore/task_types/nugets_pack.rb', line 371

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