Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 12 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ distributions {
main {
distributionBaseName = 'jgex'
contents {
into("bin") { from 'src/docs'}
into("bin") { from 'src/main/resources/docs'}
}
}
}
Expand Down Expand Up @@ -161,18 +161,24 @@ application {
}

jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE

manifest {
attributes(
'Main-Class': application.mainClass
)
}
mustRunAfter "msgFmtAll"
//to create an uber jar with all dependencies included
from {
configurations.runtimeClasspath.collect{it.isDirectory() ? it:zipTree(it)}
}
}

run {
mustRunAfter "msgFmtAll"
File runningDir = new File('src/docs')
workingDir = runningDir
// File runningDir = new File('src/main/resources/docs')
// workingDir = runningDir
}

javadoc {
Expand All @@ -183,7 +189,7 @@ javapackager {
description = "JGEX combines dynamic geometry software, automated geometry theorem prover with a visually dynamic approach for presenting proofs."
mainClass = applicationMainClass
bundleJre = true
additionalResources = [ file ("src/docs/examples"), file ("src/docs/help"), file("src/docs/import"), file("src/docs/rules") ]
additionalResources = [ file ("src/main/resources/docs/examples"), file ("src/main/resources/docs/help"), file("src/main/resources/docs/import"), file("src/main/resources/docs/rules") ]
organizationName = "JGEX Contributors"
url = "https://github.com/kovzol/Java-Geometry-Expert"
organizationEmail = "jgex@googlegroups.com"
Expand Down Expand Up @@ -220,7 +226,7 @@ task runGproverMain(type: JavaExec) {
description "A command line based test for the GProver, checking all input examples."
mustRunAfter "msgFmtAll"
classpath = sourceSets.main.runtimeClasspath
File runningDir = new File('src/docs')
File runningDir = new File('src/main/resources/docs')
workingDir = runningDir
mainClass = 'gprover.Main'
}
Expand All @@ -229,7 +235,7 @@ task runGproverMain2(type: JavaExec) {
description "A test for the GProver that allows to select a .gex file for checking."
mustRunAfter "msgFmtAll"
classpath = sourceSets.main.runtimeClasspath
File runningDir = new File('src/docs')
File runningDir = new File('src/main/resources/docs')
workingDir = runningDir
mainClass = 'gprover.Main2'
}
19 changes: 19 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- this is the initialization file needed to run this application in the browser through/with CheerpJ -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JGEX (CheerpJ version)</title>
<script src="https://cjrtnc.leaningtech.com/4.1/loader.js"></script>
</head>
<body>
<script>
(async function () {
await cheerpjInit({ version: 11 , enableDebug: true});
cheerpjCreateDisplay(1400, 800);
await cheerpjRunJar("/app/Java-Geometry-Expert-0.86.jar");
<!-- TODO: Change the version number by copying it from the Java source dynamically. -->
})();
</script>
</body>
</html>
85 changes: 64 additions & 21 deletions src/main/java/gprover/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package gprover;

import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.Vector;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

/**
* The main class for the GProver application.
Expand Down Expand Up @@ -30,11 +40,11 @@ public static void main1(String[] args) {
try {
String user_directory = System.getProperty("user.dir");
String sp = File.separator;
// examples are displayed through this method
String dr = user_directory + sp + "examples";
File file = new File(dr);

Vector vm = new Vector();
readThems(file, vm);
readThems(dr, vm);
for (int id = 0; id < vm.size(); id++) {
GTerm gt = (GTerm) vm.get(id);
System.out.print(id + " : " + gt.getName() + "\t\t");
Expand Down Expand Up @@ -96,7 +106,7 @@ public static void main1(String[] args) {
Cm.print("Total = " + vm.size() + "; t = " + t + ", f = " + f + ", n = " + n);
long t2 = System.currentTimeMillis();
Cm.print("Time = " + (t2 - t1) / 1000.0);
} catch (IOException ee) {
} catch (IOException | URISyntaxException ee) {
System.err.println("IOException: " + ee);
}
}
Expand All @@ -108,27 +118,60 @@ public static void main1(String[] args) {
* @param v the vector to store the geometric terms
* @throws IOException if an I/O error occurs
*/
static void readThems(File file, Vector v) throws IOException {
File[] sf = file.listFiles(new FileFilter() {
public boolean accept(File pathname) {
String nm = pathname.getName();
return !(nm.contains("."));
/**
* Recursively read all “.gex”‐style term files from a resource directory on the classpath.
*/
static void readThems(String resourceDir, Vector<GTerm> v) throws IOException, URISyntaxException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL dirUrl = cl.getResource(resourceDir + "/");
if (dirUrl == null) return;

if (dirUrl.getProtocol().equals("file")) {
// running in IDE or exploded build
Path folder = Paths.get(dirUrl.toURI());
try (DirectoryStream<Path> ds = Files.newDirectoryStream(folder)) {
for (Path p : ds) {
String nm = p.getFileName().toString();
if (Files.isDirectory(p)) {
readThems(resourceDir + "/" + nm, v);
} else {
loadTerms(cl.getResourceAsStream(resourceDir + "/" + nm), nm, v);
}
}
}
});
for (int i = 0; i < sf.length; i++) {
if (sf[i].isDirectory())
readThems(sf[i], v);
else {
BufferedReader in = new BufferedReader(new FileReader(sf[i]));

while (true) {
GTerm tm = new GTerm();
if (!tm.readAterm(in)) break;
tm.setName(sf[i].getName());
v.add(tm);
} else if (dirUrl.getProtocol().equals("jar")) {
// running from JAR
String path = dirUrl.getPath();
String jarPath = path.substring(path.indexOf("file:" ) + 5, path.indexOf("!"));
try (JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"))) {
String prefix = resourceDir + "/";
Enumeration<JarEntry> en = jar.entries();
while (en.hasMoreElements()) {
JarEntry entry = en.nextElement();
String name = entry.getName();
if (!name.startsWith(prefix) || entry.isDirectory()) continue;
String rel = name.substring(prefix.length());
if (rel.contains("/")) {
String sub = rel.substring(0, rel.indexOf('/'));
readThems(resourceDir + "/" + sub, v);
} else {
loadTerms(cl.getResourceAsStream(name), rel, v);
}
}
in.close();
}
}
}

private static void loadTerms(InputStream is, String fileName, Vector<GTerm> v) throws IOException {
if (is == null) return;
try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {
while (true) {
GTerm tm = new GTerm();
if (!tm.readAterm(in)) break;
tm.setName(fileName);
v.add(tm);
}
}
}

}
Loading