X-Git-Url: https://juplo.de/gitweb/?p=hibernate4-maven-plugin;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fplugins%2Fhibernate%2FModificationTracker.java;h=d9ce624d03a7efc53a8e78de471720d7180e99bc;hp=e03f78e9ab96bcb6a43d75b5541b15427ce577b9;hb=851ced4e14fefba16b690155b698e7a39670e196;hpb=4940080670944a15916c68fb294e18a6bfef12d5 diff --git a/src/main/java/de/juplo/plugins/hibernate/ModificationTracker.java b/src/main/java/de/juplo/plugins/hibernate/ModificationTracker.java index e03f78e9..d9ce624d 100644 --- a/src/main/java/de/juplo/plugins/hibernate/ModificationTracker.java +++ b/src/main/java/de/juplo/plugins/hibernate/ModificationTracker.java @@ -26,8 +26,6 @@ import org.apache.maven.plugin.logging.Log; */ public class ModificationTracker { - public final static String MD5S = "hibernate-generatedschema.md5s"; - private Map properties; private Map classes; @@ -35,19 +33,30 @@ public class ModificationTracker private final Set 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(); classNames = new HashSet(); - 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;