From 0141660c634d4636867c12201af080dd1e0e8491 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Fri, 23 Oct 2020 21:04:03 +0100 Subject: [PATCH] Refactor creation of ConfiguredJarList from list of pairs This change: * Changes splitConfiguredJarPair to return an error rather than reporting it through the context. * Extracts the splitting of a list of pairs into a pair of lists into a new splitListOfPairsIntoPairOfLists() method for reuse in a follow up change. Bug: 171479578 Test: m nothing Change-Id: I824ed1bc673b47757424563fc37e1190adff2ed1 --- android/config.go | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/android/config.go b/android/config.go index 42a286c45..51146655f 100644 --- a/android/config.go +++ b/android/config.go @@ -1449,29 +1449,41 @@ func (l *ConfiguredJarList) DevicePaths(cfg Config, ostype OsType) []string { return paths } +func splitListOfPairsIntoPairOfLists(list []string) ([]string, []string, error) { + // Now we need to populate this list by splitting each item in the slice of + // pairs and appending them to the appropriate list of apexes or jars. + apexes := make([]string, len(list)) + jars := make([]string, len(list)) + + for i, apexjar := range list { + apex, jar, err := splitConfiguredJarPair(apexjar) + if err != nil { + return nil, nil, err + } + apexes[i] = apex + jars[i] = jar + } + + return apexes, jars, nil +} + // Expected format for apexJarValue = : -func splitConfiguredJarPair(ctx PathContext, str string) (string, string) { +func splitConfiguredJarPair(str string) (string, string, error) { pair := strings.SplitN(str, ":", 2) if len(pair) == 2 { - return pair[0], pair[1] + return pair[0], pair[1], nil } else { - ReportPathErrorf(ctx, "malformed (apex, jar) pair: '%s', expected format: :", str) - return "error-apex", "error-jar" + return "error-apex", "error-jar", fmt.Errorf("malformed (apex, jar) pair: '%s', expected format: :", str) } } func CreateConfiguredJarList(ctx PathContext, list []string) ConfiguredJarList { - apexes := make([]string, 0, len(list)) - jars := make([]string, 0, len(list)) - - l := ConfiguredJarList{apexes, jars} - - for _, apexjar := range list { - apex, jar := splitConfiguredJarPair(ctx, apexjar) - l.Append(apex, jar) + apexes, jars, err := splitListOfPairsIntoPairOfLists(list) + if err != nil { + ReportPathErrorf(ctx, "%s", err) } - return l + return ConfiguredJarList{apexes, jars} } func EmptyConfiguredJarList() ConfiguredJarList {