Skip to content

style: code formatting and checks in the CI #1120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*.{java, kt, kts, xml}]
indent_style = space
indent_size = 4
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true

[*.{java, kt, kts}]
max_line_length = 165
disabled_rules = no-wildcard-imports
61 changes: 52 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,64 @@ on:
branches:
- '**'
jobs:
check-lint:
name: Lint
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Fetch Sources
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Setup Gradle Dependencies Cache
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts') }}
- name: Setup Gradle Wrapper Cache
uses: actions/cache@v2
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
- name: Spotless check
run: ./gradlew spotlessCheck --no-daemon
check-gradlewrapper:
name: Gradle Wrapper
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Fetch Sources
uses: actions/checkout@v2
- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1
check-build:
name: Gradle Build
timeout-minutes: 5
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Fetch Sources
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@e6e38bacfdf1a337459f332974bb2327a31aaf4b
- run: pip install --user codecov
- run: mkdir "$ANDROID_HOME/licenses" || true
- run: echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" >> "$ANDROID_HOME/licenses/android-sdk-license"
- run: ./gradlew clean jacocoTestReport
- run: codecov
- name: Setup Gradle Dependencies Cache
uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts') }}
- name: Setup Gradle Wrapper Cache
uses: actions/cache@v2
with:
path: ~/.gradle/wrapper
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
- name: Run tests
run: ./gradlew --no-daemon clean jacocoTestReport
- name: Report test coverage
run: |
pip install --user codecov
codecov
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ We actively welcome your pull requests. When we get one, we'll run some Parse-sp
4. Add unit tests for any new code you add.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
5. Make sure your code lints by running `./gradlew spotlessApply`.

