lib/core/plugin/project.rb in nucleon-0.2.1 vs lib/core/plugin/project.rb in nucleon-0.2.2

- old
+ new

@@ -43,11 +43,13 @@ # Project plugin interface def normalize(reload) super - set_directory(Util::Disk.filename(get(:directory, Dir.pwd))) + directory = Util::Disk.filename(get(:directory, Dir.pwd)) + + set_directory(directory) register set_url(get(:url)) if get(:url, false) myself.plugin_name = path if ! plugin_name || plugin_name.to_sym == plugin_provider @@ -68,10 +70,14 @@ pull if get(:pull, false) unless reload @cache = Util::Cache.new(directory, Nucleon.sha1(plugin_name), '.project_cache') init_cache + + unless self.class.load_provider(directory) + self.class.store_provider(directory, plugin_provider) + end end end #--- @@ -175,11 +181,11 @@ end #--- def set_url(url) - if url && url = extension_set(:set_url, url.strip) + if url && url = extension_set(:set_url, url.strip) logger.info("Setting project #{name} url to #{url}") set(:url, url) set_remote(:origin, url) end @@ -324,11 +330,11 @@ #----------------------------------------------------------------------------- # Project operations def init_cache - # Override in providers if needed + ignore(self.class.state_file) end protected :init_cache #--- @@ -804,15 +810,16 @@ #--- def push(remote = :edit, options = {}) config = Config.ensure(options).import({ :remote => remote }) + no_pull = config.delete(:no_pull, false) success = false push_project = lambda do |push_remote| logger.info("Pushing to #{push_remote} from #{directory}") - success = yield(config, push_remote) if block_given? && pull(push_remote, config) + success = yield(config, push_remote) if block_given? && ( no_pull || pull(push_remote, config) ) end if can_persist? localize do if extension_check(:push, { :directory => directory, :config => config }) @@ -868,12 +875,51 @@ else logger.warn("Project #{name} does not meet the criteria for persistence and can not push to remotes") end success end - + #----------------------------------------------------------------------------- + # State configurations + + def self.state_file + '.corl' + end + + #--- + + @@project_data = {} + + def self.store_provider(directory, provider) + if File.directory?(directory) + @@project_data[directory] = { + :provider => provider + } + json_data = Util::Data.to_json(@@project_data[directory], true) + Util::Disk.write(File.join(directory, state_file), json_data) + end + end + + #--- + + def self.clear_provider(directory) + @@project_data.delete(directory) + end + + #--- + + def self.load_provider(directory, override = nil) + @@project_data[directory] = {} unless @@project_data.has_key?(directory) + + if override.nil? && @@project_data[directory].empty? + json_data = Util::Disk.read(File.join(directory, state_file)) + @@project_data[directory] = hash(Util::Data.parse_json(json_data)) if json_data + end + override.nil? ? symbol_map(@@project_data[directory])[:provider] : override + end + + #----------------------------------------------------------------------------- # Utilities def self.build_info(namespace, plugin_type, data) data = data.split(/\s*,\s*/) if data.is_a?(String) super(namespace, plugin_type, data) @@ -891,12 +937,13 @@ options = data end if options.has_key?(:url) if matches = translate_reference(options[:url]) - options[:provider] = matches[:provider] - options[:url] = matches[:url] - options[:revision] = matches[:revision] unless options.has_key?(:revision) + options[:provider] = matches[:provider] + options[:reference] = matches[:reference] + options[:url] = matches[:url] + options[:revision] = matches[:revision] unless options.has_key?(:revision) logger.debug("Translating project options: #{options.inspect}") end end options