@Mojo(name="gen-ddl",
defaultPhase=PROCESS_CLASSES,
requiresDependencyResolution=COMPILE_PLUS_RUNTIME,
threadSafe=true)
public class GenerateDdlMojo
extends org.apache.maven.plugin.AbstractMojo
gen-ddl
goal. In the
plugins it should be enough to create an empty class which extends this class
and is annotated with the Mojo
annotation.Modifier and Type | Field and Description |
---|---|
private boolean |
createDropStatements
Set this to
true to include drop statements into the generated
DDL file. |
private String[] |
customDialects |
private static String[] |
DEFAULT_PROPERTIES_TO_USE |
private String[] |
dialects
Database dialects for which create scripts shall be generated.
|
private boolean |
includeTestClasses
Set to
true to include classes in src/test . |
private boolean |
omitDialectFromFileName
If set to true and if only one dialect is configured
and either
outputFileNamePrefix or
outputFileNameSuffix are set the dialect name will be omitted
from the name of the DDL file. |
private File |
outputDirectory
Location of the output file.
|
private String |
outputFileNamePrefix
If set each name of an output file will be prefixed with the value of
this parameter.
|
private String |
outputFileNameSuffix
If set the value of this parameter will be appended to the name of each
output file.
|
private String[] |
packages
Packages containing the entity files for which the SQL DDL scripts shall
be generated.
|
private String[] |
persistencePropertiesToUse |
private File |
persistenceXml
The
persistence.xml file to use to read properties etc. |
private org.apache.maven.project.MavenProject |
project |
Constructor and Description |
---|
GenerateDdlMojo() |
Modifier and Type | Method and Description |
---|---|
private void |
convertDialect(String dialect,
Set<Dialect> dialectsList)
Helper method for converting the dialects from
String to
instances of the Dialect enumeration. |
private Set<Dialect> |
convertDialects()
Helper method which reads the dialects from the parameter and converts
them into instances of the
Dialect enumeration. |
void |
execute()
The Mojo's execute method.
|
String[] |
getCustomDialects() |
String |
getDialectNameFromClassName(String dialectClassName) |
String[] |
getDialects() |
File |
getOutputDirectory() |
String |
getOutputFileNamePrefix() |
String |
getOutputFileNameSuffix() |
String[] |
getPackages() |
String[] |
getPersistencePropertiesToUse() |
File |
getPersistenceXml() |
boolean |
isCreateDropStatements() |
boolean |
isIncludeTestClasses() |
boolean |
isOmitDialectFromFileName() |
void |
setCreateDropStatements(boolean createDropStatments) |
void |
setCustomDialects(String... customDialects) |
void |
setDialects(String... dialects) |
void |
setIncludeTestClasses(boolean includeTestClasses) |
void |
setOmitDialectFromFileName(boolean omitDialectFromFileName) |
void |
setOutputDirectory(File outputDirectory) |
void |
setOutputFileNamePrefix(String outputFileNamePrefix) |
void |
setOutputFileNameSuffix(String outputFileNameSuffix) |
void |
setPackages(String... packages) |
void |
setPersistencePropertiesToUse(String... persistencePropertiesToUse) |
void |
setPersistenceXml(File persistenceXml) |
protected void |
writeOutputFile(String dialectClassName,
Path tmpDir) |
private static final String[] DEFAULT_PROPERTIES_TO_USE
@Parameter(defaultValue="${project.build.directory}/generated-resources/sql/ddl/auto", property="outputDir", required=true) private File outputDirectory
@Parameter(required=false, defaultValue="") private String outputFileNamePrefix
@Parameter(required=false, defaultValue="") private String outputFileNameSuffix
@Parameter(required=false) private boolean omitDialectFromFileName
outputFileNamePrefix
or
outputFileNameSuffix
are set the dialect name will be omitted
from the name of the DDL file.@Parameter(required=true) private String[] packages
@Parameter(required=false) private boolean includeTestClasses
true
to include classes in src/test
.@Parameter(required=false) private String[] dialects
Dialect
enumeration.@Parameter(required=false) private String[] customDialects
@Parameter(required=false) private boolean createDropStatements
true
to include drop statements into the generated
DDL file.@Parameter(defaultValue="${basedir}/src/main/resources/META-INF/persistence.xml", required=false) private File persistenceXml
persistence.xml
file to use to read properties etc. Default
value is src/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.@Parameter(required=false) private String[] persistencePropertiesToUse
@Parameter(defaultValue="${project}", readonly=true) private transient org.apache.maven.project.MavenProject project
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
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.public File getOutputDirectory()
public void setOutputDirectory(File outputDirectory)
public String getOutputFileNamePrefix()
public void setOutputFileNamePrefix(String outputFileNamePrefix)
public String getOutputFileNameSuffix()
public void setOutputFileNameSuffix(String outputFileNameSuffix)
public boolean isOmitDialectFromFileName()
public void setOmitDialectFromFileName(boolean omitDialectFromFileName)
public String[] getPackages()
public void setPackages(String... packages)
public String[] getDialects()
public void setDialects(String... dialects)
public String[] getCustomDialects()
public void setCustomDialects(String... customDialects)
public boolean isCreateDropStatements()
public void setCreateDropStatements(boolean createDropStatments)
public File getPersistenceXml()
public void setPersistenceXml(File persistenceXml)
public String[] getPersistencePropertiesToUse()
public void setPersistencePropertiesToUse(String... persistencePropertiesToUse)
public boolean isIncludeTestClasses()
public void setIncludeTestClasses(boolean includeTestClasses)
private Set<Dialect> convertDialects() throws org.apache.maven.plugin.MojoFailureException
Dialect
enumeration.org.apache.maven.plugin.MojoFailureException
- If an error occurs.private void convertDialect(String dialect, Set<Dialect> dialectsList) throws org.apache.maven.plugin.MojoFailureException
String
to
instances of the Dialect
enumeration.dialect
- The dialect to convert.dialectsList
- The lists of dialects where the converted dialect is
stored.org.apache.maven.plugin.MojoFailureException
- If the dialect string could not be
converted, for example if it is misspelled.
This will cause a Build Failure
protected void writeOutputFile(String dialectClassName, Path tmpDir) throws org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoFailureException
Copyright © 2016–2019 Jens Pelzetter. All rights reserved.