class ConflictDetector
Public Class Methods
compareRequire(sdk,requireArray)
click to toggle source
# File lib/furion/ver_conflict_detector.rb, line 147 def self.compareRequire(sdk,requireArray) # model a < x < b smallVersion = "0" min = smallVersion containMin = 0 # 用于区分 < 和 <= hugeVersion = "9999999.999999.999999" max = hugeVersion containMax = 0 depency = nil isConflict = 0 for require in requireArray depency = Pod::Dependency.new(sdk,require) operator = depency.requirement.requirements.first[0] version = depency.requirement.requirements.first[1] if String(operator) == '>=' || String(operator) == '~>' if self.isVersionBigger(version,min) == 1 min = version containMin = 1 end end if String(operator) == '>' if self.isVersionBigger(version,min) == 1 min = version containMin = 0 end end if String(operator) == '<=' if self.isVersionBigger(version,max) == 1 max = version containMax = 1 end end if String(operator) == '<' if self.isVersionBigger(max,version) == 1 max = version containMax = 0 end end if isVersionBigger(min,max) == 1 # 下限大于上限 isConflict = 1 else if min == max if containMax == 0 || containMin == 0 isConflict = 1 end end end if String(operator) == '=' if isVersionBigger(version,max) == 1 || isVersionBigger(min,version) ==1 # 固定版本在已有范围之外 isConflict = 1 else min = version max = version containMax = 1 containMin = 1 end end end result = {"isConflict"=>isConflict} if max != hugeVersion maxOperater = containMax == 1 ? "<=" : "<" maxRequire = maxOperater+ " " + String(max) result["maxRequire"] = maxRequire end if min != smallVersion minOperater = containMin == 1 ? ">=" : ">" minRequire = minOperater+ " " + String(min) result["minRequire"] = minRequire end return result end
detectConflict()
click to toggle source
# File lib/furion/ver_conflict_detector.rb, line 7 def self.detectConflict @openingSpec = [] @specRequire = {} # dict = Plist::parse_xml("MTPSDK.plist") file = File.read('sdkConfig.json') dict = JSON.parse(file) # "sdk":{"hypushsdk": {"wrapperVersion": "0.1.13-dev", "sdkVersion": "*", "wrapper": "pushsdk-wrapper"} sdkDict = {} sdkWrapperDict = dict["sdk"] for sdk in sdkWrapperDict.keys sdkInfo = sdkWrapperDict[sdk] sdkDict[sdk] = sdkInfo["sdkVersion"] if sdkInfo.key?"wrapper" sdkDict[sdkInfo["wrapper"]] = sdkInfo["wrapperVersion"] end end for sdk in sdkDict.keys version = sdkDict[sdk] self.loadSpec(sdk,version) end dependency = {} conflictInfo = {} for sdk in @specRequire.keys requireinfo = @specRequire[sdk] sdkConflict = self.compareRequire(sdk,requireinfo.values) dependency[sdk] = {"conflict"=>sdkConflict,"requirement"=>requireinfo} end json = dependency.to_json File.open("verionDependency.json", "w") do |out| out.write(json) end end
getSpecFromSDK(groupPath,sdkName,version)
click to toggle source
# File lib/furion/ver_conflict_detector.rb, line 123 def self.getSpecFromSDK(groupPath,sdkName,version) if version == "*" allPath = groupPath + "/" + sdkName + "/" + version subPathArray = Dir[allPath] wrapperPath = subPathArray.last else wrapperPath = groupPath + "/" + sdkName + "/" + version if !File.exist?(wrapperPath) return "" end end Find.find(wrapperPath) do |path| if path.end_with? ".podspec" return path break end end return "" end
isVersionBigger(version,otherVersion)
click to toggle source
# File lib/furion/ver_conflict_detector.rb, line 232 def self.isVersionBigger(version,otherVersion) varNumArray1 = String(version).split("-") verNum1 = varNumArray1[0] if varNumArray1.length() > 1 verExt1 = varNumArray1[1] else verExt1 = "*" end varNumArray2 = String(otherVersion).split("-") verNum2 = varNumArray2[0] if varNumArray2.length() > 1 verExt2 = varNumArray2[1] else verExt2 = "*" end if Gem::Version.new(verNum1) > Gem::Version.new(verNum2) return 1 else if Gem::Version.new(verNum1) == Gem::Version.new(verNum2) if verExt1 == '*' && verExt2 != '*' return 1 end end end return 0 end
isVersionSpecific(versionRequire)
click to toggle source
# File lib/furion/ver_conflict_detector.rb, line 104 def self.isVersionSpecific(versionRequire) symbols = ['~>','>=','<=','>','<'] for symbol in symbols if versionRequire.include?(symbol) return 1 end end return 0 end
loadSpec(specName,version)
click to toggle source
# File lib/furion/ver_conflict_detector.rb, line 47 def self.loadSpec(specName,version) if @openingSpec.include?(specName) return end user = Etc.getpwuid(Process.uid).name sourcePath = "/Users/" + user + "/.cocoapods/repos/huya-ci_team-specs" path = self.getSpecFromSDK(sourcePath,specName,version) if path.length == 0 # SDK的文件夹没找到,就从wrapper文件夹开始找 sourcePath = "/Users/" + user + "/.cocoapods/repos/Wrapper-Specs" path = self.getSpecFromSDK(sourcePath,specName,version) end if path.length == 0 # 如果在wrapper也没找到就说明找不到 return end @openingSpec.append(specName) ret = Pod::Specification.from_file(path, subspec_name = specName) if ret.dependencies.length == 0 return end dependencies = ret.dependencies for spec in ret.subspecs subDependencies = spec.dependencies for item in subDependencies dependencies.append(item) end end for item in dependencies requireStr = String(item.requirement) self.recordDependancy(item.name,requireStr,specName) if self.isVersionSpecific(requireStr) == 0 content = self.wrapSpecificVersion(requireStr) # 去掉空格和等号,只剩下大于/小于 self.loadSpec(item.name,content) end end end
recordDependancy(sdk,requirement,subscriber)
click to toggle source
# File lib/furion/ver_conflict_detector.rb, line 94 def self.recordDependancy(sdk,requirement,subscriber) requireInfo = @specRequire[sdk] if requireInfo == nil requireInfo = {} end requireInfo[subscriber] = requirement @specRequire[sdk] = requireInfo end
requestVersionDependancy()
click to toggle source
clientType=1&name=yome&projectCode=yome&type=1
# File lib/furion/ver_conflict_detector.rb, line 266 def self.requestVersionDependancy Find.find(Dir::pwd) do |path| puts path end appId = "mtpwebservices" token = "43010711d680a54c" time = DateTime.now.strftime('%Q') content = token + appId + String(time) puts content sign = Digest::SHA1.hexdigest(content) url = URI('http://aplus.local.web.hy/open-api/1.0/dependency/get?') # 设置请求参数 params = {'clientType':0,'type':1} url.query = URI.encode_www_form(params) puts url http = Net::HTTP.new(url.host, url.port) # 设置请求头 header = {'X-APLUS-APP':appId, 'X-APLUS-SIGN':sign, 'X-APLUS-TS':String(time)} puts header response = http.get(url, header) puts response.body end
wrapSpecificVersion(versionStr)
click to toggle source
# File lib/furion/ver_conflict_detector.rb, line 114 def self.wrapSpecificVersion(versionStr) content = String(versionStr) content = content.sub(" ","") content = content.sub("=","") return content end