class Nucleon::Plugin::Project

Public Class Methods

build_info(namespace, plugin_type, data) click to toggle source
Calls superclass method
    # File lib/core/plugin/project.rb
938 def self.build_info(namespace, plugin_type, data)
939   data = data.split(/\s*,\s*/) if data.is_a?(String)
940   super(namespace, plugin_type, data)
941 end
clear_project_info(directory) click to toggle source
    # File lib/core/plugin/project.rb
919 def self.clear_project_info(directory)
920   @@project_data.delete(directory)
921 end
collection() click to toggle source
   # File lib/core/plugin/project.rb
10 def self.collection
11   @@projects
12 end
load_project_info(directory) click to toggle source
    # File lib/core/plugin/project.rb
925 def self.load_project_info(directory)
926   @@project_data[directory] = {} unless @@project_data.has_key?(directory)
927 
928   if @@project_data[directory].empty?
929     json_data                 = Util::Disk.read(File.join(directory, state_file))
930     @@project_data[directory] = hash(Util::Data.parse_json(json_data)) if json_data
931   end
932   symbol_map(@@project_data[directory])
933 end
open(directory, provider, options = {}) click to toggle source
   # File lib/core/plugin/project.rb
23 def self.open(directory, provider, options = {})
24   config    = Config.ensure(options)
25   directory = File.expand_path(Util::Disk.filename(directory))
26 
27   if ! @@projects.has_key?(directory) || config.get(:reset, false)
28     logger.info("Creating new project at #{directory} with #{provider}")
29 
30     return Nucleon.project(config.import({
31       :name          => directory,
32       :directory     => directory,
33       :nucleon_cache => config.get(:nucleon_cache, true),
34       :nucleon_file  => config.get(:nucleon_file, true)
35     }), provider)
36 
37   else
38     logger.info("Opening existing project at #{directory}")
39   end
40 
41   @@projects[directory]
42 end
register_ids() click to toggle source
   # File lib/core/plugin/project.rb
16 def self.register_ids
17   [ :name, :directory ]
18 end
state_file() click to toggle source
    # File lib/core/plugin/project.rb
899 def self.state_file
900   '.nucleon'
901 end
store_project_info(directory, provider, options) click to toggle source
    # File lib/core/plugin/project.rb
907 def self.store_project_info(directory, provider, options)
908   if File.directory?(directory)
909     @@project_data[directory] = Config.ensure(options).import({
910       :provider => provider
911     }).export
912     json_data = Util::Data.to_json(@@project_data[directory], true)
913     Util::Disk.write(File.join(directory, state_file), json_data)
914   end
915 end
translate(data) click to toggle source
Calls superclass method
    # File lib/core/plugin/project.rb
945 def self.translate(data)
946   options = super(data)
947 
948   case data
949   when String
950     options = { :url => data }
951   when Hash
952     options = data
953   end
954 
955   if options.has_key?(:url)
956     if matches = translate_reference(options[:url])
957       options[:provider]  = matches[:provider]
958       options[:reference] = matches[:reference]
959       options[:url]       = matches[:url]
960       options[:revision]  = matches[:revision] unless options.has_key?(:revision)
961 
962       logger.debug("Translating project options: #{options.inspect}")
963     end
964   end
965   options
966 end
translate_reference(reference, editable = false) click to toggle source
    # File lib/core/plugin/project.rb
970 def self.translate_reference(reference, editable = false)
971   # ex: github:::username/project[branch/revision]
972   if reference && reference.match(/^\s*([a-zA-Z0-9_-]+):::([^\]\s]+)\s*(?:\[\s*([^\]\s]+)\s*\])?\s*$/)
973     provider = $1
974     url      = $2
975     revision = $3
976 
977     logger.debug("Translating project reference: #{provider}  #{url}  #{revision}")
978 
979     if provider && Nucleon.loaded_plugins(:nucleon, :project).keys.include?(provider.to_sym)
980       klass        = Nucleon.class_const([ :nucleon, :project, provider ])
981       expanded_url = klass.send(:expand_url, url, editable) if klass.respond_to?(:expand_url)
982     end
983     expanded_url = url unless expanded_url
984 
985     info = {
986       :provider  => provider,
987       :reference => url,
988       :url       => expanded_url,
989       :revision  => revision
990     }
991 
992     logger.debug("Project reference info: #{info.inspect}")
993     return info
994   end
995   nil
996 end

