Skip to content

Commit 1d36e0b

Browse files
committed
Integrate modello-ant-task to modello source tree
1 parent a5157a9 commit 1d36e0b

6 files changed

Lines changed: 1563 additions & 0 deletions

File tree

‎modello-ant-task/README.md‎

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
# Modello Ant Task
2+
3+
The `modello-ant-task` is an Apache Ant task that integrates [Codehaus Modello](https://codehaus-plexus.github.io/modello/) into Ant build workflows. It allows you to generate Java classes, XML serializers/deserializers, XML Schemas (XSD), documentation, and other outputs from Modello model description (`.mdo`) files.
4+
5+
---
6+
7+
## Installation & Definition
8+
9+
To use the task in your Ant build file, define it using either the individual task definition or the preferred standard `antlib` resource.
10+
11+
### Option 1: Using Antlib (Recommended)
12+
13+
```xml
14+
<typedef resource="org/codehaus/modello/ant/antlib.xml"
15+
classpathref="modello.classpath" />
16+
```
17+
18+
### Option 2: Using Taskdef
19+
20+
```xml
21+
<taskdef name="modello"
22+
classname="org.codehaus.modello.ant.ModelloTask"
23+
classpathref="modello.classpath" />
24+
```
25+
26+
*Note: `modello.classpath` must contain the `modello-ant-task` JAR, `modello-core`, and any runtime Modello generator plugins you wish to use.*
27+
28+
---
29+
30+
## Task Reference
31+
32+
The `<modello>` task supports several attributes and nested elements to configure code generation.
33+
34+
### Attributes
35+
36+
| Attribute | Type | Description | Required | Default |
37+
|:-------------------------------|:----------|:--------------------------------------------------------------------------------------|:--------:|:---------:|
38+
| **`version`** | `String` | The model version to generate (e.g., `1.0.0`). | **Yes** | — |
39+
| **`outputDirectory`** | `File` | The directory where the generated files will be written. | **Yes** | — |
40+
| **`javaSource`** | `String` | Target Java version for generated source code. | No | `8` |
41+
| **`encoding`** | `String` | Character encoding for generated files. | No | `"utf-8"` |
42+
| **`packageWithVersion`** | `boolean` | Whether to append the version to the package name (`"true"` / `"false"`). | No | `false` |
43+
| **`packagedVersions`** | `String` | Comma-separated list of versions to generate backward compatibility for. | No | — |
44+
| **`domAsXpp3`** | `boolean` | Whether to generate DOM content as Xpp3Dom (`"true"`) or W3C DOM Element (`"false"`). | No | `true` |
45+
| **`licenseFile`** | `File` | Path to file containing license header text to prepend to generated files. | No | — |
46+
| **`licenseText`** | `String` | License header text to prepend to generated files. | No | — |
47+
| **`extendedClassnameSuffix`** | `String` | Suffix for extended class names (e.g., `Ex`). | No | — |
48+
| **`xsdFileName`** | `String` | Custom output file name for generated XSD schema (`xsd` goal). | No | — |
49+
| **`enforceMandatoryElements`** | `boolean` | Whether to enforce mandatory elements in XSD (`"true"` / `"false"`). | No | `false` |
50+
| **`jsonSchemaFileName`** | `String` | Custom output file name for generated JSON Schema (`jsonschema` goal). | No | — |
51+
| **`firstVersion`** | `String` | Earliest version to document when generating documentation (`xdoc` goal). | No | — |
52+
| **`xdocFileName`** | `String` | Custom output file name for generated XDoc documentation (`xdoc` goal). | No | — |
53+
| **`velocityBasedir`** | `File` | Base directory of template files (required only for Velocity-based goals). | No | — |
54+
55+
### Nested Elements
56+
57+
#### `<model>`
58+
59+
Specifies the Modello model description file to read. At least one `<model>` element is required.
60+
* **`file`** (`File`, Required): Path to the `.mdo` model file.
61+
62+
```xml
63+
<model file="src/main/mdo/maven.mdo" />
64+
```
65+
66+
#### `<goal>`
67+
68+
Specifies the Modello generator target to run. At least one `<goal>` element is required.
69+
* **`name`** (`String`, Required): The generator plugin name (e.g., `java`, `xdoc`, `xsd`, `xpp3-reader`, `xpp3-writer`, `velocity`).
70+
71+
```xml
72+
<goal name="java" />
73+
```
74+
75+
#### `<packagedVersion>`
76+
77+
Specifies an additional model version to package. Can be specified multiple times.
78+
* **`name`** (`String`, Required): The version string (e.g., `1.0.0`).
79+
80+
```xml
81+
<packagedVersion name="1.0.0" />
82+
<packagedVersion name="1.1.0" />
83+
```
84+
85+
#### `<license>`
86+
87+
Specifies license header content to prepend to generated sources.
88+
* **`file`** (`File`, Optional): File containing license header text.
89+
* **`text`** (`String`, Optional): Direct license text string (can also be passed as nested text).
90+
91+
```xml
92+
<license file="${basedir}/LICENSE.txt" />
93+
```
94+
95+
#### `<pluralException>`
96+
97+
Specifies an irregular plural mapping used during field naming generation.
98+
* **`name`** (`String`, Required): The plural form (e.g., `aliases`).
99+
* **`value`** (`String`, Required): The singular form (e.g., `alias`).
100+
101+
```xml
102+
<pluralException name="aliases" value="alias" />
103+
```
104+
105+
#### `<template>`
106+
107+
Specifies a custom template file when running the Velocity-based generator (`velocity` goal).
108+
* **`name`** (`String`, Required): Name or path of the template file relative to `velocityBasedir`.
109+
110+
```xml
111+
<template name="model.vm" />
112+
```
113+
114+
#### `<param>`
115+
116+
Specifies custom velocity parameters passed to the generator context.
117+
* **`name`** (`String`, Required): Parameter name.
118+
* **`value`** (`String`, Required): Parameter value.
119+
120+
```xml
121+
<param name="packageModelV4" value="org.example.model" />
122+
```
123+
124+
#### `<property>`
125+
126+
Passes arbitrary Modello parameters directly (equivalent to `-Dkey=value` on the CLI).
127+
* **`name`** (`String`, Required): Parameter key.
128+
* **`value`** (`String`, Required): Parameter value.
129+
130+
```xml
131+
<property name="modello.package.with.version" value="true" />
132+
```
133+
134+
---
135+
136+
## Examples
137+
138+
### Example 1: Standard Code Generation (Java & XSD)
139+
140+
This example generates Java sources and XML Schema definitions (XSD) from a `model.mdo` file into the target folder `target/generated-sources`.
141+
142+
```xml
143+
<target name="generate-model">
144+
<mkdir dir="${basedir}/target/generated-sources" />
145+
146+
<modello version="1.0.0"
147+
outputDirectory="${basedir}/target/generated-sources"
148+
javaSource="11">
149+
150+
<!-- Path to the Modello model -->
151+
<model file="src/main/mdo/model.mdo" />
152+
153+
<!-- Goals to execute -->
154+
<goal name="java" />
155+
<goal name="xsd" />
156+
<goal name="xpp3-reader" />
157+
<goal name="xpp3-writer" />
158+
</modello>
159+
</target>
160+
```
161+
162+
### Example 2: Velocity-Based Generation
163+
164+
This example demonstrates how to use the Velocity generator plugin to create files using a custom `.vm` template.
165+
166+
```xml
167+
<target name="generate-velocity">
168+
<mkdir dir="${basedir}/target/generated-templates" />
169+
170+
<modello version="2.0.0"
171+
outputDirectory="${basedir}/target/generated-templates"
172+
velocityBasedir="${basedir}/src/main/templates">
173+
174+
<model file="src/main/mdo/model.mdo" />
175+
176+
<!-- Execute Velocity generator -->
177+
<goal name="velocity" />
178+
179+
<!-- Template specification -->
180+
<template name="custom-report.vm" />
181+
182+
<!-- Parameters passed to the template context -->
183+
<param name="isMavenModel" value="true" />
184+
<param name="packageModel" value="org.example.api" />
185+
</modello>
186+
</target>
187+
```
188+

‎modello-ant-task/pom.xml‎

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright 2026 Fridrich Strba
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18+
<modelVersion>4.0.0</modelVersion>
19+
20+
<parent>
21+
<groupId>org.codehaus.modello</groupId>
22+
<artifactId>modello</artifactId>
23+
<version>2.8.2-SNAPSHOT</version>
24+
</parent>
25+
26+
<artifactId>modello-ant-task</artifactId>
27+
<packaging>jar</packaging>
28+
29+
<name>Modello Ant Task</name>
30+
<description>Modello Ant Task enables the use of Modello in Apache Ant builds.</description>
31+
32+
<properties>
33+
<ant.version>1.10.18</ant.version>
34+
</properties>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>org.apache.ant</groupId>
39+
<artifactId>ant</artifactId>
40+
<version>${ant.version}</version>
41+
<scope>provided</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.codehaus.modello</groupId>
45+
<artifactId>modello-core</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.codehaus.plexus</groupId>
49+
<artifactId>plexus-xml</artifactId>
50+
</dependency>
51+
52+
<!-- plugins, sorted alphabetically -->
53+
<dependency>
54+
<groupId>org.codehaus.modello</groupId>
55+
<artifactId>modello-plugin-converters</artifactId>
56+
<scope>runtime</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.codehaus.modello</groupId>
60+
<artifactId>modello-plugin-dom4j</artifactId>
61+
<scope>runtime</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.codehaus.modello</groupId>
65+
<artifactId>modello-plugin-jackson</artifactId>
66+
<scope>runtime</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.codehaus.modello</groupId>
70+
<artifactId>modello-plugin-java</artifactId>
71+
<scope>runtime</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.codehaus.modello</groupId>
75+
<artifactId>modello-plugin-jdom</artifactId>
76+
<scope>runtime</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.codehaus.modello</groupId>
80+
<artifactId>modello-plugin-jsonschema</artifactId>
81+
<scope>runtime</scope>
82+
</dependency>
83+
<dependency>
84+
<groupId>org.codehaus.modello</groupId>
85+
<artifactId>modello-plugin-sax</artifactId>
86+
<scope>runtime</scope>
87+
</dependency>
88+
<dependency>
89+
<groupId>org.codehaus.modello</groupId>
90+
<artifactId>modello-plugin-snakeyaml</artifactId>
91+
<scope>runtime</scope>
92+
</dependency>
93+
<dependency>
94+
<groupId>org.codehaus.modello</groupId>
95+
<artifactId>modello-plugin-stax</artifactId>
96+
<scope>runtime</scope>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.codehaus.modello</groupId>
100+
<artifactId>modello-plugin-xdoc</artifactId>
101+
<scope>runtime</scope>
102+
</dependency>
103+
<dependency>
104+
<groupId>org.codehaus.modello</groupId>
105+
<artifactId>modello-plugin-xpp3</artifactId>
106+
<scope>runtime</scope>
107+
</dependency>
108+
<dependency>
109+
<groupId>org.codehaus.modello</groupId>
110+
<artifactId>modello-plugin-xsd</artifactId>
111+
<scope>runtime</scope>
112+
</dependency>
113+
<dependency>
114+
<groupId>org.codehaus.modello</groupId>
115+
<artifactId>modello-plugin-xml</artifactId>
116+
<scope>runtime</scope>
117+
</dependency>
118+
<dependency>
119+
<groupId>org.codehaus.modello</groupId>
120+
<artifactId>modello-plugin-velocity</artifactId>
121+
<scope>runtime</scope>
122+
</dependency>
123+
<dependency>
124+
<groupId>org.junit.jupiter</groupId>
125+
<artifactId>junit-jupiter-api</artifactId>
126+
<scope>test</scope>
127+
</dependency>
128+
<dependency>
129+
<groupId>org.junit.jupiter</groupId>
130+
<artifactId>junit-jupiter-engine</artifactId>
131+
<scope>test</scope>
132+
</dependency>
133+
<dependency>
134+
<groupId>org.slf4j</groupId>
135+
<artifactId>slf4j-simple</artifactId>
136+
<scope>test</scope>
137+
</dependency>
138+
</dependencies>
139+
140+
<build>
141+
<plugins>
142+
<plugin>
143+
<groupId>org.apache.maven.plugins</groupId>
144+
<artifactId>maven-jar-plugin</artifactId>
145+
<configuration>
146+
<archive>
147+
<manifestEntries>
148+
<Automatic-Module-Name>org.codehaus.modello.ant.task</Automatic-Module-Name>
149+
</manifestEntries>
150+
</archive>
151+
</configuration>
152+
</plugin>
153+
</plugins>
154+
</build>
155+
156+
</project>

0 commit comments

Comments
 (0)