|
1 | 1 | [[tooling-ant]]
|
2 |
| -=== Ant Plugin |
| 2 | +=== Ant |
3 | 3 |
|
4 |
| -Hibernate provides https://ant.apache.org/[Ant] support ... |
| 4 | +Hibernate provides https://ant.apache.org/[Ant] support. |
| 5 | +Everything Ant related is available from the |
| 6 | +https://central.sonatype.com/artifact/org.hibernate.orm/hibernate-ant[hibernate-ant] |
| 7 | +library. |
5 | 8 |
|
| 9 | +[[tooling-ant-enhancement]] |
| 10 | +==== Bytecode Enhancement ==== |
| 11 | + |
| 12 | +Hibernate provides an https://ant.apache.org/[Ant] task implementation |
| 13 | +that you can use to do build-time bytecode enhancement of your domain |
| 14 | +model. You can visit <<BytecodeEnhancement>> for discussion of the capabilities |
| 15 | +of an enhanced model. |
| 16 | + |
| 17 | +[[ant-enhance-task]] |
| 18 | +===== *Enhance Task* ===== |
| 19 | + |
| 20 | +The task implementation is in class `org.hibernate.tool.enhance.EnhancementTask`, |
| 21 | +so you will need to include a `taskdef` in your `build.xml` that uses this class |
| 22 | +to define your task. Below is a minimal Ant `build.xml` file that shows the use |
| 23 | +of the enhancement task. |
| 24 | + |
| 25 | +[[enhance-task-example]] |
| 26 | +.Enhance Task Example |
| 27 | +==== |
| 28 | +[source, XML]] |
| 29 | +---- |
| 30 | +include::extras/ant-enhance-example.xml[] |
| 31 | +---- |
| 32 | +==== |
| 33 | + |
| 34 | +As you can see above, https://ant.apache.org/ivy[Apache Ivy] was used to |
| 35 | +handle the dependency on the |
| 36 | +https://central.sonatype.com/artifact/org.hibernate.orm/hibernate-ant[hibernate-ant] |
| 37 | +library. Now let's dive a little deeper in the configuration possibilities for the |
| 38 | +enhancement task. |
| 39 | + |
| 40 | +[[ant-enhance-configuration]] |
| 41 | +===== *Enhance Configuration* ===== |
| 42 | + |
| 43 | +[[ant-enhance-base-attribute]] |
| 44 | +====== `*base*` ====== |
| 45 | +This attribute is mandatory. It points to the base folder where the enhancement task will look |
| 46 | +to discover classes that have to be enhanced. It is either combined with the `dir` |
| 47 | +attribute that specifies a subfolder of `base` where the classes are located (or of course |
| 48 | +the entire `base` folder) or else with a `<fileset>` child element that has a similar role. |
| 49 | +If neither `dir` nor `<fileset>` are used, no classes will be enhanced. |
| 50 | + |
| 51 | +==== |
| 52 | +[source, XML]] |
| 53 | +---- |
| 54 | +<enhance base='${basedir}/dest' .../> |
| 55 | +---- |
| 56 | +==== |
| 57 | + |
| 58 | +[[ant-enhance-dir-attribute]] |
| 59 | +====== `*dir*` ====== |
| 60 | +This attribute is combined with the (mandatory) `base` attribute described above. It points to |
| 61 | +a subfolder of `base` where the enhancement task will look to discover the classes to be enhanced. |
| 62 | +If the `dir` attribute is specified, the use of a `<fileset>` child element will be ignored. |
| 63 | +If neither `dir` nor `<fileset>` are used, no classes will be enhanced. |
| 64 | + |
| 65 | +==== |
| 66 | +[source, XML]] |
| 67 | +---- |
| 68 | +<enhance |
| 69 | + base='...' |
| 70 | + dir='some subfolder of base'/> |
| 71 | +---- |
| 72 | +==== |
| 73 | + |
| 74 | +[[ant-enhance-fileset-element]] |
| 75 | +===== `*<fileset>*` ===== |
| 76 | +This child element is combined with the (mandatory) `base` attribute described above. It can be used |
| 77 | +to detail which classes should be selected for enhancement. The use of `<fileset>` is well documented on the |
| 78 | +https://ant.apache.org/manual/Types/fileset.html[Ant FileSet documentation page]. If the `dir` attribute |
| 79 | +described above is specified, the `<fileset>` element will be ignored. |
| 80 | +If neither `dir` nor `<fileset>` are used, no classes will be enhanced. |
| 81 | + |
| 82 | +==== |
| 83 | +[source, XML]] |
| 84 | +---- |
| 85 | +<enhance base='${basedir}/dest'> |
| 86 | + <fileset dir="some subfolder of base"> |
| 87 | + <exclude name='Baz.class' /> |
| 88 | + </fileset> |
| 89 | +</enhance> |
| 90 | +---- |
| 91 | +==== |
| 92 | + |
| 93 | +[[ant-enhance-enableLazyInitialization-attribute]] |
| 94 | +===== `*enableLazyInitialization*` ===== |
| 95 | +This attribute has a default value of `true`. It indicates that the enhance task should perform the changes |
| 96 | +to enable lazy loading. To disable, set the value of this attribute to `false`. |
| 97 | + |
| 98 | +==== |
| 99 | +[source, XML]] |
| 100 | +---- |
| 101 | +<enhance |
| 102 | + ... |
| 103 | + enableLazyInitialization='false'/> |
| 104 | +---- |
| 105 | +==== |
| 106 | + |
| 107 | + |
| 108 | +[[ant-enhance-enableDirtyTracking-attribute]] |
| 109 | +===== `*enableDirtyTracking*` ===== |
| 110 | +This attribute has a default value of `true`. It indicates that the enhance task should perform the changes |
| 111 | +to enable dirty tracking. To disable, set the value of this attribute to `false`. |
| 112 | + |
| 113 | +==== |
| 114 | +[source, XML]] |
| 115 | +---- |
| 116 | +<enhance |
| 117 | + ... |
| 118 | + enableDirtyTracking='false'/> |
| 119 | +---- |
| 120 | +==== |
| 121 | + |
| 122 | +[[ant-enhance-enableAssociationManagement-attribute]] |
| 123 | +===== `*enableAssociationManagement*` ===== |
| 124 | +This attribute has a default value of `false`. It indicates that the enhance task should not perform the changes |
| 125 | +to enable association management. To enable, set the value of this attribute to `true`. |
| 126 | + |
| 127 | +==== |
| 128 | +[source, XML]] |
| 129 | +---- |
| 130 | +<enhance |
| 131 | + ... |
| 132 | + enableAssociationManagement='true'/> |
| 133 | +---- |
| 134 | +==== |
| 135 | + |
| 136 | +[[ant-enhance-enableExtendedEnhancement-attribute]] |
| 137 | +===== `*enableExtendedEnhancement*` ===== |
| 138 | +This attribute has a default value of `false`. It indicates that the enhance task should not perform the changes |
| 139 | +to enable the extended enhancement (i.e. even on non-entities). |
| 140 | +To enable this, set the value of this attribute to `true`. |
| 141 | + |
| 142 | +==== |
| 143 | +[source, XML]] |
| 144 | +---- |
| 145 | +<enhance |
| 146 | + ... |
| 147 | + enableExtendedEnhancement='true'/> |
| 148 | +---- |
| 149 | +==== |
| 150 | + |
| 151 | +[[ant-enhance-failOnError-attribute]] |
| 152 | +===== `*failOnError*` ===== |
| 153 | +This attribute has a default value of `true`. It indicates that the enhance task will throw an Ant BuildException |
| 154 | +when it encounters a problem. If you prefer the build to continue, you can set the value to `false`. |
| 155 | + |
| 156 | +==== |
| 157 | +[source, XML]] |
| 158 | +---- |
| 159 | +<enhance |
| 160 | + ... |
| 161 | + failOnError='false'/> |
| 162 | +---- |
| 163 | +==== |
| 164 | + |
| 165 | +===== *Final Remark* ===== |
| 166 | +If the values of the four attributes `enableLazyInitialization`, `enableDirtyTracking`, `enableAssociationManagement`, |
| 167 | +`enableExtendedEnhancement` are all `false`, the enhancement task is not executed. |
6 | 168 |
|
7 | 169 | [[tooling-ant-modelgen]]
|
8 | 170 | ==== Static Metamodel Generation in Ant
|
|
0 commit comments