Class: Luna::Binary::Common

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/luna/binary/common/common.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommon

Returns a new instance of Common.



23
24
# File 'lib/luna/binary/common/common.rb', line 23

def initialize()
end

Instance Attribute Details

#bin_devObject (readonly)

Returns the value of attribute bin_dev.



17
18
19
# File 'lib/luna/binary/common/common.rb', line 17

def bin_dev
  @bin_dev
end

#binary_download_urlObject (readonly)

Returns the value of attribute binary_download_url.



20
21
22
# File 'lib/luna/binary/common/common.rb', line 20

def binary_download_url
  @binary_download_url
end

#binary_repo_urlObject (readonly)

Returns the value of attribute binary_repo_url.



18
19
20
# File 'lib/luna/binary/common/common.rb', line 18

def binary_repo_url
  @binary_repo_url
end

#binary_upload_urlObject (readonly)

Returns the value of attribute binary_upload_url.



19
20
21
# File 'lib/luna/binary/common/common.rb', line 19

def binary_upload_url
  @binary_upload_url
end

#download_file_typeObject (readonly)

Returns the value of attribute download_file_type.



21
22
23
# File 'lib/luna/binary/common/common.rb', line 21

def download_file_type
  @download_file_type
end

#lockfileObject

Returns the value of attribute lockfile.



16
17
18
# File 'lib/luna/binary/common/common.rb', line 16

def lockfile
  @lockfile
end

#podFilePathObject

Returns the value of attribute podFilePath.



15
16
17
# File 'lib/luna/binary/common/common.rb', line 15

def podFilePath
  @podFilePath
end

#stateObject

Returns the value of attribute state.



14
15
16
# File 'lib/luna/binary/common/common.rb', line 14

def state
  @state
end

#versionObject

Returns the value of attribute version.



14
15
16
# File 'lib/luna/binary/common/common.rb', line 14

def version
  @version
end

Instance Method Details

#binary_path_armObject



66
67
68
# File 'lib/luna/binary/common/common.rb', line 66

def binary_path_arm
    return tempLunaUploaderPath + "/arm64"
end

#binary_path_mergedObject



62
63
64
# File 'lib/luna/binary/common/common.rb', line 62

def binary_path_merged
  return tempLunaUploaderPath + "/merged"
end

#binary_path_x86Object



70
71
72
# File 'lib/luna/binary/common/common.rb', line 70

def binary_path_x86
    return tempLunaUploaderPath + "/x86"
end

#command(commandStr) ⇒ Object



79
80
81
82
# File 'lib/luna/binary/common/common.rb', line 79

def command(commandStr)
  puts commandStr.yellow
  return system commandStr
end

#create_upload_lockitem(lockItem, moduleName, binary_path) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/luna/binary/common/common.rb', line 139

def create_upload_lockitem(lockItem, moduleName, binary_path)
  if lockItem.external_source == nil
    uploader = uploadLintPodSpec(moduleName, lockItem.specific_version, binary_path) 
    if uploader != nil
        return uploader
    end
  else 
    p lockItem.external_source
    gitURL = lockItem.external_source['git'.parameterize.underscore.to_sym]
    tag = lockItem.external_source['tag'.parameterize.underscore.to_sym]
    path = lockItem.external_source['path'.parameterize.underscore.to_sym]
    p "#{moduleName} git: #{gitURL} tag: #{tag} path: #{path}"
    if path
        pathArr = Dir.glob("#{Dir.pwd}/#{path}/**/#{moduleName}.podspec")
        if pathArr 
            uploader = Uploader::SingleUploader.new(moduleName, "", "", binary_path)
            uploader.local_path = pathArr.first
            return uploader
        end
        
    elsif gitURL && tag && !moduleName["/"]
        uploader = Uploader::SingleUploader.new(moduleName, gitURL, tag, binary_path)
        return uploader
    end
  end
end

#createNeedFrameworkMapperObject



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/luna/binary/common/common.rb', line 111

def createNeedFrameworkMapper
    spec_repo_binary = {}
    puts "二进制repo地址 : #{Common.instance.binary_repo_url}".yellow
    use_framework_list.each { |item|
        name = item.split('/').first
        if spec_repo_binary[name] == nil
            spec_repo_binary[name] = lockfile.version(name).version
        end
    }    
    p "use_framework_list: #{spec_repo_binary}"
    return spec_repo_binary
end

