Skip to content

Commit f89c49f

Browse files
committed
fixing one diff and off by one error for multiple diffs and addressing build log errors
1 parent 61b088b commit f89c49f

File tree

9 files changed

+35
-48
lines changed

9 files changed

+35
-48
lines changed

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,33 @@ import java.nio.file.Files
5858
import java.nio.file.Path
5959
import java.time.Instant
6060
import java.util.concurrent.atomic.AtomicBoolean
61-
import kotlinx.coroutines.CoroutineScope
62-
import kotlinx.coroutines.Dispatchers
6361
import software.aws.toolkits.jetbrains.services.codemodernizer.constants.buildStartNewTransformFollowup
6462

6563
const val DOWNLOAD_PROXY_WILDCARD_ERROR: String = "Dangling meta character '*' near index 0"
6664
const val DOWNLOAD_SSL_HANDSHAKE_ERROR: String = "Unable to execute HTTP request: javax.net.ssl.SSLHandshakeException"
6765
const val INVALID_ARTIFACT_ERROR: String = "Invalid artifact"
6866
val patchDescriptions: Map<String, String> = mapOf(
6967
"Prepare minimal upgrade to Java 17" to "This diff patch covers the set of upgrades for Springboot, JUnit, and PowerMockito frameworks.",
70-
"Popular Enterprise Specifications and Application Frameworks upgrade" to "This diff patch covers the set of upgrades for Jakarta EE 10, Hibernate 6.2, and Micronaut 3.",
71-
"HTTP Client Utilities, Apache Commons Utilities, and Web Frameworks" to "This diff patch covers the set of upgrades for Apache HTTP Client 5, Apache Commons utilities (Collections, IO, Lang, Math), Struts 6.0.",
72-
"Testing Tools and Frameworks upgrade" to "This diff patch covers the set of upgrades for ArchUnit, Mockito, TestContainers, Cucumber, and additionally, Jenkins plugins and the Maven Wrapper.",
73-
"Miscellaneous Processing Documentation upgrade" to "This diff patch covers a diverse set of upgrades spanning ORMs, XML processing, API documentation, and more.",
68+
"Popular Enterprise Specifications and Application Frameworks upgrade" to "This diff patch covers the set of upgrades for Jakarta EE 10, Hibernate 6.2, " +
69+
"and Micronaut 3.",
70+
"HTTP Client Utilities, Apache Commons Utilities, and Web Frameworks" to "This diff patch covers the set of upgrades for Apache HTTP Client 5, Apache " +
71+
"Commons utilities (Collections, IO, Lang, Math), Struts 6.0.",
72+
"Testing Tools and Frameworks upgrade" to "This diff patch covers the set of upgrades for ArchUnit, Mockito, TestContainers, Cucumber, and additionally, " +
73+
"Jenkins plugins and the Maven Wrapper.",
74+
"Miscellaneous Processing Documentation upgrade" to "This diff patch covers a diverse set of upgrades spanning ORMs, XML processing, API documentation, " +
75+
"and more.",
7476
"Updated dependencies to latest version" to "",
7577
"Upgrade Deprecated API" to ""
7678
)
7779

