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

Create a new Config object



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

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

Instance Attribute Details

#allow_insecure_sourceObject

allows a source without credentials be added



126
127
128
# File 'lib/albacore/task_types/nugets_restore.rb', line 126

def allow_insecure_source
  @allow_insecure_source
end

#include_officialObject

whether to include the official defaults to true



123
124
125
# File 'lib/albacore/task_types/nugets_restore.rb', line 123

def include_official
  @include_official
end

#list_specObject

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

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



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

def list_spec
  @list_spec
end

#out=(value) ⇒ Object (writeonly)

the output directory passed to nuget when restoring the nugets



87
88
89
# File 'lib/albacore/task_types/nugets_restore.rb', line 87

def out=(value)
  @out = value
end

Instance Method Details

#ensure_authentication!Object



140
141
142
143
144
145
146
# File 'lib/albacore/task_types/nugets_restore.rb', line 140

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



128
129
130
# File 'lib/albacore/task_types/nugets_restore.rb', line 128

def exclude_version
  add_parameter "-ExcludeVersion"
end

#has_credentials?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/albacore/task_types/nugets_restore.rb', line 136

def has_credentials?
  username && password && source
end

#no_cacheObject



132
133
134
# File 'lib/albacore/task_types/nugets_restore.rb', line 132

def no_cache
  add_parameter "-NoCache"
end

#nuget_gem_exeObject



148
149
150
# File 'lib/albacore/task_types/nugets_restore.rb', line 148

def nuget_gem_exe
  @exe = Albacore::Nugets::find_nuget_gem_exe
end

#opts_for_pkgcfg(pkg) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/albacore/task_types/nugets_restore.rb', line 152

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 allow_insecure_source
    map.set :source, source
  elsif has_credentials?
    map.set :username, username
    map.set :password, password
    map.set :source, source
  end
  map
end

#packagesObject



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

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

#sourceObject

nuget source, when other than MSFT source



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

def source
  @source
end

#source=(val) ⇒ Object

set the nuget source



95
96
97
98
99
100
101
102
103
# File 'lib/albacore/task_types/nugets_restore.rb', line 95

def source= val
  if val.is_a? String
    debug { 'you used a plain string as source, naming it after its md5 digest' }
    md5 = Digest::MD5.hexdigest val
    @source = OpenStruct.new(:name => md5, :uri => val)
  else
    @source = val
  end
end