fix: optional elements and xml schema
This commit is contained in:
parent
a715984a42
commit
6ea6895a36
1 changed files with 68 additions and 45 deletions
|
@ -80,12 +80,13 @@ type nuspecPackageTypes struct {
|
|||
}
|
||||
|
||||
type nuspecRepository struct {
|
||||
URL string `xml:"url,attr"`
|
||||
URL string `xml:"url,attr,omitempty"`
|
||||
Type string `xml:"type,attr,omitempty"`
|
||||
}
|
||||
type nuspecDependency struct {
|
||||
ID string `xml:"id,attr"`
|
||||
Version string `xml:"version,attr"`
|
||||
Exclude string `xml:"exclude,attr"`
|
||||
Exclude string `xml:"exclude,attr,omitempty"`
|
||||
}
|
||||
|
||||
type nuspecGroup struct {
|
||||
|
@ -101,16 +102,18 @@ type nuspeceMetadata struct {
|
|||
ID string `xml:"id"`
|
||||
Version string `xml:"version"`
|
||||
Authors string `xml:"authors"`
|
||||
RequireLicenseAcceptance bool `xml:"requireLicenseAcceptance"`
|
||||
ProjectURL string `xml:"projectUrl"`
|
||||
RequireLicenseAcceptance bool `xml:"requireLicenseAcceptance,omitempty"`
|
||||
ProjectURL string `xml:"projectUrl,omitempty"`
|
||||
Description string `xml:"description"`
|
||||
ReleaseNotes string `xml:"releaseNotes"`
|
||||
PackageTypes nuspecPackageTypes `xml:"packageTypes"`
|
||||
Repository nuspecRepository `xml:"repository"`
|
||||
Dependencies nuspecDependencies `xml:"dependencies"`
|
||||
ReleaseNotes string `xml:"releaseNotes,omitempty"`
|
||||
PackageTypes *nuspecPackageTypes `xml:"packageTypes,omitempty"`
|
||||
Repository *nuspecRepository `xml:"repository,omitempty"`
|
||||
Dependencies *nuspecDependencies `xml:"dependencies,omitempty"`
|
||||
}
|
||||
|
||||
type nuspecPackage struct {
|
||||
XMLName xml.Name `xml:"package"`
|
||||
Xmlns string `xml:"xmlns,attr"`
|
||||
Metadata nuspeceMetadata `xml:"metadata"`
|
||||
}
|
||||
|
||||
|
@ -162,23 +165,27 @@ func ParseNuspecMetaData(r io.Reader) (*Package, error) {
|
|||
}
|
||||
|
||||
packageType := DependencyPackage
|
||||
if p.Metadata.PackageTypes != nil {
|
||||
for _, pt := range p.Metadata.PackageTypes.PackageType {
|
||||
if pt.Name == "SymbolsPackage" {
|
||||
packageType = SymbolsPackage
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m := &Metadata{
|
||||
Description: p.Metadata.Description,
|
||||
ReleaseNotes: p.Metadata.ReleaseNotes,
|
||||
Authors: p.Metadata.Authors,
|
||||
ProjectURL: p.Metadata.ProjectURL,
|
||||
RepositoryURL: p.Metadata.Repository.URL,
|
||||
RequireLicenseAcceptance: p.Metadata.RequireLicenseAcceptance,
|
||||
Dependencies: make(map[string][]Dependency),
|
||||
}
|
||||
|
||||
if p.Metadata.Repository != nil {
|
||||
m.RepositoryURL = p.Metadata.Repository.URL
|
||||
}
|
||||
if p.Metadata.Dependencies != nil {
|
||||
for _, group := range p.Metadata.Dependencies.Group {
|
||||
deps := make([]Dependency, 0, len(group.Dependency))
|
||||
for _, dep := range group.Dependency {
|
||||
|
@ -194,6 +201,7 @@ func ParseNuspecMetaData(r io.Reader) (*Package, error) {
|
|||
m.Dependencies[group.TargetFramework] = deps
|
||||
}
|
||||
}
|
||||
}
|
||||
return &Package{
|
||||
PackageType: packageType,
|
||||
ID: p.Metadata.ID,
|
||||
|
@ -224,29 +232,44 @@ func GenerateNuspec(pd *Package) any {
|
|||
ID: pd.ID,
|
||||
Version: pd.Version,
|
||||
Authors: pd.Metadata.Authors,
|
||||
Description: pd.Metadata.Description,
|
||||
ProjectURL: pd.Metadata.ProjectURL,
|
||||
Repository: nuspecRepository{URL: pd.Metadata.RepositoryURL},
|
||||
RequireLicenseAcceptance: pd.Metadata.RequireLicenseAcceptance,
|
||||
Dependencies: nuspecDependencies{
|
||||
Group: make([]nuspecGroup, len(pd.Metadata.Dependencies)),
|
||||
},
|
||||
}
|
||||
|
||||
if pd.Metadata.RepositoryURL != "" {
|
||||
m.Repository = &nuspecRepository{
|
||||
URL: pd.Metadata.RepositoryURL,
|
||||
}
|
||||
}
|
||||
|
||||
groups := len(pd.Metadata.Dependencies)
|
||||
if groups > 0 {
|
||||
m.Dependencies = &nuspecDependencies{
|
||||
Group: make([]nuspecGroup, 0, groups),
|
||||
}
|
||||
|
||||
for tgf, deps := range pd.Metadata.Dependencies {
|
||||
gDeps := make([]nuspecDependency, len(deps))
|
||||
for i, dep := range deps {
|
||||
gDeps[i] = nuspecDependency{
|
||||
if len(deps) == 0 {
|
||||
continue
|
||||
}
|
||||
gDeps := make([]nuspecDependency, 0, len(deps))
|
||||
for _, dep := range deps {
|
||||
gDeps = append(gDeps, nuspecDependency{
|
||||
ID: dep.ID,
|
||||
Version: dep.Version,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
m.Dependencies.Group = append(m.Dependencies.Group, nuspecGroup{
|
||||
TargetFramework: tgf,
|
||||
Dependency: gDeps,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return &nuspecPackage{
|
||||
Xmlns: "http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd",
|
||||
Metadata: m,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue