cocoapods-monitor 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b12d30cde854a57cfb6d15d9e6052052a04ced0d0de7b2fd79711e68ab426d4c
4
+ data.tar.gz: 189b07ab75da82db86057bf4adf6e5dd8c523dff30b85a7d49b5d3c3848e0a9b
5
+ SHA512:
6
+ metadata.gz: 94f0933cff1eb69e618b2d93e44b78bfc071051957d2d96377938f2be9c800537911e38abd2b480369049e019c8865893a7ba8797f207353bdc04022690aea40
7
+ data.tar.gz: d58a0a5d96ffac337a4d97a757f49746989a9aa8fc1ada52282dba672e9a6d9fe04b7bfb008d072367af821dc190393acf1873bfe0ef28062afe155d1c562087
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cocoapods-monitor.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'cocoapods'
8
+
9
+ gem 'mocha'
10
+ gem 'bacon'
11
+ gem 'mocha-on-bacon'
12
+ gem 'prettybacon'
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2019 wusizhen.arch <wusizhen.arch@bytedance.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ <div align=center>
2
+
3
+ ![](http://tosv.byted.org/obj/toutiao.ios.arch/mpaas/tool/WechatIMG6.png)
4
+
5
+ </div>
6
+
7
+ # cocoapods-monitor
8
+
9
+ 用于监控和统计 APP 的组件使用情况,一键式接入 Sladar crash 自动分配功能的 Gem SDK
10
+
11
+ ## Installation
12
+
13
+ $ gem install cocoapods-monitor
14
+
15
+ ## Usage
16
+ 在 Podfile 中添加
17
+
18
+ plugin 'cocoapods-monitor'
19
+ 即可生效
20
+
21
+ ## Warning
22
+ 监控 SDK 只在 **Jenkins** 和 **Gitlab Runner** 中生效
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ def specs(dir)
4
+ FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
5
+ end
6
+
7
+ desc 'Runs all the specs'
8
+ task :specs do
9
+ sh "bundle exec bacon #{specs('**')}"
10
+ end
11
+
12
+ task :default => :specs
13
+
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cocoapods-monitor/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cocoapods-monitor'
8
+ spec.version = CocoapodsMonitor::VERSION
9
+ spec.authors = ['wusizhen.arch']
10
+ spec.email = ['wusizhen.arch@bytedance.com']
11
+ spec.description = %q{A short description of cocoapods-monitor.}
12
+ spec.summary = %q{A longer description of cocoapods-monitor.}
13
+ spec.homepage = 'https://code.byted.org/iOS_Library/cocoapods-monitor'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-monitor/gem_version'
@@ -0,0 +1 @@
1
+ require 'cocoapods-monitor/command/monitor'
@@ -0,0 +1,275 @@
1
+ # Created by Wusizhen on 3/15/18.
2
+ # Copyright (c) 2018 Bytedance. All rights reserved.
3
+
4
+ #!/usr/bin/env ruby
5
+ #!/usr/bin/ruby
6
+ # -*- coding: UTF-8 -*-
7
+ # encoding: utf-8
8
+ require 'cocoapods-monitor/gem_version'
9
+
10
+ BEGIN {
11
+ $Recorde = Hash.new
12
+ }
13
+
14
+ Pod::HooksManager.register('cocoapods-monitor', :post_install) do |installer_context|
15
+ cocoapods_bytedance_ComponentAnalyze(installer_context)
16
+ cocoapods_bytedance_SlardarRecord(installer_context)
17
+ cocoapods_bytedance_BusRecord(installer_context)
18
+ end
19
+
20
+ module Pod
21
+ class Installer
22
+
23
+ alias_method :bd_plugins,:plugins
24
+ def plugins
25
+ bd_plugins.merge({ 'cocoapods-monitor' => {} })
26
+ end
27
+ end
28
+ end
29
+
30
+ module Pod
31
+ class Specification
32
+ alias_method :bd_root , :root
33
+ def root
34
+ record_source
35
+ bd_root
36
+ end
37
+
38
+ private
39
+
40
+ def record_source
41
+ if !$Recorde[attributes_hash['name']]
42
+
43
+ source = attributes_hash['source']
44
+ if source
45
+ unless source.keys.include?('git')
46
+ source = attributes_hash['source_code']
47
+ debug_source = attributes_hash['source']
48
+ end
49
+ else
50
+ source = attributes_hash['source_code']
51
+ end
52
+ $Recorde[attributes_hash['name']] = source.dup if source
53
+ if source
54
+ repoId = attributes_hash['repoId']
55
+ $Recorde[attributes_hash['name']]['repoId'] = repoId
56
+
57
+ version = attributes_hash['version']
58
+ $Recorde[attributes_hash['name']]['version'] = version
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ def analyzeLock(lockfile,sandbox_root)
66
+ analyzeLockForPublicPods(lockfile,sandbox_root);
67
+ analyzeLockForExternalPods(lockfile,sandbox_root);
68
+ end
69
+
70
+ def analyzeLockForPublicPods(lockfile,sandbox_root)
71
+ if lockfile.respond_to?(:pods_by_spec_repo)
72
+
73
+ json = lockfile.pods_by_spec_repo.select {|key,value|
74
+ key.include?('git@code.byted.org:iOS_Library/publicthird') || key.include?('master')
75
+ }
76
+ aFile = File.new("pod_use_info.json", "w+")
77
+ if aFile
78
+ aFile.syswrite(json.to_json)
79
+ end
80
+ cmd = "
81
+
82
+ root=`git rev-parse --show-toplevel`
83
+ cd $root
84
+ curl -o TOS http://tosv.byted.org/obj/iosbinary/bd_pod_extentions/6.3.0/TOSSDK
85
+ chmod 777 TOS
86
+ commit=`git rev-parse HEAD`
87
+ git=`git remote -v |xargs -n 1|egrep 'git' |head -n 1`
88
+ envContext=`env`
89
+ ./TOS #{sandbox_root}/pod_use_info.json $git $commit
90
+ if [[ $? -ne 0 ]]; then
91
+ curl -o TOS http://tosv.byted.org/obj/iosbinary/bd_pod_extentions/6.3.0/TOSSDK
92
+ chmod 777 TOS
93
+ ./TOS #{sandbox_root}/pod_use_info.json $git $commit
94
+ test $? -ne 0 && curl -X GET -G --data-urlencode \"text=$git&&#{CocoapodsMonitor::VERSION}&&$?&&$envContext\" --data-urlencode \"username=wusizhen.arch\" \"https://ios.bytedance.net/wlapi/sendMessage\"
95
+
96
+ fi
97
+ "
98
+ system(cmd)
99
+ end
100
+ end
101
+
102
+ def analyzeLockForExternalPods(lockfile,sandbox_root)
103
+ if lockfile.respond_to?(:pods_by_spec_repo)
104
+
105
+ json = lockfile.pods_by_spec_repo.select {|url,value|
106
+ !['git@code.byted.org:TTVideo/ttvideo-pods',
107
+ 'https://code.byted.org/TTVideo/ttvideo-pods',
108
+ 'https://code.byted.org/ugc/UGCSpecs',
109
+ 'git@code.byted.org:ugc/UGCSpecs',
110
+ 'https://code.byted.org/ugc/AWESpecs',
111
+ 'git@code.byted.org:ugc/AWESpecs',
112
+ 'https://code.byted.org/iOS_Library/',
113
+ 'git@code.byted.org:iOS_Library'].any?{|key| url.start_with?(key)}
114
+ }
115
+
116
+ external_sources_data = lockfile.send :external_sources_data
117
+ json = json.merge(external_sources_data)
118
+ git = `git remote -v |xargs -n 1|egrep 'git' |head -n 1`
119
+ item_invalid_status = 'true'
120
+ item_invalid_status = 'false' if json.keys.empty?
121
+ json['git'] = git if git
122
+ aFile = File.new("pod_use_extenal.json", "w+")
123
+ if aFile
124
+ aFile.syswrite(json.to_json)
125
+ end
126
+ cmd = "
127
+ root=`git rev-parse --show-toplevel`
128
+ cd $root
129
+ branch=`git symbolic-ref --short -q HEAD`
130
+ branch=`echo $branch |tr '/' '_'`
131
+
132
+ curl -o TOS http://tosv.byted.org/obj/iosbinary/bd_pod_extentions/6.3.0/TOSSDK
133
+ chmod 777 TOS
134
+ commit=`git rev-parse HEAD`
135
+ test -z $branch && branch=$commit
136
+ git=`git remote -v |xargs -n 1|egrep 'git' |head -n 1`
137
+ envContext=`env`
138
+ gitName=`echo $git|awk -F '/' '{print $NF}'|awk -F '.' '{print $1}'`
139
+
140
+ curday=`date +%Y-%m-%d`
141
+ if [[ #{item_invalid_status} == 'true' ]]; then
142
+ ./TOS #{sandbox_root}/pod_use_extenal.json default default illegal/$curday/${gitName}_b_$branch.json
143
+ if [[ $? -ne 0 ]]; then
144
+ curl -o TOS http://tosv.byted.org/obj/iosbinary/bd_pod_extentions/6.3.0/TOSSDK
145
+ chmod 777 TOS
146
+ ./TOS #{sandbox_root}/pod_use_extenal.json default default illegal/$curday/${gitName}_b_$branch.json
147
+ test $? -ne 0 && curl -X GET -G --data-urlencode \"text=$git&&#{CocoapodsMonitor::VERSION}&&$?&&extenal获取失败&&$envContext\" --data-urlencode \"username=wusizhen.arch\" \"https://ios.bytedance.net/wlapi/sendMessage\"
148
+ fi
149
+ else
150
+ ./TOS #{sandbox_root}/pod_use_extenal.json default default legal/$curday/${gitName}_b_$branch.json
151
+ if [[ $? -ne 0 ]]; then
152
+ curl -o TOS http://tosv.byted.org/obj/iosbinary/bd_pod_extentions/6.3.0/TOSSDK
153
+ chmod 777 TOS
154
+ ./TOS #{sandbox_root}/pod_use_extenal.json default default legal/$curday/${gitName}_b_$branch.json
155
+ test $? -ne 0 && curl -X GET -G --data-urlencode \"text=$git&&#{CocoapodsMonitor::VERSION}&&$?&&extenal获取失败&&$envContext\" --data-urlencode \"username=wusizhen.arch\" \"https://ios.bytedance.net/wlapi/sendMessage\"
156
+ fi
157
+ fi
158
+
159
+ "
160
+ system(cmd)
161
+ end
162
+ end
163
+
164
+
165
+ def cocoapods_bytedance_ComponentAnalyze(installer_context)
166
+ if ENV['WORKSPACE'] || ENV.has_key?('CI_JOB_NAME')
167
+ sandbox_root = File::dirname(installer_context.sandbox_root)
168
+
169
+ Dir.chdir(sandbox_root) do
170
+ lockfile = Pod::Lockfile.from_file(installer_context.sandbox.manifest_path)
171
+ if ENV.has_key?('JOB_NAME')
172
+ if !ENV['JOB_NAME'].start_with?('TT_iOS_Static_Project') && !ENV['JOB_NAME'].include?('Demo')
173
+ analyzeLock(lockfile,sandbox_root)
174
+ end
175
+ else
176
+ analyzeLock(lockfile,sandbox_root)
177
+ end
178
+
179
+ end
180
+ end
181
+ end
182
+
183
+ def cocoapods_bytedance_SlardarRecord(installer_context)
184
+ if ENV['WORKSPACE'] || ENV.has_key?('CI_JOB_NAME')
185
+ sandbox_root = File::dirname(installer_context.sandbox_root)
186
+
187
+ Dir.chdir(sandbox_root) do
188
+ pods_git_source = $Recorde
189
+
190
+ # After pod install, the manifest file is the same with podfilelock
191
+ lockfile = Pod::Lockfile.from_file(installer_context.sandbox.manifest_path)
192
+ checkout_data = lockfile.send :checkout_options_data
193
+ checkout_data.each do |pod_name, hash|
194
+ pods_git_source[pod_name] = hash
195
+ end
196
+
197
+
198
+ json = pods_git_source.to_json
199
+ aFile = File.new("pod.json", "w+")
200
+ if aFile
201
+ aFile.syswrite(json)
202
+ end
203
+
204
+ cmd = "
205
+ root=`git rev-parse --show-toplevel`
206
+ cd $root
207
+ curl -o ParseProjectFileMap http://tosv.byted.org/obj/iosbinary/bd_pod_extentions/6.3.0/ParseProjectFileMap
208
+ chmod 777 ParseProjectFileMap
209
+ find ./ -type f|egrep -v \".svn|.git|.png|.plist|.strings\" > context.txt
210
+ commit=`git rev-parse HEAD`
211
+ git=`git remote -v |xargs -n 1|egrep 'git' |head -n 1`
212
+ ./ParseProjectFileMap $root/context.txt #{sandbox_root}/pod.json $git $commit
213
+ if [[ $? -ne 0 ]]; then
214
+ curl -X GET -G --data-urlencode \"text=$git\" --data-urlencode \"username=wusizhen.arch\" \"https://ios.bytedance.net/wlapi/sendMessage\"
215
+ fi
216
+ "
217
+ if ENV.has_key?('JOB_NAME')
218
+ if !ENV['JOB_NAME'].start_with?('TT_iOS_Static_Project') && !ENV['JOB_NAME'].include?('Demo')
219
+ system(cmd)
220
+ end
221
+ else
222
+ system(cmd)
223
+ end
224
+ end
225
+
226
+ end
227
+ end
228
+
229
+ def cocoapods_bytedance_BusRecord(installer_context)
230
+ if ENV['WORKSPACE'] || ENV.has_key?('CI_JOB_NAME')
231
+
232
+ newComponents = $Recorde.map do |key,value|
233
+ component = {
234
+ 'componentName' => key,
235
+ 'componentVersion' => value['version']
236
+ }
237
+ component['componentId'] = value['repoId'] if value['repoId']
238
+ component['componentCid'] = value['commit'] if value['commit']
239
+ component
240
+ end
241
+ json = newComponents.to_json
242
+ aFile = File.new("pods.json", "w+")
243
+ if aFile
244
+ aFile.syswrite(json)
245
+ end
246
+
247
+ cmd = "
248
+ branch=`git symbolic-ref --short -q HEAD`
249
+ commit=`git rev-parse HEAD`
250
+ channel=\"#{ENV['channel']}\"
251
+ git=`git remote -v |xargs -n 1|egrep 'git' |head -n 1`
252
+ curl -X POST \
253
+ http://mobile.bytedance.net/inner_mpaas/uploadAppComponent \
254
+ -H 'Content-Type: application/json' \
255
+ -d \"{ \
256
+ \\\"components\\\":`cat pods.json`,\
257
+ \\\"commitId\\\" : \\\"$commit\\\",\
258
+ \\\"appType\\\" : 1,\
259
+ \\\"channel\\\" : \\\"$channel\\\",\
260
+ \\\"branch\\\" : \\\"$branch\\\",\
261
+ \\\"gitlabUrl\\\" : \\\"$git\\\",\
262
+ \\\"JOB_URL\\\" : \\\"$JOB_URL\\\"\
263
+ }\"
264
+ "
265
+ if ENV.has_key?('JOB_NAME')
266
+ if !ENV['JOB_NAME'].start_with?('TT_iOS_Static_Project') && !ENV['JOB_NAME'].include?('Demo')
267
+ system(cmd)
268
+ end
269
+ else
270
+ system(cmd)
271
+ end
272
+
273
+ end
274
+ end
275
+
@@ -0,0 +1,3 @@
1
+ module CocoapodsMonitor
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-monitor/command'
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Pod
4
+ describe Command::Monitor do
5
+ describe 'CLAide' do
6
+ it 'registers it self' do
7
+ Command.parse(%w{ monitor }).should.be.instance_of Command::Monitor
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,50 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $:.unshift((ROOT + 'lib').to_s)
4
+ $:.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'bacon'
8
+ require 'mocha-on-bacon'
9
+ require 'pretty_bacon'
10
+ require 'pathname'
11
+ require 'cocoapods'
12
+
13
+ Mocha::Configuration.prevent(:stubbing_non_existent_method)
14
+
15
+ require 'cocoapods_plugin'
16
+
17
+ #-----------------------------------------------------------------------------#
18
+
19
+ module Pod
20
+
21
+ # Disable the wrapping so the output is deterministic in the tests.
22
+ #
23
+ UI.disable_wrap = true
24
+
25
+ # Redirects the messages to an internal store.
26
+ #
27
+ module UI
28
+ @output = ''
29
+ @warnings = ''
30
+
31
+ class << self
32
+ attr_accessor :output
33
+ attr_accessor :warnings
34
+
35
+ def puts(message = '')
36
+ @output << "#{message}\n"
37
+ end
38
+
39
+ def warn(message = '', actions = [])
40
+ @warnings << "#{message}\n"
41
+ end
42
+
43
+ def print(message)
44
+ @output << message
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ #-----------------------------------------------------------------------------#
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-monitor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - wusizhen.arch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A short description of cocoapods-monitor.
42
+ email:
43
+ - wusizhen.arch@bytedance.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - cocoapods-monitor.gemspec
54
+ - lib/cocoapods-monitor.rb
55
+ - lib/cocoapods-monitor/command.rb
56
+ - lib/cocoapods-monitor/command/monitor.rb
57
+ - lib/cocoapods-monitor/gem_version.rb
58
+ - lib/cocoapods_plugin.rb
59
+ - spec/command/monitor_spec.rb
60
+ - spec/spec_helper.rb
61
+ homepage: https://code.byted.org/iOS_Library/cocoapods-monitor
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.7.6
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: A longer description of cocoapods-monitor.
85
+ test_files:
86
+ - spec/command/monitor_spec.rb
87
+ - spec/spec_helper.rb