]> juplo.de Git - hibernate4-maven-plugin/commitdiff
Refined reimplementation of the plugin for Hibernate 5.x
authorKai Moritz <kai@juplo.de>
Fri, 16 Oct 2015 10:16:30 +0000 (12:16 +0200)
committerKai Moritz <kai@juplo.de>
Sun, 20 Dec 2015 20:08:48 +0000 (21:08 +0100)
Renamed the plugin from hibernate4-maven-plugin to hibernate-maven-plugin,
because the goal is, to support all recent older versions with the new
plugin.

44 files changed:
pom.xml
src/it/dependency test/h4mp/pom.xml
src/it/h4mp-mod/pom.xml
src/it/h4mp-mod/schema.sql
src/it/hib-test/h2.sql
src/it/hib-test/oracle.sql
src/it/hib-test/pom.xml
src/it/hib-test/postgres.sql
src/it/hibernate4-maven-plugin-envers-sample/README.md
src/it/hibernate4-maven-plugin-envers-sample/pom.xml
src/it/ignored-dependency/main/pom.xml
src/it/ignored-dependency/schema.sql
src/it/properties/h2.sql
src/it/properties/pom.xml
src/it/schemaexport-example/schema.sql
src/it/schemaexport-example/schemaexport-example-persistence-impl/pom.xml
src/it/tutorials/annotations/pom.xml
src/it/tutorials/basic/pom.xml
src/it/tutorials/entitymanager/pom.xml
src/it/tutorials/envers/pom.xml
src/it/tutorials/osgi/managed-jpa/pom.xml [changed mode: 0755->0644]
src/it/tutorials/osgi/unmanaged-jpa/pom.xml [changed mode: 0755->0644]
src/it/tutorials/osgi/unmanaged-native/pom.xml [changed mode: 0755->0644]
src/it/tutorials/schema-annotations.sql
src/it/tutorials/schema-basic.sql
src/it/tutorials/schema-entitymanager.sql
src/it/tutorials/schema-envers.sql
src/it/tutorials/schema-osgi-managed-jpa.sql
src/it/tutorials/schema-osgi-unmanaged-jpa.sql
src/it/tutorials/schema-osgi-unmanaged-native.sql
src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java [new file with mode: 0644]
src/main/java/de/juplo/plugins/hibernate/CreateMojo.java [new file with mode: 0644]
src/main/java/de/juplo/plugins/hibernate/ModificationTracker.java [new file with mode: 0644]
src/main/java/de/juplo/plugins/hibernate/SimpleConnectionProvider.java [new file with mode: 0644]
src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java [deleted file]
src/main/java/de/juplo/plugins/hibernate4/ValidationConfiguration.java [deleted file]
src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivatorAccessor.java [deleted file]
src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml [deleted file]
src/site/xhtml/configuration.xhtml
src/site/xhtml/debugging.xhtml
src/site/xhtml/force.xhtml
src/site/xhtml/index.xhtml
src/site/xhtml/pitfalls.xhtml
src/site/xhtml/skip.xhtml

diff --git a/pom.xml b/pom.xml
index a0a92d90f2909d29c459bd98204f445029c68a8e..dda23106a4c8c902f833bcbaf532f778c3d3c218 100644 (file)
--- a/pom.xml
+++ b/pom.xml
   </parent>
 
   <groupId>de.juplo</groupId>
-  <artifactId>hibernate4-maven-plugin</artifactId>
-  <name>Hibernate Maven Plugin</name>
-  <description>Plugin for generating a database-schema from Hibernate-4-Mapping-Annotations</description>
+  <artifactId>hibernate-maven-plugin</artifactId>
+  <name>Hibernate Maven Plugin</name>
+  <description>Plugin for generating a database-schema from Hibernate-Mapping-Annotations</description>
   <version>2.0-SNAPSHOT</version>
   <packaging>maven-plugin</packaging>
-  <url>http://juplo.de/hibernate4-maven-plugin</url>
+  <url>http://juplo.de/hibernate-maven-plugin</url>
 
   <prerequisites>
     <maven>2.0.6</maven>
@@ -31,9 +31,9 @@
   </licenses>
 
   <scm>
-    <connection>scm:git:http://juplo.de/git/hibernate4-maven-plugin</connection>
-    <developerConnection>scm:git:ssh://juplo.de:/var/lib/git/juplo/hibernate4-maven-plugin</developerConnection>
-    <url>http://juplo.de/gitweb/?p=hibernate4-maven-plugin;a=summary</url>
+    <connection>scm:git:http://juplo.de/git/hibernate-maven-plugin</connection>
+    <developerConnection>scm:git:ssh://juplo.de:/var/lib/git/juplo/hibernate-maven-plugin</developerConnection>
+    <url>http://juplo.de/gitweb/?p=hibernate-maven-plugin;a=summary</url>
   </scm>
 
   <developers>
   <distributionManagement>
     <site>
       <id>www.juplo.de</id>
-      <url>scp://juplo.de/var/www/juplo/hibernate4-maven-plugin-${project.version}</url>
+      <url>scp://juplo.de/var/www/juplo/hibernate-maven-plugin-${project.version}</url>
     </site>
   </distributionManagement>
 
     <!-- Zeichensatz -->
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <!-- Verwendete Versionen -->
-    <hibernate.version>4.3.9.Final</hibernate.version>
-    <hibernate-validator.version>5.1.3.Final</hibernate-validator.version>
+    <hibernate.version>5.0.2.Final</hibernate.version>
+    <hibernate-validator.version>5.2.2.Final</hibernate-validator.version>
     <el-api.version>3.0.0</el-api.version>
     <maven.version>3.3.3</maven.version>
     <maven-plugin-log4j.version>1.0.1</maven-plugin-log4j.version>
             <goals>
               <goal>jar</goal>
             </goals>
+            <configuration>
+              <additionalparam>-Xdoclint:none</additionalparam>
+            </configuration>
           </execution>
         </executions>
       </plugin>
index 4e179d25da151f1f91b4f4ab2bd5dffcec03bddd..f23648c3143b442c6c5682a9c24bcf0d2944ba9c 100644 (file)
                <plugins>
                        <plugin>
                                <groupId>de.juplo</groupId>
-                               <artifactId>hibernate4-maven-plugin</artifactId>
+                               <artifactId>hibernate-maven-plugin</artifactId>
                                <version>@project.version@</version>
                                <executions>
                                        <execution>
                                                <goals>
-                                                       <goal>export</goal>
+                                                       <goal>create</goal>
                                                </goals>
                                        </execution>
                                </executions>
                                <configuration>
-                                       <target>NONE</target>
+                                       <export>false</export>
                                        <envers>true</envers>
                                        <format>true</format>
                                        <delimiter>;</delimiter>
                                        <force>true</force>
-                                       <type>CREATE</type>
-                                       <hibernateDialect>org.hibernate.dialect.PostgreSQL9Dialect</hibernateDialect>
+                                       <drop>false</drop>
+                                       <dialect>org.hibernate.dialect.PostgreSQL9Dialect</dialect>
                                </configuration>
                        </plugin>
                </plugins>
index 1e05bf6ce60b69031a62981fedd3789ada5c536d..c353210f1d0e6ecc4920fbc269080a3b5e8020cd 100644 (file)
                <plugins>
                        <plugin>
                                <groupId>de.juplo</groupId>
-                               <artifactId>hibernate4-maven-plugin</artifactId>
+                               <artifactId>hibernate-maven-plugin</artifactId>
                                <version>${version}</version>
                                <executions>
                                        <execution>
                                                <goals>
-                                                       <goal>export</goal>
+                                                       <goal>create</goal>
                                                </goals>
                                        </execution>
                                </executions>
                                <configuration>
-                                       <target>NONE</target>
+                                       <export>false</export>
                                        <envers>true</envers>
                                        <format>true</format>
                                        <delimiter>;</delimiter>
                                        <force>true</force>
                                        <type>CREATE</type>
-                                       <hibernateDialect>org.hibernate.dialect.PostgreSQL9Dialect</hibernateDialect>
+                                       <dialect>org.hibernate.dialect.PostgreSQL9Dialect</dialect>
                                </configuration>
                        </plugin>
                </plugins>
index 1fc1d887a379a0a9b61eca4bd10cc7cea8630d42..9376dd730903fcd8d00a37a1bbed601706f50f36 100644 (file)
@@ -1,4 +1,6 @@
 
+    create sequence hibernate_sequence start 1 increment 1;
+
     create table MainEntity (
         id int8 not null,
         str varchar(255),
@@ -21,8 +23,6 @@
     );
 
     alter table MainEntity_AUD 
-        add constraint FK_kpx35pyi0ssiutbfxbf8klu06 
+        add constraint FKdyho0e2yvr52e1nf5rt18k2ec 
         foreign key (REV) 
         references REVINFO;
-
-    create sequence hibernate_sequence;
index 50da4e5198e48999b555c74102915e9e714e9a39..f4fff24a50e7156e6fc15ce2db02581cc196ed87 100644 (file)
@@ -1,6 +1,4 @@
 
