Skip to content

Commit 521e71d

Browse files
committed
add maven-plugin of EMF code generation with examples
Signed-off-by: Stefan Bischof <[email protected]>
1 parent c2099c1 commit 521e71d

File tree

26 files changed

+2590
-0
lines changed

26 files changed

+2590
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="catalog" nsURI="http://daanse.eclipse.org/example/catalog" nsPrefix="catalog">
4+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
5+
<details key="basePackage" value="org.eclipse.daanse.example"/>
6+
<details key="prefix" value="Catalog"/>
7+
<details key="fileExtensions" value="catalog"/>
8+
<details key="copyrightText" value="Copyright (c) 2025 Contributors to the Eclipse Foundation.&#xA;&#xA;This program and the accompanying materials are made&#xA;available under the terms of the Eclipse Public License 2.0&#xA;which is available at https://www.eclipse.org/legal/epl-2.0/&#xA;&#xA;SPDX-License-Identifier: EPL-2.0"/>
9+
<details key="documentation" value="Product catalog model demonstrating annotation-based GenModel configuration."/>
10+
</eAnnotations>
11+
<eClassifiers xsi:type="ecore:EClass" name="Catalog">
12+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
13+
<details key="documentation" value="A catalog containing products organized in categories."/>
14+
</eAnnotations>
15+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
16+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
17+
<details key="documentation" value="The catalog name."/>
18+
</eAnnotations>
19+
</eStructuralFeatures>
20+
<eStructuralFeatures xsi:type="ecore:EReference" name="categories" upperBound="-1"
21+
eType="#//Category" containment="true">
22+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
23+
<details key="documentation" value="Categories in this catalog."/>
24+
</eAnnotations>
25+
</eStructuralFeatures>
26+
</eClassifiers>
27+
<eClassifiers xsi:type="ecore:EClass" name="Category">
28+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
29+
<details key="documentation" value="A category grouping related products."/>
30+
</eAnnotations>
31+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
32+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
33+
<details key="documentation" value="The category name."/>
34+
</eAnnotations>
35+
</eStructuralFeatures>
36+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="description" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
37+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
38+
<details key="documentation" value="Optional description of the category."/>
39+
</eAnnotations>
40+
</eStructuralFeatures>
41+
<eStructuralFeatures xsi:type="ecore:EReference" name="products" upperBound="-1"
42+
eType="#//Product" containment="true">
43+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
44+
<details key="documentation" value="Products in this category."/>
45+
</eAnnotations>
46+
</eStructuralFeatures>
47+
</eClassifiers>
48+
<eClassifiers xsi:type="ecore:EClass" name="Product">
49+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
50+
<details key="documentation" value="A product with name, price and availability."/>
51+
</eAnnotations>
52+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="sku" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
53+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
54+
<details key="documentation" value="Stock Keeping Unit - unique product identifier."/>
55+
</eAnnotations>
56+
</eStructuralFeatures>
57+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
58+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
59+
<details key="documentation" value="The product name."/>
60+
</eAnnotations>
61+
</eStructuralFeatures>
62+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="price" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBigDecimal">
63+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
64+
<details key="documentation" value="The product price."/>
65+
</eAnnotations>
66+
</eStructuralFeatures>
67+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="inStock" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"
68+
defaultValueLiteral="true">
69+
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
70+
<details key="documentation" value="Whether the product is currently in stock."/>
71+
</eAnnotations>
72+
</eStructuralFeatures>
73+
</eClassifiers>
74+
</ecore:EPackage>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/*********************************************************************
4+
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
5+
*
6+
* This program and the accompanying materials are made
7+
* available under the terms of the Eclipse Public License 2.0
8+
* which is available at https://www.eclipse.org/legal/epl-2.0/
9+
*
10+
* SPDX-License-Identifier: EPL-2.0
11+
**********************************************************************/
12+
-->
13+
<project
14+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
15+
xmlns="http://maven.apache.org/POM/4.0.0"
16+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
17+
<modelVersion>4.0.0</modelVersion>
18+
19+
<parent>
20+
<groupId>org.eclipse.daanse</groupId>
21+
<artifactId>org.eclipse.daanse.tooling.emf.codegen.maven.example</artifactId>
22+
<version>0.0.1-SNAPSHOT</version>
23+
</parent>
24+
25+
<artifactId>
26+
org.eclipse.daanse.tooling.emf.codegen.maven.example.ecore.annotated</artifactId>
27+
<packaging>jar</packaging>
28+
29+
<name>Daanse EMF Codegen Example - Ecore Annotated</name>
30+
<description>Ecore model using GenModel annotations for code generation
31+
settings</description>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.eclipse.emf</groupId>
36+
<artifactId>org.eclipse.emf.common</artifactId>
37+
<version>${emf.common.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.eclipse.emf</groupId>
41+
<artifactId>org.eclipse.emf.ecore</artifactId>
42+
<version>${emf.ecore.version}</version>
43+
</dependency>
44+
<!-- Fennec EMF OSGi API (for generated OSGi service code) -->
45+
<dependency>
46+
<groupId>org.eclipse.fennec.emf</groupId>
47+
<artifactId>org.eclipse.fennec.emf.osgi.api</artifactId>
48+
<version>1.0.0-SNAPSHOT</version>
49+
</dependency>
50+
51+
</dependencies>
52+
53+
<build>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.eclipse.daanse</groupId>
57+
<artifactId>org.eclipse.daanse.tooling.emf.codegen.maven</artifactId>
58+
<version>${project.version}</version>
59+
<executions>
60+
<execution>
61+
<goals>
62+
<goal>generate</goal>
63+
</goals>
64+
<configuration>
65+
<!--
66+
This example demonstrates reading GenModel settings from ecore annotations.
67+
The ecore file contains GenModel annotations that specify:
68+
- basePackage
69+
- prefix
70+
- fileExtensions
71+
- copyrightText
72+
- documentation
73+
74+
No Maven configuration needed - all settings come from the ecore file!
75+
-->
76+
<ecoreFile>model/catalog.ecore</ecoreFile>
77+
<outputDirectory>target/generated-sources/emf</outputDirectory>
78+
</configuration>
79+
</execution>
80+
</executions>
81+
<dependencies>
82+
<dependency>
83+
<groupId>biz.aQute.bnd</groupId>
84+
<artifactId>biz.aQute.bndlib</artifactId>
85+
<version>7.1.0</version>
86+
</dependency>
87+
</dependencies>
88+
</plugin>
89+
<plugin>
90+
<groupId>org.codehaus.mojo</groupId>
91+
<artifactId>build-helper-maven-plugin</artifactId>
92+
<version>3.6.0</version>
93+
<executions>
94+
<execution>
95+
<phase>generate-sources</phase>
96+
<goals>
97+
<goal>add-source</goal>
98+
</goals>
99+
<configuration>
100+
<sources>
101+
<source>target/generated-sources/emf</source>
102+
</sources>
103+
</configuration>
104+
</execution>
105+
</executions>
106+
</plugin>
107+
</plugins>
108+
</build>
109+
110+
</project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="vehicle" nsURI="http://eclipse.org/daanse/example/vehicle" nsPrefix="vehicle">
4+
<eClassifiers xsi:type="ecore:EClass" name="Vehicle" abstract="true">
5+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="manufacturer" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
6+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="model" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
7+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="year" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
8+
</eClassifiers>
9+
<eClassifiers xsi:type="ecore:EClass" name="Car" eSuperTypes="#//Vehicle">
10+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="doors" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
11+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="electric" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
12+
</eClassifiers>
13+
<eClassifiers xsi:type="ecore:EClass" name="Motorcycle" eSuperTypes="#//Vehicle">
14+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="engineCC" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EInt"/>
15+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="sidecar" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
16+
</eClassifiers>
17+
</ecore:EPackage>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/*********************************************************************
4+
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
5+
*
6+
* This program and the accompanying materials are made
7+
* available under the terms of the Eclipse Public License 2.0
8+
* which is available at https://www.eclipse.org/legal/epl-2.0/
9+
*
10+
* SPDX-License-Identifier: EPL-2.0
11+
**********************************************************************/
12+
-->
13+
<project
14+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
15+
xmlns="http://maven.apache.org/POM/4.0.0"
16+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
17+
<modelVersion>4.0.0</modelVersion>
18+
19+
<parent>
20+
<groupId>org.eclipse.daanse</groupId>
21+
<artifactId>org.eclipse.daanse.tooling.emf.codegen.maven.example</artifactId>
22+
<version>0.0.1-SNAPSHOT</version>
23+
</parent>
24+
25+
<artifactId>
26+
org.eclipse.daanse.tooling.emf.codegen.maven.example.ecore.copyright</artifactId>
27+
<packaging>jar</packaging>
28+
29+
<name>Daanse EMF Codegen Example - Ecore Copyright Options</name>
30+
<description>Ecore model testing copyrightText and rootExtendsClass options</description>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.eclipse.emf</groupId>
35+
<artifactId>org.eclipse.emf.common</artifactId>
36+
<version>${emf.common.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.eclipse.emf</groupId>
40+
<artifactId>org.eclipse.emf.ecore</artifactId>
41+
<version>${emf.ecore.version}</version>
42+
</dependency>
43+
<!-- Fennec EMF OSGi API (for generated OSGi service code) -->
44+
<dependency>
45+
<groupId>org.eclipse.fennec.emf</groupId>
46+
<artifactId>org.eclipse.fennec.emf.osgi.api</artifactId>
47+
<version>1.0.0-SNAPSHOT</version>
48+
</dependency>
49+
</dependencies>
50+
51+
<build>
52+
<plugins>
53+
<plugin>
54+
<groupId>org.eclipse.daanse</groupId>
55+
<artifactId>org.eclipse.daanse.tooling.emf.codegen.maven</artifactId>
56+
<version>${project.version}</version>
57+
<executions>
58+
<execution>
59+
<goals>
60+
<goal>generate</goal>
61+
</goals>
62+
<configuration>
63+
<!--
64+
This example tests copyright and root extends options:
65+
- copyrightText: Custom copyright header in generated files
66+
- rootExtendsClass: Custom base class for generated model objects
67+
-->
68+
<ecoreFile>model/vehicle.ecore</ecoreFile>
69+
<basePackage>org.eclipse.daanse.example</basePackage>
70+
<copyrightText>Copyright (c) 2025 Eclipse Daanse Contributors.
71+
Licensed under EPL-2.0.</copyrightText>
72+
<rootExtendsClass>
73+
org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container</rootExtendsClass>
74+
<outputDirectory>target/generated-sources/emf</outputDirectory>
75+
</configuration>
76+
</execution>
77+
</executions>
78+
<dependencies>
79+
<dependency>
80+
<groupId>biz.aQute.bnd</groupId>
81+
<artifactId>biz.aQute.bndlib</artifactId>
82+
<version>7.1.0</version>
83+
</dependency>
84+
</dependencies>
85+
</plugin>
86+
<plugin>
87+
<groupId>org.codehaus.mojo</groupId>
88+
<artifactId>build-helper-maven-plugin</artifactId>
89+
<version>3.6.0</version>
90+
<executions>
91+
<execution>
92+
<phase>generate-sources</phase>
93+
<goals>
94+
<goal>add-source</goal>
95+
</goals>
96+
<configuration>
97+
<sources>
98+
<source>target/generated-sources/emf</source>
99+
</sources>
100+
</configuration>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
</plugins>
105+
</build>
106+
107+
</project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="extended" nsURI="http://daanse.eclipse.org/example/extended"
4+
nsPrefix="extended">
5+
<eClassifiers xsi:type="ecore:EClass" name="Employee" eSuperTypes="http://daanse.eclipse.org/example/base#//Person">
6+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="employeeId" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
7+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="department" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
8+
<eStructuralFeatures xsi:type="ecore:EReference" name="workAddress" eType="ecore:EClass http://daanse.eclipse.org/example/base#//Address"
9+
containment="true"/>
10+
</eClassifiers>
11+
<eClassifiers xsi:type="ecore:EClass" name="Company">
12+
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
13+
<eStructuralFeatures xsi:type="ecore:EReference" name="employees" upperBound="-1"
14+
eType="#//Employee" containment="true"/>
15+
<eStructuralFeatures xsi:type="ecore:EReference" name="headquartersAddress" eType="ecore:EClass http://daanse.eclipse.org/example/base#//Address"
16+
containment="true"/>
17+
</eClassifiers>
18+
</ecore:EPackage>

0 commit comments

Comments
 (0)