Public Instance Methods

add_remote_url(name, url, options = {}) { |config, url| ... } click to toggle source
    # File lib/core/plugin/project.rb
721 def add_remote_url(name, url, options = {})
722   if can_persist?
723     localize do
724       config = Config.ensure(options)
725 
726       if url = extension_set(:add_remote_url, url, { :name => name, :config => config })
727         url = translate_edit_url(url) if name == :edit && config.get(:translate, true)
728 
729         logger.info("Adding project remote url #{url} to #{name}")
730         yield(config, url) if block_given?
731       end
732     end
733   else
734     logger.warn("Project #{self.name} does not meet the criteria for persistence and can not have remotes")
735   end
736 end
add_subproject(path, url, revision, options = {}) { |config| ... } click to toggle source
    # File lib/core/plugin/project.rb
555 def add_subproject(path, url, revision, options = {})
556   success = true
557 
558   if can_persist?
559     localize do
560       config = Config.ensure(options).import({ :path => path, :url => url, :revision => revision })
561 
562       if extension_check(:add_project, { :config => config })
563         logger.info("Adding a sub project to #{config[:path]} from #{config[:url]} at #{config[:revision]}")
564 
565         success = yield(config) if block_given?
566 
567         if success
568           extension(:add_project_success, { :config => config })
569 
570           config.init(:files, '.')
571           config.init(:message, "Adding project #{config[:url]} to #{config[:path]}")
572 
573           commit(config[:files], { :message => config[:message] })
574           update_subprojects
575         end
576       else
577         success = false
578       end
579     end
580   else
581     logger.warn("Project #{name} does not meet the criteria for persistence and can not have sub projects")
582   end
583   success
584 end
cache() click to toggle source
    # File lib/core/plugin/project.rb
157 def cache
158   @cache
159 end
can_persist?() click to toggle source
    # File lib/core/plugin/project.rb
117 def can_persist?
118   return top?(directory) if directory
119   false
120 end
checkout(revision) { |success| ... } click to toggle source
    # File lib/core/plugin/project.rb
432 def checkout(revision)
433   success = false
434 
435   if can_persist?
436     localize do
437       if extension_check(:checkout, { :revision => revision })
438         logger.info("Checking out project #{name} revision: #{revision}")
439 
440         success = true
441         success = yield(success) if block_given?
442 
443         if success
444           set(:revision, revision)
445 
446           extension(:checkout_success, { :revision => revision })
447           load_subprojects
448         end
449       end
450     end
451   else
452     logger.warn("Project #{name} does not meet the criteria for persistence and can not checkout a revision")
453   end
454   success
455 end
commit(files = '.', options = {}) { |config, time, user, message| ... } click to toggle source
    # File lib/core/plugin/project.rb
459 def commit(files = '.', options = {})
460   success = false
461 
462   if can_persist?
463     localize do
464       config = Config.ensure(options)
465 
466       if extension_check(:commit, { :files => files, :config => config })
467         logger.info("Committing changes to project #{name}: #{files.inspect}")
468 
469         time     = Time.new.strftime("%Y-%m-%d %H:%M:%S")
470         user     = config.delete(:user, ENV['USER'] + '@' + fact(:fqdn))
471 
472         message  = config.get(:message, '')
473         message  = 'Saving state: ' + ( files.is_a?(Array) ? "\n\n" + files.join("\n") : files.to_s ) if message.empty?
474 
475         user = 'UNKNOWN' unless user && ! user.empty?
476 
477         logger.debug("Commit by #{user} at #{time} with #{message}")
478         success = yield(config, time, user, message) if block_given?
479 
480         if success
481           load_revision
482 
483           extension(:commit_success, { :files => files })
484 
485           if ! parent.nil? && config.get(:propogate, true)
486             logger.info("Commit to parent as parent exists and propogate option given")
487 
488             parent.load_revision
489             parent.commit(directory, config.import({
490               :message => "Updating #{path}: #{message}"
491             }))
492           end
493         end
494       end
495     end
496   else
497     logger.warn("Project #{name} does not meet the criteria for persistence and can not be committed to")
498   end
499   success
500 end
config(name, options = {}) { |config| ... } click to toggle source
    # File lib/core/plugin/project.rb
