Class: Pod::Command::Lzsource

Inherits:
Pod::Command show all
Defined in:
lib/cocoapods-lzsource/command/lzsource.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Lzsource

Returns a new instance of Lzsource.



38
39
40
41
42
43
44
45
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 38

def initialize(argv)
	@list = argv.flag?('list')
	@info = argv.flag?('info')
	@clear = argv.flag?('clear')
  @reset = argv.flag?('reset')
  @name = argv.shift_argument
  super
end

Class Method Details

.optionsObject

self.arguments = [CLAide::Argument.new(%w(NAME), true)]



28
29
30
31
32
33
34
35
36
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 28

def self.options
  [
  	['--list', 'Show all items list.'],
    ['--clear', 'Clear all items.'],
    ['--info', 'Query a item information.'],
    ['--reset', 'Reset token and gitlab url.'],
  ]
  # .concat(super)
end

Instance Method Details

#checkPodObject



217
218
219
220
221
222
223
224
225
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 217

def checkPod
    podPath = Dir.pwd+'/Pods/'
    if File.directory?(podPath)
    
    else
      UI.puts "Please check the current directory.This project directory may be not a cocoapods project."
      log()
    end
end

#cleanCacheObject



234
235
236
237
238
239
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 234

def cleanCache
  cachePath = File.expand_path('~')+"/Library/Developer/Xcode/DerivedData/"
  if File.directory?(cachePath)
    `rm -r #{cachePath}`
  end
end

#clearObject

lzsource –clear



279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 279

def clear
  if File.exist?(InstallCodePathFile)
      File.open(InstallCodePathFile,"r").each_line do |line|
        addr = line.gsub("\n", '')
        arr = addr.split("***")
        if File.directory?(arr[1])
            `sudo rm -rf #{arr[1]}`
        end
      end
      File.delete(InstallCodePathFile)
  end
  UI.puts 'Clear successful!'
end

#createDownloadDirObject



190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 190

def createDownloadDir

  if File.directory?($CodePath)
    `sudo rm -rf #{$CodePath}`
  end

  `sudo mkdir -p -m 777 #{$CodePath};sudo chown -R $(whoami) #{$CodePath}`

  if !File.directory?($CodePath)
    UI.puts 'Failed to create install path.'
    log()
  end
end

#downloadObject



204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 204

def download
  t = Thread.new {
    startLoading()
  }
  cloneFlag = system("sudo git clone #{$CodeAddr} #{$CodePath} >/dev/null 2>&1")
  Thread.kill(t)
  if cloneFlag == false
    UI.puts 'Failed to download source code.'
    log()
  end
  print "\rDownload successful!\n"
end

#getDebugPathObject



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
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 154

def getDebugPath
  
  temp_dir = 'unknow'
  
  at_name = `dwarfdump -debug-str -arch=arm64 --lookup 0x0000002f #{$LibPath} | grep 'DW_AT_name' | head -1`
  arr = at_name.split('"')
  if arr.size > 1
    if arr[1].include?(SplitWords)
      temp = arr[1].split(SplitWords)
      if temp.size > 0
        temp_dir = temp[0]+SplitWords
      end
    end
  end

  temp_path = 'unknow'

  at_comp_dir = `dwarfdump -debug-str -arch=arm64 --lookup 0x0000002f #{$LibPath} | grep 'DW_AT_comp_dir' | head -1`
  arr = at_comp_dir.split('"')
  if arr.size > 1
    if arr[1].include?(SplitWords)
      temp = arr[1].split(SplitWords)
      if temp.size > 1
        temp_path = temp[1]
      end
    end
  end

  if temp_dir != 'unknow' && temp_path != 'unknow'
    $CodePath = temp_dir+temp_path
  else
    UI.puts 'Failed to get install path.'
    log()
  end
end

#getLibPathObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 123

def getLibPath
  podPath = Dir.pwd+'/Pods/'
  path = Dir.pwd+'/Pods/'+$ProjectDir

  if File.directory?(podPath)
    if File.directory?(path)
     traverse_dir(path)
     if $LibPath == 'unknow'
      UI.puts 'Failed to get lib path.'
      log()
    end
   else
    UI.puts "Failed to get pod path.Please check the parameter."
    log()
   end
  else
    UI.puts "Failed to get pod path.This project directory may be not a cocoapods project."
    log()
  end
