Author: echatellier Date: 2014-04-11 15:56:35 +0200 (Fri, 11 Apr 2014) New Revision: 3947 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/3947 Log: Merge trunk Modified: branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/EvaluatorHelper.java Modified: branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/EvaluatorHelper.java =================================================================== --- branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/EvaluatorHelper.java 2014-04-11 12:28:28 UTC (rev 3946) +++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/EvaluatorHelper.java 2014-04-11 13:56:35 UTC (rev 3947) @@ -44,7 +44,9 @@ import fr.ifremer.isisfish.IsisFishRuntimeException; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.nuiton.util.FileUtil; +import fr.ifremer.isisfish.simulator.SimulationContext; +import java.util.HashMap; +import org.apache.commons.lang3.StringUtils; /** * Permet d'evaluer les equations ecritent en Java @@ -69,7 +71,55 @@ */ static protected Pattern grepImportPattern = Pattern.compile("(?:^\\s*|(?<=;)\\s*)(import[^;]+;)", Pattern.DOTALL + Pattern.MULTILINE); + private static final String HASH_CACHE_KEY = "__hashCache__"; + protected static String getHashCache(File fileCheckSum) { + String result = ""; + + SimulationContext context = SimulationContext.get(); + if (context == null) { + // on est pas dans une simulation + // on verifie dans le fichier + if (fileCheckSum.exists()) { + try { + result = FileUtils.readFileToString(fileCheckSum); + } catch (IOException eee) { + log.info("Can't read old checkSum: " + fileCheckSum, eee); + } + } + } else { + // on est dans une simulation, on verifie dans le cache de la simulation + String key = "__hashCache__"; + Map<String, String> cache = (Map<String, String>)context.getValue(key); + if (cache != null) { + result = StringUtils.defaultString(cache.get(fileCheckSum.getPath())); + } + } + + return result; + } + + protected static void setHashCache(File fileCheckSum, String hashcode) { + SimulationContext context = SimulationContext.get(); + if (context == null) { + // on est pas dans une simulation + // on ecrit dans le fichier + try { + FileUtils.writeStringToFile(fileCheckSum, hashcode); + } catch (IOException eee) { + log.info("Can't write checkSum: " + fileCheckSum, eee); + } + } else { + // on est dans une simulation, on verifie dans le cache de la simulation + Map<String, String> cache = (Map<String, String>)context.getValue(HASH_CACHE_KEY); + if (cache == null) { + context.setValue(HASH_CACHE_KEY, cache = new HashMap<String, String>()); + } + + cache.put(fileCheckSum.getPath(), hashcode); + } + } + protected static String normalizeClassName(String name) { StringBuilder result = new StringBuilder(name); for (int i=0; i<result.length(); i++) { @@ -152,12 +202,7 @@ // if equation's Java file exists, check the checksum if (fileSrc.exists() && fileCheckSum.exists()) { - String oldCheckSum = ""; - try { - oldCheckSum = FileUtils.readFileToString(fileCheckSum); - } catch (IOException eee) { - log.info("Can't read old checkSum: " + fileCheckSum, eee); - } + String oldCheckSum = getHashCache(fileCheckSum); String newCheckSum = Integer.toString(script.hashCode()); checkSumEquals = newCheckSum.equals(oldCheckSum); } @@ -171,14 +216,10 @@ // force writing to UTF-8 // fix compilation issue : unmappable characters FileUtils.writeStringToFile(fileSrc, content, "utf-8"); + setHashCache(fileCheckSum, Integer.toString(script.hashCode())); } catch (IOException zzz) { throw new IsisFishRuntimeException(t("isisfish.error.save.script.compilation", fileSrc), zzz); } - try { - FileUtils.writeStringToFile(fileCheckSum, Integer.toString(script.hashCode()), "utf-8"); - } catch (IOException zzz) { - throw new IsisFishRuntimeException(t("isisfish.error.save.checkSum.compilation", fileSrc), zzz); - } } // if Java file is newer than class file, compile java file
participants (1)
-
echatellier@users.forge.codelutin.com