-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.go
63 lines (53 loc) · 1.38 KB
/
project.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package sln
import (
"fmt"
"path"
"strings"
"github.com/atakanozceviz/vsdep/graph"
)
// Project hold information about a Visual Studio Project
type Project struct {
Name string
Path string
Sln string
*Csproj
}
var g = graph.NewGraph()
// createGraph creates dependency graph for project.
func (project *Project) createGraph() error {
g.AddNode(project.Name)
for _, ig := range project.Csproj.ItemGroups {
for _, pr := range ig.ProjectReferences {
csprojFilePath := strings.Replace(path.Join(path.Dir(project.Path), pr.Include), "\\", "/", -1)
csproj, err := parseCsproj(csprojFilePath)
if err != nil {
err = fmt.Errorf("cannot parse csproj file referenced in %s: %v", project.Path, err)
return err
}
fileName := path.Base(strings.Replace(pr.Include, "\\", "/", -1))
fileNameNoExt := strings.Replace(fileName, path.Ext(fileName), "", -1)
dep := &Project{
Name: fileNameNoExt,
Path: csprojFilePath,
Csproj: csproj,
}
if project.Name == "" || dep.Name == "" {
continue
}
g.AddEdge(project.Name, dep.Name)
dep.createGraph()
}
}
return nil
}
// IsTest return true if project is a test project, if not return false.
func (project *Project) IsTest() bool {
for _, ig := range project.ItemGroups {
for _, pr := range ig.PackageReferences {
if pr.Include == "Microsoft.NET.Test.Sdk" {
return true
}
}
}
return false
}