Skip to content

Commit

Permalink
Merge pull request #46 from wching/master
Browse files Browse the repository at this point in the history
Migration to RxJava 2
  • Loading branch information
wching committed Mar 22, 2019
2 parents fcccf44 + d8e2746 commit 8e37578
Show file tree
Hide file tree
Showing 34 changed files with 170 additions and 175 deletions.
45 changes: 26 additions & 19 deletions .travis.yml
@@ -1,33 +1,40 @@
language: android

sudo: required
jdk: oraclejdk8

env:
global:
- MALLOC_ARENA_MAX=2
- ADB_INSTALL_TIMEOUT=10
matrix:
- ANDROID_TARGET=android-22 ANDROID_ABI=armeabi-v7a
- ANDROID_API_LEVEL=28
- ANDROID_BUILD_TOOLS_VERSION=28.0.3
- ANDROID_ABI=armeabi-v7a

android:
components:
- tools
- build-tools-25.0.3
- android-25
- android-24
- android-22
- android-23
- sys-img-armeabi-v7a-android-22
- extra-google-m2repository
- platform-tools
- extra-android-m2repository
- extra-android-support
licenses:
- 'android-sdk-preview-license-52d11cd2'
- 'android-sdk-license-.+'
- 'google-gdk-license-.+'

sudo: required
before_install:
- touch $HOME/.android/repositories.cfg
- yes | sdkmanager "platforms;android-28"
- yes | sdkmanager "build-tools;28.0.3"

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/

cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache

before_script:
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
- chmod +x gradlew

script: ./gradlew library:test
script:
- ./gradlew library:test
4 changes: 3 additions & 1 deletion build.gradle
Expand Up @@ -2,10 +2,11 @@

buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.3.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -14,6 +15,7 @@ buildscript {

allprojects {
repositories {
google()
jcenter()
}
}
4 changes: 3 additions & 1 deletion gradle.properties
Expand Up @@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
17 changes: 6 additions & 11 deletions library/build.gradle
@@ -1,12 +1,7 @@
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'me.tatarka.retrolambda'

buildscript {
dependencies {
classpath 'me.tatarka:gradle-retrolambda:3.6.1'
}

repositories {
mavenCentral()
}
Expand All @@ -24,15 +19,15 @@ repositories {
dependencies {

// Rx
compile 'io.reactivex:rxjava:1.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.7'

// GSON
compile 'com.google.code.gson:gson:2.8.0'
implementation 'com.google.code.gson:gson:2.8.5'

// Testing
testCompile "cglib:cglib:2.2"
testCompile 'junit:junit:4.12'
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
testImplementation "cglib:cglib:2.2"
testImplementation 'junit:junit:4.12'
testImplementation('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude group: 'junit'
}
}
}
@@ -1,7 +1,6 @@
package de.rheinfabrik.heimdall;
package de.rheinfabrik.heimdall2;

import com.google.gson.annotations.SerializedName;

import java.io.Serializable;
import java.util.Calendar;

Expand Down
@@ -1,13 +1,10 @@
package de.rheinfabrik.heimdall;
package de.rheinfabrik.heimdall2;

import de.rheinfabrik.heimdall2.grants.OAuth2Grant;
import de.rheinfabrik.heimdall2.grants.OAuth2RefreshAccessTokenGrant;
import io.reactivex.Single;
import java.util.Calendar;

import de.rheinfabrik.heimdall.grants.OAuth2Grant;
import de.rheinfabrik.heimdall.grants.OAuth2RefreshAccessTokenGrant;
import rx.Single;

import static rx.Single.error;

/**
* The all-seeing and all-hearing guardian sentry of your application who
* stands on the rainbow bridge to handle all your access tokens needs!
Expand Down Expand Up @@ -78,7 +75,7 @@ public Single<TAccessToken> grantNewAccessToken(OAuth2Grant<TAccessToken> grant,
accessToken.expirationDate = expirationDate;
}
mStorage.storeAccessToken(accessToken);
}).toObservable().cache().toSingle();
}).cache();
}

/**
Expand All @@ -97,7 +94,7 @@ public Single<TAccessToken> getValidAccessToken(final OAuth2RefreshAccessTokenGr
return mStorage.getStoredAccessToken()
.flatMap(accessToken -> {
if (accessToken == null) {
return error(new IllegalStateException("No access token found."));
return Single.error(new IllegalStateException("No access token found."));
} else if (accessToken.isExpired()) {
refreshAccessTokenGrant.refreshToken = accessToken.refreshToken;

Expand Down
@@ -1,6 +1,7 @@
package de.rheinfabrik.heimdall;
package de.rheinfabrik.heimdall2;

import rx.Single;

import io.reactivex.Single;

/**
* Interface used to define how to store and retrieve a stored access token.
Expand Down
@@ -1,19 +1,17 @@
package de.rheinfabrik.heimdall.grants;
package de.rheinfabrik.heimdall2.grants;

import java.io.UnsupportedEncodingException;
import de.rheinfabrik.heimdall2.OAuth2AccessToken;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.PublishSubject;
import java.net.URL;
import java.net.URLDecoder;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import de.rheinfabrik.heimdall.OAuth2AccessToken;
import rx.Observable;
import rx.Single;
import rx.subjects.BehaviorSubject;
import rx.subjects.PublishSubject;

/**
* Class representing the Authorization Code Grant as described in https://tools.ietf.org/html/rfc6749#section-4.1.
*
Expand Down Expand Up @@ -71,7 +69,7 @@ public abstract class OAuth2AuthorizationCodeGrant<TAccessToken extends OAuth2Ac
* Observable emitting the authorization Uri.
*/
public final Observable<URL> authorizationUri() {
return mAuthorizationUrlSubject.asObservable();
return mAuthorizationUrlSubject;
}

/**
Expand Down Expand Up @@ -114,7 +112,7 @@ public Single<TAccessToken> grantNewAccessToken() {
.take(1)
.retry()
.concatMap(this::exchangeTokenUsingCode)
.toSingle();
.singleOrError();
}

// Private
Expand Down
@@ -1,6 +1,6 @@
package de.rheinfabrik.heimdall.grants;
package de.rheinfabrik.heimdall2.grants;

import de.rheinfabrik.heimdall.OAuth2AccessToken;
import de.rheinfabrik.heimdall2.OAuth2AccessToken;

/**
* Class representing the Client Credentials Grant as described in https://tools.ietf.org/html/rfc6749#section-4.4.
Expand Down
@@ -1,7 +1,7 @@
package de.rheinfabrik.heimdall.grants;
package de.rheinfabrik.heimdall2.grants;

import de.rheinfabrik.heimdall.OAuth2AccessToken;
import rx.Single;
import de.rheinfabrik.heimdall2.OAuth2AccessToken;
import io.reactivex.Single;

/**
* Interface describing an OAuth2 Grant as described in https://tools.ietf.org/html/rfc6749#page-23.
Expand Down
@@ -1,6 +1,6 @@
package de.rheinfabrik.heimdall.grants;
package de.rheinfabrik.heimdall2.grants;

import de.rheinfabrik.heimdall.OAuth2AccessToken;
import de.rheinfabrik.heimdall2.OAuth2AccessToken;

/**
* Class representing the Implicit Grant as described in https://tools.ietf.org/html/rfc6749#section-4.2.
Expand Down
@@ -1,6 +1,6 @@
package de.rheinfabrik.heimdall.grants;
package de.rheinfabrik.heimdall2.grants;

import de.rheinfabrik.heimdall.OAuth2AccessToken;
import de.rheinfabrik.heimdall2.OAuth2AccessToken;

/**
* Class representing the Refreshing Access Token Grant as described in https://tools.ietf.org/html/rfc6749#section-6.
Expand Down
@@ -1,6 +1,6 @@
package de.rheinfabrik.heimdall.grants;
package de.rheinfabrik.heimdall2.grants;

import de.rheinfabrik.heimdall.OAuth2AccessToken;
import de.rheinfabrik.heimdall2.OAuth2AccessToken;

/**
* Class representing the Resource Owner Password Credentials Grant as described in https://tools.ietf.org/html/rfc6749#section-4.3.
Expand Down
@@ -1,8 +1,8 @@
package de.rheinfabrik.heimdall
package de.rheinfabrik.heimdall2

import de.rheinfabrik.heimdall.grants.OAuth2Grant
import de.rheinfabrik.heimdall.grants.OAuth2RefreshAccessTokenGrant
import rx.Single
import de.rheinfabrik.heimdall2.grants.OAuth2Grant
import de.rheinfabrik.heimdall2.grants.OAuth2RefreshAccessTokenGrant
import io.reactivex.Single
import spock.lang.Specification
import spock.lang.Title

Expand Down Expand Up @@ -62,7 +62,7 @@ class OAuth2AccessTokenManagerGrantNewAccessTokenSpecs extends Specification {
Calendar calendar = Calendar.getInstance()

when: "I ask for a new access token"
OAuth2AccessToken newToken = tokenManager.grantNewAccessToken(grant, calendar).toBlocking().value()
OAuth2AccessToken newToken = tokenManager.grantNewAccessToken(grant, calendar).blockingGet()

then: "The access token should have the correct expiration date"
newToken.expirationDate.timeInMillis == calendar.getTimeInMillis() + 3000
Expand All @@ -82,7 +82,7 @@ class OAuth2AccessTokenManagerGrantNewAccessTokenSpecs extends Specification {
OAuth2AccessTokenManager tokenManager = new OAuth2AccessTokenManager<OAuth2AccessToken>(Mock(OAuth2AccessTokenStorage))

when: "I ask for a new access token"
OAuth2AccessToken newToken = tokenManager.grantNewAccessToken(grant).toBlocking().value()
OAuth2AccessToken newToken = tokenManager.grantNewAccessToken(grant).blockingGet()

then: "The access token should have the NO expiration date"
newToken.expirationDate == null
Expand All @@ -104,7 +104,7 @@ class OAuth2AccessTokenManagerGrantNewAccessTokenSpecs extends Specification {
OAuth2AccessTokenManager tokenManager = new OAuth2AccessTokenManager<OAuth2AccessToken>(storage)

when: "I ask for a new access token"
tokenManager.grantNewAccessToken(grant).toBlocking().value()
tokenManager.grantNewAccessToken(grant).blockingGet()

then: "The storage is asked to save the token"
1 * storage.storeAccessToken(accessToken)
Expand Down Expand Up @@ -170,7 +170,7 @@ class OAuth2AccessTokenManagerGetValidAccessTokenSpecs extends Specification {
OAuth2AccessTokenManager tokenManager = new OAuth2AccessTokenManager<OAuth2AccessToken>(storage)

when: "I ask for a valid access token"
OAuth2AccessToken validToken = tokenManager.getValidAccessToken(grant).toBlocking().value()
OAuth2AccessToken validToken = tokenManager.getValidAccessToken(grant).blockingGet()

then: "The I receive the non-expired token"
validToken == accessToken
Expand Down
@@ -1,4 +1,4 @@
package de.rheinfabrik.heimdall
package de.rheinfabrik.heimdall2

import com.google.gson.Gson
import spock.lang.Specification
Expand Down
@@ -1,4 +1,4 @@
package de.rheinfabrik.heimdall.grants
package de.rheinfabrik.heimdall2.grants

import spock.lang.Specification
import spock.lang.Title
Expand Down
@@ -1,4 +1,4 @@
package de.rheinfabrik.heimdall.grants
package de.rheinfabrik.heimdall2.grants

import spock.lang.Specification
import spock.lang.Title
Expand Down
@@ -1,4 +1,4 @@
package de.rheinfabrik.heimdall.grants
package de.rheinfabrik.heimdall2.grants

import spock.lang.Specification
import spock.lang.Title
Expand Down
@@ -1,4 +1,4 @@
package de.rheinfabrik.heimdall.grants
package de.rheinfabrik.heimdall2.grants

import spock.lang.Specification
import spock.lang.Title
Expand Down
@@ -1,4 +1,4 @@
package de.rheinfabrik.heimdall.grants
package de.rheinfabrik.heimdall2.grants

import spock.lang.Specification
import spock.lang.Title
Expand Down
@@ -1,4 +1,4 @@
package de.rheinfabrik.heimdall;
package de.rheinfabrik.heimdall2;

public class EmptyTestClass {
// This is an empty class. It exists only because the gradle compileTestGroovy
Expand Down

0 comments on commit 8e37578

Please sign in to comment.