Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "/transform: prompt user to re-authenticate if credentials expire during transformation"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.openapi.actionSystem.ActionGroup
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionToolbar
import com.intellij.openapi.application.invokeLater
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.openapi.projectRoots.JavaSdkVersion
Expand Down Expand Up @@ -38,7 +39,7 @@ import javax.swing.BorderFactory
import javax.swing.JPanel

class CodeModernizerBottomWindowPanelManager(private val project: Project) : JPanel(BorderLayout()) {
private var lastShownProgressPanel: Component? = null
private var progressPanel: Component? = null
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed just to fix a detekt issue further down about exceeding max line length

val toolbar = createToolbar().apply {
targetComponent = this@CodeModernizerBottomWindowPanelManager
component.border = BorderFactory.createCompoundBorder(
Expand All @@ -62,14 +63,16 @@ class CodeModernizerBottomWindowPanelManager(private val project: Project) : JPa
}

private fun setUI(function: () -> Unit) {
lastShownProgressPanel = this.components.firstOrNull { it == fullSizeLoadingPanel || it == buildProgressSplitterPanelManager } ?: lastShownProgressPanel
removeAll()
add(BorderLayout.WEST, toolbar.component)
add(BorderLayout.NORTH, banner)
function.invoke()
updateRunTime()
revalidate()
repaint()
runInEdt {
progressPanel = this.components.firstOrNull { it == fullSizeLoadingPanel || it == buildProgressSplitterPanelManager } ?: progressPanel
removeAll()
add(BorderLayout.WEST, toolbar.component)
add(BorderLayout.NORTH, banner)
function.invoke()
updateRunTime()
revalidate()
repaint()
}
}

private fun updateRunTime(now: Instant? = null) {
Expand Down Expand Up @@ -173,8 +176,8 @@ class CodeModernizerBottomWindowPanelManager(private val project: Project) : JPa
}

fun showUnalteredJobUI() = setUI {
if (lastShownProgressPanel != null) {
add(BorderLayout.CENTER, lastShownProgressPanel)
if (progressPanel != null) {
add(BorderLayout.CENTER, progressPanel)
} else {
add(BorderLayout.CENTER, fullSizeLoadingPanel)
fullSizeLoadingPanel.progressIndicatorLabel.text = "No jobs active"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package software.aws.toolkits.jetbrains.services.codemodernizer.utils

import com.fasterxml.jackson.module.kotlin.readValue
import com.intellij.notification.NotificationAction
import com.intellij.openapi.project.Project
import com.intellij.serviceContainer.AlreadyDisposedException
import kotlinx.coroutines.delay
Expand All @@ -23,12 +24,14 @@
import software.aws.toolkits.core.utils.Waiters.waitUntil
import software.aws.toolkits.jetbrains.services.codemodernizer.CodeTransformTelemetryManager
import software.aws.toolkits.jetbrains.services.codemodernizer.client.GumbyClient
import software.aws.toolkits.jetbrains.services.codemodernizer.commands.CodeTransformMessageListener
import software.aws.toolkits.jetbrains.services.codemodernizer.constants.BILLING_RATE
import software.aws.toolkits.jetbrains.services.codemodernizer.constants.JOB_STATISTICS_TABLE_KEY
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerArtifact.Companion.MAPPER
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeTransformType
import software.aws.toolkits.jetbrains.services.codemodernizer.model.JobId
import software.aws.toolkits.jetbrains.services.codemodernizer.model.PlanTable
import software.aws.toolkits.jetbrains.utils.notifyStickyWarn
import software.aws.toolkits.resources.message
import java.time.Duration
import java.util.Locale
Expand Down Expand Up @@ -64,8 +67,7 @@
val maxRefreshes = 10
var numRefreshes = 0

// We refresh token at the start of polling, but for some long jobs that runs for 30 minutes plus, tokens may need to be
// refreshed again when AccessDeniedException or InvalidGrantException are caught.
// refresh token at start of polling since local build just prior can take a long time
refreshToken(project)

try {
Expand Down Expand Up @@ -113,8 +115,17 @@
refreshToken(project)
return@waitUntil state
} catch (e: InvalidGrantException) {
if (numRefreshes++ > maxRefreshes) throw e
refreshToken(project)
CodeTransformMessageListener.instance.onCheckAuth()
notifyStickyWarn(
message("codemodernizer.notification.warn.expired_credentials.title"),

Check warning on line 120 in plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
message("codemodernizer.notification.warn.expired_credentials.content"),

Check warning on line 121 in plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
project,
listOf(
NotificationAction.createSimpleExpiring(message("codemodernizer.notification.warn.action.reauthenticate")) {

Check warning on line 124 in plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead

Check warning

Code scanning / QDJVMC

Usage of redundant or deprecated syntax or deprecated symbols Warning

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
CodeTransformMessageListener.instance.onReauthStarted()
}
)
)
return@waitUntil state
} finally {
delay(sleepDurationMillis)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.mockk.every
import io.mockk.just
import io.mockk.mockkStatic
import io.mockk.runs
import io.mockk.verify
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
Expand All @@ -19,14 +20,17 @@ import software.amazon.awssdk.services.codewhispererruntime.model.AccessDeniedEx
import software.amazon.awssdk.services.codewhispererruntime.model.TransformationProgressUpdate
import software.amazon.awssdk.services.codewhispererruntime.model.TransformationStatus
import software.amazon.awssdk.services.ssooidc.model.InvalidGrantException
import software.aws.toolkits.jetbrains.services.codemodernizer.commands.CodeTransformMessageListener
import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeTransformType
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getBillingText
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getTableMapping
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.parseBuildFile
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.pollTransformationStatusAndPlan
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.refreshToken
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.validateSctMetadata
import software.aws.toolkits.jetbrains.utils.notifyStickyWarn
import software.aws.toolkits.jetbrains.utils.rules.addFileToModule
import software.aws.toolkits.resources.message
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.io.path.createTempFile

Expand Down Expand Up @@ -114,18 +118,18 @@ class CodeWhispererCodeModernizerUtilsTest : CodeWhispererCodeModernizerTestBase
}

@Test
fun `refresh on invalid grant`() {
fun `show re-auth notification on invalid grant exception`() {
val mockInvalidGrantException = Mockito.mock(InvalidGrantException::class.java)

mockkStatic(::refreshToken)
every { refreshToken(any()) } just runs
mockkStatic(::notifyStickyWarn)
every { notifyStickyWarn(any(), any(), any(), any(), any()) } just runs

Mockito.doThrow(
mockInvalidGrantException
).doReturn(
exampleGetCodeMigrationResponse,
exampleGetCodeMigrationResponse.replace(TransformationStatus.STARTED),
exampleGetCodeMigrationResponse.replace(TransformationStatus.COMPLETED), // Should stop before this point
exampleGetCodeMigrationResponse.replace(TransformationStatus.COMPLETED),
).whenever(clientAdaptorSpy).getCodeModernizationJob(any())

Mockito.doReturn(exampleGetCodeMigrationPlanResponse)
Expand All @@ -152,7 +156,7 @@ class CodeWhispererCodeModernizerUtilsTest : CodeWhispererCodeModernizerTestBase
TransformationStatus.STARTED,
)
assertThat(expected).isEqualTo(mutableList)
io.mockk.verify { refreshToken(any()) }
verify { notifyStickyWarn(message("codemodernizer.notification.warn.expired_credentials.title"), any(), any(), any(), any()) }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ codemodernizer.notification.warn.download_failed_invalid_artifact=Amazon Q was u
codemodernizer.notification.warn.download_failed_other.content=Amazon Q ran into an issue while trying to download your {0}. Please try again. {1}
codemodernizer.notification.warn.download_failed_ssl.content=Please make sure all your certificates for your proxy client have been set up correctly for your IDE.
codemodernizer.notification.warn.download_failed_wildcard.content=Check your IDE proxy settings and remove any wildcard (*) references, and then try viewing the diff again.
codemodernizer.notification.warn.expired_credentials.content=Unable to check transformation status as your credentials expired. Try signing out of Amazon Q and signing back in again if 'Reauthenticate' below does not work.
codemodernizer.notification.warn.expired_credentials.title=Your connection to Q has expired
codemodernizer.notification.warn.invalid_project.description.reason.missing_content_roots=None of your open modules are supported for code transformation with Amazon Q. Amazon Q can upgrade Java 8, Java 11, Java 17, and Java 21 projects built on Maven, with content roots configured.
codemodernizer.notification.warn.invalid_project.description.reason.not_logged_in=Amazon Q cannot start the transformation as you are not logged in with Identity Center or Builder ID. Also ensure that you are not using IntelliJ version 232.8660.185 and that you are not developing on a remote host (uncommon).
Expand Down
Loading