287 def config(name, options = {})
288   localize do
289     config = Config.ensure(options)
290     can_persist? && block_given? ? yield(config) : nil
291   end
292 end
delete_config(name, options = {}) { |config| ... } click to toggle source
    # File lib/core/plugin/project.rb
310 def delete_config(name, options = {})
311   localize do
312     config = Config.ensure(options)
313 
314     if can_persist? && extension_check(:delete_config, { :name => name, :config => config })
315       logger.info("Removing project #{self.name} configuration: #{name}")
316 
317       yield(config) if block_given?
318     end
319   end
320 end
delete_remote(name) { || ... } click to toggle source
    # File lib/core/plugin/project.rb
769 def delete_remote(name)
770   if can_persist?
771     localize do
772       if extension_check(:delete_remote, { :name => name })
773         logger.info("Deleting project remote #{name}")
774         yield if block_given?
775       end
776     end
777   else
778     logger.warn("Project #{self.name} does not meet the criteria for persistence and can not have remotes")
779   end
780 end
delete_subproject(path) { |config| ... } click to toggle source
    # File lib/core/plugin/project.rb
588 def delete_subproject(path)
589   success = true
590 
591   if can_persist?
592     localize do
593       config = Config.new({ :path => path }, {}, true, false)
594 
595       if extension_check(:delete_project, { :config => config })
596         logger.info("Deleting a sub project at #{config[:path]}")
597 
598         success = yield(config) if block_given?
599 
600         if success
601           extension(:delete_project_success, { :config => config })
602 
603           config.init(:files, '.')
604           config.init(:message, "Removing project at #{config[:path]}")
605 
606           commit(config[:files], { :message => config[:message] })
607           update_subprojects
608         end
609       end
610     end
611   else
612     logger.warn("Project #{name} does not meet the criteria for persistence and can not have sub projects")
613   end
614   success
615 end
directory(default = nil) click to toggle source
    # File lib/core/plugin/project.rb
224 def directory(default = nil)
225   get(:directory, default)
226 end
each() { |path, project| ... } click to toggle source
    # File lib/core/plugin/project.rb
644 def each
645   if can_persist?
646     localize do
647       logger.info("Iterating through all sub projects of project #{name}")
648 
649       subprojects.each do |path, project|
650         extension(:process_project, { :project => project })
651 
652         logger.debug("Running process on sub project #{path}")
653         yield(path, project)
654       end
655     end
656   else
657     logger.warn("Project #{name} does not meet the criteria for persistence and can not have sub projects")
658   end
659 end
edit_url(default = nil) click to toggle source
    # File lib/core/plugin/project.rb
206 def edit_url(default = nil)
207   get(:edit, default)
208 end
full_path(local_path) click to toggle source
     # File lib/core/plugin/project.rb
1053 def full_path(local_path)
1054   File.join(directory, local_path)
1055 end
ignore(files) { || ... } click to toggle source
    # File lib/core/plugin/project.rb
504 def ignore(files)
505   return unless directory && manage_ignore?
506 
507   files = nil
508   files = yield if block_given?
509   commit(files, { :message => "Adding project ignores." }) if files
510 end
init_project() click to toggle source
   # File lib/core/plugin/project.rb
94 def init_project
95   init_auth
96   init_parent
97   init_remotes
98   load_revision
99 end
local_path(file_path) click to toggle source
     # File lib/core/plugin/project.rb
1047 def local_path(file_path)
1048   file_path.gsub(directory + File::SEPARATOR, '')
1049 end
localize(path = nil) { || ... } click to toggle source
     # File lib/core/plugin/project.rb
1031 def localize(path = nil)
1032   prev_directory = Dir.pwd
1033   path           = directory if path.nil?
1034 
1035   Dir.chdir(path)
1036 
1037   result = safe_exec(true) do
1038     yield
1039   end
1040 
1041   Dir.chdir(prev_directory)
1042   result
1043 end
manage_ignore=(ignore) click to toggle source
    # File lib/core/plugin/project.rb
146 def manage_ignore=ignore
147   set(:manage_ignore, ignore)
148 end
manage_ignore?() click to toggle source
    # File lib/core/plugin/project.rb
150 def manage_ignore?
151   get(:manage_ignore, false)
152 end
normalize(reload) click to toggle source
Calls superclass method
   # File lib/core/plugin/project.rb
