depgraph 0.11.0

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.
Files changed (44) hide show
  1. data/History.txt +28 -0
  2. data/License.txt +20 -0
  3. data/README.rdoc +40 -0
  4. data/Rakefile +31 -0
  5. data/VERSION +1 -0
  6. data/bin/depgraph +89 -0
  7. data/config/hoe.rb +71 -0
  8. data/config/requirements.rb +19 -0
  9. data/lib/DepGraph/version.rb +9 -0
  10. data/lib/dependency_types.yaml +11 -0
  11. data/lib/dependency_types_manager.rb +49 -0
  12. data/lib/file_system_node_finder.rb +64 -0
  13. data/lib/graph_creator.rb +122 -0
  14. data/lib/graph_image_creator.rb +125 -0
  15. data/lib/node.rb +44 -0
  16. data/lib/nodefinders/gems_node_finder.rb +58 -0
  17. data/lib/nodefinders/test_node_finder.rb +26 -0
  18. data/script/destroy +14 -0
  19. data/script/destroy.cmd +1 -0
  20. data/script/generate +14 -0
  21. data/script/generate.cmd +1 -0
  22. data/script/txt2html +74 -0
  23. data/script/txt2html.cmd +1 -0
  24. data/setup.rb +1585 -0
  25. data/spec/IntegrationTests/depgraph_spec.rb +90 -0
  26. data/spec/IntegrationTests/file_system_node_finder_spec.rb +54 -0
  27. data/spec/IntegrationTests/gems_node_finder_spec.rb +20 -0
  28. data/spec/IntegrationTests/graph_creator_spec.rb +30 -0
  29. data/spec/IntegrationTests/graph_image_creator_spec.rb +50 -0
  30. data/spec/UnitTests/dependency_types_manager_spec.rb +46 -0
  31. data/spec/UnitTests/file_system_node_finder_spec.rb +62 -0
  32. data/spec/UnitTests/graph_creator_spec.rb +140 -0
  33. data/spec/UnitTests/graph_image_creator_spec.rb +56 -0
  34. data/spec/UnitTests/node_spec.rb +45 -0
  35. data/spec/integration_spec.opts +4 -0
  36. data/spec/spec.opts +6 -0
  37. data/spec/spec_helper.rb +179 -0
  38. data/spec/unit_spec.opts +4 -0
  39. data/tasks/deployment.rake +34 -0
  40. data/tasks/environment.rake +7 -0
  41. data/tasks/rspec.rake +35 -0
  42. data/tasks/website.rake +17 -0
  43. data/todo.txt +4 -0
  44. metadata +128 -0
