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

Upgrade to Android Gradle Plugin 4.2.0 #117

Closed
wants to merge 1 commit 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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.idea
/.gradle
.gradle
build/
/out
/_site
Expand Down
17 changes: 9 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
subprojects {
apply from: "../gradle/dependencies.gradle"
apply plugin: 'dependencies'

buildscript {
repositories {
jcenter()
mavenLocal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
maven { url 'https://maven.google.com' }
if (System.getenv("INTERNAL_MAVEN_URL")) {
maven { url INTERNAL_MAVEN_URL }
}
google()
gradlePluginPortal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}
dependencies {
classpath dep.nexusPlugin
classpath dep.androidPlugin
classpath dep.groovyPlugin
classpath dep.kotlinPlugin
classpath dep.okreplayPlugin
classpath dep.gradleMavenPublishPlugin
}
}

allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
mavenLocal()
if (System.getenv("INTERNAL_MAVEN_URL")) {
maven { url INTERNAL_MAVEN_URL }
}
google()
gradlePluginPortal()
mavenCentral()
}
}
}
3 changes: 3 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id 'groovy-gradle-plugin'
}
Empty file added buildSrc/settings.gradle
Empty file.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ext.versions = [
okreplayVersion : VERSION_NAME,
kotlinVersion : '1.3.50',
okhttpVersion : '3.12.2',
appCompatVersion: '1.0.2'
kotlinVersion : '1.5.32',
okhttpVersion : '4.9.3',
appCompatVersion: '1.4.1'
]
ext {
isSnapshot = version.endsWith("-SNAPSHOT")
Expand All @@ -12,24 +12,25 @@ ext {
dep = [
// Build and upload with:
// ./gradlew clean assemble sourcesJar androidSourcesJar javadocsJar androidJavadocsJar uploadArchives --no-daemon --no-parallel
gradleMavenPublishPlugin : 'com.vanniktech:gradle-maven-publish-plugin:0.11.1',
androidPlugin : 'com.android.tools.build:gradle:3.6.0',
groovyPlugin : 'org.codehaus.groovy:groovy-android-gradle-plugin:2.0.1',
gradleMavenPublishPlugin : 'com.vanniktech:gradle-maven-publish-plugin:0.18.0',
androidPlugin : 'com.android.tools.build:gradle:4.2.0',
nexusPlugin : 'com.bmuschko:gradle-nexus-plugin:2.3.1',
appcompat : "androidx.appcompat:appcompat:$versions.appCompatVersion",
androidXAnnotations : "androidx.annotation:annotation:1.0.1",
groovy : "org.codehaus.groovy:groovy-all:2.4.5:indy",
guava : "com.google.guava:guava:25.0-android",
guava_jre : "com.google.guava:guava:25.0-jre",
appcompat : "androidx.appcompat:appcompat:1.4.1",
androidXAnnotations : "androidx.annotation:annotation:1.3.0",
guava : "com.google.guava:guava:31.0.1-android",
guava_jre : "com.google.guava:guava:31.0.1-jre",
ddmlib : 'com.android.tools.ddms:ddmlib:25.3.0',
junit : "junit:junit:4.12",
junit : "junit:junit:4.13.2",
cglib : "cglib:cglib-nodep:2.2.2",
jsr305 : "com.google.code.findbugs:jsr305:3.0.2",
mockito : 'org.mockito:mockito-core:2.7.13',
okio : 'com.squareup.okio:okio:1.17.2',
okhttp : "com.squareup.okhttp3:okhttp:$versions.okhttpVersion",
okhttp_bom : "com.squareup.okhttp3:okhttp-bom:$versions.okhttpVersion",
okhttp : "com.squareup.okhttp3:okhttp",
loggingInterceptor : "com.squareup.okhttp3:logging-interceptor",
mockWebServer : "com.squareup.okhttp3:mockwebserver:$versions.okhttpVersion",
snakeYaml : "org.yaml:snakeyaml:1.16",
kotlinCoroutines :"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0",
kotlinStdLib : "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlinVersion",
okreplayPlugin : "com.airbnb.okreplay:gradle-plugin:latest.release",
kotlinPlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion",
Expand All @@ -45,8 +46,8 @@ ext {
]

androidConfig = [
compileSdkVersion: 28,
compileSdkVersion: 31,
minSdkVersion : 14,
targetSdkVersion : 28
targetSdkVersion : 31
]
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROJECT_DESCRIPTION=OkReplay lets you record and replay OkHttp network interaction your Android application.
GROUP=com.airbnb.okreplay
VERSION_NAME=1.6.0-SNAPSHOT
VERSION_NAME=1.7.0-SNAPSHOT
POM_URL=https://github.com/airbnb/okreplay
POM_SCM_URL=https://github.com/airbnb/okreplay
POM_SCM_CONNECTION=scm:git://github.com/airbnb/okreplay.git
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.2-all.zip
6 changes: 4 additions & 2 deletions okreplay-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ apply plugin: 'com.vanniktech.maven.publish'
project.group = GROUP
project.version = VERSION_NAME

sourceCompatibility = 1.7
targetCompatibility = 1.7
sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
implementation dep.kotlinStdLib
implementation dep.snakeYaml
implementation(platform(dep.okhttp_bom))
implementation dep.okhttp
implementation dep.jsr305
implementation dep.guava_jre
}
6 changes: 3 additions & 3 deletions okreplay-core/src/main/java/okreplay/AbstractMessage.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package okreplay

import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okreplay.Util.CONTENT_TYPE
import okreplay.Util.isNullOrEmpty
import java.nio.charset.Charset
Expand All @@ -12,7 +12,7 @@ internal abstract class AbstractMessage : Message {
return if (isNullOrEmpty(header)) {
DEFAULT_CONTENT_TYPE
} else {
MediaType.parse(header!!)!!.toString()
header!!.toMediaTypeOrNull()!!.toString()
}
}

Expand All @@ -22,7 +22,7 @@ internal abstract class AbstractMessage : Message {
// TODO: this isn't valid for non-text data – this method should return String?
UTF_8
} else {
MediaType.parse(header!!)!!.charset() ?: UTF_8
header!!.toMediaTypeOrNull()!!.charset() ?: UTF_8
}
}

Expand Down
18 changes: 10 additions & 8 deletions okreplay-core/src/main/java/okreplay/OkReplayInterceptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import java.util.logging.Logger

import okhttp3.Interceptor
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.Protocol
import okhttp3.ResponseBody
import okhttp3.ResponseBody.Companion.toResponseBody

import okreplay.Util.VIA

Expand All @@ -27,14 +29,14 @@ class OkReplayInterceptor : Interceptor {
return replayResponse(request, tape, recordedRequest)
} else {
LOG.warning("no matching request found on tape '${tape.name}' for " +
"request ${request.method()} ${request.url()}")
"request ${request.method} ${request.url}")
if (tape.mode == TapeMode.READ_ONLY_QUIET) {
return buildResponse(request, 404, "No matching response")
}
// If the tape isn't writeable, abandon this request. This prevents us from
// talking to the server for non-mutable tapes.
if (!tape.isWritable) {
throwTapeNotWritable(request.method() + " " + request.url().toString())
throwTapeNotWritable(request.method + " " + request.url.toString())
}
// Continue the request and attempt to write the response to the tape.
return recordResponse(request, tape, recordedRequest, chain.proceed(request))
Expand Down Expand Up @@ -68,14 +70,14 @@ class OkReplayInterceptor : Interceptor {
var okhttpResponse = okhttpResponse
okhttpResponse = setOkReplayHeader(okhttpResponse, "REC")
okhttpResponse = setViaHeader(okhttpResponse)
LOG.info("Recording request ${request.method()} ${request.url()} to tape '${tape.name}'")
val bodyClone = OkHttpResponseAdapter.cloneResponseBody(okhttpResponse.body()!!)
LOG.info("Recording request ${request.method} ${request.url} to tape '${tape.name}'")
val bodyClone = OkHttpResponseAdapter.cloneResponseBody(okhttpResponse.body!!)
val recordedResponse = OkHttpResponseAdapter.adapt(okhttpResponse, bodyClone)
tape.record(recordedRequest, recordedResponse)
okhttpResponse = okhttpResponse.newBuilder()
.body(OkHttpResponseAdapter.cloneResponseBody(okhttpResponse.body()!!))
.body(OkHttpResponseAdapter.cloneResponseBody(okhttpResponse.body!!))
.build()
okhttpResponse.body()!!.close()
okhttpResponse.body!!.close()
return okhttpResponse
}

Expand All @@ -88,7 +90,7 @@ class OkReplayInterceptor : Interceptor {
.protocol(Protocol.HTTP_1_1) //
.code(code) //
.message("") //
.body(ResponseBody.create(MediaType.parse("text/plain"), message)) //
.body(message.toResponseBody("text/plain".toMediaTypeOrNull())) //
.request(request) //
.build()
}
Expand All @@ -113,7 +115,7 @@ class OkReplayInterceptor : Interceptor {
}

private fun isHostIgnored(request: okhttp3.Request): Boolean {
return configuration!!.ignoreHosts.contains(request.url().host())
return configuration!!.ignoreHosts.contains(request.url.host)
}

private fun setViaHeader(response: okhttp3.Response): okhttp3.Response {
Expand Down
5 changes: 4 additions & 1 deletion okreplay-core/src/main/java/okreplay/RecordedRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

import static okreplay.Util.CONTENT_TYPE;

class RecordedRequest extends RecordedMessage implements Request {
import com.google.common.annotations.VisibleForTesting;

@VisibleForTesting
public class RecordedRequest extends RecordedMessage implements Request {
private final String method;
private final HttpUrl url;

Expand Down
5 changes: 4 additions & 1 deletion okreplay-core/src/main/java/okreplay/RecordedResponse.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package okreplay;

import com.google.common.annotations.VisibleForTesting;

import java.io.IOException;
import java.util.Map;

Expand All @@ -8,7 +10,8 @@
import okhttp3.Protocol;
import okhttp3.ResponseBody;

class RecordedResponse extends RecordedMessage implements Response {
@VisibleForTesting
public class RecordedResponse extends RecordedMessage implements Response {
private final int code;
private final Protocol protocol;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package okreplay;

import com.google.common.annotations.VisibleForTesting;

import java.util.Date;

public class YamlRecordedInteraction {
private final Date recorded;
private final YamlRecordedRequest request;
private final YamlRecordedResponse response;
@VisibleForTesting
public final Date recorded;
final YamlRecordedRequest request;
@VisibleForTesting
public final YamlRecordedResponse response;
private transient RecordedInteraction immutableInteraction;

YamlRecordedInteraction(Date recorded, YamlRecordedRequest request,
Expand Down
5 changes: 4 additions & 1 deletion okreplay-core/src/main/java/okreplay/YamlTapeLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

import static org.yaml.snakeyaml.DumperOptions.FlowStyle.BLOCK;

class YamlTapeLoader implements TapeLoader<YamlTape> {
import com.google.common.annotations.VisibleForTesting;

@VisibleForTesting
public class YamlTapeLoader implements TapeLoader<YamlTape> {
private static final Logger LOG = Logger.getLogger(YamlTapeLoader.class.getSimpleName());
private final TapeRoot tapeRoot;

Expand Down
9 changes: 9 additions & 0 deletions okreplay-espresso/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ android {
defaultConfig {
minSdkVersion androidConfig.minSdkVersion
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {
Expand Down
2 changes: 2 additions & 0 deletions okreplay-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ test {
testLogging.showStandardStreams = isCi
}

/*
validateTaskProperties {
failOnWarning = true
}
*/
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package okreplay

import com.android.build.gradle.internal.LoggerWrapper
import com.android.builder.testing.ConnectedDeviceProvider
import com.android.build.gradle.internal.testing.ConnectedDeviceProvider
import com.android.builder.testing.api.DeviceException
import org.gradle.api.logging.Logger
import java.io.File
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package okreplay

import com.android.annotations.VisibleForTesting
import com.google.common.annotations.VisibleForTesting
import org.gradle.api.logging.Logger
import java.io.File

Expand Down
6 changes: 3 additions & 3 deletions okreplay-junit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ dependencies {
api project(":okreplay-core")
implementation dep.kotlinStdLib
implementation dep.junit
implementation dep.kotlinStdLib
implementation dep.guava_jre
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
4 changes: 3 additions & 1 deletion okreplay-junit/src/main/kotlin/okreplay/RecorderRule.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package okreplay

import com.google.common.annotations.VisibleForTesting
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.Rule
Expand All @@ -13,7 +14,8 @@ import okreplay.CaseFormat.*
* JUnit [Rule] allowing tests annotated with [OkReplay] to automatically
* activate OkReplay recording.
*/
class RecorderRule(configuration: OkReplayConfig) : Recorder(configuration), TestRule {
@VisibleForTesting
public class RecorderRule(configuration: OkReplayConfig) : Recorder(configuration), TestRule {
override fun apply(statement: Statement, description: Description): Statement {
val annotation = description.getAnnotation(OkReplay::class.java)
if (annotation != null) {
Expand Down
5 changes: 3 additions & 2 deletions okreplay-noop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ apply plugin: 'com.vanniktech.maven.publish'
project.group = GROUP
project.version = VERSION_NAME

sourceCompatibility = "1.7"
targetCompatibility = "1.7"
sourceCompatibility = "1.8"
targetCompatibility = "1.8"

dependencies {
implementation(platform(dep.okhttp_bom))
implementation dep.okhttp
}
Loading