Skip to content

Commit b07c148

Browse files
committed
addressing comments on PR, detekt issues, and adding feature flag
1 parent f2ff3d4 commit b07c148

File tree

5 files changed

+87
-71
lines changed

5 files changed

+87
-71
lines changed

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/ArtifactHandler.kt

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ import com.intellij.openapi.vcs.changes.patch.ApplyPatchMode
1515
import com.intellij.openapi.vcs.changes.patch.ImportToShelfExecutor
1616
import com.intellij.openapi.vfs.LocalFileSystem
1717
import com.intellij.openapi.vfs.VirtualFile
18-
import java.io.File
19-
import java.nio.file.Files
20-
import java.nio.file.Path
21-
import java.time.Instant
22-
import java.util.concurrent.atomic.AtomicBoolean
2318
import kotlinx.coroutines.launch
2419
import kotlinx.coroutines.withContext
2520
import software.amazon.awssdk.services.codewhispererstreaming.model.TransformationDownloadArtifactType
@@ -28,6 +23,7 @@ import software.aws.toolkits.core.utils.error
2823
import software.aws.toolkits.core.utils.exists
2924
import software.aws.toolkits.core.utils.getLogger
3025
import software.aws.toolkits.core.utils.info
26+
import software.aws.toolkits.jetbrains.core.coroutines.EDT
3127
import software.aws.toolkits.jetbrains.core.coroutines.getCoroutineBgContext
3228
import software.aws.toolkits.jetbrains.core.coroutines.projectCoroutineScope
3329
import software.aws.toolkits.jetbrains.core.credentials.sso.bearer.NoTokenInitializedException
@@ -55,16 +51,22 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeModerni
5551
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getPathToHilArtifactDir
5652
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.isValidCodeTransformConnection
5753
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTroubleshootingGuideNotificationAction
54+
import software.aws.toolkits.jetbrains.utils.notifyInfo
5855
import software.aws.toolkits.jetbrains.utils.notifyStickyInfo
5956
import software.aws.toolkits.jetbrains.utils.notifyStickyWarn
6057
import software.aws.toolkits.resources.message
6158
import software.aws.toolkits.telemetry.CodeTransformArtifactType
6259
import software.aws.toolkits.telemetry.CodeTransformVCSViewerSrcComponents
60+
import java.io.File
61+
import java.nio.file.Files
62+
import java.nio.file.Path
63+
import java.time.Instant
64+
import java.util.concurrent.atomic.AtomicBoolean
6365

