Class: Albacore::NugetsRestore::Config

Inherits:
Object
  • Object
show all
Includes:
CmdConfig, Logging, Albacore::NugetsAuthentication
Defined in:
lib/albacore/task_types/nugets_restore.rb

Overview

Public: Configure ‘nuget.exe install’ – nuget restore.

work_dir - optional exe - required NuGet.exe path out - required location of ‘packages’ folder

Constant Summary collapse

OFFICIAL_REPO =
'https://nuget.org/api/v2/'

Instance Attribute Summary collapse

Attributes included from Albacore::NugetsAuthentication

#password, #username

Instance Method Summary collapse

Methods included from Logging

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

Methods included from CmdConfig

#add_parameter, #parameters

Methods included from ConfigDSL

#attr_path, #attr_path_accessor

Constructor Details

#initializeConfig

Returns a new instance of Config.



74
75
76
77
# File 'lib/albacore/task_types/nugets_restore.rb', line 74

def initialize
  @include_official = false
  @list_spec = File.join '**', 'packages.config'
end

Instance Attribute Details

#include_officialObject

whether to include the official defaults to true



103
104
105
# File 'lib/albacore/task_types/nugets_restore.rb', line 103

def include_official
  @include_official
end

#list_specObject

specifies the list specification to load ‘packages.config’ files from.

e.g. ‘**/packages.config’ on *nix.



89
90
91
# File 'lib/albacore/task_types/nugets_restore.rb', line 89

def list_spec
  @list_spec
end

#out=(value) ⇒ Object (writeonly)

the output directory passed to nuget when restoring the nugets



80
81
82
# File 'lib/albacore/task_types/nugets_restore.rb', line 80

def out=(value)
  @out = value
end

#sourceObject

nuget source, when other than MSFT source



83
84
85
# File 'lib/albacore/task_types/nugets_restore.rb', line 83

def source
  @source
end

Instance Method Details

#ensure_authentication!Object



113
114
115
116
117
118
119
# File 'lib/albacore/task_types/nugets_restore.rb', line 113

def ensure_authentication!
  return unless has_credentials?
  remove = RemoveSourceCmd.new exe, source
  readd  = AddSourceCmd.new exe, source, username, password
  remove.execute
  readd.execute
end

#exclude_versionObject



105
106
107
# File 'lib/albacore/task_types/nugets_restore.rb', line 105

def exclude_version
  add_parameter "-ExcludeVersion"
end

#has_credentials?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/albacore/task_types/nugets_restore.rb', line 109

def has_credentials?
  username && password && source
end

#opts_for_pkgcfg(pkg) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/albacore/task_types/nugets_restore.rb', line 121

def opts_for_pkgcfg pkg
  pars = parameters.to_a
  debug "include_official nuget repo: #{include_official}"
  pars << %W[-source #{OFFICIAL_REPO}] if include_official
  
  map = Map.new({ :pkgcfg     => Albacore::Paths.normalise_slashes(pkg),
                  :out        => @out,
                  :parameters => pars })

  if has_credentials?
    map.set :username, username
    map.set :password, password
    map.set :source, source
  end 
  map
end

#packagesObject



91
92
93
94
95
96
97
98
99
# File 'lib/albacore/task_types/nugets_restore.rb', line 91

def packages
  # it seems FileList doesn't care about the curr dir
  in_work_dir do
    FileList[
      Dir.glob(list_spec, File::FNM_DOTMATCH).
        reject { |a| a =~ /^\.{1,2}$/ }
    ]
  end
end