47 def normalize(reload)
48   super
49 
50   directory = Util::Disk.filename(get(:directory, Dir.pwd))
51 
52   set_directory(directory)
53   register
54 
55   set_url(get(:url)) if get(:url, false)
56 
57   myself.plugin_name = path if ! plugin_name || plugin_name.to_sym == plugin_provider
58 
59   ui.resource = plugin_name
60   logger      = plugin_name
61 
62   if keys = delete(:keys, nil)
63     set(:private_key, keys[:private_key])
64     set(:public_key, keys[:public_key])
65   end
66 
67   extension(:normalize)
68 
69   init_project
70   extension(:init)
71 
72   pull if get(:pull, false)
73 
74   unless reload
75     if get(:nucleon_cache, true)
76       @cache = Util::Cache.new(directory, Nucleon.sha1(plugin_name), '.project_cache')
77       init_cache
78     end
79 
80     if get(:nucleon_file, true) && ( get(:nucleon_resave, false) || self.class.load_project_info(directory).empty? )
81       self.class.store_project_info(directory, plugin_provider, Util::Data.subset(export, [
82         :provider,
83         :url,
84         :edit,
85         :revision,
86         :manage_ignore
87       ]))
88     end
89   end
90 end
parent(default = nil) click to toggle source
    # File lib/core/plugin/project.rb
269 def parent(default = nil)
270   get(:parent, default)
271 end
path() click to toggle source
    # File lib/core/plugin/project.rb
230 def path
231   if parent.nil?
232     return directory
233   end
234   directory.gsub(parent.directory + File::SEPARATOR, '')
235 end
private_key() click to toggle source
    # File lib/core/plugin/project.rb
169 def private_key
170   get(:private_key, nil)
171 end
private_key_str() click to toggle source
    # File lib/core/plugin/project.rb
173 def private_key_str
174   return Util::Disk.read(private_key) if private_key
175   nil
176 end
public_key() click to toggle source
    # File lib/core/plugin/project.rb
178 def public_key
179   get(:public_key, nil)
180 end
public_key_str() click to toggle source
    # File lib/core/plugin/project.rb
182 def public_key_str
183   return Util::Disk.read(public_key) if public_key
184   nil
185 end
pull(remote = :origin, options = {}) { |config, remote| ... } click to toggle source
    # File lib/core/plugin/project.rb
785 def pull(remote = :origin, options = {})
786   config = Config.ensure(options)
787 
788   config[:remote] = remote(:edit) && remote == :origin ? :edit : remote
789 
790   success = false
791 
792   if can_persist?
793     localize do
794       if extension_check(:pull, { :directory => directory, :config => config })
795         remote = config.delete(:remote)
796 
797         if remote(remote)
798           logger.info("Pulling from #{remote} into #{directory}")
799           success = yield(config, remote) if block_given?
800         end
801 
802         if success
803           update_subprojects
804 
805           extension(:pull_success, { :directory => directory, :remote => remote, :config => config })
806 
807           if ! parent.nil? && config.get(:propogate, true)
808             logger.debug("Commit to parent as parent exists and propogate option was given")
809 
810             parent.commit(directory, config.import({
811               :message     => "Pulling updates for subproject #{path}",
812               :allow_empty => true
813             }))
814           end
815         end
816       end
817     end
818   else
819     logger.warn("Project #{name} does not meet the criteria for persistence and can not pull from remotes")
820   end
821   success
822 end
push(remote = :edit, options = {}) { |config, push_remote| ... } click to toggle source
    # File lib/core/plugin/project.rb
