diff options
author | 2016-04-15 20:35:59 +0000 | |
---|---|---|
committer | 2016-04-18 10:43:19 +0000 | |
commit | 1bdf2f49edf67c699b0ffe4a35dd89673c7d9dc8 (patch) | |
tree | e05ca9b35f892096fe00b58d0ac77da2a5f90c5e /src/tools/android/java/com/google/devtools/build/android/NinePatchOnlyCruncher.java | |
parent | ea81a7037f761c10516cfa6ef1eeee7e4bcc7d07 (diff) |
Add a crunch_png attribute to android_binary
This allows a user to turn off png crunching during
the final merge (with crunch_png = 0), but it does
not skip nine-patch processing.
RELNOTES: adds crunch_png attribute to android_binary
--
MOS_MIGRATED_REVID=119986498
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/NinePatchOnlyCruncher.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/NinePatchOnlyCruncher.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/NinePatchOnlyCruncher.java b/src/tools/android/java/com/google/devtools/build/android/NinePatchOnlyCruncher.java new file mode 100644 index 0000000000..3957ab8c4a --- /dev/null +++ b/src/tools/android/java/com/google/devtools/build/android/NinePatchOnlyCruncher.java @@ -0,0 +1,50 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.android; + +import com.google.common.io.Files; + +import com.android.SdkConstants; +import com.android.ide.common.internal.AaptCruncher; +import com.android.ide.common.internal.CommandLineRunner; +import com.android.ide.common.internal.LoggedErrorException; + +import java.io.File; +import java.io.IOException; + +/** + * A wrapper around a PNG cruncher that only processes nine-patch PNGs. + */ +public class NinePatchOnlyCruncher extends AaptCruncher { + + public NinePatchOnlyCruncher(String aaptLocation, CommandLineRunner commandLineRunner) { + super(aaptLocation, commandLineRunner); + } + + /** + * Runs the cruncher on a single file (or copies the file if no crunching is needed). + * + * @param from the file to process + * @param to the output file + */ + @Override + public void crunchPng(File from, File to) + throws InterruptedException, LoggedErrorException, IOException { + if (from.getPath().endsWith(SdkConstants.DOT_9PNG)) { + super.crunchPng(from, to); + } else { + Files.copy(from, to); + } + } +} |