1*105f6285SAndroid Build Coastguard Worker// Copyright 2020 Google LLC 2*105f6285SAndroid Build Coastguard Worker// 3*105f6285SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License"); 4*105f6285SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License. 5*105f6285SAndroid Build Coastguard Worker// You may obtain a copy of the License at 6*105f6285SAndroid Build Coastguard Worker// 7*105f6285SAndroid Build Coastguard Worker// https://www.apache.org/licenses/LICENSE-2.0 8*105f6285SAndroid Build Coastguard Worker// 9*105f6285SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software 10*105f6285SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS, 11*105f6285SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12*105f6285SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and 13*105f6285SAndroid Build Coastguard Worker// limitations under the License. 14*105f6285SAndroid Build Coastguard Worker 15*105f6285SAndroid Build Coastguard Workerpackage git 16*105f6285SAndroid Build Coastguard Worker 17*105f6285SAndroid Build Coastguard Workerimport ( 18*105f6285SAndroid Build Coastguard Worker "bufio" 19*105f6285SAndroid Build Coastguard Worker "os" 20*105f6285SAndroid Build Coastguard Worker "path" 21*105f6285SAndroid Build Coastguard Worker) 22*105f6285SAndroid Build Coastguard Worker 23*105f6285SAndroid Build Coastguard Workertype repoLister struct { 24*105f6285SAndroid Build Coastguard Worker} 25*105f6285SAndroid Build Coastguard Worker 26*105f6285SAndroid Build Coastguard Workerfunc NewRepoLister() ProjectLister { 27*105f6285SAndroid Build Coastguard Worker var rl repoLister 28*105f6285SAndroid Build Coastguard Worker return &rl 29*105f6285SAndroid Build Coastguard Worker} 30*105f6285SAndroid Build Coastguard Worker 31*105f6285SAndroid Build Coastguard Workerfunc (rl repoLister) List(codebasePath string) ([]string, error) { 32*105f6285SAndroid Build Coastguard Worker projectList := []string{".repo"} 33*105f6285SAndroid Build Coastguard Worker listPath := path.Join(codebasePath, ".repo/project.list") 34*105f6285SAndroid Build Coastguard Worker listFile, err := os.Open(listPath) 35*105f6285SAndroid Build Coastguard Worker if err != nil { 36*105f6285SAndroid Build Coastguard Worker return projectList, err 37*105f6285SAndroid Build Coastguard Worker } 38*105f6285SAndroid Build Coastguard Worker defer listFile.Close() 39*105f6285SAndroid Build Coastguard Worker scanner := bufio.NewScanner(listFile) 40*105f6285SAndroid Build Coastguard Worker for scanner.Scan() { 41*105f6285SAndroid Build Coastguard Worker line := scanner.Text() 42*105f6285SAndroid Build Coastguard Worker if line != "" { 43*105f6285SAndroid Build Coastguard Worker projectList = append(projectList, line) 44*105f6285SAndroid Build Coastguard Worker } 45*105f6285SAndroid Build Coastguard Worker } 46*105f6285SAndroid Build Coastguard Worker return projectList, err 47*105f6285SAndroid Build Coastguard Worker} 48