Merge pull request #41 from blackducksw/ubuntu_14
[ohcount] / ruby / gestalt / rules / csproj_parser.rb
1 #!/usr/bin/env ruby
2 require 'rexml/document'
3 require 'rexml/streamlistener'
4
5 class CsprojListener
6         include REXML::StreamListener
7
8         attr_accessor :callback
9         def initialize(callback)
10                 @callback = callback
11                 @is_csproj_file = false
12         end
13
14         def tag_start(name, attrs)
15                 case name
16                 when 'Project'
17                         @is_csproj_file = true
18                         if attrs['xmlns'] and attrs['xmlns'] !~ /^http:\/\/schemas\.microsoft\.com\/developer\//
19                                 # False alarm -- it contains a project element, but of another namespace
20                                 @is_csproj_file = false
21                         end
22                 when 'Import'
23                         if @is_csproj_file && attrs['Project']
24                                 @callback.call(attrs['Project'])
25                         end
26                 end
27         end
28 end