X-Git-Url: http://juplo.de/gitweb/?p=hibernate4-maven-plugin;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fplugins%2Fhibernate%2FAbstractSchemaMojo.java;h=922b77db69fdab1bf77ad09f732f7cfebe88c1f7;hp=ff68ea73f0838d626074d9c946b7d917df897f7f;hb=c81cd2f66c77e823cf03591db42d50811706c0de;hpb=ee7f6da0225efc14d89fab58d88a45c98823399e diff --git a/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java b/src/main/java/de/juplo/plugins/hibernate/AbstractSchemaMojo.java index ff68ea73..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); @@ -960,50 +975,52 @@ public abstract class AbstractSchemaMojo extends AbstractMojo String alternativeKey ) { - value = configure(properties, value, key); - if (value == null) - return; + configure(properties, value, key); if (properties.containsKey(alternativeKey)) { - getLog().warn( - "Ignoring property " + alternativeKey + "=" + - properties.getProperty(alternativeKey) + " in favour for property " + - key + "=" + properties.getProperty(key) - ); - properties.remove(alternativeKey); + if (properties.containsKey(key)) + { + getLog().warn( + "Ignoring property " + alternativeKey + "=\"" + + properties.getProperty(alternativeKey) + + "\" in favour for property " + key + "=\"" + + properties.getProperty(key) + "\"" + ); + properties.remove(alternativeKey); + } + else + { + value = properties.getProperty(alternativeKey); + properties.remove(alternativeKey); + getLog().info( + "Using value \"" + value + "\" from property " + alternativeKey + + " for property " + key + ); + properties.setProperty(key, value); + } } } - private String configure(Properties properties, String value, String key) + private void configure(Properties properties, String value, String key) { if (value != null) { if (properties.containsKey(key)) - getLog().debug( - "Overwriting property " + key + "=" + properties.getProperty(key) + - " with the value " + value + getLog().info( + "Overwriting property " + key + "=\"" + + properties.getProperty(key) + + "\" with value \"" + value + "\"" ); else - getLog().debug("Using the value " + value + " for property " + key); + getLog().debug("Using value \"" + value + "\" for property " + key); properties.setProperty(key, value); } - return properties.getProperty(key); } private void configure(Properties properties, Boolean value, String key) { - if (value != null) - { - if (properties.containsKey(key)) - getLog().debug( - "Overwriting property " + key + "=" + properties.getProperty(key) + - " with the value " + value - ); - else - getLog().debug("Using the value " + value + " for property " + key); - properties.setProperty(key, value.toString()); - } + configure(properties, value == null ? null : value.toString(), key); } private File getOutputFile(String filename)