module UVPROJX

Public Instance Methods

add_sources(doc, source_hash, path_mod, proj_path) click to toggle source
# File lib/ebngen/adapter/mdk/uvprojx.rb, line 207
def add_sources(doc, source_hash, path_mod, proj_path)
  groups_existing = Array.new
  files_hash = Hash.new
  source_hash.each do |src|
    rootdir = src['rootdir']
    virtual_dir = src['virtual_dir'] if src.has_key? 'virtual_dir'
    virtual_dir = src['virtual-dir'] if src.has_key? 'virtual-dir'
    if src.has_key?('path')
      path = src['path']
    else
      path = src['source']
    end
    if virtual_dir
      if ! groups_existing.include?(virtual_dir)
        groups_existing.insert(-1, virtual_dir)
        node = Nokogiri::XML::Node.new 'Group', doc
        node << "<GroupName>#{virtual_dir}</GroupName>"
        doc << node
      end
      files_hash[virtual_dir] = Array.new if files_hash[virtual_dir].nil?
      files_hash[virtual_dir].insert(-1, {'path' => path, 'rootdir' => rootdir})
    else
      #create a common src group
      if ! groups_existing.include?("_src")
        groups_existing.insert(-1, "_src")
        node = Nokogiri::XML::Node.new 'Group', doc
        node << "<GroupName>_src</GroupName>"
        doc << node
      end
      files_hash["_src"] = Array.new if files_hash["_src"].nil?
      files_hash["_src"].insert(-1, {'path' => path, 'rootdir' => rootdir})
    end
  end #end source_hash
  doc.css("Group").each do |node|
    files_hash[node.at_css("GroupName").text].each do |file|
      gfiles = Nokogiri::XML::Node.new('Files', node)
      gfile = Nokogiri::XML::Node.new('File', gfiles)
      sfile = Nokogiri::XML::Node.new('FileName', gfiles)
      spfile = Nokogiri::XML::Node.new('FilePath', gfiles)
      if file['rootdir']
        full_path = path_mod.fullpath(file['rootdir'],file['path'])
      else
        full_path = path_mod.fullpath('default_path',file['path'])
      end
      sfile.content = File.basename(file['path'])
      spfile.content = File.join("$PROJ_DIR$", path_mod.relpath(proj_path, full_path))
      gfile << sfile
      gfile << spfile
      gfiles << gfile
      node << gfiles
    end
  end
  return if files_hash["_src"].nil?
  files_hash["_src"].each do |file|
    gfiles = Nokogiri::XML::Node.new('File', doc)
    gfile = Nokogiri::XML::Node.new('File', gfiles)
    sfile = Nokogiri::XML::Node.new('FileName', gfiles)
    spfile = Nokogiri::XML::Node.new('FilePath', gfiles)
    if file['rootdir']
      full_path = path_mod.fullpath(file['rootdir'],file['path'])
    else
      full_path = path_mod.fullpath('default_path',file['path'])
    end
    spfile.content = File.join("$PROJ_DIR$", path_mod.relpath(proj_path, full_path))
    sfile.content = File.basename(file['path'])
    gfile << sfile
    gfile << spfile
    gfiles << gfile
    node << gfiles
  end
end
add_specific(target_node, doc) click to toggle source

add_specific Params:

  • doc: hash to add to target

  • target_node: node to be added to

  • note:

    can not add none exist node for mdk xml
# File lib/ebngen/adapter/mdk/uvprojx.rb, line 149
def add_specific(target_node, doc)
  doc.each do |key, value|
    options = target_node.xpath(key)
    options.each do |option|
      if value.class == Hash
        value.each do |subnode|
            add_specific(option, subnode)
        end
      elsif value.class == String
          option.content += ";#{value}"
      elsif value.class == Array
          value.each do |line|
            option.content += ";#{line}"
          end
      else
        puts "not support by set_specific #{value}"
      end
    end
  end
end
append_node(doc, hash_value) click to toggle source

append_node convert hash to xml and append to doc Params:

  • doc: the xml node project file

  • hash_value: hash that defines the nodes structure

# File lib/ebngen/adapter/mdk/uvprojx.rb, line 139
def append_node(doc, hash_value)
  hash_value.to_xml(doc)
end
create_node(doc, hash_value) click to toggle source

create_node convert hash to xml and add to doc Params:

  • doc: the xml node project file

  • hash_value: hash that defines the nodes structure

# File lib/ebngen/adapter/mdk/uvprojx.rb, line 131
def create_node(doc, hash_value)
  hash_value.to_xml!(doc)
