Class: Albacore::NugetModel::Package
- Inherits:
-
Object
- Object
- Albacore::NugetModel::Package
- Extended by:
- Logging
- Includes:
- Logging
- Defined in:
- lib/albacore/nuget_model.rb
Overview
the nuget package element writer
Instance Attribute Summary collapse
-
#files ⇒ Object
the files is something enumerable that corresponds to the file elements inside ‘//package/files’.
-
#metadata ⇒ Object
the metadata corresponds to the metadata element of the nuspec.
Class Method Summary collapse
-
.from_xml(xml) ⇒ Object
read the nuget specification from a nuspec file.
-
.from_xxproj(proj, *opts) ⇒ Object
Read the nuget specification from a xxproj instance (e.g. csproj, fsproj) Options: - symbols - dotnet_version Specifies the version to use for constructing the nuspec’s lib folder - known_projects - configuration - project_dependencies Specifies whether to follow the project dependencies.
-
.from_xxproj_file(file, *opts) ⇒ Object
read the nuget specification from a xxproj file (e.g. csproj, fsproj).
- .get_output_path(proj, opts) ⇒ Object
Instance Method Summary collapse
-
#add_file(src, target, exclude = nil) ⇒ Object
add a file to the instance.
-
#initialize(metadata = nil, files = nil) ⇒ Package
constructor
creates a new nuspec package instance.
-
#merge_with(other) ⇒ Object
creates a new Package/Metadata by overriding data in this instance with data from passed instance.
-
#remove_file(src) ⇒ Object
remove the file denoted by src.
- #to_s ⇒ Object
-
#to_xml ⇒ Object
gets the current package as a xml node.
-
#to_xml_builder ⇒ Object
gets the current package as a xml builder.
-
#with_metadata {|@metadata| ... } ⇒ Object
do something with the metadata.
Methods included from Logging
debug, err, error, fatal, info, puts, trace, warn
Constructor Details
#initialize(metadata = nil, files = nil) ⇒ Package
creates a new nuspec package instance
239 240 241 242 |
# File 'lib/albacore/nuget_model.rb', line 239 def initialize = nil, files = nil = || Metadata.new @files = files || [] end |
Instance Attribute Details
#files ⇒ Object
the files is something enumerable that corresponds to the file elements inside ‘//package/files’.
236 237 238 |
# File 'lib/albacore/nuget_model.rb', line 236 def files @files end |
#metadata ⇒ Object
the metadata corresponds to the metadata element of the nuspec
232 233 234 |
# File 'lib/albacore/nuget_model.rb', line 232 def end |
Class Method Details
.from_xml(xml) ⇒ Object
read the nuget specification from a nuspec file
318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/albacore/nuget_model.rb', line 318 def self.from_xml xml ns = { ng: 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd' } parser = Nokogiri::XML(xml) = Metadata.from_xml(parser.xpath('.//ng:metadata', ns)) files = parser. xpath('.//ng:files', ns). children. reject { |n| n.text? or n['src'].nil? }. collect { |n| FileItem.new n['src'], n['target'], n['exclude'] } Package.new , files end |
.from_xxproj(proj, *opts) ⇒ Object
Read the nuget specification from a xxproj instance (e.g. csproj, fsproj) Options:
- symbols
- dotnet_version
Specifies the version to use for constructing the nuspec's lib folder
- known_projects
- configuration
- project_dependencies
Specifies whether to follow the project dependencies. See nuget_model_spec.rb
for examples of usage of this property.
- nuget_dependencies
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/albacore/nuget_model.rb', line 347 def self.from_xxproj proj, *opts opts = Map.(opts || {}). apply({ symbols: false, dotnet_version: 'net45', known_projects: Set.new, configuration: 'Debug', project_dependencies: true, verify_files: false, nuget_dependencies: true, framework_dependencies: true }) trace { "#from_xxproj proj: '#{proj}' opts: #{opts} [nuget model: package]" } version = opts.get :version package = Package.new package..id = proj.id if proj.id package..title = proj.name if proj.name package..version = version if version package.. = proj. if proj. package..release_notes = Albacore::Tools.git_release_notes if opts.get :nuget_dependencies trace "adding nuget dependencies for id #{proj.id}" # add declared packages as dependencies proj.declared_packages.each do |p| debug "adding package dependency: #{proj.id} => #{p.id} at #{p.version} [nuget model: package]" package..add_dependency p.id, p.version end end if opts.get :project_dependencies # add declared projects as dependencies proj. declared_projects. keep_if { |p| opts.get(:known_projects).include? p.id }. each do |p| debug "adding project dependency: #{proj.id} => #{p.id} at #{version} [nuget model: package]" package..add_dependency p.id, version end end if opts.get :framework_dependencies fd = opts.get :framework_dependencies fd.each { |n, p| package..add_framework_dependency p.id, p.version } end output = get_output_path proj, opts target_lib = %W[lib #{opts.get(:dotnet_version)}].join(Albacore::Paths.separator) if opts.get :symbols compile_files = proj.included_files.keep_if { |f| f.item_name == "compile" } debug "add compiled files: #{compile_files} [nuget model: package]" compile_files.each do |f| target = %W[src #{Albacore::Paths.normalise_slashes(f.include)}].join(Albacore::Paths.separator) package.add_file f.include, target end debug "add dll and pdb files [nuget model: package]" package.add_file(Albacore::Paths.normalise_slashes(output + proj.asmname + '.pdb'), target_lib) package.add_file(Albacore::Paths.normalise_slashes(output + proj.asmname + '.dll.mdb'), target_lib) package.add_file(Albacore::Paths.normalise_slashes(output + proj.asmname + '.dll'), target_lib) else # add *.{dll,xml,config} %w[dll xml config pdb dll.mdb].each do |ext| file = %W{#{output} #{proj.asmname}.#{ext}}. map { |f| f.gsub /\\$/, '' }. map { |f| Albacore::Paths.normalise_slashes f }. join(Albacore::Paths.separator) debug "adding binary file #{file} [nuget model: package]" package.add_file file, target_lib end end if opts.get :verify_files package.files.each do |file| file_path = File. file.src, proj.proj_path_base unless File.exists? file_path info "while building nuspec for proj id: #{proj.id}, file: #{file_path} => #{file.target} not found, removing from nuspec [nuget model: package]" package.remove_file file.src trace { "files: #{package.files.map { |f| f.src }.inspect} [nuget model: package]" } end end end package end |
.from_xxproj_file(file, *opts) ⇒ Object
read the nuget specification from a xxproj file (e.g. csproj, fsproj)
331 332 333 334 |
# File 'lib/albacore/nuget_model.rb', line 331 def self.from_xxproj_file file, *opts proj = Albacore::Project.new file from_xxproj proj, *opts end |
.get_output_path(proj, opts) ⇒ Object
438 439 440 441 442 443 |
# File 'lib/albacore/nuget_model.rb', line 438 def self.get_output_path proj, opts try = proj.try_output_path(opts.get(:configuration)) return try if try warn 'using fallback output path' proj.fallback_output_path end |
Instance Method Details
#add_file(src, target, exclude = nil) ⇒ Object
add a file to the instance
245 246 247 248 |
# File 'lib/albacore/nuget_model.rb', line 245 def add_file src, target, exclude = nil @files << FileItem.new(src, target, exclude) self end |
#merge_with(other) ⇒ Object
creates a new Package/Metadata by overriding data in this instance with data from passed instance
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/albacore/nuget_model.rb', line 294 def merge_with other m_next = .merge_with other. files_res = {} # my files @files.each { |f| files_res[f.src] = f } # overrides other.files.each { |f| files_res[f.src] = f } # result f_next = files_res.collect { |k, v| v } Package.new m_next, f_next end |
#remove_file(src) ⇒ Object
remove the file denoted by src
251 252 253 254 255 |
# File 'lib/albacore/nuget_model.rb', line 251 def remove_file src src = src.src if src.respond_to? :src # if passed an OpenStruct e.g. trace { "remove_file: removing file '#{src}' [nuget model: package]" } @files = @files.reject { |f| f.src == src } end |
#to_s ⇒ Object
310 311 312 |
# File 'lib/albacore/nuget_model.rb', line 310 def to_s "NugetModel::Package(files: #{@files.map(&:to_s)}, metadata: #{ @metadata.to_s })" end |
#to_xml ⇒ Object
gets the current package as a xml node
288 289 290 |
# File 'lib/albacore/nuget_model.rb', line 288 def to_xml to_xml_builder.to_xml end |
#to_xml_builder ⇒ Object
gets the current package as a xml builder
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/albacore/nuget_model.rb', line 265 def to_xml_builder md = Nokogiri::XML(.to_xml).at_css('metadata').to_xml Nokogiri::XML::Builder.new(encoding: 'utf-8') do |x| x.package(xmlns: 'http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd') { x << md #x.__send__ :insert, md.at_css("metadata") # x << md.at_css("metadata").to_xml(indent: 4) unless @files.empty? x.files { @files.each do |f| if f.exclude x.file src: f.src, target: f.target, exclude: f.exclude else x.file src: f.src, target: f.target end end } end } end end |
#with_metadata {|@metadata| ... } ⇒ Object
do something with the metadata. returns the #self Package instance
259 260 261 262 |
# File 'lib/albacore/nuget_model.rb', line 259 def &block yield if block_given? self end |