From a6243dbec56d36f1d61c02b52e9f2f9ffdcbd12b Mon Sep 17 00:00:00 2001 From: Lucian Boaca Date: Thu, 25 Jul 2024 11:55:52 +0100 Subject: [PATCH] Reformat code (#39) Apply automatic code formatting using google-java-format and ktfmt. Enforce the coding standards in CI. --- .github/workflows/gradle.yml | 10 + .gitignore | 24 ++ README.md | 9 +- play-validations/build.gradle | 16 ++ .../ActiveMemoryFootprintCalculator.java | 3 +- .../AmbientMemoryFootprintCalculator.java | 9 +- .../watchface/dfx/memory/AndroidResource.java | 34 +-- .../dfx/memory/AndroidResourceLoader.java | 261 +++++++++--------- .../watchface/dfx/memory/DrawableAsset.java | 16 -- .../dfx/memory/DrawableNodeConfigTable.java | 4 +- .../dfx/memory/DrawableResourceDetails.java | 4 +- ...dePerConfigurationFootprintCalculator.java | 6 +- .../dfx/memory/EvaluationSettings.java | 17 +- .../watchface/dfx/memory/InputPackage.java | 8 +- .../memory/MemoryFootprintCalculations.java | 16 -- .../dfx/memory/OptimizationEstimator.java | 13 +- .../dfx/memory/ResourceConfigTable.java | 4 +- .../dfx/memory/ResourceMemoryEvaluator.java | 16 +- .../watchface/dfx/memory/UserConfigKey.java | 7 +- .../watchface/dfx/memory/UserConfigValue.java | 3 +- .../dfx/memory/VariantConfigValue.java | 3 +- .../watchface/dfx/memory/WatchFaceData.java | 6 +- .../dfx/memory/WatchFaceDocuments.java | 7 +- .../dfx/memory/WatchFaceLayoutEvaluator.java | 3 +- .../memory/WatchFaceResourceCollector.java | 10 +- .../AmbientMemoryFootprintCalculatorTest.java | 7 +- .../memory/DrawableNodeConfigTableTest.java | 10 +- .../memory/DrawableResourceDetailsTest.java | 24 +- .../dfx/memory/EvaluationSettingsTest.java | 4 +- .../dfx/memory/InputPackageTest.java | 8 +- .../dfx/memory/OptimizationEstimatorTest.java | 7 +- .../dfx/memory/ResourceConfigTableTest.java | 12 +- .../memory/ResourceMemoryEvaluatorTest.java | 20 +- .../dfx/memory/UserConfigKeyTest.java | 12 +- .../dfx/memory/VariantConfigValueTest.java | 8 +- .../dfx/memory/WatchFaceDataTest.java | 15 +- .../WatchFaceResourceCollectorTest.java | 9 +- tools/build.gradle | 13 + .../clockwork/wff/optimizer/BitmapFonts.kt | 42 ++- .../clockwork/wff/optimizer/ImageLoader.kt | 20 +- .../clockwork/wff/optimizer/PartImages.kt | 44 +-- .../clockwork/wff/optimizer/Settings.kt | 9 +- .../wff/optimizer/ImageLoaderTest.kt | 92 +++--- 43 files changed, 444 insertions(+), 421 deletions(-) create mode 100644 .gitignore delete mode 100644 play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableAsset.java delete mode 100644 play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/MemoryFootprintCalculations.java diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 167d847..14be170 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -37,6 +37,11 @@ jobs: run: | git_hash=$(git rev-parse --short "$GITHUB_SHA") echo "git_hash=$git_hash" >> $GITHUB_ENV + - name: Check format + uses: gradle/actions/setup-gradle@v3 + with: + build-root-directory: play-validations + arguments: spotlessCheck - name: Build memory-footprint.jar uses: gradle/actions/setup-gradle@v3 with: @@ -84,6 +89,11 @@ jobs: run: | git_hash=$(git rev-parse --short "$GITHUB_SHA") echo "git_hash=$git_hash" >> $GITHUB_ENV + - name: Check format + uses: gradle/actions/setup-gradle@v3 + with: + build-root-directory: tools + arguments: spotlessCheck - name: Build wff-optimizer.jar uses: gradle/actions/setup-gradle@v3 with: diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a2da9a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Built application files +*.apk +*.ap_ + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle/ +build/ + +# Editor files +.idea/ + +# Local configuration file (sdk path, etc) +local.properties + +# Log Files +*.log diff --git a/README.md b/README.md index c438689..013eb6a 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,13 @@ optimizing aspects of your WFF XML and your resources. For WFF samples, please see the [Wear OS Samples repository][samples] on GitHub. +## Developer Considerations + +### Formatting + +This codebase is automatically formatted using [spotless](https://github.com/diffplug/spotless) To +reformat, from the project root directory, run `./gradlew spotlessApply`. + ## License Watch Face Format is distributed under the Apache 2.0 license, see the @@ -55,4 +62,4 @@ Watch Face Format is distributed under the Apache 2.0 license, see the [xsd-specs]: third_party/wff/specification/documents/1/ [xsd-validator]: third_party/wff/README.md [wff-features]: https://developer.android.com/training/wearables/wff/features -[optimizer]: tools/wff-optimizer/ \ No newline at end of file +[optimizer]: tools/wff-optimizer/ diff --git a/play-validations/build.gradle b/play-validations/build.gradle index aa76b15..5a64cec 100644 --- a/play-validations/build.gradle +++ b/play-validations/build.gradle @@ -27,9 +27,25 @@ buildscript { } } +plugins { + id "com.diffplug.spotless" version "6.25.0" apply false +} + allprojects { project -> repositories { google() mavenCentral() } + + // Ignore third party code + if (project.name != 'validator') { + apply plugin: 'com.diffplug.spotless' + spotless { + java { + target("src/**/*.java") + googleJavaFormat().aosp().reflowLongStrings() + removeUnusedImports() + } + } + } } diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ActiveMemoryFootprintCalculator.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ActiveMemoryFootprintCalculator.java index f3c5058..d1d31dd 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ActiveMemoryFootprintCalculator.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ActiveMemoryFootprintCalculator.java @@ -3,9 +3,8 @@ import static com.google.wear.watchface.dfx.memory.DrawableResourceDetails.findInMap; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.findSceneNode; -import org.w3c.dom.Document; - import java.util.Map; +import org.w3c.dom.Document; /** Computes the memory footprint of a watch face in active. */ public class ActiveMemoryFootprintCalculator { diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AmbientMemoryFootprintCalculator.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AmbientMemoryFootprintCalculator.java index dcf891f..aadae32 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AmbientMemoryFootprintCalculator.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AmbientMemoryFootprintCalculator.java @@ -18,21 +18,18 @@ import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.findSceneNode; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.getNodeAttribute; - import static java.lang.Math.min; import static java.util.stream.Collectors.toSet; import com.google.common.collect.ImmutableList; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - import java.util.ArrayDeque; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; /** * Computes the memory footprint of a watch face in ambient. diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResource.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResource.java index f3c34ad..bed70b8 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResource.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResource.java @@ -5,11 +5,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -/** - * Represents a resource, from an AAB or APK. - */ +/** Represents a resource, from an AAB or APK. */ public class AndroidResource { - private static final Pattern VALID_RESOURCE_PATH = Pattern.compile(".*res/([^-/]+).*/([^.]+)(\\.|)(.*|)$"); + private static final Pattern VALID_RESOURCE_PATH = + Pattern.compile(".*res/([^-/]+).*/([^.]+)(\\.|)(.*|)$"); private static final int VALID_RESOURCE_GROUPS = 4; // Resource type, for example "raw", "asset", "drawable" etc. @@ -33,8 +32,7 @@ public AndroidResource( String resourceName, String extension, Path filePath, - byte[] data - ) { + byte[] data) { this.resourceType = resourceType; this.resourceName = resourceName; this.extension = extension; @@ -60,13 +58,21 @@ public Boolean isWatchFaceXml() { return "xml".equals(extension) && "raw".equals(resourceType); } - public Boolean isDrawable() { return "drawable".equals(resourceType); } + public Boolean isDrawable() { + return "drawable".equals(resourceType); + } - public Boolean isFont() { return "font".equals(resourceType); } + public Boolean isFont() { + return "font".equals(resourceType); + } - public Boolean isAsset() { return "asset".equals(resourceType); } + public Boolean isAsset() { + return "asset".equals(resourceType); + } - public Boolean isRaw() { return "raw".equals(resourceType); } + public Boolean isRaw() { + return "raw".equals(resourceType); + } static AndroidResource fromPath(Path filePath, byte[] data) { String pathWithFwdSlashes = filePath.toString().replace('\\', '/'); @@ -75,13 +81,7 @@ static AndroidResource fromPath(Path filePath, byte[] data) { String resType = m.group(1); String resName = m.group(2); String ext = m.group(4); - return new AndroidResource( - resType, - resName, - ext, - filePath, - data - ); + return new AndroidResource(resType, resName, ext, filePath, data); } throw new RuntimeException("Not a valid resource file: " + m.matches()); } diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceLoader.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceLoader.java index 3798fed..e7bd495 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceLoader.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceLoader.java @@ -7,7 +7,6 @@ import com.google.devrel.gmscore.tools.apk.arsc.ResourceTableChunk; import com.google.devrel.gmscore.tools.apk.arsc.StringPoolChunk; import com.google.devrel.gmscore.tools.apk.arsc.TypeChunk; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -27,23 +26,25 @@ /** * Represents all the resources of interest in the Android package. - *

- * Where obfuscation has been applied, the mapping is derived, for the creation of the - * AndroidResource objects. For example, for a logical resource res/raw/watchface.xml, an APK - * may in fact store this as res/aB.xml. The resources.arsc file contains this mapping, and the + * + *

Where obfuscation has been applied, the mapping is derived, for the creation of the + * AndroidResource objects. For example, for a logical resource res/raw/watchface.xml, an APK may in + * fact store this as res/aB.xml. The resources.arsc file contains this mapping, and the * AndroidResourceLoader provides a stream of resources with their logical types, names and data. - *

- * Note that more than one AndroidResource object can exist for the given dimensions. For example, - * if there is a drawable and a drawable-fr folder, then there may be multiple AndroidResource - * entries for drawables with the same type, name and extension. The configuration detail, e.g. - * "fr" or "default", is not currently exposed in the AndroidResource objects as it isn't used. + * + *

Note that more than one AndroidResource object can exist for the given dimensions. For + * example, if there is a drawable and a drawable-fr folder, then there may be multiple + * AndroidResource entries for drawables with the same type, name and extension. The configuration + * detail, e.g. "fr" or "default", is not currently exposed in the AndroidResource objects as it + * isn't used. */ public class AndroidResourceLoader { // Only certain resource types are of interest to the evaluator, notably, not string resources. - private static final Set RESOURCE_TYPES = Set.of("raw", "xml", "drawable", "font", "asset"); + private static final Set RESOURCE_TYPES = + Set.of("raw", "xml", "drawable", "font", "asset"); private static final String RESOURCES_FILE_NAME = "resources.arsc"; - private AndroidResourceLoader() { } + private AndroidResourceLoader() {} /** * Creates a resource stream from a path to an AAB structure on the file system. @@ -57,34 +58,38 @@ static Stream streamFromAabDirectory(Path aabPath) throws IOExc int relativePathOffset = aabPath.toString().length() + 1; return childrenFilesStream - .map( - filePath -> { - AndroidResource resource = null; - if (AndroidResource.isValidResourcePath(filePath)) { - try { - resource = AndroidResource.fromPath( - Paths.get(filePath.toString().substring(relativePathOffset)), - java.nio.file.Files.readAllBytes(filePath) - ); - } catch (IOException e) { - throw new RuntimeException(e); - } - } else if (filePath.endsWith("manifest/AndroidManifest.xml")) { - try { - resource = new AndroidResource( - "xml", - "AndroidManifest", - "xml", - Paths.get(filePath.toString().substring(relativePathOffset)), - java.nio.file.Files.readAllBytes(filePath) - ); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - return resource; - } - ).filter(Objects::nonNull); + .map( + filePath -> { + AndroidResource resource = null; + if (AndroidResource.isValidResourcePath(filePath)) { + try { + resource = + AndroidResource.fromPath( + Paths.get( + filePath.toString() + .substring(relativePathOffset)), + java.nio.file.Files.readAllBytes(filePath)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else if (filePath.endsWith("manifest/AndroidManifest.xml")) { + try { + resource = + new AndroidResource( + "xml", + "AndroidManifest", + "xml", + Paths.get( + filePath.toString() + .substring(relativePathOffset)), + java.nio.file.Files.readAllBytes(filePath)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return resource; + }) + .filter(Objects::nonNull); } /** @@ -95,35 +100,40 @@ static Stream streamFromAabDirectory(Path aabPath) throws IOExc */ static Stream streamFromAabFile(ZipFile aabZipFile) { return aabZipFile.stream() - .map( - zipEntry -> { - Path zipEntryPath = Paths.get(zipEntry.getName()); - AndroidResource resource = null; - if (AndroidResource.isValidResourcePath(zipEntryPath)) { - try { - resource = AndroidResource.fromPath( - zipEntryPath, - aabZipFile.getInputStream(zipEntry).readAllBytes() - ); - } catch (IOException e) { - throw new RuntimeException(e); - } - } else if (zipEntry.getName().endsWith("manifest/AndroidManifest.xml")) { - try { - resource = new AndroidResource( - "xml", - "AndroidManifest", - "xml", - Paths.get(zipEntry.getName()), - aabZipFile.getInputStream(zipEntry).readAllBytes() - ); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - return resource; - } - ).filter(Objects::nonNull); + .map( + zipEntry -> { + Path zipEntryPath = Paths.get(zipEntry.getName()); + AndroidResource resource = null; + if (AndroidResource.isValidResourcePath(zipEntryPath)) { + try { + resource = + AndroidResource.fromPath( + zipEntryPath, + aabZipFile + .getInputStream(zipEntry) + .readAllBytes()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else if (zipEntry.getName() + .endsWith("manifest/AndroidManifest.xml")) { + try { + resource = + new AndroidResource( + "xml", + "AndroidManifest", + "xml", + Paths.get(zipEntry.getName()), + aabZipFile + .getInputStream(zipEntry) + .readAllBytes()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + return resource; + }) + .filter(Objects::nonNull); } /** @@ -133,51 +143,52 @@ static Stream streamFromAabFile(ZipFile aabZipFile) { * @return A stream of resource objects. * @throws IOException when the resources file cannot be found, or other IO errors occur. */ - static Stream streamFromMokkaZip(ZipInputStream baseSplitZipStream) throws IOException { + static Stream streamFromMokkaZip(ZipInputStream baseSplitZipStream) + throws IOException { Iterator iterator = - new Iterator() { - private ZipEntry zipEntry; - - @Override - public boolean hasNext() { - try { - zipEntry = baseSplitZipStream.getNextEntry(); - // Advance over entries in the zip that aren't relevant. - while (zipEntry != null && !AndroidResource.isValidResourcePath(zipEntry.getName())) { + new Iterator() { + private ZipEntry zipEntry; + + @Override + public boolean hasNext() { + try { zipEntry = baseSplitZipStream.getNextEntry(); + // Advance over entries in the zip that aren't relevant. + while (zipEntry != null + && !AndroidResource.isValidResourcePath(zipEntry.getName())) { + zipEntry = baseSplitZipStream.getNextEntry(); + } + } catch (IOException e) { + throw new RuntimeException(e); } - } catch (IOException e) { - throw new RuntimeException(e); + return zipEntry != null; } - return zipEntry != null; - } - - @Override - public AndroidResource next() { - System.out.println(zipEntry); - byte[] entryData; - try { - entryData = readAllBytes(baseSplitZipStream); - } catch (IOException e) { - throw new RuntimeException(e); + + @Override + public AndroidResource next() { + System.out.println(zipEntry); + byte[] entryData; + try { + entryData = readAllBytes(baseSplitZipStream); + } catch (IOException e) { + throw new RuntimeException(e); + } + return AndroidResource.fromPath(zipEntry.getName(), entryData); } - return AndroidResource.fromPath(zipEntry.getName(), entryData); - } - }; + }; return StreamSupport.stream( - Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), - false); + Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false); } /** * Creates a resource stream from an APK zip file. - *

- * APK files can have their resources obfuscated, so it is necessary to extract the mapping + * + *

APK files can have their resources obfuscated, so it is necessary to extract the mapping * between the original path and the path in the obfuscated zip. * - * @param zipFile The APK zip file + * @param zipFile The APK zip file * @return A stream of resource objects. * @throws IOException when errors loading resources occur. */ @@ -196,32 +207,32 @@ static Stream streamFromApkFile(ZipFile zipFile) throws IOExcep ResourceTableChunk table = (ResourceTableChunk) chunks.get(0); StringPoolChunk stringPool = table.getStringPool(); - List typeChunks = table.getPackages() - .stream() - .flatMap(p -> p.getTypeChunks().stream()) - .toList(); + List typeChunks = + table.getPackages().stream().flatMap(p -> p.getTypeChunks().stream()).toList(); return typeChunks.stream() - .flatMap(c -> c.getEntries().values().stream()) - .filter(t -> RESOURCE_TYPES.contains(t.typeName())) - .filter(t -> t.value().type() == BinaryResourceValue.Type.STRING) - .map(entry -> { - Path path = Path.of(stringPool.getString(entry.value().data())); - byte[] data = null; - try { - data = zipFile.getInputStream(new ZipEntry(path.toString())).readAllBytes(); - } catch (IOException e) { - throw new RuntimeException(e); - } - - return new AndroidResource( - entry.parent().getTypeName(), - entry.key(), - Files.getFileExtension(path.toString()), - path, - data - ); - }); + .flatMap(c -> c.getEntries().values().stream()) + .filter(t -> RESOURCE_TYPES.contains(t.typeName())) + .filter(t -> t.value().type() == BinaryResourceValue.Type.STRING) + .map( + entry -> { + Path path = Path.of(stringPool.getString(entry.value().data())); + byte[] data = null; + try { + data = + zipFile.getInputStream(new ZipEntry(path.toString())) + .readAllBytes(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + return new AndroidResource( + entry.parent().getTypeName(), + entry.key(), + Files.getFileExtension(path.toString()), + path, + data); + }); } /** Read all bytes from an input stream to a new byte array. */ @@ -234,4 +245,4 @@ static byte[] readAllBytes(InputStream inputStream) throws IOException { } return bos.toByteArray(); } -} \ No newline at end of file +} diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableAsset.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableAsset.java deleted file mode 100644 index 1a5cc80..0000000 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableAsset.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * 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. - */ - diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableNodeConfigTable.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableNodeConfigTable.java index bb202e8..671868f 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableNodeConfigTable.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableNodeConfigTable.java @@ -19,13 +19,10 @@ import static com.google.wear.watchface.dfx.memory.UserConfigValue.SupportedConfigs.isValidUserConfigNode; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.childrenStream; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.isDrawableNode; - import static java.util.Collections.emptyMap; import static java.util.stream.Collectors.*; import static java.util.stream.Collectors.toList; -import org.w3c.dom.Node; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -33,6 +30,7 @@ import java.util.List; import java.util.Objects; import java.util.stream.Stream; +import org.w3c.dom.Node; /** * A container class that holds, for each drawable node of the watch face, the user config set that diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableResourceDetails.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableResourceDetails.java index 4a27827..87d716b 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableResourceDetails.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DrawableResourceDetails.java @@ -29,7 +29,6 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; - import javax.imageio.ImageIO; import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; @@ -139,8 +138,7 @@ static Optional fromPackageResource(AndroidResource res .build()); } - boolean isPossibleImage = - resource.isAsset() || resource.isDrawable() || resource.isRaw(); + boolean isPossibleImage = resource.isAsset() || resource.isDrawable() || resource.isRaw(); if (!isPossibleImage) { return Optional.empty(); diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DynamicNodePerConfigurationFootprintCalculator.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DynamicNodePerConfigurationFootprintCalculator.java index d23745d..209a091 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DynamicNodePerConfigurationFootprintCalculator.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/DynamicNodePerConfigurationFootprintCalculator.java @@ -20,18 +20,16 @@ import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.childrenStream; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.findSceneNode; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.isDrawableNode; - import static java.lang.Math.max; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toSet; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - import java.util.List; import java.util.Set; import java.util.function.Function; import java.util.stream.LongStream; +import org.w3c.dom.Document; +import org.w3c.dom.Node; /** * Calculates the maximum memory footprint needed to render the given dynamic nodes for any user diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/EvaluationSettings.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/EvaluationSettings.java index 0a67b47..6df18c3 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/EvaluationSettings.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/EvaluationSettings.java @@ -17,7 +17,12 @@ package com.google.wear.watchface.dfx.memory; import com.google.common.collect.ImmutableList; - +import java.io.IOException; +import java.net.URL; +import java.util.Enumeration; +import java.util.List; +import java.util.Optional; +import java.util.jar.Manifest; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; @@ -26,20 +31,14 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -import java.io.IOException; -import java.net.URL; -import java.util.Enumeration; -import java.util.List; -import java.util.Optional; -import java.util.jar.Manifest; - /** Contains the CLI arguments that the script was invoked with. */ final class EvaluationSettings { private static final String HONEYFACE_VERSION = "honeyface"; // Match versions supported by the XML validator - private static final List SUPPORTED_VERSIONS = ImmutableList.of(HONEYFACE_VERSION, "1", "2"); + private static final List SUPPORTED_VERSIONS = + ImmutableList.of(HONEYFACE_VERSION, "1", "2"); private static final int GREEDY_DEFAULT_LIMIT = 10_000_000; diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/InputPackage.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/InputPackage.java index aaaa036..8494647 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/InputPackage.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/InputPackage.java @@ -79,15 +79,11 @@ public Stream getWatchFaceFiles() { } @Override - public void close() { - - } + public void close() {} }; } - /** - * Creates an input package from a declarative watch face APK. - */ + /** Creates an input package from a declarative watch face APK. */ static InputPackage openFromApkFile(String apkPath) throws IOException { final ZipFile zipFile = new ZipFile(apkPath); return new InputPackage() { diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/MemoryFootprintCalculations.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/MemoryFootprintCalculations.java deleted file mode 100644 index 1a5cc80..0000000 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/MemoryFootprintCalculations.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2023 Google LLC - * - * 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. - */ - diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/OptimizationEstimator.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/OptimizationEstimator.java index e1c3360..e8f6178 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/OptimizationEstimator.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/OptimizationEstimator.java @@ -19,20 +19,18 @@ import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.findBitmapFontsNode; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.findSceneNode; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.getNodeAttribute; - import static java.lang.Math.ceil; import static java.lang.Math.floor; import static java.lang.Math.max; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Optional; import java.util.Set; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; /** Estimates the effects of optimizing the DWF. */ class OptimizationEstimator { @@ -91,7 +89,7 @@ private void collectMetadata(Node node, Metadata metadata) { break; } - // TODO(b/308123875): Support PartAnimatedImage + // TODO(b/308123875): Support PartAnimatedImage case "PartImage": { DrawableResourceDetails drawable = findImageNodeDrawableResourceDetails(node); @@ -180,7 +178,8 @@ private long estimateIndividualBitmapFontOptimization(Node node, Metadata metada if (maxHeight == 0) { if (evaluationSettings.isVerbose()) { - System.out.printf("BitmapFont: %s unused. Saving %s\n", fontFamily, unoptimizedSize); + System.out.printf( + "BitmapFont: %s unused. Saving %s\n", fontFamily, unoptimizedSize); } return unoptimizedSize; } diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceConfigTable.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceConfigTable.java index d4eeed6..1001880 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceConfigTable.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceConfigTable.java @@ -28,13 +28,11 @@ import com.google.common.graph.MutableGraph; import com.google.common.graph.Traverser; import com.google.mu.util.stream.BiStream; - -import org.w3c.dom.Document; - import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import org.w3c.dom.Document; /** * A container class that holds, for each resource referenced by the watch face, the {@link diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluator.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluator.java index 37afa9d..e6b0a40 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluator.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluator.java @@ -22,9 +22,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.samsung.watchface.WatchFaceXmlValidator; - -import org.w3c.dom.Document; - import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; @@ -32,6 +29,7 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; +import org.w3c.dom.Document; /** Computes the asset memory footprint for a given watch face. */ public class ResourceMemoryEvaluator { @@ -150,12 +148,12 @@ static MemoryFootprint evaluateWatchFaceForLayout( private static void validateFormat(WatchFaceData watchFaceData, String watchFaceFormatVersion) { WatchFaceXmlValidator xmlValidator = new WatchFaceXmlValidator(); for (Document watchFaceDocument : watchFaceData.watchFaceDocuments) { - boolean documentHasValidSchema = - xmlValidator.validate(watchFaceDocument, watchFaceFormatVersion); - if (!documentHasValidSchema) { - throw new TestFailedException( - "Watch Face has syntactic errors and cannot be parsed."); - } + boolean documentHasValidSchema = + xmlValidator.validate(watchFaceDocument, watchFaceFormatVersion); + if (!documentHasValidSchema) { + throw new TestFailedException( + "Watch Face has syntactic errors and cannot be parsed."); + } } } diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/UserConfigKey.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/UserConfigKey.java index 6bc4c98..37cb1cf 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/UserConfigKey.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/UserConfigKey.java @@ -17,21 +17,18 @@ package com.google.wear.watchface.dfx.memory; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.childrenStream; - import static java.util.Collections.emptyIterator; import static java.util.Collections.emptyList; import com.google.wear.watchface.dfx.memory.UserConfigValue.SupportedConfigs; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; - import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import org.w3c.dom.Document; +import org.w3c.dom.Node; /** Represents the key of a UserConfiguration ie a ListConfiguration or a BooleanConfiguration. */ class UserConfigKey { diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/UserConfigValue.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/UserConfigValue.java index 5fa7981..bb459c7 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/UserConfigValue.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/UserConfigValue.java @@ -18,11 +18,10 @@ import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.getNodeAttribute; -import org.w3c.dom.Node; - import java.util.Arrays; import java.util.Objects; import java.util.Optional; +import org.w3c.dom.Node; /** * Represents a UserConfiguration value. For example, in the following XML: diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/VariantConfigValue.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/VariantConfigValue.java index 6c04a72..68287ce 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/VariantConfigValue.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/VariantConfigValue.java @@ -19,12 +19,11 @@ import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.childrenStream; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.getNodeAttribute; +import java.util.Optional; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.util.Optional; - /** Represents a single value of a mode variant. */ class VariantConfigValue { private static final String AMBIENT = "AMBIENT"; diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceData.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceData.java index 33dcae8..c3f8d6c 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceData.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceData.java @@ -16,9 +16,6 @@ package com.google.wear.watchface.dfx.memory; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.HashMap; @@ -26,13 +23,14 @@ import java.util.List; import java.util.Map; import java.util.stream.Stream; - import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; /** * Contains the information about a watch face necessary to compute the memory footprint of that diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceDocuments.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceDocuments.java index cb53bf2..8c42496 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceDocuments.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceDocuments.java @@ -16,15 +16,14 @@ package com.google.wear.watchface.dfx.memory; +import java.util.Optional; +import java.util.stream.IntStream; +import java.util.stream.Stream; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.util.Optional; -import java.util.stream.IntStream; -import java.util.stream.Stream; - /** A set of operations performed on a watch face document or on nodes of a watch face document. */ class WatchFaceDocuments { diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceLayoutEvaluator.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceLayoutEvaluator.java index b001517..e3d6d0a 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceLayoutEvaluator.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceLayoutEvaluator.java @@ -19,10 +19,9 @@ import static com.google.wear.watchface.dfx.memory.DrawableResourceDetails.findInMap; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.findSceneNode; -import org.w3c.dom.Document; - import java.util.Map; import java.util.Set; +import org.w3c.dom.Document; class WatchFaceLayoutEvaluator { diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceResourceCollector.java b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceResourceCollector.java index 9090b71..95f238a 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceResourceCollector.java +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/WatchFaceResourceCollector.java @@ -21,26 +21,22 @@ import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.getNodeAttribute; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.isBitmapFont; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.isFont; - import static java.util.Collections.emptySet; import static java.util.stream.Collectors.toSet; import com.google.common.collect.ImmutableMap; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - import java.util.HashSet; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Stream; - import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; class WatchFaceResourceCollector { private final Map bitmapFontDefinitions; diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/AmbientMemoryFootprintCalculatorTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/AmbientMemoryFootprintCalculatorTest.java index 695a0f0..af7f787 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/AmbientMemoryFootprintCalculatorTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/AmbientMemoryFootprintCalculatorTest.java @@ -4,14 +4,11 @@ import static com.google.wear.watchface.dfx.memory.EvaluationSettings.parseFromArguments; import com.google.common.collect.ImmutableMap; - -import org.junit.Test; -import org.w3c.dom.Document; - import java.io.InputStream; import java.util.Map; - import javax.xml.parsers.DocumentBuilderFactory; +import org.junit.Test; +import org.w3c.dom.Document; public class AmbientMemoryFootprintCalculatorTest { diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/DrawableNodeConfigTableTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/DrawableNodeConfigTableTest.java index 1534c3b..8b4d061 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/DrawableNodeConfigTableTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/DrawableNodeConfigTableTest.java @@ -3,28 +3,24 @@ import static com.google.common.collect.Lists.newArrayList; import static com.google.common.truth.Truth.assertThat; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.findSceneNode; - import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertFalse; import static junit.framework.TestCase.assertTrue; import com.google.common.collect.ImmutableList; import com.google.wear.watchface.dfx.memory.DrawableNodeConfigTable.Entry; - -import org.junit.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - import java.io.InputStream; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; - import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; public class DrawableNodeConfigTableTest { diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/DrawableResourceDetailsTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/DrawableResourceDetailsTest.java index 76fde44..e7ab46c 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/DrawableResourceDetailsTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/DrawableResourceDetailsTest.java @@ -5,9 +5,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; - -import org.junit.Test; - import java.io.InputStream; import java.nio.file.FileSystem; import java.nio.file.Files; @@ -15,6 +12,7 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.Optional; +import org.junit.Test; public class DrawableResourceDetailsTest { private static final String TEST_PACKAGE_FILES_ROOT = @@ -95,8 +93,7 @@ public void fromPackageFile_parsesPngWithoutExtension() throws Exception { public void fromPackageFile_parsesPngFromDifferentQualifierDrawable() throws Exception { ImmutableList testFilePaths = ImmutableList.of("base/res/drawable-xhdpi/dial.png", "base/res/drawable/dial.png"); - AndroidResource originalPackageFile = - readPackageFile("base/res/drawable-nodpi/dial.png"); + AndroidResource originalPackageFile = readPackageFile("base/res/drawable-nodpi/dial.png"); for (String testFilePath : testFilePaths) { AndroidResource testPackageFile = changePath(originalPackageFile, Paths.get(testFilePath)); @@ -135,12 +132,13 @@ public void fromPackageFile_parsesResourceFromWindowsPath() throws Exception { // first component) and APK-style paths, where the module name does not exist try (FileSystem windowsFileSystem = Jimfs.newFileSystem(Configuration.windows())) { ImmutableList testFilePaths = - ImmutableList.of( - "base/res/font/roboto_regular.ttf", "base/res/drawable-nodpi/dial.png"); + ImmutableList.of( + "base/res/font/roboto_regular.ttf", "base/res/drawable-nodpi/dial.png"); for (String testFilePath : testFilePaths) { AndroidResource testPackageFile = - changePath(readPackageFile(testFilePath), - makeWindowsPath(testFilePath, windowsFileSystem)); + changePath( + readPackageFile(testFilePath), + makeWindowsPath(testFilePath, windowsFileSystem)); Optional testDrawableDetails = DrawableResourceDetails.fromPackageResource(testPackageFile); @@ -156,8 +154,7 @@ public void fromPackageFile_parsesResourceFromAssetsAndRaw() throws Exception { ImmutableList.of("base/res/drawable-xhdpi/dial.png", "base/res/drawable/dial.png"); AndroidResource originalFile = readPackageFile("base/res/drawable-nodpi/dial.png"); for (String testFilePath : testFilePaths) { - AndroidResource testPackageFile = - changePath(originalFile, Paths.get(testFilePath)); + AndroidResource testPackageFile = changePath(originalFile, Paths.get(testFilePath)); Optional testDrawableDetails = DrawableResourceDetails.fromPackageResource(testPackageFile); @@ -216,7 +213,7 @@ public void canUseRGB565() throws Exception { private AndroidResource readPackageFile(String originFilePath) throws Exception { Path filePath = Paths.get(TEST_PACKAGE_FILES_ROOT, originFilePath); byte[] bytes = Files.readAllBytes(filePath); - return AndroidResource.fromPath(filePath, bytes); + return AndroidResource.fromPath(filePath, bytes); } private AndroidResource changePath(AndroidResource origin, Path newPath) { @@ -237,8 +234,7 @@ Optional getDrawableResourceDetails(String name) throws String path = String.format("/res/drawable/%s", name); try (InputStream is = getClass().getResourceAsStream(path)) { return DrawableResourceDetails.fromPackageResource( - AndroidResource.fromPath(path, AndroidResourceLoader.readAllBytes(is)) - ); + AndroidResource.fromPath(path, AndroidResourceLoader.readAllBytes(is))); } } } diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/EvaluationSettingsTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/EvaluationSettingsTest.java index e68a732..f168981 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/EvaluationSettingsTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/EvaluationSettingsTest.java @@ -1,17 +1,15 @@ package com.google.wear.watchface.dfx.memory; import static com.google.wear.watchface.dfx.memory.EvaluationSettings.parseFromArguments; - import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.assertFalse; import static junit.framework.TestCase.assertTrue; +import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.util.Optional; - @RunWith(JUnit4.class) public class EvaluationSettingsTest { diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/InputPackageTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/InputPackageTest.java index d841ff9..218a240 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/InputPackageTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/InputPackageTest.java @@ -3,14 +3,12 @@ import static com.google.common.truth.Truth.assertThat; import com.google.common.truth.Correspondence; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - import java.io.File; import java.util.List; import java.util.stream.Collectors; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class InputPackageTest { diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/OptimizationEstimatorTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/OptimizationEstimatorTest.java index 7ec8c8f..98cf67d 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/OptimizationEstimatorTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/OptimizationEstimatorTest.java @@ -5,14 +5,11 @@ import static com.google.wear.watchface.dfx.memory.EvaluationSettings.parseFromArguments; import com.google.common.collect.ImmutableMap; - -import org.junit.Test; -import org.w3c.dom.Document; - import java.io.InputStream; import java.util.Map; - import javax.xml.parsers.DocumentBuilderFactory; +import org.junit.Test; +import org.w3c.dom.Document; public class OptimizationEstimatorTest { private static final EvaluationSettings TEST_SETTINGS = diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceConfigTableTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceConfigTableTest.java index 0ea3a84..53c723b 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceConfigTableTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceConfigTableTest.java @@ -3,25 +3,21 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.wear.watchface.dfx.memory.ResourceConfigTable.fromDrawableNodeConfigTable; import static com.google.wear.watchface.dfx.memory.WatchFaceDocuments.findSceneNode; - import static org.junit.Assert.assertEquals; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.w3c.dom.Document; - import java.io.InputStream; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Set; - import javax.xml.parsers.DocumentBuilderFactory; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.w3c.dom.Document; @RunWith(JUnit4.class) public class ResourceConfigTableTest { diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluatorTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluatorTest.java index 95783f8..eba7045 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluatorTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/ResourceMemoryEvaluatorTest.java @@ -6,7 +6,6 @@ import static com.google.wear.watchface.dfx.memory.WatchFaceData.SYSTEM_DEFAULT_FONT; import static com.google.wear.watchface.dfx.memory.WatchFaceData.SYSTEM_DEFAULT_FONT_SIZE; import static junit.framework.TestCase.assertEquals; - import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.runners.Parameterized.Parameter; @@ -14,16 +13,6 @@ import com.google.common.base.Charsets; import com.google.common.hash.Hashing; import com.samsung.watchface.WatchFaceXmlValidator; - -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.runners.Enclosed; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; -import org.w3c.dom.Document; - import java.io.File; import java.io.InputStream; import java.nio.file.Paths; @@ -36,8 +25,15 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; - import javax.xml.parsers.DocumentBuilderFactory; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.w3c.dom.Document; @RunWith(Enclosed.class) public class ResourceMemoryEvaluatorTest { diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/UserConfigKeyTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/UserConfigKeyTest.java index 55c7f10..ab59130 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/UserConfigKeyTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/UserConfigKeyTest.java @@ -2,12 +2,6 @@ import static org.junit.Assert.assertEquals; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; @@ -16,8 +10,12 @@ import java.util.Spliterators; import java.util.stream.Collectors; import java.util.stream.StreamSupport; - import javax.xml.parsers.DocumentBuilderFactory; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; +import org.w3c.dom.Document; +import org.w3c.dom.Element; @RunWith(JUnit4.class) public class UserConfigKeyTest { diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/VariantConfigValueTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/VariantConfigValueTest.java index 4f0c61a..ad26d1c 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/VariantConfigValueTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/VariantConfigValueTest.java @@ -2,16 +2,14 @@ import static com.google.common.truth.Truth.assertThat; -import org.junit.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - import java.io.InputStream; - import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; public class VariantConfigValueTest { private static final EvaluationSettings TEST_SETTINGS = new EvaluationSettings("", ""); diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/WatchFaceDataTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/WatchFaceDataTest.java index abd1fbc..2a1b27f 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/WatchFaceDataTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/WatchFaceDataTest.java @@ -6,9 +6,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; - -import org.junit.Test; - import java.io.IOException; import java.nio.file.FileSystem; import java.nio.file.Files; @@ -17,6 +14,7 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Stream; +import org.junit.Test; public class WatchFaceDataTest { private static final EvaluationSettings TEST_EVALUATION_SETTINGS = @@ -61,8 +59,7 @@ public class WatchFaceDataTest { @Test public void fromResourcesStream_createsPackageFromLinuxPaths() { - Stream packageFileStream = - TEST_FILES.stream().map(this::readPackageFile); + Stream packageFileStream = TEST_FILES.stream().map(this::readPackageFile); WatchFaceData watchFaceData = WatchFaceData.fromResourcesStream(packageFileStream, TEST_EVALUATION_SETTINGS); @@ -94,9 +91,7 @@ private AndroidResource readPackageFile(String path) throws RuntimeException { } catch (IOException e) { throw new RuntimeException(e); } - return AndroidResource.fromPath( - rootPath.relativize(filePath), - bytes); + return AndroidResource.fromPath(rootPath.relativize(filePath), bytes); } private AndroidResource readWindowsPackageFile(String path, FileSystem fileSystem) { @@ -111,8 +106,6 @@ private AndroidResource readWindowsPackageFile(String path, FileSystem fileSyste Path windowsPath = fileSystem.getPath( pathSplits[0], Arrays.copyOfRange(pathSplits, 1, pathSplits.length)); - return AndroidResource.fromPath( - windowsPath, - bytes); + return AndroidResource.fromPath(windowsPath, bytes); } } diff --git a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/WatchFaceResourceCollectorTest.java b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/WatchFaceResourceCollectorTest.java index 8f9bdbc..c7c3db6 100644 --- a/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/WatchFaceResourceCollectorTest.java +++ b/play-validations/memory-footprint/src/test/java/com/google/wear/watchface/dfx/memory/WatchFaceResourceCollectorTest.java @@ -1,21 +1,18 @@ package com.google.wear.watchface.dfx.memory; import static com.google.common.truth.Truth.assertThat; - import static org.junit.Assert.assertThrows; -import org.junit.Test; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - import java.io.InputStream; import java.util.HashMap; import java.util.Set; - import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; public class WatchFaceResourceCollectorTest { diff --git a/tools/build.gradle b/tools/build.gradle index f8b798b..19c4d5c 100644 --- a/tools/build.gradle +++ b/tools/build.gradle @@ -27,9 +27,22 @@ buildscript { } } +plugins { + id "com.diffplug.spotless" version "6.25.0" apply false +} + allprojects { project -> repositories { google() mavenCentral() } + apply plugin: 'com.diffplug.spotless' + spotless { + kotlin { + target("src/**/*.kt") + ktfmt().kotlinlangStyle().configure { + it.setRemoveUnusedImport(true) + } + } + } } diff --git a/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/BitmapFonts.kt b/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/BitmapFonts.kt index 9d6e790..2aec787 100644 --- a/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/BitmapFonts.kt +++ b/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/BitmapFonts.kt @@ -93,21 +93,25 @@ class BitmapFont(val name: String, val characters: Map) { // Crop if needed. var croppedImage = image.bufferedImage - if (nonTransparentBounds.width() != croppedImage.width || - nonTransparentBounds.height() != croppedImage.height) { + if ( + nonTransparentBounds.width() != croppedImage.width || + nonTransparentBounds.height() != croppedImage.height + ) { croppedImage = croppedImage.getSubimage( nonTransparentBounds.left, nonTransparentBounds.top, nonTransparentBounds.width(), - nonTransparentBounds.height()) + nonTransparentBounds.height() + ) optimizationApplied = true if (imageLoader.settings.verbose) { System.out.println( "Cropping image ${character.resourceId}: " + - "${image.bufferedImage.width}x${image.bufferedImage.height} -> " + - "${nonTransparentBounds.width()}x${nonTransparentBounds.height()}") + "${image.bufferedImage.width}x${image.bufferedImage.height} -> " + + "${nonTransparentBounds.width()}x${nonTransparentBounds.height()}" + ) } } @@ -130,19 +134,23 @@ class BitmapFont(val name: String, val characters: Map) { var marginBottom = image.bufferedImage.height - nonTransparentBounds.bottom // If the resized area is smaller, then scale image and bounds. - if (newWidth * newHeight < - nonTransparentBounds.width() * nonTransparentBounds.height()) { + if ( + newWidth * newHeight < nonTransparentBounds.width() * nonTransparentBounds.height() + ) { if (imageLoader.settings.verbose) { System.out.println( "Scaling image ${character.resourceId}: " + - "${croppedImage.getWidth()}x${croppedImage.getHeight()} -> " + - "${newWidth}x${newHeight}") + "${croppedImage.getWidth()}x${croppedImage.getHeight()} -> " + + "${newWidth}x${newHeight}" + ) } val scaledImage = BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB) val graphics = scaledImage.createGraphics() graphics.setRenderingHint( - RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR) + RenderingHints.KEY_INTERPOLATION, + RenderingHints.VALUE_INTERPOLATION_BILINEAR + ) graphics.drawImage( croppedImage, 0, @@ -153,7 +161,8 @@ class BitmapFont(val name: String, val characters: Map) { 0, croppedImage.getWidth(), croppedImage.getHeight(), - null) + null + ) graphics.dispose() marginLeft = (marginLeft.toDouble() * scaleX).toInt() @@ -162,9 +171,13 @@ class BitmapFont(val name: String, val characters: Map) { marginBottom = (marginBottom.toDouble() * scaleY).toInt() croppedImage = scaledImage character.element.setAttribute( - "width", (newWidth + marginLeft + marginRight).toString()) + "width", + (newWidth + marginLeft + marginRight).toString() + ) character.element.setAttribute( - "height", (newHeight + marginTop + marginBottom).toString()) + "height", + (newHeight + marginTop + marginBottom).toString() + ) optimizationApplied = true } @@ -208,7 +221,8 @@ class BitmapFont(val name: String, val characters: Map) { element.getIntAttribute("marginLeft") ?: 0, element.getIntAttribute("marginTop") ?: 0, element.getIntAttribute("marginRight") ?: 0, - element.getIntAttribute("marginBottom") ?: 0) + element.getIntAttribute("marginBottom") ?: 0 + ) } } } diff --git a/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/ImageLoader.kt b/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/ImageLoader.kt index 11044ce..a2993e9 100644 --- a/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/ImageLoader.kt +++ b/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/ImageLoader.kt @@ -103,14 +103,14 @@ open class ImageLoader(val settings: Settings) { } /** - * A lookup table used for computing the loss of precision when an 8bit value is quantized to a - * 5bit value. + * A lookup table used for computing the loss of precision when an 8bit value is quantized to a 5bit + * value. */ private val QUANTIZATION_ERROR_LUT5 = create8bppToNbppQuantizationErrorLookUpTable(5) /** - * A lookup table used for computing the loss of precision when an 8bit value is quantized to a - * 6bit value. + * A lookup table used for computing the loss of precision when an 8bit value is quantized to a 6bit + * value. */ private val QUANTIZATION_ERROR_LUT6 = create8bppToNbppQuantizationErrorLookUpTable(6) @@ -199,7 +199,17 @@ open class Image( BufferedImage(image.width, image.height, BufferedImage.TYPE_USHORT_565_RGB) val graphics = quantizedImage.createGraphics() graphics.drawImage( - image, 0, 0, image.width, image.height, 0, 0, image.width, image.height, null) + image, + 0, + 0, + image.width, + image.height, + 0, + 0, + image.width, + image.height, + null + ) graphics.dispose() optimizedImage = quantizedImage diff --git a/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/PartImages.kt b/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/PartImages.kt index f0e8d40..d760ea8 100644 --- a/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/PartImages.kt +++ b/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/PartImages.kt @@ -51,7 +51,9 @@ class PartImages { element.getDoubleAttribute("x")!!, element.getDoubleAttribute("y")!!, element.getDoubleAttribute("width")!!, - element.getDoubleAttribute("height")!!)) + element.getDoubleAttribute("height")!! + ) + ) } } @@ -66,7 +68,8 @@ class PartImages { maxWidth = Math.max(maxWidth, partImage.width.toInt()) maxHeight = Math.max(maxHeight, partImage.height.toInt()) image.referencingElements.add( - partImage.element.getElementsByTagName("Image").item(0) as Element) + partImage.element.getElementsByTagName("Image").item(0) as Element + ) } var nonTransparentBounds = image.nonTransparentBounds @@ -77,21 +80,25 @@ class PartImages { // Crop if needed. var croppedImage = image.bufferedImage - if (nonTransparentBounds.width() != croppedImage.width || - nonTransparentBounds.height() != croppedImage.height) { + if ( + nonTransparentBounds.width() != croppedImage.width || + nonTransparentBounds.height() != croppedImage.height + ) { croppedImage = croppedImage.getSubimage( nonTransparentBounds.left, nonTransparentBounds.top, nonTransparentBounds.width(), - nonTransparentBounds.height()) + nonTransparentBounds.height() + ) optimizationApplied = true if (imageLoader.settings.verbose) { System.out.println( "Cropping image ${resourceId}: " + - "${image.bufferedImage.width}x${image.bufferedImage.height} -> " + - "${nonTransparentBounds.width()}x${nonTransparentBounds.height()}") + "${image.bufferedImage.width}x${image.bufferedImage.height} -> " + + "${nonTransparentBounds.width()}x${nonTransparentBounds.height()}" + ) } } @@ -105,19 +112,23 @@ class PartImages { var scaledUncroppedHeight = image.bufferedImage.height.toDouble() // If the resized area is smaller, then scale image and bounds. - if (maxWidth * maxHeight < - nonTransparentBounds.width() * nonTransparentBounds.height()) { + if ( + maxWidth * maxHeight < nonTransparentBounds.width() * nonTransparentBounds.height() + ) { if (imageLoader.settings.verbose) { System.out.println( "Scaling image ${resourceId}: " + - "${croppedImage.getWidth()}x${croppedImage.getHeight()} -> " + - "${maxWidth}x${maxHeight}") + "${croppedImage.getWidth()}x${croppedImage.getHeight()} -> " + + "${maxWidth}x${maxHeight}" + ) } val scaledImage = BufferedImage(maxWidth, maxHeight, BufferedImage.TYPE_INT_ARGB) val graphics = scaledImage.createGraphics() graphics.setRenderingHint( - RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR) + RenderingHints.KEY_INTERPOLATION, + RenderingHints.VALUE_INTERPOLATION_BILINEAR + ) graphics.drawImage( croppedImage, 0, @@ -128,7 +139,8 @@ class PartImages { 0, croppedImage.getWidth(), croppedImage.getHeight(), - null) + null + ) graphics.dispose() nonTransparentBounds = @@ -160,15 +172,13 @@ class PartImages { partImage.element.getDoubleAttribute("pivotX")?.let { val oldPivotXPixel = partImage.x + partImage.width.toDouble() * it - val newPivotXFraction = - (oldPivotXPixel - newX) / newWidth + val newPivotXFraction = (oldPivotXPixel - newX) / newWidth partImage.element.setAttribute("pivotX", newPivotXFraction.toString()) } partImage.element.getDoubleAttribute("pivotY")?.let { val oldPivotYPixel = partImage.y + partImage.height.toDouble() * it - val newPivotYFraction = - (oldPivotYPixel - newY) / newHeight + val newPivotYFraction = (oldPivotYPixel - newY) / newHeight partImage.element.setAttribute("pivotY", newPivotYFraction.toString()) } } diff --git a/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/Settings.kt b/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/Settings.kt index 895e112..ffe4b64 100644 --- a/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/Settings.kt +++ b/tools/wff-optimizer/src/main/java/com/google/android/clockwork/wff/optimizer/Settings.kt @@ -35,10 +35,11 @@ class Settings(val sourcePath: String, val verbose: Boolean = false) { .required() .build() - val verboseOption = Option.builder() - .longOpt("verbose") - .desc("Verbose logging, default is false.") - .build() + val verboseOption = + Option.builder() + .longOpt("verbose") + .desc("Verbose logging, default is false.") + .build() val options = Options() options.addOption(sourcePathOption) diff --git a/tools/wff-optimizer/src/test/java/com/google/android/clockwork/wff/optimizer/ImageLoaderTest.kt b/tools/wff-optimizer/src/test/java/com/google/android/clockwork/wff/optimizer/ImageLoaderTest.kt index a5bdc59..daf408b 100644 --- a/tools/wff-optimizer/src/test/java/com/google/android/clockwork/wff/optimizer/ImageLoaderTest.kt +++ b/tools/wff-optimizer/src/test/java/com/google/android/clockwork/wff/optimizer/ImageLoaderTest.kt @@ -20,7 +20,6 @@ import com.google.common.truth.Truth.assertThat import java.awt.image.BufferedImage import java.io.File import java.io.StringWriter -import java.nio.file.Files import java.util.HashSet import javax.xml.parsers.DocumentBuilderFactory import javax.xml.transform.TransformerFactory @@ -50,10 +49,11 @@ class ImageLoaderTest { @Test fun bitmapFontImageDeduplication() { - val fixture = load( - "src/test/resources/duplicateImageTest", - "src/test/resources/duplicateImageTest/res/raw/watchface.xml" - ) + val fixture = + load( + "src/test/resources/duplicateImageTest", + "src/test/resources/duplicateImageTest/res/raw/watchface.xml" + ) fixture.optimizer.bitmapFonts.optimize(fixture.imageLoader) assertTrue(fixture.imageLoader.dedupeAndWriteOptimizedImages()) @@ -62,15 +62,17 @@ class ImageLoaderTest { // and file_b2 are the same. assertEquals( getResource("duplicateImageTest/res/raw/watchface_expected.xml"), - fixture. document.transformToString()) + fixture.document.transformToString() + ) } @Test fun partImageDeduplication() { - val fixture = load( - "src/test/resources/duplicateImageTest", - "src/test/resources/duplicateImageTest/res/raw/watchface2.xml" - ) + val fixture = + load( + "src/test/resources/duplicateImageTest", + "src/test/resources/duplicateImageTest/res/raw/watchface2.xml" + ) fixture.optimizer.partImages.optimize(fixture.imageLoader) assertTrue(fixture.imageLoader.dedupeAndWriteOptimizedImages()) @@ -79,15 +81,17 @@ class ImageLoaderTest { // and file_b2 are the same. assertEquals( getResource("duplicateImageTest/res/raw/watchface2_expected.xml"), - fixture.document.transformToString()) + fixture.document.transformToString() + ) } @Test fun bitmapFontCropAndMargins() { - val fixture = load( - "src/test/resources/bitmapFontCropTest", - "src/test/resources/bitmapFontCropTest/res/raw/watchface.xml" - ) + val fixture = + load( + "src/test/resources/bitmapFontCropTest", + "src/test/resources/bitmapFontCropTest/res/raw/watchface.xml" + ) fixture.optimizer.bitmapFonts.optimize(fixture.imageLoader) fixture.imageLoader.dedupeAndWriteOptimizedImages() @@ -95,17 +99,19 @@ class ImageLoaderTest { // The bitmap fonts should be cropped with margins added to correctly place the image. assertEquals( getResource("bitmapFontCropTest/res/raw/watchface_expected.xml"), - fixture.document.transformToString()) + fixture.document.transformToString() + ) assertThat(fixture.imageLoader.optimizedImagesSummary()) .containsExactly("a 40 x 44", "b 28 x 44") } @Test fun tooLargeBitmapFontCropAndMargins() { - val fixture = load( - "src/test/resources/bitmapFontCropTest", - "src/test/resources/bitmapFontCropTest/res/raw/too_large.xml" - ) + val fixture = + load( + "src/test/resources/bitmapFontCropTest", + "src/test/resources/bitmapFontCropTest/res/raw/too_large.xml" + ) fixture.optimizer.bitmapFonts.optimize(fixture.imageLoader) fixture.imageLoader.dedupeAndWriteOptimizedImages() @@ -114,17 +120,19 @@ class ImageLoaderTest { // them down as well as crop to the visible pixels. assertEquals( getResource("bitmapFontCropTest/res/raw/too_large_expected.xml"), - fixture.document.transformToString()) + fixture.document.transformToString() + ) assertThat(fixture.imageLoader.optimizedImagesSummary()) .containsExactly("a 40 x 44", "b 28 x 44") } @Test fun tooSmallBitmapFontCropAndMargins() { - val fixture = load( - "src/test/resources/bitmapFontCropTest", - "src/test/resources/bitmapFontCropTest/res/raw/too_small.xml" - ) + val fixture = + load( + "src/test/resources/bitmapFontCropTest", + "src/test/resources/bitmapFontCropTest/res/raw/too_small.xml" + ) fixture.optimizer.bitmapFonts.optimize(fixture.imageLoader) @@ -134,17 +142,19 @@ class ImageLoaderTest { // increace runtime memory usage so we should crop but not scale. assertEquals( getResource("bitmapFontCropTest/res/raw/too_small_expected.xml"), - fixture.document.transformToString()) + fixture.document.transformToString() + ) assertThat(fixture.imageLoader.optimizedImagesSummary()) .containsExactly("a 20 x 22", "b 14 x 22") } @Test fun partImageCrop() { - val fixture = load( - "src/test/resources/partImageCropTest", - "src/test/resources/partImageCropTest/res/raw/watchface.xml" - ) + val fixture = + load( + "src/test/resources/partImageCropTest", + "src/test/resources/partImageCropTest/res/raw/watchface.xml" + ) fixture.optimizer.partImages.optimize(fixture.imageLoader) @@ -153,17 +163,19 @@ class ImageLoaderTest { // We should update the PartImages to apply the crop. assertEquals( getResource("partImageCropTest/res/raw/watchface_expected.xml"), - fixture.document.transformToString()) + fixture.document.transformToString() + ) assertThat(fixture.imageLoader.optimizedImagesSummary()) .containsExactly("a 40 x 44", "b 28 x 44") } @Test fun partImageCropAfectsPivot() { - val fixture = load( - "src/test/resources/watchHandTest", - "src/test/resources/watchHandTest/res/raw/watchface.xml" - ) + val fixture = + load( + "src/test/resources/watchHandTest", + "src/test/resources/watchHandTest/res/raw/watchface.xml" + ) fixture.optimizer.partImages.optimize(fixture.imageLoader) @@ -172,9 +184,9 @@ class ImageLoaderTest { // We should update the PartImages to apply the crop. assertEquals( getResource("watchHandTest/res/raw/watchface_expected.xml"), - fixture.document.transformToString()) - assertThat(fixture.imageLoader.optimizedImagesSummary()) - .containsExactly("hand 33 x 183") + fixture.document.transformToString() + ) + assertThat(fixture.imageLoader.optimizedImagesSummary()).containsExactly("hand 33 x 183") } private class TestFixture( @@ -182,8 +194,8 @@ class ImageLoaderTest { val document: Document, val optimizer: Optimizer ) - - private fun load(settings: String, watchFace: String) : TestFixture { + + private fun load(settings: String, watchFace: String): TestFixture { val builder = DocumentBuilderFactory.newInstance().newDocumentBuilder() val settings = Settings(File(settings).getAbsolutePath()) val document = builder.parse(File(watchFace))