The output file is truncated, before written to
[hibernate4-maven-plugin] / src / main / java / de / juplo / plugins / hibernate / AbstractSchemaMojo.java
index ff68ea7..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);
 
@@ -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)