maruto 0.0.4 → 0.0.5
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.
- data/fixtures/magento_root/app/etc/modules/Bad_Example.xml +12 -0
- data/lib/maruto.rb +1 -1
- data/lib/maruto/magento_instance.rb +2 -1
- data/lib/maruto/module_configuration.rb +3 -3
- data/lib/maruto/module_definition.rb +22 -10
- data/lib/maruto/runner.rb +17 -7
- data/lib/maruto/version.rb +1 -1
- data/spec/module_definition_spec.rb +29 -1
- data/spec/module_version_spec.rb +50 -52
- metadata +2 -1
data/lib/maruto.rb
CHANGED
|
@@ -13,9 +13,10 @@ module Maruto::MagentoInstance
|
|
|
13
13
|
# ModuleConfiguration.analyse(m, active_modules)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
# TODO move to function: collect_warnings + write spec
|
|
16
17
|
warnings = []
|
|
17
18
|
all_modules.each do |m|
|
|
18
|
-
warnings.concat m[:warnings].map{|w|
|
|
19
|
+
warnings.concat m[:warnings].map{|w| w.merge(:module => m[:name]) } if m.include? :warnings
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
{
|
|
@@ -15,19 +15,19 @@ module Maruto::ModuleConfiguration
|
|
|
15
15
|
xml_node = xml_root.at_xpath('/config/modules')
|
|
16
16
|
if xml_node.nil?
|
|
17
17
|
m[:warnings] ||= []
|
|
18
|
-
m[:warnings] << "config.xml is missing a
|
|
18
|
+
m[:warnings] << { :file => m[:config_path], :message => "config.xml is missing a /config/modules node" }
|
|
19
19
|
return m
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
unless xml_node.at_xpath("./#{m[:name]}")
|
|
23
23
|
m[:warnings] ||= []
|
|
24
|
-
m[:warnings] << "config.xml is missing a
|
|
24
|
+
m[:warnings] << { :file => m[:config_path], :message => "config.xml is missing a /config/modules/#{m[:name]} node" }
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
xml_node.xpath("./*").each do |n|
|
|
28
28
|
unless n.name.to_sym == m[:name]
|
|
29
29
|
m[:warnings] ||= []
|
|
30
|
-
m[:warnings] << "config.xml contains configuration for a different module (
|
|
30
|
+
m[:warnings] << { :file => m[:config_path], :message => "config.xml contains configuration for a different module (/config/modules/#{n.name})" }
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -15,11 +15,13 @@ module Maruto::ModuleDefinition
|
|
|
15
15
|
module_definition[:dependencies] = deps if deps.size > 0
|
|
16
16
|
|
|
17
17
|
unless /^(true|false|off)$/ =~ xml_node.at_xpath('active').content then
|
|
18
|
-
module_definition[:warnings] = [
|
|
18
|
+
module_definition[:warnings] = []
|
|
19
|
+
module_definition[:warnings] << { :message => "value for active element should be in ['true','false','off'] (element: #{xml_node.at_xpath('active')})" }
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
unless /^(core|community|local)$/ =~ xml_node.at_xpath('codePool').content then
|
|
22
|
-
module_definition[:warnings]
|
|
23
|
+
module_definition[:warnings] ||= []
|
|
24
|
+
module_definition[:warnings] << { :message => "value for codePool element should be in ['core','community','local'] (element: #{xml_node.at_xpath('codePool')})" }
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
module_definition
|
|
@@ -30,7 +32,17 @@ module Maruto::ModuleDefinition
|
|
|
30
32
|
doc = Nokogiri::XML(f) { |config| config.strict }
|
|
31
33
|
f.close
|
|
32
34
|
|
|
33
|
-
doc.xpath('//modules/*').map { |xml_node| self.parse_module_definition(xml_node).merge({:defined => path}) }
|
|
35
|
+
modules = doc.xpath('//modules/*').map { |xml_node| self.parse_module_definition(xml_node).merge({:defined => path}) }
|
|
36
|
+
|
|
37
|
+
modules.each do |m|
|
|
38
|
+
if m.include? :warnings then
|
|
39
|
+
m[:warnings].each do |w|
|
|
40
|
+
w[:file] = path
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
modules
|
|
34
46
|
end
|
|
35
47
|
|
|
36
48
|
def self.parse_all_module_definitions()
|
|
@@ -62,19 +74,19 @@ module Maruto::ModuleDefinition
|
|
|
62
74
|
# disable first module
|
|
63
75
|
h[mod_name][:active] = false
|
|
64
76
|
m[:warnings] ||= []
|
|
65
|
-
m[:warnings] <<
|
|
77
|
+
m[:warnings] << { :file => m[:defined], :message => "duplicate module definition (in '#{h[mod_name][:defined]}' and '#{m[:defined]}')" }
|
|
66
78
|
end
|
|
67
79
|
parts = mod_name.to_s.split('_')
|
|
68
80
|
h[mod_name] = m
|
|
69
81
|
if parts.size != 2
|
|
70
82
|
m[:warnings] ||= []
|
|
71
|
-
m[:warnings] <<
|
|
83
|
+
m[:warnings] << { :file => m[:defined], :message => "invalid module name" }
|
|
72
84
|
m[:active] = false
|
|
73
85
|
else
|
|
74
86
|
m[:config_path] = "app/code/#{m[:code_pool]}/#{parts[0]}/#{parts[1]}/etc/config.xml"
|
|
75
87
|
if !File.exists?(m[:config_path])
|
|
76
88
|
m[:warnings] ||= []
|
|
77
|
-
m[:warnings]<< "config.xml is missing (searching '#{m[:config_path]}' for #{m[:name]}
|
|
89
|
+
m[:warnings]<< { :file => m[:defined], :message => "config.xml is missing (searching '#{m[:config_path]}' for #{m[:name]})" }
|
|
78
90
|
m[:active] = false
|
|
79
91
|
end
|
|
80
92
|
end
|
|
@@ -92,13 +104,13 @@ module Maruto::ModuleDefinition
|
|
|
92
104
|
m[:dependencies] = dependencies.keys
|
|
93
105
|
if duplicates.size > 0
|
|
94
106
|
m[:warnings] ||= []
|
|
95
|
-
m[:warnings] << "duplicate dependencies (#{duplicates.join(', ')})
|
|
107
|
+
m[:warnings] << { :file => m[:defined], :message => "duplicate dependencies (#{duplicates.join(', ')})" }
|
|
96
108
|
end
|
|
97
|
-
m[:dependencies].
|
|
109
|
+
m[:dependencies].delete_if do |d|
|
|
98
110
|
unless h.include? d
|
|
99
|
-
m[:dependencies].delete d
|
|
100
111
|
m[:warnings] ||= []
|
|
101
|
-
m[:warnings] << "missing dependency: '#{d}'
|
|
112
|
+
m[:warnings] << { :file => m[:defined], :message => "missing dependency: '#{d}'" }
|
|
113
|
+
true
|
|
102
114
|
end
|
|
103
115
|
end
|
|
104
116
|
end
|
data/lib/maruto/runner.rb
CHANGED
|
@@ -6,6 +6,13 @@ require 'thor'
|
|
|
6
6
|
class Maruto::Runner < Thor
|
|
7
7
|
include Thor::Actions
|
|
8
8
|
|
|
9
|
+
map "-v" => :version, "--version" => :version
|
|
10
|
+
|
|
11
|
+
desc "version", "Show Maruto version"
|
|
12
|
+
def version
|
|
13
|
+
say "Maruto #{Maruto::VERSION}"
|
|
14
|
+
end
|
|
15
|
+
|
|
9
16
|
desc "magento?", "check if MAGENTO_ROOT contains a magento app"
|
|
10
17
|
method_option :magento_root, :aliases => "-m", :default => "."
|
|
11
18
|
def magento?()
|
|
@@ -45,9 +52,12 @@ class Maruto::Runner < Thor
|
|
|
45
52
|
|
|
46
53
|
# next gen maruto:
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
puts "
|
|
55
|
+
all_warnings = Maruto::warnings magento_root
|
|
56
|
+
all_warnings.group_by { |e| e[:module] }.each do |m,module_warnings|
|
|
57
|
+
puts "[module:#{m}]"
|
|
58
|
+
module_warnings.each do |w|
|
|
59
|
+
puts " [file:#{w[:file]}] #{w[:message]}"
|
|
60
|
+
end
|
|
51
61
|
end
|
|
52
62
|
|
|
53
63
|
end
|
|
@@ -91,10 +101,10 @@ class Maruto::Runner < Thor
|
|
|
91
101
|
raise Thor::Error, "not a folder: #{magento_root}" unless magento_root.directory?
|
|
92
102
|
|
|
93
103
|
is_magento = (magento_root + 'app').directory? &&
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
(magento_root + 'app/code').directory? &&
|
|
105
|
+
(magento_root + 'app/etc').directory? &&
|
|
106
|
+
(magento_root + 'app/etc/modules').directory? &&
|
|
107
|
+
(magento_root + 'app/etc/local.xml').file?
|
|
98
108
|
raise Thor::Error, "could not find magento in this folder: #{magento_root.realpath}#{options[:magento_root] == '.' ? ' (try -m MAGENTO_ROOT)' : ''}" unless is_magento
|
|
99
109
|
|
|
100
110
|
return magento_root
|
data/lib/maruto/version.rb
CHANGED
|
@@ -97,6 +97,8 @@ describe Maruto::ModuleDefinition do
|
|
|
97
97
|
''').root)
|
|
98
98
|
h.must_include :active
|
|
99
99
|
h.must_include :warnings
|
|
100
|
+
h[:warnings].size.must_equal 1
|
|
101
|
+
h[:warnings][0].must_include :message
|
|
100
102
|
# any string that is not false or off => active
|
|
101
103
|
# TODO empty string => inactive (check in php)
|
|
102
104
|
h[:active].must_equal true
|
|
@@ -111,6 +113,8 @@ describe Maruto::ModuleDefinition do
|
|
|
111
113
|
</modname>
|
|
112
114
|
''').root)
|
|
113
115
|
h.must_include :warnings
|
|
116
|
+
h[:warnings].size.must_equal 1
|
|
117
|
+
h[:warnings][0].must_include :message
|
|
114
118
|
end
|
|
115
119
|
end
|
|
116
120
|
|
|
@@ -122,6 +126,25 @@ describe Maruto::ModuleDefinition do
|
|
|
122
126
|
a[0].must_include :name
|
|
123
127
|
a[0][:name].must_equal :Mage_Api
|
|
124
128
|
end
|
|
129
|
+
it "will return an Array of module definitions" do
|
|
130
|
+
a = Maruto::ModuleDefinition.parse_module_definition_file('app/etc/modules/Mage_Api.xml')
|
|
131
|
+
a.must_be_kind_of Array
|
|
132
|
+
a.size.must_equal 1
|
|
133
|
+
a[0].must_include :name
|
|
134
|
+
a[0][:name].must_equal :Mage_Api
|
|
135
|
+
end
|
|
136
|
+
it "will add the definition file path to all warnings" do
|
|
137
|
+
file = 'app/etc/modules/Bad_Example.xml'
|
|
138
|
+
a = Maruto::ModuleDefinition.parse_module_definition_file(file)
|
|
139
|
+
a.must_be_kind_of Array
|
|
140
|
+
a.size.must_equal 1
|
|
141
|
+
a[0].must_include :warnings
|
|
142
|
+
a[0][:warnings].size.wont_equal 0
|
|
143
|
+
a[0][:warnings].each do |w|
|
|
144
|
+
w.must_include :file
|
|
145
|
+
w[:file].must_equal file
|
|
146
|
+
end
|
|
147
|
+
end
|
|
125
148
|
it "will include the relative path to the file to the module definition" do
|
|
126
149
|
file = 'app/etc/modules/Mage_All.xml'
|
|
127
150
|
a = Maruto::ModuleDefinition.parse_module_definition_file(file)
|
|
@@ -171,6 +194,7 @@ describe Maruto::ModuleDefinition do
|
|
|
171
194
|
a,h = Maruto::ModuleDefinition.analyse_module_definitions(parsed_module_definitions)
|
|
172
195
|
h[:Mage_A][:dependencies].size.must_equal 1
|
|
173
196
|
h[:Mage_A][:warnings].size.must_equal 2
|
|
197
|
+
h[:Mage_A][:warnings][-1][:file].must_equal @module_a[:defined]
|
|
174
198
|
end
|
|
175
199
|
it "will remove duplicate dependencies and add a warning" do
|
|
176
200
|
parsed_module_definitions = [
|
|
@@ -181,6 +205,7 @@ describe Maruto::ModuleDefinition do
|
|
|
181
205
|
a,h = Maruto::ModuleDefinition.analyse_module_definitions(parsed_module_definitions)
|
|
182
206
|
h[:Mage_A][:dependencies].size.must_equal 2
|
|
183
207
|
h[:Mage_A][:warnings].size.must_equal 2
|
|
208
|
+
h[:Mage_A][:warnings][-1][:file].must_equal @module_a[:defined]
|
|
184
209
|
end
|
|
185
210
|
it "will deactivate modules with an invalid name and add a warning" do
|
|
186
211
|
parsed_module_definitions = [
|
|
@@ -189,7 +214,8 @@ describe Maruto::ModuleDefinition do
|
|
|
189
214
|
a,h = Maruto::ModuleDefinition.analyse_module_definitions(parsed_module_definitions)
|
|
190
215
|
parsed_module_definitions[0][:active].must_equal false
|
|
191
216
|
parsed_module_definitions[0][:warnings].size.must_equal 2
|
|
192
|
-
parsed_module_definitions[0][:warnings][-1].must_include "invalid module name"
|
|
217
|
+
parsed_module_definitions[0][:warnings][-1][:message].must_include "invalid module name"
|
|
218
|
+
parsed_module_definitions[0][:warnings][-1][:file].must_equal 'a'
|
|
193
219
|
end
|
|
194
220
|
it "will add the path to the module's config.xml" do
|
|
195
221
|
parsed_module_definitions = [
|
|
@@ -206,6 +232,7 @@ describe Maruto::ModuleDefinition do
|
|
|
206
232
|
a,h = Maruto::ModuleDefinition.analyse_module_definitions(parsed_module_definitions)
|
|
207
233
|
parsed_module_definitions[0][:active].must_equal false
|
|
208
234
|
parsed_module_definitions[0][:warnings].size.must_equal 2
|
|
235
|
+
parsed_module_definitions[0][:warnings][-1][:file].must_equal 'hello'
|
|
209
236
|
end
|
|
210
237
|
it "will sort the Array according to module dependencies" do
|
|
211
238
|
parsed_module_definitions = [
|
|
@@ -229,6 +256,7 @@ describe Maruto::ModuleDefinition do
|
|
|
229
256
|
a[0][:active].must_equal true
|
|
230
257
|
a[0][:defined].must_equal 'b'
|
|
231
258
|
a[0].must_include :warnings
|
|
259
|
+
a[0][:warnings][0][:file].must_equal 'b'
|
|
232
260
|
end
|
|
233
261
|
end
|
|
234
262
|
|
data/spec/module_version_spec.rb
CHANGED
|
@@ -4,66 +4,64 @@ require 'maruto/module_configuration'
|
|
|
4
4
|
|
|
5
5
|
module Maruto
|
|
6
6
|
|
|
7
|
-
describe
|
|
7
|
+
describe "when parsing a module config.xml and reading the module version" do
|
|
8
8
|
|
|
9
9
|
before do
|
|
10
10
|
@module_a = { :name => :Mage_A, :active => true, :code_pool => :core, :defined => 'a', :config_path => 'app/code/core/Mage/A/etc/config.xml' }
|
|
11
11
|
@module_b = { :name => :Mage_B, :active => true, :code_pool => :core, :defined => 'b', :config_path => 'app/code/core/Mage/B/etc/config.xml' }
|
|
12
12
|
@module_c = { :name => :Mage_C, :active => true, :code_pool => :core, :defined => 'c', :config_path => 'app/code/core/Mage/C/etc/config.xml' }
|
|
13
13
|
@module_d = { :name => :Mage_D, :active => true, :code_pool => :core, :defined => 'd', :config_path => 'app/code/core/Mage/D/etc/config.xml' }
|
|
14
|
+
@xml_config_root = Nokogiri::XML('''
|
|
15
|
+
<config><modules>
|
|
16
|
+
<Mage_A>
|
|
17
|
+
<version>0.0.1</version>
|
|
18
|
+
</Mage_A>
|
|
19
|
+
</modules></config>
|
|
20
|
+
''').root
|
|
14
21
|
end
|
|
15
22
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
<config><modules>
|
|
21
|
-
<Mage_A>
|
|
22
|
-
<version>0.0.1</version>
|
|
23
|
-
</Mage_A>
|
|
24
|
-
</modules></config>
|
|
25
|
-
''').root
|
|
26
|
-
end
|
|
27
|
-
it "will return the module definition hash" do
|
|
28
|
-
m = ModuleConfiguration.read_module_version(@module_a, @xml_config_root)
|
|
29
|
-
m.must_be_kind_of Hash
|
|
30
|
-
m.must_equal @module_a
|
|
31
|
-
end
|
|
32
|
-
it "will add the version to the hash" do
|
|
33
|
-
m = ModuleConfiguration.read_module_version(@module_a, @xml_config_root)
|
|
34
|
-
m.must_include :version
|
|
35
|
-
m[:version].must_equal '0.0.1'
|
|
36
|
-
end
|
|
37
|
-
it "will add a warning when then modules node is missing" do
|
|
38
|
-
w = @module_a.merge({ :warnings => ['first warning'] })
|
|
39
|
-
m = ModuleConfiguration.read_module_version(w, Nokogiri::XML('<config><a></a></config>').root)
|
|
40
|
-
m[:warnings].size.must_equal 2
|
|
41
|
-
m[:warnings][-1].must_include '<modules'
|
|
42
|
-
end
|
|
43
|
-
it "will add a warning when then node with the module's name is missing" do
|
|
44
|
-
w = @module_a.merge({ :warnings => ['first warning'] })
|
|
45
|
-
m = ModuleConfiguration.read_module_version(w, Nokogiri::XML('<config><modules></modules></config>').root)
|
|
46
|
-
m[:warnings].size.must_equal 2
|
|
47
|
-
m[:warnings][-1].must_include '<modules'
|
|
48
|
-
m[:warnings][-1].must_include '<Mage_A'
|
|
49
|
-
end
|
|
50
|
-
it "will add a warning when there is a node from a different module" do
|
|
51
|
-
xml_config_root = Nokogiri::XML('''
|
|
52
|
-
<config><modules>
|
|
53
|
-
<Mage_A>
|
|
54
|
-
<version>0.0.1</version>
|
|
55
|
-
</Mage_A>
|
|
56
|
-
<Mage_B>
|
|
57
|
-
<version>0.0.1</version>
|
|
58
|
-
</Mage_B>
|
|
59
|
-
</modules></config>
|
|
60
|
-
''').root
|
|
61
|
-
w = @module_a.merge({ :warnings => ['first warning'] })
|
|
62
|
-
m = ModuleConfiguration.read_module_version(w, xml_config_root)
|
|
63
|
-
m[:warnings].size.must_equal 2
|
|
64
|
-
m[:warnings][-1].must_include 'Mage_B'
|
|
65
|
-
end
|
|
66
|
-
end
|
|
23
|
+
it "will return the module definition hash" do
|
|
24
|
+
m = ModuleConfiguration.read_module_version(@module_a, @xml_config_root)
|
|
25
|
+
m.must_be_kind_of Hash
|
|
26
|
+
m.must_equal @module_a
|
|
67
27
|
end
|
|
28
|
+
it "will add the version to the hash" do
|
|
29
|
+
m = ModuleConfiguration.read_module_version(@module_a, @xml_config_root)
|
|
30
|
+
m.must_include :version
|
|
31
|
+
m[:version].must_equal '0.0.1'
|
|
32
|
+
end
|
|
33
|
+
it "will add a warning when then modules node is missing" do
|
|
34
|
+
w = @module_a.merge({ :warnings => ['first warning'] })
|
|
35
|
+
m = ModuleConfiguration.read_module_version(w, Nokogiri::XML('<config><a></a></config>').root)
|
|
36
|
+
m[:warnings].size.must_equal 2
|
|
37
|
+
m[:warnings][-1][:file].must_equal m[:config_path]
|
|
38
|
+
m[:warnings][-1][:message].must_include '/config/modules'
|
|
39
|
+
end
|
|
40
|
+
it "will add a warning when then node with the module's name is missing" do
|
|
41
|
+
w = @module_a.merge({ :warnings => ['first warning'] })
|
|
42
|
+
m = ModuleConfiguration.read_module_version(w, Nokogiri::XML('<config><modules></modules></config>').root)
|
|
43
|
+
m[:warnings].size.must_equal 2
|
|
44
|
+
m[:warnings][-1][:file].must_equal m[:config_path]
|
|
45
|
+
m[:warnings][-1][:message].must_include '/config/modules/Mage_A'
|
|
46
|
+
end
|
|
47
|
+
it "will add a warning when there is a node from a different module" do
|
|
48
|
+
xml_config_root = Nokogiri::XML('''
|
|
49
|
+
<config><modules>
|
|
50
|
+
<Mage_A>
|
|
51
|
+
<version>0.0.1</version>
|
|
52
|
+
</Mage_A>
|
|
53
|
+
<Mage_B>
|
|
54
|
+
<version>0.0.1</version>
|
|
55
|
+
</Mage_B>
|
|
56
|
+
</modules></config>
|
|
57
|
+
''').root
|
|
58
|
+
w = @module_a.merge({ :warnings => ['first warning'] })
|
|
59
|
+
m = ModuleConfiguration.read_module_version(w, xml_config_root)
|
|
60
|
+
m[:warnings].size.must_equal 2
|
|
61
|
+
m[:warnings][-1][:file].must_equal m[:config_path]
|
|
62
|
+
m[:warnings][-1][:message].must_include 'Mage_B'
|
|
63
|
+
end
|
|
64
|
+
|
|
68
65
|
end
|
|
66
|
+
|
|
69
67
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: maruto
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.5
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -111,6 +111,7 @@ files:
|
|
|
111
111
|
- fixtures/magento_root/app/code/core/Mage/B/etc/config.xml
|
|
112
112
|
- fixtures/magento_root/app/code/core/Mage/C/etc/config.xml
|
|
113
113
|
- fixtures/magento_root/app/code/core/Mage/D/etc/config.xml
|
|
114
|
+
- fixtures/magento_root/app/etc/modules/Bad_Example.xml
|
|
114
115
|
- fixtures/magento_root/app/etc/modules/Mage_All.xml
|
|
115
116
|
- fixtures/magento_root/app/etc/modules/Mage_Api.xml
|
|
116
117
|
- lib/maruto.rb
|