@@ -0,0 +1,28 @@
1
+ 0.10.1
2
+ * Applied patch DepGraph-fix_sorting_assumption.patch by Diego Algorta Casamayou
3
+ * Applied patch misleading_dependency_error_messages.patch by Trevor Fountain
4
+ * Fixed some bugs in the tests
5
+
6
+ 0.10.0
7
+ * Now you can create the dependency graph of all the installed gems.
8
+ * Fixed the missing dependencies to optiflag and ruby-graphviz to the deployed gem.
9
+
10
+ 0.9.0
11
+
12
+ * Added dynamic loading of node finders from directory lib/nodefinders.
13
+ Example:
14
+ see 'lib/nodefinders/TestNodeFinder.rb' which can be used like this:
15
+ depgraph -type test
16
+ * Added functionality to exclude the nodes the user is not interested in.
17
+ Example:
18
+ depgraph -type ruby_requires -exc "client, server"
19
+ * A transitive reduction can be applied to the graph.
20
+ Example:
21
+ depgraph -type csproj -trans
22
+ * Disconnected nodes don't show up anymore.
23
+ * The type of output can be selected by changing the file extension.
24
+ Example:
25
+ depgraph -type test -output test.dot
26
+ * Separated unit tests and integration tests in different folders.
27
+ * Renamed option -dirs to -location
28
+ * Some more refactorings.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 DepGraph - Daniel Cadenas Ni�n
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ = DepGraph
2
+
3
+ * http://depgraph.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ A Ruby tool to create dependency graph images from any kind of file
8
+
9
+ == REQUIREMENTS:
10
+
11
+ * Graphviz, ruby-graphviz and optiflag
12
+
13
+ == INSTALL:
14
+
15
+ * gem install dcadenas-DepGraph
16
+
17
+ == LICENSE:
18
+
19
+ (The MIT License)
20
+
21
+ Copyright (c) 2008 Daniel Cadenas
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining
24
+ a copy of this software and associated documentation files (the
25
+ 'Software'), to deal in the Software without restriction, including
26
+ without limitation the rights to use, copy, modify, merge, publish,
27
+ distribute, sublicense, and/or sell copies of the Software, and to
28
+ permit persons to whom the Software is furnished to do so, subject to
29
+ the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be
32
+ included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
37
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
38
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
39
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ spec = Gem::Specification.new do |s|
5
+ s.name = "depgraph"
6
+ s.summary = "A tool to create dependency graph images from source code directories"
7
+ s.description = "A tool to create dependency graph images from source code directories"
8
+ s.email = "dcadenas@gmail.com"
9
+ s.homepage = "http://github.com/dcadenas/depgraph"
10
+ s.authors = ["Daniel Cadenas"]
11
+ s.executables = ["depgraph"]
12
+
13
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
14
+ s.add_dependency(%q<ruby-graphviz>, ["~> 1.0.8"])
15
+ s.add_dependency(%q<optiflag>, [">= 0.6.5"])
16
+
17
+ s.version = File.read("VERSION")
18
+ s.files = `git ls-files`.split
19
+ end
20
+
21
+ require 'rake/extensiontask'
22
+ Gem::PackageTask.new(spec) do |pkg|
23
+ end
24
+
25
+ require 'rspec/core/rake_task'
26
+ RSpec::Core::RakeTask.new(:spec) do |t|
27
+ t.rspec_opts = ["-f progress", "-r ./spec/spec_helper.rb"]
28
+ t.pattern = 'spec/**/*_spec.rb'
29
+ end
30
+
31
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.11.0
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2008-3-9.
4
+ # Copyright (c) 2008. Daniel Cadenas. All rights reserved.
5
+ # http://depgraph.rubyforge.org
6
+
7
+ begin
8
+ require 'rubygems'
9
+ gem 'optiflag'
10
+ require 'optiflag'
11
+ rescue LoadError
12
+ puts "depgraph requires the optiflag RubyGem."
13
+ puts "Installation: gem install optiflag -y"
14
+ exit
15
+ end
16
+
17
+ begin
18
+ gem 'ruby-graphviz'
19
+ require 'graphviz'
20
+ rescue LoadError
21
+ puts "depgraph requires the ruby-graphviz."
22
+ puts "Installation: gem install ruby-graphviz"
23
+ exit
24
+ end
25
+
26
+ $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
27
+
28
+ require 'graph_creator'
29
+
30
+
31
+ module CommandLineParameters extend OptiFlagSet
32
+ flag "type" do
33
+ dependency_types = DepGraph::GraphCreator.types
34
+ description "Type of dependencies to analyze: #{dependency_types.join(', ')}"
35
+ value_in_set dependency_types
36
+ end
37
+
38
+ optional_flag "exc" do
39
+ description "The node names to be excluded.\nUse double quotes and commas for multiple nodes."
40
+ end
41
+
42
+ optional_flag "output" do
43
+ description "The file name of the graph image."
44
+ end
45
+
46
+ optional_flag "from" do
47
+ description "Regular expression that must be met by the dependency source."
48
+ end
49
+
50
+ optional_flag "to" do
51
+ description "Regular expression that must be met by the dependency target."
52
+ end
53
+
54
+ optional_flag "location" do
55
+ description "A string defining the place where the nodes to analyse are found.\nThis are directories for most dependency types.\n
56
+ Use double quotes and commas for more than one directory."
57
+ end
58
+
59
+ optional_switch_flag "trans" do
60
+ description "Applies a transitive reduction to the graph"
61
+ end
62
+
63
+ usage_flag "h","help","?"
64
+
65
+ and_process!
66
+ end
67
+
68
+ type = CommandLineParameters.flags.type
69
+ output = CommandLineParameters.flags.output || 'dependency_graph.png'
70
+ location = CommandLineParameters.flags.location
71
+ from = CommandLineParameters.flags.from if CommandLineParameters.flags.from?
72
+ to = CommandLineParameters.flags.to if CommandLineParameters.flags.to?
73
+ exc = CommandLineParameters.flags.exc || ''
74
+ trans = CommandLineParameters.flags.trans?
75
+
76
+ puts "Creating #{type} dependency graph. Please wait..."
77
+
78
+ dep_grapher = DepGraph::GraphCreator.new(type)
79
+ dep_grapher.location = location.split(',') if location
80
+ dep_grapher.from = from
81
+ dep_grapher.to = to
82
+ dep_grapher.trans = trans
83
+ dep_grapher.excluded_nodes = exc.split(',')
84
+
85
+ if dep_grapher.create_image(output)
86
+ puts "Done.\nResults in #{output}."
87
+ else
88
+ puts "No dependency graph image created."
89
+ end
@@ -0,0 +1,71 @@
1
+ require 'DepGraph/version'
2
+
3
+ AUTHOR = 'Daniel Cadenas Ni�n' # can also be an array of Authors
4
+ EMAIL = "dcadenas@gmail.com"
5
+ DESCRIPTION = "A tool to create dependency graph images from source code directories"
6
+ GEM_NAME = 'DepGraph' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'DepGraph' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT.downcase}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "dcadenas"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = DepGraph::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'DepGraph documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.developer(AUTHOR, EMAIL)
52
+ p.description = DESCRIPTION
53
+ p.summary = DESCRIPTION
54
+ p.url = HOMEPATH
55
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
+ p.test_globs = ["spec/**/*.rb"]
57
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
+
59
+ # == Optional
60
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
+ p.extra_deps = [['ruby-graphviz', '>=0.8.0'], ['optiflag', '>=0.6.5']]
63
+
64
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
+
66
+ end
67
+
68
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
70
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
71
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,19 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen filetesthelper spec optiflag graphviz rcov].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ req_gem = 'rspec' if req_gem == 'spec'
10
+ req_gem = 'ruby-graphviz' if req_gem == 'graphviz'
11
+
12
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
13
+ puts "Installation: gem install #{req_gem} -y"
14
+ exit
15
+ end
16
+ end
17
+
18
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
19
+
@@ -0,0 +1,9 @@
1
+ module DepGraph #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 10
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ ---
2
+ csproj:
3
+ file_name_pattern: "*.csproj"
4
+ dependable_regexp: !ruby/regexp /"([^"]*\\)?([^\\"]+?)\.(csproj|dll)"/
5
+ capture_group_index: 1
6
+ ruby_requires:
7
+ file_name_pattern: "*.rb"
8
+ dependable_regexp: !ruby/regexp /[\s]*require[\s]+["'](.*\/)?([^\s\/]+?)(\.rb)?["']/
9
+ capture_group_index: 1
10
+
11
+
@@ -0,0 +1,49 @@
1
+ require 'yaml'
2
+
3
+ module DepGraph
4
+ class DependencyTypesManager
5
+ def self.dependency_types_file
6
+ File.join(File.dirname(__FILE__), 'dependency_types.yaml')
7
+ end
8
+
9
+ begin
10
+ @@dependable_dependency_types = YAML.load_file(dependency_types_file)
11
+ rescue => e
12
+ fail "Could not load file #{dependency_types_file}: #{e.message}"
13
+ end
14
+
15
+ def self.types
16
+ @@dependable_dependency_types.map {|type, _| type.to_sym}
17
+ end
18
+
19
+ def initialize(node_type = :anything)
20
+ @node_type = node_type.to_s
21
+ end
22
+
23
+ def dependable_regexp
24
+ get_node_type_parameters(@node_type)['dependable_regexp']
25
+ end
26
+
27
+ def dependable_regexp_capture_group_index
28
+ get_node_type_parameters(@node_type)['capture_group_index']
29
+ end
30
+
31
+ def file_name_pattern
32
+ get_node_type_parameters(@node_type)['file_name_pattern']
33
+ end
34
+
35
+ def get_node_type_parameters(node_type)
36
+ node_type_parameters = @@dependable_dependency_types[node_type]
37
+
38
+ if node_type_parameters
39
+ return node_type_parameters
40
+ else
41
+ return default_parameters = {
42
+ 'dependable_regexp' => /.+/,
43
+ 'capture_group_index' => 0,
44
+ 'file_name_pattern' => '*'
45
+ }
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,64 @@
1
+ require 'node'
2
+ require 'dependency_types_manager'
3
+
4
+ module DepGraph
5
+ class FileSystemNodeFinder
6
+ attr_accessor :dependable_filter, :dependable_filter_capture_group_index, :file_name_pattern
7
+ attr_writer :location
8
+
9
+ def initialize(node_type)
10
+
11
+ dependable_filter_manager = DependencyTypesManager.new node_type
12
+ @file_name_pattern = dependable_filter_manager.file_name_pattern
13
+ @dependable_filter = dependable_filter_manager.dependable_regexp
14
+ @dependable_filter_capture_group_index = dependable_filter_manager.dependable_regexp_capture_group_index
15
+ @location = ['.']
16
+ end
17
+
18
+ def location=(locs)
19
+ if locs
20
+ @location = locs.map {|d| d.strip}
21
+ else
22
+ @location = ['.']
23
+ end
24
+ end
25
+
26
+ def get_nodes
27
+ files = []
28
+ @location.each do |dir|
29
+ files += Dir.glob(dir.strip + '/**/' + @file_name_pattern)
30
+ end
31
+
32
+ nodes = []
33
+ files.each { |file| nodes << create_node_from_file(file) }
34
+ return nodes
35
+ end
36
+
37
+ def load_dependencies_from_string(node, dependencies_string)
38
+ fail 'The dependable finder Regexp was not set' unless @dependable_filter
39
+
40
+ dependencies_string.scan(@dependable_filter).each do |matches|
41
+ dependable = (matches.respond_to? :to_ary) ? matches[@dependable_filter_capture_group_index] : matches
42
+ node.depends_on(dependable) unless node.depends_on? dependable
43
+ end
44
+ end
45
+
46
+ private
47
+ def create_node_from_file file
48
+ node = Node.new remove_extension(file)
49
+
50
+ File.open(file) do |f|
51
+ f.each_line do |line|
52
+ load_dependencies_from_string(node, line)
53
+ end
54
+ end
55
+
56
+ return node
57
+ end
58
+
59
+ def remove_extension file_path
60
+ file_extension_regexp = /\.[^\.]+$/
61
+ return File.basename(file_path).gsub(file_extension_regexp, '')
62
+ end
63
+ end
64
+ end