Class: VSFile_Reader
- Inherits:
-
Object
- Object
- VSFile_Reader
- Defined in:
- lib/vsfile_reader.rb
Class Method Summary collapse
-
.read_proj(path) ⇒ Object
get a list of dependencies for the given project.
-
.read_sln(path) ⇒ Object
get a list of projects from the solution file.
Class Method Details
.read_proj(path) ⇒ Object
get a list of dependencies for the given project
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vsfile_reader.rb', line 24 def self.read_proj(path) dependencies = [] begin file = File.open(path) { |f| f.read } rescue return dependencies end document = REXML::Document.new(file) # find external dependencies document.elements.each('//Project/ItemGroup/Reference') do |element| include = element.attributes["Include"] items = include.split(',') dependencies << items[0] end # find project dependencies document.elements.each('//Project/ItemGroup/ProjectReference') do |element| dep_path = File.absolute_path(File.join(File.dirname(path), element.attributes["Include"])) name = "" element.elements.each('Name') do |e| name = e.text end id = "" element.elements.each('Project') do |e| id = e.text end proj = Project.new(id, name, dep_path) dependencies << proj end return dependencies end |
.read_sln(path) ⇒ Object
get a list of projects from the solution file
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/vsfile_reader.rb', line 6 def self.read_sln(path) lines = [] projects = [] file = File.open(path) { |f| f.read } file.each_line do |line| match_data = line.match(/^\s*Project\s*\(\s*\"\{[A-F0-9\-]{36}\}\"\s*\)\s*=\s*\"(\S+)\"\s*,\s*\"(.*\.(vcproj|csproj))\"\s*,\s*\"\{([A-F0-9\-]{36})\}\"\s*$/i) if not match_data.nil? proj = Project.new(match_data[4], match_data[1], File.join(File.dirname(path), match_data[2])) projects << proj end end if projects.empty? raise "No projects found." end return projects end |