1// Copyright 2022 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14package app 15 16import ( 17 "encoding/xml" 18 "io/ioutil" 19) 20 21type RepoRemote struct { 22 Name string `xml:"name,attr"` 23 Revision string `xml:"fetch,attr"` 24} 25type RepoDefault struct { 26 Remote string `xml:"remote,attr"` 27 Revision string `xml:"revision,attr"` 28} 29type RepoProject struct { 30 Groups string `xml:"groups,attr"` 31 Name string `xml:"name,attr"` 32 Revision string `xml:"revision,attr"` 33 Path string `xml:"path,attr"` 34 Remote *string `xml:"remote,attr"` 35} 36type RepoManifest struct { 37 XMLName xml.Name `xml:"manifest"` 38 Remotes []RepoRemote `xml:"remote"` 39 Default RepoDefault `xml:"default"` 40 Projects []RepoProject `xml:"project"` 41} 42 43// Parse a repo manifest file 44func ParseXml(filename string) (*RepoManifest, error) { 45 data, err := ioutil.ReadFile(filename) 46 if err != nil { 47 return nil, err 48 } 49 v := &RepoManifest{} 50 err = xml.Unmarshal(data, &v) 51 if err != nil { 52 return nil, err 53 } 54 return v, nil 55} 56