Class GenerateDdlMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- de.jpdigital.maven.plugins.hibernate5ddl.GenerateDdlMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
@Mojo(name="gen-ddl", defaultPhase=PROCESS_CLASSES, requiresDependencyResolution=COMPILE_PLUS_RUNTIME, threadSafe=true) public class GenerateDdlMojo extends org.apache.maven.plugin.AbstractMojoBase class the the Mojo class providing thegen-ddlgoal. In the plugins it should be enough to create an empty class which extends this class and is annotated with theMojoannotation.- Author:
- Jens Pelzetter
-
-
Field Summary
Fields Modifier and Type Field Description private booleancreateDropStatementsSet this totrueto include drop statements into the generated DDL file.private String[]customDialectsprivate static String[]DEFAULT_PROPERTIES_TO_USEprivate String[]dialectsDatabase dialects for which create scripts shall be generated.private booleanincludeTestClassesSet totrueto include classes insrc/test.private booleanomitDialectFromFileNameIf set to true and if only one dialect is configured and eitheroutputFileNamePrefixoroutputFileNameSuffixare set the dialect name will be omitted from the name of the DDL file.private FileoutputDirectoryLocation of the output file.private StringoutputFileNamePrefixIf set each name of an output file will be prefixed with the value of this parameter.private StringoutputFileNameSuffixIf set the value of this parameter will be appended to the name of each output file.private String[]packagesPackages containing the entity files for which the SQL DDL scripts shall be generated.private Map<String,String>persistencePropertiesprivate String[]persistencePropertiesToUseprivate FilepersistenceXmlThepersistence.xmlfile to use to read properties etc.private org.apache.maven.project.MavenProjectproject
-
Constructor Summary
Constructors Constructor Description GenerateDdlMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidconvertDialect(String dialect, Set<Dialect> dialectsList)Helper method for converting the dialects fromStringto instances of theDialectenumeration.private Set<Dialect>convertDialects()Helper method which reads the dialects from the parameter and converts them into instances of theDialectenumeration.voidexecute()The Mojo's execute method.String[]getCustomDialects()StringgetDialectNameFromClassName(String dialectClassName)String[]getDialects()FilegetOutputDirectory()StringgetOutputFileNamePrefix()StringgetOutputFileNameSuffix()String[]getPackages()Map<String,String>getPersistenceProperties()String[]getPersistencePropertiesToUse()FilegetPersistenceXml()protected org.apache.maven.project.MavenProjectgetProject()booleanisCreateDropStatements()booleanisIncludeTestClasses()booleanisOmitDialectFromFileName()voidsetCreateDropStatements(boolean createDropStatments)voidsetCustomDialects(String... customDialects)voidsetDialects(String... dialects)voidsetIncludeTestClasses(boolean includeTestClasses)voidsetOmitDialectFromFileName(boolean omitDialectFromFileName)voidsetOutputDirectory(File outputDirectory)voidsetOutputFileNamePrefix(String outputFileNamePrefix)voidsetOutputFileNameSuffix(String outputFileNameSuffix)voidsetPackages(String... packages)voidsetPersistenceProperties(Map<String,String> persistenceProperties)voidsetPersistencePropertiesToUse(String... persistencePropertiesToUse)voidsetPersistenceXml(File persistenceXml)protected voidsetProject(org.apache.maven.project.MavenProject project)protected voidwriteOutputFile(String dialectClassName, Path tmpDir)
-
-
-
Field Detail
-
DEFAULT_PROPERTIES_TO_USE
private static final String[] DEFAULT_PROPERTIES_TO_USE
-
outputDirectory
@Parameter(defaultValue="${project.build.directory}/generated-resources/sql/ddl/auto", property="outputDir", required=true) private File outputDirectoryLocation of the output file.
-
outputFileNamePrefix
@Parameter(required=false, defaultValue="") private String outputFileNamePrefixIf set each name of an output file will be prefixed with the value of this parameter.
-
outputFileNameSuffix
@Parameter(required=false, defaultValue="") private String outputFileNameSuffixIf set the value of this parameter will be appended to the name of each output file.
-
omitDialectFromFileName
@Parameter(required=false) private boolean omitDialectFromFileName
If set to true and if only one dialect is configured and eitheroutputFileNamePrefixoroutputFileNameSuffixare set the dialect name will be omitted from the name of the DDL file.
-
packages
@Parameter(required=false) private String[] packages
Packages containing the entity files for which the SQL DDL scripts shall be generated.
-
includeTestClasses
@Parameter(required=false) private boolean includeTestClasses
Set totrueto include classes insrc/test.
-
dialects
@Parameter(required=false) private String[] dialects
Database dialects for which create scripts shall be generated. For available dialects refer to the documentation theDialectenumeration.
-
customDialects
@Parameter(required=false) private String[] customDialects
-
createDropStatements
@Parameter(required=false) private boolean createDropStatements
Set this totrueto include drop statements into the generated DDL file.
-
persistenceXml
@Parameter(defaultValue="${basedir}/src/main/resources/META-INF/persistence.xml", required=false) private File persistenceXmlThepersistence.xmlfile to use to read properties etc. Default value issrc/main/resources/META-INF/persistence.xml. If the file is not present it is ignored. If the file is present all properties set using a<property>element are set on the Hibernate configuration.
-
persistencePropertiesToUse
@Parameter(required=false) private String[] persistencePropertiesToUse
-
project
@Parameter(defaultValue="${project}", readonly=true) private transient org.apache.maven.project.MavenProject project
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionThe Mojo's execute method.- Throws:
org.apache.maven.plugin.MojoExecutionException- if the Mojo can't be executed.org.apache.maven.plugin.MojoFailureException- if something goes wrong while to Mojo is executed.
-
getOutputDirectory
public File getOutputDirectory()
-
setOutputDirectory
public void setOutputDirectory(File outputDirectory)
-
getOutputFileNamePrefix
public String getOutputFileNamePrefix()
-
setOutputFileNamePrefix
public void setOutputFileNamePrefix(String outputFileNamePrefix)
-
getOutputFileNameSuffix
public String getOutputFileNameSuffix()
-
setOutputFileNameSuffix
public void setOutputFileNameSuffix(String outputFileNameSuffix)
-
isOmitDialectFromFileName
public boolean isOmitDialectFromFileName()
-
setOmitDialectFromFileName
public void setOmitDialectFromFileName(boolean omitDialectFromFileName)
-
getPackages
public String[] getPackages()
-
setPackages
public void setPackages(String... packages)
-
getDialects
public String[] getDialects()
-
setDialects
public void setDialects(String... dialects)
-
getCustomDialects
public String[] getCustomDialects()
-
setCustomDialects
public void setCustomDialects(String... customDialects)
-
isCreateDropStatements
public boolean isCreateDropStatements()
-
setCreateDropStatements
public void setCreateDropStatements(boolean createDropStatments)
-
getPersistenceXml
public File getPersistenceXml()
-
setPersistenceXml
public void setPersistenceXml(File persistenceXml)
-
getPersistencePropertiesToUse
public String[] getPersistencePropertiesToUse()
-
setPersistencePropertiesToUse
public void setPersistencePropertiesToUse(String... persistencePropertiesToUse)
-
setPersistenceProperties
public void setPersistenceProperties(Map<String,String> persistenceProperties)
-
getProject
protected org.apache.maven.project.MavenProject getProject()
-
setProject
protected void setProject(org.apache.maven.project.MavenProject project)
-
isIncludeTestClasses
public boolean isIncludeTestClasses()
-
setIncludeTestClasses
public void setIncludeTestClasses(boolean includeTestClasses)
-
convertDialects
private Set<Dialect> convertDialects() throws org.apache.maven.plugin.MojoFailureException
Helper method which reads the dialects from the parameter and converts them into instances of theDialectenumeration.- Returns:
- A list of all dialects to use
- Throws:
org.apache.maven.plugin.MojoFailureException- If an error occurs.
-
convertDialect
private void convertDialect(String dialect, Set<Dialect> dialectsList) throws org.apache.maven.plugin.MojoFailureException
Helper method for converting the dialects fromStringto instances of theDialectenumeration.- Parameters:
dialect- The dialect to convert.dialectsList- The lists of dialects where the converted dialect is stored.- Throws:
org.apache.maven.plugin.MojoFailureException- If the dialect string could not be converted, for example if it is misspelled. This will cause aBuild Failure
-
writeOutputFile
protected void writeOutputFile(String dialectClassName, Path tmpDir) throws org.apache.maven.plugin.MojoFailureException
- Throws:
org.apache.maven.plugin.MojoFailureException
-
-