dependencytree 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/dependencytree.rb +14 -8
- data/lib/dependencytree/classcontainer.rb +10 -10
- data/lib/dependencytree/dependencyaggregator.rb +10 -10
- data/lib/dependencytree/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 312303a55740261be4a06ec055cf892eb61233e1
|
4
|
+
data.tar.gz: 865dc710ec4a18c399c3968259620b8cfc6ed4b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8b26ca2d7907e98945f34af9258561731a31ad46202b7abf4e29d43ddccac7e59d7314112a3c014bdeea51bbf42c4a8e5c08e37e3c294eddde335a2ffccf809
|
7
|
+
data.tar.gz: 395217483dbb38fc3160f0e5cda906aaa5c9971b36beb44326b7632f484c64ec83d7a7669b2b07bc975618cc1b7ed1d2ce63d41e83cde69404d3b2c2be8091ce
|
data/README.md
CHANGED
@@ -26,6 +26,7 @@ An example call would look like this:
|
|
26
26
|
The following is a list of possible command line options:
|
27
27
|
|
28
28
|
-v, --verbose Verbose output
|
29
|
+
-d, --debug Log debugging output to file 'dependencytree.log'
|
29
30
|
-p, --pattern[=OPTIONAL] Pattern to accept source codes with (default: (?-mix:.*\.rb))
|
30
31
|
-i, --ignore[=OPTIONAL] Paths to not load (default: (?-mix:^$))
|
31
32
|
-o, --output[=OPTIONAL] Output path for the JSON file
|
data/lib/dependencytree.rb
CHANGED
@@ -23,34 +23,31 @@ module Dependencytree
|
|
23
23
|
}
|
24
24
|
elsif File.file?(path)
|
25
25
|
STDERR.puts path if options[:verbose]
|
26
|
-
|
26
|
+
LOG.debug("Handling path #{path}")
|
27
27
|
tree = Parser::CurrentRuby.parse_file(path)
|
28
|
-
|
28
|
+
LOG.debug("Parsed tree: #{tree}") if LOG.debug?
|
29
29
|
consumer.visit(path, tree)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
$LOG = Logger.new('application.log', 'daily', 20)
|
34
|
-
|
35
33
|
options = {}
|
36
34
|
options[:ignore] = /^$/
|
37
35
|
options[:pattern] = /.*\.rb/
|
38
36
|
OptionParser.new do |opt|
|
39
37
|
opt.on("-v", "--verbose", "Verbose output") do |o|
|
40
38
|
options[:verbose] = true
|
41
|
-
|
39
|
+
end
|
40
|
+
opt.on("-d", "--debug", "Log debugging output to file 'dependencytree.log'") do |o|
|
41
|
+
options[:debug] = true
|
42
42
|
end
|
43
43
|
opt.on("-p", "--pattern[=OPTIONAL]", "Pattern to accept source codes with (default: #{options[:pattern].to_s})") do |o|
|
44
44
|
options[:pattern] = /#{o}/
|
45
|
-
$LOG.debug("pattern = #{o}")
|
46
45
|
end
|
47
46
|
opt.on("-i", "--ignore[=OPTIONAL]", "Paths to not load (default: #{options[:ignore].to_s})") do |o|
|
48
47
|
options[:ignore] = /#{o}/
|
49
|
-
$LOG.debug("ignore = #{o}")
|
50
48
|
end
|
51
49
|
opt.on("-o", "--output[=OPTIONAL]", "Output path for the JSON file") do |o|
|
52
50
|
options[:output] = o
|
53
|
-
$LOG.debug("output = #{o}")
|
54
51
|
end
|
55
52
|
opt.on_tail("-h", "--help", "Show this message") do
|
56
53
|
puts opt
|
@@ -58,6 +55,15 @@ module Dependencytree
|
|
58
55
|
end
|
59
56
|
end.parse!
|
60
57
|
|
58
|
+
if options[:debug]
|
59
|
+
log = Logger.new('dependencytree.log')
|
60
|
+
log.level = Logger::WARN
|
61
|
+
else
|
62
|
+
log = Logger.new(STDOUT)
|
63
|
+
log.level = Logger::WARN
|
64
|
+
end
|
65
|
+
LOG = log
|
66
|
+
|
61
67
|
consumer = DependencyAggregator.new
|
62
68
|
ARGV.each do |path|
|
63
69
|
handle_path(options, consumer, File.absolute_path(path))
|
@@ -20,7 +20,7 @@ module Dependencytree
|
|
20
20
|
# Goes thru all classes and tries to resolve the references.
|
21
21
|
def resolve_references
|
22
22
|
@classes_and_modules.each do |clazz|
|
23
|
-
|
23
|
+
LOG.debug("Processing class #{clazz.full_name} located in #{clazz.path}")
|
24
24
|
clazz.references.each do |reference_array|
|
25
25
|
refered_class = resolve_reference(clazz, reference_array)
|
26
26
|
if refered_class
|
@@ -43,9 +43,9 @@ module Dependencytree
|
|
43
43
|
end
|
44
44
|
|
45
45
|
if refered_class_model
|
46
|
-
|
46
|
+
LOG.debug("Resolved #{reference_array.join('::')} to uuid #{refered_class_model.uuid}")
|
47
47
|
else
|
48
|
-
|
48
|
+
LOG.debug("Could not resolve #{reference_array.join('::')}")
|
49
49
|
end
|
50
50
|
refered_class_model
|
51
51
|
end
|
@@ -59,16 +59,16 @@ module Dependencytree
|
|
59
59
|
reference_part = reference_array[0..-2]
|
60
60
|
constant_name = reference_array[-1]
|
61
61
|
|
62
|
-
|
62
|
+
LOG.debug("Resolving reference array #{reference_array.to_s} as reference #{reference_part.to_s} and constant #{constant_name}")
|
63
63
|
|
64
64
|
refered_class_model = resolve_reference_direct(referer_class_model, reference_part)
|
65
65
|
if refered_class_model
|
66
|
-
|
66
|
+
LOG.debug("Found reference to possible parent #{reference_part.to_s}")
|
67
67
|
if refered_class_model.constant_names.include? constant_name.to_sym
|
68
|
-
|
68
|
+
LOG.debug("Found class #{refered_class_model.full_name} constant #{constant_name}")
|
69
69
|
refered_class_model
|
70
70
|
else
|
71
|
-
|
71
|
+
LOG.debug("Found class #{refered_class_model.full_name}, but not constant #{constant_name}. Known constants: #{refered_class_model.constant_names}")
|
72
72
|
nil
|
73
73
|
end
|
74
74
|
else
|
@@ -81,15 +81,15 @@ module Dependencytree
|
|
81
81
|
# @param reference_array the reference as in the source, can be absolute or relative to the referer class.
|
82
82
|
# @return the refered class model or nil
|
83
83
|
def resolve_reference_direct(referer_class_model, reference_array)
|
84
|
-
|
84
|
+
LOG.debug("Resolving reference array #{reference_array.to_s}")
|
85
85
|
|
86
86
|
referer_array = referer_class_model.full_name_array
|
87
87
|
i = 0
|
88
88
|
refered_class_model = nil
|
89
89
|
while !refered_class_model do
|
90
|
-
|
90
|
+
LOG.debug("Referer array #{i} is #{referer_array.to_s}")
|
91
91
|
full_name = (referer_array+reference_array).join("::")
|
92
|
-
|
92
|
+
LOG.debug("Full name #{i} is #{full_name} #{full_name.class.name}")
|
93
93
|
refered_class_model = resolve_by_full_name(full_name)
|
94
94
|
|
95
95
|
break if referer_array.empty?
|
@@ -50,14 +50,14 @@ module Dependencytree
|
|
50
50
|
# Handle a const expression.
|
51
51
|
# @param node the const node itself to handle.
|
52
52
|
def _const(node)
|
53
|
-
|
53
|
+
LOG.debug("const")
|
54
54
|
|
55
55
|
raise ArgumentError, "type needs to be const (#{node.type})" if node.type != :const
|
56
56
|
raise ArgumentError, "Children count needs to be 2 (#{node.children.length})" if node.children.length != 2
|
57
57
|
|
58
58
|
reference = flatten_const_tree(node)
|
59
59
|
|
60
|
-
|
60
|
+
LOG.debug("Reference to #{reference.to_s}")
|
61
61
|
top_of_stack.add_reference(reference)
|
62
62
|
end
|
63
63
|
|
@@ -67,7 +67,7 @@ module Dependencytree
|
|
67
67
|
raise ArgumentError, "Children count for module is != 2 (#{node.children.length})" if node.children.length != 2
|
68
68
|
raise ArgumentError, "First module child needs to be a const (#{node.children[0].type} #{node.children[0].type})" if node.children[0].type != :const
|
69
69
|
|
70
|
-
|
70
|
+
LOG.debug("module #{node.children[0].children[1]}")
|
71
71
|
|
72
72
|
current_module_name = node.children[0].children[1]
|
73
73
|
_handle_class_module_common(:module, current_module_name, node)
|
@@ -78,7 +78,7 @@ module Dependencytree
|
|
78
78
|
def _class(node)
|
79
79
|
raise ArgumentError, "Children count for class is != 3 (#{node.children.length})" if node.children.length != 3
|
80
80
|
raise ArgumentError, "First class child needs to be a const (#{node.children[0].type} #{node.children[0].type})" if node.children[0].type != :const
|
81
|
-
|
81
|
+
LOG.debug("class #{node.children[0].children[1]}")
|
82
82
|
|
83
83
|
current_class_name = node.children[0].children[1]
|
84
84
|
_handle_class_module_common(:class, current_class_name, node)
|
@@ -95,7 +95,7 @@ module Dependencytree
|
|
95
95
|
parent = @context_stack[-1]
|
96
96
|
full_name = parent.full_name.to_s + "::" + name.to_s
|
97
97
|
end
|
98
|
-
|
98
|
+
LOG.debug("Full name is #{full_name}")
|
99
99
|
resolved = _resolve(full_name)
|
100
100
|
|
101
101
|
if ! resolved.nil?
|
@@ -111,7 +111,7 @@ module Dependencytree
|
|
111
111
|
end
|
112
112
|
|
113
113
|
if resolved.nil?
|
114
|
-
|
114
|
+
LOG.debug("Created new ClassModel for #{model.full_name}")
|
115
115
|
end
|
116
116
|
|
117
117
|
@context_stack << model
|
@@ -125,7 +125,7 @@ module Dependencytree
|
|
125
125
|
def _def(node)
|
126
126
|
raise ArgumentError, "Children count for def is != 3 (#{node.children.length})" if node.children.length != 3
|
127
127
|
|
128
|
-
|
128
|
+
LOG.debug("def #{node.children[0]}")
|
129
129
|
|
130
130
|
top_of_stack.add_method(node.children[0])
|
131
131
|
|
@@ -137,7 +137,7 @@ module Dependencytree
|
|
137
137
|
def _casgn(node)
|
138
138
|
raise ArgumentError, "Children count for casgn is != 3 (#{node.children.length})" if node.children.length != 3
|
139
139
|
|
140
|
-
|
140
|
+
LOG.debug("casgn #{node.children[1]}")
|
141
141
|
|
142
142
|
top_of_stack.add_constant(node.children[1])
|
143
143
|
|
@@ -177,12 +177,12 @@ module Dependencytree
|
|
177
177
|
# @param tree the AST tree node.
|
178
178
|
def visit(path, tree)
|
179
179
|
begin
|
180
|
-
|
180
|
+
LOG.debug("Visiting path #{path}")
|
181
181
|
@path = path
|
182
182
|
visit_node(tree)
|
183
183
|
@path = nil
|
184
184
|
rescue Exception => e
|
185
|
-
|
185
|
+
LOG.error("Error in path #{path}")
|
186
186
|
puts "Error in path #{path}"
|
187
187
|
raise e
|
188
188
|
end
|