-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBX-2869: Create a GenerateHBM Mojo in the Maven plugin - Add the Mojo
Signed-off-by: Koen Aers <[email protected]>
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
maven/src/main/java/org/hibernate/tool/maven/GenerateHbmMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Hibernate Tools, Tooling for your Hibernate Projects | ||
* | ||
* Copyright 2016-2020 Red Hat, Inc. | ||
* | ||
* Licensed under the GNU Lesser General Public License (LGPL), | ||
* version 2.1 or later (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* You may read the licence in the 'lgpl.txt' file in the root folder of | ||
* project or obtain a copy at | ||
* | ||
* http://www.gnu.org/licenses/lgpl-2.1.html | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.hibernate.tool.maven; | ||
|
||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.hibernate.tool.api.export.Exporter; | ||
import org.hibernate.tool.api.export.ExporterConstants; | ||
import org.hibernate.tool.api.export.ExporterFactory; | ||
import org.hibernate.tool.api.export.ExporterType; | ||
import org.hibernate.tool.api.metadata.MetadataDescriptor; | ||
|
||
import java.io.File; | ||
|
||
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES; | ||
|
||
/** | ||
* Mojo to generate hbm.xml files from an existing database. | ||
* <p> | ||
* See: https://docs.jboss.org/tools/latest/en/hibernatetools/html_single/#d0e4821 | ||
*/ | ||
@Mojo(name = "generateHbm", defaultPhase = GENERATE_SOURCES) | ||
public class GenerateHbmMojo extends AbstractGenerationMojo { | ||
|
||
/** The directory into which the DAOs will be generated. */ | ||
@Parameter(defaultValue = "${project.basedir}/src/main/resources") | ||
private File outputDirectory; | ||
|
||
@Parameter | ||
private String templatePath; | ||
|
||
protected void executeExporter(MetadataDescriptor metadataDescriptor) { | ||
try { | ||
Exporter hbmExporter = ExporterFactory.createExporter(ExporterType.HBM); | ||
hbmExporter.getProperties().put(ExporterConstants.METADATA_DESCRIPTOR, metadataDescriptor); | ||
hbmExporter.getProperties().put(ExporterConstants.DESTINATION_FOLDER, outputDirectory); | ||
if (templatePath != null) { | ||
getLog().info("Setting template path to: " + templatePath); | ||
hbmExporter.getProperties().put(ExporterConstants.TEMPLATE_PATH, new String[] {templatePath}); | ||
} | ||
getLog().info("Starting HBM export to directory: " + outputDirectory + "..."); | ||
hbmExporter.start(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
|
||
} |