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
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-30 02:05:05 +08:00
1 джерело 016240ac1b
коміт c0b5789dd6
2 files changed
+25 -1

No files matched your search

+16
Переглянути файл
@@ -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 = {
+9 -1
Переглянути файл
@@ -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" });
}