Skip to content

Commit e65a99e

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 7ff26c3 commit e65a99e

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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.tool.maven;
21+
22+
import org.apache.maven.plugins.annotations.Mojo;
23+
import org.apache.maven.plugins.annotations.Parameter;
24+
import org.hibernate.tool.api.export.Exporter;
25+
import org.hibernate.tool.api.export.ExporterConstants;
26+
import org.hibernate.tool.api.export.ExporterFactory;
27+
import org.hibernate.tool.api.export.ExporterType;
28+
import org.hibernate.tool.api.metadata.MetadataDescriptor;
29+
30+
import java.io.File;
31+
32+
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
33+
34+
/**
35+
* Mojo to generate hbm.xml files from an existing database.
36+
* <p>
37+
* See: https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4821
38+
*/
39+
@Mojo(name = "generateHbm", defaultPhase = GENERATE_SOURCES)
40+
public class GenerateHbmMojo extends AbstractGenerationMojo {
41+
42+
/** The directory into which the DAOs will be generated. */
43+
@Parameter(defaultValue = "${project.basedir}/src/main/resources")
44+
private File outputDirectory;
45+
46+
@Parameter
47+
private String templatePath;
48+
49+
protected void executeExporter(MetadataDescriptor metadataDescriptor) {
50+
try {
51+
Exporter hbmExporter = ExporterFactory.createExporter(ExporterType.HBM);
52+
hbmExporter.getProperties().put(ExporterConstants.METADATA_DESCRIPTOR, metadataDescriptor);
53+
hbmExporter.getProperties().put(ExporterConstants.DESTINATION_FOLDER, outputDirectory);
54+
if (templatePath != null) {
55+
getLog().info("Setting template path to: " + templatePath);
56+
hbmExporter.getProperties().put(ExporterConstants.TEMPLATE_PATH, new String[] {templatePath});
57+
}
58+
getLog().info("Starting HBM export to directory: " + outputDirectory + "...");
59+
hbmExporter.start();
60+
} catch (Exception e) {
61+
e.printStackTrace();
62+
}
63+
}
64+
65+
66+
}

0 commit comments

Comments
 (0)