The output file is truncated, before written to
authorKai Moritz <kai@juplo.de>
Sun, 6 Nov 2016 13:46:35 +0000 (14:46 +0100)
committerKai Moritz <kai@juplo.de>
Sun, 13 Nov 2016 16:37:15 +0000 (17:37 +0100)
src/it/tutorials/entitymanager/target/create.sql [new file with mode: 0644]
src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java

diff --git a/src/it/tutorials/entitymanager/target/create.sql b/src/it/tutorials/entitymanager/target/create.sql
new file mode 100644 (file)
index 0000000..48eb18e
--- /dev/null
@@ -0,0 +1,7 @@
+
+    create table EVENTS (
+        id bigint not null,
+        EVENT_DATE timestamp,
+        title varchar(255),
+        primary key (id)
+    );
index 9006f35..922b77d 100644 (file)
@@ -4,6 +4,7 @@ package de.juplo.plugins.hibernate;
 import com.pyx4j.log4j.MavenLogAppender;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
@@ -640,6 +641,20 @@ public abstract class AbstractSchemaMojo extends AbstractMojo
       }
 
 
+      /** Truncate output file */
+      try
+      {
+        new FileOutputStream(output).getChannel().truncate(0).close();
+      }
+      catch (IOException e)
+      {
+        String error =
+            "Error while truncating " + output.getAbsolutePath() + ": "
+            + e.getMessage();
+        getLog().warn(error);
+        throw new MojoExecutionException(error);
+      }
+
       /** Create a connection, if sufficient configuration infromation is available */
       connectionProvider.open(classLoaderService, properties);