-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsfprojparser.go
More file actions
88 lines (73 loc) · 1.78 KB
/
Copy pathsfprojparser.go
File metadata and controls
88 lines (73 loc) · 1.78 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"bufio"
"fmt"
"os"
"path/filepath"
"gopkg.in/xmlpath.v2"
)
// SfApp ..
type SfApp struct {
services []SfService
applicationName string
appManifestFile string
}
// SfService ..
type SfService struct {
projectFolder string
}
// Init ..
func (app *SfApp) Init(filePath string) {
path := xmlpath.MustCompile("//ProjectReference/@Include")
file, err := os.Open(filePath)
if err != nil {
errMsg := fmt.Sprintf("Unable to open %s for reading", filePath)
Exit(errMsg)
}
defer file.Close()
reader := bufio.NewReader(file)
root, err := xmlpath.Parse(reader)
if err != nil {
Exit("Oh no")
}
basePath := filepath.Dir(filePath)
iter := path.Iter(root)
for iter.Next() == true {
foundPath := iter.Node().String()
joined := filepath.Join(basePath, foundPath)
var fullPath string
fullPath, err = filepath.Abs(joined)
if err != nil {
Exit("Woops")
}
service := SfService{
projectFolder: filepath.Dir(fullPath),
}
app.services = append(app.services, service)
}
var appManifest string
ignoreDirs := []string{"bin", "obj", "pkg", "Backup"}
err = filepath.Walk(basePath, FindFile(ignoreDirs, "ApplicationManifest.xml", &appManifest))
if err != nil {
Exit("Something went wrong looking for application manifests")
}
app.appManifestFile = appManifest
}
// ReadManifest ..
func (app *SfApp) ReadManifest() {
path := xmlpath.MustCompile("//ApplicationManifest/@ApplicationTypeName")
file, err := os.Open(app.appManifestFile)
if err != nil {
errMsg := fmt.Sprintf("Unable to open %s for reading", app.appManifestFile)
Exit(errMsg)
}
defer file.Close()
reader := bufio.NewReader(file)
root, err := xmlpath.Parse(reader)
if err != nil {
Exit("Oh no")
}
if appName, ok := path.String(root); ok {
app.applicationName = appName
}
}