end
init_project(xml, settings) click to toggle source
# File lib/ebngen/adapter/mdk/uvprojx.rb, line 45
def init_project(xml, settings)
  project_node = xml.at_xpath("Project")
  travesernode(project_node)
  #puts workspace_node
  #puts xml
  #mdkProvider.take(:title) # => 'The Monkey Wrench Gang'
  #mdkProvider.take(:author) # => 'Edward Abbey'
  #mdkProvider.take(:display_title) # => 'Edward Abbey - The Monkey Wrench Gang'
  #mdkProvider.take(:price) # => 9.99
end
load_node(doc, xpath) click to toggle source
# File lib/ebngen/adapter/mdk/uvprojx.rb, line 56
def load_node(doc, xpath)
      return doc.xpath(xpath)
end
new_target(target, doc, name = 'debug') click to toggle source
# File lib/ebngen/adapter/mdk/uvprojx.rb, line 60
def new_target(target, doc, name = 'debug')
      nset = load_node(doc, "//Targets/Target")
      #use existing one
      nset.each do |element|
              if element.css("TargetName").text.downcase == target.downcase
      puts "find existing #{element.css("/TargetName").text.downcase}"
      return element
              end
      end
      #create new one
      nset.each do |element|
              #use the first available configuration
    @logger.info "add target #{target}"
              t = element.dup
              t.at_css("TargetName").content = target
                      #doc.xpath("/project") << t
              element.add_previous_sibling(t)
              return t
      end
       nil
end
remove_sources(doc) click to toggle source

remove_sources remove source files Params:

  • doc: the xml node project file

# File lib/ebngen/adapter/mdk/uvprojx.rb, line 101
def remove_sources(doc)
  groups = load_node(doc, "//Group")
  groups.each do |ele|
    ele.remove
  end
  files = load_node(doc, "//File")
  files.each do |ele|
    ele.remove
  end   
end
remove_targets(doc, targets_in) click to toggle source

remove_targets remove unused targets Params:

  • doc: the xml node project file

  • targets_in: used target array (will keep)

# File lib/ebngen/adapter/mdk/uvprojx.rb, line 86
def remove_targets(doc, targets_in)
      #remove the target that not in the targets_in
      nset = load_node(doc, "//Targets/Target")
      targets_in.collect{|x| x.downcase} 
  nset.each do |element|
        target = element.xpath("TargetName").text.downcase
        if !targets_in.include?(target)
           element.remove
        end        
        end
end
remove_unused(doc, xpath, **names) click to toggle source

remove_sources remove unused node Params:

  • doc: the xml node project file

  • xpath: xpath to the node

  • **names: node attribute that need to remove defined in hash

# File lib/ebngen/adapter/mdk/uvprojx.rb, line 116
def remove_unused(doc, xpath, **names)
      nset = load_node(doc, xpath)
        nset.each do |element|
                names.each do |key, value|
                        if element.xpath(key).text.downcase == value.downcase
                                element.remove
                        end
                end
        end
end
save(xml, path) click to toggle source
# File lib/ebngen/adapter/mdk/uvprojx.rb, line 199
def save(xml, path)
  Core.assert(path.is_a?(String)) do
      "param is not a string #{path.class.name}"
  end
  FileUtils.mkdir_p File.dirname(path) if ! File.exist?(File.dirname(path))
  File.write(path, xml.to_xml)
end
set_specific(target_node, doc) click to toggle source

set_specific Params:

  • doc: hash to add to target

  • target_node: node to be added to

  • note:

    can not add none exist node for mdk xml
# File lib/ebngen/adapter/mdk/uvprojx.rb, line 175
def set_specific(target_node, doc)
  doc.each do |key, value|
    options = target_node.xpath(key)
    options.each do |option|
      if value.class == Hash
        value.each do |subnode|
            add_specific(option, subnode)
        end
      elsif value.class == String
          option.content = value
          break
      elsif value.class == Array
          option.content = ""
          value.each do |line|
            option.content += ";#{line}"
          end
          break
      else
        puts "not support by set_specific #{value}"
      end
    end
  end
end
travesernode(node) click to toggle source
# File lib/ebngen/adapter/mdk/uvprojx.rb, line 32
def travesernode(node)
  if node.children
    content  = node.content
    if @@data_provider.has_key?(content.strip)
      node.content =  @@data_provider[content.strip]
    end
  end
  node.children.each do |subnode|
    next if subnode.nil?
    travesernode(subnode)
  end
 
end