Skip to content

Commit d560541

Browse files
authored
devonfw#403: Add xml merger doc to documentation (devonfw#457)
1 parent e3b0167 commit d560541

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

documentation/configurator.adoc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,63 @@ Therefore, you can try again with `ws-reverse-add` instead of `ws-reverse` (e.g.
7474
Be sure not to add undesired settings that should not be managed.
7575
* In case your changes are in an entirely new configuration file that is currently not managed, you can simply diff the current workspace folder with the previously created backup copy using a recursive diff tool (such as winmerge or maybe just `diff -R`).
7676
Once you figured out the relevant change from that diff, you can manually apply it to the according `«ide»/workspace/update` folder in your `ide-settings` git repository.
77+
78+
== XML Merger
79+
80+
The XML Merger in `IDEasy` is a tool designed to merge XML documents using different strategies.
81+
It allows control over how elements are combined, overridden, or kept intact during the merge process.
82+
This merger is mainly used to merge incoming IDE configuration files changes from ide-settings into the workspace.
83+
84+
=== Merging Strategies
85+
86+
The merger supports three main strategies, which can be specified for each element using the `merge:strategy` attribute:
87+
88+
* `COMBINE`: This strategy combines the source and target elements.
89+
It overrides text nodes and attributes, and recursively applies the process to child elements.
90+
If a source element exists in the target document, they are combined; otherwise, the source element is appended.
91+
* `OVERRIDE`: This strategy replaces the target element with the source element, without considering child elements.
92+
If the element exists in the target, it is overridden; otherwise, it is appended.
93+
* `KEEP`: This strategy keeps the existing target element intact if the source element exists in the target document.
94+
If the source element doesn't exist in the target, it is appended.
95+
96+
It is not necessary to provide a `merge:strategy` for each element, strategies are inherited to child elements.
97+
So you only need to configure a `merge:strategy` for an element if it shall be different from its parent.
98+
The default if nothing is configured for the root element is `COMBINE`.
99+
100+
=== Element Identification
101+
102+
Elements are identified and matched using the `merge:id` attribute.
103+
This attribute is used to determine which elements in the source and target documents correspond to each other.
104+
The `merge:id` can be set to one of the following:
105+
106+
* An attribute name prefixed with @ (e.g., `@id`, `@name`)
107+
* The string `name()` to match by element name
108+
* The string `text()` to match by text content
109+
* A full XPath expression (e.g., `../element[@attr=’value’]` or `/root/element[@attr=’value’]`)
110+
111+
For each first occurrence of an element the provided value of `merge:id` is saved and then later used for elements with the same name (qualified tag name), so it is enough to provide a `merge:id` for each element only once, unless you want it to change later in the document.
112+
113+
If no `merge:id` was provided, the merger uses the following strategy as default:
114+
115+
* If no attributes are present at all, use the qualified tag name
116+
* If an `id` attribute is present use it (`@id`)
117+
* Otherwise if a `name` attribute is present use it (`@name`)
118+
* Otherwise you will get an error and need to adjust your template.
119+
120+
In Eclipse and IntelliJ, elements are usually identified by either the `id` or `name` attribute, which means we could just omit `merge:id` in these cases.
121+
122+
=== Namespace declaration
123+
124+
In order to use this tool, it is necessary to declare the merge namespace in the root element like this:
125+
126+
[source,xml]
127+
----
128+
<root xmlns:merge="https://github.com/devonfw/IDEasy/merge">
129+
// some elements
130+
</root>
131+
----
132+
133+
=== Namespace declaration
134+
135+
A good example of a XML template with merge configuration can be found https://github.com/devonfw/IDEasy/blob/main/cli/src/test/resources/xmlmerger/intellijWorkspace/source.xml[here].
136+
More examples are link:https://github.com/devonfw/IDEasy/tree/main/cli/src/test/resources/xmlmerger[here].

0 commit comments

Comments
 (0)