Class: BigKeeper::LockfileParser

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/big_keeper/util/lockfile_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLockfileParser

Returns a new instance of LockfileParser.



12
13
14
15
# File 'lib/big_keeper/util/lockfile_parser.rb', line 12

def initialize
  self.pods = {}
  self.dependencies = []
end

Instance Attribute Details

#dependenciesObject

Returns the value of attribute dependencies.



9
10
11
# File 'lib/big_keeper/util/lockfile_parser.rb', line 9

def dependencies
  @dependencies
end

#main_pathObject

Returns the value of attribute main_path.



9
10
11
# File 'lib/big_keeper/util/lockfile_parser.rb', line 9

def main_path
  @main_path
end

#podfile_hashObject

Returns the value of attribute podfile_hash.



9
10
11
# File 'lib/big_keeper/util/lockfile_parser.rb', line 9

def podfile_hash
  @podfile_hash
end

#podsObject

Returns the value of attribute pods.



9
10
11
# File 'lib/big_keeper/util/lockfile_parser.rb', line 9

def pods
  @pods
end

Instance Method Details

#chose_version(cur_version, temp_version) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/big_keeper/util/lockfile_parser.rb', line 125

def chose_version(cur_version,temp_version)
 # p "cur:#{cur_version},temp:#{temp_version}"
 cur_list = cur_version.split('.')
 temp_list = temp_version.split('.')
 cur_list << 0.to_s if cur_list.size == 2
 temp_list << 0.to_s if temp_list.size == 2
 if cur_list[0] >= temp_list[0]
   if cur_list[1] >= temp_list[1]
     if cur_list[2] > temp_list[2]
       return cur_version
     end
     return temp_version
   end
   return temp_version
 end
 return temp_version
end

#deal_pod(s) ⇒ Object

处理PODS TODO 去除重复



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/big_keeper/util/lockfile_parser.rb', line 82

def deal_pod(s)
  pod_name = get_lock_podname(s)
  return if pod_name == nil
  pod_version = get_lock_version(s)
  if self.pods.keys.include?(pod_name)
    current_version = self.pods[pod_name]
    if pod_version != nil && current_version != nil
        self.pods[pod_name] = chose_version(current_version, pod_version)
    else
        self.pods[pod_name] = pod_version unless pod_version == nil
    end
  end
  self.pods[pod_name] = pod_version unless pod_version == nil
end

#deal_spec(s) ⇒ Object

处理SPEC CHECKSUMS



107
108
109
110
111
112
# File 'lib/big_keeper/util/lockfile_parser.rb', line 107

def deal_spec(s)
  if /: +/ =~ s
    dependency = $~.pre_match.strip
    self.dependencies << dependency unless self.dependencies.include?(dependency)
  end
end

#get_lock_podname(sentence) ⇒ Object

获得lock pod名称



114
115
116
117
118
# File 'lib/big_keeper/util/lockfile_parser.rb', line 114

def get_lock_podname(sentence) #获得lock pod名称
  match_result = /(\d+.){1,2}\d+/.match(sentence.delete('- :~>='))
  pod_name = match_result.pre_match unless match_result == nil
  return pod_name.delete('()') unless pod_name == nil
end

#get_lock_version(sentence) ⇒ Object

获得lock pod版本号



120
121
122
123
# File 'lib/big_keeper/util/lockfile_parser.rb', line 120

def get_lock_version(sentence)#获得lock pod版本号
  match_result = /(\d+.){1,2}\d+/.match(sentence)
  return match_result[0].strip unless match_result == nil
end

#get_unlock_pod_list(is_all) ⇒ Object



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
# File 'lib/big_keeper/util/lockfile_parser.rb', line 48

def get_unlock_pod_list(is_all)
  result = {}
  pod_parser = PodfileParser.instance
  #podfile 中 unlock pods
  unlock_pods = pod_parser.get_unlock_pod_list
  # @unlock_pod_list << pod_name unless @module_list.include pod_name
  if is_all
    self.dependencies.each do |pod_name|
      if pod_parser.pod_list.include?(pod_name)
        next
      end
      if self.pods[pod_name] != nil
        result[pod_name] = self.pods[pod_name]
      end
    end

    unlock_pods.each do |pod_name|
      if self.pods[pod_name] != nil
        result[pod_name] = self.pods[pod_name]
      end
    end
    return result
  else
    unlock_pods.each do |pod_name|
      if self.pods[pod_name] != nil
        result[pod_name] = self.pods[pod_name]
      end
    end
    return result
  end
end

#parse(main_path) ⇒ Object



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
46
# File 'lib/big_keeper/util/lockfile_parser.rb', line 17

def parse(main_path)
 self.main_path = main_path
 $mode = 'PODS'
 podfile_lock_lines = File.readlines("#{main_path}/Podfile.lock", :encoding => 'UTF-8')
 Logger.highlight("Analyzing Podfile.lock...")
 podfile_lock_lines.each do |sentence|
   if sentence.include?('PODS')
     $mode = 'PODS'
   elsif sentence.include?('DEPENDENCIES')
     $mode = 'DEPENDENCIES'
   elsif sentence.include?('SPEC REPOS')
     $mode = 'SPEC REPOS'
   elsif sentence.include?('SPEC CHECKSUMS')
     $mode = 'SPEC CHECKSUMS'
   elsif sentence.include?('CHECKOUT OPTIONS')
     $mode = 'CHECKOUT OPTIONS'
   elsif sentence.include?('EXTERNAL SOURCES')
     $mode = 'EXTERNAL SOURCES'
   elsif sentence.include?('PODFILE CHECKSUM')
     $mode = 'PODFILE CHECKSUM'
   else
     if $mode == 'PODS'
        deal_pod(sentence.strip.chomp)
     end
     if $mode == 'SPEC CHECKSUMS'
        deal_spec(sentence.strip.chomp)
     end
   end
  end
end