diff options
author | 2017-08-24 21:38:41 +0200 | |
---|---|---|
committer | 2017-08-25 12:53:47 +0200 | |
commit | ebafc963884149086bf915da3267f1778270a0ae (patch) | |
tree | 58fb9347d1702bf684b0112c1af9c2180a981783 /src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java | |
parent | e7e0f87cb69ecf69503b3fbe82ab12c62f383666 (diff) |
Enable using a parameter for large lists of resources to link.
RELNOTES: None
PiperOrigin-RevId: 166379334
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/AaptCommandBuilder.java | 25 |
1 files changed, 25 insertions, 0 deletions
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<String> 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) { |