class Albacore::Tools::RestoreHintPaths::Task

Public Class Methods

new(config) click to toggle source
# File lib/albacore/tools/restore_hint_paths.rb, line 32
def initialize config
  @config = config
end

Public Instance Methods

execute() click to toggle source
# File lib/albacore/tools/restore_hint_paths.rb, line 35
def execute
  ps = map_file_list(@config.projs) || find_projs_in_need(@config.lang)
  ps.each do |proj|
    info "fixing #{proj}"
    fix_refs proj, @config.asmname_to_package
    info "saving #{proj}"
    proj.save unless @config.dry_run
  end
end

Private Instance Methods

find_projs_in_need(ext) click to toggle source
# File lib/albacore/tools/restore_hint_paths.rb, line 46
def find_projs_in_need ext
  map_file_list FileList["./src/**/*.#{ext}proj"]
end
fix_refs(p, asmname_to_package = {}) click to toggle source
# File lib/albacore/tools/restore_hint_paths.rb, line 64
def fix_refs p, asmname_to_package = {}
  packages = Hash[p.find_packages.collect { |v| [v.id, v] }]
  trace "packages: #{packages}"
  matches = matched_refs p.faulty_refs, packages, asmname_to_package
  trace "matches: #{matches}"
  matches.each{ |match|
    dll_path = Pathname.new match.package.path
    proj_path = Pathname.new p.proj_path_base
    hint_path = Nokogiri::XML::Node.new "HintPath", p.proj_xml_node
    hint_path.content = dll_path.relative_path_from proj_path
    match.ref << hint_path
    debug "For #{p.asmname} => hint_path: #{hint_path}"
  }
  trace p.proj_xml_node
end
map_file_list(fl) click to toggle source
# File lib/albacore/tools/restore_hint_paths.rb, line 49
def map_file_list fl
  return nil if fl.nil?
  fl.collect{ |path| Project.new(path) }.
     keep_if{ |fp| fp.has_faulty_refs? && fp.has_packages_config? }
end
matched_refs(refs, packages, asmname_to_package = {}) click to toggle source
# File lib/albacore/tools/restore_hint_paths.rb, line 54
def matched_refs refs, packages, asmname_to_package = {}
  refs.collect { |ref| 
    ref_include_id = asmname_to_package.fetch(ref['Include'].split(',')[0]) { |k| k }
    found_pkg = packages[ref_include_id]
    debug "ref[Include] = #{ref_include_id}, package: #{found_pkg}" unless found_pkg.nil?
    debug "NOMATCH: #{ref_include_id}" if found_pkg.nil?
    found_pkg.nil? ? nil : MatchedRef.new(found_pkg, ref)
  }.keep_if { |match| not match.nil? }
end