Code Transform
Aeon Dev Tools allows you to easily perform bulk code transformations of your projects.
Usage
To use the code transform feature, you need to create a configuration yaml file (see below), and execute it using the maven plugin:
mvn com.aeontronix.devtools:aeon-dev-tools-maven-plugin:1.0.0-beta14:code-transform -Dconfig=code-transform.yaml
It will then process to perform all transformations against each directory or version control repository specified in the configuration file.
You can specify the folder where they will be generated using the workDir parameter (other current folder will be used). ie:
mvn com.aeontronix.devtools:aeon-dev-tools-maven-plugin:1.0.0-beta14:code-transform -Dconfig=code-transform.yaml -DworkDir=work-dir
You can also specify a directory file to be transformed using the directory parameter in maven:
mvn com.aeontronix.devtools:aeon-dev-tools-maven-plugin:1.0.0-beta14:code-transform -Dconfig=code-transform.yaml -Ddirectory=myproject
The code-transform goal supports the following parameters:
| Parameter | Description |
|---|---|
| config | Configuration file to use |
| workDir | Work directory to use |
| directory | Directory to transform |
| force | Force overwrite of existing working directory if exists |
| push | Push changes to version control |
Configuration File
Top-level elements
title: Optional title for this transformation configurationworkdir: Optional work directory
ie:
title: Update my projects
workdir: _test
Directories
You can specify a list of directories for the transformations to be directly performed against.
directories:
- myproject
- myotherproject
Version control
You can also specify version control repositories where the transformations will be performed against.
GIT repository
You can specify various git repositories by specifying the type git:
vcs:
- type: git
baseUrl: git@github.com:myorg
suffix: ".git"
checkoutBranch: test
checkinBranch: test-transformed
repositories:
- repo1
- repo2
This assumes that you have the git executable in your path, and you have authentication already setup to
checkout the projects.
It will automatically checkout the specified checkoutBranch branch, perform the transformations.
If the maven command is executed with the push parameter set to true, it will then push the changes to the
checkinBranch branch.
Transformation Steps
You can then specify a list of transformation steps to be performed.
Each step will include a matcher, and a list of actions to perform. ie:
steps:
- matcher:
type: "path-regex"
regex: "pom\\.xml"
actions:
- type: maven-set-parent-pom
groupId: "com.mycompany"
artifactId: "my-parent"
version: "1.0.5"
Matchers
Path
The path matcher will match exact files, independently of them existing or not (this is useful for example to create
new files)
ie:
- matcher:
type: path
paths:
- test.txt
Path regex
The path-regex matcher will compare each file's path (relative to the repository root, assuming unix-style /
separator)
against a regular expression. This will only support files that actually exist.
- matcher:
type: "path-regex"
regex: "src/main/mule/.*?\\.xml"
Actions
File: Set content
The file-set-content action will set the content of a file.
Parameters:
content: Content to set (if the content type isbinary, it must be base64 encoded)content-type: Content type of the file (eithertextorbinary,fileand defaults totextif not specified)
If the content type is file, the content will be read from the specified file, relative to the configuration file.
If the content type is binary, it should be base64 encoded binary content.
Example:
- type: file-set-content
content: "Hello World!"
Filename: Change case
The filename-change-case action can be used to change the case of a file name.
Parameters:
case: The case to convert to (eitherupperorlower)regex: Regex to match against (defaults to.*) of what needs to be changed in the filename
Example:
- type: filename-change-case
case: lower
JSON: add json
The add-json action can be used to add content to a JSON file.
Supported elements to add to are:
- Array elements
Parameters:
point: A JSON pointer to the location where the content should be addedjson: JSON content to be added
Example:
- type: add-json
pointer: /mylist
json: |
{
"foo": "bar"
}
this would modify the file from this:
{
"mylist": [
{
"test": "value"
}
]
}
to
{
"mylist": [
{
"test": "value"
},
{
"foo": "bar"
}
]
}
Maven: Set parent pom
The maven-set-parent-pom action can be used to set the parent pom for a maven project.
Parameters:
groupId: groupId of the parentartifactId: artifactId of the parentversion: version of the parent
Example:
- type: maven-set-parent-pom
groupId: "com.mycompany"
artifactId: "my-parent"
version: "1.0.5"
XML: Add
The add-xml action can be used to add content to an XML file. This currently only supports adding XML content to an
element.
Parameters:
namespace: Enable namespace support (defaults tofalse)prettyPrint: If the XML should be pretty printed (defaults totrue)xmlDeclaration: If the XML should have an XML declaration (defaults totrue)condition: XPath condition (must resolve to a boolean) to check if content should be added (defaults totrue)xpath: XPath to the location where the content should be addedvalue: XML content to add
Example:
- type: add-xml
condition: not(boolean(//dependencies/dependency[artifactId='splunk-library-javalogging']))
xpath: "//dependencies"
value: |-
<dependency>
<groupId>com.splunk.logging</groupId>
<artifactId>splunk-library-javalogging</artifactId>
<version>1.11.8</version>
</dependency>
XML: Delete
The delete-xml action can be used to delete a node from XML file.
Parameters:
namespace: Enable namespace support (defaults tofalse)prettyPrint: If the XML should be pretty printed (defaults totrue)xmlDeclaration: If the XML should have an XML declaration (defaults totrue)condition: XPath condition (must resolve to a boolean) to check if content should be deleted (defaults totrue)xpath: XPath to the location where the content should be addedvalue: XML content to add
Example:
- type: delete-xml
xpath: "//dependencies/dependency[artifactId='mule-splunk-plugin']"
XML: Update
The delete-xml action can be used to delete a node from XML file.
Parameters:
namespace: Enable namespace support (defaults tofalse)prettyPrint: If the XML should be pretty printed (defaults totrue)xmlDeclaration: If the XML should have an XML declaration (defaults totrue)xpath: XPath to the location where the content should be addedvalue: XML content to add
Example: Updating an attribute value
- type: update-xml
xpath: /mule/request-config/request-connection[starts-with(@host,'\{secure::domain.https.req.host}')]/@host
value: "www.mydomain.com"
Example: Updating an element's text content
- type: update-xml
xpath: "/project/properties/java.version"
value: "17"
Full example
title: Update my projects
workdir: _test
vcs:
- type: git
baseUrl: git@github.com:foo
suffix: ".git"
checkoutBranch: test-transform
repositories:
- project1
- project2
steps:
- matcher:
type: path
paths:
- test.txt
actions:
- type: file-set-content
content: "Hello World!"
- matcher:
type: path
paths:
- src/main/resources/key.jks
actions:
- type: file-set-content
content: "foo"
- matcher:
type: "path-regex"
regex: "pom\\.xml"
actions:
- type: maven-set-parent-pom
groupId: "com.mycompany"
artifactId: "my-parent"
version: "1.0.5"
- type: update-xml
xpath: "/project/properties/java.version"
value: "17"
- type: delete-xml
xpath: "//plugin[artifactId='mule-maven-plugin']/configuration/standaloneDeployment"
- type: delete-xml
xpath: "//plugin[artifactId='mule-maven-plugin']/executions"
- type: delete-xml
xpath: "//dependencies/dependency[artifactId='mule-splunk-plugin']"
- type: add-xml
condition: not(boolean(//dependencies/dependency[artifactId='splunk-library-javalogging']))
xpath: "//dependencies"
value: |-
<dependency>
<groupId>com.splunk.logging</groupId>
<artifactId>splunk-library-javalogging</artifactId>
<version>1.11.8</version>
</dependency>
- type: add-xml
condition: boolean(//dependencies/dependency[artifactId='resource-common-error-handlerlibrary'])
xpath: "//dependencies"
value: |-
<dependency>
<groupId>org.mule.module</groupId>
<artifactId>mule-java-module</artifactId>
<version>2.0.2</version>
<classifier>mule-plugin</classifier>
</dependency>
- matcher:
type: "path-regex"
regex: "src/main/mule/.*?\\.xml"
actions:
- type: update-xml
xpath: /mule/request-config/request-connection[starts-with(@host,'\{secure::domain.https.req.host}')]/@host
value: "[FIXME: remote app name]"