end

#getSourceCodeInfo(keyword) ⇒ Object

下载源代码流程 lzsource



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 100

def getSourceCodeInfo(keyword)

  gitlabHttp= GitLabHttp.new 
  info = gitlabHttp.getSourceCodeInfo(keyword)
  if info.count > 0
    $CodeAddr = info[2]
    $ProjectDir = info[3]
  else
    UI.puts "No search result by the keyword.Please check the parameter."
    log()
  end

  if $ProjectDir == 'unknow'
    UI.puts 'Failed to get lib dir.'
    log()
  end
  if $CodeAddr == 'unknow'
    UI.puts 'Failed to get git address.'
    log()
  end

end

#info(keyword) ⇒ Object

lzsource –info



262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 262

def info(keyword)
  gitlabHttp= GitLabHttp.new 
  info = gitlabHttp.getProjectInfo(keyword)
  if info.count > 0
    puts '----------------'
  end
  info.each do |d|
    puts 'Repository name:'+d[0]
    puts 'Repository web:'+d[1]
    puts 'Repository ssh:'+d[2]
    # puts 'Repository path:'+d[3]
    puts '----------------'
  end
end

#listObject

lzsource –list



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 242

def list
  if File.exist?(InstallCodePathFile)
    UI.puts "Currently installed:"
    tempNames = Array.new
    names = Array.new
    count = 0
    File.open(InstallCodePathFile,"r").each_line do |line|
      temp = line.gsub("\n", '')
      arr = temp.split("***")
      if !tempNames.include?(arr[0])
        names << " "+"#{count+1}:"+ arr[0]
        tempNames << arr[0]
        count = count +1
      end
    end
    puts names
  end
end

#logObject

tools



303
304
305
306
307
308
309
310
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 303

def log
	# UI.puts ''
 #  UI.puts 'Dir  Name:'+$ProjectDir
 #  UI.puts 'Lib  Path:'+$LibPath
 #  UI.puts 'Code Path:'+$CodePath
 #  UI.puts 'Code Addr:'+$CodeAddr
  exit
end

#resetObject

lzsource –reset



295
296
297
298
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 295

def reset
  gitlabHttp= GitLabHttp.new 
  gitlabHttp.resetInfo()
end

#runObject



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
93
94
95
96
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 53

def run
	if @clear != true &&  @list != true && @reset != true && @info != true && @name.nil?
		help!
		log()
	end
	if @clear == true
    checkPod()
		clear()
	elsif @list == true
    checkPod()
		list()
  elsif @reset == true
    checkPod()
    reset()
	elsif @info == true
		if @name.nil?
			help!
			log()
		else
      checkPod()
			info(@name)
		end
	else

    checkPod()

    getSourceCodeInfo(@name) # CodeAddr ProjectDir

  	getLibPath() # LibPath

  	getDebugPath() # $CodePath
  	
    createDownloadDir()

    download()

    saveCodePath()

    cleanCache()

    list()

	end
end

#saveCodePathObject



227
228
229
230
231
232
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 227

def saveCodePath
  f=File.open(InstallCodePathFile,"a+")
  f.puts $ProjectDir+"***"+$CodePath
  f.close
  
end

#startLoadingObject



312
313
314
315
316
317
318
319
320
321
322
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 312

def startLoading
  spin = ["\\",'|','/','-']
  cunt = 0
  while true
    cunt +=1
    str = spin[cunt%4]
    print "downloading:#{str}"
    sleep 0.12
    print "\r"
  end
end

#traverse_dir(file_path) ⇒ Object



144
145
146
147
148
149
150
151
152
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 144

def traverse_dir(file_path)
  Find.find(file_path) do |filename|
    extn = File.extname filename
    if extn == '.a'
      $LibPath = filename
      break
    end
  end
end

#validate!Object



47
48
49
50
51
# File 'lib/cocoapods-lzsource/command/lzsource.rb', line 47

def validate!
  super

  # help!
end