Class SchemaGeneratorTask
- All Implemented Interfaces:
Cloneable
This task scans the configured classpath for classes with @PermazenType
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. Conflicts are only possible when explicit storage ID's are used.
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. |
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. |
schemaIdProperty |
No |
The name of an ant property to set to the 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 |
encodingRegistry |
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>
- See Also:
-
Field Summary
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addOldSchemas
(org.apache.tools.ant.types.FileSet oldSchemas) org.apache.tools.ant.types.Path
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
setEncodingRegistryClass
(String encodingRegistryClassName) void
setFailOnError
(boolean failOnError) void
void
void
setPackages
(String packages) void
setSchemaIdProperty
(String schemaIdProperty) void
setVerifiedProperty
(String verifiedProperty) Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
-
Field Details
-
MODE_VERIFY
- See Also:
-
MODE_GENERATE
- See Also:
-
MODE_GENERATE_AND_VERIFY
- See Also:
-
-
Constructor Details
-
SchemaGeneratorTask
public SchemaGeneratorTask()
-
-
Method Details
-
setClasses
-
setPackages
-
setMode
-
setFailOnError
public void setFailOnError(boolean failOnError) -
setVerifiedProperty
-
setSchemaIdProperty
-
setFile
-
createClasspath
public org.apache.tools.ant.types.Path createClasspath() -
setClasspath
public void setClasspath(org.apache.tools.ant.types.Path classPath) -
setClasspathRef
public void setClasspathRef(org.apache.tools.ant.types.Reference ref) -
setEncodingRegistryClass
-
addOldSchemas
public void addOldSchemas(org.apache.tools.ant.types.FileSet oldSchemas) -
execute
public void execute()- Overrides:
execute
in classorg.apache.tools.ant.Task
- Throws:
org.apache.tools.ant.BuildException
- if operation fails
-