require 'cocoapods' require_relative 'utils.rb' require_relative 'config.rb' require 'pathname' require 'parseconfig' require_relative 'pod_helper.rb' require "git" module QCloudHive HIVE_MODULES_FILE_NAME = ".hivemodules" class << self @@xcodeprojectvar = nil end class XCodeProject attr_accessor :path attr_reader :hiveSpecModules def podfile if @podfile.nil? @podfile = Pod::Podfile.from_file(Pathname(@path).join("Podfile").to_path) end @podfile end def hiveSpecModules if @hiveSpecModules.nil? hivemodules = Pathname.new(@path).join(QCloudHive::HIVE_MODULES_FILE_NAME) configedModules = [] if hivemodules.exist? parseConfig = ParseConfig.new(hivemodules.to_path) configedModules += parseConfig.groups.map { |e| spec = HiveSpec.new(e, nil) spec.commit = parseConfig[e]["commit"] spec.branch= parseConfig[e]["branch"] spec.sourceURL = Config.manifest.sourceURLByModuleName(e) localSpec = QCloudHive::HivePod.podspecs.select{|s| s.name == e}.first if not localSpec.nil? spec.path = localSpec.path end if (not spec.path.nil?) && Pathname.new(spec.path).exist? begin git = Git.open(Pathname.new(spec.path).parent.to_s) if not git.nil? spec.branch = git.current_branch if not git.branches[git.current_branch].nil? spec.commit = git.branches[git.current_branch].gcommit.sha end end rescue => err puts "读取git工程失败 #{path} #{err}" end end spec } end configedModules += QCloudHive::HivePod.podspecs.map { |s| spec = nil if configedModules.select { |e| e.name == s.name }.count == 0 spec = HiveSpec.new(s.name, nil) spec.sourceURL = Config.manifest.sourceURLByModuleName(s.name) spec.path = s.path if (not spec.path.nil?) && Pathname.new(spec.path).exist? begin git = Git.open(Pathname.new(spec.path).parent.to_path) L.debug "Create git #{git}" rescue => err puts "读取git工程失败 #{path} #{err}" end if not git.nil? spec.branch = git.current_branch if not git.branches[git.current_branch].nil? spec.commit = git.branches[git.current_branch].gcommit.sha end end end else # exist spec = nil end spec } configedModules = configedModules.compact @hiveSpecModules = configedModules end return @hiveSpecModules end def initialize(path) @path = path @podfile = nil @hiveSpecModules = nil end def saveHiveModulesConfig config = "" hiveSpecModules.each { |e| config += "\n#{e.toConfig}" } File.open(Pathname.new(@path).join(QCloudHive::HIVE_MODULES_FILE_NAME).to_s, "w") { |f| f.write config } end end def QCloudHive.findXcodeProject(path) dirPath = Pathname.new(path) if not dirPath.directory? return [] end projects = dirPath.each_child.select{|f| f.extname == ".xcodeproj" } if projects.count != 0 return [dirPath.to_path] else subProjects = [] dirPath.each_child { |file| if file.basename.to_path == ".git" next end if file.basename.to_path == ".repo" next end subDir = dirPath.join(file) if subDir.directory? subProjects+=findXcodeProject(subDir) end } return subProjects end end def QCloudHive.xcodeprojects if @@xcodeprojectvar.nil? root = Config.projectRootDirectory L.info("find xcode projects") projects = findXcodeProject(root) xcodePojects = [] projects.each { |xcp| xcodePojects << XCodeProject.new(xcp) } @@xcodeprojectvar = xcodePojects end return @@xcodeprojectvar end def QCloudHive.xcodeprojectByPath(path) QCloudHive.xcodeprojects.select{|p| p.path == path}.first end def QCloudHive.UpdateProducts(cmd, opts) name = opts[:i_name] Config.dumpShareConfig if name.nil? updateAllProducts end end def QCloudHive.updateAllProducts QCloudHive.xcodeprojects.each { |hive| L.debug "codeproject #{hive.path}" Rake::sh "cd #{Pathname(hive.path).to_path};pod update" } end end