class PodsOrz::PodsSort

Public Instance Methods

recursive_puts(key,array,pathArray) click to toggle source
# File lib/podsorz/core/PodsOrz/pods_sort.rb, line 64
def recursive_puts(key,array,pathArray)
    # pathArray << key
    totalArray = []
    if array.empty?
        # puts ("kong - #{key}")
        
    else
        array.each {|line|
            pathArray << line
            priority = @@fileHash[line] + 1
            @@fileHash[line] = priority
            tempArray = @@filterHash[line]
            if tempArray.empty?
                pathArray.pop
            else
                
                cycle = false
                tempArray.each {|podsName|
                    if pathArray.include?(podsName)
                       cycle = true 
                       Logger.error("path:#{pathArray} pod:#{podsName} has dependence cycle, please fix cycle")
                       exit()
                    end
                    # priorityN = @@fileHash[podsName] + 1
                    # puts("次数 podsName #{podsName} #{priorityN}")
                    # @@fileHash[podsName] = priorityN
                }

                if cycle
                   #包含
                    # puts pathArray
                    
                else
                    # puts ("#{key} #{line} #{pathArray}")
                    recursive_puts(line,tempArray,pathArray)
                    pathArray.pop
                end
                
            end

        }
        
    end

    
end
sort(pods_list,kx_pods_subPath) click to toggle source
# File lib/podsorz/core/PodsOrz/pods_sort.rb, line 8
def sort(pods_list,kx_pods_subPath)
    # file priority 1 hash
    @@fileHash = {}
    # podspec hash
    @@podspecHash = {}

    @@filterHash = {}
    pods_list.each { |fileName|
        @@fileHash[fileName] = 1
    }

    pods_list.each { |fileName|
    filePath = "#{kx_pods_subPath}/#{fileName}"
    is_directory = File.directory?(filePath)
    if is_directory
        spec_with_path("#{filePath}/#{fileName}.podspec",fileName)
    else
        Logger.warning("#{filePath} is an empty file")
    end
    }
    sort_with_hash()
    @resultHash = {}

    @@filterHash.each { |fileName,array| 
        # puts ("#{fileName},#{array}")
        recursive_puts(fileName,array,[fileName])
        
    }

    @@fileHash.each {|file,priority|
        # puts ("#{file} #{priority}")
        if  @resultHash.key?(priority)
            array = @resultHash[priority]
            array << file
            @resultHash[priority] = array
        else
            @resultHash[priority] = [file]
        end
    }
    sortList = []
    checkHash = {}
    # puts @resultHash
    @resultHash.sort.sort!.each { |priority,array| 
        # puts ("#{priority},#{array}")
        array.each { |line| 
           puts ("#{priority} -- #{line}") 
           checkHash[line] = priority
           sortList << line
        }
    }

    sortList.reverse!

end
sort_with_hash() click to toggle source
# File lib/podsorz/core/PodsOrz/pods_sort.rb, line 111
def sort_with_hash()

    @@podspecHash.each { |fileName,specArray| 
        # puts "#{fileName} #{specArray}"
        tempArray = []
        @@fileHash.each {|file,priority|
            
            specArray.each { |line| 
                if line.include? "dependency"
                    
                    if line.include? file and file != fileName

                        priority += 1

                        # @@fileHash[file] = priority
                        tempArray << file
                        # puts "#{fileName},#{file},#{line}"
                        
                    end
                end 
            }

        }
        @@filterHash[fileName] = tempArray

    }
    
end
spec_with_path(path,fileName) click to toggle source
# File lib/podsorz/core/PodsOrz/pods_sort.rb, line 140
def spec_with_path(path,fileName)
    return if path.nil?
    path = Pathname.new(path)
    path = Pathname.new(Dir.pwd).join(path) unless path.absolute?
    return unless path.exist?

    @path = path.expand_path

    arr = IO.readlines("#{@path}")
    @@podspecHash[fileName] = arr

end