Class: VSFile_Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/vsfile_reader.rb

Class Method Summary collapse

Class Method Details

.read_proj(path) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vsfile_reader.rb', line 22

def self.read_proj(path)
	dependencies = []
	file = File.open(path) { |f| f.read }
	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|
		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, path)
		dependencies << proj
	end
	return dependencies
end

.read_sln(path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vsfile_reader.rb', line 5

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], match_data[2])
			projects << proj
		end
	end
	if projects.empty?
		raise "No projects found."
	end
	return projects
end