Fixed bug: the execution is no more skipped after a failed build
[hibernate4-maven-plugin] / src / main / java / de / juplo / plugins / hibernate / ModificationTracker.java
index e03f78e..d9ce624 100644 (file)
@@ -26,8 +26,6 @@ import org.apache.maven.plugin.logging.Log;
  */
 public class ModificationTracker
 {
-  public final static String MD5S = "hibernate-generatedschema.md5s";
-
   private Map<String,String> properties;
   private Map<String,String> classes;
 
@@ -35,19 +33,30 @@ public class ModificationTracker
   private final Set<String> classNames;
 
   private boolean modified = false;
+  private boolean failed = false;
 
   private final File saved;
   private final MessageDigest digest;
   private final Log log;
 
 
-  ModificationTracker(String buildDirectory, Log log)
+  ModificationTracker(String buildDirectory, String filename, Log log)
       throws
         NoSuchAlgorithmException
   {
     propertyNames = new HashSet<String>();
     classNames = new HashSet<String>();
-    saved = new File(buildDirectory + File.separator + MD5S);
+    File output = new File(filename + ".md5s");
+    if (output.isAbsolute())
+    {
+      saved = output;
+    }
+    else
+    {
+      // Interpret relative file path relative to build directory
+      saved = new File(buildDirectory, output.getPath());
+      log.debug("Adjusted relative path, resulting path is " + saved.getPath());
+    }
     digest = java.security.MessageDigest.getInstance("MD5");
     this.log = log;
   }
@@ -79,7 +88,7 @@ public class ModificationTracker
   }
 
 
-  boolean check(String name, InputStream is) throws IOException
+  boolean track(String name, InputStream is) throws IOException
   {
     boolean result = check(classes, name, calculate(is));
     classNames.add(name);
@@ -87,23 +96,34 @@ public class ModificationTracker
     return result;
   }
 
+
   boolean check(String name, String property)
   {
-    boolean result = check(properties, name, property);
     propertyNames.add(name);
+    return check(properties, name, property);
+  }
+
+  boolean track(String name, String property)
+  {
+    boolean result = check(name, property);
     modified |= result;
     return result;
   }
 
-  boolean check(Properties properties)
+  boolean track(Properties properties)
   {
     boolean result = false;
     for (String name : properties.stringPropertyNames())
-      result |= check(name, properties.getProperty(name));
+      result |= track(name, properties.getProperty(name));
     return result;
   }
 
 
+  void touch()
+  {
+    modified = true;
+  }
+
   boolean modified()
   {
     modified |= !propertyNames.containsAll(properties.keySet());
@@ -114,6 +134,12 @@ public class ModificationTracker
   }
 
 
+  void failed()
+  {
+    failed = true;
+  }
+
+
   void load()
   {
     if (saved.isFile() && saved.length() > 0)
@@ -150,6 +176,12 @@ public class ModificationTracker
 
   void save()
   {
+    if (failed)
+    {
+      saved.delete();
+      return;
+    }
+
     if (!modified)
       return;