This is an automated email from the ASF dual-hosted git repository.
stariy95 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git
The following commit(s) were added to refs/heads/master by this push:
new f56256aa1 MCP `cgen_run` tool: correctly set last modification time
f56256aa1 is described below
commit f56256aa1ee1d798682245b59f924d26054ddd87
Author: Nikita Timofeev <[email protected]>
AuthorDate: Tue May 26 20:11:40 2026 +0400
MCP `cgen_run` tool: correctly set last modification time
---
.../apache/cayenne/mcp/tools/cgen/CgenRunTool.java | 12 +++++++++++
.../apache/cayenne/mcp/tools/cgen/CgenRunIT.java | 25 ++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git
a/cayenne-mcp-server/src/main/java/org/apache/cayenne/mcp/tools/cgen/CgenRunTool.java
b/cayenne-mcp-server/src/main/java/org/apache/cayenne/mcp/tools/cgen/CgenRunTool.java
index 2f766baab..4b027f81b 100644
---
a/cayenne-mcp-server/src/main/java/org/apache/cayenne/mcp/tools/cgen/CgenRunTool.java
+++
b/cayenne-mcp-server/src/main/java/org/apache/cayenne/mcp/tools/cgen/CgenRunTool.java
@@ -168,6 +168,18 @@ public class CgenRunTool {
}
CgenConfiguration cgenConfig = configList.getAll().getFirst();
+ // Set the DataMap file's mtime as the timestamp so fileNeedUpdate()
can detect DataMap changes correctly.
+ if (dataMap.getConfigurationSource() != null) {
+ try {
+ Path dataMapFile =
Path.of(dataMap.getConfigurationSource().getURL().toURI());
+
cgenConfig.setTimestamp(Files.getLastModifiedTime(dataMapFile).toMillis());
+ } catch (Exception e) {
+ // URI conversion failed (e.g. non-file: URL) or some problems
with file mtime read,
+ // better to regen all, than silently fail.
+ cgenConfig.setForce(true);
+ }
+ }
+
// Step 5 — destDir specified?
Path destDir = cgenConfig.buildOutputPath();
if (destDir == null) {
diff --git
a/cayenne-mcp-server/src/test/java/org/apache/cayenne/mcp/tools/cgen/CgenRunIT.java
b/cayenne-mcp-server/src/test/java/org/apache/cayenne/mcp/tools/cgen/CgenRunIT.java
index 687353a44..f02c14e15 100644
---
a/cayenne-mcp-server/src/test/java/org/apache/cayenne/mcp/tools/cgen/CgenRunIT.java
+++
b/cayenne-mcp-server/src/test/java/org/apache/cayenne/mcp/tools/cgen/CgenRunIT.java
@@ -28,6 +28,7 @@ import org.junit.jupiter.api.io.TempDir;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.nio.file.attribute.FileTime;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
@@ -117,6 +118,30 @@ public class CgenRunIT {
assertTrue(skipped >= 1, "At least one file (the existing subclass)
should have been skipped");
}
+ @Test
+ public void regeneratesAfterDataMapChange() throws IOException {
+ // First run — generates files
+ CgenRunResult first = tool.run(projectFile.toString(), "PersonMap");
+ assertEquals("generated", first.status());
+
+ // Bump the DataMap's mtime to be clearly newer than the generated
files.
+ // Use setLastModifiedTime rather than a wall-clock sleep to avoid
+ // filesystem mtime granularity issues (Windows has 1-second
resolution).
+ long maxGeneratedMtime = first.files().stream()
+ .mapToLong(e -> Path.of(e.path()).toFile().lastModified())
+ .max()
+ .orElseThrow();
+ Path dataMapFile = tempDir.resolve("PersonMap.map.xml");
+ Files.setLastModifiedTime(dataMapFile,
FileTime.fromMillis(maxGeneratedMtime + 5_000L));
+
+ // Second run — must detect that the DataMap is newer than the
generated files
+ // and regenerate the superclass(es).
+ CgenRunResult second = tool.run(projectFile.toString(), "PersonMap");
+ assertEquals("generated", second.status(),
+ "Expected regeneration after DataMap mtime was bumped past
generated files");
+ assertTrue(second.summary().filesWritten() > 0);
+ }
+
private Path writeFixture(String mapName, String pkg, Path destDir,
boolean makePairs) throws IOException {
// Project descriptor