-
Notifications
You must be signed in to change notification settings - Fork 2
XML Usage
In this example, we configure replacements for XML files, specifying the paths and placeholder details. Here’s a breakdown of the configuration structure and its elements:
steps:
- kind: XmlHandler
apiVersion: v1
spec:
- files:
- pom.xml
placeholders:
- match: /project/groupId
replace: cookiecutter.param.groupId
- match: /project/artifactId
replace: Cookiecutter.test.replace.map.artifactId
- match: /project/dependencies/dependency/scope[text()='test']
replace: cookiecutter.replace.map.scopes
- files:
- xmls/generic_1.xml
placeholders:
- match: /note/heading
replace: New Reminder
- files:
- xmls/complex/generic_2.xml
placeholders:
- match: /bookstore/book/author[text()='Kurt Cagle']
replace: cookiecutter.kurtCagle
- match: /bookstore/book/year[text()='2005']
replace: cookiecutter.NewYear
This defines the handler type as XmlHandler, specifying that the operations pertain to XML files.
Indicates the version of the API for handling XML configurations. Ensure compatibility by matching the correct API version.
Each element in the spec array defines a set of files to be processed along with specific placeholders.
The pom.xml file has several placeholders to automate common configurations:
-
/project/groupId: Replaces the project’sgroupIdwith the value specified incookiecutter.param.groupId. -
/project/artifactId: Substitutes theartifactIdwithCookiecutter.test.replace.map.artifactId. -
/project/dependencies/dependency/scope[text()='test']: Replaces the test scope withcookiecutter.replace.map.scopes.
-
xmls/generic_1.xml:-
/note/heading: Updates theheadingelement within a<note>tag to"New Reminder".
-
-
xmls/complex/generic_2.xml:-
/bookstore/book/author[text()='Kurt Cagle']: Replaces occurrences of"Kurt Cagle"in theauthortag with the value fromcookiecutter.kurtCagle. -
/bookstore/book/year[text()='2005']: Changes theyearfrom"2005"to the new value incookiecutter.NewYear.
-
This XML configuration enables flexible replacement for various fields within multiple XML files, streamlining project customization through centrally managed placeholders.