78-
class ArtifactHandler(private val project: Project, private val clientAdaptor: GumbyClient, private val codeTransformChatHelper: CodeTransformChatHelper? = null) {
80+
class ArtifactHandler(private val project: Project, private val clientAdaptor: GumbyClient,
81+
private val codeTransformChatHelper: CodeTransformChatHelper? = null) {
7982
private val telemetry = CodeTransformTelemetryManager.getInstance(project)
8083
private val downloadedArtifacts = mutableMapOf<JobId, Path>()
8184
private val downloadedSummaries = mutableMapOf<JobId, TransformationSummary>()
8285
private val downloadedBuildLogPath = mutableMapOf<JobId, Path>()
8386
private var isCurrentlyDownloading = AtomicBoolean(false)
84-
private val scope = CoroutineScope(Dispatchers.Default)
87+
// private val scope = CoroutineScope(Dispatchers.Default)
8588
private var totalPatchFiles: Int = 0
8689

8790

@@ -261,7 +264,8 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
261264
/**
262265
* Opens the built-in patch dialog to display the diff and allowing users to apply the changes locally.
263266
*/
264-
internal suspend fun displayDiffUsingPatch(patchFile: VirtualFile, totalPatchFiles: Int, diffDescription: PatchInfo?, jobId: JobId, source: CodeTransformVCSViewerSrcComponents) {
267+
internal suspend fun displayDiffUsingPatch(patchFile: VirtualFile, totalPatchFiles: Int, diffDescription: PatchInfo?, jobId: JobId,
268+
source: CodeTransformVCSViewerSrcComponents) {
265269
runInEdt {
266270
val dialog = ApplyPatchDifferentiatedDialog(
267271
project,
@@ -286,11 +290,11 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
286290
dialog.isModal = true
287291

288292
if (dialog.showAndGet()) {
289-
scope.launch {
293+
projectCoroutineScope(project).launch {
290294
telemetry.viewArtifact(CodeTransformArtifactType.ClientInstructions, jobId, "Submit", source)
291295
if (getCurrentPatchIndex() < totalPatchFiles){
292296
val message = if (diffDescription != null) {
293-
"I applied the changes in diff patch ${getCurrentPatchIndex()} of $totalPatchFiles. ${patchDescriptions[diffDescription.name]} You can make a commit if the diff shows success. If the diff shows partial success, apply and fix the errors, and start a new transformation."
297+
"I applied the changes in diff patch ${getCurrentPatchIndex() + 1} of $totalPatchFiles. ${patchDescriptions[diffDescription.name]}"
294298
} else {
295299
"I applied the changes to your project."
296300
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,12 +560,6 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
560560
resumeJob(session, lastJobId, currentJobResult)
561561
}
562562

563-
// private fun displayDiffNotificationAction(jobId: JobId): NotificationAction = NotificationAction.createSimple(
564-
// message("codemodernizer.notification.info.modernize_complete.view_diff")
565-
// ) {
566-
// artifactHandler.displayDiffAction(jobId, CodeTransformVCSViewerSrcComponents.ToastNotification)
567-
// }
568-
569563
private fun displaySummaryNotificationAction(jobId: JobId) =
570564
NotificationAction.createSimple(message("codemodernizer.notification.info.modernize_complete.view_summary")) {
571565
artifactHandler.showTransformationSummary(jobId)

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ private val viewDiffButton = Button(
8787
)
8888

8989
fun createViewDiffButton(buttonLabel: String): Button {
90-
return Button(
91-
id = CodeTransformButtonId.ViewDiff.id,
92-
text = buttonLabel,
93-
keepCardAfterClick = true
94-
)
90+
return Button(id = CodeTransformButtonId.ViewDiff.id, text = buttonLabel, keepCardAfterClick = true)
9591
}
9692

9793
val viewSummaryButton = Button(

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ fun runMavenCopyCommands(sourceFolder: File, buildlogBuilder: StringBuilder, log
6363
val telemetry = CodeTransformTelemetryManager.getInstance(project)
6464
var telemetryErrorMessage = ""
6565
var telemetryLocalBuildResult = Result.Succeeded
66-
// return MavenCopyCommandsResult.Success(destinationDir.toFile())
6766

6867
logger.info { "Executing IntelliJ bundled Maven" }
6968
try {

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import java.io.File
1818
import kotlin.io.path.ExperimentalPathApi
1919
import kotlin.io.path.Path
2020
import kotlin.io.path.isDirectory
21-
21+
import kotlin.io.path.walk
2222

2323

2424
/**
@@ -61,7 +61,6 @@ open class CodeModernizerArtifact(
6161
val patches = extractPatches(manifest, description)
6262
val summary = extractSummary(manifest)
6363
val summaryMarkdownFile = getSummaryFile(manifest)
64-
// if (patches.size != 1) throw RuntimeException("Expected 1 patch, but found ${patches.size}")
6564
return CodeModernizerArtifact(zipPath, manifest, patches, description, summary, summaryMarkdownFile)
6665
}
6766
throw RuntimeException("Could not find artifact")
@@ -101,7 +100,7 @@ open class CodeModernizerArtifact(
101100
@OptIn(ExperimentalPathApi::class)
102101
private fun extractPatches(manifest: CodeModernizerManifest, description: List<PatchInfo>?): List<VirtualFile> {
103102
if (description == null) {
104-
return listOf(extractSinglePatch(manifest))
103+
return extractSinglePatch(manifest)
105104
}
106105
val fileSystem = LocalFileSystem.getInstance()
107106
val patchesDir = tempDir.toPath().resolve(manifest.patchesRoot)
@@ -119,17 +118,15 @@ open class CodeModernizerArtifact(
119118
}
120119
}
121120
@OptIn(ExperimentalPathApi::class)
122-
private fun extractSinglePatch(manifest: CodeModernizerManifest): VirtualFile {
121+
private fun extractSinglePatch(manifest: CodeModernizerManifest): List<VirtualFile> {
123122
val fileSystem = LocalFileSystem.getInstance()
124123
val patchesDir = tempDir.toPath().resolve(manifest.patchesRoot)
125-
126124
if (!patchesDir.isDirectory()) {
127125
throw RuntimeException("Expected root for patches was not a directory.")
128126
}
129-
130-
val diffPatchFile = patchesDir.resolve("diff.patch")
131-
return fileSystem.findFileByNioFile(diffPatchFile.parent.resolve("diff.patch"))
132-
?: throw IllegalStateException("Could not find diff.patch in directory: ${diffPatchFile.parent}")
127+
return patchesDir.walk()
128+
.map { fileSystem.refreshAndFindFileByNioFile(it) ?: throw RuntimeException("Could not find diff.patch") }
129+
.toList()
133130

134131
}
135132

plugins/amazonq/codetransform/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codemodernizer/panels/managers/CodeModernizerBottomWindowPanelManager.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ class CodeModernizerBottomWindowPanelManager(private val project: Project) : JPa
207207
private fun setJobCompletedSuccessfullyUI() {
208208
add(BorderLayout.CENTER, buildProgressSplitterPanelManager)
209209
buildProgressSplitterPanelManager.apply {
210-
// addViewDiffToBanner()
211210
addViewSummaryToBanner()
212211
banner.updateContent(message("codemodernizer.toolwindow.banner.run_scan_complete"), AllIcons.Actions.Commit)
213212
setSplitPanelStopView()
@@ -278,8 +277,6 @@ class CodeModernizerBottomWindowPanelManager(private val project: Project) : JPa
278277

279278
fun addPlanToBanner() = banner.updateActions(banner.showPlanAction)
280279

281-
fun addViewDiffToBanner() = banner.updateActions(banner.showDiffAction)
282-
283280
fun addViewSummaryToBanner() = banner.updateActions(banner.showSummaryAction)
284281

285282
private fun stopTimer() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class CodeModernizerState : BaseState() {
6767
configurationFile,
6868
sourceJavaSdkVersion,
6969
targetJavaSdkVersion,
70-
listOf(EXPLAINABILITY_V1), //should this be from lastJobContext? , defaulting to one diff
70+
listOf(EXPLAINABILITY_V1), //default to one diff
7171
lastJobContext[JobDetails.CUSTOM_BUILD_COMMAND] ?: MAVEN_BUILD_RUN_UNIT_TESTS // default to running unit tests
7272
)
7373
}

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererConstants.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ object CodeWhispererConstants {
119119
}
120120

121121
object Config {
122-
const val CODEWHISPERER_ENDPOINT = "https://rts.alpha-us-west-2.codewhisperer.ai.aws.dev/" // PROD
122+
const val CODEWHISPERER_ENDPOINT = "https://codewhisperer.us-east-1.amazonaws.com/" // PROD
123123
const val CODEWHISPERER_IDPOOL_ID = "us-east-1:70717e99-906f-4add-908c-bd9074a2f5b9"
124124
val Sigv4ClientRegion = Region.US_EAST_1
125125
val BearerClientRegion = Region.US_EAST_1

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ code.aws.workspaces=Amazon CodeCatalyst
561561
code.aws.workspaces.short=Dev Environments
562562
codemodernizer.builderrordialog.description.title=Error occurred when building your project
563563
codemodernizer.chat.form.user_selection.item.choose_module=Choose a module to transform
564-
codemodernizer.chat.form.user_selection.item.choose_skip_tests_option=Choose to skip unit tests
565564
codemodernizer.chat.form.user_selection.item.choose_one_or_multiple_diffs_option=Choose how to receive proposed changes
565+
codemodernizer.chat.form.user_selection.item.choose_skip_tests_option=Choose to skip unit tests
566566
codemodernizer.chat.form.user_selection.item.choose_target_version=Choose the target code version
567567
codemodernizer.chat.form.user_selection.title=Q - Code transformation
568568
codemodernizer.chat.message.absolute_path_detected=I detected {0} potential absolute file path(s) in your {1} file: **{2}**. Absolute file paths might cause issues when I build your code. Any errors will show up in the build log.
@@ -606,6 +606,16 @@ codemodernizer.chat.message.hil.user_rejected=I'll continue upgrading your modul
606606
codemodernizer.chat.message.local_build_begin=I'm building your module. This can take up to 10 minutes, depending on the size of your module.
607607
codemodernizer.chat.message.local_build_failed=Sorry, I couldn't run the Maven clean install command to build your module.
608608
codemodernizer.chat.message.local_build_success=I was able to build your module and will start uploading your code.
609+
codemodernizer.chat.message.one_or_multiple_diffs=\
610+
I can now divide the transformation results into diff patches (if applicable to the app) if you would like to review and accept each diff with fewer changes:\n\n\
611+
- Minimal Compatible Library Upgrade to Java 17: Dependencies to the minimum compatible versions in Java 17, including Springboot, JUnit, and PowerMockito.\n\n\
612+
- Popular Enterprise Specifications Application Frameworks: Popular enterprise and application frameworks like Jakarta EE, Hibernate, and Micronaut 3.\n\n\
613+
- HTTP Client Utilities Web Frameworks: HTTP client libraries, Apache Commons utilities, and Struts frameworks.\n\n\
614+
- Testing Tools Frameworks: Testing tools like ArchUnit, Mockito, and TestContainers and build tools like Jenkins and Maven Wrapper.\n\n\
615+
- Miscellaneous Processing Documentation: Diverse set spanning ORMs, XML processing, and API documentation like Swagger to SpringDoc/OpenAPI.
616+
codemodernizer.chat.message.one_or_multiple_diffs_form.multiple_diffs=Multiple diffs
617+
codemodernizer.chat.message.one_or_multiple_diffs_form.one_diff=One diff
618+
codemodernizer.chat.message.one_or_multiple_diffs_form.response=Okay, I will create {0} when providing the proposed changes.
609619
codemodernizer.chat.message.result.fail=Sorry, I ran into an issue during the transformation. Please try again.
610620
codemodernizer.chat.message.result.fail_initial_build=I am having trouble building your project in the secure build environment and couldn't complete the transformation.
611621
codemodernizer.chat.message.result.fail_initial_build_no_build_log=I am having trouble building your project in the secure build environment: {0}.
@@ -618,19 +628,9 @@ codemodernizer.chat.message.result.zip_too_large=Sorry, your project size exceed
618628
codemodernizer.chat.message.resume_ongoing=I'm still transforming your code. It can take 10 to 30 minutes to upgrade your code, depending on the size of your module. To monitor progress, go to the Transformation Hub.
619629
codemodernizer.chat.message.skip_tests=I will build your module using `mvn test` by default. If you would like me to build your module without running unit tests, I will use `mvn test-compile`.
620630
codemodernizer.chat.message.skip_tests_form.response=Okay, I will {0} when building your module.
621-
codemodernizer.chat.message.one_or_multiple_diffs_form.response=Okay, I will create {0} when providing the proposed changes.
622631
codemodernizer.chat.message.skip_tests_form.run_tests=Run unit tests
623632
codemodernizer.chat.message.skip_tests_form.skip=Skip unit tests
624-
codemodernizer.chat.message.one_or_multiple_diffs_form.one_diff=One diff
625-
codemodernizer.chat.message.one_or_multiple_diffs_form.multiple_diffs=Multiple diffs
626633
codemodernizer.chat.message.transform_begin=I'm starting to transform your code. It can take 10 to 30 minutes to upgrade your code, depending on the size of your module. To monitor progress, go to the Transformation Hub.
627-
codemodernizer.chat.message.one_or_multiple_diffs=\
628-
I can now divide the transformation results into diff patches (if applicable to the app) if you would like to review and accept each diff with fewer changes:\n\n\
629-
- Minimal Compatible Library Upgrade to Java 17: Dependencies to the minimum compatible versions in Java 17, including Springboot, JUnit, and PowerMockito.\n\n\
630-
- Popular Enterprise Specifications Application Frameworks: Popular enterprise and application frameworks like Jakarta EE, Hibernate, and Micronaut 3.\n\n\
631-
- HTTP Client Utilities Web Frameworks: HTTP client libraries, Apache Commons utilities, and Struts frameworks.\n\n\
632-
- Testing Tools Frameworks: Testing tools like ArchUnit, Mockito, and TestContainers and build tools like Jenkins and Maven Wrapper.\n\n\
633-
- Miscellaneous Processing Documentation: Diverse set spanning ORMs, XML processing, and API documentation like Swagger to SpringDoc/OpenAPI.
634634
codemodernizer.chat.message.transform_cancelled_by_user=I cancelled your transformation. If you want to start another transformation, choose **Start a new transformation**.
635635
codemodernizer.chat.message.transform_in_progress=If I run into any issues, I might pause the transformation to get input from you on how to proceed.
636636
codemodernizer.chat.message.transform_stopped_by_user=I stopped your transformation. If you want to start another transformation, choose **Start a new transformation**.

0 commit comments

Comments
 (0)