826 def push(remote = :edit, options = {})
827   config  = Config.ensure(options).import({ :remote => remote })
828   no_pull = config.delete(:no_pull, false)
829   success = false
830 
831   push_project = lambda do |push_remote|
832     logger.info("Pushing to #{push_remote} from #{directory}")
833     success = yield(config, push_remote) if block_given? && ( no_pull || pull(push_remote, config) )
834   end
835 
836   if can_persist?
837     unless remote(remote)
838       logger.warn("Project #{plugin_name} does not have the remote '#{remote}' defined")
839       return true
840     end
841     localize do
842       if extension_check(:push, { :directory => directory, :config => config })
843         remote = config.delete(:remote)
844         tries  = config.delete(:tries, 5)
845 
846         # TODO: Figure out a better way through specialized exception handling
847         begin
848           success = push_project.call(remote)
849           raise unless success
850 
851         rescue
852           tries -= 1
853           retry if tries > 0
854         end
855 
856         if success
857           config.delete(:revision)
858 
859           extension(:push_success, { :directory => directory, :remote => remote, :config => config })
860 
861           if config.get(:propogate, true)
862             unless parent.nil?
863               propogate_up = config.get(:propogate_up, nil)
864 
865               if propogate_up.nil? || propogate_up
866                 logger.debug("Commit to parent as parent exists and propogate option was given")
867                 parent.push(remote, Config.new(config.export.dup).import({
868                   :propogate_up   => true,
869                   :propogate_down => false
870                 }))
871               end
872             end
873 
874             logger.debug("Pushing sub projects")
875 
876             propogate_down = config.get(:propogate_down, nil)
877 
878             if propogate_down.nil? || propogate_down
879               each do |path, project|
880                 project.push(remote, Config.new(config.export.dup).import({
881                   :propogate_up   => false,
882                   :propogate_down => true
883                 }))
884               end
885             end
886           end
887         end
888       end
889     end
890   else
891     logger.warn("Project #{plugin_name} does not meet the criteria for persistence and can not push to remotes")
892   end
893   success
894 end
reference() click to toggle source
    # File lib/core/plugin/project.rb
163 def reference
164   get(:reference, nil)
165 end
register() click to toggle source
Calls superclass method
    # File lib/core/plugin/project.rb
104 def register
105   super
106   if directory
107     lib_path = File.join(directory, 'lib')
108     if File.directory?(lib_path)
109       Nucleon.register(lib_path)
110     end
111   end
112 end
remote(name) { || ... } click to toggle source
    # File lib/core/plugin/project.rb
685 def remote(name)
686   url = nil
687   if can_persist?
688     localize do
689       logger.info("Fetching remote url for #{name}")
690       url = yield if block_given?
691     end
692   end
693   url
694 end
revision(default = nil) click to toggle source
    # File lib/core/plugin/project.rb
281 def revision(default = nil)
282   get(:revision, default).to_s
283 end
set_config(name, value, options = {}) { |config, value| ... } click to toggle source
    # File lib/core/plugin/project.rb
296 def set_config(name, value, options = {})
297   localize do
298     config = Config.ensure(options)
299 
300     if can_persist? && value = extension_set(:set_config, value, { :name => name, :config => config })
301       logger.info("Setting project #{self.name} configuration: #{name} = #{value.inspect}")
302 
303       yield(config, value) if block_given?
304     end
305   end
306 end
set_edit_url(url) click to toggle source
    # File lib/core/plugin/project.rb
212 def set_edit_url(url)
213   url = url.strip
214   if url && url = extension_set(:set_edit_url, url)
215     logger.info("Setting project #{name} edit url to #{url}")
216 
217     set(:edit, url)
218     set_remote(:edit, url)
219   end
220 end
set_host_remote(name, hosts, path, options = {}) click to toggle source
    # File lib/core/plugin/project.rb
740 def set_host_remote(name, hosts, path, options = {})
741   if can_persist?
742     localize do
743       config = Config.ensure(options).import({ :path => path, :translate => false })
744       hosts  = array(hosts)
745 
746       unless hosts.empty?
747         if hosts = extension_set(:set_host_remote, hosts, { :name => name, :config => config })
748           unless ! hosts || hosts.empty?
749             path = config.delete(:path)
750 
751             logger.info("Setting host remote #{name} for #{hosts.inspect} at #{path}")
752             set_remote(name, translate_url(hosts.shift, path, config.export), config)
753 
754             hosts.each do |host|
755               logger.debug("Adding remote url to #{host}")
756               add_remote_url(name, translate_url(host, path, config.export), config)
757             end
758           end
759         end
760       end
761     end
762   else
763     logger.warn("Project #{self.name} does not meet the criteria for persistence and can not have remotes")
764   end
765 end
set_location(directory) { || ... } click to toggle source
    # File lib/core/plugin/project.rb
259 def set_location(directory)
260   set_directory(directory)
261 
262   yield if block_given?
263 
264   init_project
265 end
set_remote(name, url, options = {}) { |url| ... } click to toggle source
    # File lib/core/plugin/project.rb
