eac_launcher 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 59a443736eaaf23cbf3cb9690e04f5ff625d2325
4
- data.tar.gz: a2d16dda60c6c7584121401bbe8bedb4e69c4313
3
+ metadata.gz: 52aa71693d4a4209ac7290124875448649aaed7b
4
+ data.tar.gz: 16cd264adfe0fbd7803a0f1226211071fc9c47f6
5
5
  SHA512:
6
- metadata.gz: 0b24a6b4c192e00298cd8126b559447c1d8bb7d1397657e95ad2a1a7501009c5056df1f5a15a51cfcf9d3eef16f1ca2d2bbf003cadf3ebe9ed15001ed291c7eb
7
- data.tar.gz: e692b08209116dc4d56d0526378e0d24b10b0e1c9fa2cab3585a91ca29fe029c44938d9661301421e0d9175e36ae08f4f39f2e310b79c956cbd758132c9a57ac
6
+ metadata.gz: 647bcc691051e3f74abf673997c289ba5246b51104278ebc3e4c9d48669ffb54e3d01c7fcd904f6172d523bdf29cb9610aa5084c43e6fd3ff25bf3a3620dc363
7
+ data.tar.gz: 29a16f00a5abd889bc15719dd3e1c3e2a9c8d22ace0a9b41181e397178b3886d5ff9a42ac7199c21fa27d61a1bff5e26c767b40d654c8fb1d0d010c516178a2c
@@ -14,7 +14,8 @@ require('yaml')
14
14
 
15
15
  module EacLauncher
16
16
  require 'eac_launcher/context'
17
- require 'eac_launcher/path'
17
+ require 'eac_launcher/paths/logical'
18
+ require 'eac_launcher/paths/real'
18
19
  require 'eac_launcher/project'
19
20
  require 'eac_launcher/stereotype'
20
21
  require 'eac_launcher/context/settings'
@@ -1,6 +1,7 @@
1
1
  module EacLauncher
2
2
  class Context
3
3
  include ::Eac::SimpleCache
4
+ include ::EacRubyUtils::Console::Speaker
4
5
 
5
6
  DEFAULT_PROJECTS_ROOT = '.'.freeze
6
7
  DEFAULT_SETTINGS_FILE = ::File.join(ENV['HOME'], '.config', 'eac_launcher', 'settings.yml')
@@ -23,7 +24,7 @@ module EacLauncher
23
24
 
24
25
  def initialize(options = {})
25
26
  @options = options.with_indifferent_access
26
- @root = ::EacLauncher::Instances::Base.new(build_option(:projects_root), nil)
27
+ @root = ::EacLauncher::Paths::Logical.new(nil, build_option(:projects_root), '/')
27
28
  @settings = ::EacLauncher::Context::Settings.new(build_option(:settings_file))
28
29
  @cache_root = build_option(:cache_root)
29
30
  @publish_options = { new: false, confirm: false, stereotype: nil }
@@ -50,30 +51,34 @@ module EacLauncher
50
51
  def projects_uncached
51
52
  r = {}
52
53
  instances.each do |i|
53
- r[i.basename] ||= []
54
- r[i.basename] << i
54
+ r[i.project_name] ||= []
55
+ r[i.project_name] << i
55
56
  end
56
57
  r.map { |name, instances| ::EacLauncher::Project.new(name, instances) }
57
- .select { |p| include_project?(p) }
58
58
  end
59
59
 
60
60
  def instances_uncached
61
- instance_instances(root)
61
+ path_instances(root, nil)
62
62
  end
63
63
 
64
- def instance_instances(i)
65
- r = []
66
- r << i if include_instance?(i)
67
- r += i.children.flat_map { |c| instance_instances(c) }
68
- r
69
- end
70
-
71
- def include_project?(p)
72
- !@settings.excluded_projects.include?(p.name)
64
+ def path_instances(path, parent_instance)
65
+ on_rescued_path_instances(path) do |r|
66
+ if path.project?
67
+ parent_instance = ::EacLauncher::Instances::Base.instanciate(path, self, parent_instance)
68
+ r << path if path.included?
69
+ end
70
+ r.concat(path.children.flat_map { |c| path_instances(c, parent_instance) })
71
+ end
73
72
  end
74
73
 
