Skip to content
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

Migrate the source base to Kotlin #1099

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ coverage:
range: "45...100"

status:
project:
project:
default:
target: 45%
patch: yes
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: Java CI with Gradle
on:
push:
branches:
- master
pull_request:
branches:
- '**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- run: pip install --user codecov
- run: mkdir "$ANDROID_HOME/licenses" || true
- run: echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" >> "$ANDROID_HOME/licenses/android-sdk-license"
- run: ./gradlew clean jacocoTestReport
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

26 changes: 8 additions & 18 deletions bolts-tasks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,19 @@
apply plugin: 'java'
apply plugin: 'maven'

configurations {
provided
}

sourceSets {
main {
compileClasspath += configurations.provided
}
}

dependencies {
provided 'com.google.android:android:4.1.1.4'
testImplementation 'junit:junit:4.12'
compileOnly 'com.google.android:android:4.1.1.4'
testImplementation 'junit:junit:4.13.2'
}


javadoc.options.addStringOption('Xdoclint:none', '-quiet')

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allJava
}

task javadocJar (type: Jar, dependsOn: javadoc) {
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
Expand All @@ -45,10 +34,6 @@ artifacts {

apply plugin: 'jacoco'

jacoco {
toolVersion = '0.7.1.201405082137'
}

jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
Expand All @@ -59,3 +44,8 @@ jacocoTestReport {
}

//endregion

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AggregateException extends Exception {

private static final String DEFAULT_MESSAGE = "There were multiple errors.";

private List<Throwable> innerThrowables;
private final List<Throwable> innerThrowables;

/**
* Constructs a new {@code AggregateException} with the current stack trace, the specified detail
Expand Down Expand Up @@ -103,7 +103,7 @@ public void printStackTrace(PrintWriter err) {
*/
@Deprecated
public List<Exception> getErrors() {
List<Exception> errors = new ArrayList<Exception>();
List<Exception> errors = new ArrayList<>();
if (innerThrowables == null) {
return errors;
}
Expand All @@ -123,7 +123,7 @@ public List<Exception> getErrors() {
*/
@Deprecated
public Throwable[] getCauses() {
return innerThrowables.toArray(new Throwable[innerThrowables.size()]);
return innerThrowables.toArray(new Throwable[0]);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@
*/
/* package */ final class AndroidExecutors {

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

private final Executor uiThread;

private AndroidExecutors() {
uiThread = new UIThreadExecutor();
}

/**
* Nexus 5: Quad-Core
* Moto X: Dual-Core
Expand All @@ -55,7 +49,11 @@ private AndroidExecutors() {
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;
/* package */ static final long KEEP_ALIVE_TIME = 1L;
private final Executor uiThread;

private AndroidExecutors() {
uiThread = new UIThreadExecutor();
}

/**
* Creates a proper Cached Thread Pool. Tasks will reuse cached threads if available
Expand All @@ -72,7 +70,7 @@ public static ExecutorService newCachedThreadPool() {
CORE_POOL_SIZE,
MAX_POOL_SIZE,
KEEP_ALIVE_TIME, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>());
new LinkedBlockingQueue<>());

allowCoreThreadTimeout(executor, true);

Expand All @@ -95,7 +93,7 @@ public static ExecutorService newCachedThreadPool(ThreadFactory threadFactory) {
CORE_POOL_SIZE,
MAX_POOL_SIZE,
KEEP_ALIVE_TIME, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(),
new LinkedBlockingQueue<>(),
threadFactory);

allowCoreThreadTimeout(executor, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@
/* package */ final class BoltsExecutors {

private static final BoltsExecutors INSTANCE = new BoltsExecutors();

private static boolean isAndroidRuntime() {
String javaRuntimeName = System.getProperty("java.runtime.name");
if (javaRuntimeName == null) {
return false;
}
return javaRuntimeName.toLowerCase(Locale.US).contains("android");
}

private final ExecutorService background;
private final ScheduledExecutorService scheduled;
private final Executor immediate;
Expand All @@ -39,6 +30,14 @@ private BoltsExecutors() {
immediate = new ImmediateExecutor();
}

private static boolean isAndroidRuntime() {
String javaRuntimeName = System.getProperty("java.runtime.name");
if (javaRuntimeName == null) {
return false;
}
return javaRuntimeName.toLowerCase(Locale.US).contains("android");
}

/**
* An {@link java.util.concurrent.Executor} that executes tasks in parallel.
*/
Expand Down Expand Up @@ -69,7 +68,7 @@ static Executor immediate() {
*/
private static class ImmediateExecutor implements Executor {
private static final int MAX_DEPTH = 15;
private ThreadLocal<Integer> executionDepth = new ThreadLocal<>();
private final ThreadLocal<Integer> executionDepth = new ThreadLocal<>();

/**
* Increments the depth.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public String toString() {
return String.format(Locale.US, "%s@%s[cancellationRequested=%s]",
getClass().getName(),
Integer.toHexString(hashCode()),
Boolean.toString(tokenSource.isCancellationRequested()));
tokenSource.isCancellationRequested());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,11 @@ private void cancelAfter(long delay, TimeUnit timeUnit) {
cancelScheduledCancellation();

if (delay != -1) {
scheduledCancellation = executor.schedule(new Runnable() {
@Override
public void run() {
synchronized (lock) {
scheduledCancellation = null;
}
cancel();
scheduledCancellation = executor.schedule(() -> {
synchronized (lock) {
scheduledCancellation = null;
}
cancel();
}, delay, timeUnit);
}
}
Expand Down Expand Up @@ -187,7 +184,7 @@ public String toString() {
return String.format(Locale.US, "%s@%s[cancellationRequested=%s]",
getClass().getName(),
Integer.toHexString(hashCode()),
Boolean.toString(isCancellationRequested()));
isCancellationRequested());
}

// This method makes no attempt to perform any synchronization itself - you should ensure
Expand Down
Loading