#deleteDirectory(dirPath) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/luna/binary/common/common.rb', line 41

def deleteDirectory(dirPath)
    if File.directory?(dirPath)
      Dir.foreach(dirPath) do |subFile|
        if subFile != '.' and subFile != '..' 
          deleteDirectory(File.join(dirPath, subFile));
        end
      end
      Dir.rmdir(dirPath);
    else
      if File.exist?(dirPath)
        File.delete(dirPath);
      end
    end
end

#dependenciesMapperObject



218
219
220
# File 'lib/luna/binary/common/common.rb', line 218

def dependenciesMapper
  return lockfile.dependencies.map { |item| [item.name.split("/").first, item]}.to_h
end

#findLintPodspec(moduleName) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/luna/binary/common/common.rb', line 84

def findLintPodspec(moduleName)
  sets = Pod::Config.instance.sources_manager.search_by_name(moduleName)
  # p sets
  if sets.count == 1
      set = sets.first
  elsif sets.map(&:name).include?(moduleName)
      set = sets.find { |s| s.name == moduleName }
  else
      names = sets.map(&:name) * ', '
      # raise Informative, "More than one spec found for '#{moduleName}':\n#{names}"
  end  
  return set  
end

#repoPathObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/luna/binary/common/common.rb', line 26

def repoPath
    sources = Pod::Config.instance.sources_manager.all
    repoPath = nil
    sources.each { |item|
      if item.url == Common.instance.binary_repo_url
        repoPath = item.repo
      end
    }
    if repoPath == nil
      p '没找到repo路径'
      raise '没找到repo路径'  
    end
    return repoPath
end

#request_result_hashObject



102
103
104
105
106
107
108
109
# File 'lib/luna/binary/common/common.rb', line 102

def request_result_hash
    command = "curl #{Common.instance.binary_upload_url}"
    p command
    result = %x(#{command})
    request_result_hash = JSON.parse(result)
    p request_result_hash
    return request_result_hash
end

#tempLunaUploaderPathObject



56
57
58
59
60
# File 'lib/luna/binary/common/common.rb', line 56

def tempLunaUploaderPath
  result = `pwd`
  rootName = result.strip! + "/temp-luna-uploader"
  return rootName
end

#upload_lockitem(dependencies_mapper, moduleName, binary_path, is_refresh = false) ⇒ Object



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
# File 'lib/luna/binary/common/common.rb', line 166

def upload_lockitem(dependencies_mapper, moduleName, binary_path, is_refresh = false)
  if dependencies_mapper[moduleName]
    lockContent = lockfile.dependencies_to_lock_pod_named(moduleName)
    if lockContent  #dependencies 应该拿不到所有的spec的依赖,我理解只能拿到podfile里面标明的,词典碰到dependency 没有bonmot的情况
        lockContent.each { |lockItem|
            begin
                loader = create_upload_lockitem(lockItem, moduleName, binary_path)
                if is_refresh
                  loader.refresh_specification_work
                else
                  loader.specificationWork
                end
                return loader
            rescue => exception
                raise exception
            ensure

            end
        }   
    end
  else
      begin
          uploader = uploadLintPodSpec(moduleName, lockfile.version(moduleName), binary_path) 
          if uploader != nil
              if is_refresh
                uploader.refresh_specification_work
              else
                uploader.specificationWork
              end
              return uploader
          end
      rescue => exception
        raise exception
      ensure

      end
  end
end

#uploadLintPodSpec(moduleName, specificVersion, binaryPath) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/luna/binary/common/common.rb', line 205

def uploadLintPodSpec(moduleName, specificVersion, binaryPath) 
  set = findLintPodspec(moduleName)
  if set 
      pathArr = set.specification_paths_for_version(specificVersion)
      if pathArr.length > 0
          uploader = Uploader::SingleUploader.new(moduleName, "", "", binaryPath)
          uploader.specification=Pod::Specification.from_file(pathArr.first)
          # uploader.specificationWork
      end
  end
  return uploader
end

#use_framework_listObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/luna/binary/common/common.rb', line 124

def use_framework_list
  list = []
  File.open(Dir.pwd+"/Podfile", 'r:utf-8') do  |f|
      f.each_line do |item|
          if item[":dev_env_use_binary"]
              matchs = item.match(/\'(?<=').*?(?=')\'/)
              if matchs != nil
                  list << matchs[0].gsub("'", "")
              end
          end
      end
    end
  return list
end