From c0b5789dd6215e4fab9c0118f8ea5438d52417d8 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Mon, 30 Nov 2026 02:05:05 +0800 Subject: [PATCH] fix(run): rebuild the WAR before redeploying a copied Tomcat update (#6871) Update classes while debugging copies the compiled outputs into the exploded deployment, then HotSwaps. When HotSwap could not apply the change (a new class or method) it fell back to a redeploy, which explodes the recorded WAR into the deployment again; that WAR predates the change, so the old classes came back and classes added since were removed while the IDE reported "Application updated". The WAR is now rebuilt before that redeploy. Refs #6603 --- src/features/run/applicationUpdate.test.ts | 16 ++++++++++++++++ src/features/run/applicationUpdate.ts | 10 +++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/features/run/applicationUpdate.test.ts b/src/features/run/applicationUpdate.test.ts index 21a767ecc3..9de80cbf7c 100644 --- a/src/features/run/applicationUpdate.test.ts +++ b/src/features/run/applicationUpdate.test.ts @@ -137,6 +137,22 @@ describe("Tomcat application updates", () => { await updateTomcat(session, "classes"); expect(mocks.update).toHaveBeenLastCalledWith(session.config, "redeploy"); }); + // The redeploy explodes the WAR again; the copied outputs are newer than the WAR the + // deployment came from, so redeploying that WAR would drop the change (and a new class). + it("rebuilds the WAR before redeploying after a copied update HotSwap could not apply", async () => { + mocks.sync.mockResolvedValue(true); + mocks.action.mockResolvedValue(false); + await updateTomcat(session, "classes"); + expect(mocks.build).toHaveBeenCalledTimes(1); + expect(mocks.update).toHaveBeenCalledTimes(1); + expect(mocks.update).toHaveBeenCalledWith(session.config, "redeploy"); + expect(mocks.build.mock.invocationCallOrder[0]).toBeLessThan(mocks.update.mock.invocationCallOrder[0]!); + }); + it("builds the WAR once when it was already rebuilt for the update", async () => { + mocks.action.mockResolvedValue(false); + await updateTomcat(session, "classes"); + expect(mocks.build).toHaveBeenCalledTimes(1); + }); }); const boot = { diff --git a/src/features/run/applicationUpdate.ts b/src/features/run/applicationUpdate.ts index a3ed261572..c9ce060cf6 100644 --- a/src/features/run/applicationUpdate.ts +++ b/src/features/run/applicationUpdate.ts @@ -99,15 +99,23 @@ export async function updateApplication(session: UpdateSession, mode: string): P if (session.config.kind === "spring-boot") { await updateSpringBoot(session.config, mode, debugging); } else { + // Synced: the deployment has the new outputs, but the WAR it was exploded from is older. + let built = false; if (mode === "redeploy" || !(await syncTomcatOutputs(session.config, mode === "resources"))) { await buildTomcatArtifact(session.config); + built = true; await call(commands.runTomcatUpdate(session.config, mode)); } if (mode === "classes" && debugging) { const swapped = getAction("debug.reloadChangedClasses") && (await executeAction("debug.reloadChangedClasses", { configId: session.config.id })); - if (!swapped) await call(commands.runTomcatUpdate(session.config, "redeploy")); + // A redeploy explodes the WAR into the deployment again: after a sync that WAR predates + // the change (a class added since would be removed), so it is rebuilt first. + if (!swapped) { + if (!built) await buildTomcatArtifact(session.config); + await call(commands.runTomcatUpdate(session.config, "redeploy")); + } } notifications().notify({ group: "run", level: "info", title: "Application updated" }); }