698 def set_remote(name, url, options = {})
699   config = Config.ensure(options)
700 
701   if can_persist?
702     localize do
703       unless url.strip.empty?
704         if url = extension_set(:set_remote, url, { :name => name })
705           delete_remote(name)
706 
707           url = translate_edit_url(url) if name == :edit && config.get(:translate, true)
708 
709           logger.info("Setting project remote #{name} to #{url}")
710           yield(url) if block_given?
711         end
712       end
713     end
714   else
715     logger.warn("Project #{self.name} does not meet the criteria for persistence and can not have remotes")
716   end
717 end
set_url(url) click to toggle source
    # File lib/core/plugin/project.rb
195 def set_url(url)
196   if url && url = extension_set(:set_url, url.strip)
197     logger.info("Setting project #{name} url to #{url}")
198 
199     set(:url, url)
200     set_remote(:origin, url)
201   end
202 end
subproject?(path) click to toggle source
    # File lib/core/plugin/project.rb
131 def subproject?(path)
132   false
133 end
subprojects(default = nil) click to toggle source
    # File lib/core/plugin/project.rb
275 def subprojects(default = nil)
276   get(:subprojects, default)
277 end
top?(path) click to toggle source
    # File lib/core/plugin/project.rb
124 def top?(path)
125   return true if File.directory?(path)
126   false
127 end
translate_edit_url(url, options = {}) { |config| ... } click to toggle source
     # File lib/core/plugin/project.rb
1019 def translate_edit_url(url, options = {})
1020   config = Config.ensure(options)
1021 
1022   if block_given?
1023     temp_url = yield(config)
1024     url      = temp_url if temp_url
1025   end
1026   url
1027 end
translate_reference(reference, editable = false) click to toggle source
     # File lib/core/plugin/project.rb
1000 def translate_reference(reference, editable = false)
1001   myself.class.translate_reference(reference, editable)
1002 end
translate_url(host, path, options = {}) { |config| ... } click to toggle source
     # File lib/core/plugin/project.rb
1006 def translate_url(host, path, options = {})
1007   config = Config.ensure(options)
1008   url    = "#{host}/#{path}"
1009 
1010   if block_given?
1011     temp_url = yield(config)
1012     url      = temp_url if temp_url
1013   end
1014   url
1015 end
url(default = nil) click to toggle source
    # File lib/core/plugin/project.rb
189 def url(default = nil)
190   get(:url, default)
191 end

Protected Instance Methods

init_auth() { || ... } click to toggle source
    # File lib/core/plugin/project.rb
351 def init_auth
352   if can_persist?
353     localize do
354       logger.info("Initializing project #{name} authorization")
355       yield if block_given?
356     end
357   else
358     logger.warn("Project #{name} does not meet the criteria for persistence can not be authorized")
359   end
360 end
init_cache() click to toggle source
    # File lib/core/plugin/project.rb
344 def init_cache
345   ignore(self.class.state_file)
346 end
init_parent() click to toggle source
    # File lib/core/plugin/project.rb
365 def init_parent
366   delete(:parent)
367 
368   logger.info("Initializing project #{name} parents")
369 
370   if top?(directory)
371     logger.debug("Project #{name} has no parents to initialize")
372   else
373     search_dir = directory
374     last_dir   = nil
375 
376     while File.directory?((search_dir = File.expand_path('..', search_dir)))
377       logger.debug("Scanning directory #{search_dir} for parent project")
378 
379       unless last_dir.nil? || last_dir != search_dir
380         break
381       end
382       if project_directory?(search_dir)
383         logger.debug("Directory #{search_dir} is a valid parent for this #{plugin_provider} project")
384 
385         project = myself.class.open(search_dir, plugin_provider)
386 
387         extension(:init_parent, { :parent => project })
388 
389         set(:parent, project)
390         logger.debug("Setting parent to #{parent.inspect}")
391         break;
392       end
393       last_dir = search_dir
394     end
395   end
396 end
init_remotes() { || ... } click to toggle source
    # File lib/core/plugin/project.rb