## Bugs
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.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Add this in your root `build.gradle` file (**not** your module `build.gradle` fi

```gradle
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
repositories {
...
maven { url "https://jitpack.io" }
}
}
```

Expand Down
2 changes: 1 addition & 1 deletion bolts-tasks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ jacocoTestReport {
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,37 @@ public class AggregateException extends Exception {
private final List<Throwable> innerThrowables;

/**
* Constructs a new {@code AggregateException} with the current stack trace, the specified detail
* message and with references to the inner throwables that are the cause of this exception.
* Constructs a new {@code AggregateException} with the current stack trace, the specified
* detail message and with references to the inner throwables that are the cause of this
* exception.
*
* @param detailMessage The detail message for this exception.
* @param detailMessage The detail message for this exception.
* @param innerThrowables The exceptions that are the cause of the current exception.
*/
public AggregateException(String detailMessage, Throwable[] innerThrowables) {
this(detailMessage, Arrays.asList(innerThrowables));
}


/**
* Constructs a new {@code AggregateException} with the current stack trace, the specified detail
* message and with references to the inner throwables that are the cause of this exception.
* Constructs a new {@code AggregateException} with the current stack trace, the specified
* detail message and with references to the inner throwables that are the cause of this
* exception.
*
* @param detailMessage The detail message for this exception.
* @param detailMessage The detail message for this exception.
* @param innerThrowables The exceptions that are the cause of the current exception.
*/
public AggregateException(String detailMessage, List<? extends Throwable> innerThrowables) {
super(detailMessage,
innerThrowables != null && innerThrowables.size() > 0 ? innerThrowables.get(0) : null);
super(
detailMessage,
innerThrowables != null && innerThrowables.size() > 0
? innerThrowables.get(0)
: null);
this.innerThrowables = Collections.unmodifiableList(innerThrowables);
}

/**
* Constructs a new {@code AggregateException} with the current stack trace and with references to
* the inner throwables that are the cause of this exception.
* Constructs a new {@code AggregateException} with the current stack trace and with references
* to the inner throwables that are the cause of this exception.
*
* @param innerThrowables The exceptions that are the cause of the current exception.
*/
Expand Down Expand Up @@ -98,9 +102,7 @@ public void printStackTrace(PrintWriter err) {
}
}

/**
* @deprecated Please use {@link #getInnerThrowables()} instead.
*/
/** @deprecated Please use {@link #getInnerThrowables()} instead. */
@Deprecated
public List<Exception> getErrors() {
List<Exception> errors = new ArrayList<>();
Expand All @@ -118,12 +120,9 @@ public List<Exception> getErrors() {
return errors;
}

/**
* @deprecated Please use {@link #getInnerThrowables()} instead.
*/
/** @deprecated Please use {@link #getInnerThrowables()} instead. */
@Deprecated
public Throwable[] getCauses() {
return innerThrowables.toArray(new Throwable[0]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.os.Build;
import android.os.Handler;
import android.os.Looper;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
Expand All @@ -21,30 +20,27 @@
/**
* This was created because the helper methods in {@link java.util.concurrent.Executors} do not work
* as people would normally expect.
* <p>
* Normally, you would think that a cached thread pool would create new threads when necessary,
*
* <p>Normally, you would think that a cached thread pool would create new threads when necessary,
* queue them when the pool is full, and kill threads when they've been inactive for a certain
* period of time. This is not how {@link java.util.concurrent.Executors#newCachedThreadPool()}
* works.
* <p>
* Instead, {@link java.util.concurrent.Executors#newCachedThreadPool()} executes all tasks on
* a new or cached thread immediately because corePoolSize is 0, SynchronousQueue is a queue with
* size 0 and maxPoolSize is Integer.MAX_VALUE. This is dangerous because it can create an unchecked
*
* <p>Instead, {@link java.util.concurrent.Executors#newCachedThreadPool()} executes all tasks on a
* new or cached thread immediately because corePoolSize is 0, SynchronousQueue is a queue with size
* 0 and maxPoolSize is Integer.MAX_VALUE. This is dangerous because it can create an unchecked
* amount of threads.
*/
/* package */ final class AndroidExecutors {

/* package */ static final long KEEP_ALIVE_TIME = 1L;
private static final AndroidExecutors INSTANCE = new AndroidExecutors();
/**
* Nexus 5: Quad-Core
* Moto X: Dual-Core
* <p>
* AsyncTask:
* CORE_POOL_SIZE = CPU_COUNT + 1
* MAX_POOL_SIZE = CPU_COUNT * 2 + 1
* <p>
* https://github.com/android/platform_frameworks_base/commit/719c44e03b97e850a46136ba336d729f5fbd1f47
* Nexus 5: Quad-Core Moto X: Dual-Core
*
* <p>AsyncTask: CORE_POOL_SIZE = CPU_COUNT + 1 MAX_POOL_SIZE = CPU_COUNT * 2 + 1
*
* <p>https://github.com/android/platform_frameworks_base/commit/719c44e03b97e850a46136ba336d729f5fbd1f47
*/
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
/* package */ static final int CORE_POOL_SIZE = CPU_COUNT + 1;
Expand All @@ -56,59 +52,63 @@ private AndroidExecutors() {
}

/**
* Creates a proper Cached Thread Pool. Tasks will reuse cached threads if available
* or create new threads until the core pool is full. tasks will then be queued. If an
* task cannot be queued, a new thread will be created unless this would exceed max pool
* size, then the task will be rejected. Threads will time out after 1 second.
* <p>
* Core thread timeout is only available on android-9+.
* Creates a proper Cached Thread Pool. Tasks will reuse cached threads if available or create
* new threads until the core pool is full. tasks will then be queued. If an task cannot be
* queued, a new thread will be created unless this would exceed max pool size, then the task
* will be rejected. Threads will time out after 1 second.
*
* <p>Core thread timeout is only available on android-9+.
*
* @return the newly created thread pool
*/
public static ExecutorService newCachedThreadPool() {
ThreadPoolExecutor executor = new ThreadPoolExecutor(
CORE_POOL_SIZE,
MAX_POOL_SIZE,
KEEP_ALIVE_TIME, TimeUnit.SECONDS,
new LinkedBlockingQueue<>());
ThreadPoolExecutor executor =
new ThreadPoolExecutor(
CORE_POOL_SIZE,
MAX_POOL_SIZE,
KEEP_ALIVE_TIME,
TimeUnit.SECONDS,
new LinkedBlockingQueue<>());

allowCoreThreadTimeout(executor, true);

return executor;
}

/**
* Creates a proper Cached Thread Pool. Tasks will reuse cached threads if available
* or create new threads until the core pool is full. tasks will then be queued. If an
* task cannot be queued, a new thread will be created unless this would exceed max pool
* size, then the task will be rejected. Threads will time out after 1 second.
* <p>
* Core thread timeout is only available on android-9+.
* Creates a proper Cached Thread Pool. Tasks will reuse cached threads if available or create
* new threads until the core pool is full. tasks will then be queued. If an task cannot be
* queued, a new thread will be created unless this would exceed max pool size, then the task
* will be rejected. Threads will time out after 1 second.
*
* <p>Core thread timeout is only available on android-9+.
*
* @param threadFactory the factory to use when creating new threads
* @return the newly created thread pool
*/
public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) {
ThreadPoolExecutor executor = new ThreadPoolExecutor(
CORE_POOL_SIZE,
MAX_POOL_SIZE,
KEEP_ALIVE_TIME, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(),
threadFactory);
ThreadPoolExecutor executor =
new ThreadPoolExecutor(
CORE_POOL_SIZE,
MAX_POOL_SIZE,
KEEP_ALIVE_TIME,
TimeUnit.SECONDS,
new LinkedBlockingQueue<>(),
threadFactory);

allowCoreThreadTimeout(executor, true);

return executor;
}

/**
* Compatibility helper function for
* {@link java.util.concurrent.ThreadPoolExecutor#allowCoreThreadTimeOut(boolean)}
* <p>
* Only available on android-9+.
* Compatibility helper function for {@link
* java.util.concurrent.ThreadPoolExecutor#allowCoreThreadTimeOut(boolean)}
*
* <p>Only available on android-9+.
*
* @param executor the {@link java.util.concurrent.ThreadPoolExecutor}
* @param value true if should time out, else false
* @param value true if should time out, else false
*/
@SuppressLint("NewApi")
public static void allowCoreThreadTimeout(ThreadPoolExecutor executor, boolean value) {
Expand All @@ -117,16 +117,12 @@ public static void allowCoreThreadTimeout(ThreadPoolExecutor executor, boolean v
}
}

/**
* An {@link java.util.concurrent.Executor} that executes tasks on the UI thread.
*/
/** An {@link java.util.concurrent.Executor} that executes tasks on the UI thread. */
public static Executor uiThread() {
return INSTANCE.uiThread;
}

/**
* An {@link java.util.concurrent.Executor} that runs tasks on the UI thread.
*/
/** An {@link java.util.concurrent.Executor} that runs tasks on the UI thread. */
private static class UIThreadExecutor implements Executor {
@Override
public void execute(Runnable command) {
Expand Down
Loading