class QCloudHive::Manifest
Attributes
default[RW]
projects[RW]
remotes[RW]
Public Class Methods
new(filePath)
click to toggle source
# File lib/qcloudhive/manifest.rb, line 167 def initialize(filePath) @manifestPath = filePath @doc = Nokogiri::XML(File.open(filePath)) @default = ManifestDefault.new @projects = [] @doc.xpath("//project").each { |p| remote = p.attribute("remote").value name = p.attribute("name").value if name.start_with?("/") name= name[1..name.length] end path = p.attribute("path").value project = ManifestProject.new(remote, name, path) @projects << project L.debug project } @remotes = [] @doc.xpath("//remote").each { |r| name = r.attribute("name").value fetch = r.attribute("fetch").value if not fetch.end_with?("/") fetch = fetch+"/" end remote = ManifestRemote.new(name, fetch) @remotes << remote } end
Public Instance Methods
addModule(url, path)
click to toggle source
# File lib/qcloudhive/manifest.rb, line 196 def addModule(url, path) uri = URI(url) host = uri.host scheme = uri.scheme remote = nil uriPath = uri.path.split(".").first if uriPath.start_with?("/") uriPath= uriPath[1..uriPath.length] end name = uriPath.split("/").last @projects.each { |p| if p.name == uriPath return @projects end } @remotes.each { |r| rfetch = URI(r.fetch) if rfetch.host == host and rfetch.scheme == scheme remote = r.name end } projectPath = "#{name}" if path != nil if path.start_with?("/") path = path[1..-1] end if path.end_with?("/") projectPath = "#{path}#{name}" else if path.length > 0 projectPath = "#{path}/#{name}" else projectPath = "#{name}" end end end remote = ManifestProject.new(remote, uriPath ,projectPath) @projects << remote end
deleteModule(url)
click to toggle source
# File lib/qcloudhive/manifest.rb, line 259 def deleteModule(url) uri = URI(url) uriPath = uri.path.split(".").first if uriPath.start_with?("/") uriPath= uriPath[1..uriPath.length] end L.debug "#{@projects}" @projects=@projects.select{ |e| e.name != uriPath } L.debug "#{@projects}" end
deleteModuleByName(name)
click to toggle source
# File lib/qcloudhive/manifest.rb, line 272 def deleteModuleByName(name) L.debug "#{@projects}" @projects=@projects.select{ |e| e.moduleName != name } L.debug "#{@projects}" end
existModule?(name)
click to toggle source
# File lib/qcloudhive/manifest.rb, line 236 def existModule?(name) @projects.select{ |p| if p.name.start_with?(Config.team) p.name == Config.team+"/#{name}" else p.name == name end }.count > 0 end
flushStorage()
click to toggle source
# File lib/qcloudhive/manifest.rb, line 307 def flushStorage File.open(@manifestPath, "w") { |f| f.write toXML } end
moduleByName(name)
click to toggle source
# File lib/qcloudhive/manifest.rb, line 246 def moduleByName(name) @projects.each { |p| L.info p.name } @projects.select{ |p| if p.name.start_with?(Config.team) p.name == Config.team+"/#{name}" else p.name == name end }.first end
remoteByName(name)
click to toggle source
# File lib/qcloudhive/manifest.rb, line 312 def remoteByName(name) @remotes.select { |e| e.name == name }.first end
sourceURLByModuleName(name)
click to toggle source
# File lib/qcloudhive/manifest.rb, line 315 def sourceURLByModuleName(name) L.debug "#{@projects}" moduleSpec = @projects.select{ |e| e.moduleName != name }.first if moduleSpec.nil? return nil end remote = remoteByName(moduleSpec.remote) return "#{remote.fetch}#{moduleSpec.name}" end
toXML()
click to toggle source
# File lib/qcloudhive/manifest.rb, line 280 def toXML doc = Nokogiri::XML('''<?xml version="1.0" encoding="UTF-8"?><manifest></manifest>''') manifest = doc.xpath("//manifest").first @remotes.each { |r| ele = Nokogiri::XML::Element.new("remote", doc) ele.set_attribute("name", r.name) ele.set_attribute("fetch", r.fetch) manifest.add_child(ele) } default = Nokogiri::XML::Element.new("default", doc) default.set_attribute("revision", @default.revision) default.set_attribute("remote", @default.remote) default.set_attribute("sync-j", @default.sync_j) manifest.add_child(default) @projects.each { |r| ele =Nokogiri::XML::Element.new("project", doc) ele.set_attribute("name",r.name) ele.set_attribute("remote" ,r.remote ) ele.set_attribute("path" ,r.path) manifest.add_child(ele) } return doc.to_s end