diff --git a/.gitignore b/.gitignore index 072fa68c..4d5d0f69 100644 --- a/.gitignore +++ b/.gitignore @@ -4,19 +4,20 @@ .mtj.tmp/ # Package Files # -*.jar +!/target/*.jar *.war +*.jar *.ear *Thumbs.db font_easter.png font_easter.rft font_fu32.rft -math-rules-cache.zip /target/ +!/target/*.jar /backups/ /Resources_and_Videos/ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -/bin/ +/bin/ \ No newline at end of file diff --git a/math-rules-cache.zip b/math-rules-cache.zip new file mode 100644 index 00000000..8fb6b49d Binary files /dev/null and b/math-rules-cache.zip differ diff --git a/src/main/java/org/warp/picalculator/Main.java b/src/main/java/org/warp/picalculator/Main.java index efcc8edd..3b796248 100755 --- a/src/main/java/org/warp/picalculator/Main.java +++ b/src/main/java/org/warp/picalculator/Main.java @@ -85,6 +85,9 @@ public class Main { } if (arg.contains("verbose") || arg.contains("debug")) { StaticVars.outputLevel = Utils.OUTPUTLEVEL_DEBUG_VERBOSE; + if (arg.contains("uncached")) { + Utils.debugCache = true; + } } if (arg.contains("ms-dos")) { Utils.headlessOverride = true; diff --git a/src/main/java/org/warp/picalculator/Utils.java b/src/main/java/org/warp/picalculator/Utils.java index e263fe64..8c957817 100755 --- a/src/main/java/org/warp/picalculator/Utils.java +++ b/src/main/java/org/warp/picalculator/Utils.java @@ -84,6 +84,7 @@ public class Utils { private static String OS = System.getProperty("os.name").toLowerCase(); public static String forceEngine; public static boolean msDosMode; + public static boolean debugCache; public static final class AdvancedOutputStream extends StringWriter { diff --git a/src/main/java/org/warp/picalculator/math/rules/RulesManager.java b/src/main/java/org/warp/picalculator/math/rules/RulesManager.java index 55003ebd..c33c49a7 100644 --- a/src/main/java/org/warp/picalculator/math/rules/RulesManager.java +++ b/src/main/java/org/warp/picalculator/math/rules/RulesManager.java @@ -25,33 +25,16 @@ import java.nio.file.StandardOpenOption; import java.nio.file.attribute.BasicFileAttributes; import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.zip.ZipFile; - -import javax.script.Bindings; -import javax.script.Compilable; -import javax.script.CompiledScript; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; - -import org.eclipse.jdt.core.JDTCompilerAdapter; import org.warp.picalculator.Error; import org.warp.picalculator.StaticVars; import org.warp.picalculator.Utils; import org.warp.picalculator.math.Function; import org.warp.picalculator.math.MathContext; import org.warp.picalculator.math.functions.Expression; -import org.warp.picalculator.math.functions.Subtraction; -import org.warp.picalculator.math.functions.Sum; -import org.warp.picalculator.math.functions.SumSubtraction; import org.warp.picalculator.math.functions.Variable; import org.warp.picalculator.math.functions.Variable.V_TYPE; import org.warp.picalculator.math.solver.MathSolver; -import com.jogamp.common.util.IOUtil; - import it.unimi.dsi.fastutil.objects.ObjectArrayList; public class RulesManager { @@ -69,6 +52,7 @@ public class RulesManager { rules[val.ordinal()] = new ObjectArrayList(); } try { + boolean compiledSomething = false; final Path rulesPath = Utils.getResource("/rules.csv"); if (!Files.exists(rulesPath)) { throw new FileNotFoundException("rules.csv not found!"); @@ -78,15 +62,17 @@ public class RulesManager { boolean useCache = false; Path tDir = Paths.get(System.getProperty("java.io.tmpdir"), "WarpPi-Calculator").resolve("rules-rt"); - Path cacheFilePath = Paths.get(Utils.getJarDirectory().toString()).resolve("math-rules-cache.zip").toAbsolutePath(); +// try { +// final Path defaultResource = Utils.getResource("/math-rules-cache.zip"); +// } + Path cacheFilePath = Utils.getResource("/math-rules-cache.zip");//Paths.get(Utils.getJarDirectory().toString()).resolve("math-rules-cache.zip").toAbsolutePath(); if (cacheFilePath.toFile().exists()) { try { if (tDir.toFile().exists()) { tDir.toFile().delete(); } Utils.unzip(cacheFilePath.toString(), tDir.getParent().toString(), ""); - useCache = !StaticVars.debugOn; - cacheFilePath.toFile().delete(); + useCache = !Utils.debugCache; } catch (Exception ex) { ex.printStackTrace(); } @@ -120,6 +106,7 @@ public class RulesManager { Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_MIN, "RulesManager", ruleName, "This rule is not cached. Compiling"); try { r = compileJavaRule(scriptFile, tDir); + compiledSomething = true; } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException e) { e.printStackTrace(); } @@ -132,8 +119,10 @@ public class RulesManager { } } Utils.out.println(Utils.OUTPUTLEVEL_NODEBUG, "RulesManager", "Loaded all the rules successfully"); - Utils.zip(tDir.toString(), cacheFilePath.toString(), ""); - Utils.out.println(Utils.OUTPUTLEVEL_NODEBUG, "RulesManager", "Cached the compiled rules"); + if (compiledSomething) { + Utils.zip(tDir.toString(), cacheFilePath.toString(), ""); + Utils.out.println(Utils.OUTPUTLEVEL_NODEBUG, "RulesManager", "Cached the compiled rules"); + } } catch (URISyntaxException | IOException e) { e.printStackTrace(); System.exit(1); @@ -157,9 +146,12 @@ public class RulesManager { if (!tDirPath.toFile().exists()) { Files.createDirectories(tDirPath); } + if (tFileJava.toFile().exists()) { + tFileJava.toFile().delete(); + } Files.write(tFileJava, javaCode.getBytes("UTF-8"), StandardOpenOption.WRITE, StandardOpenOption.CREATE); boolean compiled = org.eclipse.jdt.internal.compiler.batch.Main.compile(new String[] {"-nowarn", "-1.8", tFileJava.toString()}, new PrintWriter(System.out), new PrintWriter(System.err), null); - if (StaticVars.debugOn) { + if (Utils.debugCache) { tFileJava.toFile().deleteOnExit(); } else { tFileJava.toFile().delete();