Module: UVPROJX
- Included in:
- MDK::Project
- Defined in:
- lib/ebngen/adapter/mdk/uvprojx.rb
Overview
end Hash
Instance Method Summary collapse
- #add_sources(doc, source_hash, path_mod, proj_path) ⇒ Object
-
#add_specific(target_node, doc) ⇒ Object
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.
-
#append_node(doc, hash_value) ⇒ Object
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.
-
#create_node(doc, hash_value) ⇒ Object
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.
- #init_project(xml, settings) ⇒ Object
- #load_node(doc, xpath) ⇒ Object
- #new_target(target, doc, name = 'debug') ⇒ Object
-
#remove_sources(doc) ⇒ Object
remove_sources remove source files Params: - doc: the xml node project file.
-
#remove_targets(doc, targets_in) ⇒ Object
remove_targets remove unused targets Params: - doc: the xml node project file - targets_in: used target array (will keep).
-
#remove_unused(doc, xpath, **names) ⇒ Object
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.
- #save(xml, path) ⇒ Object
-
#set_specific(target_node, doc) ⇒ Object
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.
- #travesernode(node) ⇒ Object
Instance Method Details
#add_sources(doc, source_hash, path_mod, proj_path) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# 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) ⇒ Object
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
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/ebngen/adapter/mdk/uvprojx.rb', line 149 def add_specific(target_node, doc) doc.each do |key, value| = target_node.xpath(key) .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) ⇒ Object
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
139 140 141 |
# 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) ⇒ Object
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
131 132 133 |
# 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) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# 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) ⇒ Object
56 57 58 |
# 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') ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# 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) ⇒ Object
remove_sources remove source files Params:
-
doc: the xml node project file
101 102 103 104 105 106 107 108 109 110 |
# 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) ⇒ Object
remove_targets remove unused targets Params:
-
doc: the xml node project file
-
targets_in: used target array (will keep)
86 87 88 89 90 91 92 93 94 95 96 |
# 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) ⇒ Object
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
116 117 118 119 120 121 122 123 124 125 |
# 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) ⇒ Object
199 200 201 202 203 204 205 |
# 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) ⇒ Object
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
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/ebngen/adapter/mdk/uvprojx.rb', line 175 def set_specific(target_node, doc) doc.each do |key, value| = target_node.xpath(key) .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) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |