Skip to content

refactor: Bump spotless from 5.17.1 to 6.25.0 #1209

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

Closed
Closed
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
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@

/* package */ static final long KEEP_ALIVE_TIME = 1L;
private static final AndroidExecutors INSTANCE = new AndroidExecutors();

/**
* Nexus 5: Quad-Core Moto X: Dual-Core
*
@@ -43,6 +44,7 @@
* <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;
/* package */ static final int MAX_POOL_SIZE = CPU_COUNT * 2 + 1;
private final Executor uiThread;
Original file line number Diff line number Diff line change
@@ -46,7 +46,9 @@ public boolean isCancellationRequested() {
}
}

/** @return the token that can be passed to asynchronous method to control cancellation. */
/**
* @return the token that can be passed to asynchronous method to control cancellation.
*/
public CancellationToken getToken() {
synchronized (lock) {
throwIfClosed();
18 changes: 14 additions & 4 deletions bolts-tasks/src/main/java/com/parse/boltsinternal/Task.java
Original file line number Diff line number Diff line change
@@ -28,8 +28,10 @@
public class Task<TResult> {
/** An {@link java.util.concurrent.Executor} that executes tasks in parallel. */
public static final ExecutorService BACKGROUND_EXECUTOR = BoltsExecutors.background();

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

/**
* An {@link java.util.concurrent.Executor} that executes tasks in the current thread unless the
* stack runs too deep, at which point it will delegate to {@link Task#BACKGROUND_EXECUTOR} in
@@ -541,28 +543,36 @@ public boolean isCompleted() {
}
}

/** @return {@code true} if the task was cancelled, {@code false} otherwise. */
/**
* @return {@code true} if the task was cancelled, {@code false} otherwise.
*/
public boolean isCancelled() {
synchronized (lock) {
return cancelled;
}
}

/** @return {@code true} if the task has an error, {@code false} otherwise. */
/**
* @return {@code true} if the task has an error, {@code false} otherwise.
*/
public boolean isFaulted() {
synchronized (lock) {
return getError() != null;
}
}

/** @return The result of the task, if set. {@code null} otherwise. */
/**
* @return The result of the task, if set. {@code null} otherwise.
*/
public TResult getResult() {
synchronized (lock) {
return result;
}
}

/** @return The error for the task, if set. {@code null} otherwise. */
/**
* @return The error for the task, if set. {@code null} otherwise.
*/
public Exception getError() {
synchronized (lock) {
if (error != null) {
Original file line number Diff line number Diff line change
@@ -24,7 +24,9 @@ public TaskCompletionSource() {
task = new Task<>();
}

/** @return the Task associated with this TaskCompletionSource. */
/**
* @return the Task associated with this TaskCompletionSource.
*/
public Task<TResult> getTask() {
return task;
}
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
buildscript {
ext.kotlin_version = "1.7.10"
ext.jacocoVersion = '0.8.12'
ext.spotlessVersion = '6.25.0'
repositories {
google()
mavenCentral()
@@ -11,13 +12,13 @@ buildscript {
classpath "org.jacoco:org.jacoco.core:$jacocoVersion"
classpath "com.dicedmelon.gradle:jacoco-android:0.1.5"
classpath "io.freefair.gradle:android-gradle-plugins:4.2.0-m1"
classpath "com.diffplug.spotless:spotless-plugin-gradle:5.17.1"
classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion"
}
}

plugins {
id "com.github.ben-manes.versions" version "0.28.0"
id "com.diffplug.spotless" version "5.17.1"
id "com.diffplug.spotless" version "$spotlessVersion"
}

allprojects {
@@ -39,7 +40,7 @@ allprojects {
}
kotlin {
target '**/*.kt'
ktlint().userData(["disabled_rules": "no-wildcard-imports"])
ktlint()
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
Original file line number Diff line number Diff line change
@@ -7,11 +7,17 @@ import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

suspend fun <T> callCloudFunction(functionName: String, params: Map<String, Any>): T {
suspend fun <T> callCloudFunction(
functionName: String,
params: Map<String, Any>,
): T {
return suspendCoroutine { continuation ->
ParseCloud.callFunctionInBackground<T>(functionName, params) { result, e ->
if (e == null) continuation.resume(result)
else continuation.resumeWithException(e)
if (e == null) {
continuation.resume(result)
} else {
continuation.resumeWithException(e)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -11,8 +11,11 @@ suspend fun <T : ParseObject> ParseObject.suspendFetch(): T {
return suspendCoroutine { continuation ->

fetchInBackground<T> { obj, e ->
if (e == null) continuation.resume(obj)
else continuation.resumeWithException(e)
if (e == null) {
continuation.resume(obj)
} else {
continuation.resumeWithException(e)
}
}
}
}
@@ -21,8 +24,11 @@ suspend fun <T : ParseObject> ParseObject.suspendFetchIfNeeded(): T {
return suspendCoroutine { continuation ->

fetchIfNeededInBackground<T> { obj, e ->
if (e == null) continuation.resume(obj)
else continuation.resumeWithException(e)
if (e == null) {
continuation.resume(obj)
} else {
continuation.resumeWithException(e)
}
}
}
}
@@ -31,8 +37,11 @@ suspend fun <T : ParseObject> ParseObject.fetchFromLocal(): T {
return suspendCoroutine { continuation ->

fetchFromLocalDatastoreInBackground<T> { obj, e ->
if (e == null) continuation.resume(obj)
else continuation.resumeWithException(e)
if (e == null) {
continuation.resume(obj)
} else {
continuation.resumeWithException(e)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -10,17 +10,23 @@ import kotlin.coroutines.suspendCoroutine
suspend fun ParseObject.suspendSave() {
return suspendCoroutine { continuation ->
saveInBackground {
if (it == null) continuation.resume(Unit)
else continuation.resumeWithException(it)
if (it == null) {
continuation.resume(Unit)
} else {
continuation.resumeWithException(it)
}
}
}
}

suspend fun ParseObject.suspendPin() {
return suspendCoroutine { continuation ->
pinInBackground {
if (it == null) continuation.resume(Unit)
else continuation.resumeWithException(it)
if (it == null) {
continuation.resume(Unit)
} else {
continuation.resumeWithException(it)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import kotlin.coroutines.EmptyCoroutineContext
fun <T : ParseObject> CoroutineScope.launchQuery(
query: ParseQuery<T>,
context: CoroutineContext = EmptyCoroutineContext,
block: suspend ParseQueryOperation<T>.() -> Unit
block: suspend ParseQueryOperation<T>.() -> Unit,
): Job {
return launch(context) {
block.invoke(ParseQueryOperationImpl(query))
Original file line number Diff line number Diff line change
@@ -19,8 +19,11 @@ internal suspend fun <T : ParseObject> ParseQuery<T>.findInternal(): List<T> {
}

findInBackground { objects, e ->
if (e == null) continuation.resume(objects)
else continuation.resumeWithException(e)
if (e == null) {
continuation.resume(objects)
} else {
continuation.resumeWithException(e)
}
}
}
}
@@ -36,8 +39,11 @@ internal suspend fun <T : ParseObject> ParseQuery<T>.getInternal(id: String): T
}

getInBackground(id) { obj, e ->
if (e == null) continuation.resume(obj)
else continuation.resumeWithException(e)
if (e == null) {
continuation.resume(obj)
} else {
continuation.resumeWithException(e)
}
}
}
}
@@ -53,8 +59,11 @@ internal suspend fun <T : ParseObject> ParseQuery<T>.firstInternal(): T {
}

getFirstInBackground { obj, e ->
if (e == null) continuation.resume(obj)
else continuation.resumeWithException(e)
if (e == null) {
continuation.resume(obj)
} else {
continuation.resumeWithException(e)
}
}
}
}
@@ -70,8 +79,11 @@ internal suspend fun <T : ParseObject> ParseQuery<T>.countInternal(): Int {
}

countInBackground { count, e ->
if (e == null) continuation.resume(count)
else continuation.resumeWithException(e)
if (e == null) {
continuation.resume(count)
} else {
continuation.resumeWithException(e)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -2,7 +2,10 @@ package com.parse.coroutines

interface ParseQueryOperation<out T> {
suspend fun find(): List<T>

suspend fun get(id: String): T

suspend fun first(): T

suspend fun count(): Int
}
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ import com.parse.ParseQuery

class ParseQueryOperationImpl<T : ParseObject>(private val query: ParseQuery<T>) :
ParseQueryOperation<T> {

override suspend fun find(): List<T> = query.findInternal()

override suspend fun get(id: String): T = query.getInternal(id)
Original file line number Diff line number Diff line change
@@ -12,19 +12,27 @@ import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

@Suppress("BlockingMethodInNonBlockingContext")
suspend fun <T> Task<T>.suspendGet(dispatcher: CoroutineDispatcher = Dispatchers.IO) = withContext<T>(dispatcher) {
return@withContext suspendCoroutine { continuation ->
waitForCompletion()
if (isFaulted) continuation.resumeWithException(error)
else continuation.resume(result)
suspend fun <T> Task<T>.suspendGet(dispatcher: CoroutineDispatcher = Dispatchers.IO) =
withContext<T>(dispatcher) {
return@withContext suspendCoroutine { continuation ->
waitForCompletion()
if (isFaulted) {
continuation.resumeWithException(error)
} else {
continuation.resume(result)
}
}
}
}

@Suppress("BlockingMethodInNonBlockingContext")
suspend fun Task<Void>.suspendRun(dispatcher: CoroutineDispatcher = Dispatchers.IO) = withContext<Unit>(dispatcher) {
return@withContext suspendCoroutine { continuation ->
waitForCompletion()
if (isFaulted) continuation.resumeWithException(error)
else continuation.resume(Unit)
suspend fun Task<Void>.suspendRun(dispatcher: CoroutineDispatcher = Dispatchers.IO) =
withContext<Unit>(dispatcher) {
return@withContext suspendCoroutine { continuation ->
waitForCompletion()
if (isFaulted) {
continuation.resumeWithException(error)
} else {
continuation.resume(Unit)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -10,17 +10,26 @@ import kotlin.coroutines.suspendCoroutine
suspend fun ParseUser.suspendSignUp(): ParseUser {
return suspendCoroutine { continuation ->
signUpInBackground { e ->
if (e == null) continuation.resume(this)
else continuation.resumeWithException(e)
if (e == null) {
continuation.resume(this)
} else {
continuation.resumeWithException(e)
}
}
}
}

suspend fun parseLogIn(username: String, password: String): ParseUser {
suspend fun parseLogIn(
username: String,
password: String,
): ParseUser {
return suspendCoroutine { continuation ->
ParseUser.logInInBackground(username, password) { user, e ->
if (e == null) continuation.resume(user)
else continuation.resumeWithException(e)
if (e == null) {
continuation.resume(user)
} else {
continuation.resumeWithException(e)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ class FacebookController {

// Used as default activityCode. From FacebookSdk.java.
public static final int DEFAULT_AUTH_ACTIVITY_CODE = 0xface;

/** Precise date format required for auth expiration data. */
private static final DateFormat PRECISE_DATE_FORMAT =
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
Loading