From c81cd2f66c77e823cf03591db42d50811706c0de Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 6 Nov 2016 14:46:35 +0100 Subject: [PATCH] The output file is truncated, before written to --- src/it/tutorials/entitymanager/target/create.sql | 7 +++++++ .../plugins/hibernate/AbstractSchemaMojo.java | 15 +++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/it/tutorials/entitymanager/target/create.sql diff --git a/src/it/tutorials/entitymanager/target/create.sql b/src/it/tutorials/entitymanager/target/create.sql new file mode 100644 index 00000000..48eb18ef --- /dev/null +++ b/src/it/tutorials/entitymanager/target/create.sql @@ -0,0 +1,7 @@ + + create table EVENTS ( + id bigint not null, + EVENT_DATE timestamp, + title varchar(255), + primary key (id) + ); diff --git a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java index 9006f352..922b77db 100644 --- a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java +++ b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java @@ -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); -- 2.20.1