Author: bpoussin Date: 2014-03-25 17:11:09 +0100 (Tue, 25 Mar 2014) New Revision: 3907 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/3907 Log: during simulation don't use hashcode file for java file, use Map in ContextSimulation.getValue Modified: trunk/src/main/java/fr/ifremer/isisfish/util/EvaluatorHelper.java Modified: trunk/src/main/java/fr/ifremer/isisfish/util/EvaluatorHelper.java =================================================================== --- trunk/src/main/java/fr/ifremer/isisfish/util/EvaluatorHelper.java 2014-03-25 13:48:04 UTC (rev 3906) +++ trunk/src/main/java/fr/ifremer/isisfish/util/EvaluatorHelper.java 2014-03-25 16:11:09 UTC (rev 3907) @@ -43,6 +43,9 @@ import fr.ifremer.isisfish.IsisFish; import fr.ifremer.isisfish.IsisFishRuntimeException; +import fr.ifremer.isisfish.simulator.SimulationContext; +import java.util.HashMap; +import org.apache.commons.lang3.StringUtils; /** @@ -61,8 +64,58 @@ /** Logger for this class. */ private static Log log = LogFactory.getLog(EvaluatorHelper.class); + 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) { - StringBuffer result = new StringBuffer(name); + StringBuffer result = new StringBuffer(name); for (int i=0; i<result.length(); i++) { char c = result.charAt(i); if (!Character.isJavaIdentifierPart(c)) { @@ -143,12 +196,7 @@ // if equation's Java file exists, check the checksum if (fileSrc.exists() && fileCheckSum.exists()) { - String oldCheckSum = ""; - try { - oldCheckSum = FileUtil.readAsString(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); } @@ -162,14 +210,10 @@ // force writing to UTF-8 // fix compilation issue : unmappable characters FileUtil.writeString(fileSrc, content, "utf-8"); + setHashCache(fileCheckSum, Integer.toString(script.hashCode())); } catch (IOException zzz) { throw new IsisFishRuntimeException(_("isisfish.error.save.script.compilation", fileSrc), zzz); } - try { - FileUtil.writeString(fileCheckSum, Integer.toString(script.hashCode())); - } catch (IOException zzz) { - throw new IsisFishRuntimeException(_("isisfish.error.save.checkSum.compilation", fileSrc), zzz); - } } // if Java file is newer than class file, compile java file
participants (1)
-
bpoussin@users.forge.codelutin.com