Class: ConflictDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/furion/ver_conflict_detector.rb

Class Method Summary collapse

Class Method Details

.compareRequire(sdk, requireArray) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# 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

.detectConflictObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# 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) ⇒ Object



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
# 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) ⇒ Object



104
105
106
107
108
109
110
111
112
# 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) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 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) ⇒ Object



94
95
96
97
98
99
100
101
102
# 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

.requestVersionDependancyObject

clientType=1&name=yome&projectCode=yome&type=1



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# 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) ⇒ Object



114
115
116
117
118
119
# 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