Skip to content

Commit 2945b30

Browse files
authored
style: code formatting and checks in the CI (#1120)
1 parent dd9a9e6 commit 2945b30

File tree

281 files changed

+12314
-10973
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

281 files changed

+12314
-10973
lines changed

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*.{java, kt, kts, xml}]
4+
indent_style = space
5+
indent_size = 4
6+
charset = utf-8
7+
end_of_line = lf
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.{java, kt, kts}]
12+
max_line_length = 165
13+
disabled_rules = no-wildcard-imports

.github/workflows/ci.yml

+52-9
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,64 @@ on:
99
branches:
1010
- '**'
1111
jobs:
12+
check-lint:
13+
name: Lint
14+
timeout-minutes: 5
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Fetch Sources
18+
uses: actions/checkout@v2
19+
- name: Set up JDK 11
20+
uses: actions/setup-java@v2
21+
with:
22+
java-version: '11'
23+
distribution: 'adopt'
24+
- name: Setup Gradle Dependencies Cache
25+
uses: actions/cache@v2
26+
with:
27+
path: ~/.gradle/caches
28+
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts') }}
29+
- name: Setup Gradle Wrapper Cache
30+
uses: actions/cache@v2
31+
with:
32+
path: ~/.gradle/wrapper
33+
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
34+
- name: Spotless check
35+
run: ./gradlew spotlessCheck --no-daemon
36+
check-gradlewrapper:
37+
name: Gradle Wrapper
38+
timeout-minutes: 5
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Fetch Sources
42+
uses: actions/checkout@v2
43+
- name: Gradle Wrapper Validation
44+
uses: gradle/wrapper-validation-action@v1
1245
check-build:
1346
name: Gradle Build
14-
timeout-minutes: 5
47+
timeout-minutes: 15
1548
runs-on: ubuntu-latest
1649
steps:
17-
- uses: actions/checkout@v2
50+
- name: Fetch Sources
51+
uses: actions/checkout@v2
1852
- name: Set up JDK 11
1953
uses: actions/setup-java@v2
2054
with:
2155
java-version: '11'
2256
distribution: 'adopt'
23-
- name: Validate Gradle wrapper
24-
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
25-
- run: pip install --user codecov
26-
- run: mkdir "$ANDROID_HOME/licenses" || true
27-
- run: echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" >> "$ANDROID_HOME/licenses/android-sdk-license"
28-
- run: ./gradlew clean jacocoTestReport
29-
- run: codecov
57+
- name: Setup Gradle Dependencies Cache
58+
uses: actions/cache@v2
59+
with:
60+
path: ~/.gradle/caches
61+
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts') }}
62+
- name: Setup Gradle Wrapper Cache
63+
uses: actions/cache@v2
64+
with:
65+
path: ~/.gradle/wrapper
66+
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
67+
- name: Run tests
68+
run: ./gradlew --no-daemon clean jacocoTestReport
69+
- name: Report test coverage
70+
run: |
71+
pip install --user codecov
72+
codecov

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ We actively welcome your pull requests. When we get one, we'll run some Parse-sp
1414
4. Add unit tests for any new code you add.
1515
3. If you've changed APIs, update the documentation.
1616
4. Ensure the test suite passes.
17-
5. Make sure your code lints.
17+
5. Make sure your code lints by running `./gradlew spotlessApply`.
1818

