Skip to content

Commit

Permalink
chore: Upgrade Gradle, AGP, and KtLint (#2172)
Browse files Browse the repository at this point in the history
* Remove deprecated maven project

* Fix task name grep

* Upgrade Gradle to 7.5.1

* Upgrade AGP

* Add VERSION_NAME back to BuildConfig

This was removed for library projects in AGP 4.1. We may consider renaming this in the future to disambiguate the Amplify version and the application version.

* Update KtLint and fix all new lint errors

* Use JDK11 on codebuild

* Use JDK11 in workflows

* Upgrade compileSdkVersion to 31

* Try using custom commands to install Android SDK 31

* Update device farm buildspec with manual Android SDK install

* Fix additional ktlint errors

* Upgrade Desugar to JDK11-compatible version

* Upgrade Robolectric

* Set locale explicitly to match expectation
  • Loading branch information
mattcreaser authored Dec 13, 2022
1 parent dfb5b55 commit dee1a81
Show file tree
Hide file tree
Showing 27 changed files with 324 additions and 293 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov_code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Setup Java
uses: actions/setup-java@v3
with:
java-version: '8'
java-version: '11'
distribution: 'corretto'

- name: Run test and generate jacoco report
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 1.8
java-version: 11
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
Expand Down
3 changes: 3 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.amplifyframework.analytics.pinpoint.models

import java.util.Locale
import org.junit.Assert.assertEquals
import org.junit.Test

Expand Down Expand Up @@ -41,7 +42,7 @@ class PinpointEventTest {
eventTimestamp = 1657035956917L,
uniqueId = "UNIQUE_ID",
androidAppDetails = AndroidAppDetails("appId", "appTitle", "packageName", "versionCode", "versionName"),
androidDeviceDetails = AndroidDeviceDetails()
androidDeviceDetails = AndroidDeviceDetails(locale = Locale.US)
)
assertEquals(expectedOutput, pinpointEvent.toJsonString())
}
Expand All @@ -58,7 +59,7 @@ class PinpointEventTest {
eventTimestamp = 1657035956917L,
uniqueId = "UNIQUE_ID",
androidAppDetails = AndroidAppDetails("appId", "appTitle", "packageName", "versionCode", "versionName"),
androidDeviceDetails = AndroidDeviceDetails()
androidDeviceDetails = AndroidDeviceDetails(locale = Locale.US)
)

