From 1fb6d89dee9c1ff29648c46031e4e5078d58c650 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Fri, 29 Mar 2024 14:09:26 -0700 Subject: [PATCH 01/12] Chore - refactor util files for separation of concerns --- .../clients/FeatureDevClient.kt | 2 +- .../codemodernizer/ArtifactHandler.kt | 12 +- .../codemodernizer/CodeModernizerManager.kt | 17 +- .../codemodernizer/CodeModernizerSession.kt | 18 +- .../CodeTransformTelemetryManager.kt | 16 +- .../codemodernizer/CodeTransformUtils.kt | 286 ------------------ .../auth/CodeTransformAuthUtils.kt | 2 +- .../constants/CodeTransformChatItems.kt | 2 +- .../controller/CodeTransformChatController.kt | 6 +- .../model/CodeModernizerArtifact.kt | 2 +- .../state/CodeModernizerState.kt | 4 +- .../components/PreCodeTransformUserDialog.kt | 4 +- .../utils/CodeTransformApiUtils.kt | 116 +++++++ .../utils/CodeTransformFileUtils.kt | 78 +++++ .../utils/CodeTransformUtils.kt | 74 +++++ .../utils/CodeTransformValidationUtils.kt | 24 ++ .../codemodernizer/utils/ModuleUtils.kt | 20 ++ .../{ModuleUtils.kt => utils/ProjectUtils.kt} | 23 +- .../CodeWhispererCodeModernizerTest.kt | 4 +- .../CodeWhispererCodeModernizerUtilsTest.kt | 6 +- 20 files changed, 382 insertions(+), 334 deletions(-) delete mode 100644 plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformUtils.kt create mode 100644 plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt create mode 100644 plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformFileUtils.kt create mode 100644 plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformUtils.kt create mode 100644 plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformValidationUtils.kt create mode 100644 plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ModuleUtils.kt rename plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/{ModuleUtils.kt => utils/ProjectUtils.kt} (80%) diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/clients/FeatureDevClient.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/clients/FeatureDevClient.kt index 70e8232034..a5f91a3d0a 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/clients/FeatureDevClient.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/clients/FeatureDevClient.kt @@ -35,7 +35,7 @@ import software.aws.toolkits.jetbrains.core.awsClient import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection import software.aws.toolkits.jetbrains.services.amazonq.clients.AmazonQStreamingClient -import software.aws.toolkits.jetbrains.services.codemodernizer.calculateTotalLatency +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency import java.time.Instant import software.amazon.awssdk.services.codewhispererruntime.model.ChatTriggerType as SyncChatTriggerType diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt index 29afb72012..93864f7dc8 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt @@ -152,7 +152,11 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G message("codemodernizer.notification.warn.view_diff_failed.title"), message("codemodernizer.notification.warn.view_diff_failed.content"), project, - listOf(openTroubleshootingGuideNotificationAction(TROUBLESHOOTING_URL_DOWNLOAD_DIFF)), + listOf( + software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction( + software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_DOWNLOAD_DIFF + ) + ), ) } @@ -162,7 +166,11 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G message("codemodernizer.notification.warn.view_summary_failed.title"), message("codemodernizer.notification.warn.view_summary_failed.content"), project, - listOf(openTroubleshootingGuideNotificationAction(TROUBLESHOOTING_URL_DOWNLOAD_DIFF)), + listOf( + software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction( + software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_DOWNLOAD_DIFF + ) + ), ) } diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt index 43e3a7a9b8..e5258c8c85 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt @@ -47,6 +47,11 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeModerni import software.aws.toolkits.jetbrains.services.codemodernizer.state.StateFlags import software.aws.toolkits.jetbrains.services.codemodernizer.state.buildState import software.aws.toolkits.jetbrains.services.codemodernizer.toolwindow.CodeModernizerBottomToolWindowFactory +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedBuildFilesWithSupportedJdk +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedJavaMappings +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedModules +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.tryGetJdk import software.aws.toolkits.jetbrains.ui.feedback.FeedbackDialog import software.aws.toolkits.jetbrains.utils.isRunningOnRemoteBackend import software.aws.toolkits.jetbrains.utils.notifyStickyError @@ -153,7 +158,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo message("codemodernizer.notification.warn.invalid_project.description.reason.no_valid_files", supportedBuildFileNames.joinToString()), InvalidTelemetryReason( CodeTransformPreValidationError.NonMavenProject, - if (isGradleProject(project)) "Gradle build" else "other build" + if (software.aws.toolkits.jetbrains.services.codemodernizer.utils.isGradleProject(project)) "Gradle build" else "other build" ) ) } @@ -278,7 +283,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo return@launch } try { - val plan = if (currentJobResult.status() in STATES_WHERE_PLAN_EXIST) { + val plan = if (currentJobResult.status() in software.aws.toolkits.jetbrains.services.codemodernizer.utils.STATES_WHERE_PLAN_EXIST) { try { delay(1000) session.fetchPlan(lastJobId).transformationPlan() @@ -320,7 +325,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo message("codemodernizer.notification.warn.maven_failed.title"), message("codemodernizer.notification.warn.maven_failed.content"), project, - listOf(openTroubleshootingGuideNotificationAction(TROUBLESHOOTING_URL_MAVEN_COMMANDS), displayFeedbackNotificationAction()), + listOf(software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction(software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_MAVEN_COMMANDS), displayFeedbackNotificationAction()), ) } @@ -589,13 +594,13 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo message("codemodernizer.notification.warn.maven_failed.title"), message("codemodernizer.notification.warn.maven_failed.content"), project, - listOf(openTroubleshootingGuideNotificationAction(TROUBLESHOOTING_URL_MAVEN_COMMANDS), displayFeedbackNotificationAction()), + listOf(software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction(software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_MAVEN_COMMANDS), displayFeedbackNotificationAction()), ) is CodeModernizerJobCompletedResult.JobAbortedZipTooLarge -> notifyStickyInfo( message("codemodernizer.notification.warn.zip_too_large.title"), message("codemodernizer.notification.warn.zip_too_large.content"), project, - listOf(openTroubleshootingGuideNotificationAction(TROUBLESHOOTING_URL_PREREQUISITES), displayFeedbackNotificationAction()), + listOf(software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction(software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_PREREQUISITES), displayFeedbackNotificationAction()), ) is CodeModernizerJobCompletedResult.Stopped -> notifyStickyInfo( message("codemodernizer.notification.info.transformation_stop.title"), @@ -682,7 +687,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo message("codemodernizer.validationerrordialog.description.title"), message("codemodernizer.validationerrordialog.description.main"), project, - listOf(openTroubleshootingGuideNotificationAction(TROUBLESHOOTING_URL_PREREQUISITES)), + listOf(software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction(software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_PREREQUISITES)), ) } diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt index c8896f2562..5dfde6cf81 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt @@ -29,6 +29,13 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.model.MavenCopyCo import software.aws.toolkits.jetbrains.services.codemodernizer.model.ZipCreationResult import software.aws.toolkits.jetbrains.services.codemodernizer.plan.CodeModernizerPlanEditorProvider import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeModernizerSessionState +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.STATES_AFTER_INITIAL_BUILD +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.STATES_AFTER_STARTED +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.STATES_WHERE_JOB_STOPPED_PRE_PLAN_READY +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.STATES_WHERE_PLAN_EXIST +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.pollTransformationStatusAndPlan +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.toTransformationLanguage import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.CodeWhispererCodeScanSession import software.aws.toolkits.resources.message import software.aws.toolkits.telemetry.CodeTransformApiNames @@ -94,6 +101,11 @@ class CodeModernizerSession( } val startTime = Instant.now() val result = sessionContext.createZipWithModuleFiles(copyResult) + val humanInTheLoopFlag = true + + if (humanInTheLoopFlag) { + + } if (result is ZipCreationResult.Missing1P) { return CodeModernizerStartJobResult.CancelledMissingDependencies @@ -214,8 +226,8 @@ class CodeModernizerSession( } private fun startJob(uploadId: String): StartTransformationResponse { - val sourceLanguage = sessionContext.sourceJavaVersion.name.toTransformationLanguage() - val targetLanguage = sessionContext.targetJavaVersion.name.toTransformationLanguage() + val sourceLanguage = uploadId.toTransformationLanguage() + val targetLanguage = uploadId.toTransformationLanguage() if (sourceLanguage == TransformationLanguage.UNKNOWN_TO_SDK_VERSION) { throw RuntimeException("Source language is not supported") } @@ -448,6 +460,4 @@ class CodeModernizerSession( fun getActiveJobId() = state.currentJobId fun fetchPlan(lastJobId: JobId) = clientAdaptor.getCodeModernizationPlan(lastJobId) - - fun didJobStart() = state.currentJobId != null } diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt index ff4f7b86c3..06efa3d247 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt @@ -13,6 +13,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.model.JobId import software.aws.toolkits.jetbrains.services.codemodernizer.model.ValidationResult import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeModernizerSessionState import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeTransformTelemetryState +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.tryGetJdk import software.aws.toolkits.telemetry.CodeTransformApiNames import software.aws.toolkits.telemetry.CodeTransformCancelSrcComponents import software.aws.toolkits.telemetry.CodeTransformJavaSourceVersionsAllowed @@ -93,15 +94,18 @@ class CodeTransformTelemetryManager(private val project: Project) { codeTransformJobId = jobId?.toString(), codeTransformSessionId = sessionId, codeTransformResultStatusMessage = codeTransformResultStatusMessage, - codeTransformRunTimeLatency = calculateTotalLatency(CodeTransformTelemetryState.instance.getStartTime(), Instant.now()), - codeTransformLocalJavaVersion = getJavaVersionFromProjectSetting(project), - codeTransformLocalMavenVersion = getMavenVersion(project), + codeTransformRunTimeLatency = software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency( + CodeTransformTelemetryState.instance.getStartTime(), + Instant.now() + ), + codeTransformLocalJavaVersion = software.aws.toolkits.jetbrains.services.codemodernizer.utils.getJavaVersionFromProjectSetting(project), + codeTransformLocalMavenVersion = software.aws.toolkits.jetbrains.services.codemodernizer.utils.getMavenVersion(project), ) fun jobCreateZipEndTime(payloadSize: Int, startTime: Instant) = CodetransformTelemetry.jobCreateZipEndTime( codeTransformTotalByteSize = payloadSize, codeTransformSessionId = sessionId, - codeTransformRunTimeLatency = calculateTotalLatency(startTime, Instant.now()), + codeTransformRunTimeLatency = software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency(startTime, Instant.now()), ) fun error(errorMessage: String) = CodetransformTelemetry.logGeneralError( @@ -126,7 +130,7 @@ class CodeTransformTelemetryManager(private val project: Project) { ) = CodetransformTelemetry.logApiLatency( codeTransformApiNames = apiName, codeTransformSessionId = sessionId, - codeTransformRunTimeLatency = calculateTotalLatency(startTime, Instant.now()), + codeTransformRunTimeLatency = software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency(startTime, Instant.now()), codeTransformUploadId = codeTransformUploadId, codeTransformJobId = codeTransformJobId, codeTransformTotalByteSize = codeTransformTotalByteSize, @@ -167,7 +171,7 @@ class CodeTransformTelemetryManager(private val project: Project) { fun jobArtifactDownloadAndDeserializeTime(downloadStartTime: Instant, jobId: JobId, totalDownloadBytes: Int, telemetryErrorMessage: String?) { CodetransformTelemetry.jobArtifactDownloadAndDeserializeTime( codeTransformSessionId = sessionId, - codeTransformRunTimeLatency = calculateTotalLatency(downloadStartTime, Instant.now()), + codeTransformRunTimeLatency = software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency(downloadStartTime, Instant.now()), codeTransformJobId = jobId.id, codeTransformTotalByteSize = totalDownloadBytes, codeTransformRuntimeError = telemetryErrorMessage, diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformUtils.kt deleted file mode 100644 index cb888e0cf3..0000000000 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformUtils.kt +++ /dev/null @@ -1,286 +0,0 @@ -// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -package software.aws.toolkits.jetbrains.services.codemodernizer - -import com.intellij.openapi.application.ApplicationInfo -import com.intellij.openapi.module.ModuleUtil -import com.intellij.openapi.project.Project -import com.intellij.openapi.vfs.VfsUtilCore -import com.intellij.openapi.vfs.VirtualFile -import com.intellij.openapi.vfs.VirtualFileManager -import com.intellij.serviceContainer.AlreadyDisposedException -import org.jetbrains.idea.maven.project.MavenProjectsManager -import org.jetbrains.plugins.gradle.settings.GradleSettings -import software.amazon.awssdk.awscore.exception.AwsServiceException -import software.amazon.awssdk.services.codewhispererruntime.model.AccessDeniedException -import software.amazon.awssdk.services.codewhispererruntime.model.CodeWhispererRuntimeException -import software.amazon.awssdk.services.codewhispererruntime.model.GetTransformationResponse -import software.amazon.awssdk.services.codewhispererruntime.model.InternalServerException -import software.amazon.awssdk.services.codewhispererruntime.model.ThrottlingException -import software.amazon.awssdk.services.codewhispererruntime.model.TransformationJob -import software.amazon.awssdk.services.codewhispererruntime.model.TransformationLanguage -import software.amazon.awssdk.services.codewhispererruntime.model.TransformationPlan -import software.amazon.awssdk.services.codewhispererruntime.model.TransformationStatus -import software.amazon.awssdk.services.codewhispererruntime.model.ValidationException -import software.aws.toolkits.core.TokenConnectionSettings -import software.aws.toolkits.core.utils.WaiterUnrecoverableException -import software.aws.toolkits.core.utils.Waiters.waitUntil -import software.aws.toolkits.core.utils.createParentDirectories -import software.aws.toolkits.core.utils.exists -import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager -import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection -import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.BearerTokenProvider -import software.aws.toolkits.jetbrains.services.codemodernizer.client.GumbyClient -import software.aws.toolkits.jetbrains.services.codemodernizer.model.JobId -import software.aws.toolkits.jetbrains.services.codemodernizer.model.MAVEN_CONFIGURATION_FILE_NAME -import software.aws.toolkits.jetbrains.utils.actions.OpenBrowserAction -import software.aws.toolkits.resources.message -import java.io.File -import java.io.FileOutputStream -import java.lang.Thread.sleep -import java.nio.file.Path -import java.time.Duration -import java.time.Instant -import java.util.concurrent.atomic.AtomicBoolean -import java.util.zip.ZipFile -import kotlin.io.path.Path - -val STATES_WHERE_PLAN_EXIST = setOf( - TransformationStatus.PLANNED, - TransformationStatus.TRANSFORMING, - TransformationStatus.TRANSFORMED, - TransformationStatus.PARTIALLY_COMPLETED, - TransformationStatus.COMPLETED, -) - -val STATES_AFTER_INITIAL_BUILD = setOf( - TransformationStatus.PREPARED, - TransformationStatus.PLANNING, - *STATES_WHERE_PLAN_EXIST.toTypedArray() -) - -val STATES_AFTER_STARTED = setOf( - TransformationStatus.STARTED, - TransformationStatus.PREPARING, - *STATES_AFTER_INITIAL_BUILD.toTypedArray(), -) - -val STATES_WHERE_JOB_STOPPED_PRE_PLAN_READY = setOf( - TransformationStatus.FAILED, - TransformationStatus.STOPPED, - TransformationStatus.STOPPING, - TransformationStatus.REJECTED, - TransformationStatus.UNKNOWN_TO_SDK_VERSION, -) - -val TERMINAL_STATES = setOf( - TransformationStatus.FAILED, - TransformationStatus.STOPPED, - TransformationStatus.REJECTED, - TransformationStatus.PARTIALLY_COMPLETED, - TransformationStatus.COMPLETED, -) - -const val TROUBLESHOOTING_URL_DOWNLOAD_DIFF = - "https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html#w24aac14c20c19c11" -const val TROUBLESHOOTING_URL_MAVEN_COMMANDS = - "https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html#w24aac14c20c19b7" -const val TROUBLESHOOTING_URL_PREREQUISITES = - "https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html#prerequisites" - -fun String.toVirtualFile() = VirtualFileManager.getInstance().findFileByUrl(VfsUtilCore.pathToUrl(this)) -fun Project.moduleFor(path: String) = ModuleUtil.findModuleForFile( - path.toVirtualFile() ?: throw RuntimeException("File not found $path"), - this, -) - -/** - * Unzips a zip into a dir. Returns the true when successfully unzips the file pointed to by [zipFilePath] to [destDir] - */ -fun unzipFile(zipFilePath: Path, destDir: Path): Boolean { - if (!zipFilePath.exists()) return false - val zipFile = ZipFile(zipFilePath.toFile()) - zipFile.use { file -> - file.entries().asSequence() - .filterNot { it.isDirectory } - .map { zipEntry -> - val destPath = destDir.resolve(zipEntry.name) - destPath.createParentDirectories() - FileOutputStream(destPath.toFile()).use { targetFile -> - zipFile.getInputStream(zipEntry).copyTo(targetFile) - } - }.toList() - } - return true -} - -fun String.toTransformationLanguage() = when (this) { - "JDK_1_8" -> TransformationLanguage.JAVA_8 - "JDK_11" -> TransformationLanguage.JAVA_11 - "JDK_17" -> TransformationLanguage.JAVA_17 - else -> TransformationLanguage.UNKNOWN_TO_SDK_VERSION -} - -fun calculateTotalLatency(startTime: Instant, endTime: Instant) = (endTime.toEpochMilli() - startTime.toEpochMilli()).toInt() - -data class PollingResult( - val succeeded: Boolean, - val jobDetails: TransformationJob?, - val state: TransformationStatus, - val transformationPlan: TransformationPlan? -) - -fun refreshToken(project: Project) { - val connection = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(QConnection.getInstance()) - val provider = (connection?.getConnectionSettings() as TokenConnectionSettings).tokenProvider.delegate as BearerTokenProvider - provider.refresh() -} - -/** - * Wrapper around [waitUntil] that polls the API DescribeMigrationJob to check the migration job status. - */ -suspend fun JobId.pollTransformationStatusAndPlan( - succeedOn: Set, - failOn: Set, - clientAdaptor: GumbyClient, - initialSleepDurationMillis: Long, - sleepDurationMillis: Long, - isDisposed: AtomicBoolean, - project: Project, - maxDuration: Duration = Duration.ofSeconds(604800), - onStateChange: (previousStatus: TransformationStatus?, currentStatus: TransformationStatus, transformationPlan: TransformationPlan?) -> Unit, -): PollingResult { - val telemetry = CodeTransformTelemetryManager.getInstance(project) - var state = TransformationStatus.UNKNOWN_TO_SDK_VERSION - var transformationResponse: GetTransformationResponse? = null - var transformationPlan: TransformationPlan? = null - var didSleepOnce = false - val maxRefreshes = 10 - var numRefreshes = 0 - refreshToken(project) - - try { - waitUntil( - succeedOn = { result -> result in succeedOn }, - failOn = { result -> result in failOn }, - maxDuration = maxDuration, - exceptionsToStopOn = setOf( - InternalServerException::class, - ValidationException::class, - AwsServiceException::class, - CodeWhispererRuntimeException::class, - RuntimeException::class, - ), - exceptionsToIgnore = setOf(ThrottlingException::class) - ) { - try { - if (!didSleepOnce) { - sleep(initialSleepDurationMillis) - didSleepOnce = true - } - if (isDisposed.get()) throw AlreadyDisposedException("The invoker is disposed.") - transformationResponse = clientAdaptor.getCodeModernizationJob(this.id) - val newStatus = transformationResponse?.transformationJob()?.status() ?: throw RuntimeException("Unable to get job status") - var newPlan: TransformationPlan? = null - if (newStatus in STATES_WHERE_PLAN_EXIST) { - sleep(sleepDurationMillis) - newPlan = clientAdaptor.getCodeModernizationPlan(this).transformationPlan() - } - if (newStatus != state) { - telemetry.jobStatusChanged(this, newStatus.toString(), state.toString()) - } - if (newPlan != transformationPlan) { - telemetry.jobStatusChanged(this, "PLAN_UPDATED", state.toString()) - } - if (newStatus !in failOn && (newStatus != state || newPlan != transformationPlan)) { - transformationPlan = newPlan - onStateChange(state, newStatus, transformationPlan) - } - state = newStatus - numRefreshes = 0 - return@waitUntil state - } catch (e: AccessDeniedException) { - if (numRefreshes++ > maxRefreshes) throw e - refreshToken(project) - return@waitUntil state - } finally { - sleep(sleepDurationMillis) - } - } - } catch (e: Exception) { - // Still call onStateChange to update the UI - onStateChange(state, TransformationStatus.FAILED, transformationPlan) - when (e) { - is WaiterUnrecoverableException, is AccessDeniedException -> { - return PollingResult(false, transformationResponse?.transformationJob(), state, transformationPlan) - } - else -> throw e - } - } - return PollingResult(true, transformationResponse?.transformationJob(), state, transformationPlan) -} - -fun filterOnlyParentFiles(filePaths: Set): List { - if (filePaths.isEmpty()) return listOf() - // sorts it like: - // foo - // foo/bar - // foo/bar/bas - val sorted = filePaths.sortedBy { Path(it.path).nameCount } - val uniquePrefixes = mutableSetOf(Path(sorted.first().path).parent) - val shortestRoots = mutableSetOf(sorted.first()) - shortestRoots.add(sorted.first()) - sorted.drop(1).forEach { file -> - if (uniquePrefixes.none { Path(file.path).startsWith(it) }) { - shortestRoots.add(file) - uniquePrefixes.add(Path(file.path).parent) - } else if (Path(file.path).parent in uniquePrefixes) { - shortestRoots.add(file) // handles multiple parent files on the same level - } - } - return shortestRoots.toList() -} - -/** - * @description For every directory, check if any supported build files (pom.xml etc) exists. - * If we find a valid build file, store it and stop further recursion. - */ -fun findBuildFiles(sourceFolder: File, supportedBuildFileNames: List): List { - val buildFiles = mutableListOf() - sourceFolder.walkTopDown() - .maxDepth(5) - .onEnter { currentDir -> - supportedBuildFileNames.forEach { - val maybeSupportedFile = currentDir.resolve(MAVEN_CONFIGURATION_FILE_NAME) - if (maybeSupportedFile.exists()) { - buildFiles.add(maybeSupportedFile) - return@onEnter false - } - } - return@onEnter true - }.forEach { - // noop, collects the sequence - } - return buildFiles -} - -fun isIntellij(): Boolean { - val productCode = ApplicationInfo.getInstance().build.productCode - return productCode == "IC" || productCode == "IU" -} - -fun isGradleProject(project: Project) = !GradleSettings.getInstance(project).linkedProjectsSettings.isEmpty() - -fun getJavaVersionFromProjectSetting(project: Project): String? = project.tryGetJdk()?.toString() - -fun getMavenVersion(project: Project): String { - val mavenSettings = MavenProjectsManager.getInstance(project).getGeneralSettings() - // should be set to "Bundled (Maven X)" if setup instructions were followed - return mavenSettings.getMavenHome() ?: "Unknown" -} - -fun openTroubleshootingGuideNotificationAction(targetUrl: String) = OpenBrowserAction( - message("codemodernizer.notification.info.view_troubleshooting_guide"), - url = targetUrl -) diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/auth/CodeTransformAuthUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/auth/CodeTransformAuthUtils.kt index f58659c9ce..650ecef1e6 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/auth/CodeTransformAuthUtils.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/auth/CodeTransformAuthUtils.kt @@ -8,7 +8,7 @@ import software.aws.toolkits.jetbrains.core.gettingstarted.editor.ActiveConnecti import software.aws.toolkits.jetbrains.core.gettingstarted.editor.ActiveConnectionType import software.aws.toolkits.jetbrains.core.gettingstarted.editor.BearerTokenFeatureSet import software.aws.toolkits.jetbrains.core.gettingstarted.editor.checkBearerConnectionValidity -import software.aws.toolkits.jetbrains.services.codemodernizer.isIntellij +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.isIntellij fun isCodeTransformAvailable(project: Project): Boolean { if (!isIntellij()) return false diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/constants/CodeTransformChatItems.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/constants/CodeTransformChatItems.kt index 27be6d8aea..51127bb584 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/constants/CodeTransformChatItems.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/constants/CodeTransformChatItems.kt @@ -6,7 +6,7 @@ package software.aws.toolkits.jetbrains.services.codemodernizer.constants import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import software.aws.toolkits.jetbrains.services.amazonq.CODE_TRANSFORM_TROUBLESHOOT_DOC -import software.aws.toolkits.jetbrains.services.codemodernizer.getModuleOrProjectNameForFile +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile import software.aws.toolkits.jetbrains.services.codemodernizer.messages.Button import software.aws.toolkits.jetbrains.services.codemodernizer.messages.CodeTransformButtonId import software.aws.toolkits.jetbrains.services.codemodernizer.messages.CodeTransformChatMessageContent diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt index 0fb158da34..1e7eb53695 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt @@ -37,7 +37,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.constants.buildUs import software.aws.toolkits.jetbrains.services.codemodernizer.constants.buildUserInputChatContent import software.aws.toolkits.jetbrains.services.codemodernizer.constants.buildUserSelectionSummaryChatContent import software.aws.toolkits.jetbrains.services.codemodernizer.constants.buildUserStopTransformChatContent -import software.aws.toolkits.jetbrains.services.codemodernizer.getModuleOrProjectNameForFile +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile import software.aws.toolkits.jetbrains.services.codemodernizer.messages.AuthenticationNeededExceptionMessage import software.aws.toolkits.jetbrains.services.codemodernizer.messages.CodeTransformChatMessage import software.aws.toolkits.jetbrains.services.codemodernizer.messages.CodeTransformCommandMessage @@ -49,7 +49,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.model.MavenCopyCo import software.aws.toolkits.jetbrains.services.codemodernizer.session.ChatSessionStorage import software.aws.toolkits.jetbrains.services.codemodernizer.session.Session import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeModernizerSessionState -import software.aws.toolkits.jetbrains.services.codemodernizer.toVirtualFile +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.toVirtualFile import software.aws.toolkits.jetbrains.services.cwc.messages.ChatMessageType import software.aws.toolkits.resources.message import software.aws.toolkits.telemetry.CodeTransformStartSrcComponents @@ -170,7 +170,7 @@ class CodeTransformChatController( val (tabId, modulePath, targetVersion) = message - val moduleVirtualFile: VirtualFile = modulePath.toVirtualFile() as VirtualFile + val moduleVirtualFile: VirtualFile = software.aws.toolkits.jetbrains.services.codemodernizer.utils.toVirtualFile() as VirtualFile val moduleName = context.project.getModuleOrProjectNameForFile(moduleVirtualFile) codeTransformChatHelper.run { diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/model/CodeModernizerArtifact.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/model/CodeModernizerArtifact.kt index 1a5f2c3419..0f36ec22f5 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/model/CodeModernizerArtifact.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/model/CodeModernizerArtifact.kt @@ -13,7 +13,7 @@ import software.aws.toolkits.core.utils.exists import software.aws.toolkits.core.utils.getLogger import software.aws.toolkits.core.utils.warn import software.aws.toolkits.jetbrains.services.codemodernizer.TransformationSummary -import software.aws.toolkits.jetbrains.services.codemodernizer.unzipFile +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.unzipFile import kotlin.io.path.ExperimentalPathApi import kotlin.io.path.Path import kotlin.io.path.isDirectory diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/state/CodeModernizerState.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/state/CodeModernizerState.kt index 16e57ebbd8..85659f9ad6 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/state/CodeModernizerState.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/state/CodeModernizerState.kt @@ -9,7 +9,7 @@ import com.intellij.openapi.projectRoots.JavaSdkVersion import com.intellij.util.xmlb.annotations.Property import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerSessionContext import software.aws.toolkits.jetbrains.services.codemodernizer.model.JobId -import software.aws.toolkits.jetbrains.services.codemodernizer.toVirtualFile +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.toVirtualFile enum class JobDetails { LAST_JOB_ID, @@ -48,7 +48,7 @@ class CodeModernizerState : BaseState() { fun getLatestJobId() = JobId(lastJobContext[JobDetails.LAST_JOB_ID] ?: throw RuntimeException("No Job has been executed!")) fun toSessionContext(project: Project): CodeModernizerSessionContext { - val configurationFile = lastJobContext[JobDetails.CONFIGURATION_FILE_PATH]?.toVirtualFile() + val configurationFile = software.aws.toolkits.jetbrains.services.codemodernizer.utils.toVirtualFile() ?: throw RuntimeException("No build file store in the state") val targetString = lastJobContext[JobDetails.TARGET_JAVA_VERSION] ?: throw RuntimeException("Expected target language for migration path of previous job but was null") diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ui/components/PreCodeTransformUserDialog.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ui/components/PreCodeTransformUserDialog.kt index 169fe4658c..89205ac035 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ui/components/PreCodeTransformUserDialog.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ui/components/PreCodeTransformUserDialog.kt @@ -21,9 +21,9 @@ import com.intellij.ui.dsl.builder.columns import com.intellij.ui.dsl.builder.panel import com.intellij.ui.dsl.builder.toMutableProperty import software.aws.toolkits.jetbrains.services.codemodernizer.CodeTransformTelemetryManager -import software.aws.toolkits.jetbrains.services.codemodernizer.getSupportedJavaMappings +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedJavaMappings import software.aws.toolkits.jetbrains.services.codemodernizer.model.CustomerSelection -import software.aws.toolkits.jetbrains.services.codemodernizer.tryGetJdk +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.tryGetJdk import software.aws.toolkits.resources.message import kotlin.math.max diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt new file mode 100644 index 0000000000..b3758a0032 --- /dev/null +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt @@ -0,0 +1,116 @@ +// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package software.aws.toolkits.jetbrains.services.codemodernizer.utils + +import com.intellij.openapi.project.Project +import com.intellij.serviceContainer.AlreadyDisposedException +import software.amazon.awssdk.awscore.exception.AwsServiceException +import software.amazon.awssdk.services.codewhispererruntime.model.AccessDeniedException +import software.amazon.awssdk.services.codewhispererruntime.model.CodeWhispererRuntimeException +import software.amazon.awssdk.services.codewhispererruntime.model.GetTransformationResponse +import software.amazon.awssdk.services.codewhispererruntime.model.InternalServerException +import software.amazon.awssdk.services.codewhispererruntime.model.ThrottlingException +import software.amazon.awssdk.services.codewhispererruntime.model.TransformationJob +import software.amazon.awssdk.services.codewhispererruntime.model.TransformationPlan +import software.amazon.awssdk.services.codewhispererruntime.model.TransformationStatus +import software.amazon.awssdk.services.codewhispererruntime.model.ValidationException +import software.aws.toolkits.core.utils.WaiterUnrecoverableException +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.model.JobId +import java.lang.Thread.sleep +import java.time.Duration +import java.util.concurrent.atomic.AtomicBoolean + +data class PollingResult( + val succeeded: Boolean, + val jobDetails: TransformationJob?, + val state: TransformationStatus, + val transformationPlan: TransformationPlan? +) + +/** + * Wrapper around [waitUntil] that polls the API DescribeMigrationJob to check the migration job status. + */ +suspend fun JobId.pollTransformationStatusAndPlan( + succeedOn: Set, + failOn: Set, + clientAdaptor: GumbyClient, + initialSleepDurationMillis: Long, + sleepDurationMillis: Long, + isDisposed: AtomicBoolean, + project: Project, + maxDuration: Duration = Duration.ofSeconds(604800), + onStateChange: (previousStatus: TransformationStatus?, currentStatus: TransformationStatus, transformationPlan: TransformationPlan?) -> Unit, +): PollingResult { + val telemetry = CodeTransformTelemetryManager.getInstance(project) + var state = TransformationStatus.UNKNOWN_TO_SDK_VERSION + var transformationResponse: GetTransformationResponse? = null + var transformationPlan: TransformationPlan? = null + var didSleepOnce = false + val maxRefreshes = 10 + var numRefreshes = 0 + refreshToken(project) + + try { + waitUntil( + succeedOn = { result -> result in succeedOn }, + failOn = { result -> result in failOn }, + maxDuration = maxDuration, + exceptionsToStopOn = setOf( + InternalServerException::class, + ValidationException::class, + AwsServiceException::class, + CodeWhispererRuntimeException::class, + RuntimeException::class, + ), + exceptionsToIgnore = setOf(ThrottlingException::class) + ) { + try { + if (!didSleepOnce) { + sleep(initialSleepDurationMillis) + didSleepOnce = true + } + if (isDisposed.get()) throw AlreadyDisposedException("The invoker is disposed.") + transformationResponse = clientAdaptor.getCodeModernizationJob(this.id) + val newStatus = transformationResponse?.transformationJob()?.status() ?: throw RuntimeException("Unable to get job status") + var newPlan: TransformationPlan? = null + if (newStatus in STATES_WHERE_PLAN_EXIST) { + sleep(sleepDurationMillis) + newPlan = clientAdaptor.getCodeModernizationPlan(this).transformationPlan() + } + if (newStatus != state) { + telemetry.jobStatusChanged(this, newStatus.toString(), state.toString()) + } + if (newPlan != transformationPlan) { + telemetry.jobStatusChanged(this, "PLAN_UPDATED", state.toString()) + } + if (newStatus !in failOn && (newStatus != state || newPlan != transformationPlan)) { + transformationPlan = newPlan + onStateChange(state, newStatus, transformationPlan) + } + state = newStatus + numRefreshes = 0 + return@waitUntil state + } catch (e: AccessDeniedException) { + if (numRefreshes++ > maxRefreshes) throw e + refreshToken(project) + return@waitUntil state + } finally { + sleep(sleepDurationMillis) + } + } + } catch (e: Exception) { + // Still call onStateChange to update the UI + onStateChange(state, TransformationStatus.FAILED, transformationPlan) + when (e) { + is WaiterUnrecoverableException, is AccessDeniedException -> { + return PollingResult(false, transformationResponse?.transformationJob(), state, transformationPlan) + } + else -> throw e + } + } + return PollingResult(true, transformationResponse?.transformationJob(), state, transformationPlan) +} diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformFileUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformFileUtils.kt new file mode 100644 index 0000000000..5359910ceb --- /dev/null +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformFileUtils.kt @@ -0,0 +1,78 @@ +// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package software.aws.toolkits.jetbrains.services.codemodernizer.utils + +import com.intellij.openapi.vfs.VirtualFile +import software.aws.toolkits.core.utils.createParentDirectories +import software.aws.toolkits.core.utils.exists +import software.aws.toolkits.jetbrains.services.codemodernizer.model.MAVEN_CONFIGURATION_FILE_NAME +import java.io.File +import java.io.FileOutputStream +import java.nio.file.Path +import java.util.zip.ZipFile +import kotlin.io.path.Path + +fun filterOnlyParentFiles(filePaths: Set): List { + if (filePaths.isEmpty()) return listOf() + // sorts it like: + // foo + // foo/bar + // foo/bar/bas + val sorted = filePaths.sortedBy { Path(it.path).nameCount } + val uniquePrefixes = mutableSetOf(Path(sorted.first().path).parent) + val shortestRoots = mutableSetOf(sorted.first()) + shortestRoots.add(sorted.first()) + sorted.drop(1).forEach { file -> + if (uniquePrefixes.none { Path(file.path).startsWith(it) }) { + shortestRoots.add(file) + uniquePrefixes.add(Path(file.path).parent) + } else if (Path(file.path).parent in uniquePrefixes) { + shortestRoots.add(file) // handles multiple parent files on the same level + } + } + return shortestRoots.toList() +} + +/** + * @description For every directory, check if any supported build files (pom.xml etc) exists. + * If we find a valid build file, store it and stop further recursion. + */ +fun findBuildFiles(sourceFolder: File, supportedBuildFileNames: List): List { + val buildFiles = mutableListOf() + sourceFolder.walkTopDown() + .maxDepth(5) + .onEnter { currentDir -> + supportedBuildFileNames.forEach { + val maybeSupportedFile = currentDir.resolve(MAVEN_CONFIGURATION_FILE_NAME) + if (maybeSupportedFile.exists()) { + buildFiles.add(maybeSupportedFile) + return@onEnter false + } + } + return@onEnter true + }.forEach { + // noop, collects the sequence + } + return buildFiles +} + +/** + * Unzips a zip into a dir. Returns the true when successfully unzips the file pointed to by [zipFilePath] to [destDir] + */ +fun unzipFile(zipFilePath: Path, destDir: Path): Boolean { + if (!zipFilePath.exists()) return false + val zipFile = ZipFile(zipFilePath.toFile()) + zipFile.use { file -> + file.entries().asSequence() + .filterNot { it.isDirectory } + .map { zipEntry -> + val destPath = destDir.resolve(zipEntry.name) + destPath.createParentDirectories() + FileOutputStream(destPath.toFile()).use { targetFile -> + zipFile.getInputStream(zipEntry).copyTo(targetFile) + } + }.toList() + } + return true +} diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformUtils.kt new file mode 100644 index 0000000000..84640d0ea4 --- /dev/null +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformUtils.kt @@ -0,0 +1,74 @@ +// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package software.aws.toolkits.jetbrains.services.codemodernizer.utils + +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VfsUtilCore +import com.intellij.openapi.vfs.VirtualFileManager +import software.amazon.awssdk.services.codewhispererruntime.model.TransformationLanguage +import software.amazon.awssdk.services.codewhispererruntime.model.TransformationStatus +import software.aws.toolkits.core.TokenConnectionSettings +import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager +import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection +import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.BearerTokenProvider +import software.aws.toolkits.jetbrains.utils.actions.OpenBrowserAction +import software.aws.toolkits.resources.message +import java.time.Instant + +val STATES_WHERE_PLAN_EXIST = setOf( + TransformationStatus.PLANNED, + TransformationStatus.TRANSFORMING, + TransformationStatus.TRANSFORMED, + TransformationStatus.PARTIALLY_COMPLETED, + TransformationStatus.COMPLETED, +) + +val STATES_AFTER_INITIAL_BUILD = setOf( + TransformationStatus.PREPARED, + TransformationStatus.PLANNING, + *STATES_WHERE_PLAN_EXIST.toTypedArray() +) + +val STATES_AFTER_STARTED = setOf( + TransformationStatus.STARTED, + TransformationStatus.PREPARING, + *STATES_AFTER_INITIAL_BUILD.toTypedArray(), +) + +val STATES_WHERE_JOB_STOPPED_PRE_PLAN_READY = setOf( + TransformationStatus.FAILED, + TransformationStatus.STOPPED, + TransformationStatus.STOPPING, + TransformationStatus.REJECTED, + TransformationStatus.UNKNOWN_TO_SDK_VERSION, +) + +const val TROUBLESHOOTING_URL_DOWNLOAD_DIFF = + "https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html#w24aac14c20c19c11" +const val TROUBLESHOOTING_URL_MAVEN_COMMANDS = + "https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html#w24aac14c20c19b7" +const val TROUBLESHOOTING_URL_PREREQUISITES = + "https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html#prerequisites" + +fun calculateTotalLatency(startTime: Instant, endTime: Instant) = (endTime.toEpochMilli() - startTime.toEpochMilli()).toInt() + +fun refreshToken(project: Project) { + val connection = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(QConnection.getInstance()) + val provider = (connection?.getConnectionSettings() as TokenConnectionSettings).tokenProvider.delegate as BearerTokenProvider + provider.refresh() +} + +fun openTroubleshootingGuideNotificationAction(targetUrl: String) = OpenBrowserAction( + message("codemodernizer.notification.info.view_troubleshooting_guide"), + url = targetUrl +) + +fun String.toVirtualFile() = VirtualFileManager.getInstance().findFileByUrl(VfsUtilCore.pathToUrl(this)) + +fun String.toTransformationLanguage() = when (this) { + "JDK_1_8" -> TransformationLanguage.JAVA_8 + "JDK_11" -> TransformationLanguage.JAVA_11 + "JDK_17" -> TransformationLanguage.JAVA_17 + else -> TransformationLanguage.UNKNOWN_TO_SDK_VERSION +} diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformValidationUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformValidationUtils.kt new file mode 100644 index 0000000000..0be64ed5a4 --- /dev/null +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformValidationUtils.kt @@ -0,0 +1,24 @@ +// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package software.aws.toolkits.jetbrains.services.codemodernizer.utils + +import com.intellij.openapi.application.ApplicationInfo +import com.intellij.openapi.project.Project +import org.jetbrains.idea.maven.project.MavenProjectsManager +import org.jetbrains.plugins.gradle.settings.GradleSettings + +fun isIntellij(): Boolean { + val productCode = ApplicationInfo.getInstance().build.productCode + return productCode == "IC" || productCode == "IU" +} + +fun isGradleProject(project: Project) = !GradleSettings.getInstance(project).linkedProjectsSettings.isEmpty() + +fun getJavaVersionFromProjectSetting(project: Project): String? = project.tryGetJdk()?.toString() + +fun getMavenVersion(project: Project): String { + val mavenSettings = MavenProjectsManager.getInstance(project).getGeneralSettings() + // should be set to "Bundled (Maven X)" if setup instructions were followed + return mavenSettings.getMavenHome() ?: "Unknown" +} diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ModuleUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ModuleUtils.kt new file mode 100644 index 0000000000..df6adc3f49 --- /dev/null +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ModuleUtils.kt @@ -0,0 +1,20 @@ +// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +package software.aws.toolkits.jetbrains.services.codemodernizer.utils + +import com.intellij.openapi.module.Module +import com.intellij.openapi.project.Project +import com.intellij.openapi.projectRoots.JavaSdkVersion +import com.intellij.openapi.projectRoots.impl.JavaSdkImpl +import com.intellij.openapi.roots.ModuleRootManager +import com.intellij.openapi.roots.ProjectRootManager + +/** + * @description Try to get the module SDK version and fallback to the project SDK version from the "project structure" settings. + */ +fun Module.tryGetJdk(project: Project): JavaSdkVersion? { + val sdk = ModuleRootManager.getInstance(this).sdk ?: ProjectRootManager.getInstance(project).projectSdk ?: return null + val javaSdk = JavaSdkImpl.getInstance() + return javaSdk.getVersion(sdk) +} diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ModuleUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt similarity index 80% rename from plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ModuleUtils.kt rename to plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt index 09d6490aa0..9dbc9e89a3 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ModuleUtils.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt @@ -1,27 +1,17 @@ -// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. +// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -package software.aws.toolkits.jetbrains.services.codemodernizer +package software.aws.toolkits.jetbrains.services.codemodernizer.utils import com.intellij.openapi.application.runReadAction -import com.intellij.openapi.module.Module import com.intellij.openapi.module.ModuleUtil import com.intellij.openapi.project.Project import com.intellij.openapi.project.modules import com.intellij.openapi.projectRoots.JavaSdkVersion import com.intellij.openapi.projectRoots.impl.JavaSdkImpl -import com.intellij.openapi.roots.ModuleRootManager import com.intellij.openapi.roots.ProjectRootManager import com.intellij.openapi.vfs.VirtualFile -/** - * @description Try to get the module SDK version and fallback to the project SDK version from the "project structure" settings. - */ -fun Module.tryGetJdk(project: Project): JavaSdkVersion? { - val sdk = ModuleRootManager.getInstance(this).sdk ?: ProjectRootManager.getInstance(project).projectSdk ?: return null - val javaSdk = JavaSdkImpl.getInstance() - return javaSdk.getVersion(sdk) -} /** * @description Try to get the project SDK version from the "project structure" settings @@ -49,7 +39,7 @@ private fun Project.getAllSupportedBuildFiles(supportedBuildFileNames: List): List { val projectRootManager = ProjectRootManager.getInstance(this) - val probableProjectRoot = this.basePath?.toVirtualFile() // May point to only one intellij module (the first opened one) + val probableProjectRoot = projectRootManager.toString().toVirtualFile() // May point to only one intellij module (the first opened one) val probableContentRoots = projectRootManager.contentRoots.toMutableSet() // May not point to the topmost folder of modules probableContentRoots.add(probableProjectRoot) // dedupe val topLevelRoots = filterOnlyParentFiles(probableContentRoots) @@ -93,3 +83,8 @@ fun Project.getSupportedModules(supportedJavaMappings: Map() runBlocking { - jobId.pollTransformationStatusAndPlan( + software.aws.toolkits.jetbrains.services.codemodernizer.utils.pollTransformationStatusAndPlan( setOf(TransformationStatus.STARTED), setOf(TransformationStatus.FAILED), clientAdaptorSpy, @@ -67,7 +67,7 @@ class CodeWhispererCodeModernizerUtilsTest : CodeWhispererCodeModernizerTestBase val mutableList = mutableListOf() val result = runBlocking { - jobId.pollTransformationStatusAndPlan( + software.aws.toolkits.jetbrains.services.codemodernizer.utils.pollTransformationStatusAndPlan( setOf(TransformationStatus.COMPLETED), setOf(TransformationStatus.FAILED), clientAdaptorSpy, From a230b8d8e9965a97b5d4f63618bb1209cf0807d2 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Fri, 29 Mar 2024 15:24:39 -0700 Subject: [PATCH 02/12] Chore - fix merge conflicst with refactoring and import long form strings --- .../services/codemodernizer/ArtifactHandler.kt | 10 ++++++---- .../codemodernizer/CodeModernizerManager.kt | 9 ++++++--- .../codemodernizer/CodeModernizerSession.kt | 4 ++-- .../CodeTransformTelemetryManager.kt | 15 +++++++++------ .../controller/CodeTransformChatController.kt | 2 +- .../codemodernizer/state/CodeModernizerState.kt | 2 +- .../services/codemodernizer/utils/ProjectUtils.kt | 4 ++-- .../CodeWhispererCodeModernizerUtilsTest.kt | 4 ++-- 8 files changed, 29 insertions(+), 21 deletions(-) diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt index 93864f7dc8..320f28da54 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt @@ -22,6 +22,8 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.client.GumbyClien import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerArtifact import software.aws.toolkits.jetbrains.services.codemodernizer.model.JobId import software.aws.toolkits.jetbrains.services.codemodernizer.summary.CodeModernizerSummaryEditorProvider +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_DOWNLOAD_DIFF +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction import software.aws.toolkits.jetbrains.utils.notifyStickyInfo import software.aws.toolkits.jetbrains.utils.notifyStickyWarn import software.aws.toolkits.resources.message @@ -153,8 +155,8 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G message("codemodernizer.notification.warn.view_diff_failed.content"), project, listOf( - software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction( - software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_DOWNLOAD_DIFF + openTroubleshootingGuideNotificationAction( + TROUBLESHOOTING_URL_DOWNLOAD_DIFF ) ), ) @@ -167,8 +169,8 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G message("codemodernizer.notification.warn.view_summary_failed.content"), project, listOf( - software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction( - software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_DOWNLOAD_DIFF + openTroubleshootingGuideNotificationAction( + TROUBLESHOOTING_URL_DOWNLOAD_DIFF ) ), ) diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt index e5258c8c85..6b74f25ff6 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt @@ -47,10 +47,13 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeModerni import software.aws.toolkits.jetbrains.services.codemodernizer.state.StateFlags import software.aws.toolkits.jetbrains.services.codemodernizer.state.buildState import software.aws.toolkits.jetbrains.services.codemodernizer.toolwindow.CodeModernizerBottomToolWindowFactory +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_MAVEN_COMMANDS +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_PREREQUISITES import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedBuildFilesWithSupportedJdk import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedJavaMappings import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedModules +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction import software.aws.toolkits.jetbrains.services.codemodernizer.utils.tryGetJdk import software.aws.toolkits.jetbrains.ui.feedback.FeedbackDialog import software.aws.toolkits.jetbrains.utils.isRunningOnRemoteBackend @@ -594,13 +597,13 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo message("codemodernizer.notification.warn.maven_failed.title"), message("codemodernizer.notification.warn.maven_failed.content"), project, - listOf(software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction(software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_MAVEN_COMMANDS), displayFeedbackNotificationAction()), + listOf(openTroubleshootingGuideNotificationAction(TROUBLESHOOTING_URL_MAVEN_COMMANDS), displayFeedbackNotificationAction()), ) is CodeModernizerJobCompletedResult.JobAbortedZipTooLarge -> notifyStickyInfo( message("codemodernizer.notification.warn.zip_too_large.title"), message("codemodernizer.notification.warn.zip_too_large.content"), project, - listOf(software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction(software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_PREREQUISITES), displayFeedbackNotificationAction()), + listOf(openTroubleshootingGuideNotificationAction(TROUBLESHOOTING_URL_PREREQUISITES), displayFeedbackNotificationAction()), ) is CodeModernizerJobCompletedResult.Stopped -> notifyStickyInfo( message("codemodernizer.notification.info.transformation_stop.title"), @@ -687,7 +690,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo message("codemodernizer.validationerrordialog.description.title"), message("codemodernizer.validationerrordialog.description.main"), project, - listOf(software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction(software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_PREREQUISITES)), + listOf(openTroubleshootingGuideNotificationAction(TROUBLESHOOTING_URL_PREREQUISITES)), ) } diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt index 5dfde6cf81..f2f21107d8 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt @@ -226,8 +226,8 @@ class CodeModernizerSession( } private fun startJob(uploadId: String): StartTransformationResponse { - val sourceLanguage = uploadId.toTransformationLanguage() - val targetLanguage = uploadId.toTransformationLanguage() + val sourceLanguage = sessionContext.sourceJavaVersion.name.toTransformationLanguage() + val targetLanguage = sessionContext.targetJavaVersion.name.toTransformationLanguage() if (sourceLanguage == TransformationLanguage.UNKNOWN_TO_SDK_VERSION) { throw RuntimeException("Source language is not supported") } diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt index 06efa3d247..77c2d9f09a 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformTelemetryManager.kt @@ -13,6 +13,9 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.model.JobId import software.aws.toolkits.jetbrains.services.codemodernizer.model.ValidationResult import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeModernizerSessionState import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeTransformTelemetryState +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getJavaVersionFromProjectSetting +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getMavenVersion import software.aws.toolkits.jetbrains.services.codemodernizer.utils.tryGetJdk import software.aws.toolkits.telemetry.CodeTransformApiNames import software.aws.toolkits.telemetry.CodeTransformCancelSrcComponents @@ -94,18 +97,18 @@ class CodeTransformTelemetryManager(private val project: Project) { codeTransformJobId = jobId?.toString(), codeTransformSessionId = sessionId, codeTransformResultStatusMessage = codeTransformResultStatusMessage, - codeTransformRunTimeLatency = software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency( + codeTransformRunTimeLatency = calculateTotalLatency( CodeTransformTelemetryState.instance.getStartTime(), Instant.now() ), - codeTransformLocalJavaVersion = software.aws.toolkits.jetbrains.services.codemodernizer.utils.getJavaVersionFromProjectSetting(project), - codeTransformLocalMavenVersion = software.aws.toolkits.jetbrains.services.codemodernizer.utils.getMavenVersion(project), + codeTransformLocalJavaVersion = getJavaVersionFromProjectSetting(project), + codeTransformLocalMavenVersion = getMavenVersion(project), ) fun jobCreateZipEndTime(payloadSize: Int, startTime: Instant) = CodetransformTelemetry.jobCreateZipEndTime( codeTransformTotalByteSize = payloadSize, codeTransformSessionId = sessionId, - codeTransformRunTimeLatency = software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency(startTime, Instant.now()), + codeTransformRunTimeLatency = calculateTotalLatency(startTime, Instant.now()), ) fun error(errorMessage: String) = CodetransformTelemetry.logGeneralError( @@ -130,7 +133,7 @@ class CodeTransformTelemetryManager(private val project: Project) { ) = CodetransformTelemetry.logApiLatency( codeTransformApiNames = apiName, codeTransformSessionId = sessionId, - codeTransformRunTimeLatency = software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency(startTime, Instant.now()), + codeTransformRunTimeLatency = calculateTotalLatency(startTime, Instant.now()), codeTransformUploadId = codeTransformUploadId, codeTransformJobId = codeTransformJobId, codeTransformTotalByteSize = codeTransformTotalByteSize, @@ -171,7 +174,7 @@ class CodeTransformTelemetryManager(private val project: Project) { fun jobArtifactDownloadAndDeserializeTime(downloadStartTime: Instant, jobId: JobId, totalDownloadBytes: Int, telemetryErrorMessage: String?) { CodetransformTelemetry.jobArtifactDownloadAndDeserializeTime( codeTransformSessionId = sessionId, - codeTransformRunTimeLatency = software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency(downloadStartTime, Instant.now()), + codeTransformRunTimeLatency = calculateTotalLatency(downloadStartTime, Instant.now()), codeTransformJobId = jobId.id, codeTransformTotalByteSize = totalDownloadBytes, codeTransformRuntimeError = telemetryErrorMessage, diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt index 1e7eb53695..b320a22b57 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt @@ -170,7 +170,7 @@ class CodeTransformChatController( val (tabId, modulePath, targetVersion) = message - val moduleVirtualFile: VirtualFile = software.aws.toolkits.jetbrains.services.codemodernizer.utils.toVirtualFile() as VirtualFile + val moduleVirtualFile: VirtualFile = modulePath.toVirtualFile() as VirtualFile val moduleName = context.project.getModuleOrProjectNameForFile(moduleVirtualFile) codeTransformChatHelper.run { diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/state/CodeModernizerState.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/state/CodeModernizerState.kt index 85659f9ad6..b4298c8f40 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/state/CodeModernizerState.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/state/CodeModernizerState.kt @@ -48,7 +48,7 @@ class CodeModernizerState : BaseState() { fun getLatestJobId() = JobId(lastJobContext[JobDetails.LAST_JOB_ID] ?: throw RuntimeException("No Job has been executed!")) fun toSessionContext(project: Project): CodeModernizerSessionContext { - val configurationFile = software.aws.toolkits.jetbrains.services.codemodernizer.utils.toVirtualFile() + val configurationFile = lastJobContext[JobDetails.CONFIGURATION_FILE_PATH]?.toVirtualFile() ?: throw RuntimeException("No build file store in the state") val targetString = lastJobContext[JobDetails.TARGET_JAVA_VERSION] ?: throw RuntimeException("Expected target language for migration path of previous job but was null") diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt index 9dbc9e89a3..0b67e8f190 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt @@ -39,7 +39,7 @@ private fun Project.getAllSupportedBuildFiles(supportedBuildFileNames: List): List { val projectRootManager = ProjectRootManager.getInstance(this) - val probableProjectRoot = projectRootManager.toString().toVirtualFile() // May point to only one intellij module (the first opened one) + val probableProjectRoot = this.basePath?.toVirtualFile() // May point to only one intellij module (the first opened one) val probableContentRoots = projectRootManager.contentRoots.toMutableSet() // May not point to the topmost folder of modules probableContentRoots.add(probableProjectRoot) // dedupe val topLevelRoots = filterOnlyParentFiles(probableContentRoots) diff --git a/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/services/codewhisperer/codemodernizer/CodeWhispererCodeModernizerUtilsTest.kt b/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/services/codewhisperer/codemodernizer/CodeWhispererCodeModernizerUtilsTest.kt index 70250c271f..64c3873fda 100644 --- a/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/services/codewhisperer/codemodernizer/CodeWhispererCodeModernizerUtilsTest.kt +++ b/plugins/toolkit/jetbrains-core/tst/software/aws/toolkits/jetbrains/services/codewhisperer/codemodernizer/CodeWhispererCodeModernizerUtilsTest.kt @@ -35,7 +35,7 @@ class CodeWhispererCodeModernizerUtilsTest : CodeWhispererCodeModernizerTestBase .whenever(clientAdaptorSpy).getCodeModernizationPlan(any()) val mutableList = mutableListOf() runBlocking { - software.aws.toolkits.jetbrains.services.codemodernizer.utils.pollTransformationStatusAndPlan( + jobId.pollTransformationStatusAndPlan( setOf(TransformationStatus.STARTED), setOf(TransformationStatus.FAILED), clientAdaptorSpy, @@ -67,7 +67,7 @@ class CodeWhispererCodeModernizerUtilsTest : CodeWhispererCodeModernizerTestBase val mutableList = mutableListOf() val result = runBlocking { - software.aws.toolkits.jetbrains.services.codemodernizer.utils.pollTransformationStatusAndPlan( + jobId.pollTransformationStatusAndPlan( setOf(TransformationStatus.COMPLETED), setOf(TransformationStatus.FAILED), clientAdaptorSpy, From 49f953dc50726f9ccbab1d7a3a7abfa933e62379 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Fri, 29 Mar 2024 15:27:53 -0700 Subject: [PATCH 03/12] Chore - remove unused code from refactor --- plugins/toolkit/jetbrains-core/build.gradle.kts | 1 + .../services/codemodernizer/CodeModernizerManager.kt | 8 +++++--- .../services/codemodernizer/utils/ProjectUtils.kt | 5 ----- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/toolkit/jetbrains-core/build.gradle.kts b/plugins/toolkit/jetbrains-core/build.gradle.kts index 346b44c7bf..5b6dc1f068 100644 --- a/plugins/toolkit/jetbrains-core/build.gradle.kts +++ b/plugins/toolkit/jetbrains-core/build.gradle.kts @@ -122,6 +122,7 @@ dependencies { api(libs.aws.sns) api(libs.aws.sqs) api(libs.aws.services) + implementation(project(mapOf("path" to ":plugin-toolkit:jetbrains-rider"))) compileOnlyApi(project(":plugin-core:jetbrains-community")) implementation(project(":plugin-amazonq:mynah-ui")) diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt index 6b74f25ff6..176c50d918 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt @@ -47,12 +47,14 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeModerni import software.aws.toolkits.jetbrains.services.codemodernizer.state.StateFlags import software.aws.toolkits.jetbrains.services.codemodernizer.state.buildState import software.aws.toolkits.jetbrains.services.codemodernizer.toolwindow.CodeModernizerBottomToolWindowFactory +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.STATES_WHERE_PLAN_EXIST import software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_MAVEN_COMMANDS import software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_PREREQUISITES import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedBuildFilesWithSupportedJdk import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedJavaMappings import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedModules +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.isGradleProject import software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction import software.aws.toolkits.jetbrains.services.codemodernizer.utils.tryGetJdk import software.aws.toolkits.jetbrains.ui.feedback.FeedbackDialog @@ -161,7 +163,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo message("codemodernizer.notification.warn.invalid_project.description.reason.no_valid_files", supportedBuildFileNames.joinToString()), InvalidTelemetryReason( CodeTransformPreValidationError.NonMavenProject, - if (software.aws.toolkits.jetbrains.services.codemodernizer.utils.isGradleProject(project)) "Gradle build" else "other build" + if (isGradleProject(project)) "Gradle build" else "other build" ) ) } @@ -286,7 +288,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo return@launch } try { - val plan = if (currentJobResult.status() in software.aws.toolkits.jetbrains.services.codemodernizer.utils.STATES_WHERE_PLAN_EXIST) { + val plan = if (currentJobResult.status() in STATES_WHERE_PLAN_EXIST) { try { delay(1000) session.fetchPlan(lastJobId).transformationPlan() @@ -328,7 +330,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo message("codemodernizer.notification.warn.maven_failed.title"), message("codemodernizer.notification.warn.maven_failed.content"), project, - listOf(software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction(software.aws.toolkits.jetbrains.services.codemodernizer.utils.TROUBLESHOOTING_URL_MAVEN_COMMANDS), displayFeedbackNotificationAction()), + listOf(openTroubleshootingGuideNotificationAction(TROUBLESHOOTING_URL_MAVEN_COMMANDS), displayFeedbackNotificationAction()), ) } diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt index 0b67e8f190..e41d45fb4d 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt @@ -83,8 +83,3 @@ fun Project.getSupportedModules(supportedJavaMappings: Map Date: Fri, 29 Mar 2024 15:29:08 -0700 Subject: [PATCH 04/12] Chore - remove extra code added by jetbrains --- plugins/toolkit/jetbrains-core/build.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/toolkit/jetbrains-core/build.gradle.kts b/plugins/toolkit/jetbrains-core/build.gradle.kts index 5b6dc1f068..346b44c7bf 100644 --- a/plugins/toolkit/jetbrains-core/build.gradle.kts +++ b/plugins/toolkit/jetbrains-core/build.gradle.kts @@ -122,7 +122,6 @@ dependencies { api(libs.aws.sns) api(libs.aws.sqs) api(libs.aws.services) - implementation(project(mapOf("path" to ":plugin-toolkit:jetbrains-rider"))) compileOnlyApi(project(":plugin-core:jetbrains-community")) implementation(project(":plugin-amazonq:mynah-ui")) From 91ec7844e0e8c162634e19117036d563da7f3116 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Fri, 29 Mar 2024 15:31:26 -0700 Subject: [PATCH 05/12] Chore - rename all new files to have CodeTransform prefix --- .../utils/{ModuleUtils.kt => CodeTransformModuleUtils.kt} | 0 .../utils/{ProjectUtils.kt => CodeTransformProjectUtils.kt} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/{ModuleUtils.kt => CodeTransformModuleUtils.kt} (100%) rename plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/{ProjectUtils.kt => CodeTransformProjectUtils.kt} (100%) diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ModuleUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformModuleUtils.kt similarity index 100% rename from plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ModuleUtils.kt rename to plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformModuleUtils.kt diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformProjectUtils.kt similarity index 100% rename from plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/ProjectUtils.kt rename to plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformProjectUtils.kt From 4bfd00a7936f130bdc106446748a51dbd11574f0 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Fri, 29 Mar 2024 15:32:01 -0700 Subject: [PATCH 06/12] Chore - remove testing if statement --- .../services/codemodernizer/CodeModernizerSession.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt index f2f21107d8..30e1a131db 100644 --- a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt +++ b/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt @@ -101,11 +101,6 @@ class CodeModernizerSession( } val startTime = Instant.now() val result = sessionContext.createZipWithModuleFiles(copyResult) - val humanInTheLoopFlag = true - - if (humanInTheLoopFlag) { - - } if (result is ZipCreationResult.Missing1P) { return CodeModernizerStartJobResult.CancelledMissingDependencies From ca8046cdabe98f6d923063893e963927cf96a7d4 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Tue, 2 Apr 2024 11:44:14 -0700 Subject: [PATCH 07/12] Chore - revert feedback dialog constructor --- .../services/codemodernizer/CodeModernizerManager.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt index 176c50d918..4d51fb0ec1 100644 --- a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt +++ b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt @@ -57,7 +57,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupporte import software.aws.toolkits.jetbrains.services.codemodernizer.utils.isGradleProject import software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction import software.aws.toolkits.jetbrains.services.codemodernizer.utils.tryGetJdk -import software.aws.toolkits.jetbrains.ui.feedback.FeedbackDialog +import software.aws.toolkits.jetbrains.ui.feedback.CodeTransformFeedbackDialog import software.aws.toolkits.jetbrains.utils.isRunningOnRemoteBackend import software.aws.toolkits.jetbrains.utils.notifyStickyError import software.aws.toolkits.jetbrains.utils.notifyStickyInfo @@ -545,7 +545,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo private fun displayFeedbackNotificationAction() = NotificationAction.createSimple(message("codemodernizer.notification.warn.submit_feedback")) { - FeedbackDialog(project, productName = AMAZON_Q_FEEDBACK_DIALOG_KEY).showAndGet() + CodeTransformFeedbackDialog(project).showAndGet() } private fun informUserOfCompletion(result: CodeModernizerJobCompletedResult) { From 124b77ff896ec0791d8c702a75838fd0e3dee155 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Tue, 2 Apr 2024 11:54:44 -0700 Subject: [PATCH 08/12] Chore - refactor folder location since upstream refactor moved our repository code --- .../codemodernizer/CodeTransformUtils.kt | 286 ------------------ .../services/codemodernizer/ModuleUtils.kt | 85 ------ .../utils/CodeTransformApiUtils.kt | 0 .../utils/CodeTransformFileUtils.kt | 0 .../utils/CodeTransformModuleUtils.kt | 0 .../utils/CodeTransformProjectUtils.kt | 0 .../utils/CodeTransformUtils.kt | 0 .../utils/CodeTransformValidationUtils.kt | 0 8 files changed, 371 deletions(-) delete mode 100644 plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformUtils.kt delete mode 100644 plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/ModuleUtils.kt rename plugins/{toolkit/jetbrains-core => amazonq/codetransform/jetbrains-community}/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt (100%) rename plugins/{toolkit/jetbrains-core => amazonq/codetransform/jetbrains-community}/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformFileUtils.kt (100%) rename plugins/{toolkit/jetbrains-core => amazonq/codetransform/jetbrains-community}/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformModuleUtils.kt (100%) rename plugins/{toolkit/jetbrains-core => amazonq/codetransform/jetbrains-community}/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformProjectUtils.kt (100%) rename plugins/{toolkit/jetbrains-core => amazonq/codetransform/jetbrains-community}/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformUtils.kt (100%) rename plugins/{toolkit/jetbrains-core => amazonq/codetransform/jetbrains-community}/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformValidationUtils.kt (100%) diff --git a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformUtils.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformUtils.kt deleted file mode 100644 index cb888e0cf3..0000000000 --- a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeTransformUtils.kt +++ /dev/null @@ -1,286 +0,0 @@ -// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -package software.aws.toolkits.jetbrains.services.codemodernizer - -import com.intellij.openapi.application.ApplicationInfo -import com.intellij.openapi.module.ModuleUtil -import com.intellij.openapi.project.Project -import com.intellij.openapi.vfs.VfsUtilCore -import com.intellij.openapi.vfs.VirtualFile -import com.intellij.openapi.vfs.VirtualFileManager -import com.intellij.serviceContainer.AlreadyDisposedException -import org.jetbrains.idea.maven.project.MavenProjectsManager -import org.jetbrains.plugins.gradle.settings.GradleSettings -import software.amazon.awssdk.awscore.exception.AwsServiceException -import software.amazon.awssdk.services.codewhispererruntime.model.AccessDeniedException -import software.amazon.awssdk.services.codewhispererruntime.model.CodeWhispererRuntimeException -import software.amazon.awssdk.services.codewhispererruntime.model.GetTransformationResponse -import software.amazon.awssdk.services.codewhispererruntime.model.InternalServerException -import software.amazon.awssdk.services.codewhispererruntime.model.ThrottlingException -import software.amazon.awssdk.services.codewhispererruntime.model.TransformationJob -import software.amazon.awssdk.services.codewhispererruntime.model.TransformationLanguage -import software.amazon.awssdk.services.codewhispererruntime.model.TransformationPlan -import software.amazon.awssdk.services.codewhispererruntime.model.TransformationStatus -import software.amazon.awssdk.services.codewhispererruntime.model.ValidationException -import software.aws.toolkits.core.TokenConnectionSettings -import software.aws.toolkits.core.utils.WaiterUnrecoverableException -import software.aws.toolkits.core.utils.Waiters.waitUntil -import software.aws.toolkits.core.utils.createParentDirectories -import software.aws.toolkits.core.utils.exists -import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager -import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection -import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.BearerTokenProvider -import software.aws.toolkits.jetbrains.services.codemodernizer.client.GumbyClient -import software.aws.toolkits.jetbrains.services.codemodernizer.model.JobId -import software.aws.toolkits.jetbrains.services.codemodernizer.model.MAVEN_CONFIGURATION_FILE_NAME -import software.aws.toolkits.jetbrains.utils.actions.OpenBrowserAction -import software.aws.toolkits.resources.message -import java.io.File -import java.io.FileOutputStream -import java.lang.Thread.sleep -import java.nio.file.Path -import java.time.Duration -import java.time.Instant -import java.util.concurrent.atomic.AtomicBoolean -import java.util.zip.ZipFile -import kotlin.io.path.Path - -val STATES_WHERE_PLAN_EXIST = setOf( - TransformationStatus.PLANNED, - TransformationStatus.TRANSFORMING, - TransformationStatus.TRANSFORMED, - TransformationStatus.PARTIALLY_COMPLETED, - TransformationStatus.COMPLETED, -) - -val STATES_AFTER_INITIAL_BUILD = setOf( - TransformationStatus.PREPARED, - TransformationStatus.PLANNING, - *STATES_WHERE_PLAN_EXIST.toTypedArray() -) - -val STATES_AFTER_STARTED = setOf( - TransformationStatus.STARTED, - TransformationStatus.PREPARING, - *STATES_AFTER_INITIAL_BUILD.toTypedArray(), -) - -val STATES_WHERE_JOB_STOPPED_PRE_PLAN_READY = setOf( - TransformationStatus.FAILED, - TransformationStatus.STOPPED, - TransformationStatus.STOPPING, - TransformationStatus.REJECTED, - TransformationStatus.UNKNOWN_TO_SDK_VERSION, -) - -val TERMINAL_STATES = setOf( - TransformationStatus.FAILED, - TransformationStatus.STOPPED, - TransformationStatus.REJECTED, - TransformationStatus.PARTIALLY_COMPLETED, - TransformationStatus.COMPLETED, -) - -const val TROUBLESHOOTING_URL_DOWNLOAD_DIFF = - "https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html#w24aac14c20c19c11" -const val TROUBLESHOOTING_URL_MAVEN_COMMANDS = - "https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/troubleshooting-code-transformation.html#w24aac14c20c19b7" -const val TROUBLESHOOTING_URL_PREREQUISITES = - "https://docs.aws.amazon.com/amazonq/latest/aws-builder-use-ug/code-transformation.html#prerequisites" - -fun String.toVirtualFile() = VirtualFileManager.getInstance().findFileByUrl(VfsUtilCore.pathToUrl(this)) -fun Project.moduleFor(path: String) = ModuleUtil.findModuleForFile( - path.toVirtualFile() ?: throw RuntimeException("File not found $path"), - this, -) - -/** - * Unzips a zip into a dir. Returns the true when successfully unzips the file pointed to by [zipFilePath] to [destDir] - */ -fun unzipFile(zipFilePath: Path, destDir: Path): Boolean { - if (!zipFilePath.exists()) return false - val zipFile = ZipFile(zipFilePath.toFile()) - zipFile.use { file -> - file.entries().asSequence() - .filterNot { it.isDirectory } - .map { zipEntry -> - val destPath = destDir.resolve(zipEntry.name) - destPath.createParentDirectories() - FileOutputStream(destPath.toFile()).use { targetFile -> - zipFile.getInputStream(zipEntry).copyTo(targetFile) - } - }.toList() - } - return true -} - -fun String.toTransformationLanguage() = when (this) { - "JDK_1_8" -> TransformationLanguage.JAVA_8 - "JDK_11" -> TransformationLanguage.JAVA_11 - "JDK_17" -> TransformationLanguage.JAVA_17 - else -> TransformationLanguage.UNKNOWN_TO_SDK_VERSION -} - -fun calculateTotalLatency(startTime: Instant, endTime: Instant) = (endTime.toEpochMilli() - startTime.toEpochMilli()).toInt() - -data class PollingResult( - val succeeded: Boolean, - val jobDetails: TransformationJob?, - val state: TransformationStatus, - val transformationPlan: TransformationPlan? -) - -fun refreshToken(project: Project) { - val connection = ToolkitConnectionManager.getInstance(project).activeConnectionForFeature(QConnection.getInstance()) - val provider = (connection?.getConnectionSettings() as TokenConnectionSettings).tokenProvider.delegate as BearerTokenProvider - provider.refresh() -} - -/** - * Wrapper around [waitUntil] that polls the API DescribeMigrationJob to check the migration job status. - */ -suspend fun JobId.pollTransformationStatusAndPlan( - succeedOn: Set, - failOn: Set, - clientAdaptor: GumbyClient, - initialSleepDurationMillis: Long, - sleepDurationMillis: Long, - isDisposed: AtomicBoolean, - project: Project, - maxDuration: Duration = Duration.ofSeconds(604800), - onStateChange: (previousStatus: TransformationStatus?, currentStatus: TransformationStatus, transformationPlan: TransformationPlan?) -> Unit, -): PollingResult { - val telemetry = CodeTransformTelemetryManager.getInstance(project) - var state = TransformationStatus.UNKNOWN_TO_SDK_VERSION - var transformationResponse: GetTransformationResponse? = null - var transformationPlan: TransformationPlan? = null - var didSleepOnce = false - val maxRefreshes = 10 - var numRefreshes = 0 - refreshToken(project) - - try { - waitUntil( - succeedOn = { result -> result in succeedOn }, - failOn = { result -> result in failOn }, - maxDuration = maxDuration, - exceptionsToStopOn = setOf( - InternalServerException::class, - ValidationException::class, - AwsServiceException::class, - CodeWhispererRuntimeException::class, - RuntimeException::class, - ), - exceptionsToIgnore = setOf(ThrottlingException::class) - ) { - try { - if (!didSleepOnce) { - sleep(initialSleepDurationMillis) - didSleepOnce = true - } - if (isDisposed.get()) throw AlreadyDisposedException("The invoker is disposed.") - transformationResponse = clientAdaptor.getCodeModernizationJob(this.id) - val newStatus = transformationResponse?.transformationJob()?.status() ?: throw RuntimeException("Unable to get job status") - var newPlan: TransformationPlan? = null - if (newStatus in STATES_WHERE_PLAN_EXIST) { - sleep(sleepDurationMillis) - newPlan = clientAdaptor.getCodeModernizationPlan(this).transformationPlan() - } - if (newStatus != state) { - telemetry.jobStatusChanged(this, newStatus.toString(), state.toString()) - } - if (newPlan != transformationPlan) { - telemetry.jobStatusChanged(this, "PLAN_UPDATED", state.toString()) - } - if (newStatus !in failOn && (newStatus != state || newPlan != transformationPlan)) { - transformationPlan = newPlan - onStateChange(state, newStatus, transformationPlan) - } - state = newStatus - numRefreshes = 0 - return@waitUntil state - } catch (e: AccessDeniedException) { - if (numRefreshes++ > maxRefreshes) throw e - refreshToken(project) - return@waitUntil state - } finally { - sleep(sleepDurationMillis) - } - } - } catch (e: Exception) { - // Still call onStateChange to update the UI - onStateChange(state, TransformationStatus.FAILED, transformationPlan) - when (e) { - is WaiterUnrecoverableException, is AccessDeniedException -> { - return PollingResult(false, transformationResponse?.transformationJob(), state, transformationPlan) - } - else -> throw e - } - } - return PollingResult(true, transformationResponse?.transformationJob(), state, transformationPlan) -} - -fun filterOnlyParentFiles(filePaths: Set): List { - if (filePaths.isEmpty()) return listOf() - // sorts it like: - // foo - // foo/bar - // foo/bar/bas - val sorted = filePaths.sortedBy { Path(it.path).nameCount } - val uniquePrefixes = mutableSetOf(Path(sorted.first().path).parent) - val shortestRoots = mutableSetOf(sorted.first()) - shortestRoots.add(sorted.first()) - sorted.drop(1).forEach { file -> - if (uniquePrefixes.none { Path(file.path).startsWith(it) }) { - shortestRoots.add(file) - uniquePrefixes.add(Path(file.path).parent) - } else if (Path(file.path).parent in uniquePrefixes) { - shortestRoots.add(file) // handles multiple parent files on the same level - } - } - return shortestRoots.toList() -} - -/** - * @description For every directory, check if any supported build files (pom.xml etc) exists. - * If we find a valid build file, store it and stop further recursion. - */ -fun findBuildFiles(sourceFolder: File, supportedBuildFileNames: List): List { - val buildFiles = mutableListOf() - sourceFolder.walkTopDown() - .maxDepth(5) - .onEnter { currentDir -> - supportedBuildFileNames.forEach { - val maybeSupportedFile = currentDir.resolve(MAVEN_CONFIGURATION_FILE_NAME) - if (maybeSupportedFile.exists()) { - buildFiles.add(maybeSupportedFile) - return@onEnter false - } - } - return@onEnter true - }.forEach { - // noop, collects the sequence - } - return buildFiles -} - -fun isIntellij(): Boolean { - val productCode = ApplicationInfo.getInstance().build.productCode - return productCode == "IC" || productCode == "IU" -} - -fun isGradleProject(project: Project) = !GradleSettings.getInstance(project).linkedProjectsSettings.isEmpty() - -fun getJavaVersionFromProjectSetting(project: Project): String? = project.tryGetJdk()?.toString() - -fun getMavenVersion(project: Project): String { - val mavenSettings = MavenProjectsManager.getInstance(project).getGeneralSettings() - // should be set to "Bundled (Maven X)" if setup instructions were followed - return mavenSettings.getMavenHome() ?: "Unknown" -} - -fun openTroubleshootingGuideNotificationAction(targetUrl: String) = OpenBrowserAction( - message("codemodernizer.notification.info.view_troubleshooting_guide"), - url = targetUrl -) diff --git a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/ModuleUtils.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/ModuleUtils.kt deleted file mode 100644 index e41d45fb4d..0000000000 --- a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/ModuleUtils.kt +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -package software.aws.toolkits.jetbrains.services.codemodernizer.utils - -import com.intellij.openapi.application.runReadAction -import com.intellij.openapi.module.ModuleUtil -import com.intellij.openapi.project.Project -import com.intellij.openapi.project.modules -import com.intellij.openapi.projectRoots.JavaSdkVersion -import com.intellij.openapi.projectRoots.impl.JavaSdkImpl -import com.intellij.openapi.roots.ProjectRootManager -import com.intellij.openapi.vfs.VirtualFile - - -/** - * @description Try to get the project SDK version from the "project structure" settings - */ -fun Project.tryGetJdk(): JavaSdkVersion? { - val projectSdk = ProjectRootManager.getInstance(this).projectSdk - val javaSdk = JavaSdkImpl.getInstance() - return javaSdk.getVersion(projectSdk ?: return null) -} - -fun Project.getSupportedJavaMappings(supportedJavaMappings: Map>): List { - val projectSdk = ProjectRootManager.getInstance(this).projectSdk - val javaSdk = JavaSdkImpl.getInstance() - return if (projectSdk == null) { - listOf() - } else { - supportedJavaMappings.getOrDefault(javaSdk.getVersion(projectSdk), listOf()).map { it.name }.toList() - } -} - -private fun Project.getAllSupportedBuildFiles(supportedBuildFileNames: List): List { - /** - * Strategy: - * 1. Find folders with pom.xml or build.gradle.kts or build.gradle - * 2. Filter out subdirectories - */ - val projectRootManager = ProjectRootManager.getInstance(this) - val probableProjectRoot = this.basePath?.toVirtualFile() // May point to only one intellij module (the first opened one) - val probableContentRoots = projectRootManager.contentRoots.toMutableSet() // May not point to the topmost folder of modules - probableContentRoots.add(probableProjectRoot) // dedupe - val topLevelRoots = filterOnlyParentFiles(probableContentRoots) - return topLevelRoots.flatMap { root -> - findBuildFiles(root.toNioPath().toFile(), supportedBuildFileNames).mapNotNull { it.path.toVirtualFile() } - } -} - -fun Project.getSupportedBuildFilesWithSupportedJdk( - supportedBuildFileNames: List, - supportedJavaMappings: Map< - JavaSdkVersion, - Set - > -): List { - val detectedBuildFiles = this.getAllSupportedBuildFiles(supportedBuildFileNames) - val supportedModules = this.getSupportedModules(supportedJavaMappings).toSet() - val validProjectJdk = this.getSupportedJavaMappings(supportedJavaMappings).isNotEmpty() - val projectRootManager = ProjectRootManager.getInstance(this) - return detectedBuildFiles.filter { - val moduleOfFile = runReadAction { projectRootManager.fileIndex.getModuleForFile(it) } - return@filter (moduleOfFile in supportedModules) || (moduleOfFile == null && validProjectJdk) - } -} - -fun Project.getSupportedBuildModulesPath(supportedBuildFileNames: List): List { - val projectRootManager = ProjectRootManager.getInstance(this) - val probableProjectRoot = this.basePath?.toVirtualFile() // May point to only one intellij module (the first opened one) - val probableContentRoots = projectRootManager.contentRoots.toMutableSet() // May not point to the topmost folder of modules - probableContentRoots.add(probableProjectRoot) // dedupe - val topLevelRoots = filterOnlyParentFiles(probableContentRoots) - val detectedBuildFilePaths = topLevelRoots.flatMap { root -> - findBuildFiles(root.toNioPath().toFile(), supportedBuildFileNames).mapNotNull { it.path } - } - return detectedBuildFilePaths -} - -fun Project.getSupportedModules(supportedJavaMappings: Map>) = this.modules.filter { - val moduleJdk = it.tryGetJdk(this) ?: return@filter false - moduleJdk in supportedJavaMappings -} - -fun Project.getModuleOrProjectNameForFile(file: VirtualFile) = ModuleUtil.findModuleForFile(file, this)?.name ?: this.name diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt similarity index 100% rename from plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt rename to plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformApiUtils.kt diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformFileUtils.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformFileUtils.kt similarity index 100% rename from plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformFileUtils.kt rename to plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformFileUtils.kt diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformModuleUtils.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformModuleUtils.kt similarity index 100% rename from plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformModuleUtils.kt rename to plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformModuleUtils.kt diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformProjectUtils.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformProjectUtils.kt similarity index 100% rename from plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformProjectUtils.kt rename to plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformProjectUtils.kt diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformUtils.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformUtils.kt similarity index 100% rename from plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformUtils.kt rename to plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformUtils.kt diff --git a/plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformValidationUtils.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformValidationUtils.kt similarity index 100% rename from plugins/toolkit/jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformValidationUtils.kt rename to plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformValidationUtils.kt From 4e44fceb10c575d391af1eb18b27d1dd07573b89 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Wed, 3 Apr 2024 10:49:32 -0700 Subject: [PATCH 09/12] Chore - fix detekt issues --- .../codemodernizer/constants/CodeTransformChatItems.kt | 2 +- .../controller/CodeTransformChatController.kt | 2 +- .../ui/components/PreCodeTransformUserDialog.kt | 2 +- .../codemodernizer/utils/CodeTransformProjectUtils.kt | 1 - .../codemodernizer/CodeWhispererCodeModernizerTest.kt | 7 ++----- .../codemodernizer/CodeWhispererCodeModernizerUtilsTest.kt | 2 +- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/constants/CodeTransformChatItems.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/constants/CodeTransformChatItems.kt index 51127bb584..d45a12a068 100644 --- a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/constants/CodeTransformChatItems.kt +++ b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/constants/CodeTransformChatItems.kt @@ -6,7 +6,6 @@ package software.aws.toolkits.jetbrains.services.codemodernizer.constants import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import software.aws.toolkits.jetbrains.services.amazonq.CODE_TRANSFORM_TROUBLESHOOT_DOC -import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile import software.aws.toolkits.jetbrains.services.codemodernizer.messages.Button import software.aws.toolkits.jetbrains.services.codemodernizer.messages.CodeTransformButtonId import software.aws.toolkits.jetbrains.services.codemodernizer.messages.CodeTransformChatMessageContent @@ -16,6 +15,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.messages.FormItem import software.aws.toolkits.jetbrains.services.codemodernizer.messages.FormItemOption import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerJobCompletedResult import software.aws.toolkits.jetbrains.services.codemodernizer.model.ValidationResult +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile import software.aws.toolkits.jetbrains.services.cwc.clients.chat.model.FollowUpType import software.aws.toolkits.jetbrains.services.cwc.messages.FollowUp import software.aws.toolkits.resources.message diff --git a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt index b320a22b57..d03d4a9849 100644 --- a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt +++ b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt @@ -37,7 +37,6 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.constants.buildUs import software.aws.toolkits.jetbrains.services.codemodernizer.constants.buildUserInputChatContent import software.aws.toolkits.jetbrains.services.codemodernizer.constants.buildUserSelectionSummaryChatContent import software.aws.toolkits.jetbrains.services.codemodernizer.constants.buildUserStopTransformChatContent -import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile import software.aws.toolkits.jetbrains.services.codemodernizer.messages.AuthenticationNeededExceptionMessage import software.aws.toolkits.jetbrains.services.codemodernizer.messages.CodeTransformChatMessage import software.aws.toolkits.jetbrains.services.codemodernizer.messages.CodeTransformCommandMessage @@ -49,6 +48,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.model.MavenCopyCo import software.aws.toolkits.jetbrains.services.codemodernizer.session.ChatSessionStorage import software.aws.toolkits.jetbrains.services.codemodernizer.session.Session import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeModernizerSessionState +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile import software.aws.toolkits.jetbrains.services.codemodernizer.utils.toVirtualFile import software.aws.toolkits.jetbrains.services.cwc.messages.ChatMessageType import software.aws.toolkits.resources.message diff --git a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/ui/components/PreCodeTransformUserDialog.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/ui/components/PreCodeTransformUserDialog.kt index 89205ac035..85da3f5508 100644 --- a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/ui/components/PreCodeTransformUserDialog.kt +++ b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/ui/components/PreCodeTransformUserDialog.kt @@ -21,8 +21,8 @@ import com.intellij.ui.dsl.builder.columns import com.intellij.ui.dsl.builder.panel import com.intellij.ui.dsl.builder.toMutableProperty import software.aws.toolkits.jetbrains.services.codemodernizer.CodeTransformTelemetryManager -import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedJavaMappings import software.aws.toolkits.jetbrains.services.codemodernizer.model.CustomerSelection +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getSupportedJavaMappings import software.aws.toolkits.jetbrains.services.codemodernizer.utils.tryGetJdk import software.aws.toolkits.resources.message import kotlin.math.max diff --git a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformProjectUtils.kt b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformProjectUtils.kt index e41d45fb4d..d0a945de88 100644 --- a/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformProjectUtils.kt +++ b/plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/utils/CodeTransformProjectUtils.kt @@ -12,7 +12,6 @@ import com.intellij.openapi.projectRoots.impl.JavaSdkImpl import com.intellij.openapi.roots.ProjectRootManager import com.intellij.openapi.vfs.VirtualFile - /** * @description Try to get the project SDK version from the "project structure" settings */ diff --git a/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerTest.kt b/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerTest.kt index 1e66a8a855..7d65ba0f11 100644 --- a/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerTest.kt +++ b/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerTest.kt @@ -1,7 +1,7 @@ // Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -package software.aws.toolkits.jetbrains.services.codewhisperer.codemodernizer +package software.aws.toolkits.jetbrains.services.codemodernizer import com.intellij.testFramework.LightVirtualFile import junit.framework.TestCase.assertEquals @@ -17,12 +17,9 @@ import org.mockito.kotlin.spy import org.mockito.kotlin.times import org.mockito.kotlin.verify import org.mockito.kotlin.whenever -import software.aws.toolkits.jetbrains.services.codemodernizer.ArtifactHandler -import software.aws.toolkits.jetbrains.services.codemodernizer.DownloadArtifactResult -import software.aws.toolkits.jetbrains.services.codemodernizer.utils.filterOnlyParentFiles -import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerArtifact import software.aws.toolkits.jetbrains.services.codemodernizer.model.InvalidTelemetryReason import software.aws.toolkits.jetbrains.services.codemodernizer.model.ValidationResult +import software.aws.toolkits.jetbrains.services.codemodernizer.utils.filterOnlyParentFiles import software.aws.toolkits.jetbrains.services.codemodernizer.utils.unzipFile import software.aws.toolkits.resources.message import software.aws.toolkits.telemetry.CodeTransformPreValidationError diff --git a/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerUtilsTest.kt b/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerUtilsTest.kt index 64c3873fda..41e7438993 100644 --- a/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerUtilsTest.kt +++ b/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerUtilsTest.kt @@ -1,7 +1,7 @@ // Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -package software.aws.toolkits.jetbrains.services.codewhisperer.codemodernizer +package software.aws.toolkits.jetbrains.services.codemodernizer import kotlinx.coroutines.runBlocking import org.assertj.core.api.Assertions.assertThat From 1ee0abdd3a9956bd42e5934f9deb4cca0023a89f Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 4 Apr 2024 09:41:41 -0700 Subject: [PATCH 10/12] Chore - fix bad import in util file --- .../services/codemodernizer/auth/CodeTransformAuthUtils.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/auth/CodeTransformAuthUtils.kt b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/auth/CodeTransformAuthUtils.kt index 650ecef1e6..f58659c9ce 100644 --- a/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/auth/CodeTransformAuthUtils.kt +++ b/plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/auth/CodeTransformAuthUtils.kt @@ -8,7 +8,7 @@ import software.aws.toolkits.jetbrains.core.gettingstarted.editor.ActiveConnecti import software.aws.toolkits.jetbrains.core.gettingstarted.editor.ActiveConnectionType import software.aws.toolkits.jetbrains.core.gettingstarted.editor.BearerTokenFeatureSet import software.aws.toolkits.jetbrains.core.gettingstarted.editor.checkBearerConnectionValidity -import software.aws.toolkits.jetbrains.services.codemodernizer.utils.isIntellij +import software.aws.toolkits.jetbrains.services.codemodernizer.isIntellij fun isCodeTransformAvailable(project: Project): Boolean { if (!isIntellij()) return false From 7e24ef8c1451892e67e9305848b3c91ef9c8ba90 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 4 Apr 2024 10:52:44 -0700 Subject: [PATCH 11/12] Chore - fix util import in FeatureDevClient --- .../services/amazonqFeatureDev/clients/FeatureDevClient.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/clients/FeatureDevClient.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/clients/FeatureDevClient.kt index a5f91a3d0a..70e8232034 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/clients/FeatureDevClient.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/clients/FeatureDevClient.kt @@ -35,7 +35,7 @@ import software.aws.toolkits.jetbrains.core.awsClient import software.aws.toolkits.jetbrains.core.credentials.ToolkitConnectionManager import software.aws.toolkits.jetbrains.core.credentials.pinning.QConnection import software.aws.toolkits.jetbrains.services.amazonq.clients.AmazonQStreamingClient -import software.aws.toolkits.jetbrains.services.codemodernizer.utils.calculateTotalLatency +import software.aws.toolkits.jetbrains.services.codemodernizer.calculateTotalLatency import java.time.Instant import software.amazon.awssdk.services.codewhispererruntime.model.ChatTriggerType as SyncChatTriggerType From 77d65d1a3889658ea1e3a96d06c7a3ba92988e06 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 4 Apr 2024 14:01:56 -0700 Subject: [PATCH 12/12] Chore - add missing import post merge --- .../services/codemodernizer/CodeWhispererCodeModernizerTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerTest.kt b/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerTest.kt index 7d65ba0f11..d55038929c 100644 --- a/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerTest.kt +++ b/plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerTest.kt @@ -17,6 +17,7 @@ import org.mockito.kotlin.spy import org.mockito.kotlin.times import org.mockito.kotlin.verify import org.mockito.kotlin.whenever +import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerArtifact import software.aws.toolkits.jetbrains.services.codemodernizer.model.InvalidTelemetryReason import software.aws.toolkits.jetbrains.services.codemodernizer.model.ValidationResult import software.aws.toolkits.jetbrains.services.codemodernizer.utils.filterOnlyParentFiles