From: Kai Moritz Date: Sun, 6 Nov 2016 13:46:35 +0000 (+0100) Subject: The output file is truncated, before written to X-Git-Tag: hibernate-maven-plugin-2.1.0~20 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=c81cd2f66c77e823cf03591db42d50811706c0de;p=hibernate-maven-plugin The output file is truncated, before written to --- 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);