Documentation ¶
Overview ¶
Package manifest implements marshal and unmarshal of manifest XML.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ManifestsProject = &Project{ Name: "manifests", Path: "manifests", RemoteName: "origin", isMetaProject: true, }
ManifestsProject is a special instance of Project.
Functions ¶
func Marshal ¶
Marshal implements encoding manifest to XML.
Example ¶
m := Manifest{ Remotes: []Remote{ Remote{ Name: "aone", Alias: "origin", Fetch: "https://example.com", Review: "https://example.com", Revision: "default", }, }, Default: &Default{ RemoteName: "aone", Revision: "master", }, Projects: []Project{ Project{ Name: "platform/drivers", Path: "platform-drivers", Projects: []Project{ Project{ Name: "platform/nic", Path: "nic", }, }, CopyFiles: []CopyFile{ CopyFile{ Src: "Makefile", Dest: "../Makefile", }, }, }, Project{ Name: "platform/manifest", Path: "platform-manifest", }, }, } buf, err := Marshal(&m) if err != nil { log.Fatal(err) } fmt.Println(string(buf))
Output: <manifest> <remote name="aone" alias="origin" fetch="https://example.com" review="https://example.com" revision="default"></remote> <default remote="aone" revision="master"></default> <project name="platform/drivers" path="platform-drivers"> <project name="platform/nic" path="nic"></project> <copyfile src="Makefile" dest="../Makefile"></copyfile> </project> <project name="platform/manifest" path="platform-manifest"></project> </manifest>
Types ¶
type Annotation ¶
type Annotation struct { Name string `xml:"name,attr,omitempty"` Value string `xml:"value,attr,omitempty"` Keep string `xml:"keep,attr,omitempty"` }
Annotation is for annotation XML element.
type CopyFile ¶
type CopyFile struct { Src string `xml:"src,attr,omitempty"` Dest string `xml:"dest,attr,omitempty"` }
CopyFile is for copyfile XML element.
func (*CopyFile) CheckAndFixup ¶ added in v0.7.8
CheckAndFixup will fixup "copyfile" element
type Default ¶
type Default struct { RemoteName string `xml:"remote,attr,omitempty"` Revision string `xml:"revision,attr,omitempty"` DestBranch string `xml:"dest-branch,attr,omitempty"` Upstream string `xml:"upstream,attr,omitempty"` Override bool `xml:"override,attr,omitempty"` SyncJ int `xml:"sync-j,attr,omitempty"` SyncC string `xml:"sync-c,attr,omitempty"` SyncS string `xml:"sync-s,attr,omitempty"` SyncTags string `xml:"sync-tags,attr,omitempty"` }
Default is for default XML element.
type ExtendProject ¶
type ExtendProject struct { Name string `xml:"name,attr,omitempty"` Path string `xml:"path,attr,omitempty"` Groups string `xml:"groups,attr,omitempty"` Revision string `xml:"revision,attr,omitempty"` }
ExtendProject is for extend-project XML element.
func (*ExtendProject) CheckAndFixup ¶ added in v0.7.8
func (v *ExtendProject) CheckAndFixup() error
CheckAndFixup will fixup "ExtendProject" element
type Include ¶
type Include struct {
Name string `xml:"name,attr,omitempty"`
}
Include is for include XML element.
func (*Include) CheckAndFixup ¶ added in v0.7.8
CheckAndFixup will fixup "Include" element
type LinkFile ¶
type LinkFile struct { Src string `xml:"src,attr,omitempty"` Dest string `xml:"dest,attr,omitempty"` }
LinkFile is for linkfile XML element.
func (*LinkFile) CheckAndFixup ¶ added in v0.7.8
CheckAndFixup will fixup "linkfile" element
type Manifest ¶
type Manifest struct { XMLName xml.Name `xml:"manifest"` Notice string `xml:"notice,omitempty"` Remotes []Remote `xml:"remote,omitempty"` Default *Default `xml:"default,omitempty"` Server *Server `xml:"manifest-server,omitempty"` Projects []Project `xml:"project,omitempty"` RemoveProjects []RemoveProject `xml:"remove-project,omitempty"` ExtendProjects []ExtendProject `xml:"extend-project,omitempty"` RepoHooks *RepoHooks `xml:"repo-hooks,omitempty"` Includes []Include `xml:"include,omitempty"` SourceFile string `xml:"-"` }
Manifest is for toplevel XML structure.
func Unmarshal ¶
Unmarshal implements decoding XML (in buf) to manifest.
Example ¶
buf := []byte(` <manifest> <remote name="aone" alias="origin" fetch="https://example.com" review="https://example.com" revision="default"></remote> <default remote="aone" revision="master"></default> <project name="platform/drivers" path="platform-drivers"> <project name="platform/nic" path="nic"></project> <copyfile src="Makefile" dest="../Makefile"></copyfile> </project> <project name="platform/manifest" path="platform-manifest"></project> </manifest>`) m, err := Unmarshal(buf) if err != nil { log.Fatal(err) } remote := m.Remotes[0] fmt.Printf("remote> name: %s, alias: %s\n", remote.Name, remote.Alias) d := m.Default fmt.Printf("default> name: %s, revision: %s\n", d.RemoteName, d.Revision) for i, p := range m.AllProjects() { fmt.Printf("project #%d> name: %s, path: %s\n", i+1, p.Name, p.Path) for _, cf := range p.CopyFiles { fmt.Printf(" copyfile> src: %s, dest: %s\n", cf.Src, cf.Dest) } }
Output: remote> name: aone, alias: origin default> name: aone, revision: master project #1> name: platform/drivers, path: platform-drivers copyfile> src: Makefile, dest: ../Makefile project #2> name: platform/drivers/platform/nic, path: platform-drivers/nic project #3> name: platform/manifest, path: platform-manifest
func (*Manifest) AllProjects ¶
AllProjects returns all projects and fill missing fields
func (*Manifest) CheckAndFixup ¶ added in v0.7.8
CheckAndFixup will fixup "Manifest" element
func (*Manifest) ProjectHandle ¶
func (v *Manifest) ProjectHandle(handle ProjectHandler) error
ProjectHandle executes Process method of the given handle on each project
type Project ¶
type Project struct { Annotations []Annotation `xml:"annotation,omitempty"` Projects []Project `xml:"project,omitempty"` CopyFiles []CopyFile `xml:"copyfile,omitempty"` LinkFiles []LinkFile `xml:"linkfile,omitempty"` Name string `xml:"name,attr,omitempty"` Path string `xml:"path,attr,omitempty"` RemoteName string `xml:"remote,attr,omitempty"` Revision string `xml:"revision,attr,omitempty"` DestBranch string `xml:"dest-branch,attr,omitempty"` Groups string `xml:"groups,attr,omitempty"` Rebase string `xml:"rebase,attr,omitempty"` SyncC string `xml:"sync-c,attr,omitempty"` SyncS string `xml:"sync-s,attr,omitempty"` SyncTags string `xml:"sync-tags,attr,omitempty"` Upstream string `xml:"upstream,attr,omitempty"` CloneDepth string `xml:"clone-depth,attr,omitempty"` ForcePath string `xml:"force-path,attr,omitempty"` ManifestRemote *Remote `xml:"-"` // contains filtered or unexported fields }
Project is for project XML element.
func (*Project) AllProjects ¶
AllProjects returns all projects (include current project and all sub-projects) of a project recursively.
func (*Project) CheckAndFixup ¶ added in v0.7.8
CheckAndFixup will fixup "Project" element
func (Project) IsMetaProject ¶
IsMetaProject indicates current project is a ManifestProject or not.
func (Project) IsRebase ¶
IsRebase indicates a project should use rebase instead of reset for syncing.
func (Project) IsSyncTags ¶
IsSyncTags indicates a project should sync tags.
type ProjectHandler ¶
type ProjectHandler interface { // The 1st parameter is pointer of a project, and the 2nd parameter // is parent dir of the path of the project. Process(*Project, string) error }
ProjectHandler is an interface to manipulate projects of manifest
type Remote ¶
type Remote struct { Name string `xml:"name,attr,omitempty"` Alias string `xml:"alias,attr,omitempty"` Fetch string `xml:"fetch,attr,omitempty"` PushURL string `xml:"pushurl,attr,omitempty"` Override bool `xml:"override,attr,omitempty"` Review string `xml:"review,attr,omitempty"` Revision string `xml:"revision,attr,omitempty"` Type string `xml:"type,attr,omitempty"` }
Remote is for remote XML element.
func (*Remote) CheckAndFixup ¶ added in v0.7.8
CheckAndFixup will fixup "Remote" element
type RemoveProject ¶
type RemoveProject struct {
Name string `xml:"name,attr,omitempty"`
}
RemoveProject is for remove-project XML element.
func (*RemoveProject) CheckAndFixup ¶ added in v0.7.8
func (v *RemoveProject) CheckAndFixup() error
CheckAndFixup will fixup "RemoveProject" element