Skip to content

Commit

Permalink
Reformat code (#39)
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 authored Jul 25, 2024
1 parent ee39265 commit a6243db
Show file tree
Hide file tree
Showing 43 changed files with 444 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
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
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 a6243db

Please sign in to comment.