Skip to content

Commit a89a47d

Browse files
committed
HBX-2869: Create a GenerateHBM Mojo in the Maven plugin - Add the Mojo
Signed-off-by: Koen Aers <[email protected]>
1 parent 00b7de4 commit a89a47d

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Hibernate Tools, Tooling for your Hibernate Projects
3+
*
4+
* Copyright 2016-2020 Red Hat, Inc.
5+
*
6+
* Licensed under the GNU Lesser General Public License (LGPL),
7+
* version 2.1 or later (the "License").
8+
* You may not use this file except in compliance with the License.
9+
* You may read the licence in the 'lgpl.txt' file in the root folder of
10+
* project or obtain a copy at
11+
*
12+
* http://www.gnu.org/licenses/lgpl-2.1.html
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" basis,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package org.hibernate.mvn;
21+
22+
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
23+
24+
import java.io.File;
25+
26+
import org.apache.maven.plugins.annotations.Mojo;
27+
import org.apache.maven.plugins.annotations.Parameter;
28+
import org.hibernate.tool.api.metadata.MetadataDescriptor;
29+
import org.hibernate.tool.hbm2x.HibernateMappingExporter;
30+
31+
/**
32+
* Mojo to generate hbm.xml files from an existing database.
33+
* <p>
34+
* See: https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4821
35+
*/
36+
@Mojo(name = "generateHbm", defaultPhase = GENERATE_SOURCES)
37+
public class GenerateHbmMojo extends AbstractHbm2xMojo {
38+
39+
/** The directory into which the DAOs will be generated. */
40+
@Parameter(defaultValue = "${project.basedir}/src/main/resources")
41+
private File outputDirectory;
42+
43+
@Parameter
44+
private String templatePath;
45+
46+
protected void executeExporter(MetadataDescriptor metadataDescriptor) {
47+
try {
48+
HibernateMappingExporter hbmExporter = new HibernateMappingExporter();
49+
hbmExporter.setMetadataDescriptor(metadataDescriptor);
50+
hbmExporter.setOutputDirectory(outputDirectory);
51+
if (templatePath != null) {
52+
getLog().info("Setting template path to: " + templatePath);
53+
hbmExporter.setTemplatePath(new String[] {templatePath});
54+
}
55+
getLog().info("Starting HBM export to directory: " + outputDirectory + "...");
56+
hbmExporter.start();
57+
} catch (Exception e) {
58+
e.printStackTrace();
59+
}
60+
}
61+
62+
63+
}

0 commit comments

Comments
 (0)