public class SchemaGeneratorTask
extends org.apache.tools.ant.Task
This task scans the configured classpath for classes with @PermazenType
and @JFieldType
annotations and either writes the generated schema
to an XML file, or verifies the schema matches an existing XML file.
Generation of schema XML files and the use of this task is not necessary. However, it does allow certain schema-related problems to be detected at build time instead of runtime. In particular, it can let you know if any change to your model classes requires a new Permazen schema version.
This task can also check for conflicts between the schema in question and older schema versions that may still
exist in production databases. These other schema versions are specified using nested <oldschemas>
elements, which work just like <fileset>
's.
The following attributes are supported by this task:
Attribute | Required? | Description |
---|---|---|
mode |
No |
Set to
Default is |
file |
Yes |
The XML file to generate or verify. |
matchNames |
No |
Whether to verify not only Two schemas that are equivalent except for names are compatible, because the core API uses storage ID's, not names. However, if names change then some Permazen layer operations, such as index queries and reference path inversion, may need to be updated.
Default is |
failOnError |
No |
Whether to fail if verification fails when
Default is |
verifiedProperty |
No |
The name of an ant property to set to Default is to not set any property. |
schemaVersionProperty |
No |
The name of an ant property to set to the auto-generated schema version number. This is the schema
version number that will be auto-generated when a schema version number of Default is to not set any property. |
classpath or classpathref |
Yes |
Specifies the search path containing classes with |
packages |
Yes, unless classes are specified |
Specifies one or more Java package names (separated by commas and/or whitespace) under which to look
for classes with
Use of this attribute requires Spring's classpath scanning classes ( |
classes |
Yes, unless packages are specified |
Specifies one or more Java class names (separated by commas and/or whitespace) of
classes with |
storageIdGeneratorClass |
No |
Specifies the name of an optional custom
By default, a |
Classes are found by scanning the packages listed in the "packages"
attribute.
Alternatively, or in addition, specific classes may specified using the "classes"
attribute.
To install this task into ant:
<project xmlns:permazen="urn:io.permazen.ant" ... > ... <taskdef uri="urn:io.permazen.ant" name="schema" classname="io.permazen.ant.SchemaGeneratorTask" classpathref="permazen.classpath"/>
Example of generating a schema XML file that corresponds to the specified Java model classes:
<permazen:schema mode="generate" classpathref="myclasses.classpath" file="schema.xml" packages="com.example.model"/>
Example of verifying that the schema generated from the Java model classes has not changed incompatibly (i.e., in a way that would require a new schema version):
<permazen:schema mode="verify" classpathref="myclasses.classpath" file="expected-schema.xml" packages="com.example.model"/>
Example of doing the same thing, and also verifying the generated schema is compatible with prior schema versions that may still be in use in production databases:
<permazen:schema mode="verify" classpathref="myclasses.classpath" file="expected-schema.xml" packages="com.example.model"> <permazen:oldschemas dir="obsolete-schemas" includes="*.xml"/> </permazen:schema>
Permazen
,
SchemaModel
Modifier and Type | Field and Description |
---|---|
static String |
MODE_GENERATE |
static String |
MODE_GENERATE_AND_VERIFY |
static String |
MODE_VERIFY |
Constructor and Description |
---|
SchemaGeneratorTask() |
Modifier and Type | Method and Description |
---|---|
void |
addOldSchemas(org.apache.tools.ant.types.FileSet oldSchemas) |
org.apache.tools.ant.types.Path |
createClasspath() |
void |
execute() |
void |
setClasses(String classes) |
void |
setClasspath(org.apache.tools.ant.types.Path classPath) |
void |
setClasspathRef(org.apache.tools.ant.types.Reference ref) |
void |
setFailOnError(boolean failOnError) |
void |
setFile(File file) |
void |
setMatchNames(boolean matchNames) |
void |
setMode(String mode) |
void |
setPackages(String packages) |
void |
setSchemaVersionProperty(String schemaVersionProperty) |
void |
setStorageIdGeneratorClass(String storageIdGeneratorClassName) |
void |
setVerifiedProperty(String verifiedProperty) |
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
public static final String MODE_VERIFY
public static final String MODE_GENERATE
public static final String MODE_GENERATE_AND_VERIFY
public void setClasses(String classes)
public void setPackages(String packages)
public void setMode(String mode)
public void setMatchNames(boolean matchNames)
public void setFailOnError(boolean failOnError)
public void setVerifiedProperty(String verifiedProperty)
public void setSchemaVersionProperty(String schemaVersionProperty)
public void setFile(File file)
public org.apache.tools.ant.types.Path createClasspath()
public void setClasspath(org.apache.tools.ant.types.Path classPath)
public void setClasspathRef(org.apache.tools.ant.types.Reference ref)
public void setStorageIdGeneratorClass(String storageIdGeneratorClassName)
public void addOldSchemas(org.apache.tools.ant.types.FileSet oldSchemas)
public void execute()
execute
in class org.apache.tools.ant.Task
org.apache.tools.ant.BuildException
- if operation failsCopyright © 2022. All rights reserved.