75
- def include_instance?(i)
76
- i.project? && !@settings.excluded_projects.include?(i.project_name)
74
+ def on_rescued_path_instances(path)
75
+ r = []
76
+ begin
77
+ yield(r)
78
+ rescue StandardError => ex
79
+ warn("#{path}: #{ex}")
80
+ end
81
+ r
77
82
  end
78
83
  end
79
84
  end
@@ -3,7 +3,7 @@ require_relative 'base/subrepo'
3
3
 
4
4
  module EacLauncher
5
5
  module Git
6
- class Base < ::EacLauncher::Path
6
+ class Base < ::EacLauncher::Paths::Real
7
7
  include ::Eac::SimpleCache
8
8
  include ::EacLauncher::Git::Base::Subrepo
9
9
  include ::EacLauncher::Git::Base::Underlying
@@ -1,6 +1,6 @@
1
1
  module EacLauncher
2
2
  module Git
3
- class Base < ::EacLauncher::Path
3
+ class Base < ::EacLauncher::Paths::Real
4
4
  module Subrepo
5
5
  def subrepo_status(subrepo_path)
6
6
  s = execute!('subrepo', 'status', subrepo_path.gsub(%r{\A/}, ''))
@@ -10,6 +10,13 @@ module EacLauncher
10
10
  r
11
11
  end
12
12
 
13
+ def subrepo_remote_url(subrepo_path)
14
+ h = subrepo_status(subrepo_path)
15
+ url = h['Remote URL']
16
+ return url if url.present?
17
+ raise "Remote URL is blank for subrepo \"#{subrepo_path}\" (Subrepo status: #{h})"
18
+ end
19
+
13
20
  private
14
21
 
15
22
  def subrepo_status_parse_output(s)
@@ -1,6 +1,6 @@
1
1
  module EacLauncher
2
2
  module Git
3
- class Base < ::EacLauncher::Path
3
+ class Base < ::EacLauncher::Paths::Real
4
4
  module Underlying
5
5
  def execute!(*args)
6
6
  args, options = build_args(args)
@@ -1,6 +1,6 @@
1
1
  module EacLauncher
2
2
  module Git
3
- class MirrorUpdate < ::EacLauncher::Path
3
+ class MirrorUpdate < ::EacLauncher::Paths::Real
4
4
  include ::Eac::SimpleCache
5
5
 
6
6
  def initialize(target_path, source_path, source_rev)
@@ -20,7 +20,8 @@ module EacLauncher
20
20
 
21
21
  def fetch_remote_source
22
22
  @target_git.git
23
- @target_git.fetch("file://#{@source_git}", tags: true)
23
+ @target_git.assert_remote_url('origin', @source_git)
24
+ @target_git.fetch('origin', tags: true)
24
25
  end
25
26
 
26
27
  def reset_source_rev
@@ -37,7 +37,7 @@ module EacLauncher
37
37
  end
38
38
 
39
39
  def sgit_uncached
40
- ::EacLauncher::Git::Base.new(@instance.current_cache)
40
+ ::EacLauncher::Git::Base.new(@instance.warped)
41
41
  end
42
42
 
43
43
  def publish
@@ -4,7 +4,7 @@ module EacLauncher
4
4
  # * source_instance
5
5
  # * source_remote_name
6
6
  # * current_ref
7
- class WarpBase < ::EacLauncher::Path
7
+ class WarpBase < ::EacLauncher::Paths::Real
8
8
  include ::Eac::SimpleCache
9
9
 
10
10
  TARGET_REMOTE = 'target'.freeze
@@ -23,7 +23,7 @@ module EacLauncher
23
23
  def update
24
24
  ::EacLauncher::Git::MirrorUpdate.new(
25
25
  path,
26
- source_instance,
26
+ source_instance.real,
27
27
  source_instance.options.git_current_revision
28
28
  )
29
29
  end
@@ -33,7 +33,7 @@ module EacLauncher
33
33
  end
34
34
 
35
35
  def source_git_uncached
36
- ::EacLauncher::Git::Base.new(source_instance)
36
+ ::EacLauncher::Git::Base.new(source_instance.real)
37
37
  end
38
38
 
39
39
  def cache_git_uncached
@@ -2,41 +2,39 @@ require_relative 'base/cache'
2
2
 
3
3
  module EacLauncher
4
4
  module Instances
