Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
Apply automatic code formatting using google-java-format and ktfmt. Enforce the coding standards in CI.
  • Loading branch information
lucianbc committed Jul 25, 2024
1 parent 5deacdf commit fe3cdaf
Show file tree
Hide file tree
Showing 50 changed files with 573 additions and 421 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/google-java-format.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/ktfmt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/watchface.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/
[optimizer]: tools/wff-optimizer/
16 changes: 16 additions & 0 deletions play-validations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -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('\\', '/');
Expand All @@ -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());
}
Expand Down
Loading

0 comments on commit fe3cdaf

Please sign in to comment.