You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: ai-plugin/references/cgen-config.md
+38-4Lines changed: 38 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,7 +49,7 @@ Note the **different namespace** for `<cgen>` (`http://cayenne.apache.org/schema
49
49
50
50
| Field | Default | Meaning |
51
51
|---|---|---|
52
-
|`<destDir>`| — | Output directory, **relative to the project XML directory** (the directory containing `cayenne-*.xml`). Typical values: `.`, `../java`, `../../main/java`. Absolute paths also work. |
52
+
|`<destDir>`| — | Output directory, **relative to the directorycontaining `*.map.xml`**. Typical values: `.`, `../java`, `../../main/java`. |
53
53
|`<mode>`|`entity`| What to generate. `entity` = per-entity classes. `all` = per-entity classes + a single DataMap class with named-query helpers. |
54
54
55
55
### Pairs vs single class
@@ -107,13 +107,45 @@ The MCP tool:
107
107
1. Loads the project at `projectPath`.
108
108
2. Finds the named DataMap (`dataMap` argument).
109
109
3. Reads its embedded `<cgen>` block.
110
-
4. Resolves `destDir` relative to the project file.
110
+
4. Resolves `destDir` relative to the `*.map.xml` file.
111
111
5. Runs the generator. Returns a JSON object listing files `written`, files `skipped` (already up-to-date), and any `errors`.
112
112
113
113
If the DataMap has no `<cgen>` block, the tool returns an error and the user must add one — typically via the `cayenne-modeling` skill or the Modeler GUI.
114
114
115
-
## Recommended starting config
115
+
## Determining `destDir`
116
+
117
+
`destDir` is relative to the directory that contains `*.map.xml`.
118
+
119
+
**Before writing the default config, inspect the project tree** to find the Java source root and express it as a relative path from the map file's directory. Do not blindly paste `../java`.
120
+
121
+
### Standard Maven layout
122
+
123
+
Map files are frequently placed in a package subdirectory under `resources/` rather than directly in `resources/` itself. Count the directory levels between `resources/` and the map file and add that many extra `../` segments.
The rule: one `../` to escape `resources/`, then one `../` per package segment, then `java`. Always verify by resolving the resulting path mentally before writing it.
116
135
136
+
### Non-standard layouts
137
+
138
+
If the project doesn't follow Maven conventions, locate the actual Java sources:
139
+
140
+
1. Look for existing `.java` files or a `src/` directory near the map file.
141
+
2. Compute the relative path from the map file's directory to that sources root.
142
+
3. If no Java sources exist yet, ask the user where generated classes should go.
143
+
144
+
### Distinguishing main vs test maps
145
+
146
+
If the map file lives under a test resource directory (`src/test/resources/`, `test/`, or a path containing `test`), the generated classes belong in the test source tree. Point `destDir` there rather than at the main sources — test entity classes mixed into `src/main/java/` are a common mistake.
@@ -125,10 +157,12 @@ If the DataMap has no `<cgen>` block, the tool returns an error and the user mus
125
157
</cgen>
126
158
```
127
159
128
-
Assuming the project XML lives at `src/main/resources/cayenne-mydb.xml`, this writes to `src/main/java/<package>/`.
160
+
The `../java` value above assumes a standard Maven layout (`src/main/resources/` or `src/test/resources/`). Adjust if the project uses a non-standard layout — see "Determining `destDir`" above.
129
161
130
162
## Anti-patterns
131
163
132
164
- Setting `<makePairs>false</makePairs>` to "simplify" — you lose the ability to add user code without it being overwritten on the next cgen run.
133
165
- Editing `_<Entity>.java` files (the superclasses). They are regenerated. Customize `<Entity>.java` (the subclass) instead.
134
166
-`<destDir>` as an absolute path checked into source — breaks reproducibility for other developers. Use a relative path.
167
+
- Pasting `../java` blindly without checking the actual project layout. Inspect the tree first; see "Determining `destDir`" above.
168
+
- Pointing a test DataMap's `destDir` at `src/main/java/` — test entity classes belong in the test source tree.
Copy file name to clipboardExpand all lines: ai-plugin/skills/cayenne-cgen/SKILL.md
+9-24Lines changed: 9 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ description: "Use this skill whenever the user wants to (re)generate Cayenne ent
23
23
-->
24
24
# cayenne-cgen
25
25
26
-
Run Cayenne's class generator on a DataMap via the `mcp__cayenne__cgen_run` MCP tool. Reads the embedded `<cgen>` block in the DataMap to determine destination, mode, templates, etc.
26
+
Run Cayenne's class generator on a DataMap via the `mcp__cayenne__cgen_run` MCP tool. The tool reads the embedded `<cgen>` block in the DataMap to determine destination, mode, templates, etc.; if no block is present the tool reports an error and the skill adds a default one then retries.
27
27
28
28
## Required reading
29
29
@@ -42,26 +42,7 @@ Locate the descriptor via `project-layout.md`. If multiple descriptors exist, as
42
42
43
43
If the user named the DataMap directly (e.g. "regenerate classes for the customers DataMap"), use that. If they said "regenerate everything" and there are multiple DataMaps, run `cgen_run` once per DataMap in sequence (the tool generates per-DataMap).
44
44
45
-
## Step 2 — Verify `<cgen>` block exists
46
-
47
-
Before calling the tool, check the target DataMap for a `<cgen xmlns="http://cayenne.apache.org/schema/12/cgen">` block. If missing:
48
-
49
-
1. Don't call `cgen_run` blindly — it will return an error.
50
-
2. Either:
51
-
-**Add a minimal block** by delegating to the `cayenne-modeling` skill. Use the starter config from `cgen-config.md`:
Confirm `destDir` with the user — it's relative to the project XML directory and decides where generated `.java` files land.
62
-
- Or, if the user prefers the GUI, suggest the `cayenne-modeler` skill and tell them to configure the DataMap's "Class Generation" tab.
63
-
64
-
## Step 3 — Call `cgen_run`
45
+
## Step 2 — Call `cgen_run`
65
46
66
47
```
67
48
mcp__cayenne__cgen_run({
@@ -72,7 +53,11 @@ mcp__cayenne__cgen_run({
72
53
73
54
If the tool is not available (MCP server not registered), surface `cayenne-mcp-server/README.md` and stop. **Do not** suggest `mvn cayenne:cgen` or the Gradle cgen task.
74
55
75
-
## Step 4 — Surface the result
56
+
If the tool errors because no `<cgen>` block is present in the DataMap, add a minimal one using the starting config approach from `cgen-config.md`
57
+
58
+
If the `destDir` can't be determined reliably (non-standard project layout, empty project, etc.), conform it with the user
59
+
60
+
## Step 3 — Surface the result
76
61
77
62
The tool returns structured JSON. Report:
78
63
@@ -82,14 +67,14 @@ The tool returns structured JSON. Report:
82
67
83
68
If `writtenCount` is 0 and `skippedCount` covers everything, say so — it means everything is already up-to-date and no work was needed.
84
69
85
-
## Step 5 — Next steps
70
+
## Step 4 — Next steps
86
71
87
72
- If new `_<Entity>.java` superclass files were generated, gently remind the user not to edit those — they will be overwritten next run. User code goes in the matching `<Entity>.java` subclass.
88
73
- If the user just ran reverse engineering, this skill is the natural follow-up. Cross-link back to `cayenne-modeling` if they need to tweak names/types before regenerating.
89
74
90
75
## Anti-patterns
91
76
92
-
- **Do not** call `cgen_run` without verifying the `<cgen>` block exists — the tool returns an error and confuses the user.
77
+
-**Do not**pre-check the DataMap for a`<cgen>` block before calling `cgen_run`. Call the tool first; add the default config only if the tool reports it is missing.
93
78
-**Do not** suggest Maven (`mvn cayenne:cgen`) or Gradle (`cayenneCgen`) goals when MCP is unavailable. Those build plugins are out of scope. Point at MCP setup instead.
-**Do not** confuse `projectPath` and `dataMap` arguments. `projectPath` is a file system path to `cayenne-*.xml`. `dataMap` is a logical name (e.g. `mydb`), not a path to `mydb.map.xml`.
0 commit comments