class Physique::OctopusPack::Task

Public Class Methods

new(opts) click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 41
def initialize(opts)
  @opts = opts
  @project = Albacore::Project.new opts.project_file

  opts.metadata.id = @project.name if @project.name
  @package = Albacore::NugetModel::Package.new opts.metadata
end

Public Instance Methods

execute() click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 49
def execute
  if @opts.type == :website
    add_content_files
    add_binary_files target: 'bin'
  else
    add_content_files
    add_binary_files
  end

  nuspec_path = write_nuspec!
  create_nuget! @project.proj_path_base, nuspec_path
ensure
  cleanup_nuspec nuspec_path
end

Private Instance Methods

add_binary_files(options = {}) click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 118
def add_binary_files(options = {})
  target = options[:target] || ''

  output_path = get_output_path
  Dir.new(get_absolute_output_path).entries.
    keep_if { |f| f =~ /^.*\.(dll|exe|pdb|config)$/i}.
    each { |f| @package.add_file bin_target(output_path, f), bin_target(target, f) }
end
add_content_files() click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 111
def add_content_files
  @project.
    included_files.
    keep_if { |f| f.item_name == 'content' && f.item_name != 'packages.config' }.
    each { |f| @package.add_file f.include, f.include}
end
bin_target(target, file_name) click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 127
def bin_target(target, file_name)
  return file_name if target.blank?
  File.join(target, file_name)
end
cleanup_nuspec(nuspec) click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 93
def cleanup_nuspec nuspec
  return if nuspec.nil? or not File.exists? nuspec
  return if @opts.get :leave_nuspec, false
  File.delete nuspec
end
create_nuget!(cwd, nuspec_file) click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 74
def create_nuget!(cwd, nuspec_file)
  # create the command
  exe = path_to(@opts.exe, cwd)
  out = path_to(@opts.out, cwd)
  nuspec = path_to(nuspec_file, cwd)
  cmd = Albacore::NugetsPack::Cmd.new exe,
                                      work_dir: cwd,
                                      out: out

  # Octopus packages don't conform to NuGet standards so
  # disable package analysis to prevent unnecessary warnings.
  cmd.disable_package_analysis

  # run the command for the file
  pkg, _ = cmd.execute nuspec

  publish_artifact nuspec, pkg
end
get_absolute_output_path() click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 132
def get_absolute_output_path
  File.expand_path get_output_path, @project.proj_path_base
end
get_output_path() click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 136
def get_output_path
  Albacore::NugetModel::Package.get_output_path(@project, Map.new(configuration: @opts.configuration))
end
path_to(relative_file_path, cwd) click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 99
def path_to(relative_file_path, cwd)
  File.expand_path(File.join(@opts.get(:original_path), relative_file_path), cwd)
end
publish_artifact(nuspec, nuget) click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 103
def publish_artifact(nuspec, nuget)
  Albacore.publish :artifact, OpenStruct.new(
    nuspec: nuspec,
    nupkg: nuget,
    location: nuget
  )
end
write_nuspec!() click to toggle source
# File lib/physique/tasks/octopus_pack.rb, line 66
def write_nuspec!
  raise ArgumentError, "no nuspec metadata id, project at path: #{@project.proj_path_base}, nuspec: #{@package.inspect}" unless @package.metadata.id

  path = File.join(@project.proj_path_base, @package.metadata.id + '.nuspec')
  File.write(path, @package.to_xml)
  path
end