cocoapods-dependency-graph 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f7e970165190f39fda0730defde8735b2adfb0ba85cc6a35add519dc0f3e55b6
4
+ data.tar.gz: b4d5435fb27e0eab9b8fc747926aa5080f59c6f13a8f3bac857e01d92f739c82
5
+ SHA512:
6
+ metadata.gz: 0ead64f867b33a4bfa127574ee90672461b9c2e6ff6c1259a705168bd5e0c13b8790c18016b9200be7a6acb265b569c0be7512d626ba1b9569b84a4f95d1ea9f
7
+ data.tar.gz: 9ae60778070e00ebb18f47b2ba87bec61881d899a8552b4000dae0304058e27d2b7513c68f9f85fa7cdeae28802d270fd71939c76c12de9eb701df5d060650e1
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cocoapods-dependency-graph.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
+ gem 'fast_excel'
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 RY Zheng
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # cocoapods-dependency-graph
2
+
3
+ A Cocoapods plugin to create the dependency graph and help you manage dependencies in your project.
4
+
5
+
6
+ ## Installation
7
+ ### Install Dependency
8
+ $ gem install rgl
9
+
10
+ ### Install
11
+
12
+ ```
13
+ $ gem install cocoapods-dependency-graph
14
+ ```
15
+
16
+ ### Build and Install Plugin
17
+
18
+ $ git clone git@github.com:sueLan/cocoapods-dependency-graph.git
19
+ $ cd cocoapods-dependency-graph
20
+ $ gem build cocoapods-dependency-graph.gemspec && gem install cocoapods-dependency-graph --user-install
21
+
22
+ ## Usage
23
+
24
+ 1. add `plugin` in the `Podfile`
25
+
26
+ ```
27
+ plugin 'cocoapods-dependency-graph'
28
+ ```
29
+
30
+ 2. run `pod install`
31
+ 3. output files in the project folder
32
+
33
+ In the `Podfile`, you can define `dependency_output` to decide which kind of output file this plugin generates.
34
+
35
+ ```
36
+ dependency_output :json
37
+ dependency_output :excel
38
+ dependency_output :graph
39
+ ```
40
+ There are 3 symbols to control the output format. You can choose one of them. If you don't define `dependency_output`, by default, this plugin generates `graph.jpg` and `graph.dot`.
41
+
42
+ The following are output files you can generate:
43
+
44
+ - `dependency_json.json`: JSON file for dependencies. You can view the json in any JSON becauty tool you like.
45
+
46
+ <img src="README.assets/image-20201007205410006.png" alt="image-20201007205410006" style="zoom:50%;" />
47
+
48
+ - `graph.jpg`: A png picture shows the dependency graph
49
+
50
+ ![image-20201007213841235](README.assets/image-20201007213841235.png)
51
+
52
+ - `graph.dot`: A dot file which represents the dependency graph. [A site](https://dreampuf.github.io/GraphvizOnline/) that can process the dot language. Or you can use [Graphviz](https://www.graphviz.org/theory/)
53
+
54
+ - `cocoapods-dependency-list.xlsx`: xlsx file for dependency list.
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-dependency-graph/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cocoapods-dependency-graph'
8
+ spec.version = CocoapodsDependencyGraph::VERSION
9
+ spec.authors = ['Rongyan Zheng']
10
+ spec.email = ['scutryzheng@gmail.com']
11
+ spec.description = %q{A short description of cocoapods-dependency-graph.}
12
+ spec.summary = %q{A longer description of cocoapods-dependency-graph.}
13
+ spec.homepage = 'https://github.com/EXAMPLE/cocoapods-dependency-graph'
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-dependency-graph/command/graph'
@@ -0,0 +1,44 @@
1
+ module Pod
2
+ class Command
3
+ # This is an example of a cocoapods plugin adding a top-level subcommand
4
+ # to the 'pod' command.
5
+ #
6
+ # You can also create subcommands of existing or new commands. Say you
7
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
8
+ # (e.g. `pod list deprecated`), there are a few things that would need
9
+ # to change.
10
+ #
11
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
12
+ # the class to exist in the the Pod::Command::List namespace
13
+ # - change this class to extend from `List` instead of `Command`. This
14
+ # tells the plugin system that it is a subcommand of `list`.
15
+ # - edit `lib/cocoapods_plugins.rb` to require this file
16
+ #
17
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
18
+ # in the `plugins.json` file, once your plugin is released.
19
+ #
20
+ class Dependency < Command
21
+ self.summary = 'Short description of cocoapods-dependency-graph.'
22
+
23
+ self.description = <<-DESC
24
+ Longer description of cocoapods-dependency-graph.
25
+ DESC
26
+
27
+ self.arguments = 'NAME'
28
+
29
+ def initialize(argv)
30
+ @name = argv.shift_argument
31
+ super
32
+ end
33
+
34
+ def validate!
35
+ super
36
+ help! 'A Pod name is required.' unless @name
37
+ end
38
+
39
+ def run
40
+ UI.puts "Add your implementation for the cocoapods-dependency-graph plugin in #{__FILE__}"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module CocoapodsDependencyGraph
2
+ VERSION = "1.0.2"
3
+ end
@@ -0,0 +1,49 @@
1
+ require 'fast_excel'
2
+
3
+ module Dependency
4
+ class ExcelGenerator
5
+ attr_accessor :workbook
6
+ attr_accessor :worksheet
7
+
8
+ def create_excel
9
+ filename = 'cocoapods_dependency_list.xlsx'
10
+ File.delete(filename) if File.file?(filename)
11
+
12
+ @workbook = FastExcel.open(filename, constant_memory: true)
13
+ @worksheet = workbook.add_worksheet("cocoapods-dependency-list")
14
+ @worksheet.auto_width = true
15
+ end
16
+
17
+ def create_title()
18
+ @worksheet.append_row(["module name", "local", "source", "version", "homepage", "summary"], @workbook.bold_format)
19
+ end
20
+
21
+ def create_row(spec)
22
+ return unless spec.source
23
+ local = spec.local? if spec.source
24
+ summary = spec.root.attributes_hash['summary']
25
+ worksheet << [spec.module_name, local, spec.source, spec.version, spec.homepage, summary]
26
+ end
27
+
28
+ # @param [Array<Specification>] specs a list specification
29
+ def create_content(specs)
30
+ specs.each { | spec |
31
+ create_row(spec)
32
+ }
33
+ end
34
+
35
+ def close_excel
36
+ @workbook.close
37
+ end
38
+
39
+ # @param [UmbrellaTargetDescription] umbrella_target the CocoaPods umbrella targets generated by the installer.
40
+ # @param [Hash{<String, Specification>}] module_spec_hash
41
+ #
42
+ def generate(umbrella_target, module_spec_hash)
43
+ create_excel
44
+ create_title
45
+ create_content(umbrella_target.specs)
46
+ close_excel
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,39 @@
1
+ require 'rgl/adjacency'
2
+ require 'rgl/dot'
3
+
4
+ module Dependency
5
+ class GraphGenerator
6
+ def dependency_spces(spec)
7
+ dependencies = []
8
+ spec.dependencies.each { | dependency |
9
+ d_spec = @module_spec_hash[dependency.name]
10
+ next unless d_spec.source
11
+ dependencies << d_spec
12
+ }
13
+ dependencies
14
+ end
15
+
16
+ def dfs_graph(parent, specs)
17
+ specs.each { | spec |
18
+ next unless spec.source
19
+ @graph.add_edge(parent, spec)
20
+ dfs_graph(spec, dependency_spces(spec))
21
+ }
22
+ end
23
+
24
+ # @param [UmbrellaTargetDescription] umbrella_target the CocoaPods umbrella targets generated by the installer.
25
+ # @param [Hash{<String, Specification>}] module_spec_hash
26
+ #
27
+ def generate(umbrella_target, module_spec_hash)
28
+ @graph = RGL::DirectedAdjacencyGraph.new
29
+ @module_spec_hash = module_spec_hash
30
+
31
+ target_name = umbrella_target.cocoapods_target_label
32
+ root_node = {:target => target_name}
33
+ dfs_graph(root_node, umbrella_target.specs)
34
+
35
+ @graph.print_dotted_on
36
+ @graph.write_to_graphic_file('jpg')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,66 @@
1
+ require 'json'
2
+
3
+ module Dependency
4
+ class JsonGenerator
5
+ # @param [Array<Specification>] specs a list specification
6
+ def create_hash(target_name, specs)
7
+ dependencies = Array.new
8
+ specs.each { | spec |
9
+ next unless spec.source
10
+ dependencies << SpecNode.new(spec).to_hash
11
+ }
12
+
13
+ {:target_name => dependencies}
14
+ end
15
+
16
+ def self.module_spec_hash
17
+ @@module_spec_hash
18
+ end
19
+
20
+ # @param [UmbrellaTargetDescription] umbrella_target the CocoaPods umbrella targets generated by the installer.
21
+ # @param [Hash{<String, Specification>}] module_spec_hash
22
+ #
23
+ def generate(umbrella_target, module_spec_hash)
24
+ @@module_spec_hash = module_spec_hash
25
+ target_name = umbrella_target.cocoapods_target_label
26
+ dependency_hash = create_hash(target_name, umbrella_target.specs)
27
+ # puts dependency_hash.to_json
28
+ File.open("cocoapods_dependency_json.json","w") do |f|
29
+ f.write(dependency_hash.to_json)
30
+ end
31
+ end
32
+
33
+ class SpecNode
34
+ def spec_brief_info(spec)
35
+ spec_brief = Hash.new
36
+ spec_brief[:name] = spec.name
37
+ spec_brief[:module_name] = spec.module_name
38
+ spec_brief[:source] = spec.source
39
+ spec_brief[:version] = spec.version
40
+ spec_brief[:homepage] = spec.homepage
41
+ spec_brief[:local] = spec.local? if spec.source
42
+ spec_brief[:summary] = spec.root.attributes_hash['summary']
43
+ spec_brief[:subspec] = spec.subspecs
44
+
45
+ spec_brief
46
+ end
47
+
48
+ def initialize(spec)
49
+ @name = spec_brief_info(spec)
50
+ @dependencies = []
51
+ spec.dependencies.each { | dependency |
52
+ d_spec = JsonGenerator.module_spec_hash[dependency.name]
53
+ next unless d_spec.source
54
+ @dependencies << SpecNode.new(d_spec).to_hash
55
+ }
56
+ end
57
+
58
+ def to_hash()
59
+ res = Hash.new
60
+ res[:name] = @name
61
+ res[:dependencies] = @dependencies
62
+ res
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,81 @@
1
+ require 'cocoapods-dependency-graph/gem_version'
2
+ require 'cocoapods'
3
+ require 'fileutils'
4
+ require_relative 'cocoapods-dependency-graph/generator/excel_generator'
5
+ require_relative 'cocoapods-dependency-graph/generator/json_generator'
6
+ require_relative 'cocoapods-dependency-graph/generator/graph_generator'
7
+
8
+ module Output
9
+ GRAPH = :graph
10
+ JSON = :json
11
+ EXCEL = :excel
12
+ end
13
+
14
+ # attr_accessor for class variable.
15
+ def class_attr_accessor(symbol)
16
+ self.class.send(:attr_accessor, symbol)
17
+ end
18
+
19
+ module Pod
20
+ class Podfile
21
+ module DSL
22
+ def dependency_output(output_symbol)
23
+ puts "read dependency_output #{output_symbol}"
24
+ DSL.dependency_output_format = output_symbol
25
+ end
26
+
27
+ private
28
+ class_attr_accessor :dependency_output_format
29
+ DSL.dependency_output_format = Output::GRAPH
30
+ end
31
+ end
32
+ end
33
+
34
+ module Dependency
35
+ class Graph
36
+ attr_accessor :output_class_hash
37
+
38
+ def init_output_hash
39
+ @output_class_hash = {
40
+ :graph => 'Dependency::GraphGenerator',
41
+ :json => 'Dependency::JsonGenerator',
42
+ :excel => 'Dependency::ExcelGenerator'
43
+ }
44
+ end
45
+
46
+ # @param [Array<UmbrellaTargetDescription>] The list of
47
+ # the CocoaPods umbrella targets generated by the installer.
48
+ #
49
+ def generate(umbrella_targets)
50
+ unless umbrella_targets.length() > 0
51
+ puts "No target detected"
52
+ end
53
+
54
+ umbrella_target = umbrella_targets[0]
55
+
56
+ module_spec_hash = {}
57
+ umbrella_target.specs.each { | spec |
58
+ module_spec_hash[spec.name] = spec
59
+ }
60
+
61
+ init_output_hash
62
+ output_key = Pod::Podfile::DSL.dependency_output_format
63
+ puts "#{output_key} key"
64
+ output_key = Output::GRAPH unless output_key
65
+
66
+ puts "output key #{output_key}, #{@output_class_hash}"
67
+ generator_string = @output_class_hash[output_key]
68
+
69
+ puts "gen #{generator_string}"
70
+ unless generator_string
71
+ puts "The dependency_output should be one of #{Output::GRAPH}, #{Output::JSON}, and #{Output::EXCEL}"
72
+ return
73
+ end
74
+
75
+ generator_class = Object.const_get(generator_string)
76
+ puts "gener class #{generator_class}"
77
+ generator_class.new.generate(umbrella_target,module_spec_hash)
78
+ end
79
+ end
80
+ end
81
+
@@ -0,0 +1,9 @@
1
+ require 'cocoapods-dependency-graph/command'
2
+ require_relative 'cocoapods_dependency_graph'
3
+
4
+ module Dependency
5
+ # Register the post_install hook. The context is passed when running block
6
+ Pod::HooksManager.register('cocoapods-dependency-graph', :post_install) do |installer_context|
7
+ Graph.new.generate(installer_context.umbrella_targets)
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Pod
4
+ describe Command::Graph do
5
+ describe 'CLAide' do
6
+ it 'registers it self' do
7
+ Command.parse(%w{ graph }).should.be.instance_of Command::Graph
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,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-dependency-graph
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Rongyan Zheng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-22 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-dependency-graph.
42
+ email:
43
+ - scutryzheng@gmail.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-dependency-graph.gemspec
54
+ - lib/cocoapods-dependency-graph/command.rb
55
+ - lib/cocoapods-dependency-graph/command/graph.rb
56
+ - lib/cocoapods-dependency-graph/gem_version.rb
57
+ - lib/cocoapods-dependency-graph/generator/excel_generator.rb
58
+ - lib/cocoapods-dependency-graph/generator/graph_generator.rb
59
+ - lib/cocoapods-dependency-graph/generator/json_generator.rb
60
+ - lib/cocoapods_dependency_graph.rb
61
+ - lib/cocoapods_plugin.rb
62
+ - spec/command/graph_spec.rb
63
+ - spec/spec_helper.rb
64
+ homepage: https://github.com/EXAMPLE/cocoapods-dependency-graph
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.0.3
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: A longer description of cocoapods-dependency-graph.
87
+ test_files:
88
+ - spec/command/graph_spec.rb
89
+ - spec/spec_helper.rb