val pinpointEventJson =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,34 +181,32 @@ internal class KotlinAuthFacadeInternal(private val delegate: RealAWSCognitoAuth
suspend fun signInWithSocialWebUI(
provider: AuthProvider,
callingActivity: Activity
):
AuthSignInResult {
return suspendCoroutine { continuation ->
delegate.signInWithSocialWebUI(
provider,
callingActivity,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}
): AuthSignInResult {
return suspendCoroutine { continuation ->
delegate.signInWithSocialWebUI(
provider,
callingActivity,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}
}

suspend fun signInWithSocialWebUI(
provider: AuthProvider,
callingActivity: Activity,
options: AuthWebUISignInOptions
):
AuthSignInResult {
return suspendCoroutine { continuation ->
delegate.signInWithSocialWebUI(
provider,
callingActivity,
options,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}
): AuthSignInResult {
return suspendCoroutine { continuation ->
delegate.signInWithSocialWebUI(
provider,
callingActivity,
options,
{ continuation.resume(it) },
{ continuation.resumeWithException(it) }
)
}
}

suspend fun signInWithWebUI(
callingActivity: Activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ internal class RealAWSCognitoAuthPlugin(
}
}
}
authNState is AuthenticationState.SignedIn
&& authZState is AuthorizationState.SessionEstablished -> {
authNState is AuthenticationState.SignedIn &&
authZState is AuthorizationState.SessionEstablished -> {
authStateMachine.cancel(token)
val authSignInResult = AuthSignInResult(
true,
Expand Down Expand Up @@ -594,8 +594,8 @@ internal class RealAWSCognitoAuthPlugin(
val signInState = (authNState as? AuthenticationState.SigningIn)?.signInState
val challengeState = (signInState as? SignInState.ResolvingChallenge)?.challengeState
when {
authNState is AuthenticationState.SignedIn
&& authZState is AuthorizationState.SessionEstablished -> {
authNState is AuthenticationState.SignedIn &&
authZState is AuthorizationState.SessionEstablished -> {
authStateMachine.cancel(token)
val authSignInResult = AuthSignInResult(
true,
Expand Down Expand Up @@ -740,8 +740,8 @@ internal class RealAWSCognitoAuthPlugin(
authStateMachine.send(AuthenticationEvent(AuthenticationEvent.EventType.CancelSignIn()))
}
}
authNState is AuthenticationState.SignedIn
&& authZState is AuthorizationState.SessionEstablished -> {
authNState is AuthenticationState.SignedIn &&
authZState is AuthorizationState.SessionEstablished -> {
authStateMachine.cancel(token)
val authSignInResult =
AuthSignInResult(
Expand Down Expand Up @@ -1798,8 +1798,8 @@ internal class RealAWSCognitoAuthPlugin(
val authNState = authState.authNState
val authZState = authState.authZState
when {
authNState is AuthenticationState.FederatedToIdentityPool
&& authZState is AuthorizationState.SessionEstablished -> {
authNState is AuthenticationState.FederatedToIdentityPool &&
authZState is AuthorizationState.SessionEstablished -> {
authStateMachine.cancel(token)
val credential = authZState.amplifyCredential as? AmplifyCredential.IdentityPoolFederated
val identityId = credential?.identityId
Expand Down Expand Up @@ -1853,12 +1853,11 @@ internal class RealAWSCognitoAuthPlugin(
(
authNState is AuthenticationState.FederatedToIdentityPool &&
authZState is AuthorizationState.SessionEstablished
) ||
(
authZState is AuthorizationState.Error &&
authZState.exception is SessionError &&
authZState.exception.amplifyCredential is AmplifyCredential.IdentityPoolFederated
) -> {
) || (
authZState is AuthorizationState.Error &&
authZState.exception is SessionError &&
authZState.exception.amplifyCredential is AmplifyCredential.IdentityPoolFederated
) -> {
val event = AuthenticationEvent(AuthenticationEvent.EventType.ClearFederationToIdentityPool())
authStateMachine.send(event)
_clearFederationToIdentityPool(onSuccess, onError)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import java.net.HttpURLConnection
import java.net.URL
import java.net.URLEncoder
import javax.net.ssl.HttpsURLConnection
import kotlin.jvm.Throws
import kotlin.time.Duration.Companion.seconds
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand All @@ -39,39 +38,42 @@ internal object HostedUIHttpHelper {
private val json = Json { ignoreUnknownKeys = true }

@Throws(Exception::class)
fun fetchTokens(url: URL, headerParams: Map<String, String>, bodyParams: Map<String, String>):
CognitoUserPoolTokens {
val connection = (url.openConnection() as HttpsURLConnection).apply {
requestMethod = "POST"
doOutput = true
// add headers
headerParams.map { addRequestProperty(it.key, it.value) }
// add body
DataOutputStream(outputStream).use { dos ->
val requestBody = bodyParams.map {
"${URLEncoder.encode(it.key, "UTF-8")}=${URLEncoder.encode(it.value, "UTF-8")}"
}.joinToString("&")
dos.writeBytes(requestBody)
}
fun fetchTokens(
url: URL,
headerParams: Map<String, String>,
bodyParams: Map<String, String>
): CognitoUserPoolTokens {
val connection = (url.openConnection() as HttpsURLConnection).apply {
requestMethod = "POST"
doOutput = true
// add headers
headerParams.map { addRequestProperty(it.key, it.value) }
// add body
DataOutputStream(outputStream).use { dos ->
val requestBody = bodyParams.map {
"${URLEncoder.encode(it.key, "UTF-8")}=${URLEncoder.encode(it.value, "UTF-8")}"
}.joinToString("&")
dos.writeBytes(requestBody)
}
}

val responseCode = connection.responseCode
val responseCode = connection.responseCode

if (responseCode >= HttpURLConnection.HTTP_OK && responseCode < HttpURLConnection.HTTP_INTERNAL_ERROR) {
val responseStream = if (responseCode < HttpURLConnection.HTTP_MULT_CHOICE) {
connection.inputStream
} else {
connection.errorStream
}
val responseString = responseStream.bufferedReader().use(BufferedReader::readText)
return parseTokenResponse(responseString)
if (responseCode >= HttpURLConnection.HTTP_OK && responseCode < HttpURLConnection.HTTP_INTERNAL_ERROR) {
val responseStream = if (responseCode < HttpURLConnection.HTTP_MULT_CHOICE) {
connection.inputStream
} else {
throw ServiceException(
message = connection.responseMessage,
recoverySuggestion = AmplifyException.TODO_RECOVERY_SUGGESTION
)
connection.errorStream
}
val responseString = responseStream.bufferedReader().use(BufferedReader::readText)
return parseTokenResponse(responseString)
} else {
throw ServiceException(
message = connection.responseMessage,
recoverySuggestion = AmplifyException.TODO_RECOVERY_SUGGESTION
)
}
}

private fun parseTokenResponse(responseString: String): CognitoUserPoolTokens {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ internal object SignInChallengeHelper {
}
}
challengeNameType is ChallengeNameType.SmsMfa ||
challengeNameType is ChallengeNameType.CustomChallenge
|| challengeNameType is ChallengeNameType.NewPasswordRequired -> {
challengeNameType is ChallengeNameType.CustomChallenge ||
challengeNameType is ChallengeNameType.NewPasswordRequired -> {
val challenge =
AuthChallenge(challengeNameType.value, username, session, challengeParameters)
SignInEvent(SignInEvent.EventType.ReceivedChallenge(challenge))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,19 @@ object SignUpTestCaseGenerator : SerializableProvider {
ExpectationShapes.Amplify(
apiName = AuthAPI.signUp,
responseType = ResponseType.Success,
response =
AuthSignUpResult(
false,
AuthNextSignUpStep(
AuthSignUpStep.CONFIRM_SIGN_UP_STEP,
emptyMap(),
AuthCodeDeliveryDetails(
email,
AuthCodeDeliveryDetails.DeliveryMedium.EMAIL,
"attributeName"
)
),
null
).toJsonElement()
response = AuthSignUpResult(
false,
AuthNextSignUpStep(
AuthSignUpStep.CONFIRM_SIGN_UP_STEP,
emptyMap(),
AuthCodeDeliveryDetails(
email,
AuthCodeDeliveryDetails.DeliveryMedium.EMAIL,
"attributeName"
)
),
null
).toJsonElement()
)
)
)
Expand Down Expand Up @@ -131,15 +130,15 @@ object SignUpTestCaseGenerator : SerializableProvider {
apiName = AuthAPI.signUp,
responseType = ResponseType.Success,
response =
AuthSignUpResult(
true,
AuthNextSignUpStep(
AuthSignUpStep.DONE,
emptyMap(),
null
),
AuthSignUpResult(
true,
AuthNextSignUpStep(
AuthSignUpStep.DONE,
emptyMap(),
null
).toJsonElement()
),
null
).toJsonElement()
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ class AWSS3StoragePluginConfiguration private constructor(builder: Builder) {
.build()
}

fun getAWSS3PluginPrefixResolver(authCredentialsProvider: AuthCredentialsProvider):
AWSS3PluginPrefixResolver {
return awsS3PluginPrefixResolver ?: StorageAccessLevelAwarePrefixResolver(
authCredentialsProvider
)
}
fun getAWSS3PluginPrefixResolver(authCredentialsProvider: AuthCredentialsProvider): AWSS3PluginPrefixResolver {
return awsS3PluginPrefixResolver ?: StorageAccessLevelAwarePrefixResolver(
authCredentialsProvider
)
}

class Builder {
var awsS3PluginPrefixResolver: AWSS3PluginPrefixResolver? = null
Expand Down
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.0.2'
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
classpath "org.jetbrains.dokka:dokka-gradle-plugin:1.7.10"
classpath 'org.jlleitschuh.gradle:ktlint-gradle:9.4.1'
classpath 'org.jlleitschuh.gradle:ktlint-gradle:11.0.0'
classpath "org.gradle:test-retry-gradle-plugin:1.4.1"
}
}
Expand Down Expand Up @@ -66,15 +66,15 @@ task clean(type: Delete) {

ext {
buildToolsVersion = "30.0.2"
compileSdkVersion = 30
compileSdkVersion = 31
minSdkVersion = 24
targetSdkVersion = 30
awsKotlinSdkVersion = '0.17.12-beta'
fragmentVersion = '1.3.1'
navigationVersion = '2.3.4'
dependency = [
android: [
desugartools: 'com.android.tools:desugar_jdk_libs:1.0.9',
desugartools: 'com.android.tools:desugar_jdk_libs:1.2.0',
],
androidx: [
v4support: 'androidx.legacy:legacy-support-v4:1.0.0',
Expand Down Expand Up @@ -153,7 +153,7 @@ ext {
mockkandroid: 'io.mockk:mockk-android:1.12.3',
mockwebserver: 'com.squareup.okhttp3:mockwebserver:5.0.0-alpha.9',
mockitoinline: 'org.mockito:mockito-inline:3.11.2',
robolectric: 'org.robolectric:robolectric:4.5.1',
robolectric: 'org.robolectric:robolectric:4.7',
jsonassert: 'org.skyscreamer:jsonassert:1.5.0'
]
}
Expand Down Expand Up @@ -224,6 +224,8 @@ private void configureAndroidLibrary(Project project) {
includeAndroidResources = true
}
}

buildConfigField "String", "VERSION_NAME", "\"${project.ext.VERSION_NAME}\""
}

lintOptions {
Expand Down
Loading

0 comments on commit dee1a81

Please sign in to comment.