6466
const val DOWNLOAD_PROXY_WILDCARD_ERROR: String = "Dangling meta character '*' near index 0"
6567
const val DOWNLOAD_SSL_HANDSHAKE_ERROR: String = "Unable to execute HTTP request: javax.net.ssl.SSLHandshakeException"
6668
const val INVALID_ARTIFACT_ERROR: String = "Invalid artifact"
67-
val patchDescriptions: Map<String, String> = mapOf(
69+
val patchDescriptions = mapOf(
6870
"Prepare minimal upgrade to Java 17" to "This diff patch covers the set of upgrades for Springboot, JUnit, and PowerMockito frameworks.",
6971
"Popular Enterprise Specifications and Application Frameworks upgrade" to "This diff patch covers the set of upgrades for Jakarta EE 10, Hibernate 6.2, " +
7072
"and Micronaut 3.",
@@ -74,8 +76,7 @@ val patchDescriptions: Map<String, String> = mapOf(
7476
"Jenkins plugins and the Maven Wrapper.",
7577
"Miscellaneous Processing Documentation upgrade" to "This diff patch covers a diverse set of upgrades spanning ORMs, XML processing, API documentation, " +
7678
"and more.",
77-
"Updated dependencies to latest version" to "",
78-
"Upgrade Deprecated API" to ""
79+
"Deprecated API replacement and dependency upgrades" to "This diff patch replaces deprecated APIs and makes additional dependency version upgrades."
7980
)
8081

8182
class ArtifactHandler(
@@ -89,6 +90,7 @@ class ArtifactHandler(
8990
private val downloadedBuildLogPath = mutableMapOf<JobId, Path>()
9091
private var isCurrentlyDownloading = AtomicBoolean(false)
9192
private var totalPatchFiles: Int = 0
93+
private var sharedPatchIndex: Int = 0
9294

9395
internal suspend fun displayDiff(job: JobId, source: CodeTransformVCSViewerSrcComponents) {
9496
if (isCurrentlyDownloading.get()) return
@@ -277,14 +279,14 @@ class ArtifactHandler(
277279
/**
278280
* Opens the built-in patch dialog to display the diff and allowing users to apply the changes locally.
279281
*/
280-
internal fun displayDiffUsingPatch(
282+
internal suspend fun displayDiffUsingPatch(
281283
patchFile: VirtualFile,
282284
totalPatchFiles: Int,
283285
diffDescription: PatchInfo?,
284286
jobId: JobId,
285287
source: CodeTransformVCSViewerSrcComponents,
286288
) {
287-
runInEdt {
289+
withContext(EDT) {
288290
val dialog = ApplyPatchDifferentiatedDialog(
289291
project,
290292
ApplyPatchDefaultExecutor(project),
@@ -309,44 +311,41 @@ class ArtifactHandler(
309311
dialog.isModal = true
310312

311313
if (dialog.showAndGet()) {
312-
projectCoroutineScope(project).launch {
313-
telemetry.viewArtifact(CodeTransformArtifactType.ClientInstructions, jobId, "Submit", source)
314-
if (diffDescription == null) {
315-
val message = "I applied the changes to your project."
316-
val resultContent = CodeTransformChatMessageContent(
317-
type = CodeTransformChatMessageType.PendingAnswer,
318-
message = message,
319-
)
320-
codeTransformChatHelper?.updateLastPendingMessage(resultContent)
321-
codeTransformChatHelper?.addNewMessage(buildStartNewTransformFollowup())
322-
} else {
323-
if (getCurrentPatchIndex() < totalPatchFiles) {
324-
val message = "I applied the changes in diff patch ${getCurrentPatchIndex() + 1} of $totalPatchFiles. " +
325-
"${patchDescriptions[diffDescription.name]}"
326-
val notificationMessage = "Amazon Q applied the changes in diff patch ${getCurrentPatchIndex() + 1} of $totalPatchFiles " +
327-
"to your project."
328-
val notificationTitle = "Diff patch ${getCurrentPatchIndex() + 1} of $totalPatchFiles applied"
329-
setCurrentPatchIndex(getCurrentPatchIndex() + 1)
330-
notifyStickyInfo(notificationTitle, notificationMessage, project)
331-
if (getCurrentPatchIndex() == totalPatchFiles) {
332-
codeTransformChatHelper?.updateLastPendingMessage(
333-
CodeTransformChatMessageContent(type = CodeTransformChatMessageType.PendingAnswer, message = message)
334-
)
335-
} else {
336-
codeTransformChatHelper?.updateLastPendingMessage(
337-
CodeTransformChatMessageContent(
338-
type = CodeTransformChatMessageType.PendingAnswer,
339-
message = message,
340-
buttons = listOf(
341-
createViewDiffButton("View diff ${getCurrentPatchIndex() + 1}/$totalPatchFiles"),
342-
viewSummaryButton
343-
)
314+
telemetry.viewArtifact(CodeTransformArtifactType.ClientInstructions, jobId, "Submit", source)
315+
if (diffDescription == null) {
316+
val resultContent = CodeTransformChatMessageContent(
317+
type = CodeTransformChatMessageType.PendingAnswer,
318+
message = message("codemodernizer.chat.message.changes_applied"),
319+
)
320+
codeTransformChatHelper?.updateLastPendingMessage(resultContent)
321+
codeTransformChatHelper?.addNewMessage(buildStartNewTransformFollowup())
322+
} else {
323+
if (getCurrentPatchIndex() < totalPatchFiles) {
324+
val message = "I applied the changes in diff patch ${getCurrentPatchIndex() + 1} of $totalPatchFiles. " +
325+
"${patchDescriptions[diffDescription.name]}"
326+
val notificationMessage = "Amazon Q applied the changes in diff patch ${getCurrentPatchIndex() + 1} of $totalPatchFiles " +
327+
"to your project."
328+
val notificationTitle = "Diff patch ${getCurrentPatchIndex() + 1} of $totalPatchFiles applied"
329+
setCurrentPatchIndex(getCurrentPatchIndex() + 1)
330+
notifyInfo(notificationTitle, notificationMessage, project)
331+
if (getCurrentPatchIndex() == totalPatchFiles) {
332+
codeTransformChatHelper?.updateLastPendingMessage(
333+
CodeTransformChatMessageContent(type = CodeTransformChatMessageType.PendingAnswer, message = message)
334+
)
335+
} else {
336+
codeTransformChatHelper?.updateLastPendingMessage(
337+
CodeTransformChatMessageContent(
338+
type = CodeTransformChatMessageType.PendingAnswer,
339+
message = message,
340+
buttons = listOf(
341+
createViewDiffButton("View diff ${getCurrentPatchIndex() + 1}/$totalPatchFiles"),
342+
viewSummaryButton
344343
)
345344
)
346-
}
347-
} else {
348-
codeTransformChatHelper?.addNewMessage(buildStartNewTransformFollowup())
345+
)
349346
}
347+
} else {
348+
codeTransformChatHelper?.addNewMessage(buildStartNewTransformFollowup())
350349
}
351350
}
352351
} else {
@@ -471,6 +470,12 @@ class ArtifactHandler(
471470

472471
fun getSummary(job: JobId) = downloadedSummaries[job]
473472

473+
private fun getCurrentPatchIndex() = sharedPatchIndex
474+
475+
private fun setCurrentPatchIndex(index: Int) {
476+
sharedPatchIndex = index
477+
}
478+
474479
private fun showSummaryFromFile(summaryFile: File) {
475480
val summaryMarkdownVirtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(summaryFile)
476481
if (summaryMarkdownVirtualFile != null) {
@@ -529,10 +534,5 @@ class ArtifactHandler(
529534

530535
companion object {
531536
val LOG = getLogger<ArtifactHandler>()
532-
private var sharedPatchIndex: Int = 0
533-
fun getCurrentPatchIndex() = sharedPatchIndex
534-
fun setCurrentPatchIndex(index: Int) {
535-
sharedPatchIndex = index
536-
}
537537
}
538538
}

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/controller/CodeTransformChatController.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.CodeTransformTele
2929
import software.aws.toolkits.jetbrains.services.codemodernizer.EXPLAINABILITY_V1
3030
import software.aws.toolkits.jetbrains.services.codemodernizer.HilTelemetryMetaData
3131
import software.aws.toolkits.jetbrains.services.codemodernizer.InboundAppMessagesHandler
32+
import software.aws.toolkits.jetbrains.services.codemodernizer.SELECTIVE_TRANSFORMATION_V1
3233
import software.aws.toolkits.jetbrains.services.codemodernizer.client.GumbyClient
3334
import software.aws.toolkits.jetbrains.services.codemodernizer.commands.CodeTransformActionMessage
3435
import software.aws.toolkits.jetbrains.services.codemodernizer.commands.CodeTransformCommand
@@ -98,7 +99,6 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.model.MavenDepend
9899
import software.aws.toolkits.jetbrains.services.codemodernizer.model.UploadFailureReason
99100
import software.aws.toolkits.jetbrains.services.codemodernizer.model.ValidationResult
100101
import software.aws.toolkits.jetbrains.services.codemodernizer.panels.managers.CodeModernizerBottomWindowPanelManager
101-
import software.aws.toolkits.jetbrains.services.codemodernizer.SELECTIVE_TRANSFORMATION_V1
102102
import software.aws.toolkits.jetbrains.services.codemodernizer.session.ChatSessionStorage
103103
import software.aws.toolkits.jetbrains.services.codemodernizer.session.Session
104104
import software.aws.toolkits.jetbrains.services.codemodernizer.state.CodeModernizerSessionState
@@ -378,13 +378,20 @@ class CodeTransformChatController(
378378
message("codemodernizer.chat.message.skip_tests_form.skip") -> MAVEN_BUILD_SKIP_UNIT_TESTS
379379
else -> MAVEN_BUILD_RUN_UNIT_TESTS
380380
}
381+
//feature flag for Selective Transformation
382+
val isSelectiveTransformationReady = false
381383
codeTransformChatHelper.addNewMessage(buildUserSkipTestsFlagSelectionChatContent(message.skipTestsSelection))
382384
codeModernizerManager.codeTransformationSession?.let {
383385
it.sessionContext.customBuildCommand = customBuildCommand
386+
if (!isSelectiveTransformationReady){
387+
codeModernizerManager.runLocalMavenBuild(context.project, it)
388+
}
384389
}
385-
codeTransformChatHelper.run {
386-
addNewMessage(buildUserInputOneOrMultipleDiffsChatIntroContent())
387-
addNewMessage(buildUserInputOneOrMultipleDiffsFlagChatContent())
390+
if (isSelectiveTransformationReady){
391+
codeTransformChatHelper.run {
392+
addNewMessage(buildUserInputOneOrMultipleDiffsChatIntroContent())
393+
addNewMessage(buildUserInputOneOrMultipleDiffsFlagChatContent())
394+
}
388395
}
389396
}
390397

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/model/CodeModernizerArtifact.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,22 @@ open class CodeModernizerArtifact(
117117
}
118118
}
119119

120-
@OptIn(ExperimentalPathApi::class)
121120
private fun extractPatches(manifest: CodeModernizerManifest, description: List<PatchInfo>?): List<VirtualFile> {
122121
if (description == null) {
123122
return extractSinglePatch(manifest)
124123
}
125124
val fileSystem = LocalFileSystem.getInstance()
126125
val patchesDir = tempDir.toPath().resolve(manifest.patchesRoot)
127126
if (!patchesDir.isDirectory()) {
128-
throw RuntimeException("Expected root for patches was not a directory.")
127+
error("Expected root for patches was not a directory.")
129128
}
130129
return description.map { patchInfo ->
131130
val patchFile = patchesDir.resolve(patchInfo.filename)
132131
if (patchFile.toFile().exists()) {
133132
fileSystem.findFileByNioFile(patchFile)
134-
?: throw RuntimeException("Could not find patch: ${patchInfo.filename}")
133+
?: error("Could not find patch: ${patchInfo.filename}")
135134
} else {
136-
throw RuntimeException("Patch file not found: ${patchInfo.filename}")
135+
error("Patch file not found: ${patchInfo.filename}")
137136
}
138137
}
139138
}
@@ -163,7 +162,7 @@ open class CodeModernizerArtifact(
163162
// No JSON description file found, return null
164163
return null
165164
}
166-
val descriptionContent: DescriptionContent = MAPPER.readValue(descriptionFile, DescriptionContent::class.java)
165+
val descriptionContent: DescriptionContent = MAPPER.readValue(descriptionFile)
167166
return descriptionContent.content
168167
}
169168
}

plugins/amazonq/codetransform/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codemodernizer/CodeWhispererCodeModernizerTestBase.kt

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ open class CodeWhispererCodeModernizerTestBase(
9393
internal val minJDKUpgradePatchResource = "min_jdk_upgrade.patch".toResourceFile()
9494
internal val minJDKUpgradePatchResourceFile = LightVirtualFile("min_jdk_upgrade.patch", minJDKUpgradePatchResource.readText())
9595
internal val enterpriseApplicationUpgradePatchResource = "popular_enterprise_application_framework.patch".toResourceFile()
96-
internal val enterpriseApplicationUpgradePatchResourceFile = LightVirtualFile("popular_enterprise_application_framework.patch",
97-
enterpriseApplicationUpgradePatchResource.readText())
96+
internal val enterpriseApplicationUpgradePatchResourceFile = LightVirtualFile(
97+
"popular_enterprise_application_framework.patch",
98+
enterpriseApplicationUpgradePatchResource.readText()
99+
)
98100
internal val testingToolPatchResource = "testing_tool.patch".toResourceFile()
99101
internal val testingToolPatchResourceFile = LightVirtualFile("testing_tool.patch", testingToolPatchResource.readText())
100102
internal val deprecatedAPIPatchResource = "update_deprecated_api.patch".toResourceFile()
@@ -299,13 +301,15 @@ open class CodeWhispererCodeModernizerTestBase(
299301
val summaryFileMock = Mockito.mock(File::class.java)
300302
val logFileMock = Mockito.mock(File::class.java)
301303
doReturn("dummy/path").whenever(virtualFileMock).path
302-
testSessionContextSpy = spy(CodeModernizerSessionContext(
303-
project,
304-
virtualFileMock,
305-
JavaSdkVersion.JDK_1_8,
306-
JavaSdkVersion.JDK_11,
307-
listOf("EXPLAINABILITY_V1", "SELECTIVE_TRANSFORMATION_V1"),
308-
"test")
304+
testSessionContextSpy = spy(
305+
CodeModernizerSessionContext(
306+
project,
307+
virtualFileMock,
308+
JavaSdkVersion.JDK_1_8,
309+
JavaSdkVersion.JDK_11,
310+
listOf("EXPLAINABILITY_V1", "SELECTIVE_TRANSFORMATION_V1"),
311+
"test"
312+
)
309313
)
310314

311315
testSessionSpy = spy(CodeModernizerSession(testSessionContextSpy, 0, 0))
@@ -316,8 +320,12 @@ open class CodeWhispererCodeModernizerTestBase(
316320
CodeModernizerArtifact(
317321
exampleZipPath.toAbsolutePath().toString(),
318322
validManifest,
319-
listOf(minJDKUpgradePatchResourceFile, enterpriseApplicationUpgradePatchResourceFile,
320-
testingToolPatchResourceFile, deprecatedAPIPatchResourceFile),
323+
listOf(
324+
minJDKUpgradePatchResourceFile,
325+
enterpriseApplicationUpgradePatchResourceFile,
326+
testingToolPatchResourceFile,
327+
deprecatedAPIPatchResourceFile
328+
),
321329
exampleDescriptionContent.content,
322330
validTransformationSummary,
323331
summaryFileMock,

plugins/core/resources/resources/software/aws/toolkits/resources/MessagesBundle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ codemodernizer.chat.message.button.view_diff=View diff
583583
codemodernizer.chat.message.button.view_failure_build_log=View Failure Build Log
584584
codemodernizer.chat.message.button.view_summary=View summary
585585
codemodernizer.chat.message.choose_objective=Enter "language upgrade" or "SQL conversion"
586+
codemodernizer.chat.message.changes_applied=I applied the changes to your project.
586587
codemodernizer.chat.message.download_failed_client_instructions_expired=Your transformation is not available anymore. Your code and transformation summary are deleted 24 hours after the transformation completes. Please try starting the transformation again.
587588
codemodernizer.chat.message.download_failed_invalid_artifact=Sorry, I was unable to find your {0}. Artifacts are deleted after 24 hours. Please try starting the transformation again.
588589
codemodernizer.chat.message.download_failed_other=Sorry, I ran into an issue while trying to download your {0}. Please try again. {1}
@@ -617,7 +618,8 @@ I can now divide the transformation results into diff patches (if applicable to
617618
- Popular Enterprise Specifications Application Frameworks: Popular enterprise and application frameworks like Jakarta EE, Hibernate, and Micronaut 3.\n\n\
618619
- HTTP Client Utilities Web Frameworks: HTTP client libraries, Apache Commons utilities, and Struts frameworks.\n\n\
619620
- Testing Tools Frameworks: Testing tools like ArchUnit, Mockito, and TestContainers and build tools like Jenkins and Maven Wrapper.\n\n\
620-
- Miscellaneous Processing Documentation: Diverse set spanning ORMs, XML processing, and API documentation like Swagger to SpringDoc/OpenAPI.
621+
- Miscellaneous Processing Documentation: Diverse set spanning ORMs, XML processing, and API documentation like Swagger to SpringDoc/OpenAPI.\n\n\
622+
- Deprecated API replacement and dependency upgrades: Replaces deprecated APIs and makes additional dependency version upgrades.
621623
codemodernizer.chat.message.one_or_multiple_diffs_form.multiple_diffs=Multiple diffs
622624
codemodernizer.chat.message.one_or_multiple_diffs_form.one_diff=One diff
623625
codemodernizer.chat.message.one_or_multiple_diffs_form.response=Okay, I will create {0} when providing the proposed changes.

0 commit comments

Comments
 (0)