From ebafc963884149086bf915da3267f1778270a0ae Mon Sep 17 00:00:00 2001 From: corysmith Date: Thu, 24 Aug 2017 21:38:41 +0200 Subject: Enable using a parameter for large lists of resources to link. RELNOTES: None PiperOrigin-RevId: 166379334 --- .../devtools/build/android/AaptCommandBuilder.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java') diff --git a/src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java b/src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java index 6e9c9a41ab..ad645a6fdd 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java +++ b/src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java @@ -23,9 +23,11 @@ import com.google.common.io.CharStreams; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; import java.util.List; +import java.util.stream.Collectors; import javax.annotation.Nullable; /** @@ -110,6 +112,29 @@ public class AaptCommandBuilder { return this; } + /** + * Adds a flag to the builder multiple times, once for each value in the given collection. {@code + * null} values will be skipped. If the collection is empty, nothing will be added. The values + * will be added in the source collection's iteration order. See {@link + * AaptCommandBuilder#addRepeated(String, Collection)} for more information. If the collection + * exceed 200 items, the values will be written to a file and passed as <flag> @<file>. + */ + public AaptCommandBuilder addParameterableRepeated( + final String flag, Collection values, Path workingDirectory) throws IOException { + Preconditions.checkNotNull(flag); + Preconditions.checkNotNull(workingDirectory); + if (values.size() > 200) { + add( + flag, + "@" + Files.write( + Files.createDirectories(workingDirectory).resolve("params" + flag), + ImmutableList.of(values.stream().collect(Collectors.joining(" "))))); + } else { + addRepeated(flag, values); + } + return this; + } + /** Adds the next flag to the builder only if the condition is true. */ public ConditionalAaptCommandBuilder when(boolean condition) { if (condition) { -- cgit v1.2.3