github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/buildtools/dotnet/packages_config.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 Packages struct { 10 Package []Package `xml:"package"` 11 } 12 13 type Package struct { 14 ID string `xml:"id,attr"` 15 Version string `xml:"version,attr"` 16 } 17 18 // PackageConfigGraph reads a `packages.config` file and returns a dependency graph. 19 func PackageConfigGraph(file string) (graph.Deps, error) { 20 var pacconfig Packages 21 err := files.ReadXML(&pacconfig, file) 22 if err != nil { 23 return graph.Deps{}, err 24 } 25 26 depMap := make(map[pkg.ID]pkg.Package) 27 imports := []pkg.Import{} 28 for _, dep := range pacconfig.Package { 29 id := pkg.ID{ 30 Type: pkg.NuGet, 31 Name: dep.ID, 32 Revision: dep.Version, 33 } 34 imports = append(imports, pkg.Import{ 35 Target: dep.ID, 36 Resolved: id, 37 }) 38 depMap[id] = pkg.Package{ 39 ID: id, 40 } 41 } 42 43 return graph.Deps{ 44 Direct: imports, 45 Transitive: depMap, 46 }, nil 47 }