diff options
author | 2017-03-24 03:12:29 +0000 | |
---|---|---|
committer | 2017-03-24 12:19:27 +0000 | |
commit | 5e1a420f1b385382a2df5359faf3ae773aa8d61e (patch) | |
tree | 8736029d0bf4beebaffa46af230ab4834738caa8 /src/tools/android/java/com/google/devtools/build/android/AndroidDataWriter.java | |
parent | 58a615c4941e041d68bceeb68b0d77269f6143f5 (diff) |
Rollback of commit bd40871283a54268945dcb0c47c0326645ffda18.
*** Reason for rollback ***
Rolling forward with the correct changes to the AndroidResourceMergingAction. Tested manually.
*** Original change description ***
Automated [] rollback of commit a58f245a4b40c0ef961b1f30d96b16a9349711c3.
*** Reason for rollback ***
broke over 100k targets, in the depot, see []
*** Original change description ***
Move library R generation to a separate action, ensuring the merging happens
off the java critical path.
--
PiperOrigin-RevId: 151087737
MOS_MIGRATED_REVID=151087737
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/AndroidDataWriter.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/AndroidDataWriter.java | 58 |
1 files changed, 55 insertions, 3 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidDataWriter.java b/src/tools/android/java/com/google/devtools/build/android/AndroidDataWriter.java index 7b5f14d501..433620d144 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidDataWriter.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidDataWriter.java @@ -28,6 +28,7 @@ import com.google.common.collect.Ordering; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; +import com.google.devtools.build.android.AndroidResourceMergingAction.Options; import com.google.devtools.build.android.xml.Namespaces; import java.io.BufferedWriter; import java.io.File; @@ -103,7 +104,7 @@ public class AndroidDataWriter implements AndroidDataWritingVisitor { private static final char[] START_RESOURCES_TAG = "<resources".toCharArray(); public static final char[] END_RESOURCES = "</resources>".toCharArray(); private static final char[] LINE_END = "\n".toCharArray(); - private static final PngCruncher NOOP_CRUNCHER = + static final PngCruncher NOOP_CRUNCHER = new PngCruncher() { @Override public int start() { @@ -111,8 +112,7 @@ public class AndroidDataWriter implements AndroidDataWritingVisitor { } @Override - public void end(int key) throws InterruptedException { - } + public void end(int key) throws InterruptedException {} @Override public void crunchPng(int key, @NonNull File source, @NonNull File destination) @@ -126,6 +126,38 @@ public class AndroidDataWriter implements AndroidDataWritingVisitor { } }; + /** + * The merged {@link Options#resourcesOutput} is only used for validation and not for running + * (unlike the final APK), so the image files do not need to be the true image files. We only need + * the filenames to be the same. + * + * <p>Thus, we only create empty files for PNGs (convenient with a custom PngCruncher object). + * This does miss out on other image files like .webp. + */ + static final PngCruncher STUB_CRUNCHER = + new PngCruncher() { + + @Override + public void crunchPng(int key, File from, File to) throws PngException { + try { + to.createNewFile(); + if (!to.setLastModified(System.currentTimeMillis())) { + throw new PngException("Could not set milliseconds"); + } + } catch (IOException e) { + throw new PngException(e); + } + } + + @Override + public int start() { + return 0; + } + + @Override + public void end(int key) {} + }; + private final Path destination; private final Map<String, ResourceValuesDefinitions> valueTags = new HashMap<>(); @@ -166,6 +198,26 @@ public class AndroidDataWriter implements AndroidDataWritingVisitor { NOOP_CRUNCHER, MoreExecutors.newDirectExecutorService()); } + + /** + * Creates a new writer for processing android libraries. + * + * <p>This writer has stub png cruncher that touches empty files for png resources. + * + * @param manifestDirectory The base directory for the AndroidManifest. + * @param resourceDirectory The directory to copy resources into. + * @param assetsDirectory The directory to copy assets into. + * @param executorService An execution service for multi-threaded writing. + * @return A new {@link AndroidDataWriter}. + */ + public static AndroidDataWriter createForLibrary( + Path manifestDirectory, + Path resourceDirectory, + Path assetsDirectory, + ListeningExecutorService executorService) { + return createWith( + manifestDirectory, resourceDirectory, assetsDirectory, STUB_CRUNCHER, executorService); + } /** * Creates a new writer. |