Skip to content

Commit aad1faa

Browse files
committed
changed file loading and docs folder location
-moved the docs folder into java-directory -instead of gradle setting file paths we do it by hand to make it accessible for cheerpj jvm as well -example files are loaded -some workarounds are in place for the help window -some features might still not be working and/or crashing the application
1 parent 1224297 commit aad1faa

File tree

2,929 files changed

+709
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,929 files changed

+709
-82
lines changed

build.gradle

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,24 @@ application {
161161
}
162162

163163
jar {
164+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
165+
164166
manifest {
165167
attributes(
166168
'Main-Class': application.mainClass
167169
)
168170
}
169171
mustRunAfter "msgFmtAll"
172+
//to create an uber jar with all dependencies included
173+
from {
174+
configurations.runtimeClasspath.collect{it.isDirectory() ? it:zipTree(it)}
175+
}
170176
}
171177

172178
run {
173179
mustRunAfter "msgFmtAll"
174-
File runningDir = new File('src/docs')
175-
workingDir = runningDir
180+
// File runningDir = new File('src/main/resources/docs')
181+
// workingDir = runningDir
176182
}
177183

178184
javadoc {
@@ -183,7 +189,7 @@ javapackager {
183189
description = "JGEX combines dynamic geometry software, automated geometry theorem prover with a visually dynamic approach for presenting proofs."
184190
mainClass = applicationMainClass
185191
bundleJre = true
186-
additionalResources = [ file ("src/docs/examples"), file ("src/docs/help"), file("src/docs/import"), file("src/docs/rules") ]
192+
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") ]
187193
organizationName = "JGEX Contributors"
188194
url = "https://github.com/kovzol/Java-Geometry-Expert"
189195
organizationEmail = "jgex@googlegroups.com"
@@ -220,7 +226,7 @@ task runGproverMain(type: JavaExec) {
220226
description "A command line based test for the GProver, checking all input examples."
221227
mustRunAfter "msgFmtAll"
222228
classpath = sourceSets.main.runtimeClasspath
223-
File runningDir = new File('src/docs')
229+
File runningDir = new File('src/main/resources/docs')
224230
workingDir = runningDir
225231
mainClass = 'gprover.Main'
226232
}
@@ -229,7 +235,7 @@ task runGproverMain2(type: JavaExec) {
229235
description "A test for the GProver that allows to select a .gex file for checking."
230236
mustRunAfter "msgFmtAll"
231237
classpath = sourceSets.main.runtimeClasspath
232-
File runningDir = new File('src/docs')
238+
File runningDir = new File('src/main/resources/docs')
233239
workingDir = runningDir
234240
mainClass = 'gprover.Main2'
235241
}

src/index.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!-- this is the initialization file needed to run this application in the browser through/with CheerpJ -->
2+
<!doctype html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="utf-8" />
6+
<title>CheerpJ test</title>
7+
<script src="https://cjrtnc.leaningtech.com/4.1/loader.js"></script>
8+
</head>
9+
<body>
10+
<script>
11+
(async function () {
12+
await cheerpjInit({ version: 11 , enableDebug: true});
13+
cheerpjCreateDisplay(1400, 800);
14+
await cheerpjRunJar("/app/Java-Geometry-Expert-0.86.jar");
15+
})();
16+
</script>
17+
</body>
18+
</html>

src/main/java/gprover/Main.java

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
package gprover;
22

33
import java.io.*;
4+
import java.net.URISyntaxException;
5+
import java.net.URL;
6+
import java.net.URLDecoder;
7+
import java.nio.file.DirectoryStream;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
import java.util.Enumeration;
412
import java.util.Vector;
13+
import java.util.jar.JarEntry;
14+
import java.util.jar.JarFile;
515

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

3646
Vector vm = new Vector();
37-
readThems(file, vm);
47+
readThems(dr, vm);
3848
for (int id = 0; id < vm.size(); id++) {
3949
GTerm gt = (GTerm) vm.get(id);
4050
System.out.print(id + " : " + gt.getName() + "\t\t");
@@ -96,7 +106,7 @@ public static void main1(String[] args) {
96106
Cm.print("Total = " + vm.size() + "; t = " + t + ", f = " + f + ", n = " + n);
97107
long t2 = System.currentTimeMillis();
98108
Cm.print("Time = " + (t2 - t1) / 1000.0);
99-
} catch (IOException ee) {
109+
} catch (IOException | URISyntaxException ee) {
100110
System.err.println("IOException: " + ee);
101111
}
102112
}
@@ -108,27 +118,60 @@ public static void main1(String[] args) {
108118
* @param v the vector to store the geometric terms
109119
* @throws IOException if an I/O error occurs
110120
*/
111-
static void readThems(File file, Vector v) throws IOException {
112-
File[] sf = file.listFiles(new FileFilter() {
113-
public boolean accept(File pathname) {
114-
String nm = pathname.getName();
115-
return !(nm.contains("."));
121+
/**
122+
* Recursively read all “.gex”‐style term files from a resource directory on the classpath.
123+
*/
124+
static void readThems(String resourceDir, Vector<GTerm> v) throws IOException, URISyntaxException {
125+
ClassLoader cl = Thread.currentThread().getContextClassLoader();
126+
URL dirUrl = cl.getResource(resourceDir + "/");
127+
if (dirUrl == null) return;
128+
129+
if (dirUrl.getProtocol().equals("file")) {
130+
// running in IDE or exploded build
131+
Path folder = Paths.get(dirUrl.toURI());
132+
try (DirectoryStream<Path> ds = Files.newDirectoryStream(folder)) {
133+
for (Path p : ds) {
134+
String nm = p.getFileName().toString();
135+
if (Files.isDirectory(p)) {
136+
readThems(resourceDir + "/" + nm, v);
137+
} else {
138+
loadTerms(cl.getResourceAsStream(resourceDir + "/" + nm), nm, v);
139+
}
140+
}
116141
}
117-
});
118-
for (int i = 0; i < sf.length; i++) {
119-
if (sf[i].isDirectory())
120-
readThems(sf[i], v);
121-
else {
122-
BufferedReader in = new BufferedReader(new FileReader(sf[i]));
123-
124-
while (true) {
125-
GTerm tm = new GTerm();
126-
if (!tm.readAterm(in)) break;
127-
tm.setName(sf[i].getName());
128-
v.add(tm);
142+
} else if (dirUrl.getProtocol().equals("jar")) {
143+
// running from JAR
144+
String path = dirUrl.getPath();
145+
String jarPath = path.substring(path.indexOf("file:" ) + 5, path.indexOf("!"));
146+
try (JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"))) {
147+
String prefix = resourceDir + "/";
148+
Enumeration<JarEntry> en = jar.entries();
149+
while (en.hasMoreElements()) {
150+
JarEntry entry = en.nextElement();
151+
String name = entry.getName();
152+
if (!name.startsWith(prefix) || entry.isDirectory()) continue;
153+
String rel = name.substring(prefix.length());
154+
if (rel.contains("/")) {
155+
String sub = rel.substring(0, rel.indexOf('/'));
156+
readThems(resourceDir + "/" + sub, v);
157+
} else {
158+
loadTerms(cl.getResourceAsStream(name), rel, v);
159+
}
129160
}
130-
in.close();
131161
}
132162
}
133163
}
164+
165+
private static void loadTerms(InputStream is, String fileName, Vector<GTerm> v) throws IOException {
166+
if (is == null) return;
167+
try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {
168+
while (true) {
169+
GTerm tm = new GTerm();
170+
if (!tm.readAterm(in)) break;
171+
tm.setName(fileName);
172+
v.add(tm);
173+
}
174+
}
175+
}
176+
134177
}

0 commit comments

Comments
 (0)