r3950 - branches/4.0.1/src/main/java/fr/ifremer/isisfish/util
Author: echatellier Date: 2014-04-11 17:21:43 +0200 (Fri, 11 Apr 2014) New Revision: 3950 Url: http://forge.codelutin.com/projects/isis-fish/repository/revisions/3950 Log: Improve file access performance during simulation 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 15:18:59 UTC (rev 3949) +++ branches/4.0.1/src/main/java/fr/ifremer/isisfish/util/EvaluatorHelper.java 2014-04-11 15:21:43 UTC (rev 3950) @@ -196,16 +196,12 @@ File fileRootSrc = IsisFish.config.getCompileDirectory(); File fileCheckSum = new File(fileRootSrc, packageName + File.separator + className + ".hashCode"); File fileSrc = new File(fileRootSrc, packageName + File.separator + className + ".java"); - File fileDest = new File(fileRootSrc, packageName + File.separator + className + ".class"); + //File fileDest = new File(fileRootSrc, packageName + File.separator + className + ".class"); - boolean checkSumEquals = false; - // if equation's Java file exists, check the checksum - if (fileSrc.exists() && fileCheckSum.exists()) { - String oldCheckSum = getHashCache(fileCheckSum); - String newCheckSum = Integer.toString(script.hashCode()); - checkSumEquals = newCheckSum.equals(oldCheckSum); - } + String oldCheckSum = getHashCache(fileCheckSum); + String newCheckSum = Integer.toString(script.hashCode()); + boolean checkSumEquals = newCheckSum.equals(oldCheckSum); // if Java file's checkSum is not equals to script's checkSum // generate new Java file @@ -220,10 +216,7 @@ } catch (IOException zzz) { throw new IsisFishRuntimeException(t("isisfish.error.save.script.compilation", fileSrc), zzz); } - } - // if Java file is newer than class file, compile java file - if (!fileDest.exists() || FileUtils.isFileNewer(fileSrc, fileDest)) { try { List<File> classpath = new ArrayList<File>(); classpath.add(fileRootSrc.getAbsoluteFile()); @@ -242,8 +235,26 @@ try { ClassLoader cl = IsisFish.config.getScriptClassLoader(); clazz = cl.loadClass(classname); - } catch (Exception zzz) { - throw new IsisFishRuntimeException(t("isisfish.error.load.class", classname), zzz); + } catch (Exception ex) { + + // force to compile it again; may happen if hashcode + // is correct, but .class file can't be loaded + try { + List<File> classpath = new ArrayList<File>(); + classpath.add(fileRootSrc.getAbsoluteFile()); + classpath.add(IsisFish.config.getDatabaseDirectory().getAbsoluteFile()); + int compileResult = CompileHelper.compile(classpath, Collections.singletonList(fileSrc), fileRootSrc, null); + + if (compileResult != 0) { + throw new IsisFishRuntimeException(t("isisfish.error.compile.script", compileResult, fileSrc)); + } + + // second load + ClassLoader cl = IsisFish.config.getScriptClassLoader(); + clazz = cl.loadClass(classname); + } catch (Exception ex2) { + throw new IsisFishRuntimeException(t("isisfish.error.compile.script", fileSrc), ex2); + } } result = invoke(clazz, interfaceMethod, args);
participants (1)
-
echatellier@users.forge.codelutin.com