Skip to content

Commit 810b3a2

Browse files
committed
issue 34 (.sh/.bat) and fix running from outside sh/bat directory
1 parent 2ca6c6c commit 810b3a2

16 files changed

Lines changed: 56 additions & 25 deletions

File tree

‎koans/app/lib/file-compiler.jar‎

-14 Bytes
Binary file not shown.

‎koans/app/lib/file-monitor.jar‎

49 Bytes
Binary file not shown.

‎koans/app/lib/koans.jar‎

453 Bytes
Binary file not shown.

‎koans/app/lib/util.jar‎

77 Bytes
Binary file not shown.

‎koans/run.bat‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
@echo off
22
cls
3-
3+
setLocal EnableDelayedExpansion
4+
set CLASSPATH="%~dp0app\bin
5+
for /R "%~dp0\app\lib" %%a in (*.jar) do (
6+
set CLASSPATH=!CLASSPATH!;%%a
7+
)
8+
set CLASSPATH=!CLASSPATH!;"
49
javac -version
510
if ERRORLEVEL 3 goto no_javac
611
java -version
712
if ERRORLEVEL 1 goto no_java
813
mkdir "%~dp0\app\data"
914
mkdir "%~dp0\app\bin"
1015
cls
11-
java -classpath "%~dp0\app\bin;%~dp0\app\lib\*" com.sandwich.koan.runner.AppLauncher %1 %2 %3 %4 %5 %6 %7 %8 %9
16+
echo "%~dp0app\bin%CLASSPATH%"
17+
java -Dapplication.basedir="%~dp0"" -classpath %CLASSPATH% com.sandwich.koan.runner.AppLauncher %1 %2 %3 %4 %5 %6 %7 %8 %9
1218

1319
goto end
1420

‎koans/run.sh‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1+
DIR="$( cd -P "$( dirname "$0" )" && pwd )"
22
mkdir -p "$DIR"/app/data
33
mkdir -p "$DIR"/app/bin
4-
function exitOnError()
4+
exitOnError()
55
{
66
rc=$?
77
if [[ $rc != 0 ]] ; then
@@ -10,10 +10,11 @@ function exitOnError()
1010
fi
1111
}
1212

13-
function buildClasspath()
13+
buildClasspath()
1414
{
1515
appDir=$1
1616
classpath=$appDir/bin
17+
IFS=$'\n'
1718

1819
for jar in $appDir/lib/*; do
1920
classpath=$classpath:$jar
@@ -24,4 +25,4 @@ exitOnError 'javac'
2425
java -version > /dev/null 2>&1
2526
exitOnError 'java'
2627
buildClasspath "$DIR"/app
27-
java -classpath $classpath com.sandwich.koan.runner.AppLauncher "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"
28+
java -Dapplication.basedir=\"$DIR\" -classpath \"$classpath\" com.sandwich.koan.runner.AppLauncher "$1" "$2" "$3" "$4" "$5" "$6" "$7" "$8" "$9"

‎lib/file-monitor/src/com/sandwich/util/io/DataFileHelper.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public T read(){
3939
ObjectInputStream objectInputStream = null;
4040
try {
4141
File dataFile = getDataFile();
42+
if(!dataFile.exists()){
43+
return null;
44+
}
4245
objectInputStream = new ObjectInputStream(new FileInputStream(dataFile));
4346
if(dataFile.exists()){
4447
return lastRetrieval = (T)objectInputStream.readObject();

‎lib/koans-lib/src/com/sandwich/koan/KoanClassLoader.java‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.sandwich.koan;
22

33
import java.io.File;
4+
import java.io.UTFDataFormatException;
45

6+
import com.sandwich.koan.util.ApplicationUtils;
57
import com.sandwich.util.io.FileMonitor;
68
import com.sandwich.util.io.FileMonitorFactory;
79
import com.sandwich.util.io.classloader.DynamicClassLoader;
@@ -18,7 +20,19 @@ private KoanClassLoader(){
1820
buildClassPath(),
1921
DynamicClassLoader.class.getClassLoader(),
2022
ApplicationSettings.getFileCompilationTimeoutInMs(),
21-
FileMonitorFactory.getInstance(new File(DirectoryManager.getMainDir()), new File(DirectoryManager.getDataFile())));
23+
getFileMonitor());
24+
}
25+
26+
private static FileMonitor getFileMonitor() {
27+
try{
28+
return FileMonitorFactory.getInstance(new File(DirectoryManager.getMainDir()), new File(DirectoryManager.getDataFile()));
29+
}catch(RuntimeException x){
30+
if(x.getCause() instanceof UTFDataFormatException){
31+
ApplicationUtils.getPresenter().displayError("Issue loading file system hashes, please rerun run.bat or run.sh with the -clear switch to reset.");
32+
System.exit(4);
33+
}
34+
throw x;
35+
}
2236
}
2337

2438
private KoanClassLoader(String binDir, String sourceDir,

‎lib/koans-lib/src/com/sandwich/koan/cmdline/behavior/Clear.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ public class Clear extends AbstractArgumentBehavior {
88

99
public void run(String... values) throws Exception {
1010
new File(DirectoryManager.getDataFile()).delete();
11-
new File(DirectoryManager.getBinDir()).delete();
11+
new File(DirectoryManager.getBinDir()).delete();
12+
new File(DirectoryManager.getDataDir()).delete();
1213
}
1314

1415
}

‎lib/koans-lib/src/com/sandwich/util/io/directories/DirectorySet.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ public String getDataDir(){
4444
}
4545

4646
private static String createBaseDir() {
47+
String baseDir = System.getProperty("application.basedir");
48+
if(baseDir != null){
49+
if(baseDir.startsWith("\"")){
50+
baseDir = baseDir.substring(1);
51+
}
52+
if(baseDir.endsWith("\"")){
53+
baseDir = baseDir.substring(0, baseDir.length() - 1);
54+
}
55+
return new File(baseDir).getParentFile().getAbsolutePath();
56+
}
4757
return new File("").getAbsoluteFile().getParentFile().getAbsolutePath();
4858
}
4959
}

0 commit comments

Comments
 (0)