Skip to content

Commit 451c066

Browse files
author
David Hasani
committed
always resume even on empty diff
1 parent 3ac81a5 commit 451c066

File tree

2 files changed

+40
-43
lines changed

2 files changed

+40
-43
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ data class CodeModernizerSessionContext(
234234
}
235235

236236
val zipSources = File(ZIP_SOURCES_PATH)
237-
val depSources = File(ZIP_DEPENDENCIES_PATH)
238237
val outputFile = createTemporaryZipFile { zip ->
239238
// 1) Manifest file
240239
var manifest = ZipManifest(transformCapabilities = transformCapabilities, customBuildCommand = customBuildCommand)

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

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,8 @@ suspend fun attemptLocalBuild(plan: TransformationPlan, jobId: JobId, project: P
170170
if (artifactId != null) {
171171
val clientInstructionsPath = downloadClientInstructions(jobId, artifactId, project)
172172
getLogger<CodeModernizerManager>().info { "Downloaded client instructions for job ${jobId.id} and artifact $artifactId at: $clientInstructionsPath" }
173-
if (clientInstructionsPath.toFile().readText().trim().isNotEmpty()) {
174-
processClientInstructions(clientInstructionsPath, jobId, artifactId, project)
175-
getLogger<CodeModernizerManager>().info { "Finished processing client instructions for job ${jobId.id} and artifact $artifactId" }
176-
} else {
177-
getLogger<CodeModernizerManager>().info { "Client instructions for job ${jobId.id} and artifact $artifactId is empty; skipping client-side build" }
178-
}
173+
processClientInstructions(clientInstructionsPath, jobId, artifactId, project)
174+
getLogger<CodeModernizerManager>().info { "Finished processing client instructions for job ${jobId.id} and artifact $artifactId" }
179175
}
180176
}
181177

@@ -190,45 +186,47 @@ suspend fun processClientInstructions(clientInstructionsPath: Path, jobId: JobId
190186
val targetDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(copyOfProjectSources.toFile())
191187
?: throw RuntimeException("Cannot find copy of project sources directory")
192188

193-
withContext(EDT) {
194-
runWriteAction {
195-
// create temp module with project copy so that we can apply diff.patch
196-
val modifiableModel = ModuleManager.getInstance(project).getModifiableModel()
197-
val tempModule = modifiableModel.newModule(
198-
Paths.get(targetDir.path).resolve("temp.iml").toString(),
199-
JavaModuleType.getModuleType().id
200-
)
189+
if (clientInstructionsPath.toFile().readText().trim().isNotEmpty()) {
190+
withContext(EDT) {
191+
runWriteAction {
192+
// create temp module with project copy so that we can apply diff.patch
193+
val modifiableModel = ModuleManager.getInstance(project).getModifiableModel()
194+
val tempModule = modifiableModel.newModule(
195+
Paths.get(targetDir.path).resolve("temp.iml").toString(),
196+
JavaModuleType.getModuleType().id
197+
)
201198

202-
try {
203-
val moduleModel = ModuleRootManager.getInstance(tempModule).modifiableModel
204-
moduleModel.addContentEntry(targetDir.url)
205-
moduleModel.commit()
206-
modifiableModel.commit()
199+
try {
200+
val moduleModel = ModuleRootManager.getInstance(tempModule).modifiableModel
201+
moduleModel.addContentEntry(targetDir.url)
202+
moduleModel.commit()
203+
modifiableModel.commit()
207204

208-
// apply diff.patch
209-
val patchReader = PatchReader(clientInstructionsPath)
210-
patchReader.parseAllPatches()
211-
PatchApplier(
212-
project,
213-
targetDir,
214-
patchReader.allPatches,
215-
null,
216-
null
217-
).execute()
218-
getLogger<CodeModernizerManager>().info { "Successfully applied patch file at $clientInstructionsPath" }
205+
// apply diff.patch
206+
val patchReader = PatchReader(clientInstructionsPath)
207+
patchReader.parseAllPatches()
208+
PatchApplier(
209+
project,
210+
targetDir,
211+
patchReader.allPatches,
212+
null,
213+
null
214+
).execute()
215+
getLogger<CodeModernizerManager>().info { "Successfully applied patch file at $clientInstructionsPath" }
219216

220-
val virtualFile = LocalFileSystem.getInstance().findFileByIoFile(clientInstructionsPath.toFile())
221-
?: throw RuntimeException("Cannot find patch file at $clientInstructionsPath")
222-
FileEditorManager.getInstance(project).openFile(virtualFile, true)
223-
} catch (e: Exception) {
224-
getLogger<CodeModernizerManager>().error {
225-
"Error applying intermediate diff.patch for job ${jobId.id} and artifact $artifactId located at " +
226-
"$clientInstructionsPath: $e"
227-
}
228-
throw e
229-
} finally {
230-
runWriteAction {
231-
ModuleManager.getInstance(project).disposeModule(tempModule)
217+
val virtualFile = LocalFileSystem.getInstance().findFileByIoFile(clientInstructionsPath.toFile())
218+
?: throw RuntimeException("Cannot find patch file at $clientInstructionsPath")
219+
FileEditorManager.getInstance(project).openFile(virtualFile, true)
220+
} catch (e: Exception) {
221+
getLogger<CodeModernizerManager>().error {
222+
"Error applying intermediate diff.patch for job ${jobId.id} and artifact $artifactId located at " +
223+
"$clientInstructionsPath: $e"
224+
}
225+
throw e
226+
} finally {
227+
runWriteAction {
228+
ModuleManager.getInstance(project).disposeModule(tempModule)
229+
}
232230
}
233231
}
234232
}

0 commit comments

Comments
 (0)