664 def init_remotes
665   if can_persist?
666     localize do
667       logger.info("Initializing project #{name} remotes")
668 
669       origin_url = url
670       origin_url = yield if block_given?
671 
672       if origin_url && origin_url = extension_set(:init_remotes, origin_url).to_s.strip
673         set(:url, origin_url)
674         set_edit_url(translate_edit_url(url))
675       end
676     end
677   else
678     logger.warn("Project #{name} does not meet the criteria for persistence and can not have remotes")
679   end
680 end
load_revision() { || ... } click to toggle source
    # File lib/core/plugin/project.rb
401 def load_revision
402   if can_persist?
403     localize do
404       logger.info("Loading project #{plugin_name} revision")
405 
406       specified_revision = get(:revision, nil)
407 
408       current_revision = revision.to_s
409       current_revision = yield if block_given?
410 
411       if current_revision && extended_revision = extension_set(:load_revision, specified_revision).to_s.strip
412         if extended_revision.empty?
413           extended_revision = current_revision
414         end
415 
416         set(:revision, extended_revision)
417         checkout(extended_revision) if current_revision != extended_revision
418 
419         logger.debug("Loaded revision: #{revision}")
420 
421         load_subprojects
422       end
423     end
424   else
425     logger.warn("Project #{name} does not meet the criteria for persistence and has no revision")
426   end
427 end
load_subprojects(options = {}) { |project_path, data| ... } click to toggle source
    # File lib/core/plugin/project.rb
515 def load_subprojects(options = {})
516   subprojects = {}
517 
518   if can_persist?
519     config = Config.ensure(options)
520 
521     logger.info("Loading sub projects for project #{name}")
522 
523     subproject_config(config).each do |path, data|
524       project_path = File.join(directory, path)
525 
526       if File.directory?(project_path)
527         logger.debug("Checking if project path #{project_path} is a valid sub project")
528 
529         add_project = true
530         add_project = yield(project_path, data) if block_given?
531 
532         if add_project
533           logger.debug("Directory #{project_path} is a valid sub project for this #{plugin_provider} project")
534 
535           project = myself.class.open(project_path, plugin_provider, { :nucleon_file => get(:nucleon_file, true) })
536 
537           extension(:load_project, { :project => project })
538           subprojects[path] = project
539         else
540           logger.warn("Directory #{project_path} is not a valid sub project for this #{plugin_provider} project")
541         end
542       else
543         logger.warn("Sub project configuration points to a location that is not a directory: #{project_path}")
544       end
545     end
546   else
547     logger.warn("Project #{name} does not meet the criteria for persistence and can not have sub projects")
548   end
549   set(:subprojects, subprojects)
550 end
project_directory?(path, require_top_level = false) click to toggle source
    # File lib/core/plugin/project.rb
137 def project_directory?(path, require_top_level = false)
138   path = File.expand_path(path)
139   return true if File.directory?(path) && (! require_top_level || top?(path))
140   false
141 end
set_directory(directory) click to toggle source
    # File lib/core/plugin/project.rb
239 def set_directory(directory)
240   if Util::Data.empty?(directory)
241     current_directory = Dir.pwd
242   else
243     current_directory = File.expand_path(Util::Disk.filename(directory))
244   end
245 
246   if current_directory = extension_set(:set_directory, current_directory)
247     logger.info("Setting project #{name} directory to #{current_directory}")
248 
249     @@projects.delete(get(:directory)) if get(:directory)
250     @@projects[current_directory] = myself
251 
252     set(:directory, current_directory)
253   end
254 end
subproject_config(options = {}) { |config| ... } click to toggle source
    # File lib/core/plugin/project.rb
324 def subproject_config(options = {})
325   result = {}
326 
327   localize do
328     if can_persist?
329       config = Config.ensure(options)
330       result = yield(config) if block_given?
331 
332       extension(:subproject_config, { :config => result })
333 
334       logger.debug("Subproject configuration: #{result.inspect}")
335     end
336   end
337   result
338 end
update_subprojects(options = {}) { |config| ... } click to toggle source
    # File lib/core/plugin/project.rb
619 def update_subprojects(options = {})
620   if can_persist?
621     localize do
622       config = Config.ensure(options)
623 
624       if extension_check(:update_projects)
625         logger.info("Updating sub projects in project #{name}")
626 
627         success = false
628         success = yield(config) if block_given?
629 
630         if success
631           extension(:update_projects_success)
632           load_subprojects
633         end
634       end
635     end
636   else
637     logger.warn("Project #{name} does not meet the criteria for persistence and can not have sub projects")
638   end
639 end