Skip to content

Commit

Permalink
Merge okhttp-android into okhttp (#8635)
Browse files Browse the repository at this point in the history
* Merge okhttp-android into okhttp.

Since :okhttp is kmp, it isn't required to be separate. And also the okhttp-android/jvm artifact naming conflicts with it.
  • Loading branch information
yschimke authored Dec 30, 2024
1 parent b669048 commit 1786dd7
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 187 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ jobs:
uses: gradle/actions/setup-gradle@v4

- name: Gradle cache
run: ./gradlew -PandroidBuild=true :okhttp-android:test
run: ./gradlew -PandroidBuild=true :android-test:test

- name: AVD cache
uses: actions/cache@v4
Expand All @@ -545,7 +545,7 @@ jobs:
with:
api-level: ${{ matrix.api-level }}
arch: ${{ matrix.api-level == '34' && 'x86_64' || 'x86' }}
script: ./gradlew -PandroidBuild=true :okhttp-android:connectedCheck :android-test:connectedCheck
script: ./gradlew -PandroidBuild=true :android-test:connectedCheck
env:
API_LEVEL: ${{ matrix.api-level }}

Expand Down
1 change: 0 additions & 1 deletion android-test-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ android {
dependencies {
implementation(libs.playservices.safetynet)
implementation(projects.okhttp)
implementation(projects.okhttpAndroid)
implementation(libs.androidx.activity)

androidTestImplementation(libs.androidx.junit)
Expand Down
17 changes: 15 additions & 2 deletions android-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,20 @@ dependencies {
implementation(libs.kotlin.reflect)
implementation(libs.playservices.safetynet)
implementation(projects.okhttp)
implementation(projects.okhttpAndroid)

testImplementation(libs.junit)
testImplementation(libs.junit.ktx)
testImplementation(libs.assertk)
testImplementation(projects.okhttpTls)
testImplementation(projects.loggingInterceptor)
testImplementation(libs.androidx.test.runner)
testImplementation(libs.robolectric)
testImplementation(libs.androidx.espresso.core)
testImplementation(libs.squareup.okio.fakefilesystem)
testImplementation(projects.okhttpTestingSupport)
testImplementation(rootProject.libs.conscrypt.openjdk)
testImplementation(rootProject.libs.junit.jupiter.engine)
testImplementation(rootProject.libs.junit.vintage.engine)

androidTestImplementation(projects.okhttpTestingSupport) {
exclude("org.openjsse", "openjsse")
Expand All @@ -72,13 +85,13 @@ dependencies {
androidTestImplementation(libs.bouncycastle.bcprov)
androidTestImplementation(libs.bouncycastle.bctls)
androidTestImplementation(libs.conscrypt.android)
androidTestImplementation(projects.mockwebserver3Junit4)
androidTestImplementation(projects.mockwebserver3Junit5)
androidTestImplementation(projects.okhttpBrotli)
androidTestImplementation(projects.okhttpDnsoverhttps)
androidTestImplementation(projects.loggingInterceptor)
androidTestImplementation(projects.okhttpSse)
androidTestImplementation(projects.okhttpTls)
androidTestImplementation(projects.okhttpAndroid)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(libs.httpClient5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
package okhttp3.android
package okhttp.android.test

import android.content.Context
import android.net.ConnectivityManager
Expand All @@ -36,6 +36,7 @@ import okhttp3.AsyncDns
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.android.AndroidAsyncDns
import okhttp3.tls.HandshakeCertificates
import okhttp3.tls.HeldCertificate
import okio.IOException
Expand Down
1 change: 1 addition & 0 deletions android-test/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
xmlns:tools="http://schemas.android.com/tools" package="okhttp.android.test">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application android:usesCleartextTraffic="true" tools:targetApi="m"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.android
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")

package okhttp.android.test

import assertk.assertFailure
import assertk.assertions.hasMessage
import assertk.assertions.isInstanceOf
import java.net.UnknownHostException
import okhttp3.AsyncDns
import okhttp3.android.AndroidAsyncDns
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
package okhttp3.android
package okhttp.android.test

import android.util.Log
import assertk.assertThat
Expand All @@ -26,6 +26,7 @@ import okhttp3.ConnectionSpec
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.internal.platform.AndroidPlatform
import okhttp3.logging.HttpLoggingInterceptor
import okhttp3.logging.LoggingEventListener
import org.junit.Test
Expand All @@ -36,18 +37,16 @@ import org.robolectric.shadows.ShadowLog
@RunWith(RobolectricTestRunner::class)
class AndroidLoggingTest {
val clientBuilder =
OkHttpClient.Builder()
.connectionSpecs(listOf(ConnectionSpec.CLEARTEXT))
.dns {
throw UnknownHostException("shortcircuit")
}
OkHttpClient.Builder().connectionSpecs(listOf(ConnectionSpec.CLEARTEXT)).dns {
throw UnknownHostException("shortcircuit")
}

val request = Request("http://google.com/robots.txt".toHttpUrl())

@Test
fun testHttpLoggingInterceptor() {
val interceptor =
HttpLoggingInterceptor.androidLogging(tag = "testHttpLoggingInterceptor").apply {
HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BASIC
}

Expand All @@ -59,7 +58,7 @@ class AndroidLoggingTest {
// expected
}

val logs = ShadowLog.getLogsForTag("testHttpLoggingInterceptor")
val logs = ShadowLog.getLogsForTag(AndroidPlatform.Tag)
assertThat(logs.map { it.type }).containsOnly(Log.INFO)
assertThat(logs.map { it.msg }).containsExactly(
"--> GET http://google.com/robots.txt",
Expand All @@ -71,16 +70,15 @@ class AndroidLoggingTest {

@Test
fun testLoggingEventListener() {
val client =
clientBuilder.eventListenerFactory(LoggingEventListener.androidLogging(tag = "testLoggingEventListener")).build()
val client = clientBuilder.eventListenerFactory(LoggingEventListener.Factory()).build()

try {
client.newCall(request).execute()
} catch (uhe: UnknownHostException) {
// expected
}

val logs = ShadowLog.getLogsForTag("testLoggingEventListener")
val logs = ShadowLog.getLogsForTag(AndroidPlatform.Tag)
assertThat(logs.map { it.type }).containsOnly(Log.INFO)
assertThat(
logs.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.android
package okhttp.android.test

import java.security.Provider
import javax.net.ssl.SSLContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/
package okhttp3.android
package okhttp.android.test

import android.app.Application
import android.content.Context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.android
package okhttp.android.test

import android.net.DnsResolver
import android.net.Network
Expand Down
3 changes: 0 additions & 3 deletions okhttp-android/Module.md

This file was deleted.

13 changes: 0 additions & 13 deletions okhttp-android/README.md

This file was deleted.

19 changes: 0 additions & 19 deletions okhttp-android/api/okhttp-android.api

This file was deleted.

82 changes: 0 additions & 82 deletions okhttp-android/build.gradle.kts

This file was deleted.

6 changes: 0 additions & 6 deletions okhttp-android/src/androidTest/AndroidManifest.xml

This file was deleted.

6 changes: 0 additions & 6 deletions okhttp-android/src/main/AndroidManifest.xml

This file was deleted.

36 changes: 0 additions & 36 deletions okhttp-android/src/main/kotlin/okhttp3/android/AndroidLogging.kt

This file was deleted.

12 changes: 12 additions & 0 deletions okhttp/api/android/okhttp.api
Original file line number Diff line number Diff line change
Expand Up @@ -1292,3 +1292,15 @@ public abstract class okhttp3/WebSocketListener {
public fun onOpen (Lokhttp3/WebSocket;Lokhttp3/Response;)V
}

public final class okhttp3/android/AndroidAsyncDns : okhttp3/AsyncDns {
public static final field Companion Lokhttp3/android/AndroidAsyncDns$Companion;
public fun <init> (Lokhttp3/AsyncDns$DnsClass;Landroid/net/Network;)V
public synthetic fun <init> (Lokhttp3/AsyncDns$DnsClass;Landroid/net/Network;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun query (Ljava/lang/String;Lokhttp3/AsyncDns$Callback;)V
}

public final class okhttp3/android/AndroidAsyncDns$Companion {
public final fun getIPv4 ()Lokhttp3/android/AndroidAsyncDns;
public final fun getIPv6 ()Lokhttp3/android/AndroidAsyncDns;
}

Loading

0 comments on commit 1786dd7

Please sign in to comment.