-    drop table test_simple if exists;
-
     create table test_simple (
         uuid varchar(36) not null,
         content clob,
index 37ad107455b65f7e608c99c8da4e33241821013e..15df9419fb3bda52eadfe73f24ca23100d35681d 100644 (file)
@@ -1,6 +1,4 @@
 
-    drop table test_simple cascade constraints;
-
     create table test_simple (
         uuid varchar2(36 char) not null,
         content clob,
index fe46e3212f5b4a73f3c809124be6515a4a5a28dd..ba6f6b3f8e967f914825b9557a8e24c43d8c3951 100644 (file)
       <!--  Generate database schema files -->
       <plugin>
         <groupId>de.juplo</groupId>
-        <artifactId>hibernate4-maven-plugin</artifactId>
+        <artifactId>hibernate-maven-plugin</artifactId>
         <version>@project.version@</version>
         <configuration>
-          <!-- Target of none generates schema only, no DB connection -->
-          <target>none</target>
-          <!-- Generate both CREATE and DROP statements in scripts -->
-          <type>both</type>
+          <!-- Generat schema only, no DB connection needed -->
+          <export>false</export>
         </configuration>
         <executions>
           <execution>
             <id>create-h2-ddl</id>
             <goals>
-              <goal>export</goal>
+              <goal>create</goal>
             </goals>
             <configuration>
-              <hibernateDialect>org.hibernate.dialect.H2Dialect</hibernateDialect>
+              <dialect>org.hibernate.dialect.H2Dialect</dialect>
               <outputFile>h2.sql</outputFile>
             </configuration>
           </execution>
           <execution>
             <id>create-postgres-ddl</id>
             <goals>
-              <goal>export</goal>
+              <goal>create</goal>
             </goals>
             <configuration>
-              <hibernateDialect>org.hibernate.dialect.PostgreSQL82Dialect</hibernateDialect>
+              <dialect>org.hibernate.dialect.PostgreSQL82Dialect</dialect>
               <outputFile>postgres.sql</outputFile>
             </configuration>
           </execution>
           <execution>
             <id>create-oracle-ddl</id>
             <goals>
-              <goal>export</goal>
+              <goal>create</goal>
             </goals>
             <configuration>
-              <hibernateDialect>org.hibernate.dialect.Oracle10gDialect</hibernateDialect>
+              <dialect>org.hibernate.dialect.Oracle10gDialect</dialect>
               <outputFile>oracle.sql</outputFile>
             </configuration>
           </execution>
index 43c3d58178cf1273bec921c5287e3823147bea8c..99bdf22fbcd35d08079f7e5d7ecbb4327efc0dba 100644 (file)
@@ -1,6 +1,4 @@
 
-    drop table if exists test_simple cascade;
-
     create table test_simple (
         uuid varchar(36) not null,
         content text,
index cc048a433775754a0fbecf0c136a2173176686d9..792ecc6d7e2cfc9acbfe4a1bca3f73e295b6bb10 100644 (file)
@@ -30,7 +30,7 @@ Usage
 
 __Rebuild the SQL-script using the Hibernate4-maven-plugin to create the database__
 
-    mvn -PcreateHsqlDbScript clean compile hibernate4:export
+    mvn -PcreateHsqlDbScript clean compile hibernate:export
 
 __Build and run the integration tests__
 
index 1897c09ff5eba0305ddf0e7f19328de7486b7f3c..5520ac2c041c086a99a1590be918eeef6a144270 100644 (file)
@@ -16,7 +16,7 @@
     <description>Sample project to test the maven plugin</description>
     <version>1.0-SNAPSHOT</version>
     <packaging>jar</packaging>
-    <url>http://juplo.de/hibernate4-maven-plugin</url>
+    <url>http://juplo.de/hibernate-maven-plugin</url>
 
     <properties>
         <de.juplo-hibernate-plugin-version>@project.version@</de.juplo-hibernate-plugin-version>
             </plugin>
             <plugin>
                 <groupId>de.juplo</groupId>
-                <artifactId>hibernate4-maven-plugin</artifactId>
+                <artifactId>hibernate-maven-plugin</artifactId>
                 <version>${de.juplo-hibernate-plugin-version}</version>
                 <executions>
                     <execution>
                         <id>create-create-script</id>
                         <goals>
-                            <goal>export</goal>
+                            <goal>create</goal>
                         </goals>
                         <configuration>
                             <outputFile>${project.build.directory}/test-classes/sql/create-tables-hsqldb.sql
                             </outputFile>
-                            <type>CREATE</type>
+                            <drop>false</drop>
                         </configuration>
                     </execution>
                     <execution>
                         <id>create-drop-script</id>
                         <goals>
-                            <goal>export</goal>
+                            <goal>create</goal>
                         </goals>
                         <configuration>
                             <outputFile>${project.build.directory}/test-classes/sql/drop-tables-hsqldb.sql
                             </outputFile>
-                            <type>DROP</type>
+                            <drop>true</drop>
                         </configuration>
                     </execution>
                 </executions>
                 <configuration>
-                    <target>SCRIPT</target>
-                    <driverClassName>org.hsqldb.jdbc.JDBCDriver</driverClassName>
-                    <hibernateDialect>org.hibernate.dialect.HSQLDialect</hibernateDialect>
+                    <export>false</export>
+                    <driver>org.hsqldb.jdbc.JDBCDriver</driver>
+                    <dialect>org.hibernate.dialect.HSQLDialect</dialect>
                     <envers>true</envers>
                 </configuration>
                 <dependencies>
index d198fc9ba917a9642d3235db757a111d14b3bd0d..1dab9a54e576f2a084856bc856b2c5f530cb9064 100644 (file)
     <plugins>
       <plugin>
         <groupId>de.juplo</groupId>
-        <artifactId>hibernate4-maven-plugin</artifactId>
+        <artifactId>hibernate-maven-plugin</artifactId>
         <version>@project.version@</version>
         <executions>
           <execution>
             <goals>
-              <goal>export</goal>
+              <goal>create</goal>
             </goals>
           </execution>
         </executions>
         <configuration>
-          <target>NONE</target>
+          <export>false</export>
           <format>true</format>
-          <type>CREATE</type>
-          <hibernateDialect>org.hibernate.dialect.PostgreSQL9Dialect</hibernateDialect>
+          <drop>false</drop>
+          <dialect>org.hibernate.dialect.PostgreSQL9Dialect</dialect>
           <scanDependencies>none</scanDependencies>
         </configuration>
       </plugin>
index 510de4f24bb7899fd373b5dc8df23118bab72dea..d2a1838cfd5f3430a0f918a986bf12828ca5bcbe 100644 (file)
@@ -1,7 +1,7 @@
 
+    create sequence hibernate_sequence start 1 increment 1;
+
     create table MainEntity (
         id int8 not null,
         primary key (id)
     );
-
-    create sequence hibernate_sequence;
index 9569fa60a45bf23d008fe696f30f9680aad91b46..10d07285fd4ded0c9a463b515acbcabf18187edd 100644 (file)
@@ -1,6 +1,4 @@
 
-    drop table test_simple if exists;
-
     create table test_simple (
         uuid varchar(36) not null,
         content clob,
index f3a6fc732c6c54ab42c01da94126606acba76f7d..7a9922e4843487e56c1b37a1af04ed96d1f02fa9 100644 (file)
       <!--  Generate database schema files -->
       <plugin>
         <groupId>de.juplo</groupId>
-        <artifactId>hibernate4-maven-plugin</artifactId>
+        <artifactId>hibernate-maven-plugin</artifactId>
         <version>@project.version@</version>
         <configuration>
-          <!-- Target of none generates schema only, no DB connection -->
-          <target>none</target>
-          <!-- Generate both CREATE and DROP statements in scripts -->
-          <type>both</type>
+          <!-- Gnerate schema only, no DB connection needed -->
+          <export>false</export>
         </configuration>
         <executions>
           <execution>
             <goals>
-              <goal>export</goal>
+              <goal>create</goal>
             </goals>
           </execution>
         </executions>
index bd7142cdb29ce7823dc2dc2a114bef1dead17e4b..5c57479e623784869bd654f9f2e5583e204fd161 100644 (file)
@@ -1,26 +1,21 @@
 
-    alter table Employee 
-        drop constraint FK_12v0w2dqasbw95xtn8qc2uj83;
-
-    drop table ABTEILUNG if exists;
-
-    drop table Employee if exists;
+    create sequence hibernate_sequence start with 1 increment by 1;
 
     create table ABTEILUNG (
-        OID bigint generated by default as identity (start with 1),
+        OID bigint not null,
         gender varchar(255),
         name varchar(255) not null,
         primary key (OID)
     );
 
     create table Employee (
-        OID bigint generated by default as identity (start with 1),
-        name varchar(81) not null,
+        OID bigint not null,
+        name varchar(255) not null,
         FK_department bigint,
         primary key (OID)
     );
 
     alter table Employee 
-        add constraint FK_12v0w2dqasbw95xtn8qc2uj83 
+        add constraint FKps0mm7o60mrhle838yeh1u1rh 
         foreign key (FK_department) 
         references ABTEILUNG;
index e7c74191e28a5f6aebd0e7b6261548e76c7b2e0c..1215a10cfdd8141ec124cccd39c6dbcbff0962ef 100644 (file)
                <plugins>\r
                        <plugin>\r
                                <groupId>de.juplo</groupId>\r
-                               <artifactId>hibernate4-maven-plugin</artifactId>\r
+                               <artifactId>hibernate-maven-plugin</artifactId>\r
                                <version>@project.version@</version>\r
                                <configuration>\r
-                                       <target>SCRIPT</target>\r
-                                       <driverClassName>org.hsqldb.jdbcDriver</driverClassName>\r
-                                       <hibernateDialect>org.hibernate.dialect.HSQLDialect</hibernateDialect>\r
+                                       <driver>org.hsqldb.jdbcDriver</driver>\r
+                                       <dialect>org.hibernate.dialect.HSQLDialect</dialect>\r
                                        <!-- \r
-                                       <driverClassName>com.mysql.jdbc.Driver</driverClassName>\r
-                                       <hibernateDialect>org.hibernate.dialect.MySQLDialect</hibernateDialect>\r
+                                       <driver>com.mysql.jdbc.Driver</driver>\r
+                                       <dialect>org.hibernate.dialect.MySQLDialect</dialect>\r
                                        -->\r
                                </configuration>\r
                                <executions>\r
                                        <execution>\r
                                                <goals>\r
-                                                       <goal>export</goal>\r
+                                                       <goal>create</goal>\r
                                                </goals>\r
                                        </execution>\r
                                </executions>\r
                        </plugin>\r
                </plugins>\r
        </build>\r
-</project>
\ No newline at end of file
+</project>\r
index fc816f656b17b1d280ef7af31df370690189aad6..47c599166d369ce24c83f0cc6f5dcb6df6c690a0 100644 (file)
         <plugins>
             <plugin>
                 <groupId>de.juplo</groupId>
-                <artifactId>hibernate4-maven-plugin</artifactId>
+                <artifactId>hibernate-maven-plugin</artifactId>
                 <version>${h4mp.version}</version>
                 <executions>
                     <execution>
                         <phase>process-test-classes</phase>
                         <goals>
-                            <goal>export</goal>
+                            <goal>create</goal>
                         </goals>
                     </execution>
                 </executions>
index 5a064d442b3cb0969f22cd8ab73fa6b43811df58..6973129118bd2725c8947c8abb4ee38bd0179e14 100644 (file)
         <plugins>
             <plugin>
                 <groupId>de.juplo</groupId>
-                <artifactId>hibernate4-maven-plugin</artifactId>
+                <artifactId>hibernate-maven-plugin</artifactId>
                 <version>${h4mp.version}</version>
                 <executions>
                     <execution>
                         <phase>process-test-classes</phase>
                         <goals>
-                            <goal>export</goal>
+                            <goal>create</goal>
                         </goals>
                     </execution>
                 </executions>
index 5ec5b6914dded407ea04c99789a9d68a91ee5a2a..3531d41b0a79a2a80928fb28c7133f84e3eab289 100644 (file)
         <plugins>
             <plugin>
                 <groupId>de.juplo</groupId>
-                <artifactId>hibernate4-maven-plugin</artifactId>
+                <artifactId>hibernate-maven-plugin</artifactId>
                 <version>${h4mp.version}</version>
                 <executions>
                     <execution>
                         <phase>process-test-classes</phase>
                         <goals>
-                            <goal>export</goal>
+                            <goal>create</goal>
                         </goals>
                     </execution>
                 </executions>
                 <configuration>
                     <scanTestClasses>true</scanTestClasses>
-                    <hibernateDialect>org.hibernate.dialect.H2Dialect</hibernateDialect>
+                    <dialect>org.hibernate.dialect.H2Dialect</dialect>
                 </configuration>
             </plugin>
         </plugins>
index 9980de39ae7779fae9a7663c2be0e4fb57ff9a4a..69eeb5afca97429585943377d231b9c3f2d92650 100644 (file)
         <plugins>
             <plugin>
                 <groupId>de.juplo</groupId>
-                <artifactId>hibernate4-maven-plugin</artifactId>
+                <artifactId>hibernate-maven-plugin</artifactId>
                 <version>${h4mp.version}</version>
                 <executions>
                     <execution>
                         <phase>process-test-classes</phase>
                         <goals>
-                            <goal>export</goal>
+                            <goal>create</goal>
                         </goals>
                     </execution>
                 </executions>
                 <configuration>
                     <scanTestClasses>true</scanTestClasses>
-                    <hibernateDialect>org.hibernate.dialect.H2Dialect</hibernateDialect>
+                    <dialect>org.hibernate.dialect.H2Dialect</dialect>
                 </configuration>
             </plugin>
         </plugins>
old mode 100755 (executable)
new mode 100644 (file)
index 08ef2fe..1aa763c
                        </plugin>
                        <plugin>
                                <groupId>de.juplo</groupId>
-                               <artifactId>hibernate4-maven-plugin</artifactId>
+                               <artifactId>hibernate-maven-plugin</artifactId>
                                <version>${h4mp.version}</version>
                                <executions>
                                        <execution>
                                                <goals>
-                                                       <goal>export</goal>
+                                                       <goal>create</goal>
                                                </goals>
                                        </execution>
                                </executions>
old mode 100755 (executable)
new mode 100644 (file)
index 259540e..24b8463
                        </plugin>
                        <plugin>
                                <groupId>de.juplo</groupId>
-                               <artifactId>hibernate4-maven-plugin</artifactId>
+                               <artifactId>hibernate-maven-plugin</artifactId>
                                <version>${h4mp.version}</version>
                                <executions>
                                        <execution>
                                                <goals>
-                                                       <goal>export</goal>
+                                                       <goal>create</goal>
                                                </goals>
                                        </execution>
                                </executions>
old mode 100755 (executable)
new mode 100644 (file)
index cd33736..b83dea5
                        </plugin>
                        <plugin>
                                <groupId>de.juplo</groupId>
-                               <artifactId>hibernate4-maven-plugin</artifactId>
+                               <artifactId>hibernate-maven-plugin</artifactId>
                                <version>${h4mp.version}</version>
                                <executions>
                                        <execution>
                                                <goals>
-                                                       <goal>export</goal>
+                                                       <goal>create</goal>
                                                </goals>
                                        </execution>
                                </executions>
index 8448e8a2c43b12f8c0dbbb15d9e8133955e5518c..48eb18eff00d5c93301f13db88e8ad9cdbe16ee5 100644 (file)
@@ -1,6 +1,4 @@
 
-    drop table EVENTS if exists;
-
     create table EVENTS (
         id bigint not null,
         EVENT_DATE timestamp,
index 4da1a3c1e280ca3016d8a3445a7750002459ec93..c5e2c0e79636068b1b3faf35e3caa3f571ea8919 100644 (file)
@@ -1,6 +1,4 @@
 
-    drop table EVENTS if exists;
-
     create table EVENTS (
         EVENT_ID bigint not null,
         EVENT_DATE timestamp,
index 8448e8a2c43b12f8c0dbbb15d9e8133955e5518c..48eb18eff00d5c93301f13db88e8ad9cdbe16ee5 100644 (file)
@@ -1,6 +1,4 @@
 
-    drop table EVENTS if exists;
-
     create table EVENTS (
         id bigint not null,
         EVENT_DATE timestamp,
index 44643fa8dc09f43ffc2be62311b187f0a3f5de94..ecec80efc160ef1ab938315d898949770bfcf47d 100644 (file)
@@ -1,10 +1,4 @@
 
-    drop table EVENTS if exists;
-
-    drop table EVENTS_AUD if exists;
-
-    drop table REVINFO if exists;
-
     create table EVENTS (
         id bigint not null,
         EVENT_DATE timestamp,
@@ -28,6 +22,6 @@
     );
 
     alter table EVENTS_AUD 
-        add constraint FK_3hegaqrrpmx0jj0c8qacjtira 
+        add constraint FK5cembm6xahf542q8e4h0pq2t1 
         foreign key (REV) 
         references REVINFO;
index 66738bb5cff0aa791a5a8a38f850c53b144c4e8d..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,8 +0,0 @@
-
-    drop table DataPoint if exists;
-
-    create table DataPoint (
-        id bigint generated by default as identity,
-        name varchar(255),
-        primary key (id)
-    );
index 66738bb5cff0aa791a5a8a38f850c53b144c4e8d..ef982198f800fc2edd385e1f6c1dc5f514a2d16d 100644 (file)
@@ -1,6 +1,4 @@
 
-    drop table DataPoint if exists;
-
     create table DataPoint (
         id bigint generated by default as identity,
         name varchar(255),
index 37165353765dc85b3cb963946a99ad73e1efce2c..9f02ba42df263ccbc3719fb2b94dc111560a65ab 100644 (file)
@@ -1,12 +1,8 @@
 
-    drop table DataPoint if exists;
-
-    drop table DataPoint_AUD if exists;
-
-    drop table REVINFO if exists;
+    create sequence hibernate_sequence start with 1 increment by 1;
 
     create table DataPoint (
-        id bigint generated by default as identity,
+        id bigint not null,
         name varchar(255),
         primary key (id)
     );
@@ -26,6 +22,6 @@
     );
 
     alter table DataPoint_AUD 
-        add constraint FK_7pdslro8w1n74eqwmorrn0hnb 
+        add constraint FK43jw6b5mtbfxur0xhyjxynbea 
         foreign key (REV) 
         references REVINFO;
diff --git a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java
new file mode 100644 (file)
index 0000000..6c8a281
--- /dev/null
@@ -0,0 +1,949 @@
+package de.juplo.plugins.hibernate;
+
+
+import com.pyx4j.log4j.MavenLogAppender;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.NoSuchAlgorithmException;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.persistence.Embeddable;
+import javax.persistence.Entity;
+import javax.persistence.MappedSuperclass;
+import javax.persistence.spi.PersistenceUnitTransactionType;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.hibernate.boot.MetadataBuilder;
+import org.hibernate.boot.MetadataSources;
+import org.hibernate.boot.cfgxml.internal.ConfigLoader;
+import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
+import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
+import org.hibernate.boot.registry.BootstrapServiceRegistry;
+import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
+import org.hibernate.boot.registry.StandardServiceRegistry;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
+import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
+import org.hibernate.boot.registry.selector.spi.StrategySelector;
+import org.hibernate.boot.spi.MetadataImplementor;
+import static org.hibernate.cfg.AvailableSettings.DIALECT;
+import static org.hibernate.cfg.AvailableSettings.DRIVER;
+import static org.hibernate.cfg.AvailableSettings.IMPLICIT_NAMING_STRATEGY;
+import static org.hibernate.cfg.AvailableSettings.PASS;
+import static org.hibernate.cfg.AvailableSettings.PHYSICAL_NAMING_STRATEGY;
+import static org.hibernate.cfg.AvailableSettings.USER;
+import static org.hibernate.cfg.AvailableSettings.URL;
+import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
+import org.hibernate.internal.util.config.ConfigurationException;
+import static org.hibernate.jpa.AvailableSettings.JDBC_DRIVER;
+import static org.hibernate.jpa.AvailableSettings.JDBC_PASSWORD;
+import static org.hibernate.jpa.AvailableSettings.JDBC_URL;
+import static org.hibernate.jpa.AvailableSettings.JDBC_USER;
+import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor;
+import org.hibernate.jpa.boot.internal.PersistenceXmlParser;
+import org.hibernate.jpa.boot.spi.ProviderChecker;
+import org.scannotation.AnnotationDB;
+
+
+/**
+ * Baseclass with common attributes and methods.
+ *
+ * @phase process-classes
+ * @threadSafe
+ * @requiresDependencyResolution runtime
+ */
+public abstract class AbstractSchemaMojo extends AbstractMojo
+{
+  public final static String EXPORT_SKIPPED_PROPERTY = "hibernate.export.skipped";
+
+  private final static Pattern SPLIT = Pattern.compile("[^,\\s]+");
+
+
+  /**
+   * The maven project.
+   * <p>
+   * Only needed internally.
+   *
+   * @parameter property="project"
+   * @required
+   * @readonly
+   */
+  private MavenProject project;
+
+  /**
+   * Build-directory.
+   * <p>
+   * Only needed internally.
+   *
+   * @parameter property="project.build.directory"
+   * @required
+   * @readonly
+   */
+  String buildDirectory;
+
+  /**
+   * Classes-Directory to scan.
+   * <p>
+   * This parameter defaults to the maven build-output-directory for classes.
+   * Additionally, all dependencies are scanned for annotated classes.
+   *
+   * @parameter property="project.build.outputDirectory"
+   * @since 1.0
+   */
+  private String outputDirectory;
+
+  /**
+   * Whether to scan test-classes too, or not.
+   * <p>
+   * If this parameter is set to <code>true</code> the test-classes of the
+   * artifact will be scanned for hibernate-annotated classes additionally.
+   *
+   * @parameter property="hibernate.export.scan_testclasses" default-value="false"
+   * @since 1.0.1
+   */
+  private boolean scanTestClasses;
+
+  /**
+   * Dependency-Scopes, that should be scanned for annotated classes.
+   * <p>
+   * By default, only dependencies in the scope <code>compile</code> are
+   * scanned for annotated classes. Multiple scopes can be seperated by
+   * white space or commas.
+   * <p>md5s
+   * If you do not want any dependencies to be scanned for annotated
+   * classes, set this parameter to <code>none</code>.
+   * <p>
+   * The plugin does not scan for annotated classes in transitive
+   * dependencies. If some of your annotated classes are hidden in a
+   * transitive dependency, you can simply add that dependency explicitly.
+   *
+   * @parameter property="hibernate.export.scan_dependencies" default-value="compile"
+   * @since 1.0.3
+   */
+  private String scanDependencies;
+
+  /**
+   * Test-Classes-Directory to scan.
+   * <p>
+   * This parameter defaults to the maven build-output-directory for
+   * test-classes.
+   * <p>
+   * This parameter is only used, when <code>scanTestClasses</code> is set
+   * to <code>true</code>!
+   *
+   * @parameter property="project.build.testOutputDirectory"
+   * @since 1.0.2
+   */
+  private String testOutputDirectory;
+
+  /**
+   * Skip execution
+   * <p>
+   * If set to <code>true</code>, the execution is skipped.
+   * <p>
+   * A skipped execution is signaled via the maven-property
+   * <code>${hibernate.export.skipped}</code>.
+   * <p>
+   * The execution is skipped automatically, if no modified or newly added
+   * annotated classes are found and the dialect was not changed.
+   *
+   * @parameter property="hibernate.skip" default-value="${maven.test.skip}"
+   * @since 1.0
+   */
+  private boolean skip;
+
+  /**
+   * Force execution
+   * <p>
+   * Force execution, even if no modified or newly added annotated classes
+   * where found and the dialect was not changed.
+   * <p>
+   * <code>skip</code> takes precedence over <code>force</code>.
+   *
+   * @parameter property="hibernate.export.force" default-value="false"
+   * @since 1.0
+   */
+  private boolean force;
+
+  /**
+   * SQL-Driver name.
+   *
+   * @parameter property="hibernate.connection.driver_class"
+   * @since 1.0
+   */
+  private String driver;
+
+  /**
+   * Database URL.
+   *
+   * @parameter property="hibernate.connection.url"
+   * @since 1.0
+   */
+  private String url;
+
+  /**
+   * Database username
+   *
+   * @parameter property="hibernate.connection.username"
+   * @since 1.0
+   */
+  private String username;
+
+  /**
+   * Database password
+   *
+   * @parameter property="hibernate.connection.password"
+   * @since 1.0
+   */
+  private String password;
+
+  /**
+   * Hibernate dialect.
+   *
+   * @parameter property="hibernate.dialect"
+   * @since 1.0
+   */
+  private String dialect;
+
+  /**
+   * Implicit naming strategy
+   *
+   * @parameter property=IMPLICIT_NAMING_STRATEGY
+   * @since 2.0
+   */
+  private String implicitNamingStrategy;
+
+  /**
+   * Physical naming strategy
+   *
+   * @parameter property=PHYSICAL_NAMING_STRATEGY
+   * @since 2.0
+   */
+  private String physicalNamingStrategy;
+
+  /**
+   * Path to a file or name of a ressource with hibernate properties.
+   * If this parameter is specified, the plugin will try to load configuration
+   * values from a file with the given path or a ressource on the classpath with
+   * the given name. If both fails, the execution of the plugin will fail.
+   * <p>
+   * If this parameter is not set the plugin will load configuration values
+   * from a ressource named <code>hibernate.properties</code> on the classpath,
+   * if it is present, but will not fail if there is no such ressource.
+   * <p>
+   * During ressource-lookup, the test-classpath takes precedence.
+   *
+   * @parameter
+   * @since 1.0
+   */
+  private String hibernateProperties;
+
+  /**
+   * Path to Hibernate configuration file (.cfg.xml).
+   * If this parameter is specified, the plugin will try to load configuration
+   * values from a file with the given path or a ressource on the classpath with
+   * the given name. If both fails, the execution of the plugin will fail.
+   * <p>
+   * If this parameter is not set the plugin will load configuration values
+   * from a ressource named <code>hibernate.cfg.xml</code> on the classpath,
+   * if it is present, but will not fail if there is no such ressource.
+   * <p>
+   * During ressource-lookup, the test-classpath takes precedence.
+   * <p>
+   * Settings in this file will overwrite settings in the properties file.
+   *
+   * @parameter
+   * @since 1.1.0
+   */
+  private String hibernateConfig;
+
+  /**
+   * Name of the persistence-unit.
+   * If this parameter is specified, the plugin will try to load configuration
+   * values from a persistence-unit with the specified name. If no such
+   * persistence-unit can be found, the plugin will throw an exception.
+   * <p>
+   * If this parameter is not set and there is only one persistence-unit
+   * available, that unit will be used automatically. But if this parameter is
+   * not set and there are multiple persistence-units available on,
+   * the class-path, the execution of the plugin will fail.
+   * <p>
+   * Settings in this file will overwrite settings in the properties or the
+   * configuration file.
+   *
+   * @parameter
+   * @since 1.1.0
+   */
+  private String persistenceUnit;
+
+  /**
+   * List of Hibernate-Mapping-Files (XML).
+   * Multiple files can be separated with white-spaces and/or commas.
+   *
+   * @parameter property="hibernate.mapping"
+   * @since 1.0.2
+   */
+  private String mappings;
+
+
+  @Override
+  public final void execute()
+    throws
+      MojoFailureException,
+      MojoExecutionException
+  {
+    if (skip)
+    {
+      getLog().info("Execution of hibernate-maven-plugin was skipped!");
+      project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
+      return;
+    }
+
+    ModificationTracker tracker;
+    try
+    {
+      tracker = new ModificationTracker(buildDirectory, getLog());
+    }
+    catch (NoSuchAlgorithmException e)
+    {
+      throw new MojoFailureException("Digest-Algorithm MD5 is missing!", e);
+    }
+
+    SimpleConnectionProvider connectionProvider =
+        new SimpleConnectionProvider(getLog());
+
+    try
+    {
+      /** Start extended logging */
+      MavenLogAppender.startPluginLog(this);
+
+      /** Load checksums for old mapping and configuration */
+      tracker.load();
+
+      /** Create a BootstrapServiceRegistry with special ClassLoader */
+      BootstrapServiceRegistry bootstrapServiceRegitry =
+          new BootstrapServiceRegistryBuilder()
+              .applyClassLoader(createClassLoader())
+              .build();
+      ClassLoaderService classLoaderService =
+          bootstrapServiceRegitry.getService(ClassLoaderService.class);
+
+      Properties properties = new Properties();
+      ConfigLoader configLoader = new ConfigLoader(bootstrapServiceRegitry);
+
+      /** Loading and merging configuration */
+      properties.putAll(loadProperties(configLoader));
+      properties.putAll(loadConfig(configLoader));
+      properties.putAll(loadPersistenceUnit(classLoaderService, properties));
+
+      /** Overwriting/Completing configuration */
+      configure(properties);
+
+      /** Check configuration for modifications */
+      if(tracker.check(properties))
+        getLog().debug("Configuration has changed.");
+      else
+        getLog().debug("Configuration unchanged.");
+
+      /** Configure Hibernate */
+      StandardServiceRegistry serviceRegistry =
+          new StandardServiceRegistryBuilder(bootstrapServiceRegitry)
+              .applySettings(properties)
+              .addService(ConnectionProvider.class, connectionProvider)
+              .build();
+
+      /** Load Mappings */
+      MetadataSources sources = new MetadataSources(serviceRegistry);
+      addAnnotatedClasses(sources, classLoaderService, tracker);
+      addMappings(sources, tracker);
+
+      /** Skip execution, if mapping and configuration is unchanged */
+      if (!tracker.modified())
+      {
+        getLog().info(
+            "Mapping and configuration unchanged."
+            );
+        if (force)
+          getLog().info("Schema generation is forced!");
+        else
+        {
+          getLog().info("Skipping schema generation!");
+          project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
+          return;
+        }
+      }
+
+
+      /** Create a connection, if sufficient configuration infromation is available */
+      connectionProvider.open(classLoaderService, properties);
+
+      MetadataBuilder metadataBuilder = sources.getMetadataBuilder();
+
+      StrategySelector strategySelector =
+          serviceRegistry.getService(StrategySelector.class);
+
+      if (properties.containsKey(IMPLICIT_NAMING_STRATEGY))
+      {
+        metadataBuilder.applyImplicitNamingStrategy(
+            strategySelector.resolveStrategy(
+                ImplicitNamingStrategy.class,
+                properties.getProperty(IMPLICIT_NAMING_STRATEGY)
+                )
+            );
+      }
+
+      if (properties.containsKey(PHYSICAL_NAMING_STRATEGY))
+      {
+        metadataBuilder.applyPhysicalNamingStrategy(
+            strategySelector.resolveStrategy(
+                PhysicalNamingStrategy.class,
+                properties.getProperty(PHYSICAL_NAMING_STRATEGY)
+                )
+            );
+      }
+
+      build((MetadataImplementor)metadataBuilder.build());
+    }
+    finally
+    {
+      /** Remember mappings and configuration */
+      tracker.save();
+
+      /** Close the connection - if one was opened */
+      connectionProvider.close();
+
+      /** Stop Log-Capturing */
+      MavenLogAppender.endPluginLog(this);
+    }
+  }
+
+
+  abstract void build(MetadataImplementor metadata)
+    throws
+      MojoFailureException,
+      MojoExecutionException;
+
+
+  private URLClassLoader createClassLoader() throws MojoExecutionException
+  {
+    try
+    {
+      getLog().debug("Creating ClassLoader for project-dependencies...");
+      List<String> classpathFiles = project.getCompileClasspathElements();
+      if (scanTestClasses)
+        classpathFiles.addAll(project.getTestClasspathElements());
+      List<URL> urls = new LinkedList<URL>();
+      File file;
+      file = new File(testOutputDirectory);
+      if (!file.exists())
+      {
+        getLog().info("creating test-output-directory: " + testOutputDirectory);
+        file.mkdirs();
+      }
+      urls.add(file.toURI().toURL());
+      file = new File(outputDirectory);
+      if (!file.exists())
+      {
+        getLog().info("creating output-directory: " + outputDirectory);
+        file.mkdirs();
+      }
+      urls.add(file.toURI().toURL());
+      for (String pathElement : classpathFiles)
+      {
+        getLog().debug("Dependency: " + pathElement);
+        urls.add(new File(pathElement).toURI().toURL());
+      }
+      return
+          new URLClassLoader(
+              urls.toArray(new URL[urls.size()]),
+              getClass().getClassLoader()
+              );
+    }
+    catch (Exception e)
+    {
+      getLog().error("Error while creating ClassLoader!", e);
+      throw new MojoExecutionException(e.getMessage());
+    }
+  }
+
+  private Map loadProperties(ConfigLoader configLoader)
+      throws
+        MojoExecutionException
+  {
+    /** Try to read configuration from properties-file */
+    if (hibernateProperties == null)
+    {
+      try
+      {
+        return configLoader.loadProperties("hibernate.properties");
+      }
+      catch (ConfigurationException e)
+      {
+        getLog().debug(e.getMessage());
+        return Collections.EMPTY_MAP;
+      }
+    }
+    else
+    {
+      try
+      {
+        File file = new File(hibernateProperties);
+        if (file.exists())
+        {
+          getLog().info("Reading settings from file " + hibernateProperties + "...");
+          return configLoader.loadProperties(file);
+        }
+        else
+          return configLoader.loadProperties(hibernateProperties);
+      }
+      catch (ConfigurationException e)
+      {
+        getLog().error("Error while reading properties!", e);
+        throw new MojoExecutionException(e.getMessage());
+      }
+    }
+  }
+
+  private Map loadConfig(ConfigLoader configLoader)
+      throws MojoExecutionException
+  {
+    /** Try to read configuration from configuration-file */
+    if (hibernateConfig == null)
+    {
+      try
+      {
+        return
+            configLoader
+                .loadConfigXmlResource("hibernate.cfg.xml")
+                .getConfigurationValues();
+      }
+      catch (ConfigurationException e)
+      {
+        getLog().debug(e.getMessage());
+        return Collections.EMPTY_MAP;
+      }
+    }
+    else
+    {
+      try
+      {
+        File file = new File(hibernateConfig);
+        if (file.exists())
+        {
+          getLog().info("Reading configuration from file " + hibernateConfig + "...");
+          return configLoader.loadConfigXmlFile(file).getConfigurationValues();
+        }
+        else
+          return
+              configLoader
+                  .loadConfigXmlResource(hibernateConfig)
+                  .getConfigurationValues();
+      }
+      catch (ConfigurationException e)
+      {
+        getLog().error("Error while reading configuration!", e);
+        throw new MojoExecutionException(e.getMessage());
+      }
+    }
+  }
+
+  private void configure(Properties properties)
+      throws MojoFailureException
+  {
+    /** Overwrite values from properties-file or set, if given */
+
+    if (driver != null)
+    {
+      if (properties.containsKey(DRIVER))
+        getLog().debug("Overwriting property " +
+            DRIVER + "=" + properties.getProperty(DRIVER) +
+            " with the value " + driver
+          );
+      else
+        getLog().debug("Using the value " + driver);
+      properties.setProperty(DRIVER, driver);
+    }
+    if (properties.getProperty(DRIVER) == null)
+    {
+      String driver = properties.getProperty(JDBC_DRIVER);
+      if (driver != null)
+      {
+        getLog().info(DRIVER +
+            " is not set. Borrow setting from " +
+            JDBC_DRIVER +
+            ": " +
+            driver);
+        properties.setProperty(DRIVER, driver);
+      }
+    }
+
+    if (url != null)
+    {
+      if (properties.containsKey(URL))
+        getLog().debug(
+            "Overwriting property " +
+            URL + "=" + properties.getProperty(URL) +
+            " with the value " + url
+          );
+      else
+        getLog().debug("Using the value " + url);
+      properties.setProperty(URL, url);
+    }
+    if (properties.getProperty(URL) == null)
+    {
+      String url = properties.getProperty(JDBC_URL);
+      if (url != null)
+      {
+        getLog().info(URL +
+            " is not set. Borrow setting from " +
+            JDBC_URL +
+            ": " +
+            url);
+        properties.setProperty(URL, url);
+      }
+    }
+
+    if (username != null)
+    {
+      if (properties.containsKey(USER))
+        getLog().debug("Overwriting property " +
+            USER + "=" + properties.getProperty(USER) +
+            " with the value " + username
+          );
+      else
+        getLog().debug("Using the value " + username);
+      properties.setProperty(USER, username);
+    }
+    if (properties.getProperty(USER) == null)
+    {
+      username = properties.getProperty(JDBC_USER);
+      if (username != null)
+      {
+        getLog().info(USER +
+            " is not set. Borrow setting from " +
+            JDBC_USER +
+            ": " +
+            username);
+        properties.setProperty(USER, username);
+      }
+    }
+
+    if (password != null)
+    {
+      if (properties.containsKey(PASS))
+        getLog().debug("Overwriting property " +
+            PASS + "=" + properties.getProperty(PASS) +
+            " with value " + password
+          );
+      else
+        getLog().debug("Using value " + password + " for property " + PASS);
+      properties.setProperty(PASS, password);
+    }
+    if (properties.getProperty(PASS) == null)
+    {
+      password = properties.getProperty(JDBC_PASSWORD);
+      if (password != null)
+      {
+        getLog().info(PASS +
+            " is not set. Borrow setting from " +
+            JDBC_PASSWORD +
+            ": " +
+            password);
+        properties.setProperty(PASS, password);
+      }
+    }
+
+    if (dialect != null)
+    {
+      if (properties.containsKey(DIALECT))
+        getLog().debug(
+            "Overwriting property " +
+            DIALECT + "=" + properties.getProperty(DIALECT) +
+            " with value " + dialect
+          );
+      else
+        getLog().debug(
+            "Using value " + dialect + " for property " + DIALECT
+            );
+      properties.setProperty(DIALECT, dialect);
+    }
+
+    if (implicitNamingStrategy != null )
+    {
+      if ( properties.contains(IMPLICIT_NAMING_STRATEGY))
+        getLog().debug(
+            "Overwriting property " +
+            IMPLICIT_NAMING_STRATEGY + "=" + properties.getProperty(IMPLICIT_NAMING_STRATEGY) +
+            " with value " + implicitNamingStrategy
+           );
+      else
+        getLog().debug(
+            "Using value " + implicitNamingStrategy + " for property " +
+            IMPLICIT_NAMING_STRATEGY +
+            "Using value " + dialect + " for property " + DIALECT
+            );
+      properties.setProperty(IMPLICIT_NAMING_STRATEGY, implicitNamingStrategy);
+    }
+
+    if (physicalNamingStrategy != null )
+    {
+      if ( properties.contains(PHYSICAL_NAMING_STRATEGY))
+        getLog().debug(
+            "Overwriting property " +
+            PHYSICAL_NAMING_STRATEGY + "=" + properties.getProperty(PHYSICAL_NAMING_STRATEGY) +
+            " with value " + physicalNamingStrategy
+           );
+      else
+        getLog().debug(
+            "Using value " + physicalNamingStrategy + " for property " +
+            PHYSICAL_NAMING_STRATEGY +
+            "Using value " + dialect + " for property " + DIALECT
+            );
+      properties.setProperty(PHYSICAL_NAMING_STRATEGY, physicalNamingStrategy);
+    }
+
+    if (properties.isEmpty())
+    {
+      getLog().error("No properties set!");
+      throw new MojoFailureException("Hibernate configuration is missing!");
+    }
+
+    getLog().info("Gathered hibernate-configuration (turn on debugging for details):");
+    for (Entry<Object,Object> entry : properties.entrySet())
+      getLog().info("  " + entry.getKey() + " = " + entry.getValue());
+  }
+
+  private void addMappings(MetadataSources sources, ModificationTracker tracker)
+      throws MojoFailureException
+  {
+    getLog().debug("Adding explicitly configured mappings...");
+    if (mappings != null)
+    {
+      try
+      {
+        for (String filename : mappings.split("[\\s,]+"))
+        {
+          // First try the filename as absolute/relative path
+          File file = new File(filename);
+          if (!file.exists())
+          {
+            // If the file was not found, search for it in the resource-directories
+            for (Resource resource : project.getResources())
+            {
+              file = new File(resource.getDirectory() + File.separator + filename);
+              if (file.exists())
+                break;
+            }
+          }
+          if (file.exists())
+          {
+            if (file.isDirectory())
+              // TODO: add support to read all mappings under a directory
+              throw new MojoFailureException(file.getAbsolutePath() + " is a directory");
+            if (tracker.check(filename, new FileInputStream(file)))
+              getLog().debug("Found new or modified mapping-file: " + filename);
+            else
+              getLog().debug("mapping-file unchanged: " + filename);
+
+            sources.addFile(file);
+          }
+          else
+            throw new MojoFailureException("File " + filename + " could not be found in any of the configured resource-directories!");
+        }
+      }
+      catch (IOException e)
+      {
+        throw new MojoFailureException("Cannot calculate MD5 sums!", e);
+      }
+    }
+  }
+
+  private void addAnnotatedClasses(
+      MetadataSources sources,
+      ClassLoaderService classLoaderService,
+      ModificationTracker tracker
+      )
+      throws
+        MojoFailureException,
+        MojoExecutionException
+
+  {
+    try
+    {
+      AnnotationDB db = new AnnotationDB();
+      File dir;
+
+      dir = new File(outputDirectory);
+      if (dir.exists())
+      {
+        getLog().info("Scanning directory " + dir.getAbsolutePath() + " for annotated classes...");
+        URL dirUrl = dir.toURI().toURL();
+        db.scanArchives(dirUrl);
+      }
+
+      if (scanTestClasses)
+      {
+        dir = new File(testOutputDirectory);
+        if (dir.exists())
+        {
+          getLog().info("Scanning directory " + dir.getAbsolutePath() + " for annotated classes...");
+          URL dirUrl = dir.toURI().toURL();
+          db.scanArchives(dirUrl);
+        }
+      }
+
+      if (scanDependencies != null)
+      {
+        Matcher matcher = SPLIT.matcher(scanDependencies);
+        while (matcher.find())
+        {
+          getLog().info("Scanning dependencies for scope " + matcher.group());
+          for (Artifact artifact : project.getDependencyArtifacts())
+          {
+            if (!artifact.getScope().equalsIgnoreCase(matcher.group()))
+              continue;
+            if (artifact.getFile() == null)
+            {
+              getLog().warn("Cannot scan dependency " + artifact.getId() + ": no JAR-file available!");
+              continue;
+            }
+            getLog().info("Scanning dependency " + artifact.getId() + " for annotated classes...");
+            db.scanArchives(artifact.getFile().toURI().toURL());
+          }
+        }
+      }
+
+      Set<String> classes = new HashSet<String>();
+      if (db.getAnnotationIndex().containsKey(Entity.class.getName()))
+        classes.addAll(db.getAnnotationIndex().get(Entity.class.getName()));
+      if (db.getAnnotationIndex().containsKey(MappedSuperclass.class.getName()))
+        classes.addAll(db.getAnnotationIndex().get(MappedSuperclass.class.getName()));
+      if (db.getAnnotationIndex().containsKey(Embeddable.class.getName()))
+        classes.addAll(db.getAnnotationIndex().get(Embeddable.class.getName()));
+
+      Set<String> packages = new HashSet<String>();
+
+      for (String name : classes)
+      {
+        Class<?> annotatedClass = classLoaderService.classForName(name);
+        String packageName = annotatedClass.getPackage().getName();
+        if (!packages.contains(packageName))
+        {
+          InputStream is =
+              annotatedClass.getResourceAsStream("package-info.class");
+          if (is == null)
+          {
+            // No compiled package-info available: no package-level annotations!
+            getLog().debug("Package " + packageName + " is not annotated.");
+          }
+          else
+          {
+            if (tracker.check(packageName, is))
+              getLog().debug("New or modified package: " + packageName);
+            else
+              getLog().debug("Unchanged package: " + packageName);
+            getLog().info("Adding annotated package " + packageName);
+            sources.addPackage(packageName);
+          }
+          packages.add(packageName);
+        }
+        String resourceName = annotatedClass.getName();
+        resourceName =
+            resourceName.substring(
+                resourceName.lastIndexOf(".") + 1,
+                resourceName.length()
+                ) + ".class";
+        InputStream is =
+            annotatedClass
+                .getResourceAsStream(resourceName);
+        if (tracker.check(name, is))
+          getLog().debug("New or modified class: " + name);
+        else
+          getLog().debug("Unchanged class: " + name);
+        getLog().info("Adding annotated class " + annotatedClass);
+        sources.addAnnotatedClass(annotatedClass);
+      }
+    }
+    catch (Exception e)
+    {
+      getLog().error("Error while scanning!", e);
+      throw new MojoFailureException(e.getMessage());
+    }
+  }
+
+  private Properties loadPersistenceUnit(
+      ClassLoaderService classLoaderService,
+      Properties properties
+      )
+      throws
+        MojoFailureException
+  {
+    PersistenceXmlParser parser =
+        new PersistenceXmlParser(
+            classLoaderService,
+            PersistenceUnitTransactionType.RESOURCE_LOCAL
+             );
+
+    List<ParsedPersistenceXmlDescriptor> units = parser.doResolve(properties);
+
+    if (persistenceUnit == null)
+    {
+      switch (units.size())
+      {
+        case 0:
+          getLog().info("Found no META-INF/persistence.xml.");
+          return new Properties();
+        case 1:
+          getLog().info("Using persistence-unit " + units.get(0).getName());
+          return units.get(0).getProperties();
+        default:
+          StringBuilder builder = new StringBuilder();
+          builder.append("No name provided and multiple persistence units found: ");
+          Iterator<ParsedPersistenceXmlDescriptor> it = units.iterator();
+          builder.append(it.next().getName());
+          while (it.hasNext())
+          {
+            builder.append(", ");
+            builder.append(it.next().getName());
+          }
+          builder.append('.');
+          throw new MojoFailureException(builder.toString());
+      }
+    }
+
+    for (ParsedPersistenceXmlDescriptor unit : units)
+    {
+      getLog().debug("Found persistence-unit " + unit.getName());
+      if (!unit.getName().equals(persistenceUnit))
+        continue;
+
+      // See if we (Hibernate) are the persistence provider
+      if (!ProviderChecker.isProvider(unit, properties))
+      {
+        getLog().debug("Wrong provider: " + unit.getProviderClassName());
+        continue;
+      }
+
+      getLog().info("Using persistence-unit " + unit.getName());
+      return unit.getProperties();
+    }
+
+    throw new MojoFailureException("Could not find persistence-unit " + persistenceUnit);
+  }
+}
diff --git a/src/main/java/de/juplo/plugins/hibernate/CreateMojo.java b/src/main/java/de/juplo/plugins/hibernate/CreateMojo.java
new file mode 100644 (file)
index 0000000..19078ea
--- /dev/null
@@ -0,0 +1,122 @@
+package de.juplo.plugins.hibernate;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.hibernate.boot.spi.MetadataImplementor;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+
+
+/**
+ * Goal which extracts the hibernate-mapping-configuration and
+ * exports an according SQL-database-schema.
+ *
+ * @goal create
+ * @phase process-classes
+ * @threadSafe
+ * @requiresDependencyResolution runtime
+ */
+public class CreateMojo extends AbstractSchemaMojo
+{
+  /**
+   * Export the database-schma to the database.
+   * If set to <code>false</code>, only the SQL-script is created and the
+   * database is not touched.
+   *
+   * @parameter property="hibernate.export.export" default-value="true"
+   * @since 2.0
+   */
+  private boolean export;
+
+  /**
+   * Create the catalog
+   * If set to <code>false</code>, only the SQL-script is created and the
+   * database is not touched.
+   *
+   * @parameter property=org.hibernate.cfg.AvailableSettings.HBM2DDL_IMPORT_FILES_SQL_EXTRACTOR default-value="false"
+   * @since 2.0
+   */
+  private boolean createNamespaces; // TODO handle in configure-Method
+
+  /**
+   * Output file.
+   *
+   * @parameter property="hibernate.export.schema.filename" default-value="${project.build.directory}/schema.sql"
+   * @since 1.0
+   */
+  private String outputFile;
+
+  /**
+   * Delimiter in output-file.
+   *
+   * @parameter property="hibernate.export.schema.delimiter" default-value=";"
+   * @since 1.0
+   */
+  private String delimiter;
+
+  /**
+   * Format output-file.
+   *
+   * @parameter property="hibernate.export.schema.format" default-value="true"
+   * @since 1.0
+   */
+  private boolean format;
+
+
+  @Override
+  void build(MetadataImplementor metadata)
+      throws
+        MojoExecutionException,
+        MojoFailureException
+  {
+    SchemaExport schemaExport = new SchemaExport(metadata, createNamespaces);
+    schemaExport.setDelimiter(delimiter);
+    schemaExport.setFormat(format);
+
+    File output = new File(outputFile);
+
+    if (!output.isAbsolute())
+    {
+      // Interpret relative file path relative to build directory
+      output = new File(buildDirectory, outputFile);
+      getLog().debug("Adjusted relative path, resulting path is " + output.getPath());
+    }
+
+    // Ensure that directory path for specified file exists
+    File outFileParentDir = output.getParentFile();
+    if (null != outFileParentDir && !outFileParentDir.exists())
+    {
+      try
+      {
+        getLog().info("Creating directory path for output file:" + outFileParentDir.getPath());
+        outFileParentDir.mkdirs();
+      }
+      catch (Exception e)
+      {
+        getLog().error("Error creating directory path for output file: " + e.getLocalizedMessage());
+      }
+    }
+
+    schemaExport.setOutputFile(output.getPath());
+    schemaExport.execute(false, this.export, false, true);
+
+    for (Object exception : schemaExport.getExceptions())
+      getLog().error(exception.toString());
+  }
+}
diff --git a/src/main/java/de/juplo/plugins/hibernate/ModificationTracker.java b/src/main/java/de/juplo/plugins/hibernate/ModificationTracker.java
new file mode 100644 (file)
index 0000000..e03f78e
--- /dev/null
@@ -0,0 +1,171 @@
+package de.juplo.plugins.hibernate;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import org.apache.maven.plugin.logging.Log;
+
+
+
+/**
+ *
+ * @author Kai Moritz
+ */
+public class ModificationTracker
+{
+  public final static String MD5S = "hibernate-generatedschema.md5s";
+
+  private Map<String,String> properties;
+  private Map<String,String> classes;
+
+  private final Set<String> propertyNames;
+  private final Set<String> classNames;
+
+  private boolean modified = false;
+
+  private final File saved;
+  private final MessageDigest digest;
+  private final Log log;
+
+
+  ModificationTracker(String buildDirectory, Log log)
+      throws
+        NoSuchAlgorithmException
+  {
+    propertyNames = new HashSet<String>();
+    classNames = new HashSet<String>();
+    saved = new File(buildDirectory + File.separator + MD5S);
+    digest = java.security.MessageDigest.getInstance("MD5");
+    this.log = log;
+  }
+
+
+  private String calculate(InputStream is)
+      throws
+        IOException
+  {
+    byte[] buffer = new byte[1024*4]; // copy data in 4MB-chunks
+    int i;
+    while((i = is.read(buffer)) > -1)
+      digest.update(buffer, 0, i);
+    is.close();
+    byte[] bytes = digest.digest();
+    BigInteger bi = new BigInteger(1, bytes);
+    return String.format("%0" + (bytes.length << 1) + "x", bi);
+  }
+
+  private boolean check(Map<String,String> values, String name, String value)
+  {
+    if (!values.containsKey(name) || !values.get(name).equals(value))
+    {
+      values.put(name, value);
+      return true;
+    }
+    else
+      return false;
+  }
+
+
+  boolean check(String name, InputStream is) throws IOException
+  {
+    boolean result = check(classes, name, calculate(is));
+    classNames.add(name);
+    modified |= result;
+    return result;
+  }
+
+  boolean check(String name, String property)
+  {
+    boolean result = check(properties, name, property);
+    propertyNames.add(name);
+    modified |= result;
+    return result;
+  }
+
+  boolean check(Properties properties)
+  {
+    boolean result = false;
+    for (String name : properties.stringPropertyNames())
+      result |= check(name, properties.getProperty(name));
+    return result;
+  }
+
+
+  boolean modified()
+  {
+    modified |= !propertyNames.containsAll(properties.keySet());
+    modified |= !properties.keySet().containsAll(propertyNames);
+    modified |= !classNames.containsAll(classes.keySet());
+    modified |= !classes.keySet().containsAll(classNames);
+    return modified;
+  }
+
+
+  void load()
+  {
+    if (saved.isFile() && saved.length() > 0)
+    {
+      try
+      {
+        FileInputStream fis = new FileInputStream(saved);
+        ObjectInputStream ois = new ObjectInputStream(fis);
+        properties = (HashMap<String,String>)ois.readObject();
+        classes = (HashMap<String,String>)ois.readObject();
+        ois.close();
+      }
+      catch (Exception e)
+      {
+        properties = new HashMap<String,String>();
+        classes = new HashMap<String,String>();
+        log.warn("Cannot read md5s from saved: " + e);
+      }
+    }
+    else
+    {
+      properties = new HashMap<String,String>();
+      classes = new HashMap<String,String>();
+      try
+      {
+        saved.createNewFile();
+      }
+      catch (IOException e)
+      {
+        log.debug("Cannot create file \"" + saved.getPath() + "\" for md5s: " + e);
+      }
+    }
+  }
+
+  void save()
+  {
+    if (!modified)
+      return;
+
+    /** Write md5-sums for annotated classes to file */
+    try
+    {
+      FileOutputStream fos = new FileOutputStream(saved);
+      ObjectOutputStream oos = new ObjectOutputStream(fos);
+      oos.writeObject(properties);
+      oos.writeObject(classes);
+      oos.close();
+      fos.close();
+    }
+    catch (Exception e)
+    {
+      log.error("Cannot write md5-sums to file: " + e);
+    }
+  }  
+}
diff --git a/src/main/java/de/juplo/plugins/hibernate/SimpleConnectionProvider.java b/src/main/java/de/juplo/plugins/hibernate/SimpleConnectionProvider.java
new file mode 100644 (file)
index 0000000..36fe561
--- /dev/null
@@ -0,0 +1,249 @@
+package de.juplo.plugins.hibernate;
+
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Properties;
+import java.util.logging.Logger;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import static org.eclipse.aether.repository.AuthenticationContext.PASSWORD;
+import static org.eclipse.aether.repository.AuthenticationContext.USERNAME;
+import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
+import static org.hibernate.cfg.AvailableSettings.DRIVER;
+import static org.hibernate.cfg.AvailableSettings.PASS;
+import static org.hibernate.cfg.AvailableSettings.URL;
+import static org.hibernate.cfg.AvailableSettings.USER;
+import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
+import static org.hibernate.jpa.AvailableSettings.JDBC_DRIVER;
+import static org.hibernate.jpa.AvailableSettings.JDBC_PASSWORD;
+import static org.hibernate.jpa.AvailableSettings.JDBC_URL;
+import static org.hibernate.jpa.AvailableSettings.JDBC_USER;
+
+/**
+ *
+ * @author Kai Moritz
+ */
+class SimpleConnectionProvider implements ConnectionProvider
+{
+  private final Log log;
+
+  private Connection connection;
+
+
+  SimpleConnectionProvider(Log log)
+  {
+    this.log = log;
+  }
+
+
+  void open(ClassLoaderService classLoaderService, Properties properties)
+      throws
+        MojoFailureException
+  {
+
+    String driver = (String)
+        (properties.containsKey(DRIVER)
+            ? properties.getProperty(DRIVER)
+            : properties.getProperty(JDBC_DRIVER)
+            );
+    String url = (String)
+        (properties.containsKey(URL)
+            ? properties.getProperty(URL)
+            : properties.getProperty(JDBC_URL)
+            );
+    String user = (String)
+        (properties.containsKey(USER)
+            ? properties.getProperty(USER)
+            : properties.getProperty(JDBC_USER)
+            );
+    String password = (String)
+        (properties.containsKey(PASS)
+            ? properties.getProperty(PASS)
+            : properties.getProperty(JDBC_PASSWORD)
+            );
+
+    if (driver == null || url == null || user == null)
+    {
+      log.info("No connection opened, because connection information is incomplete");
+      log.info("Driver-Class: " + driver);
+      log.info("URL: " + url);
+      log.info("User: " + user);
+      return;
+    }
+
+    try
+    {
+      Class driverClass = classLoaderService.classForName(driver);
+
+      log.debug("Registering JDBC-driver " + driverClass.getName());
+      DriverManager
+          .registerDriver(new DriverProxy((Driver) driverClass.newInstance()));
+
+      log.debug(
+          "Opening JDBC-connection to " + properties.getProperty(URL) +
+          " as " + properties.getProperty(USERNAME) +
+          " with password " + properties.getProperty(PASSWORD)
+          );
+    
+      connection = DriverManager.getConnection(url, user, password);
+    }
+    catch (Exception e)
+    {
+      throw new MojoFailureException("Could not open the JDBC-connection", e);
+    }
+  }
+
+  void close()
+  {
+    if (connection == null)
+      return;
+
+    log.debug("Closing the JDBC-connection.");
+    try
+    {
+      connection.close();
+    }
+    catch (SQLException e)
+    {
+      log.error("Error while closing the JDBC-connection: " + e.getMessage());
+    }
+  }
+
+  @Override
+  public Connection getConnection() throws SQLException
+  {
+    log.debug("Connection aquired.");
+
+    if (connection == null)
+      throw new SQLException("No connection available, because of insufficient connection information!");
+
+    return connection;
+  }
+
+  @Override
+  public void closeConnection(Connection conn) throws SQLException
+  {
+    log.debug("Connection released");
+  }
+
+  @Override
+  public boolean supportsAggressiveRelease()
+  {
+    return false;
+  }
+
+  @Override
+  public boolean isUnwrappableAs(Class unwrapType)
+  {
+    return false;
+  }
+
+  @Override
+  public <T> T unwrap(Class<T> unwrapType)
+  {
+    throw new UnsupportedOperationException("Not supported.");
+  }
+
+  /**
+   * Needed, because DriverManager won't pick up drivers, that were not
+   * loaded by the system-classloader!
+   * See:
+   * http://stackoverflow.com/questions/288828/how-to-use-a-jdbc-driver-fromodifiedm-an-arbitrary-location
+   */
+  static final class DriverProxy implements Driver
+  {
+    private final Driver target;
+
+    DriverProxy(Driver target)
+    {
+      if (target == null)
+        throw new NullPointerException();
+      this.target = target;
+    }
+
+    public java.sql.Driver getTarget()
+    {
+      return target;
+    }
+
+    @Override
+    public boolean acceptsURL(String url) throws SQLException
+    {
+      return target.acceptsURL(url);
+    }
+
+    @Override
+    public java.sql.Connection connect(
+        String url,
+        java.util.Properties info
+      )
+      throws
+        SQLException
+    {
+      return target.connect(url, info);
+    }
+
+    @Override
+    public int getMajorVersion()
+    {
+      return target.getMajorVersion();
+    }
+
+    @Override
+    public int getMinorVersion()
+    {
+      return target.getMinorVersion();
+    }
+
+    @Override
+    public DriverPropertyInfo[] getPropertyInfo(
+        String url,
+        Properties info
+      )
+      throws
+        SQLException
+    {
+      return target.getPropertyInfo(url, info);
+    }
+
+    @Override
+    public boolean jdbcCompliant()
+    {
+      return target.jdbcCompliant();
+    }
+
+    /**
+     * This Method cannot be annotated with @Override, becaus the plugin
+     * will not compile then under Java 1.6!
+     */
+    public Logger getParentLogger() throws SQLFeatureNotSupportedException
+    {
+      throw new SQLFeatureNotSupportedException("Not supported, for backward-compatibility with Java 1.6");
+    }
+
+    @Override
+    public String toString()
+    {
+      return "Proxy: " + target;
+    }
+
+    @Override
+    public int hashCode()
+    {
+      return target.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+      if (!(obj instanceof DriverProxy))
+        return false;
+      DriverProxy other = (DriverProxy) obj;
+      return this.target.equals(other.target);
+    }
+  }
+}
diff --git a/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java b/src/main/java/de/juplo/plugins/hibernate4/Hbm2DdlMojo.java
deleted file mode 100644 (file)
index f8c0634..0000000
+++ /dev/null
@@ -1,1307 +0,0 @@
-package de.juplo.plugins.hibernate4;
-
-/*
- * Copyright 2001-2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import com.pyx4j.log4j.MavenLogAppender;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.math.BigInteger;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.sql.Driver;
-import java.sql.DriverPropertyInfo;
-import java.sql.SQLException;
-import java.sql.SQLFeatureNotSupportedException;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.logging.Logger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import javax.persistence.Embeddable;
-import javax.persistence.Entity;
-import javax.persistence.MappedSuperclass;
-import javax.persistence.spi.PersistenceUnitTransactionType;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.model.Resource;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
-import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
-import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
-import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
-import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
-import org.hibernate.cfg.Environment;
-import org.hibernate.cfg.NamingStrategy;
-import org.hibernate.envers.configuration.spi.AuditConfiguration;
-import org.hibernate.internal.util.config.ConfigurationHelper;
-import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor;
-import org.hibernate.jpa.boot.internal.PersistenceXmlParser;
-import org.hibernate.jpa.boot.spi.ProviderChecker;
-import org.hibernate.tool.hbm2ddl.SchemaExport;
-import org.hibernate.tool.hbm2ddl.SchemaExport.Type;
-import org.hibernate.tool.hbm2ddl.Target;
-import org.scannotation.AnnotationDB;
-
-
-/**
- * Goal which extracts the hibernate-mapping-configuration and
- * exports an according SQL-database-schema.
- *
- * @goal export
- * @phase process-classes
- * @threadSafe
- * @requiresDependencyResolution runtime
- */
-public class Hbm2DdlMojo extends AbstractMojo
-{
-  public final static String EXPORT_SKIPPED_PROPERTY = "hibernate.export.skipped";
-
-  public final static String DRIVER_CLASS = "hibernate.connection.driver_class";
-  public final static String URL = "hibernate.connection.url";
-  public final static String USERNAME = "hibernate.connection.username";
-  public final static String PASSWORD = "hibernate.connection.password";
-  public final static String DIALECT = "hibernate.dialect";
-  public final static String NAMING_STRATEGY="hibernate.ejb.naming_strategy";
-  public final static String ENVERS = "hibernate.export.envers";
-
-  public final static String JPA_DRIVER = "javax.persistence.jdbc.driver";
-  public final static String JPA_URL = "javax.persistence.jdbc.url";
-  public final static String JPA_USERNAME = "javax.persistence.jdbc.user";
-  public final static String JPA_PASSWORD = "javax.persistence.jdbc.password";
-
-  public final static String MD5S = "hibernate4-generatedschema.md5s";
-
-  private final static Pattern split = Pattern.compile("[^,\\s]+");
-
-
-  /**
-   * The maven project.
-   * <p>
-   * Only needed internally.
-   *
-   * @parameter property="project"
-   * @required
-   * @readonly
-   */
-  private MavenProject project;
-
-  /**
-   * Build-directory.
-   * <p>
-   * Only needed internally.
-   *
-   * @parameter property="project.build.directory"
-   * @required
-   * @readonly
-   */
-  private String buildDirectory;
-
-  /**
-   * Classes-Directory to scan.
-   * <p>
-   * This parameter defaults to the maven build-output-directory for classes.
-   * Additionally, all dependencies are scanned for annotated classes.
-   *
-   * @parameter property="project.build.outputDirectory"
-   * @since 1.0
-   */
-  private String outputDirectory;
-
-  /**
-   * Whether to scan test-classes too, or not.
-   * <p>
-   * If this parameter is set to <code>true</code> the test-classes of the
-   * artifact will be scanned for hibernate-annotated classes additionally.
-   *
-   * @parameter property="hibernate.export.scan_testclasses" default-value="false"
-   * @since 1.0.1
-   */
-  private boolean scanTestClasses;
-
-  /**
-   * Dependency-Scopes, that should be scanned for annotated classes.
-   * <p>
-   * By default, only dependencies in the scope <code>compile</code> are
-   * scanned for annotated classes. Multiple scopes can be seperated by
-   * white space or commas.
-   * <p>
-   * If you do not want any dependencies to be scanned for annotated
-   * classes, set this parameter to <code>none</code>.
-   * <p>
-   * The plugin does not scan for annotated classes in transitive
-   * dependencies. If some of your annotated classes are hidden in a
-   * transitive dependency, you can simply add that dependency explicitly.
-   *
-   * @parameter property="hibernate.export.scan_dependencies" default-value="compile"
-   * @since 1.0.3
-   */
-  private String scanDependencies;
-
-  /**
-   * Test-Classes-Directory to scan.
-   * <p>
-   * This parameter defaults to the maven build-output-directory for
-   * test-classes.
-   * <p>
-   * This parameter is only used, when <code>scanTestClasses</code> is set
-   * to <code>true</code>!
-   *
-   * @parameter property="project.build.testOutputDirectory"
-   * @since 1.0.2
-   */
-  private String testOutputDirectory;
-
-  /**
-   * Skip execution
-   * <p>
-   * If set to <code>true</code>, the execution is skipped.
-   * <p>
-   * A skipped execution is signaled via the maven-property
-   * <code>${hibernate.export.skipped}</code>.
-   * <p>
-   * The execution is skipped automatically, if no modified or newly added
-   * annotated classes are found and the dialect was not changed.
-   *
-   * @parameter property="hibernate.skip" default-value="${maven.test.skip}"
-   * @since 1.0
-   */
-  private boolean skip;
-
-  /**
-   * Force execution
-   * <p>
-   * Force execution, even if no modified or newly added annotated classes
-   * where found and the dialect was not changed.
-   * <p>
-   * <code>skip</code> takes precedence over <code>force</code>.
-   *
-   * @parameter property="hibernate.export.force" default-value="false"
-   * @since 1.0
-   */
-  private boolean force;
-
-  /**
-   * SQL-Driver name.
-   *
-   * @parameter property="hibernate.connection.driver_class"
-   * @since 1.0
-   */
-  private String driverClassName;
-
-  /**
-   * Database URL.
-   *
-   * @parameter property="hibernate.connection.url"
-   * @since 1.0
-   */
-  private String url;
-
-  /**
-   * Database username
-   *
-   * @parameter property="hibernate.connection.username"
-   * @since 1.0
-   */
-  private String username;
-
-  /**
-   * Database password
-   *
-   * @parameter property="hibernate.connection.password"
-   * @since 1.0
-   */
-  private String password;
-
-  /**
-   * Hibernate dialect.
-   *
-   * @parameter property="hibernate.dialect"
-   * @since 1.0
-   */
-  private String hibernateDialect;
-
-  /**
-   * Hibernate Naming Strategy
-   *
-   * @parameter property="hibernate.ejb.naming_strategy"
-   * @since 1.0.2
-   */
-  private String hibernateNamingStrategy;
-
-  /**
-   * Path to Hibernate properties file.
-   * If this parameter is not set the plugin will try to load the configuration
-   * from a file <code>hibernate.properties</code> on the classpath. The
-   * test-classpath takes precedence.
-   *
-   * @parameter
-   * @since 1.0
-   */
-  private String hibernateProperties;
-
-  /**
-   * Path to Hibernate configuration file (.cfg.xml).
-   * Settings in this file will overwrite settings in the properties file.
-   * If this parameter is not set the plugin will try to load the configuration
-   * from a file <code>hibernate.cfg.xml</code> on the classpath. The
-   * test-classpath takes precedence.
-   *
-   * @parameter
-   * @since 1.1.0
-   */
-  private String hibernateConfig;
-
-  /**
-   * Name of the persistence-unit.
-   * If there is only one persistence-unit available, that unit will be used
-   * automatically.
-   * Settings in this file will overwrite settings in the properties or the
-   * configuration file.
-   *
-   * @parameter
-   * @since 1.1.0
-   */
-  private String persistenceUnit;
-
-  /**
-   * List of Hibernate-Mapping-Files (XML).
-   * Multiple files can be separated with white-spaces and/or commas.
-   *
-   * @parameter property="hibernate.mapping"
-   * @since 1.0.2
-   */
-  private String hibernateMapping;
-
-  /**
-   * Target of execution:
-   * <ul>
-   *   <li><strong>NONE</strong> only export schema to SQL-script (forces execution, signals skip)</li>
-   *   <li><strong>EXPORT</strong> create database (<strong>DEFAULT!</strong>). forces execution, signals skip)</li>
-   *   <li><strong>SCRIPT</strong> export schema to SQL-script and print it to STDOUT</li>
-   *   <li><strong>BOTH</strong></li>
-   * </ul>
-   *
-   * A database connection is only needed for EXPORT and BOTH, but a
-   * Hibernate-Dialect must always be chosen.
-   *
-   * @parameter property="hibernate.export.target" default-value="EXPORT"
-   * @since 1.0
-   */
-  private String target;
-
-  /**
-   * Type of execution.
-   * <ul>
-   *   <li><strong>NONE</strong> do nothing - just validate the configuration</li>
-   *   <li><strong>CREATE</strong> create database-schema</li>
-   *   <li><strong>DROP</strong> drop database-schema</li>
-   *   <li><strong>BOTH</strong> (<strong>DEFAULT!</strong>)</li>
-   * </ul>
-   *
-   * If NONE is choosen, no databaseconnection is needed.
-   *
-   * @parameter property="hibernate.export.type" default-value="BOTH"
-   * @since 1.0
-   */
-  private String type;
-
-  /**
-   * Output file.
-   *
-   * @parameter property="hibernate.export.schema.filename" default-value="${project.build.directory}/schema.sql"
-   * @since 1.0
-   */
-  private String outputFile;
-
-  /**
-   * Delimiter in output-file.
-   *
-   * @parameter property="hibernate.export.schema.delimiter" default-value=";"
-   * @since 1.0
-   */
-  private String delimiter;
-
-  /**
-   * Format output-file.
-   *
-   * @parameter property="hibernate.export.schema.format" default-value="true"
-   * @since 1.0
-   */
-  private boolean format;
-
-  /**
-   * Generate envers schema for auditing tables.
-   *
-   * @parameter property="hibernate.export.envers" default-value="true"
-   * @since 1.0.3
-   */
-  private boolean envers;
-
-
-  @Override
-  public void execute()
-    throws
-      MojoFailureException,
-      MojoExecutionException
-  {
-    if (skip)
-    {
-      getLog().info("Execution of hibernate4-maven-plugin:export was skipped!");
-      project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
-      return;
-    }
-
-    Map<String,String> md5s;
-    boolean modified = false;
-    File saved = new File(buildDirectory + File.separator + MD5S);
-
-    if (saved.isFile() && saved.length() > 0)
-    {
-      try
-      {
-        FileInputStream fis = new FileInputStream(saved);
-        ObjectInputStream ois = new ObjectInputStream(fis);
-        md5s = (HashMap<String,String>)ois.readObject();
-        ois.close();
-      }
-      catch (Exception e)
-      {
-        md5s = new HashMap<String,String>();
-        getLog().warn("Cannot read timestamps from saved: " + e);
-      }
-    }
-    else
-    {
-      md5s = new HashMap<String,String>();
-      try
-      {
-        saved.createNewFile();
-      }
-      catch (IOException e)
-      {
-        getLog().debug("Cannot create file \"" + saved.getPath() + "\" for timestamps: " + e);
-      }
-    }
-
-    URLClassLoader classLoader = null;
-    try
-    {
-      getLog().debug("Creating ClassLoader for project-dependencies...");
-      List<String> classpathFiles = project.getCompileClasspathElements();
-      if (scanTestClasses)
-        classpathFiles.addAll(project.getTestClasspathElements());
-      List<URL> urls = new LinkedList<URL>();
-      File file;
-      file = new File(testOutputDirectory);
-      if (!file.exists())
-      {
-        getLog().info("creating test-output-directory: " + testOutputDirectory);
-        file.mkdirs();
-      }
-      urls.add(file.toURI().toURL());
-      file = new File(outputDirectory);
-      if (!file.exists())
-      {
-        getLog().info("creating output-directory: " + outputDirectory);
-        file.mkdirs();
-      }
-      urls.add(file.toURI().toURL());
-      for (String pathElement : classpathFiles)
-      {
-        getLog().debug("Dependency: " + pathElement);
-        urls.add(new File(pathElement).toURI().toURL());
-      }
-      classLoader =
-          new URLClassLoader(
-              urls.toArray(new URL[urls.size()]),
-              getClass().getClassLoader()
-              );
-    }
-    catch (Exception e)
-    {
-      getLog().error("Error while creating ClassLoader!", e);
-      throw new MojoExecutionException(e.getMessage());
-    }
-
-    Set<Class<?>> classes =
-        new TreeSet<Class<?>>(
-            new Comparator<Class<?>>() {
-              @Override
-              public int compare(Class<?> a, Class<?> b)
-              {
-                return a.getName().compareTo(b.getName());
-              }
-            }
-          );
-
-    try
-    {
-      AnnotationDB db = new AnnotationDB();
-      File dir = new File(outputDirectory);
-      if (dir.exists())
-      {
-        getLog().info("Scanning directory " + outputDirectory + " for annotated classes...");
-        URL dirUrl = dir.toURI().toURL();
-        db.scanArchives(dirUrl);
-      }
-      if (scanTestClasses)
-      {
-        dir = new File(testOutputDirectory);
-        if (dir.exists())
-        {
-          getLog().info("Scanning directory " + testOutputDirectory + " for annotated classes...");
-          URL dirUrl = dir.toURI().toURL();
-          db.scanArchives(dirUrl);
-        }
-      }
-      if (scanDependencies != null)
-      {
-        Matcher matcher = split.matcher(scanDependencies);
-        while (matcher.find())
-        {
-          getLog().info("Scanning dependencies for scope " + matcher.group());
-          for (Artifact artifact : project.getDependencyArtifacts())
-          {
-            if (!artifact.getScope().equalsIgnoreCase(matcher.group()))
-              continue;
-            if (artifact.getFile() == null)
-            {
-              getLog().warn(
-                  "Cannot scan dependency " +
-                  artifact.getId() +
-                  ": no JAR-file available!"
-                  );
-              continue;
-            }
-            getLog().info(
-                "Scanning dependency " +
-                artifact.getId() +
-                " for annotated classes..."
-                );
-            db.scanArchives(artifact.getFile().toURI().toURL());
-          }
-        }
-      }
-
-      Set<String> classNames = new HashSet<String>();
-      if (db.getAnnotationIndex().containsKey(Entity.class.getName()))
-        classNames.addAll(db.getAnnotationIndex().get(Entity.class.getName()));
-      if (db.getAnnotationIndex().containsKey(MappedSuperclass.class.getName()))
-        classNames.addAll(db.getAnnotationIndex().get(MappedSuperclass.class.getName()));
-      if (db.getAnnotationIndex().containsKey(Embeddable.class.getName()))
-        classNames.addAll(db.getAnnotationIndex().get(Embeddable.class.getName()));
-
-      MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
-      for (String name : classNames)
-      {
-        Class<?> annotatedClass = classLoader.loadClass(name);
-        classes.add(annotatedClass);
-        String resourceName = annotatedClass.getName();
-        resourceName = resourceName.substring(resourceName.lastIndexOf(".") + 1, resourceName.length()) + ".class";
-        InputStream is =
-            annotatedClass
-                .getResourceAsStream(resourceName);
-        byte[] buffer = new byte[1024*4]; // copy data in 4MB-chunks
-        int i;
-        while((i = is.read(buffer)) > -1)
-          digest.update(buffer, 0, i);
-        is.close();
-        byte[] bytes = digest.digest();
-        BigInteger bi = new BigInteger(1, bytes);
-        String newMd5 = String.format("%0" + (bytes.length << 1) + "x", bi);
-        String oldMd5 = !md5s.containsKey(name) ? "" : md5s.get(name);
-        if (!newMd5.equals(oldMd5))
-        {
-          getLog().debug("Found new or modified annotated class: " + name);
-          modified = true;
-          md5s.put(name, newMd5);
-        }
-        else
-        {
-          getLog().debug(oldMd5 + " -> class unchanged: " + name);
-        }
-      }
-    }
-    catch (ClassNotFoundException e)
-    {
-      getLog().error("Error while adding annotated classes!", e);
-      throw new MojoExecutionException(e.getMessage());
-    }
-    catch (Exception e)
-    {
-      getLog().error("Error while scanning!", e);
-      throw new MojoFailureException(e.getMessage());
-    }
-
-
-    ValidationConfiguration config = new ValidationConfiguration();
-    // Clear unused system-properties
-    config.setProperties(new Properties());
-
-
-    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
-    StandardServiceRegistryImpl registry = null;
-    MavenLogAppender.startPluginLog(this);
-
-    try
-    {
-      /**
-       * Change class-loader of current thread, so that hibernate can
-       * see all dependencies!
-       */
-      Thread.currentThread().setContextClassLoader(classLoader);
-
-
-      /** Try to read configuration from properties-file */
-      try
-      {
-        if (hibernateProperties == null)
-        {
-          URL url = classLoader.findResource("hibernate.properties");
-          if (url == null)
-          {
-            getLog().info("No hibernate.properties on the classpath!");
-          }
-          else
-          {
-            getLog().info("Reading settings from hibernate.properties on the classpath.");
-            Properties properties = new Properties();
-            properties.load(url.openStream());
-            config.setProperties(properties);
-          }
-        }
-        else
-        {
-          File file = new File(hibernateProperties);
-          if (file.exists())
-          {
-            getLog().info("Reading settings from file " + hibernateProperties + "...");
-            Properties properties = new Properties();
-            properties.load(new FileInputStream(file));
-            config.setProperties(properties);
-          }
-          else
-            getLog().info("No hibernate-properties-file found! (Checked path: " + hibernateProperties + ")");
-        }
-      }
-      catch (IOException e)
-      {
-        getLog().error("Error while reading properties!", e);
-        throw new MojoExecutionException(e.getMessage());
-      }
-
-      /** Try to read configuration from configuration-file */
-      try
-      {
-        if (hibernateConfig == null)
-        {
-          URL url = classLoader.findResource("hibernate.cfg.xml");
-          if (url == null)
-          {
-            getLog().info("No hibernate.cfg.xml on the classpath!");
-          }
-          else
-          {
-            getLog().info("Reading settings from hibernate.cfg.xml on the classpath.");
-            config.configure(url);
-          }
-        }
-        else
-        {
-          File file = new File(hibernateConfig);
-          if (file.exists())
-          {
-            getLog().info("Reading configuration from file " + hibernateConfig + "...");
-            config.configure(file);
-          }
-          else
-            getLog().info("No hibernate-configuration-file found! (Checked path: " + hibernateConfig + ")");
-        }
-      }
-      catch (Exception e)
-      {
-        getLog().error("Error while reading configuration!", e);
-        throw new MojoExecutionException(e.getMessage());
-      }
-
-      ParsedPersistenceXmlDescriptor persistenceUnitDescriptor =
-          getPersistenceUnitDescriptor(
-              persistenceUnit,
-              config.getProperties(),
-              new MavenProjectClassLoaderService(classLoader)
-              );
-      if (persistenceUnitDescriptor != null)
-        config.setProperties(persistenceUnitDescriptor.getProperties());
-
-
-      /** Overwrite values from properties-file or set, if given */
-
-      if (driverClassName != null)
-      {
-        if (config.getProperties().containsKey(DRIVER_CLASS))
-          getLog().debug(
-              "Overwriting property " +
-              DRIVER_CLASS + "=" + config.getProperty(DRIVER_CLASS) +
-              " with the value " + driverClassName
-            );
-        else
-          getLog().debug("Using the value " + driverClassName);
-        config.setProperty(DRIVER_CLASS, driverClassName);
-      }
-      if (config.getProperty(DRIVER_CLASS) == null)
-      {
-        String driver = config.getProperty(JPA_DRIVER);
-        if (driver != null)
-        {
-          getLog().info(
-              DRIVER_CLASS +
-              " is not set. Borrow setting from " +
-              JPA_DRIVER +
-              ": " +
-              driver);
-          config.setProperty(DRIVER_CLASS, driver);
-        }
-      }
-
-      if (url != null)
-      {
-        if (config.getProperties().containsKey(URL))
-          getLog().debug(
-              "Overwriting property " +
-              URL + "=" + config.getProperty(URL) +
-              " with the value " + url
-            );
-        else
-          getLog().debug("Using the value " + url);
-        config.setProperty(URL, url);
-      }
-      if (config.getProperty(URL) == null)
-      {
-        String url = config.getProperty(JPA_URL);
-        if (url != null)
-        {
-          getLog().info(
-              URL +
-              " is not set. Borrow setting from " +
-              JPA_URL +
-              ": " +
-              url);
-          config.setProperty(URL, url);
-        }
-      }
-
-      if (username != null)
-      {
-        if (config.getProperties().containsKey(USERNAME))
-          getLog().debug(
-              "Overwriting property " +
-              USERNAME + "=" + config.getProperty(USERNAME) +
-              " with the value " + username
-            );
-        else
-          getLog().debug("Using the value " + username);
-        config.setProperty(USERNAME, username);
-      }
-      if (config.getProperty(USERNAME) == null)
-      {
-        String username = config.getProperty(JPA_USERNAME);
-        if (username != null)
-        {
-          getLog().info(
-              USERNAME +
-              " is not set. Borrow setting from " +
-              JPA_USERNAME +
-              ": " +
-              username);
-          config.setProperty(USERNAME, username);
-        }
-      }
-
-      if (password != null)
-      {
-        if (config.getProperties().containsKey(PASSWORD))
-          getLog().debug(
-              "Overwriting property " +
-              PASSWORD + "=" + config.getProperty(PASSWORD) +
-              " with value " + password
-            );
-        else
-          getLog().debug("Using value " + password + " for property " + PASSWORD);
-        config.setProperty(PASSWORD, password);
-      }
-      if (config.getProperty(PASSWORD) == null)
-      {
-        String password = config.getProperty(JPA_PASSWORD);
-        if (password != null)
-        {
-          getLog().info(
-              PASSWORD +
-              " is not set. Borrow setting from " +
-              JPA_PASSWORD +
-              ": " +
-              password);
-          config.setProperty(PASSWORD, password);
-        }
-      }
-
-      if (hibernateDialect != null)
-      {
-        if (config.getProperties().containsKey(DIALECT))
-          getLog().debug(
-              "Overwriting property " +
-              DIALECT + "=" + config.getProperty(DIALECT) +
-              " with value " + hibernateDialect
-            );
-        else
-          getLog().debug(
-              "Using value " + hibernateDialect + " for property " + DIALECT
-              );
-        config.setProperty(DIALECT, hibernateDialect);
-      }
-
-      if ( hibernateNamingStrategy != null )
-      {
-        if ( config.getProperties().contains(NAMING_STRATEGY))
-          getLog().debug(
-              "Overwriting property " +
-              NAMING_STRATEGY + "=" + config.getProperty(NAMING_STRATEGY) +
-              " with value " + hibernateNamingStrategy
-             );
-        else
-          getLog().debug(
-              "Using value " + hibernateNamingStrategy + " for property " +
-              NAMING_STRATEGY
-              );
-        config.setProperty(NAMING_STRATEGY, hibernateNamingStrategy);
-      }
-
-      /** The generated SQL varies with the dialect! */
-      if (md5s.containsKey(DIALECT))
-      {
-        String dialect = config.getProperty(DIALECT);
-        if (md5s.get(DIALECT).equals(dialect))
-          getLog().debug("SQL-dialect unchanged.");
-        else
-        {
-          modified = true;
-          if (dialect == null)
-          {
-            getLog().debug("SQL-dialect was unset.");
-            md5s.remove(DIALECT);
-          }
-          else
-          {
-            getLog().debug("SQL-dialect changed: " + dialect);
-            md5s.put(DIALECT, dialect);
-          }
-        }
-      }
-      else
-      {
-        String dialect = config.getProperty(DIALECT);
-        if (dialect != null)
-        {
-          modified = true;
-          md5s.put(DIALECT, config.getProperty(DIALECT));
-        }
-      }
-
-      /** The generated SQL varies with the envers-configuration */
-      if (md5s.get(ENVERS) != null)
-      {
-        if (md5s.get(ENVERS).equals(Boolean.toString(envers)))
-          getLog().debug("Envers-Configuration unchanged. Enabled: " + envers);
-        else
-        {
-          getLog().debug("Envers-Configuration changed. Enabled: " + envers);
-          modified = true;
-          md5s.put(ENVERS, Boolean.toString(envers));
-        }
-      }
-      else
-      {
-        modified = true;
-        md5s.put(ENVERS, Boolean.toString(envers));
-      }
-
-      if (config.getProperties().isEmpty())
-      {
-        getLog().error("No properties set!");
-        throw new MojoFailureException("Hibernate configuration is missing!");
-      }
-
-      getLog().info("Gathered hibernate-configuration (turn on debugging for details):");
-      for (Entry<Object,Object> entry : config.getProperties().entrySet())
-        getLog().info("  " + entry.getKey() + " = " + entry.getValue());
-
-
-      getLog().debug("Adding explicitly configured mappings...");
-      if (hibernateMapping != null)
-      {
-        try
-        {
-          MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
-          for (String filename : hibernateMapping.split("[\\s,]+"))
-          {
-            // First try the filename as absolute/relative path
-            File file = new File(filename);
-            if (!file.exists())
-            {
-              // If the file was not found, search for it in the resource-directories
-              for (Resource resource : project.getResources())
-              {
-                file = new File(resource.getDirectory() + File.separator + filename);
-                if (file.exists())
-                  break;
-              }
-            }
-            if (file != null && file.exists())
-            {
-              InputStream is = new FileInputStream(file);
-              byte[] buffer = new byte[1024*4]; // copy data in 4MB-chunks
-              int i;
-              while((i = is.read(buffer)) > -1)
-                digest.update(buffer, 0, i);
-              is.close();
-              byte[] bytes = digest.digest();
-              BigInteger bi = new BigInteger(1, bytes);
-              String newMd5 = String.format("%0" + (bytes.length << 1) + "x", bi);
-              String oldMd5 = !md5s.containsKey(filename) ? "" : md5s.get(filename);
-              if (!newMd5.equals(oldMd5))
-              {
-                getLog().debug("Found new or modified mapping-file: " + filename);
-                modified = true;
-                md5s.put(filename, newMd5);
-              }
-              else
-              {
-                getLog().debug(oldMd5 + " -> mapping-file unchanged: " + filename);
-              }
-              getLog().debug("Adding mappings from XML-configurationfile: " + file);
-              config.addFile(file);
-            }
-            else
-              throw new MojoFailureException("File " + filename + " could not be found in any of the configured resource-directories!");
-          }
-        }
-        catch (NoSuchAlgorithmException e)
-        {
-          throw new MojoFailureException("Cannot calculate MD5 sums!", e);
-        }
-        catch (FileNotFoundException e)
-        {
-          throw new MojoFailureException("Cannot calculate MD5 sums!", e);
-        }
-        catch (IOException e)
-        {
-          throw new MojoFailureException("Cannot calculate MD5 sums!", e);
-        }
-      }
-
-      getLog().debug("Adding annotated classes to hibernate-mapping-configuration...");
-      // build annotated packages
-      Set<String> packages = new HashSet<String>();
-      for (Class<?> annotatedClass : classes)
-      {
-        String packageName = annotatedClass.getPackage().getName();
-        if (!packages.contains(packageName))
-        {
-          getLog().debug("Add package " + packageName);
-          packages.add(packageName);
-          config.addPackage(packageName);
-          getLog().debug("type definintions" + config.getTypeDefs());
-        }
-        getLog().debug("Class " + annotatedClass);
-        config.addAnnotatedClass(annotatedClass);
-      }
-
-      Target target = null;
-      try
-      {
-        target = Target.valueOf(this.target.toUpperCase());
-      }
-      catch (IllegalArgumentException e)
-      {
-        getLog().error("Invalid value for configuration-option \"target\": " + this.target);
-        getLog().error("Valid values are: NONE, SCRIPT, EXPORT, BOTH");
-        throw new MojoExecutionException("Invalid value for configuration-option \"target\"");
-      }
-      Type type = null;
-      try
-      {
-        type = Type.valueOf(this.type.toUpperCase());
-      }
-      catch (IllegalArgumentException e)
-      {
-        getLog().error("Invalid value for configuration-option \"type\": " + this.type);
-        getLog().error("Valid values are: NONE, CREATE, DROP, BOTH");
-        throw new MojoExecutionException("Invalid value for configuration-option \"type\"");
-      }
-
-
-      if (config.getProperty(DIALECT) == null)
-        throw new MojoFailureException("hibernate-dialect must be set!");
-
-
-      if (target.equals(Target.SCRIPT) || target.equals(Target.NONE))
-      {
-        project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
-      }
-      if (
-          !modified
-          && !target.equals(Target.SCRIPT)
-          && !target.equals(Target.NONE)
-          && !force
-        )
-      {
-        getLog().info("No modified annotated classes or mapping-files found and dialect unchanged.");
-        getLog().info("Skipping schema generation!");
-        project.getProperties().setProperty(EXPORT_SKIPPED_PROPERTY, "true");
-        return;
-      }
-
-
-      if ( config.getProperties().containsKey(NAMING_STRATEGY))
-      {
-        String namingStrategy = config.getProperty(NAMING_STRATEGY);
-        getLog().debug("Explicitly set NamingStrategy: " + namingStrategy);
-        try
-        {
-          @SuppressWarnings("unchecked")
-          Class<NamingStrategy> namingStrategyClass = (Class<NamingStrategy>) Class.forName(namingStrategy);
-          config.setNamingStrategy(namingStrategyClass.newInstance());
-        }
-        catch (Exception e)
-        {
-          getLog().error("Error setting NamingStrategy", e);
-          throw new MojoExecutionException(e.getMessage());
-        }
-      }
-
-
-      Environment.verifyProperties(config.getProperties());
-      ConfigurationHelper.resolvePlaceHolders(config.getProperties());
-      registry =
-          (StandardServiceRegistryImpl)
-          new StandardServiceRegistryBuilder()
-              .applySettings(config.getProperties())
-              .build();
-
-      config.buildMappings();
-
-      if (envers)
-      {
-        getLog().info("Automatic auditing via hibernate-envers enabled!");
-        AuditConfiguration.getFor(config);
-      }
-
-      SchemaExport export = new SchemaExport(registry, config);
-      export.setDelimiter(delimiter);
-      export.setFormat(format);
-
-      File outF = new File(outputFile);
-
-      if (!outF.isAbsolute())
-      {
-        // Interpret relative file path relative to build directory
-        outF = new File(buildDirectory, outputFile);
-        getLog().info("Adjusted relative path, resulting path is " + outF.getPath());
-      }
-
-      // Ensure that directory path for specified file exists
-      File outFileParentDir = outF.getParentFile();
-      if (null != outFileParentDir && !outFileParentDir.exists())
-      {
-        try
-        {
-          getLog().info("Creating directory path for output file:" + outFileParentDir.getPath());
-          outFileParentDir.mkdirs();
-        }
-        catch (Exception e)
-        {
-          getLog().error("Error creating directory path for output file: " + e.getLocalizedMessage());
-        }
-      }
-
-      export.setOutputFile(outF.getPath());
-      export.execute(target, type);
-
-      for (Object exception : export.getExceptions())
-        getLog().debug(exception.toString());
-    }
-    finally
-    {
-      /** Stop Log-Capturing */
-      MavenLogAppender.endPluginLog(this);
-
-      /** Restore the old class-loader (TODO: is this really necessary?) */
-      Thread.currentThread().setContextClassLoader(contextClassLoader);
-
-      if (registry != null)
-        registry.destroy();
-    }
-
-    /** Write md5-sums for annotated classes to file */
-    try
-    {
-      FileOutputStream fos = new FileOutputStream(saved);
-      ObjectOutputStream oos = new ObjectOutputStream(fos);
-      oos.writeObject(md5s);
-      oos.close();
-      fos.close();
-    }
-    catch (Exception e)
-    {
-      getLog().error("Cannot write md5-sums to file: " + e);
-    }
-  }
-
-  private ParsedPersistenceXmlDescriptor getPersistenceUnitDescriptor(
-      String name,
-      Properties properties,
-      ClassLoaderService loader
-      )
-      throws
-        MojoFailureException
-  {
-    PersistenceXmlParser parser =
-        new PersistenceXmlParser(
-            loader,
-            PersistenceUnitTransactionType.RESOURCE_LOCAL
-             );
-
-    List<ParsedPersistenceXmlDescriptor> units = parser.doResolve(properties);
-
-    if (name == null)
-    {
-      switch (units.size())
-      {
-        case 0:
-          getLog().info("Found no META-INF/persistence.xml.");
-          return null;
-        case 1:
-          getLog().info("Using persistence-unit " + units.get(0).getName());
-          return units.get(0);
-        default:
-          getLog().warn("No name provided and multiple persistence units found:");
-          for (ParsedPersistenceXmlDescriptor unit : units)
-            getLog().warn(" - " + unit.getName());
-          return null;
-      }
-
-    }
-
-    for (ParsedPersistenceXmlDescriptor unit : units)
-    {
-      getLog().debug("Found persistence-unit " + unit.getName());
-      if (!unit.getName().equals(name))
-        continue;
-
-      // See if we (Hibernate) are the persistence provider
-      if (!ProviderChecker.isProvider(unit, properties))
-      {
-        getLog().debug("Wrong provider: " + unit.getProviderClassName());
-        continue;
-      }
-
-      getLog().info("Using persistence-unit " + unit.getName());
-      return unit;
-    }
-
-    throw new MojoFailureException("Could not find persistence-unit " + name);
-  }
-
-
-  static final class MavenProjectClassLoaderService implements ClassLoaderService
-  {
-    final private ClassLoader loader;
-
-
-    public MavenProjectClassLoaderService(ClassLoader loader)
-    {
-      this.loader = loader;
-    }
-
-
-    @Override
-    public <T> Class<T> classForName(String name)
-    {
-      try
-      {
-        return (Class<T>)loader.loadClass(name);
-      }
-      catch (ClassNotFoundException e)
-      {
-        throw new ClassLoadingException( "Unable to load class [" + name + "]", e );
-      }
-    }
-
-    @Override
-    public URL locateResource(String name)
-    {
-      return loader.getResource(name);
-    }
-
-    @Override
-    public InputStream locateResourceStream(String name)
-    {
-      return loader.getResourceAsStream(name);
-    }
-
-    @Override
-    public List<URL> locateResources(String name)
-    {
-      try
-      {
-        return Collections.list(loader.getResources(name));
-      }
-      catch (IOException e)
-      {
-        return Collections.EMPTY_LIST;
-      }
-    }
-
-    @Override
-    public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract)
-    {
-      throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-    }
-
-    @Override
-    public void stop() { }
-
-  }
-
-
-  /**
-   * Needed, because DriverManager won't pick up drivers, that were not
-   * loaded by the system-classloader!
-   * See:
-   * http://stackoverflow.com/questions/288828/how-to-use-a-jdbc-driver-fromodifiedm-an-arbitrary-location
-   */
-  static final class DriverProxy implements Driver
-  {
-    private final Driver target;
-
-    DriverProxy(Driver target)
-    {
-      if (target == null)
-        throw new NullPointerException();
-      this.target = target;
-    }
-
-    public java.sql.Driver getTarget()
-    {
-      return target;
-    }
-
-    @Override
-    public boolean acceptsURL(String url) throws SQLException
-    {
-      return target.acceptsURL(url);
-    }
-
-    @Override
-    public java.sql.Connection connect(
-        String url,
-        java.util.Properties info
-      )
-      throws
-        SQLException
-    {
-      return target.connect(url, info);
-    }
-
-    @Override
-    public int getMajorVersion()
-    {
-      return target.getMajorVersion();
-    }
-
-    @Override
-    public int getMinorVersion()
-    {
-      return target.getMinorVersion();
-    }
-
-    @Override
-    public DriverPropertyInfo[] getPropertyInfo(
-        String url,
-        Properties info
-      )
-      throws
-        SQLException
-    {
-      return target.getPropertyInfo(url, info);
-    }
-
-    @Override
-    public boolean jdbcCompliant()
-    {
-      return target.jdbcCompliant();
-    }
-
-    /**
-     * This Method cannot be annotated with @Override, becaus the plugin
-     * will not compile then under Java 1.6!
-     */
-    public Logger getParentLogger() throws SQLFeatureNotSupportedException
-    {
-      throw new SQLFeatureNotSupportedException("Not supported, for backward-compatibility with Java 1.6");
-    }
-
-    @Override
-    public String toString()
-    {
-      return "Proxy: " + target;
-    }
-
-    @Override
-    public int hashCode()
-    {
-      return target.hashCode();
-    }
-
-    @Override
-    public boolean equals(Object obj)
-    {
-      if (!(obj instanceof DriverProxy))
-        return false;
-      DriverProxy other = (DriverProxy) obj;
-      return this.target.equals(other.target);
-    }
-  }
-}
diff --git a/src/main/java/de/juplo/plugins/hibernate4/ValidationConfiguration.java b/src/main/java/de/juplo/plugins/hibernate4/ValidationConfiguration.java
deleted file mode 100644 (file)
index d16be20..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-package de.juplo.plugins.hibernate4;
-
-import javax.validation.Validation;
-
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.beanvalidation.TypeSafeActivatorAccessor;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.metamodel.source.MappingException;
-
-
-/**
- * This integration is usually performed by BeanValidationIntegrator.
- * Unfortunately, that integration will only be activated upon
- * initialization of the ServiceRegistry, which initializes
- * DatasourceConnectionProviderImpl, which looks up the datasource,
- * which requires a JNDI context ...
- * We therefore reimplement the relevant parts of BeanValidatorIntegrator.
- * Since that must occur after secondPassCompile(), which is invoked by
- * Configuration.generateSchemaCreationScript, which is invoked by
- * SchemaExport, some fancy subclassing is needed to invoke the integration
- * at the right time.
- * @author Mark Robinson <mark@mrobinson.ca>
- * @author Frank Schimmel <frank.schimmel@cm4all.com>
- */
-public class ValidationConfiguration extends Configuration
-{
-  private static final long serialVersionUID = 1L;
-
-
-  @Override
-  protected void secondPassCompile() throws MappingException
-  {
-    super.secondPassCompile();
-
-    try
-    {
-      TypeSafeActivatorAccessor.applyRelationalConstraints(
-          Validation.buildDefaultValidatorFactory(),
-          classes.values(),
-          getProperties(),
-          ((Class<Dialect>)Class.forName(getProperty(Hbm2DdlMojo.DIALECT))).newInstance()
-          );
-    }
-    catch (Exception e)
-    {
-      throw new RuntimeException(e);
-    }
-  }
-
-  public String getTypeDefs()
-  {
-    return typeDefs.entrySet().toString();
-  }
-}
diff --git a/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivatorAccessor.java b/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivatorAccessor.java
deleted file mode 100644 (file)
index faece3f..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-package org.hibernate.cfg.beanvalidation;
-
-/**
- * This class enables access to the public methods of {@link TypeSafeActivator}
- * which itself is visible in the package only.
- *
- * @author Frank Schimmel <frank.schimmel@cm4all.com>
- */
-public class TypeSafeActivatorAccessor extends TypeSafeActivator {
-    // Empty: just makes public methods accessible.
-}
diff --git a/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
deleted file mode 100644 (file)
index bd7af1e..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<lifecycleMappingMetadata>
-  <pluginExecutions>
-    <pluginExecution>
-      <pluginExecutionFilter>
-        <goals>
-          <goal>export</goal>
-        </goals>
-      </pluginExecutionFilter>
-      <action>
-        <execute>
-          <runOnIncremental>true</runOnIncremental>
-          <runOnConfiguration>true</runOnConfiguration>
-        </execute>
-      </action>
-    </pluginExecution>
-  </pluginExecutions>
-</lifecycleMappingMetadata>
index 8360b8f873bf6425609566cbea6d0987fd5233d6..e8c5afd592af9b47d6386318ab06904108bcf02c 100644 (file)
@@ -19,7 +19,7 @@
   <pre class="prettyprint linenums lang-html">
 &lt;plugin&gt;
   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
-  &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+  &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
   &lt;version&gt;${project.version}&lt;/version&gt;
   &lt;executions&gt;
     &lt;execution&gt;
@@ -46,7 +46,7 @@
   <pre class="prettyprint linenums lang-html">
 &lt;plugin&gt;
   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
-  &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+  &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
   &lt;version&gt;${project.version}&lt;/version&gt;
   &lt;executions&gt;
     &lt;execution&gt;
 
   &lt;plugin&gt;
     &lt;groupId&gt;de.juplo&lt;/groupId&gt;
-    &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+    &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
     &lt;version&gt;${project.version}&lt;/version&gt;
     &lt;executions&gt;
       &lt;execution&gt;
   The relevant configuration-parameters are:
   </p>
   <ul>
-    <li><code>driverClassName</code></li>
-    <li><code>hibernateDialect</code></li>
+    <li><code>driver</code></li>
+    <li><code>dialect</code></li>
     <li><code>url</code></li>
     <li><code>username</code></li>
     <li><code>password</code></li>
   <pre class="prettyprint linenums lang-html">
 &lt;plugin&gt;
   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
-  &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+  &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
   &lt;version&gt;${project.version}&lt;/version&gt;
   &lt;executions&gt;
     &lt;execution&gt;
     &lt;/execution&gt;
   &lt;/executions&gt;
   &lt;configuration&gt;
-    &lt;driverClassName&gt;org.hsqldb.jdbcDriver&lt;/driverClassName&gt;
-    &lt;hibernateDialect&gt;org.hibernate.dialect.HSQLDialect&lt;/hibernateDialect&gt;
+    &lt;driver&gt;org.hsqldb.jdbcDriver&lt;/driver&gt;
+    &lt;dialect&gt;org.hibernate.dialect.HSQLDialect&lt;/dialect&gt;
     &lt;url&gt;&lt;![CDATA[jdbc:hsqldb:target/db/fotos;shutdown=true]]&gt;&lt;/url&gt;
     &lt;username&gt;sa&lt;/username&gt;
     &lt;password&gt;&lt;/password&gt;
   </ol>
   <p>
   If you are in doubt about where a configuration-value comes from, run
-  maven with the <a href="./debugging.html">debug-output</a> enabled: <code>mvn -X hibernate4:export</code>
+  maven with the <a href="./debugging.html">debug-output</a> enabled: <code>mvn -X hibernate:export</code>
   and be aware, that maven-properties can be overwitten on the command-line,
   in your <code>~/.m2/settings.xml</code> and in a profile.
   </p>
   <pre class="prettyprint linenums lang-html">
 &lt;plugin&gt;
   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
-  &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+  &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
   &lt;version&gt;${project.version}&lt;/version&gt;
   &lt;executions&gt;
     &lt;execution&gt;
index 8f91f3f9154b030a65172cea5a7fc30f23746456..c67d8c00afe1b37f1c19983c8aa1135ae5fa43cb 100644 (file)
@@ -5,7 +5,7 @@
  </head>
  <body>
   <p>
-  If you are new to <code>hibernate4-maven-plugin</code>, in many cases, the
+  If you are new to <code>hibernate-maven-plugin</code>, in many cases, the
   {Configuration-Method-Precedence} may be the source of configuration
   errors.
   To solve this problem, you should run maven with the debugging output
   For example, by executing:
   </p>
   <pre class="prettyprint linenums lang-html">
-mvn -X compile hibernate4:export</pre>
+mvn -X compile hibernate:export</pre>
   <p>
-  (The <code>compile</code> might be necessary, because <code>hibernate4-maven-plugin</code>
+  (The <code>compile</code> might be necessary, because <code>hibernate-maven-plugin</code>
   has to scan the compiled classes for annotations!)
   </p>
   <p>
-  Unlike the majority of the maven-plugins, <code>hibernate4-maven-plugin</code> was
+  Unlike the majority of the maven-plugins, <code>hibernate-maven-plugin</code> was
   designed to give a good many hints, when debugging is enabled.
   Because, if you do not know, what went wrong, you can't fix it!
   </p>
   <p>
-  <strong>But be warned:</strong> <code>hibernate4-maven-plugin</code> tends to be very chatty ;)
+  <strong>But be warned:</strong> <code>hibernate-maven-plugin</code> tends to be very chatty ;)
   </p>
  </body>
 </html>
index 0a94070e1a289eca80af2e8b9a39c5f31d413a79..cd582db3d5c854be187a813d5cf42ec1dd8fe4d9 100644 (file)
@@ -5,7 +5,7 @@
  </head>
  <body>
   <p>
-  The hibernate4-maven-plugin computes MD5-sums for all found annotated
+  The hibernate-maven-plugin computes MD5-sums for all found annotated
   classes and stores them together with the generated schema.
   If no classes were changed or added and the dialect wasn't changed too, it
   automatically skips the configured schema-export, to speed up the development
   <a href="./pitfalls.html#fails">may fail</a>, when the execution is skipped.
   </p>
   <p>
-  If you need the hibernate4-maven-plugin to &lt;never skip execution automatically&gt;,
+  If you need the hibernate-maven-plugin to &lt;never skip execution automatically&gt;,
   you can force it to do so, if you set the parameter <code>force</code> to
   <code>true</code>:
   </p>
   <pre class="prettyprint linenums lang-html">
 &lt;plugin&gt;
   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
-  &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+  &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
   &lt;version&gt;${project.version}&lt;/version&gt;
   &lt;configuration&gt;
     &lt;force&gt;true&lt;/force&gt;
@@ -34,7 +34,7 @@
 &lt;/plugin&gt;</pre>
   <p>
   Or you may specify <code>-Dhibernate.export.force=true</code> at the command line,
-  if you want to force hibernate4-maven-plugin only once.
+  if you want to force hibernate-maven-plugin only once.
   </p>
  </body>
 </html>
index 39d191eabaeba3f4d4364f8e2a894d7da1bb0879..a30e6d6299b60eca6fa4e6203f2ccd24293671a2 100644 (file)
@@ -7,7 +7,7 @@
   <h1>Hibernate 4 Maven Plugin</h1>
   <h2>A simple Plugin for generating a Database-Schema from Hibernate 4 Mapping-Annotations</h2>
   <p>
-  The <strong>hibernate4-maven-plugin</strong> is a plugin for generating a database-schema
+  The <strong>hibernate-maven-plugin</strong> is a plugin for generating a database-schema
   from your Hibernate-4-Mappings and create or update your database
   accordingly.
   Its main usage is to automatically create and populate a test-database
   </p>
   <p>
   Last but not least, in order to not slow down the development cycle, the
-  hibernate4-maven-plugin only executes the schema-export, if the mapping
+  hibernate-maven-plugin only executes the schema-export, if the mapping
   or the dialect changes (or if you force it to do so).
   </p>
   <p>
   For more information about the inspiration to write this tiny plugin,
-  <a href="/hibernate4-maven-plugin-a-simple-plugin-for-generating-a-database-schema-from-hibernate-4-mapping-annotations/">read our blog-article about the hibernate4-maven-plugin</a>.
+  <a href="/hibernate-maven-plugin-a-simple-plugin-for-generating-a-database-schema-from-hibernate-4-mapping-annotations/">read our blog-article about the hibernate-maven-plugin</a>.
   </p>
   <h2>Documentation</h2>
   <ul>
@@ -48,7 +48,7 @@
    and simple examples of how to use this plugin.
    </li>
    <li>
-   See <a href="./export-mojo.html">hibernate4:export</a> and
+   See <a href="./export-mojo.html">hibernate:export</a> and
    <a href="./plugin-info.html">Plugin Documentation</a> for the full
    autogenerated documentation. These are mostly configuration-options
    of the Hibernate-Tools <code>SchemaExport</code> and <code>SchemaUpdate</code>, that do
@@ -57,7 +57,7 @@
   </ul>
   <h2>Releases</h2>
   <ul>
-    <li><a href="http://juplo.de/hibernate4-maven-plugin">current version</a></li>
+    <li><a href="http://juplo.de/hibernate-maven-plugin">current version</a></li>
     <li>${project.version} (this version)</li>
     <li><a href="http://juplo.de/hibernate4-maven-plugin-1.0.5">1.0.5</a></li>
     <li><a href="http://juplo.de/hibernate4-maven-plugin-1.0.4">1.0.4</a></li>
index 71839293395c61ff627c5156e50929da387e8710..3967811bcff10e730e135d067c493eae7dc5290f 100644 (file)
@@ -6,14 +6,14 @@
  <body>
   <h2>Annotated classes in dependencies are not found.</h2>
   <p>
-  hibernate4-maven-plugin by default scans dependencies in the scope
+  hibernate-maven-plugin by default scans dependencies in the scope
   <code>compile</code>. You can configure it to scan dependencies in other
   scopes as well. But it scans only direct dependencies. Transitive
   dependencies are not scanned for annotated classes. If some of your
   annotated classes are hidden in a transitive dependency, you can simply
   add that dependency explicitly.
   </p>
-  <h2>hibernate4-maven-plugin always needs a database-connection</h2>
+  <h2>hibernate-maven-plugin always needs a database-connection</h2>
   <p>
   The default-configuration uses the EXPORT-target of the SchemaExport-Tool.
   If you do not need to create a database with the evaluated schema, you can
@@ -36,7 +36,7 @@
   So a tidy maven-developer would usually scope it for <code>runtime</code>.
   </p>
   <p>
-  But this will break the execution of the <code>hibernate4-maven-plugin</code>.
+  But this will break the execution of the <code>hibernate-maven-plugin</code>.
   Since it will not be able to see the needed dependency, it will fail with
   an error-message like:
   </p>
@@ -70,7 +70,7 @@
   <pre class="prettyprint linenums lang-html">
 &lt;plugin&gt;
   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
-  &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+  &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
   &lt;version&gt;${project.version}&lt;/version&gt;
   &lt;executions&gt;
     &lt;execution&gt;
   Because otherwise, this dependency will unnecessarily bloat the
   runtime-dependencies of your project.
   </p>
-  <h2 id="fails">DBUnit fails after execution of hibernate4 was skipped because nothing has changed</h2>
+  <h2 id="fails">DBUnit fails after execution of hibernate was skipped because nothing has changed</h2>
   <p>
-  If hibernate4-maven-plugin skips its excecution, this may lead to errors in
+  If hibernate-maven-plugin skips its excecution, this may lead to errors in
   other plugins.
   For example, when importing sample-data in the automatically created database
   with the help of the <a href="http://mojo.codehaus.org/dbunit-maven-plugin/">dbunit-plugin</a>,
   the <code>CLEAN_INSERT</code>-operation may fail because of foreign-key-constraints,
-  if the database was not recreated, because the hibernate4-maven-plugin has
+  if the database was not recreated, because the hibernate-maven-plugin has
   skipped its excecution.
   </p>
   <p>
   A quick fix to this problem is, to <a href="./force.html">force</a>
-  hibernate4-maven-plugin to export the schema every time it is running.
+  hibernate-maven-plugin to export the schema every time it is running.
   But to recreate the database on every testrun may noticeable slow down your
   development cycle, if you have to wait for slow IO.
   </p>
   <p>
-  To circumvent this problem, hibernate4-maven-plugin signals a skipped
+  To circumvent this problem, hibernate-maven-plugin signals a skipped
   excecution by setting the  maven property <code>$\{hibernate.export.skipped\}</code> to
   <code>true</code>.
   You can configure other plugins to react on this signal.
   For example, the dbunit-plugin can be configured to skip its excecution, if
-  hibernate4-maven-plugin was skipped like this:
+  hibernate-maven-plugin was skipped like this:
   </p>
   <pre class="prettyprint linenums lang-html">
 &lt;plugin&gt;
   <h2>The database will not be recreated after a manual drop/clean</h2>
   <p>
   If one manually drops the database or removes the hsqldb-files, it will not
-  be recreated by the hibernate4-maven-plugin, because it cannot detect, that
+  be recreated by the hibernate-maven-plugin, because it cannot detect, that
   the database needs to be recreated.
   This happens, because the plugin will not recreate the database if neither
   the configuration nor the annotated classes have changed, because an
   Otherwise the recreation must be <a href="./force.html">forced</a>:
   </p>
   <pre class="prettyprint">
-mvn hibernate4:export -Dhibernate.export.force=true</pre>
-  <h2>The hibernate4:export goal is not executed, when tests are skipped</h2>
+mvn hibernate:export -Dhibernate.export.force=true</pre>
+  <h2>The hibernate:export goal is not executed, when tests are skipped</h2>
   <p>
-  The hibernate4-maven-plugin automatically skips its execution, when
+  The hibernate-maven-plugin automatically skips its execution, when
   <code>maven.test.skip</code> is set to <code>true</code>. If you need it to be always
   executed, you can configure that explicitly like this:
   </p>
   <pre class="prettyprint linenums lang-html">
 &lt;plugin&gt;
   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
-  &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+  &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
   ...
   &lt;configuration&gt;
     &lt;skip&gt;false&lt;/skip&gt;
@@ -173,7 +173,7 @@ mvn hibernate4:export -Dhibernate.export.force=true</pre>
   <pre class="prettyprint linenums lang-html">
 &lt;plugin&gt;
   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
-  &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+  &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
   ...
   &lt;configuration&gt;
     &lt;scanDependencies&gt;none&lt;/scanDependencies&gt;
index 51a20af746243d94058ec442b2a68c9dc2249ce7..5f893b82f75853538c4a600369ed9e2e5794798b 100644 (file)
@@ -5,7 +5,7 @@
  </head>
  <body>
   <p>
-  In most use-cases, the hibernate4-maven-plugin is used to create a
+  In most use-cases, the hibernate-maven-plugin is used to create a
   test-database automatically. In this use-cases, it is very likely, that it
   will result in mistakes/errors, if the goal is executed, when the tests
   are skipped.
@@ -19,7 +19,7 @@
   <p>
   Because of this, the configuration-parameter <code>skip</code> defaults to the value
   of the proptery <code>maven.test.skip</code>. This way, the execution of the
-  hibernate4-maven-plugin is skipped automatically, when the tests are
+  hibernate-maven-plugin is skipped automatically, when the tests are
   skipped. Think of it as a build-in security-belt.
   </p>
   <p>
@@ -30,7 +30,7 @@
   <pre class="prettyprint linenums lang-html">
 &lt;plugin&gt;
   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
-  &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+  &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
   ...
   &lt;configuration&gt;
     &lt;skip&gt;false&lt;/skip&gt;
@@ -44,7 +44,7 @@
   <pre class="prettyprint linenums lang-html">
 &lt;plugin&gt;
   &lt;groupId&gt;de.juplo&lt;/groupId&gt;
-  &lt;artifactId&gt;hibernate4-maven-plugin&lt;/artifactId&gt;
+  &lt;artifactId&gt;hibernate-maven-plugin&lt;/artifactId&gt;
   ...
   &lt;configuration&gt;
     &lt;skip&gt;${foo.bar}&lt;/skip&gt;