5
- class Base < ::EacLauncher::Path
6
- include ::Eac::SimpleCache
7
- include ::EacRubyUtils::Console::Speaker
8
- include ::EacLauncher::Instances::Base::Cache
9
-
10
- attr_reader :parent
5
+ module Base
6
+ class << self
7
+ def extend_object(object)
8
+ object.extend ::Eac::SimpleCache
9
+ object.extend ::EacRubyUtils::Console::Speaker
10
+ object.extend ::EacLauncher::Instances::Base::Cache
11
+ super
12
+ end
11
13
 
12
- def initialize(path, parent)
13
- super(path)
14
- @parent = parent
14
+ def instanciate(path, context, parent)
15
+ unless path.is_a?(::EacLauncher::Instances::Base)
16
+ raise "#{path} is not a project" unless path.project?
17
+ path.extend(::EacLauncher::Instances::Base)
18
+ path.context = context
19
+ path.parent = parent
20
+ end
21
+ path
22
+ end
15
23
  end
16
24
 
17
- def name
18
- to_root_path
19
- end
25
+ attr_accessor :context, :parent
20
26
 
21
- def stereotypes_uncached
22
- EacLauncher::Stereotype.stereotypes.select { |s| s.match?(self) }
27
+ def name
28
+ logical
23
29
  end
24
30
 
25
31
  def stereotype?(stereotype)
26
32
  stereotypes.include?(stereotype)
27
33
  end
28
34
 
29
- def children
30
- scan(self)
31
- end
32
-
33
35
  def to_parent_path
34
36
  return self unless @parent
