Updated cache
This commit is contained in:
parent
821af919fa
commit
7279a44b0e
5
.gitignore
vendored
5
.gitignore
vendored
@ -4,16 +4,17 @@
|
|||||||
.mtj.tmp/
|
.mtj.tmp/
|
||||||
|
|
||||||
# Package Files #
|
# Package Files #
|
||||||
*.jar
|
!/target/*.jar
|
||||||
*.war
|
*.war
|
||||||
|
*.jar
|
||||||
*.ear
|
*.ear
|
||||||
*Thumbs.db
|
*Thumbs.db
|
||||||
font_easter.png
|
font_easter.png
|
||||||
font_easter.rft
|
font_easter.rft
|
||||||
font_fu32.rft
|
font_fu32.rft
|
||||||
math-rules-cache.zip
|
|
||||||
|
|
||||||
/target/
|
/target/
|
||||||
|
!/target/*.jar
|
||||||
/backups/
|
/backups/
|
||||||
/Resources_and_Videos/
|
/Resources_and_Videos/
|
||||||
|
|
||||||
|
BIN
math-rules-cache.zip
Normal file
BIN
math-rules-cache.zip
Normal file
Binary file not shown.
@ -85,6 +85,9 @@ public class Main {
|
|||||||
}
|
}
|
||||||
if (arg.contains("verbose") || arg.contains("debug")) {
|
if (arg.contains("verbose") || arg.contains("debug")) {
|
||||||
StaticVars.outputLevel = Utils.OUTPUTLEVEL_DEBUG_VERBOSE;
|
StaticVars.outputLevel = Utils.OUTPUTLEVEL_DEBUG_VERBOSE;
|
||||||
|
if (arg.contains("uncached")) {
|
||||||
|
Utils.debugCache = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (arg.contains("ms-dos")) {
|
if (arg.contains("ms-dos")) {
|
||||||
Utils.headlessOverride = true;
|
Utils.headlessOverride = true;
|
||||||
|
@ -84,6 +84,7 @@ public class Utils {
|
|||||||
private static String OS = System.getProperty("os.name").toLowerCase();
|
private static String OS = System.getProperty("os.name").toLowerCase();
|
||||||
public static String forceEngine;
|
public static String forceEngine;
|
||||||
public static boolean msDosMode;
|
public static boolean msDosMode;
|
||||||
|
public static boolean debugCache;
|
||||||
|
|
||||||
public static final class AdvancedOutputStream extends StringWriter {
|
public static final class AdvancedOutputStream extends StringWriter {
|
||||||
|
|
||||||
|
@ -25,33 +25,16 @@ import java.nio.file.StandardOpenOption;
|
|||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
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.Error;
|
||||||
import org.warp.picalculator.StaticVars;
|
import org.warp.picalculator.StaticVars;
|
||||||
import org.warp.picalculator.Utils;
|
import org.warp.picalculator.Utils;
|
||||||
import org.warp.picalculator.math.Function;
|
import org.warp.picalculator.math.Function;
|
||||||
import org.warp.picalculator.math.MathContext;
|
import org.warp.picalculator.math.MathContext;
|
||||||
import org.warp.picalculator.math.functions.Expression;
|
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;
|
||||||
import org.warp.picalculator.math.functions.Variable.V_TYPE;
|
import org.warp.picalculator.math.functions.Variable.V_TYPE;
|
||||||
import org.warp.picalculator.math.solver.MathSolver;
|
import org.warp.picalculator.math.solver.MathSolver;
|
||||||
|
|
||||||
import com.jogamp.common.util.IOUtil;
|
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||||
|
|
||||||
public class RulesManager {
|
public class RulesManager {
|
||||||
@ -69,6 +52,7 @@ public class RulesManager {
|
|||||||
rules[val.ordinal()] = new ObjectArrayList<Rule>();
|
rules[val.ordinal()] = new ObjectArrayList<Rule>();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
boolean compiledSomething = false;
|
||||||
final Path rulesPath = Utils.getResource("/rules.csv");
|
final Path rulesPath = Utils.getResource("/rules.csv");
|
||||||
if (!Files.exists(rulesPath)) {
|
if (!Files.exists(rulesPath)) {
|
||||||
throw new FileNotFoundException("rules.csv not found!");
|
throw new FileNotFoundException("rules.csv not found!");
|
||||||
@ -78,15 +62,17 @@ public class RulesManager {
|
|||||||
|
|
||||||
boolean useCache = false;
|
boolean useCache = false;
|
||||||
Path tDir = Paths.get(System.getProperty("java.io.tmpdir"), "WarpPi-Calculator").resolve("rules-rt");
|
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()) {
|
if (cacheFilePath.toFile().exists()) {
|
||||||
try {
|
try {
|
||||||
if (tDir.toFile().exists()) {
|
if (tDir.toFile().exists()) {
|
||||||
tDir.toFile().delete();
|
tDir.toFile().delete();
|
||||||
}
|
}
|
||||||
Utils.unzip(cacheFilePath.toString(), tDir.getParent().toString(), "");
|
Utils.unzip(cacheFilePath.toString(), tDir.getParent().toString(), "");
|
||||||
useCache = !StaticVars.debugOn;
|
useCache = !Utils.debugCache;
|
||||||
cacheFilePath.toFile().delete();
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -120,6 +106,7 @@ public class RulesManager {
|
|||||||
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_MIN, "RulesManager", ruleName, "This rule is not cached. Compiling");
|
Utils.out.println(Utils.OUTPUTLEVEL_DEBUG_MIN, "RulesManager", ruleName, "This rule is not cached. Compiling");
|
||||||
try {
|
try {
|
||||||
r = compileJavaRule(scriptFile, tDir);
|
r = compileJavaRule(scriptFile, tDir);
|
||||||
|
compiledSomething = true;
|
||||||
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException e) {
|
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -132,8 +119,10 @@ public class RulesManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Utils.out.println(Utils.OUTPUTLEVEL_NODEBUG, "RulesManager", "Loaded all the rules successfully");
|
Utils.out.println(Utils.OUTPUTLEVEL_NODEBUG, "RulesManager", "Loaded all the rules successfully");
|
||||||
Utils.zip(tDir.toString(), cacheFilePath.toString(), "");
|
if (compiledSomething) {
|
||||||
Utils.out.println(Utils.OUTPUTLEVEL_NODEBUG, "RulesManager", "Cached the compiled rules");
|
Utils.zip(tDir.toString(), cacheFilePath.toString(), "");
|
||||||
|
Utils.out.println(Utils.OUTPUTLEVEL_NODEBUG, "RulesManager", "Cached the compiled rules");
|
||||||
|
}
|
||||||
} catch (URISyntaxException | IOException e) {
|
} catch (URISyntaxException | IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
@ -157,9 +146,12 @@ public class RulesManager {
|
|||||||
if (!tDirPath.toFile().exists()) {
|
if (!tDirPath.toFile().exists()) {
|
||||||
Files.createDirectories(tDirPath);
|
Files.createDirectories(tDirPath);
|
||||||
}
|
}
|
||||||
|
if (tFileJava.toFile().exists()) {
|
||||||
|
tFileJava.toFile().delete();
|
||||||
|
}
|
||||||
Files.write(tFileJava, javaCode.getBytes("UTF-8"), StandardOpenOption.WRITE, StandardOpenOption.CREATE);
|
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);
|
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();
|
tFileJava.toFile().deleteOnExit();
|
||||||
} else {
|
} else {
|
||||||
tFileJava.toFile().delete();
|
tFileJava.toFile().delete();
|
||||||
|
Loading…
Reference in New Issue
Block a user