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 #118

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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 @@ -11,25 +11,29 @@ 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',
// ./gradlew clean assemble publish --no-daemon --no-parallel
gradleMavenPublishPlugin : 'com.vanniktech:gradle-maven-publish-plugin:0.18.0',
androidPlugin : 'com.android.tools.build:gradle:7.2.1',
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",
builderTestApi : 'com.android.tools.build:builder-test-api:7.2.1',
toolsCommon : 'com.android.tools:common:30.2.1',
commonsIo : 'commons-io:commons-io:2.11.0',
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 +49,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.1-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
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Wed Jul 13 13:40:38 EDT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
zipStoreBase=GRADLE_USER_HOME
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
9 changes: 0 additions & 9 deletions okreplay-core/src/main/java/okreplay/Headers.java

This file was deleted.

11 changes: 11 additions & 0 deletions okreplay-core/src/main/java/okreplay/Headers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package okreplay

object Headers {
const val X_OKREPLAY = "X-OkReplay"
const val VIA_HEADER = "OkReplay"

enum class XHeader(val headerName: String) {
HEADER_PLAY("PLAY"),
HEADER_REC("REC"),
}
}
32 changes: 16 additions & 16 deletions okreplay-core/src/main/java/okreplay/OkReplayInterceptor.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package okreplay

import java.io.IOException
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.Headers.XHeader.HEADER_PLAY
import okreplay.Headers.XHeader.HEADER_REC
import okreplay.Util.VIA
import java.io.IOException
import java.util.logging.Logger

class OkReplayInterceptor : Interceptor {
private var configuration: OkReplayConfig? = null
Expand All @@ -27,14 +27,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 All @@ -54,7 +54,7 @@ class OkReplayInterceptor : Interceptor {
recordedRequest.method(), recordedRequest.url().toString(), tape.name))
val recordedResponse = tape.play(recordedRequest)
var okhttpResponse = OkHttpResponseAdapter.adapt(request, recordedResponse)
okhttpResponse = setOkReplayHeader(okhttpResponse, "PLAY")
okhttpResponse = setOkReplayHeader(okhttpResponse, HEADER_PLAY.headerName)
okhttpResponse = setViaHeader(okhttpResponse)
return okhttpResponse
}
Expand All @@ -66,16 +66,16 @@ class OkReplayInterceptor : Interceptor {
okhttpResponse: okhttp3.Response
): okhttp3.Response {
var okhttpResponse = okhttpResponse
okhttpResponse = setOkReplayHeader(okhttpResponse, "REC")
okhttpResponse = setOkReplayHeader(okhttpResponse, HEADER_REC.headerName)
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 +88,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 +113,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_11
targetCompatibility JavaVersion.VERSION_11
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_11
}
}

dependencies {
Expand Down
8 changes: 4 additions & 4 deletions okreplay-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ apply plugin: 'org.jetbrains.kotlin.jvm'
apply plugin: 'java-gradle-plugin'
apply plugin: 'com.vanniktech.maven.publish'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

dependencies {
compileOnly gradleApi()
compileOnly dep.androidPlugin
compileOnly dep.ddmlib
implementation dep.kotlinStdLib
implementation dep.builderTestApi
implementation dep.toolsCommon
implementation dep.commonsIo
testImplementation gradleTestKit()
testImplementation dep.androidPlugin
testImplementation dep.ddmlib
Expand All @@ -23,6 +23,6 @@ test {
testLogging.showStandardStreams = isCi
}

validateTaskProperties {
validatePlugins {
failOnWarning = true
}
Loading