├── .idea ├── .name ├── scopes │ └── scope_settings.xml ├── encodings.xml ├── vcs.xml ├── modules.xml ├── .rakeTasks ├── misc.xml └── cocoapods-multithread-installpod.iml ├── Rakefile ├── lib ├── cocoapods_plugin.rb ├── cocoapods-multithread-installpod │ └── version.rb └── cocoapods-multithread-installpod.rb ├── Gemfile ├── .gitignore ├── README.md ├── LICENSE.txt └── cocoapods-multithread-installpod.gemspec /.idea/.name: -------------------------------------------------------------------------------- 1 | cocoapods-multithread-installpod -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | -------------------------------------------------------------------------------- /lib/cocoapods_plugin.rb: -------------------------------------------------------------------------------- 1 | require 'cocoapods-multithread-installpod.rb' 2 | -------------------------------------------------------------------------------- /lib/cocoapods-multithread-installpod/version.rb: -------------------------------------------------------------------------------- 1 | module CocoapodsMultithreadInstallpod 2 | VERSION = "0.0.8" 3 | end 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in cocoapods-multithread-installpod.gemspec 4 | gemspec 5 | gem 'cocoapods', '1.0.0' -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | test/tmp 16 | test/version_tmp 17 | tmp 18 | *.bundle 19 | *.so 20 | *.o 21 | *.a 22 | mkmf.log 23 | .idea 24 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/.rakeTasks: -------------------------------------------------------------------------------- 1 | 2 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cocoapods::Multithread::Installpod 2 | 3 | TODO: Write a gem description 4 | 5 | ## Installation 6 | 7 | Add this line to your application's Gemfile: 8 | 9 | gem 'cocoapods-multithread-installpod' 10 | 11 | And then execute: 12 | 13 | $ bundle 14 | 15 | Or install it yourself as: 16 | 17 | $ gem install cocoapods-multithread-installpod 18 | 19 | ## Usage 20 | 21 | TODO: Write usage instructions here 22 | 23 | ## Contributing 24 | 25 | 1. Fork it ( https://github.com/[my-github-username]/cocoapods-multithread-installpod/fork ) 26 | 2. Create your feature branch (`git checkout -b my-new-feature`) 27 | 3. Commit your changes (`git commit -am 'Add some feature'`) 28 | 4. Push to the branch (`git push origin my-new-feature`) 29 | 5. Create a new Pull Request 30 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 晨燕 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. 23 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /cocoapods-multithread-installpod.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'cocoapods-multithread-installpod/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "cocoapods-multithread-installpod" 8 | spec.version = CocoapodsMultithreadInstallpod::VERSION 9 | spec.authors = ["晨燕"] 10 | spec.email = ["chenyan.mnn@taobao.com"] 11 | spec.summary = "将cocoapods installer过程中download_dependencies改为多线程,提高效率" 12 | spec.description = "将cocoapods installer过程中download_dependencies改为20个线程并发,提高pod update的效率" 13 | spec.homepage = "https://github.com/mahaiyannn/cocoapods-multithread-installpod" 14 | spec.license = "MIT" 15 | spec.files = Dir["lib/**/*.rb"]+Dir["cocoapods-multithread-installpod.gemspec"] 16 | 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.6" 22 | spec.add_development_dependency "rake" 23 | spec.add_development_dependency "cocoapods" 24 | 25 | end 26 | -------------------------------------------------------------------------------- /.idea/cocoapods-multithread-installpod.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 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 | -------------------------------------------------------------------------------- /lib/cocoapods-multithread-installpod.rb: -------------------------------------------------------------------------------- 1 | require "cocoapods-multithread-installpod/version" 2 | require 'thread' 3 | 4 | if Pod::VERSION>='0.39.0' 5 | module Pod 6 | class Installer 7 | def install_pod_sources 8 | @installed_specs = [] 9 | pods_to_install = sandbox_state.added | sandbox_state.changed 10 | title_options = { :verbose_prefix => '-> '.green } 11 | 12 | work_q = Queue.new 13 | root_specs.sort_by(&:name).each{|spec| work_q.push spec } 14 | workers = (0...20).map do 15 | Thread.new do 16 | begin 17 | while spec = work_q.pop(true) 18 | if pods_to_install.include?(spec.name) 19 | if sandbox_state.changed.include?(spec.name) && sandbox.manifest 20 | previous = sandbox.manifest.version(spec.name) 21 | title = "Installing #{spec.name} #{spec.version} (was #{previous})" 22 | else 23 | title = "Installing #{spec}" 24 | end 25 | UI.titled_section(title.green, title_options) do 26 | install_source_of_pod(spec.name) 27 | #UI.titled_section("Installed #{spec}", title_options) 28 | end 29 | else 30 | UI.titled_section("Using #{spec}", title_options) do 31 | create_pod_installer(spec.name) 32 | #UI.titled_section("Installed #{spec}", title_options) 33 | end 34 | end 35 | end 36 | rescue ThreadError 37 | end 38 | end 39 | end 40 | UI.titled_section("Installing... Please Wait...", title_options) 41 | workers.map(&:join) 42 | end 43 | end 44 | 45 | 46 | module Downloader 47 | # The class responsible for managing Pod downloads, transparently caching 48 | # them in a cache directory. 49 | # 50 | class Cache 51 | @@mutex=Mutex.new 52 | def ensure_matching_version 53 | @@mutex.lock 54 | version_file = root + 'VERSION' 55 | version = version_file.read.strip if version_file.file? 56 | 57 | root.rmtree if version != Pod::VERSION && root.exist? 58 | root.mkpath 59 | version_file.open('w') { |f| f << Pod::VERSION } 60 | @@mutex.unlock 61 | end 62 | end 63 | end 64 | end 65 | 66 | elsif Pod::VERSION=='0.35.0' 67 | module Pod 68 | class Installer 69 | def install_pod_sources 70 | @installed_specs = [] 71 | pods_to_install = sandbox_state.added | sandbox_state.changed 72 | title_options = { :verbose_prefix => '-> '.green } 73 | sorted_root_specs = root_specs.sort_by(&:name) 74 | threads=[] 75 | max_thread_count = 20.0 76 | per_thead_task_count =(sorted_root_specs.count/max_thread_count).ceil 77 | i = 0 78 | while i < max_thread_count 79 | sub_sorted_root_specs = sorted_root_specs[i*per_thead_task_count, per_thead_task_count] 80 | if sub_sorted_root_specs != nil 81 | threads << Thread.new(sub_sorted_root_specs) do |specs| 82 | specs.each do |spec| 83 | if pods_to_install.include?(spec.name) 84 | if sandbox_state.changed.include?(spec.name) && sandbox.manifest 85 | previous = sandbox.manifest.version(spec.name) 86 | title = "Installing #{spec.name} #{spec.version} (was #{previous})" 87 | else 88 | title = "Installing #{spec}" 89 | end 90 | UI.titled_section(title.green, title_options) do 91 | install_source_of_pod(spec.name) 92 | end 93 | else 94 | UI.titled_section("Using #{spec}", title_options) 95 | end 96 | end 97 | end 98 | end 99 | i+=1 100 | end 101 | threads.each{|t| t.join} 102 | end 103 | end 104 | 105 | module UserInterface 106 | class << self 107 | def wrap_string(string, indent = 0) 108 | if disable_wrap 109 | string 110 | else 111 | first_space = ' ' * indent 112 | # indented = CLAide::Helper.wrap_with_indent(string, indent, 9999) 113 | # first_space + indented 114 | end 115 | end 116 | end 117 | end 118 | end 119 | end 120 | 121 | 122 | --------------------------------------------------------------------------------