github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/buildtools/dotnet/nuspec.go (about) 1 package dotnet 2 3 import ( 4 "github.com/fossas/fossa-cli/files" 5 "github.com/fossas/fossa-cli/graph" 6 "github.com/fossas/fossa-cli/pkg" 7 ) 8 9 type NuSpec struct { 10 Metadata Metadata `xml:"metadata"` 11 } 12 13 type Metadata struct { 14 ID string `xml:"id"` 15 Version string `xml:"version"` 16 Dependencies Dependencies `xml:"dependencies"` 17 } 18 19 type Dependencies struct { 20 Groups []Group `xml:"group"` 21 } 22 23 type Group struct { 24 Dependencies []Dependency `xml:"dependency"` 25 } 26 27 type Dependency struct { 28 ID string `xml:"id,attr"` 29 Version string `xml:"version,attr"` 30 } 31 32 func NuspecGraph(file string) (graph.Deps, error) { 33 var nuspec NuSpec 34 err := files.ReadXML(&nuspec, file) 35 if err != nil { 36 return graph.Deps{}, err 37 } 38 39 depMap := make(map[pkg.ID]pkg.Package) 40 imports := []pkg.Import{} 41 for _, group := range nuspec.Metadata.Dependencies.Groups { 42 for _, dep := range group.Dependencies { 43 id := pkg.ID{ 44 Type: pkg.NuGet, 45 Name: dep.ID, 46 Revision: dep.Version, 47 } 48 imports = append(imports, pkg.Import{ 49 Target: dep.ID, 50 Resolved: id, 51 }) 52 depMap[id] = pkg.Package{ 53 ID: id, 54 } 55 } 56 } 57 58 return graph.Deps{ 59 Direct: imports, 60 Transitive: depMap, 61 }, nil 62 }