1919
## Bugs
2020
Although we try to keep developing on Parse easy, you still may run into some issues. Technical questions should be asked on [Stack Overflow][stack-overflow], and for everything else we'll be using GitHub issues.

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ Add this in your root `build.gradle` file (**not** your module `build.gradle` fi
1717

1818
```gradle
1919
allprojects {
20-
repositories {
21-
...
22-
maven { url "https://jitpack.io" }
23-
}
20+
repositories {
21+
...
22+
maven { url "https://jitpack.io" }
23+
}
2424
}
2525
```
2626

bolts-tasks/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ jacocoTestReport {
4848
java {
4949
sourceCompatibility = JavaVersion.VERSION_1_8
5050
targetCompatibility = JavaVersion.VERSION_1_8
51-
}
51+
}

bolts-tasks/src/main/java/com/parse/boltsinternal/AggregateException.java

+17-18
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,37 @@ public class AggregateException extends Exception {
2626
private final List<Throwable> innerThrowables;
2727

2828
/**
29-
* Constructs a new {@code AggregateException} with the current stack trace, the specified detail
30-
* message and with references to the inner throwables that are the cause of this exception.
29+
* Constructs a new {@code AggregateException} with the current stack trace, the specified
30+
* detail message and with references to the inner throwables that are the cause of this
31+
* exception.
3132
*
32-
* @param detailMessage The detail message for this exception.
33+
* @param detailMessage The detail message for this exception.
3334
* @param innerThrowables The exceptions that are the cause of the current exception.
3435
*/
3536
public AggregateException(String detailMessage, Throwable[] innerThrowables) {
3637
this(detailMessage, Arrays.asList(innerThrowables));
3738
}
3839

39-
4040
/**
41-
* Constructs a new {@code AggregateException} with the current stack trace, the specified detail
42-
* message and with references to the inner throwables that are the cause of this exception.
41+
* Constructs a new {@code AggregateException} with the current stack trace, the specified
42+
* detail message and with references to the inner throwables that are the cause of this
43+
* exception.
4344
*
44-
* @param detailMessage The detail message for this exception.
45+
* @param detailMessage The detail message for this exception.
4546
* @param innerThrowables The exceptions that are the cause of the current exception.
4647
*/
4748
public AggregateException(String detailMessage, List<? extends Throwable> innerThrowables) {
48-
super(detailMessage,
49-
innerThrowables != null && innerThrowables.size() > 0 ? innerThrowables.get(0) : null);
49+
super(
50+
detailMessage,
51+
innerThrowables != null && innerThrowables.size() > 0
52+
? innerThrowables.get(0)
53+
: null);
5054
this.innerThrowables = Collections.unmodifiableList(innerThrowables);
5155
}
5256

5357
/**
54-
* Constructs a new {@code AggregateException} with the current stack trace and with references to
55-
* the inner throwables that are the cause of this exception.
58+
* Constructs a new {@code AggregateException} with the current stack trace and with references
59+
* to the inner throwables that are the cause of this exception.
5660
*
5761
* @param innerThrowables The exceptions that are the cause of the current exception.
5862
*/
@@ -98,9 +102,7 @@ public void printStackTrace(PrintWriter err) {
98102
}
99103
}
100104

101-
/**
102-
* @deprecated Please use {@link #getInnerThrowables()} instead.
103-
*/
105+
/** @deprecated Please use {@link #getInnerThrowables()} instead. */
104106
@Deprecated
105107
public List<Exception> getErrors() {
106108
List<Exception> errors = new ArrayList<>();
@@ -118,12 +120,9 @@ public List<Exception> getErrors() {
118120
return errors;
119121
}
120122

121-
/**
122-
* @deprecated Please use {@link #getInnerThrowables()} instead.
123-
*/
123+
/** @deprecated Please use {@link #getInnerThrowables()} instead. */
124124
@Deprecated
125125
public Throwable[] getCauses() {
126126
return innerThrowables.toArray(new Throwable[0]);
127127
}
128-
129128
}

bolts-tasks/src/main/java/com/parse/boltsinternal/AndroidExecutors.java

+45-49
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.os.Build;
1111
import android.os.Handler;
1212
import android.os.Looper;
13-
1413
import java.util.concurrent.Executor;
1514
import java.util.concurrent.ExecutorService;
1615
import java.util.concurrent.LinkedBlockingQueue;
@@ -21,30 +20,27 @@
2120
/**
2221
* This was created because the helper methods in {@link java.util.concurrent.Executors} do not work
2322
* as people would normally expect.
24-
* <p>
25-
* Normally, you would think that a cached thread pool would create new threads when necessary,
23+
*
24+
* <p>Normally, you would think that a cached thread pool would create new threads when necessary,
2625
* queue them when the pool is full, and kill threads when they've been inactive for a certain
2726
* period of time. This is not how {@link java.util.concurrent.Executors#newCachedThreadPool()}
2827
* works.
29-
* <p>
30-
* Instead, {@link java.util.concurrent.Executors#newCachedThreadPool()} executes all tasks on
31-
* a new or cached thread immediately because corePoolSize is 0, SynchronousQueue is a queue with
32-
* size 0 and maxPoolSize is Integer.MAX_VALUE. This is dangerous because it can create an unchecked
28+
*
29+
* <p>Instead, {@link java.util.concurrent.Executors#newCachedThreadPool()} executes all tasks on a
30+
* new or cached thread immediately because corePoolSize is 0, SynchronousQueue is a queue with size
31+
* 0 and maxPoolSize is Integer.MAX_VALUE. This is dangerous because it can create an unchecked
3332
* amount of threads.
3433
*/
3534
/* package */ final class AndroidExecutors {
3635

3736
/* package */ static final long KEEP_ALIVE_TIME = 1L;
3837
private static final AndroidExecutors INSTANCE = new AndroidExecutors();
3938
/**
40-
* Nexus 5: Quad-Core
41-
* Moto X: Dual-Core
42-
* <p>
43-
* AsyncTask:
44-
* CORE_POOL_SIZE = CPU_COUNT + 1
45-
* MAX_POOL_SIZE = CPU_COUNT * 2 + 1
46-
* <p>
47-
* https://github.com/android/platform_frameworks_base/commit/719c44e03b97e850a46136ba336d729f5fbd1f47
39+
* Nexus 5: Quad-Core Moto X: Dual-Core
40+
*
41+
* <p>AsyncTask: CORE_POOL_SIZE = CPU_COUNT + 1 MAX_POOL_SIZE = CPU_COUNT * 2 + 1
42+
*
43+
* <p>https://github.com/android/platform_frameworks_base/commit/719c44e03b97e850a46136ba336d729f5fbd1f47
4844
*/
4945
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
5046
/* package */ static final int CORE_POOL_SIZE = CPU_COUNT + 1;
@@ -56,59 +52,63 @@ private AndroidExecutors() {
5652
}
5753

5854
/**
59-
* Creates a proper Cached Thread Pool. Tasks will reuse cached threads if available
60-
* or create new threads until the core pool is full. tasks will then be queued. If an
61-
* task cannot be queued, a new thread will be created unless this would exceed max pool
62-
* size, then the task will be rejected. Threads will time out after 1 second.
63-
* <p>
64-
* Core thread timeout is only available on android-9+.
55+
* Creates a proper Cached Thread Pool. Tasks will reuse cached threads if available or create
56+
* new threads until the core pool is full. tasks will then be queued. If an task cannot be
57+
* queued, a new thread will be created unless this would exceed max pool size, then the task
58+
* will be rejected. Threads will time out after 1 second.
59+
*
60+
* <p>Core thread timeout is only available on android-9+.
6561
*
6662
* @return the newly created thread pool
6763
*/
6864
public static ExecutorService newCachedThreadPool() {
69-
ThreadPoolExecutor executor = new ThreadPoolExecutor(
70-
CORE_POOL_SIZE,
71-
MAX_POOL_SIZE,
72-
KEEP_ALIVE_TIME, TimeUnit.SECONDS,
73-
new LinkedBlockingQueue<>());
65+
ThreadPoolExecutor executor =
66+
new ThreadPoolExecutor(
67+
CORE_POOL_SIZE,
68+
MAX_POOL_SIZE,
69+
KEEP_ALIVE_TIME,
70+
TimeUnit.SECONDS,
71+
new LinkedBlockingQueue<>());
7472

7573
allowCoreThreadTimeout(executor, true);
7674

7775
return executor;
7876
}
7977

8078
/**
81-
* Creates a proper Cached Thread Pool. Tasks will reuse cached threads if available
82-
* or create new threads until the core pool is full. tasks will then be queued. If an
83-
* task cannot be queued, a new thread will be created unless this would exceed max pool
84-
* size, then the task will be rejected. Threads will time out after 1 second.
85-
* <p>
86-
* Core thread timeout is only available on android-9+.
79+
* Creates a proper Cached Thread Pool. Tasks will reuse cached threads if available or create
80+
* new threads until the core pool is full. tasks will then be queued. If an task cannot be
81+
* queued, a new thread will be created unless this would exceed max pool size, then the task
82+
* will be rejected. Threads will time out after 1 second.
83+
*
84+
* <p>Core thread timeout is only available on android-9+.
8785
*
8886
* @param threadFactory the factory to use when creating new threads
8987
* @return the newly created thread pool
9088
*/
9189
public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) {
92-
ThreadPoolExecutor executor = new ThreadPoolExecutor(
93-
CORE_POOL_SIZE,
94-
MAX_POOL_SIZE,
95-
KEEP_ALIVE_TIME, TimeUnit.SECONDS,
96-
new LinkedBlockingQueue<>(),
97-
threadFactory);
90+
ThreadPoolExecutor executor =
91+
new ThreadPoolExecutor(
92+
CORE_POOL_SIZE,
93+
MAX_POOL_SIZE,
94+
KEEP_ALIVE_TIME,
95+
TimeUnit.SECONDS,
96+
new LinkedBlockingQueue<>(),
97+
threadFactory);
9898

9999
allowCoreThreadTimeout(executor, true);
100100

101101
return executor;
102102
}
103103

104104
/**
105-
* Compatibility helper function for
106-
* {@link java.util.concurrent.ThreadPoolExecutor#allowCoreThreadTimeOut(boolean)}
107-
* <p>
108-
* Only available on android-9+.
105+
* Compatibility helper function for {@link
106+
* java.util.concurrent.ThreadPoolExecutor#allowCoreThreadTimeOut(boolean)}
107+
*
108+
* <p>Only available on android-9+.
109109
*
110110
* @param executor the {@link java.util.concurrent.ThreadPoolExecutor}
111-
* @param value true if should time out, else false
111+
* @param value true if should time out, else false
112112
*/
113113
@SuppressLint("NewApi")
114114
public static void allowCoreThreadTimeout(ThreadPoolExecutor executor, boolean value) {
@@ -117,16 +117,12 @@ public static void allowCoreThreadTimeout(ThreadPoolExecutor executor, boolean v
117117
}
118118
}
119119

120-
/**
121-
* An {@link java.util.concurrent.Executor} that executes tasks on the UI thread.
122-
*/
120+
/** An {@link java.util.concurrent.Executor} that executes tasks on the UI thread. */
123121
public static Executor uiThread() {
124122
return INSTANCE.uiThread;
125123
}
126124

127-
/**
128-
* An {@link java.util.concurrent.Executor} that runs tasks on the UI thread.
129-
*/
125+
/** An {@link java.util.concurrent.Executor} that runs tasks on the UI thread. */
130126
private static class UIThreadExecutor implements Executor {
131127
@Override
132128
public void execute(Runnable command) {

0 commit comments

Comments
 (0)