35
- gsub(/\A#{Regexp.quote(@parent)}/, '')
36
- end
37
-
38
- def to_root_path
39
- gsub(/\A#{root}/, '')
37
+ logical.gsub(/\A#{Regexp.quote(@parent.logical)}/, '')
40
38
  end
41
39
 
42
40
  def project?
@@ -60,14 +58,11 @@ module EacLauncher
60
58
  end
61
59
 
62
60
  def project_name
63
- File.basename(self)
61
+ ::File.basename(logical)
64
62
  end
65
63
 
66
- def current_cache
67
- stereotypes.each do |s|
68
- return s.warp_class.new(self) if s.warp_class
69
- end
70
- self
64
+ def included?
65
+ !::EacLauncher::Context.current.settings.excluded_projects.include?(project_name)
71
66
  end
72
67
 
73
68
  private
@@ -81,33 +76,6 @@ module EacLauncher
81
76
  def options_uncached
82
77
  ::EacLauncher::Context.current.settings.instance_settings(self)
83
78
  end
84
-
85
- def root_uncached
86
- return self unless @parent
87
- @parent.root
88
- end
89
-
90
- def scan(path)
91
- r = []
92
- scan_subdirectories(path) do |sp|
93
- c = self.class.new(sp, self)
94
- if c.stereotypes.any?
95
- r << c
96
- else
97
- r += scan(sp)
98
- end
99
- end
100
- r
101
- end
102
-
103
- def scan_subdirectories(path)
104
- Dir.entries(path).each do |basename|
105
- next if %w[. ..].include?(basename)
106
- sp = path.subpath(basename)
107
- next unless File.directory?(sp)
108
- yield(sp)
109
- end
110
- end
111
79
  end
112
80
  end
113
81
  end
@@ -1,6 +1,6 @@
1
1
  module EacLauncher
2
2
  module Instances
3
- class Base < ::EacLauncher::Path
3
+ module Base
4
4
  module Cache
5
5
  def cache_path(subpath)
6
6
  File.join(cache_root, subpath)
@@ -0,0 +1,59 @@
1
+ require 'eac_launcher/paths/real'
2
+
3
+ module EacLauncher
4
+ module Paths
5
+ class Logical
6
+ include ::Eac::SimpleCache
7
+
8
+ attr_reader :real, :logical, :parent_path
9
+
10
+ def initialize(parent_path, real, logical)
11
+ @parent_path = parent_path
12
+ @real = ::EacLauncher::Paths::Real.new(real)
13
+ @logical = logical
14
+ end
15
+
16
+ def to_s
17
+ logical
18
+ end
19
+
20
+ def project?
21
+ stereotypes.any?
22
+ end
23
+
24
+ def children
25
+ r = []
26
+ Dir.entries(warped).each do |c|
27
+ c_path = ::File.join(warped, c)
28
+ next unless ::File.directory?(c_path)
29
+ next if c.start_with?('.')
30
+ r << build_child(c)
31
+ end
32
+ r
33
+ end
34
+
35
+ private
36
+
37
+ def stereotypes_uncached
38
+ ::EacLauncher::Stereotype.stereotypes.select { |s| s.match?(self) }
39
+ end
40
+
41
+ def build_child(name)
42
+ ::EacLauncher::Paths::Logical.new(
43
+ self,
44
+ ::File.join(warped, name),
45
+ ::File.join(logical, name)
46
+ )
47
+ end
48
+
49
+ def warped_uncached
50
+ if is_a?(::EacLauncher::Instances::Base)
51
+ stereotypes.each do |s|
52
+ return s.warp_class.new(self) if s.warp_class
53
+ end
54
+ end
55
+ real
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,37 @@
1
+ module EacLauncher
2
+ module Paths
3
+ class Real < String
4
+ def initialize(path)
5
+ raise "Argument path is not a string: \"#{path}\"|#{path.class}" unless path.is_a?(String)
6
+ super(path)
7
+ end
8
+
9
+ def subpath(relative_path)
10
+ ::EacLauncher::Paths::Real.new(::File.expand_path(relative_path, self))
11
+ end
12
+
13
+ def basename
14
+ ::File.basename(self)
15
+ end
16
+
17
+ def dirname
18
+ return nil if self == '/'
19
+ self.class.new(::File.dirname(self))
20
+ end
21
+
22
+ def find_file_with_extension(extension)
23
+ r = find_files_with_extension(extension)
24
+ return r.first if r.any?
25
+ raise "Extension \"#{extension}\" not found in directory \"#{self}\""
26
+ end
27
+
28
+ def find_files_with_extension(extension)
29
+ r = []
30
+ ::Dir.entries(self).each do |i|
31
+ r << ::File.expand_path(i, self) if i =~ /#{::Regexp.quote(extension)}\z/
32
+ end
33
+ r
34
+ end
35
+ end
36
+ end
37
+ end
@@ -33,7 +33,7 @@ module EacLauncher
33
33
  private
34
34
 
35
35
  def copy_gem_files
36
- @gem_root = ::EacLauncher::Path.new(::Dir.mktmpdir)
36
+ @gem_root = ::EacLauncher::Paths::Real.new(::Dir.mktmpdir)
37
37
  FileUtils.cp_r "#{@original_gem_root}/.", @gem_root
38
38
  end
39
39
 
@@ -5,7 +5,7 @@ module EacLauncher
5
5
 
6
6
  class << self
7
7
  def match?(path)
8
- File.directory?(path.subpath('.git'))
8
+ File.directory?(path.real.subpath('.git'))
9
9
  end
10
10
 
11
11
  def color
@@ -5,7 +5,7 @@ module EacLauncher
5
5
 
6
6
  class << self
7
7
  def match?(path)
8
- File.exist?(path.subpath('.gitrepo')) && subrepo_url(path) != 'none'
8
+ File.exist?(path.real.subpath('.gitrepo')) && subrepo_url(path.real) != 'none'
9
9
  end
10
10
 
11
11
  def color
@@ -1,7 +1,7 @@
1
1
  module EacLauncher
2
2
  module Stereotypes
3
3
  class GitSubrepo
4
- class Warp < ::EacLauncher::Path
4
+ class Warp < ::EacLauncher::Paths::Real
5
5
  include ::Eac::SimpleCache
6
6
 
7
7
  attr_reader :instance
@@ -41,11 +41,11 @@ module EacLauncher
41
41
  end
42
42
 
43
43
  def parent_git_uncached
44
- ::EacLauncher::Git::Base.new(instance.parent)
44
+ ::EacLauncher::Git::Base.new(parent_instance.real)
45
45
  end
46
46
 
47
47
  def parent_cache_git_uncached
48
- ::EacLauncher::Git::Base.new(parent_instance.current_cache)
48
+ ::EacLauncher::Git::Base.new(parent_instance.warped)
49
49
  end
50
50
 
51
51
  def aux_path
@@ -77,7 +77,7 @@ module EacLauncher
77
77
 
78
78
  def target_remote_url
79
79
  ::EacLauncher::Vendor::Github.to_ssh_url(
80
- parent_git.git.remote("subrepo/#{subrepo_subdir}").url
80
+ parent_cache_git.subrepo_remote_url(subrepo_subdir)
81
81
  )
82
82
  end
83
83
  end
@@ -5,12 +5,11 @@ module EacLauncher
5
5
 
6
6
  class << self
7
7
  def match?(path)
8
- return false if ::EacLauncher::Stereotypes::Git.match?(path) ||
9
- ::EacLauncher::Stereotypes::GitSubrepo.match?(path)
8
+ return false if other_git_stereotype?(path)
10
9
  return false unless other_nogit_stereotype?(path)
11
- parent = parent_git(path.parent)
10
+ parent = parent_git(path.parent_path)
12
11
  return false unless parent
13
- ::Git.open(parent).remote(File.basename(path)).url ? true : false
12
+ ::Git.open(parent.real).remote(path.real.basename).url ? true : false
14
13
  end
15
14
 
16
15
  def color
@@ -19,7 +18,12 @@ module EacLauncher
19
18
 
20
19
  def parent_git(p)
21
20
  return nil unless p
22
- ::EacLauncher::Stereotypes::Git.match?(p) ? p : parent_git(p.parent)
21
+ ::EacLauncher::Stereotypes::Git.match?(p) ? p : parent_git(p.parent_path)
22
+ end
23
+
24
+ def other_git_stereotype?(path)
25
+ ::EacLauncher::Stereotypes::Git.match?(path) ||
26
+ ::EacLauncher::Stereotypes::GitSubrepo.match?(path)
23
27
  end
24
28
 
25
29
  def other_nogit_stereotype?(path)
@@ -5,7 +5,7 @@ module EacLauncher
5
5
 
6
6
  class << self
7
7
  def match?(path)
8
- File.exist?(path.subpath('config.ru')) && File.basename(path) != 'dummy'
8
+ File.exist?(path.real.subpath('config.ru')) && path.real.basename != 'dummy'
9
9
  end
10
10
 
11
11
  def color
@@ -5,7 +5,7 @@ module EacLauncher
5
5
 
6
6
  class << self
7
7
  def match?(path)
8
- File.exist?(path.subpath('init.rb'))
8
+ File.exist?(path.real.subpath('init.rb'))
9
9
  end
10
10
 
11
11
  def color
@@ -5,7 +5,7 @@ module EacLauncher
5
5
 
6
6
  class << self
7
7
  def match?(path)
8
- Dir.glob(File.join(path, '*.gemspec')).any?
8
+ Dir.glob(File.join(path.real, '*.gemspec')).any?
9
9
  end
10
10
 
11
11
  def color
@@ -27,7 +27,7 @@ module EacLauncher
27
27
  private
28
28
 
29
29
  def source_uncached
30
- @instance.current_cache
30
+ @instance.warped
31
31
  end
32
32
 
33
33
  def gem_spec_uncached
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacLauncher
4
- VERSION = '0.2.0'.freeze
4
+ VERSION = '0.2.1'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esquilo Azul Company
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2018-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -163,7 +163,8 @@ files:
163
163
  - lib/eac_launcher/instances/error.rb
164
164
  - lib/eac_launcher/instances/runner_helper.rb
165
165
  - lib/eac_launcher/instances/settings.rb
166
- - lib/eac_launcher/path.rb
166
+ - lib/eac_launcher/paths/logical.rb
167
+ - lib/eac_launcher/paths/real.rb
167
168
  - lib/eac_launcher/project.rb
168
169
  - lib/eac_launcher/publish/base.rb
169
170
  - lib/eac_launcher/publish/check_result.rb
@@ -1,25 +0,0 @@
1
- module EacLauncher
2
- class Path < String
3
- def subpath(relative_path)
4
- ::EacLauncher::Path.new(::File.expand_path(relative_path, self))
5
- end
6
-
7
- def basename
8
- ::File.basename(self)
9
- end
10
-
11
- def find_file_with_extension(extension)
12
- r = find_files_with_extension(extension)
13
- return r.first if r.any?
14
- raise "Extension \"#{extension}\" not found in directory \"#{self}\""
15
- end
16
-
17
- def find_files_with_extension(extension)
18
- r = []
19
- ::Dir.entries(self).each do |i|
20
- r << ::File.expand_path(i, self) if i =~ /#{::Regexp.quote(extension)}\z/
21
- end
22
- r
23
- end
24
- end
25
- end