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" }); }